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 ]
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 <value>\n");
+ if (argc > 1) {
+ printf("usage: password change [<value>]\n");
return 1;
}
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;