File: upn_dns_info.go

package info (click to toggle)
golang-gopkg-jcmturner-gokrb5.v5 5.3.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, bullseye-backports, sid, trixie
  • size: 1,168 kB
  • sloc: makefile: 2
file content (66 lines) | stat: -rw-r--r-- 1,666 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package pac

import (
	"encoding/binary"
	"sort"

	"gopkg.in/jcmturner/rpc.v0/ndr"
)

// UPNDNSInfo implements https://msdn.microsoft.com/en-us/library/dd240468.aspx
type UPNDNSInfo struct {
	UPNLength           uint16
	UPNOffset           uint16
	DNSDomainNameLength uint16
	DNSDomainNameOffset uint16
	Flags               uint32
	UPN                 string
	DNSDomain           string
}

const (
	upnNoUPNAttr = 31
)

// Unmarshal bytes into the UPN_DNSInfo struct
func (k *UPNDNSInfo) Unmarshal(b []byte) error {
	//The UPN_DNS_INFO structure is a simple structure that is not NDR-encoded.
	var p int
	var e binary.ByteOrder = binary.LittleEndian

	k.UPNLength = ndr.ReadUint16(&b, &p, &e)
	k.UPNOffset = ndr.ReadUint16(&b, &p, &e)
	k.DNSDomainNameLength = ndr.ReadUint16(&b, &p, &e)
	k.DNSDomainNameOffset = ndr.ReadUint16(&b, &p, &e)
	k.Flags = ndr.ReadUint32(&b, &p, &e)
	ub := b[k.UPNOffset : k.UPNOffset+k.UPNLength]
	db := b[k.DNSDomainNameOffset : k.DNSDomainNameOffset+k.DNSDomainNameLength]

	u := make([]rune, k.UPNLength/2, k.UPNLength/2)
	for i := 0; i < len(u); i++ {
		q := i * 2
		u[i] = rune(ndr.ReadUint16(&ub, &q, &e))
	}
	k.UPN = string(u)
	d := make([]rune, k.DNSDomainNameLength/2, k.DNSDomainNameLength/2)
	for i := 0; i < len(d); i++ {
		q := i * 2
		d[i] = rune(ndr.ReadUint16(&db, &q, &e))
	}
	k.DNSDomain = string(d)

	l := []int{
		p,
		int(k.UPNOffset + k.UPNLength),
		int(k.DNSDomainNameOffset + k.DNSDomainNameLength),
	}
	sort.Ints(l)
	//Check that there is only zero padding left
	for _, v := range b[l[2]:] {
		if v != 0 {
			return ndr.Malformed{EText: "non-zero padding left over at end of data stream."}
		}
	}

	return nil
}