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