This commit is contained in:
Pierre-Olivier Mercier
2020-09-02 15:09:14 +02:00
parent f819320f5a
commit b8d9118b56
4 changed files with 11 additions and 16 deletions

10
ldap.go
View File

@@ -24,10 +24,10 @@ type LDAP struct {
func (l LDAP) Connect() (*LDAPConn, error) {
if l.Ssl {
if c, err := ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", l.Host, l.Port), &tls.Config{ServerName: l.Host}); err != nil {
return nil, errors.New("unable to establish LDAPS connection to " + fmt.Sprintf("%s:%d", l.Host, l.Port) + ": " + err.Error())
return nil, errors.New("unable to establish LDAPS connection to " + fmt.Sprintf("%s:%d", l.Host, l.Port) + ": " + err.Error())
} else {
return &LDAPConn{
LDAP: l,
LDAP: l,
connection: c,
}, nil
}
@@ -42,13 +42,12 @@ func (l LDAP) Connect() (*LDAPConn, error) {
}
return &LDAPConn{
LDAP: l,
LDAP: l,
connection: c,
}, nil
}
}
type LDAPConn struct {
LDAP
connection *ldap.Conn
@@ -117,7 +116,7 @@ func (l LDAPConn) ChangePassword(dn string, rawpassword string) error {
return err
}
hashedpasswd, err := crypt.Crypt(rawpassword, "$6$" + salt + "$")
hashedpasswd, err := crypt.Crypt(rawpassword, "$6$"+salt+"$")
if err != nil {
return err
}
@@ -125,6 +124,5 @@ func (l LDAPConn) ChangePassword(dn string, rawpassword string) error {
modify := ldap.NewModifyRequest(dn)
modify.Replace("userPassword", []string{"{CRYPT}" + hashedpasswd})
return l.connection.Modify(modify)
}