|
|
|
@ -14,9 +14,10 @@ type User struct {
|
|
|
|
|
DN string |
|
|
|
|
Name string |
|
|
|
|
Shell string |
|
|
|
|
Home string |
|
|
|
|
Mail string |
|
|
|
|
UID int |
|
|
|
|
GID int |
|
|
|
|
Home string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ValidateUser in the ldap
|
|
|
|
@ -90,7 +91,7 @@ func (l Ldap) ListUsers() ([]User, error) {
|
|
|
|
|
"ou=people,"+l.DC, |
|
|
|
|
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, |
|
|
|
|
"(&(objectClass=posixAccount))", |
|
|
|
|
[]string{"dn", "uid", "uidNumber", "gidNumber", "loginShell", "homeDirectory"}, |
|
|
|
|
[]string{"dn", "uid", "uidNumber", "gidNumber", "loginShell", "homeDirectory", "mail"}, |
|
|
|
|
nil, |
|
|
|
|
) |
|
|
|
|
sr, err := conn.Search(searchRequest) |
|
|
|
@ -128,11 +129,15 @@ func (l *Ldap) AddUser(user string, pass string, gid int) error {
|
|
|
|
|
addRequest := ldap.NewAddRequest(dn) |
|
|
|
|
addRequest.Attribute("uid", []string{ldap.EscapeFilter(user)}) |
|
|
|
|
addRequest.Attribute("cn", []string{ldap.EscapeFilter(user)}) |
|
|
|
|
addRequest.Attribute("objectClass", []string{"account", "posixAccount"}) |
|
|
|
|
addRequest.Attribute("loginShell", []string{"/bin/false"}) |
|
|
|
|
addRequest.Attribute("homeDirectory", []string{l.HomePath + user}) |
|
|
|
|
addRequest.Attribute("sn", []string{ldap.EscapeFilter(user)}) |
|
|
|
|
addRequest.Attribute("objectClass", []string{"inetOrgPerson", "posixAccount", "shadowAccount", "inetLocalMailRecipient", "top"}) |
|
|
|
|
addRequest.Attribute("uidNumber", []string{strconv.Itoa(uid)}) |
|
|
|
|
addRequest.Attribute("gidNumber", []string{strconv.Itoa(gid)}) |
|
|
|
|
addRequest.Attribute("loginShell", []string{"/bin/false"}) |
|
|
|
|
addRequest.Attribute("homeDirectory", []string{l.HomePath + user}) |
|
|
|
|
addRequest.Attribute("mail", []string{user + "@" + l.MailDomain}) |
|
|
|
|
addRequest.Attribute("mailHost", []string{"mail." + l.MailDomain}) |
|
|
|
|
addRequest.Attribute("mailRoutingAddress", []string{user + "@mail." + l.MailDomain}) |
|
|
|
|
err = conn.Add(addRequest) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
@ -186,7 +191,7 @@ func (l Ldap) searchUser(user string, conn *ldap.Conn) (entry *ldap.Entry, err e
|
|
|
|
|
"ou=people,"+l.DC, |
|
|
|
|
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, |
|
|
|
|
fmt.Sprintf("(&(objectClass=posixAccount)(uid=%s))", ldap.EscapeFilter(user)), |
|
|
|
|
[]string{"dn", "uid", "uidNumber", "gidNumber", "loginShell", "homeDirectory"}, |
|
|
|
|
[]string{"dn", "uid", "uidNumber", "gidNumber", "loginShell", "homeDirectory", "mail"}, |
|
|
|
|
nil, |
|
|
|
|
) |
|
|
|
|
sr, err := conn.Search(searchRequest) |
|
|
|
@ -212,8 +217,9 @@ func newUser(entry *ldap.Entry) User {
|
|
|
|
|
DN: entry.DN, |
|
|
|
|
Name: entry.GetAttributeValue("uid"), |
|
|
|
|
Shell: entry.GetAttributeValue("loginShell"), |
|
|
|
|
Home: entry.GetAttributeValue("homeDirectory"), |
|
|
|
|
Mail: entry.GetAttributeValue("mail"), |
|
|
|
|
UID: uid, |
|
|
|
|
GID: gid, |
|
|
|
|
Home: entry.GetAttributeValue("homeDirectory"), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|