]> git.ipfire.org Git - ipfire-2.x.git/blame - src/install+setup/setup/passwords.c
Hinzugefuegt:
[ipfire-2.x.git] / src / install+setup / setup / passwords.c
CommitLineData
cd1a2927
MT
1/* SmoothWall setup program.\r
2 *\r
3 * This program is distributed under the terms of the GNU General Public\r
4 * Licence. See the file COPYING for details.\r
5 *\r
6 * (c) Lawrence Manning, 2001\r
7 * Password stuff.\r
8 * \r
9 * $Id: passwords.c,v 1.5.2.1 2004/04/14 22:05:41 gespinasse Exp $\r
10 * \r
11 */\r
12\r
13#include "setup.h"\r
14\r
15extern FILE *flog;\r
16extern char *mylog;\r
17\r
18extern char **ctr;\r
19\r
20extern int automode;\r
21\r
22int getpassword(char *password, char *text);\r
23\r
24/* Root password. */\r
25int handlerootpassword(void)\r
26{\r
27 char password[STRING_SIZE];\r
28 char commandstring[STRING_SIZE];\r
29 \r
30 /* Root password. */\r
31 if (getpassword(password, ctr[TR_ENTER_ROOT_PASSWORD]) == 2)\r
32 return 0;\r
33 \r
34 snprintf(commandstring, STRING_SIZE,\r
35 "/bin/echo 'root:%s' | /usr/sbin/chpasswd", password);\r
36 if (runhiddencommandwithstatus(commandstring, ctr[TR_SETTING_ROOT_PASSWORD]))\r
37 {\r
38 errorbox(ctr[TR_PROBLEM_SETTING_ROOT_PASSWORD]);\r
39 return 0;\r
40 }\r
41 \r
42 return 1;\r
43}\r
44\r
45int handleadminpassword(void)\r
46{\r
47 char password[STRING_SIZE];\r
48 char commandstring[STRING_SIZE];\r
49 char message[1000];\r
50 \r
51 /* web interface admin password. */\r
52 sprintf(message, ctr[TR_ENTER_ADMIN_PASSWORD], NAME, NAME);\r
53 if (getpassword(password, message) == 2)\r
54 return 0;\r
55 \r
56 snprintf(commandstring, STRING_SIZE,\r
57 "/usr/bin/htpasswd -c -m -b " CONFIG_ROOT "/auth/users admin '%s'", password);\r
58 sprintf(message, ctr[TR_SETTING_ADMIN_PASSWORD], NAME);\r
59 if (runhiddencommandwithstatus(commandstring, message))\r
60 {\r
61 sprintf(message, ctr[TR_PROBLEM_SETTING_ADMIN_PASSWORD], NAME);\r
62 errorbox(message);\r
63 return 0;\r
64 }\r
65\r
66 return 1;\r
67}\r
68\r
69/* Taken from the cdrom one. */\r
70int getpassword(char *password, char *text)\r
71{\r
72 char *values[] = { NULL, NULL, NULL }; /* pointers for the values. */\r
73 struct newtWinEntry entries[] =\r
74 { \r
75 { ctr[TR_PASSWORD_PROMPT], &values[0], 2 },\r
76 { ctr[TR_AGAIN_PROMPT], &values[1], 2 },\r
77 { NULL, NULL, 0 }\r
78 };\r
79 char title[STRING_SIZE];\r
80 int rc;\r
81 int done;\r
82 \r
83 do\r
84 {\r
85 done = 1;\r
86 sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);\r
87 rc = newtWinEntries(title, text,\r
88 50, 5, 5, 20, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);\r
89\r
90 if (rc != 2)\r
91 {\r
92 if (strlen(values[0]) == 0 || strlen(values[1]) == 0)\r
93 {\r
94 errorbox(ctr[TR_PASSWORD_CANNOT_BE_BLANK]);\r
95 done = 0;\r
96 strcpy(values[0], "");\r
97 strcpy(values[1], "");\r
98 }\r
99 else if (strcmp(values[0], values[1]) != 0)\r
100 {\r
101 errorbox(ctr[TR_PASSWORDS_DO_NOT_MATCH]);\r
102 done = 0;\r
103 strcpy(values[0], "");\r
104 strcpy(values[1], "");\r
105 }\r
106 else if (strchr(values[0], ' '))\r
107 {\r
108 errorbox(ctr[TR_PASSWORD_CANNOT_CONTAIN_SPACES]);\r
109 done = 0;\r
110 strcpy(values[0], "");\r
111 strcpy(values[1], "");\r
112 }\r
113 }\r
114 }\r
115 while (!done);\r
116\r
117 strncpy(password, values[0], STRING_SIZE);\r
118\r
119 if (values[0]) free(values[0]);\r
120 if (values[1]) free(values[1]);\r
121\r
122 return rc;\r
123}\r