]> git.sur5r.net Git - ngadmin/commitdiff
Cli: change password can ask new password with terminal echo disabled
authordarkcoven <admin@darkcoven.tk>
Fri, 18 Oct 2013 21:31:40 +0000 (23:31 +0200)
committerdarkcoven <admin@darkcoven.tk>
Fri, 18 Oct 2013 21:31:40 +0000 (23:31 +0200)
cli/man/ngcli.1
cli/src/com_password.c

index 6c3d8631d9747daf5db8497897af06e382dd4908..66101c24683e999c082218c2c806a91db39959ba 100644 (file)
@@ -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 ]
index 0303b2b3c902abd53f1f4c1e2fa161a1b79a99ec..720c5d2cb68bd164529fd0ba6f6ce2903683ea24 100644 (file)
@@ -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 <value>\n");
+       if (argc > 1) {
+               printf("usage: password change [<value>]\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, &current_term);
+               pass = fgets(buf, sizeof(buf), stdin);
+               trim(buf, strlen(buf));
+               current_term.c_lflag |= ECHO;
+               tcsetattr(STDIN_FILENO, TCSANOW, &current_term);
+               putchar('\n');
+       } else {
+               pass = argv[0];
+       }
+       
+       if (pass != NULL) {
+               i = ngadmin_changePassword(nga, pass);
+               printErrCode(i);
+       }
        
        
        return 0;