Skip to content

Commit

Permalink
Implement Subtree delete control type (go-ldap#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpuschma committed Apr 25, 2022
1 parent a4f752b commit 1be170d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
29 changes: 29 additions & 0 deletions control.go
Expand Up @@ -20,6 +20,8 @@ const (
ControlTypeManageDsaIT = "2.16.840.1.113730.3.4.2"
// ControlTypeWhoAmI - https://tools.ietf.org/html/rfc4532
ControlTypeWhoAmI = "1.3.6.1.4.1.4203.1.11.3"
// ControlTypeSubTreeDelete - https://datatracker.ietf.org/doc/html/draft-armijo-ldap-treedelete-02
ControlTypeSubtreeDelete = "1.2.840.113556.1.4.805"

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

type ControlSubtreeDelete struct{}

func (c *ControlSubtreeDelete) GetControlType() string {
return ControlTypeSubtreeDelete
}

func NewControlSubtreeDelete() *ControlSubtreeDelete {
return &ControlSubtreeDelete{}
}

func (c *ControlSubtreeDelete) Encode() *ber.Packet {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control")
packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeSubtreeDelete, "Control Type ("+ControlTypeMap[ControlTypeSubtreeDelete]+")"))

return packet
}

func (c *ControlSubtreeDelete) String() string {
return fmt.Sprintf(
"Control Type: %s (%q)",
ControlTypeMap[ControlTypeSubtreeDelete],
ControlTypeSubtreeDelete)
}

func encodeControls(controls []Control) *ber.Packet {
packet := ber.Encode(ber.ClassContext, ber.TypeConstructed, 0, nil, "Controls")
for _, control := range controls {
Expand Down
8 changes: 8 additions & 0 deletions control_test.go
Expand Up @@ -32,6 +32,10 @@ func TestControlMicrosoftServerLinkTTL(t *testing.T) {
runControlTest(t, NewControlMicrosoftServerLinkTTL())
}

func TestControlSubtreeDelete(t *testing.T) {
runControlTest(t, NewControlSubtreeDelete())
}

func TestControlString(t *testing.T) {
runControlTest(t, NewControlString("x", true, "y"))
runControlTest(t, NewControlString("x", true, ""))
Expand Down Expand Up @@ -89,6 +93,10 @@ func TestDescribeControlPaging(t *testing.T) {
runAddControlDescriptions(t, NewControlPaging(0), "Control Type (Paging)", "Control Value (Paging)")
}

func TestDescribeControlSubtreeDelete(t *testing.T) {
runAddControlDescriptions(t, NewControlSubtreeDelete(), "Control Type (Subtree Delete Control)")
}

func TestDescribeControlMicrosoftNotification(t *testing.T) {
runAddControlDescriptions(t, NewControlMicrosoftNotification(), "Control Type (Change Notification - Microsoft)")
}
Expand Down
29 changes: 29 additions & 0 deletions v3/control.go
Expand Up @@ -20,6 +20,8 @@ const (
ControlTypeManageDsaIT = "2.16.840.1.113730.3.4.2"
// ControlTypeWhoAmI - https://tools.ietf.org/html/rfc4532
ControlTypeWhoAmI = "1.3.6.1.4.1.4203.1.11.3"
// ControlTypeSubTreeDelete - https://datatracker.ietf.org/doc/html/draft-armijo-ldap-treedelete-02
ControlTypeSubtreeDelete = "1.2.840.113556.1.4.805"

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

type ControlSubtreeDelete struct{}

func (c *ControlSubtreeDelete) GetControlType() string {
return ControlTypeSubtreeDelete
}

func NewControlSubtreeDelete() *ControlSubtreeDelete {
return &ControlSubtreeDelete{}
}

func (c *ControlSubtreeDelete) Encode() *ber.Packet {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control")
packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeSubtreeDelete, "Control Type ("+ControlTypeMap[ControlTypeSubtreeDelete]+")"))

return packet
}

func (c *ControlSubtreeDelete) String() string {
return fmt.Sprintf(
"Control Type: %s (%q)",
ControlTypeMap[ControlTypeSubtreeDelete],
ControlTypeSubtreeDelete)
}

func encodeControls(controls []Control) *ber.Packet {
packet := ber.Encode(ber.ClassContext, ber.TypeConstructed, 0, nil, "Controls")
for _, control := range controls {
Expand Down
8 changes: 8 additions & 0 deletions v3/control_test.go
Expand Up @@ -32,6 +32,10 @@ func TestControlMicrosoftServerLinkTTL(t *testing.T) {
runControlTest(t, NewControlMicrosoftServerLinkTTL())
}

func TestControlSubtreeDelete(t *testing.T) {
runControlTest(t, NewControlSubtreeDelete())
}

func TestControlString(t *testing.T) {
runControlTest(t, NewControlString("x", true, "y"))
runControlTest(t, NewControlString("x", true, ""))
Expand Down Expand Up @@ -89,6 +93,10 @@ func TestDescribeControlPaging(t *testing.T) {
runAddControlDescriptions(t, NewControlPaging(0), "Control Type (Paging)", "Control Value (Paging)")
}

func TestDescribeControlSubtreeDelete(t *testing.T) {
runAddControlDescriptions(t, NewControlSubtreeDelete(), "Control Type (Subtree Delete Control)")
}

func TestDescribeControlMicrosoftNotification(t *testing.T) {
runAddControlDescriptions(t, NewControlMicrosoftNotification(), "Control Type (Change Notification - Microsoft)")
}
Expand Down

0 comments on commit 1be170d

Please sign in to comment.