diff --git a/add.go b/add.go index 0e5f6cdb..1b49cf12 100644 --- a/add.go +++ b/add.go @@ -41,6 +41,8 @@ type AddRequest struct { DN string // Attributes list the attributes of the new entry Attributes []Attribute + // Controls hold optional controls to send with the request + Controls []Control } func (a AddRequest) encode() *ber.Packet { @@ -60,9 +62,10 @@ func (a *AddRequest) Attribute(attrType string, attrVals []string) { } // NewAddRequest returns an AddRequest for the given DN, with no attributes -func NewAddRequest(dn string) *AddRequest { +func NewAddRequest(dn string, controls []Control) *AddRequest { return &AddRequest{ - DN: dn, + DN: dn, + Controls: controls, } } @@ -72,6 +75,9 @@ func (l *Conn) Add(addRequest *AddRequest) error { packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID")) packet.AppendChild(addRequest.encode()) + if len(addRequest.Controls) > 0 { + packet.AppendChild(encodeControls(addRequest.Controls)) + } l.Debug.PrintPacket(packet) diff --git a/example_test.go b/example_test.go index 650af0a4..4c3a76c5 100644 --- a/example_test.go +++ b/example_test.go @@ -152,7 +152,7 @@ func ExampleConn_Modify() { defer l.Close() // Add a description, and replace the mail attributes - modify := ldap.NewModifyRequest("cn=user,dc=example,dc=com") + modify := ldap.NewModifyRequest("cn=user,dc=example,dc=com", nil) modify.Add("description", []string{"An example user"}) modify.Replace("mail", []string{"user@example.org"}) diff --git a/modify.go b/modify.go index c179bb1c..67f27918 100644 --- a/modify.go +++ b/modify.go @@ -79,6 +79,8 @@ type ModifyRequest struct { DN string // Changes contain the attributes to modify Changes []Change + // Controls hold optional controls to send with the request + Controls []Control } // Add appends the given attribute to the list of changes to be made @@ -114,9 +116,11 @@ func (m ModifyRequest) encode() *ber.Packet { // NewModifyRequest creates a modify request for the given DN func NewModifyRequest( dn string, + controls []Control, ) *ModifyRequest { return &ModifyRequest{ - DN: dn, + DN: dn, + Controls: controls, } } @@ -125,6 +129,9 @@ func (l *Conn) Modify(modifyRequest *ModifyRequest) error { packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID")) packet.AppendChild(modifyRequest.encode()) + if len(modifyRequest.Controls) > 0 { + packet.AppendChild(encodeControls(modifyRequest.Controls)) + } l.Debug.PrintPacket(packet)