]> git.sur5r.net Git - ngadmin/blobdiff - cli/com_password.c
Remove Makefiles and use autotools
[ngadmin] / cli / com_password.c
index 4b1f184381050079d67f34bd4346d40a7ff25b77..0303b2b3c902abd53f1f4c1e2fa161a1b79a99ec 100644 (file)
@@ -1,60 +1,65 @@
 
-#include "common.h"
-
-
-
-
-static bool do_password_change (const struct TreeNode *tn UNUSED, int nb, const char **com, struct ngadmin *nga) {
- int i;
- const struct swi_attr *sa;
- if ( nb!=1 ) {
-  printf("Usage: password set <value>\n");
-  return false;
- }
- if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
-  printf("must be logged\n");
-  return false;
- }
- i=ngadmin_changePassword(nga, com[0]);
- printErrCode(i);
- return true;
+#include "commands.h"
+
+
+int do_password_change (int argc, const char **argv, struct ngadmin *nga)
+{
+       int i;
+       const struct swi_attr *sa;
+       
+       
+       if (argc != 1) {
+               printf("usage: password change <value>\n");
+               return 1;
+       }
+       
+       sa = ngadmin_getCurrentSwitch(nga);
+       if (sa == NULL) {
+               printf("must be logged\n");
+               return 1;
+       }
+       
+       i = ngadmin_changePassword(nga, argv[0]);
+       printErrCode(i);
+       
+       
+       return 0;
 }
 
 
-
-static bool do_password_set (const struct TreeNode *tn UNUSED, int nb, const char **com, struct ngadmin *nga) {
- int i;
- if ( nb!=1 ) {
-  printf("Usage: password set <value>\n");
-  return false;
- }
- i=ngadmin_setPassword(nga, com[0]);
- printErrCode(i);
- return true;
+int do_password_set (int argc, const char **argv, struct ngadmin *nga)
+{
+       int i;
+       char buf[64];
+       const char *pass;
+       
+       
+       if (argc > 1) {
+               printf("usage: password set [<value>]\n");
+               return 1;
+       }
+       
+       if (argc == 0) {
+               printf("Enter 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_setPassword(nga, pass);
+               printErrCode(i);
+       }
+       
+       
+       return 0;
 }
 
 
-
-
-static const struct TreeNode com_password_change=COM("change", do_password_change, true, NULL);
-static const struct TreeNode com_password_set=COM("set", do_password_set, true, NULL);
-
-const struct TreeNode com_password=COM("password", NULL, false, &com_password_change, &com_password_set, NULL);
-
-
-