Browse Source

Use an admin connection to get the user data

webdeploy
meskio 3 years ago
parent
commit
9e9359114f
Signed by: meskio
GPG Key ID: 52B8F5AC97A2DA86
  1. 10
      ldap/user.go
  2. 1
      server/user.go

10
ldap/user.go

@ -37,6 +37,12 @@ func (l Ldap) ValidateUser(user string, pass string) (User, error) {
if err != nil {
return User{}, err
}
conn.Close()
conn, err = l.connect()
if err != nil {
return User{}, err
}
defer conn.Close()
entry, err := l.searchUser(user, conn)
@ -137,7 +143,7 @@ func (l Ldap) ListUsers() ([]User, error) {
defer conn.Close()
searchRequest := ldap.NewSearchRequest(
"ou=people,"+l.DC,
"ou=People,"+l.DC,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
"(&(objectClass=posixAccount))",
searchAttributes,
@ -262,7 +268,7 @@ func (l Ldap) login(user string, password string) (*ldap.Conn, error) {
func (l Ldap) searchUser(user string, conn *ldap.Conn) (entry *ldap.Entry, err error) {
searchRequest := ldap.NewSearchRequest(
"ou=people,"+l.DC,
"ou=People,"+l.DC,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(&(objectClass=posixAccount)(uid=%s))", ldap.EscapeFilter(user)),
searchAttributes,

1
server/user.go

@ -28,6 +28,7 @@ func (s *server) loginHandler(w http.ResponseWriter, r *http.Request) {
user, err := s.ldap.ValidateUser(name, pass)
if err != nil {
log.Printf("Error login %s: %v", name, err)
response := s.newResponse("login", w, r)
response.execute(true)
return

Loading…
Cancel
Save