]> git.sur5r.net Git - ngadmin/blob - cli/com_password.c
92e96c6067c22c61c8ad2cb89351aa4564fe0a4a
[ngadmin] / cli / com_password.c
1
2 #include "commands.h"
3
4
5
6 bool do_password_change (int nb, const char **com, struct ngadmin *nga) {
7  
8  int i;
9  const struct swi_attr *sa;
10  
11  
12  if ( nb!=1 ) {
13   printf("Usage: password change <value>\n");
14   return false;
15  }
16  
17  if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
18   printf("must be logged\n");
19   return false;
20  }
21  
22  i=ngadmin_changePassword(nga, com[0]);
23  printErrCode(i);
24  
25  
26  return true;
27  
28 }
29
30
31
32 bool do_password_set (int nb, const char **com, struct ngadmin *nga) {
33  
34  int i;
35  char buf[64];
36  const char *pass;
37  
38  
39  if ( nb>1 ) {
40   printf("Usage: password set [<value>]\n");
41   return false;
42  }
43  
44  
45  if ( nb==0 ) {
46   printf("Enter password: ");
47   fflush(stdout);
48   current_term.c_lflag&=~ECHO;
49   tcsetattr(STDIN_FILENO, TCSANOW, &current_term);
50   pass=fgets(buf, sizeof(buf), stdin);
51   trim(buf, strlen(buf));
52   current_term.c_lflag|=ECHO;
53   tcsetattr(STDIN_FILENO, TCSANOW, &current_term);
54   putchar('\n');
55  } else {
56   pass=com[0];
57  }
58  
59  
60  if ( pass!=NULL ) {
61   i=ngadmin_setPassword(nga, pass);
62   printErrCode(i);
63  }
64  
65  
66  
67  return true;
68  
69 }
70
71
72