func (p *Person) MarshalLDAP() (*ldap.Entry, error) { if len(p.sn) < 1 { return nil, errors.New("sn is a must attribute") } if len(p.cn) < 1 { return nil, errors.New("cn is a must attribute") } entry := ldap.NewEntry("") entry.AddAttributeValue("objectClass", "person") entry.AddAttributeValues("sn", p.sn) entry.AddAttributeValues("cn", p.cn) entry.AddAttributeValue("userPassword", "foobar") return entry, nil }
func (o *User) MarshalLDAP() (*ldap.Entry, error) { e := ldap.NewEntry(o.dn) if o.Person { e.AddAttributeValue("objectClass", "person") if len(o.Sn) == 0 { return nil, errors.New(fmt.Sprintf("Marshalling %v: Attribute %v is empty", "User", "Sn")) } e.AddAttributeValues("sn", o.Sn) e.AddAttributeValues("seeAlso", o.SeeAlso) e.AddAttributeValues("telephoneNumber", o.TelephoneNumber) } if o.PosixAccount { e.AddAttributeValue("objectClass", "posixAccount") if len(o.Cn) == 0 { return nil, errors.New(fmt.Sprintf("Marshalling %v: Attribute %v is empty", "User", "Cn")) } if len(o.GidNumber) == 0 { return nil, errors.New(fmt.Sprintf("Marshalling %v: Attribute %v is empty", "User", "GidNumber")) } if len(o.HomeDirectory) == 0 { return nil, errors.New(fmt.Sprintf("Marshalling %v: Attribute %v is empty", "User", "HomeDirectory")) } if len(o.Uid) == 0 { return nil, errors.New(fmt.Sprintf("Marshalling %v: Attribute %v is empty", "User", "Uid")) } if len(o.UidNumber) == 0 { return nil, errors.New(fmt.Sprintf("Marshalling %v: Attribute %v is empty", "User", "UidNumber")) } e.AddAttributeValues("cn", o.Cn) e.AddAttributeValue("gidNumber", o.GidNumber) e.AddAttributeValue("homeDirectory", o.HomeDirectory) e.AddAttributeValues("uid", o.Uid) e.AddAttributeValue("uidNumber", o.UidNumber) e.AddAttributeValues("description", o.Description) e.AddAttributeValue("gecos", o.Gecos) e.AddAttributeValue("loginShell", o.LoginShell) e.AddAttributeValues("userPassword", o.UserPassword) } return e, nil }