forked from go-ldap/ldap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrol_dirsync.go
127 lines (103 loc) · 4 KB
/
control_dirsync.go
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package ldap
import (
"fmt"
"gopkg.in/asn1-ber.v1"
)
func init() {
ControlTypeMap[ControlTypeDirSync] = "DIRSYNC"
ControlTypeMap[ControlTypeDirSyncEx] = "DIRSYNC EX"
}
func NewControlDirSync(flags, maxAttributes uint64, cookie []byte) *ControlDirSync {
return &ControlDirSync{
Criticality: true,
Flags: flags,
MaxAttributeCount: maxAttributes,
Cookie: cookie,
}
}
type ControlDirSync struct {
Criticality bool
Flags uint64
MaxAttributeCount uint64
Cookie []byte
}
func (c *ControlDirSync) GetControlType() string {
return ControlTypeDirSync
}
func (c *ControlDirSync) Encode() *ber.Packet {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control")
packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeDirSync, "Control Type ("+ControlTypeMap[ControlTypeDirSync]+")"))
p2 := ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "Control Value (DIRSYNC)")
seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "DIRSYNC Control Value")
seq.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, uint64(c.Flags), "Flags"))
seq.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, uint64(c.MaxAttributeCount), "MaxAttributeCount"))
cookie := ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "Cookie")
cookie.Value = c.Cookie
cookie.Data.Write(c.Cookie)
seq.AppendChild(cookie)
p2.AppendChild(seq)
if c.Criticality {
packet.AppendChild(ber.NewBoolean(ber.ClassUniversal, ber.TypePrimitive, ber.TagBoolean, c.Criticality, "Criticality"))
}
packet.AppendChild(p2)
return packet
}
func (c *ControlDirSync) decode(criticality bool, value *ber.Packet) {
value.Description = "Control Value (DIRSYNC)"
if value.Value != nil {
valueChildren := ber.DecodePacket(value.Data.Bytes())
value.Data.Truncate(0)
value.Value = nil
value.AppendChild(valueChildren)
}
value = value.Children[0]
value.Description = "Search Control Value"
value.Children[0].Description = "Flags"
value.Children[1].Description = "MaxAttributeCount"
value.Children[2].Description = "Cookie"
c.Flags = uint64(value.Children[0].Value.(int64))
c.MaxAttributeCount = uint64(value.Children[1].Value.(int64))
c.Cookie = value.Children[2].Data.Bytes()
value.Children[2].Value = c.Cookie
}
func (c *ControlDirSync) String() string {
return fmt.Sprintf(
"Control Type: %s (%q) Criticality:%v Flags:%v MaxAttributeCount:%v Cookie:%s",
ControlTypeMap[ControlTypeDirSync],
ControlTypeDirSync,
c.Criticality,
c.Flags,
c.MaxAttributeCount,
c.Cookie)
}
func (c *ControlDirSync) SetCookie(cookie []byte) {
c.Cookie = cookie
}
type ControlDirSyncEx struct {
Flag uint64
}
func NewControlDirSyncEx(flag uint64) *ControlDirSyncEx {
return &ControlDirSyncEx{Flag: flag}
}
func (c *ControlDirSyncEx) GetControlType() string {
return ControlTypeDirSyncEx
}
func (c *ControlDirSyncEx) Encode() *ber.Packet {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control")
packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeDirSyncEx, "Control Type ("+ControlTypeMap[ControlTypeDirSyncEx]+")"))
p2 := ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "Control Value (DIRSYNC EX)")
seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Search Control Value")
seq.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, uint64(c.Flag), "Flag"))
p2.AppendChild(seq)
packet.AppendChild(ber.NewBoolean(ber.ClassUniversal, ber.TypePrimitive, ber.TagBoolean, true, "Criticality"))
packet.AppendChild(p2)
return packet
}
func (c *ControlDirSyncEx) String() string {
return fmt.Sprintf(
"Control Type: %s (%q) Criticality: %t Flag: %d",
ControlTypeMap[ControlTypeDirSyncEx],
ControlTypeDirSyncEx,
true,
c.Flag)
}