Elia Battiston | 4750d3c | 2022-07-14 13:24:56 +0000 | [diff] [blame] | 1 | package pac |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | |
| 6 | "github.com/jcmturner/rpc/v2/mstypes" |
| 7 | ) |
| 8 | |
| 9 | // UPNDNSInfo implements https://msdn.microsoft.com/en-us/library/dd240468.aspx |
| 10 | type UPNDNSInfo struct { |
| 11 | UPNLength uint16 // An unsigned 16-bit integer in little-endian format that specifies the length, in bytes, of the UPN field. |
| 12 | UPNOffset uint16 // An unsigned 16-bit integer in little-endian format that contains the offset to the beginning of the buffer, in bytes, from the beginning of the UPN_DNS_INFO structure. |
| 13 | DNSDomainNameLength uint16 |
| 14 | DNSDomainNameOffset uint16 |
| 15 | Flags uint32 |
| 16 | UPN string |
| 17 | DNSDomain string |
| 18 | } |
| 19 | |
| 20 | const ( |
| 21 | upnNoUPNAttr = 31 // The user account object does not have the userPrincipalName attribute ([MS-ADA3] section 2.349) set. A UPN constructed by concatenating the user name with the DNS domain name of the account domain is provided. |
| 22 | ) |
| 23 | |
| 24 | // Unmarshal bytes into the UPN_DNSInfo struct |
| 25 | func (k *UPNDNSInfo) Unmarshal(b []byte) (err error) { |
| 26 | //The UPN_DNS_INFO structure is a simple structure that is not NDR-encoded. |
| 27 | r := mstypes.NewReader(bytes.NewReader(b)) |
| 28 | k.UPNLength, err = r.Uint16() |
| 29 | if err != nil { |
| 30 | return |
| 31 | } |
| 32 | k.UPNOffset, err = r.Uint16() |
| 33 | if err != nil { |
| 34 | return |
| 35 | } |
| 36 | k.DNSDomainNameLength, err = r.Uint16() |
| 37 | if err != nil { |
| 38 | return |
| 39 | } |
| 40 | k.DNSDomainNameOffset, err = r.Uint16() |
| 41 | if err != nil { |
| 42 | return |
| 43 | } |
| 44 | k.Flags, err = r.Uint32() |
| 45 | if err != nil { |
| 46 | return |
| 47 | } |
| 48 | ub := mstypes.NewReader(bytes.NewReader(b[k.UPNOffset : k.UPNOffset+k.UPNLength])) |
| 49 | db := mstypes.NewReader(bytes.NewReader(b[k.DNSDomainNameOffset : k.DNSDomainNameOffset+k.DNSDomainNameLength])) |
| 50 | |
| 51 | u := make([]rune, k.UPNLength/2, k.UPNLength/2) |
| 52 | for i := 0; i < len(u); i++ { |
| 53 | var r uint16 |
| 54 | r, err = ub.Uint16() |
| 55 | if err != nil { |
| 56 | return |
| 57 | } |
| 58 | u[i] = rune(r) |
| 59 | } |
| 60 | k.UPN = string(u) |
| 61 | d := make([]rune, k.DNSDomainNameLength/2, k.DNSDomainNameLength/2) |
| 62 | for i := 0; i < len(d); i++ { |
| 63 | var r uint16 |
| 64 | r, err = db.Uint16() |
| 65 | if err != nil { |
| 66 | return |
| 67 | } |
| 68 | d[i] = rune(r) |
| 69 | } |
| 70 | k.DNSDomain = string(d) |
| 71 | |
| 72 | return |
| 73 | } |