package ldap import ( "strings" "github.com/vjeantet/goldap/message" ) // attributeRequested reports whether an attribute selection includes // the named attribute. // // Per RFC 4511 section 4.5.1.8 an empty selection, or one containing // "*", asks for all user attributes, while "1.1" asks for none at // all. Anything else is an explicit list. This is used to skip the // extra NetAuth round trip needed for group membership when the client // never asked for it. func attributeRequested(selection message.AttributeSelection, name string) bool { if len(selection) == 0 { return true } name = strings.ToLower(name) for _, sel := range selection { switch s := strings.ToLower(strings.TrimSpace(string(sel))); { case s == "*": return true case s == "1.1", s == "+": continue case strings.HasPrefix(s, name+";"): // An attribute with options, e.g. member;binary. return true case s == name: return true } } return false }