Password change option for Samba server
This commit is contained in:
parent
5b06f17358
commit
cbce4f1dfc
1 changed files with 10 additions and 2 deletions
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ChangeUnixPass(ctx context.Context, sc *ssh.Client, user string, pwd string) error {
|
func genericChangePass(ctx context.Context, sc *ssh.Client, user string, pwd string, cmd string) error {
|
||||||
if !utils.ValidateUnixUsername(user) {
|
if !utils.ValidateUnixUsername(user) {
|
||||||
return fmt.Errorf("invalid unix username")
|
return fmt.Errorf("invalid unix username")
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +27,7 @@ func ChangeUnixPass(ctx context.Context, sc *ssh.Client, user string, pwd string
|
||||||
return errors.Wrap(err, "stdin pipe")
|
return errors.Wrap(err, "stdin pipe")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = sess.Start("passwd " + shellescape.Quote(user))
|
err = sess.Start(cmd + " " + shellescape.Quote(user))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "start change user password cmd")
|
return errors.Wrap(err, "start change user password cmd")
|
||||||
}
|
}
|
||||||
|
|
@ -55,3 +55,11 @@ func ChangeUnixPass(ctx context.Context, sc *ssh.Client, user string, pwd string
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ChangeUnixPass(ctx context.Context, sc *ssh.Client, user string, pwd string) error {
|
||||||
|
return genericChangePass(ctx, sc, user, pwd, "passwd")
|
||||||
|
}
|
||||||
|
|
||||||
|
func ChangeSambaPass(ctx context.Context, sc *ssh.Client, user string, pwd string) error {
|
||||||
|
return genericChangePass(ctx, sc, user, pwd, "smbpasswd -a")
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue