From: darkcoven Date: Fri, 18 Oct 2013 21:31:40 +0000 (+0200) Subject: Cli: change password can ask new password with terminal echo disabled X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e45068f68f416238be6b204d22781fe9d4c3b06f;p=ngadmin Cli: change password can ask new password with terminal echo disabled --- diff --git a/cli/man/ngcli.1 b/cli/man/ngcli.1 index 6c3d863..66101c2 100644 --- a/cli/man/ngcli.1 +++ b/cli/man/ngcli.1 @@ -198,8 +198,9 @@ mask : set the switch netmask to \fImask\fR gw : set the switch gateway to \fIgw\fR . .TP -\fBpassword change\fI password -Change the switch password to \fIpassword\fR. +\fBpassword change\fR [ \fIpassword\fR ] +Change the switch password to \fIpassword\fR. If not specified, it is asked +from user (with terminal echo disabled). . .TP \fBpassword set\fR [ \fIpassword\fR ] diff --git a/cli/src/com_password.c b/cli/src/com_password.c index 0303b2b..720c5d2 100644 --- a/cli/src/com_password.c +++ b/cli/src/com_password.c @@ -5,11 +5,13 @@ int do_password_change (int argc, const char **argv, struct ngadmin *nga) { int i; + char buf[64]; const struct swi_attr *sa; + const char *pass; - if (argc != 1) { - printf("usage: password change \n"); + if (argc > 1) { + printf("usage: password change []\n"); return 1; } @@ -19,8 +21,24 @@ int do_password_change (int argc, const char **argv, struct ngadmin *nga) return 1; } - i = ngadmin_changePassword(nga, argv[0]); - printErrCode(i); + if (argc == 0) { + printf("Enter new password: "); + fflush(stdout); + current_term.c_lflag &= ~ECHO; + tcsetattr(STDIN_FILENO, TCSANOW, ¤t_term); + pass = fgets(buf, sizeof(buf), stdin); + trim(buf, strlen(buf)); + current_term.c_lflag |= ECHO; + tcsetattr(STDIN_FILENO, TCSANOW, ¤t_term); + putchar('\n'); + } else { + pass = argv[0]; + } + + if (pass != NULL) { + i = ngadmin_changePassword(nga, pass); + printErrCode(i); + } return 0;