Exemple #1
0
func (p *Person) UnmarshalLDAP(entry *ldap.Entry) error {
	p.dn = entry.DN
	p.sn = entry.GetAttributeValues("sn")
	if len(p.sn) < 1 {
		return errors.New("sn is a must attribute")
	}

	p.cn = entry.GetAttributeValues("cn")
	if len(p.cn) < 1 {
		return errors.New("cn is a must attribute")
	}

	return nil
}
func (o *User) UnmarshalLDAP(e *ldap.Entry) error {
	o.dn = e.DN

	for _, v := range e.GetAttributeValues("objectClass") {
		switch strings.ToLower(v) {
		case "person":
			o.Person = true
		case "posixaccount":
			o.PosixAccount = true

		}
	}

	o.Cn = e.GetAttributeValues("cn")
	o.GidNumber = e.GetAttributeValue("gidNumber")
	o.HomeDirectory = e.GetAttributeValue("homeDirectory")
	o.Sn = e.GetAttributeValues("sn")
	o.Uid = e.GetAttributeValues("uid")
	o.UidNumber = e.GetAttributeValue("uidNumber")

	o.Description = e.GetAttributeValues("description")
	o.Gecos = e.GetAttributeValue("gecos")
	o.LoginShell = e.GetAttributeValue("loginShell")
	o.SeeAlso = e.GetAttributeValues("seeAlso")
	o.TelephoneNumber = e.GetAttributeValues("telephoneNumber")
	o.UserPassword = e.GetAttributeValues("userPassword")
	return nil
}