mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-12-06 07:58:14 -05:00
Bumps [github.com/go-ldap/ldap/v3](https://github.com/go-ldap/ldap) from 3.4.14 to 3.4.15. - [Release notes](https://github.com/go-ldap/ldap/releases) - [Commits](https://github.com/go-ldap/ldap/compare/v3.4.14...v3.4.15) --- updated-dependencies: - dependency-name: github.com/go-ldap/ldap/v3 dependency-version: 3.4.15 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
package ldap
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
ber "github.com/go-asn1-ber/asn1-ber"
|
|
)
|
|
|
|
// CompareRequest represents an LDAP CompareRequest operation.
|
|
type CompareRequest struct {
|
|
DN string
|
|
Attribute string
|
|
Value string
|
|
}
|
|
|
|
func (req *CompareRequest) appendTo(envelope *ber.Packet) error {
|
|
pkt := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationCompareRequest, nil, "Compare Request")
|
|
pkt.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, req.DN, "DN"))
|
|
|
|
ava := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "AttributeValueAssertion")
|
|
ava.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, req.Attribute, "AttributeDesc"))
|
|
ava.AppendChild(ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, req.Value, "AssertionValue"))
|
|
|
|
pkt.AppendChild(ava)
|
|
|
|
envelope.AppendChild(pkt)
|
|
|
|
return nil
|
|
}
|
|
|
|
// Compare checks to see if the attribute of the dn matches value. Returns true if it does otherwise
|
|
// false with any error that occurs if any.
|
|
func (l *Conn) Compare(dn, attribute, value string) (bool, error) {
|
|
msgCtx, err := l.doRequest(&CompareRequest{
|
|
DN: dn,
|
|
Attribute: attribute,
|
|
Value: value,
|
|
})
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
defer l.finishMessage(msgCtx)
|
|
|
|
packet, err := l.readPacket(msgCtx)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
protocolOp, err := packetChild(packet, 1)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
if protocolOp.Tag == ApplicationCompareResponse {
|
|
err := GetLDAPError(packet)
|
|
|
|
switch {
|
|
case IsErrorWithCode(err, LDAPResultCompareTrue):
|
|
return true, nil
|
|
case IsErrorWithCode(err, LDAPResultCompareFalse):
|
|
return false, nil
|
|
default:
|
|
return false, err
|
|
}
|
|
}
|
|
return false, fmt.Errorf("unexpected Response: %d", protocolOp.Tag)
|
|
}
|