Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement MS Active Directory LDAP_SERVER_FAST_BIND_OID control #515

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions control.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const (
ControlTypeSyncDone = "1.3.6.1.4.1.4203.1.9.1.3"
// ControlTypeSyncInfo - https://www.ietf.org/rfc/rfc4533.txt
ControlTypeSyncInfo = "1.3.6.1.4.1.4203.1.9.1.4"

// ControlFastConcurrentBin - https://msdn.microsoft.com/en-us/library/dc4eb502-fb94-470c-9ab8-ad09fa720ea6
ControlTypeFastBind = "1.2.840.113556.1.4.1781"
)

// Flags for DirSync control
Expand All @@ -72,6 +75,7 @@ var ControlTypeMap = map[string]string{
ControlTypeSyncState: "Sync State",
ControlTypeSyncDone: "Sync Done",
ControlTypeSyncInfo: "Sync Info",
ControlTypeFastBind: "Fast Bind",
}

// Control defines an interface controls provide to encode and describe themselves
Expand Down Expand Up @@ -556,6 +560,8 @@ func DecodeControl(packet *ber.Packet) (Control, error) {
return nil, fmt.Errorf("failed to decode data bytes: %s", err)
}
return NewControlSyncInfo(valueChildren)
case ControlTypeFastBind:
return NewControlFastBind(), nil
default:
c := new(ControlString)
c.ControlType = ControlType
Expand Down Expand Up @@ -1292,3 +1298,29 @@ func (c *ControlSyncInfo) String() string {
c.SyncIdSet,
)
}

// ControlFastBind implements the Active Directory specific
// LDAP_SERVER_FAST_BIND_OID control.
// https://msdn.microsoft.com/en-us/library/58bbd5c4-b5c4-41e2-b12c-cdaad1223d6a
type ControlFastBind struct{}

func NewControlFastBind() *ControlFastBind {
return &ControlFastBind{}
}

// GetControlType returns the OID
func (c *ControlFastBind) GetControlType() string {
return ControlTypeFastBind
}

// Encode encodes the control
func (c *ControlFastBind) Encode() *ber.Packet {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control")
packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeFastBind, "Control Type ("+ControlTypeMap[ControlTypeFastBind]+")"))
return packet
}

// String returns a human-readable description
func (c *ControlFastBind) String() string {
return fmt.Sprintf("Control Type: %s (%q)", ControlTypeMap[ControlTypeFastBind], ControlTypeFastBind)
}
4 changes: 4 additions & 0 deletions control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func TestControlSubtreeDelete(t *testing.T) {
runControlTest(t, NewControlSubtreeDelete())
}

func TestControlFastBind(t *testing.T) {
runControlTest(t, NewControlFastBind())
}

func TestControlString(t *testing.T) {
runControlTest(t, NewControlString("x", true, "y"))
runControlTest(t, NewControlString("x", true, ""))
Expand Down
32 changes: 32 additions & 0 deletions v3/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const (
ControlTypeSyncDone = "1.3.6.1.4.1.4203.1.9.1.3"
// ControlTypeSyncInfo - https://www.ietf.org/rfc/rfc4533.txt
ControlTypeSyncInfo = "1.3.6.1.4.1.4203.1.9.1.4"

// ControlFastConcurrentBin - https://msdn.microsoft.com/en-us/library/dc4eb502-fb94-470c-9ab8-ad09fa720ea6
ControlTypeFastBind = "1.2.840.113556.1.4.1781"
)

// Flags for DirSync control
Expand All @@ -72,6 +75,7 @@ var ControlTypeMap = map[string]string{
ControlTypeSyncState: "Sync State",
ControlTypeSyncDone: "Sync Done",
ControlTypeSyncInfo: "Sync Info",
ControlTypeFastBind: "Fast Bind",
}

// Control defines an interface controls provide to encode and describe themselves
Expand Down Expand Up @@ -556,6 +560,8 @@ func DecodeControl(packet *ber.Packet) (Control, error) {
return nil, fmt.Errorf("failed to decode data bytes: %s", err)
}
return NewControlSyncInfo(valueChildren)
case ControlTypeFastBind:
return NewControlFastBind(), nil
default:
c := new(ControlString)
c.ControlType = ControlType
Expand Down Expand Up @@ -1292,3 +1298,29 @@ func (c *ControlSyncInfo) String() string {
c.SyncIdSet,
)
}

// ControlFastBind implements the Active Directory specific
// LDAP_SERVER_FAST_BIND_OID control.
// https://msdn.microsoft.com/en-us/library/58bbd5c4-b5c4-41e2-b12c-cdaad1223d6a
type ControlFastBind struct{}

func NewControlFastBind() *ControlFastBind {
return &ControlFastBind{}
}

// GetControlType returns the OID
func (c *ControlFastBind) GetControlType() string {
return ControlTypeFastBind
}

// Encode encodes the control
func (c *ControlFastBind) Encode() *ber.Packet {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control")
packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeFastBind, "Control Type ("+ControlTypeMap[ControlTypeFastBind]+")"))
return packet
}

// String returns a human-readable description
func (c *ControlFastBind) String() string {
return fmt.Sprintf("Control Type: %s (%q)", ControlTypeMap[ControlTypeFastBind], ControlTypeFastBind)
}
4 changes: 4 additions & 0 deletions v3/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func TestControlSubtreeDelete(t *testing.T) {
runControlTest(t, NewControlSubtreeDelete())
}

func TestControlFastBind(t *testing.T) {
runControlTest(t, NewControlFastBind())
}

func TestControlString(t *testing.T) {
runControlTest(t, NewControlString("x", true, "y"))
runControlTest(t, NewControlString("x", true, ""))
Expand Down
Loading