ChangeShell added

merge-requests/6/head
meskio 5 years ago
parent bb301140ce
commit 1806b2a0b0
Signed by: meskio
GPG Key ID: 52B8F5AC97A2DA86
  1. 13
      ldap/user.go
  2. 26
      ldap/user_test.go

@ -149,6 +149,19 @@ func (l Ldap) DelUser(user string) error {
return l.del(l.userDN(user))
}
// ChangeShell for the user
func (l Ldap) ChangeShell(user, shell string) error {
conn, err := l.connect()
if err != nil {
return err
}
defer conn.Close()
modifyRequest := ldap.NewModifyRequest(l.userDN(user))
modifyRequest.Replace("loginShell", []string{shell})
return conn.Modify(modifyRequest)
}
func (l Ldap) userDN(user string) string {
userStr := ldap.EscapeFilter(user)
return fmt.Sprintf("uid=%s,ou=People,%s", userStr, l.DC)

@ -160,3 +160,29 @@ func TestAddExistingUser(t *testing.T) {
}
}
func TestChangeShell(t *testing.T) {
const shell = "otherShell"
l := testLdap()
user, err := l.GetUser("user")
actualShell := user.Shell
err = l.ChangeShell("user", shell)
if err != nil {
t.Errorf("ChangeShell() failed: %v", err)
}
user, err = l.GetUser("user")
if user.Shell != shell {
t.Errorf("The shell was not changed: %v", user.Shell)
}
err = l.ChangeShell("user", actualShell)
if err != nil {
t.Errorf("ChangeShell() failed: %v", err)
}
user, err = l.GetUser("user")
if user.Shell != actualShell {
t.Errorf("The shell was not changed: %v", user.Shell)
}
}

Loading…
Cancel
Save