Skip to content

Commit 7d3b8d4

Browse files
authored
Implement Subtree delete control type (#373)
1 parent f5d7636 commit 7d3b8d4

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

control.go

+29
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const (
2020
ControlTypeManageDsaIT = "2.16.840.1.113730.3.4.2"
2121
// ControlTypeWhoAmI - https://tools.ietf.org/html/rfc4532
2222
ControlTypeWhoAmI = "1.3.6.1.4.1.4203.1.11.3"
23+
// ControlTypeSubTreeDelete - https://datatracker.ietf.org/doc/html/draft-armijo-ldap-treedelete-02
24+
ControlTypeSubtreeDelete = "1.2.840.113556.1.4.805"
2325

2426
// ControlTypeMicrosoftNotification - https://msdn.microsoft.com/en-us/library/aa366983(v=vs.85).aspx
2527
ControlTypeMicrosoftNotification = "1.2.840.113556.1.4.528"
@@ -34,6 +36,7 @@ var ControlTypeMap = map[string]string{
3436
ControlTypePaging: "Paging",
3537
ControlTypeBeheraPasswordPolicy: "Password Policy - Behera Draft",
3638
ControlTypeManageDsaIT: "Manage DSA IT",
39+
ControlTypeSubtreeDelete: "Subtree Delete Control",
3740
ControlTypeMicrosoftNotification: "Change Notification - Microsoft",
3841
ControlTypeMicrosoftShowDeleted: "Show Deleted Objects - Microsoft",
3942
ControlTypeMicrosoftServerLinkTTL: "Return TTL-DNs for link values with associated expiry times - Microsoft",
@@ -485,6 +488,8 @@ func DecodeControl(packet *ber.Packet) (Control, error) {
485488
return NewControlMicrosoftShowDeleted(), nil
486489
case ControlTypeMicrosoftServerLinkTTL:
487490
return NewControlMicrosoftServerLinkTTL(), nil
491+
case ControlTypeSubtreeDelete:
492+
return NewControlSubtreeDelete(), nil
488493
default:
489494
c := new(ControlString)
490495
c.ControlType = ControlType
@@ -519,6 +524,30 @@ func NewControlBeheraPasswordPolicy() *ControlBeheraPasswordPolicy {
519524
}
520525
}
521526

527+
type ControlSubtreeDelete struct{}
528+
529+
func (c *ControlSubtreeDelete) GetControlType() string {
530+
return ControlTypeSubtreeDelete
531+
}
532+
533+
func NewControlSubtreeDelete() *ControlSubtreeDelete {
534+
return &ControlSubtreeDelete{}
535+
}
536+
537+
func (c *ControlSubtreeDelete) Encode() *ber.Packet {
538+
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control")
539+
packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeSubtreeDelete, "Control Type ("+ControlTypeMap[ControlTypeSubtreeDelete]+")"))
540+
541+
return packet
542+
}
543+
544+
func (c *ControlSubtreeDelete) String() string {
545+
return fmt.Sprintf(
546+
"Control Type: %s (%q)",
547+
ControlTypeMap[ControlTypeSubtreeDelete],
548+
ControlTypeSubtreeDelete)
549+
}
550+
522551
func encodeControls(controls []Control) *ber.Packet {
523552
packet := ber.Encode(ber.ClassContext, ber.TypeConstructed, 0, nil, "Controls")
524553
for _, control := range controls {

control_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func TestControlMicrosoftServerLinkTTL(t *testing.T) {
3232
runControlTest(t, NewControlMicrosoftServerLinkTTL())
3333
}
3434

35+
func TestControlSubtreeDelete(t *testing.T) {
36+
runControlTest(t, NewControlSubtreeDelete())
37+
}
38+
3539
func TestControlString(t *testing.T) {
3640
runControlTest(t, NewControlString("x", true, "y"))
3741
runControlTest(t, NewControlString("x", true, ""))
@@ -89,6 +93,10 @@ func TestDescribeControlPaging(t *testing.T) {
8993
runAddControlDescriptions(t, NewControlPaging(0), "Control Type (Paging)", "Control Value (Paging)")
9094
}
9195

96+
func TestDescribeControlSubtreeDelete(t *testing.T) {
97+
runAddControlDescriptions(t, NewControlSubtreeDelete(), "Control Type (Subtree Delete Control)")
98+
}
99+
92100
func TestDescribeControlMicrosoftNotification(t *testing.T) {
93101
runAddControlDescriptions(t, NewControlMicrosoftNotification(), "Control Type (Change Notification - Microsoft)")
94102
}

v3/control.go

+29
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const (
2020
ControlTypeManageDsaIT = "2.16.840.1.113730.3.4.2"
2121
// ControlTypeWhoAmI - https://tools.ietf.org/html/rfc4532
2222
ControlTypeWhoAmI = "1.3.6.1.4.1.4203.1.11.3"
23+
// ControlTypeSubTreeDelete - https://datatracker.ietf.org/doc/html/draft-armijo-ldap-treedelete-02
24+
ControlTypeSubtreeDelete = "1.2.840.113556.1.4.805"
2325

2426
// ControlTypeMicrosoftNotification - https://msdn.microsoft.com/en-us/library/aa366983(v=vs.85).aspx
2527
ControlTypeMicrosoftNotification = "1.2.840.113556.1.4.528"
@@ -34,6 +36,7 @@ var ControlTypeMap = map[string]string{
3436
ControlTypePaging: "Paging",
3537
ControlTypeBeheraPasswordPolicy: "Password Policy - Behera Draft",
3638
ControlTypeManageDsaIT: "Manage DSA IT",
39+
ControlTypeSubtreeDelete: "Subtree Delete Control",
3740
ControlTypeMicrosoftNotification: "Change Notification - Microsoft",
3841
ControlTypeMicrosoftShowDeleted: "Show Deleted Objects - Microsoft",
3942
ControlTypeMicrosoftServerLinkTTL: "Return TTL-DNs for link values with associated expiry times - Microsoft",
@@ -485,6 +488,8 @@ func DecodeControl(packet *ber.Packet) (Control, error) {
485488
return NewControlMicrosoftShowDeleted(), nil
486489
case ControlTypeMicrosoftServerLinkTTL:
487490
return NewControlMicrosoftServerLinkTTL(), nil
491+
case ControlTypeSubtreeDelete:
492+
return NewControlSubtreeDelete(), nil
488493
default:
489494
c := new(ControlString)
490495
c.ControlType = ControlType
@@ -519,6 +524,30 @@ func NewControlBeheraPasswordPolicy() *ControlBeheraPasswordPolicy {
519524
}
520525
}
521526

527+
type ControlSubtreeDelete struct{}
528+
529+
func (c *ControlSubtreeDelete) GetControlType() string {
530+
return ControlTypeSubtreeDelete
531+
}
532+
533+
func NewControlSubtreeDelete() *ControlSubtreeDelete {
534+
return &ControlSubtreeDelete{}
535+
}
536+
537+
func (c *ControlSubtreeDelete) Encode() *ber.Packet {
538+
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control")
539+
packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeSubtreeDelete, "Control Type ("+ControlTypeMap[ControlTypeSubtreeDelete]+")"))
540+
541+
return packet
542+
}
543+
544+
func (c *ControlSubtreeDelete) String() string {
545+
return fmt.Sprintf(
546+
"Control Type: %s (%q)",
547+
ControlTypeMap[ControlTypeSubtreeDelete],
548+
ControlTypeSubtreeDelete)
549+
}
550+
522551
func encodeControls(controls []Control) *ber.Packet {
523552
packet := ber.Encode(ber.ClassContext, ber.TypeConstructed, 0, nil, "Controls")
524553
for _, control := range controls {

v3/control_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func TestControlMicrosoftServerLinkTTL(t *testing.T) {
3232
runControlTest(t, NewControlMicrosoftServerLinkTTL())
3333
}
3434

35+
func TestControlSubtreeDelete(t *testing.T) {
36+
runControlTest(t, NewControlSubtreeDelete())
37+
}
38+
3539
func TestControlString(t *testing.T) {
3640
runControlTest(t, NewControlString("x", true, "y"))
3741
runControlTest(t, NewControlString("x", true, ""))
@@ -89,6 +93,10 @@ func TestDescribeControlPaging(t *testing.T) {
8993
runAddControlDescriptions(t, NewControlPaging(0), "Control Type (Paging)", "Control Value (Paging)")
9094
}
9195

96+
func TestDescribeControlSubtreeDelete(t *testing.T) {
97+
runAddControlDescriptions(t, NewControlSubtreeDelete(), "Control Type (Subtree Delete Control)")
98+
}
99+
92100
func TestDescribeControlMicrosoftNotification(t *testing.T) {
93101
runAddControlDescriptions(t, NewControlMicrosoftNotification(), "Control Type (Change Notification - Microsoft)")
94102
}

0 commit comments

Comments
 (0)