Nuestro burocrata preferido: Sam Lowry https://lowry.sindominio.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lowry/ldap/user.go

50 lines
1.1 KiB

package ldap
import (
"errors"
"fmt"
"github.com/go-ldap/ldap"
)
// LogIn in the ldap
func (s *Session) LogIn(user string, pass string) error {
entry, err := s.searchUser(user)
if err != nil {
return err
}
userdn := entry.DN
return s.conn.Bind(userdn, pass)
}
5 years ago
// ChangePass changes logged in user's password
func (s *Session) ChangePass(oldpass string, newpass string) error {
passwordModifyRequest := ldap.NewPasswordModifyRequest("", oldpass, newpass)
_, err := s.conn.PasswordModify(passwordModifyRequest)
return err
}
func (s *Session) searchUser(user string) (entry *ldap.Entry, err error) {
searchRequest := ldap.NewSearchRequest(
"ou=people,"+s.dc,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(&(objectClass=posixAccount)(uid=%s))", user),
[]string{"dn"},
nil,
)
sr, err := s.conn.Search(searchRequest)
if err != nil {
return entry, err
}
switch len(sr.Entries) {
case 1:
entry = sr.Entries[0]
return entry, nil
case 0:
return entry, errors.New("No user found")
default:
return entry, errors.New("More than one user found!!!")
}
}