]> git.ipfire.org Git - ipfire-2.x.git/blame - src/setup/passwords.c
Merge branch 'ipsec' into next
[ipfire-2.x.git] / src / 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
e1457ba0
MT
13// Translation
14#include <libintl.h>
15#define _(x) dgettext("setup", x)
16
90c973a6
MT
17#include "setup.h"
18
19extern FILE *flog;
20extern char *mylog;
21
90c973a6
MT
22extern int automode;
23
24int getpassword(char *password, char *text);
25
26/* Root password. */
27int handlerootpassword(void)
28{
29 char password[STRING_SIZE];
30 char commandstring[STRING_SIZE];
31
32 /* Root password. */
e1457ba0 33 if (getpassword(password, _("Enter the 'root' user password. Login as this user for commandline access.")) == 2)
90c973a6
MT
34 return 0;
35
36 snprintf(commandstring, STRING_SIZE,
069680ac 37 "/bin/echo 'root:%s' | /usr/sbin/chpasswd", password);
46b56e20 38 if (runhiddencommandwithstatus(commandstring, _("Setting password"), _("Setting 'root' password...."), NULL)) {
e1457ba0 39 errorbox(_("Problem setting 'root' password."));
90c973a6
MT
40 return 0;
41 }
42
43 return 1;
44}
45
46int handleadminpassword(void)
47{
48 char password[STRING_SIZE];
49 char commandstring[STRING_SIZE];
50 char message[1000];
51
52 /* web interface admin password. */
e1457ba0
MT
53 sprintf(message, _("Enter %s 'admin' user password. "
54 "This is the user to use for logging into the %s web administration pages."), NAME, NAME);
90c973a6
MT
55 if (getpassword(password, message) == 2)
56 return 0;
57
58 snprintf(commandstring, STRING_SIZE,
d41fe99f 59 "/usr/bin/htpasswd -c -B -C 7 -b " CONFIG_ROOT "/auth/users admin '%s'", password);
e1457ba0 60 sprintf(message, _("Setting %s 'admin' user password..."), NAME);
46b56e20 61 if (runhiddencommandwithstatus(commandstring, _("Setting password"), message, NULL)) {
e1457ba0 62 sprintf(message, _("Problem setting %s 'admin' user password."), NAME);
90c973a6
MT
63 errorbox(message);
64 return 0;
65 }
66
67 return 1;
68}
69
70/* Taken from the cdrom one. */
71int getpassword(char *password, char *text)
72{
73 char *values[] = { NULL, NULL, NULL }; /* pointers for the values. */
74 struct newtWinEntry entries[] =
75 {
e1457ba0
MT
76 { _("Password:"), &values[0], 2 },
77 { _("Again:"), &values[1], 2 },
90c973a6
MT
78 { NULL, NULL, 0 }
79 };
80 char title[STRING_SIZE];
81 int rc;
82 int done;
83
84 do
85 {
86 done = 1;
d1782bf0 87 sprintf (title, "%s - %s", NAME, SLOGAN);
90c973a6 88 rc = newtWinEntries(title, text,
e1457ba0 89 65, 5, 5, 50, entries, _("OK"), _("Cancel"), NULL);
90c973a6
MT
90
91 if (rc != 2)
92 {
93 if (strlen(values[0]) == 0 || strlen(values[1]) == 0)
94 {
e1457ba0 95 errorbox(_("Password cannot be blank."));
90c973a6
MT
96 done = 0;
97 strcpy(values[0], "");
98 strcpy(values[1], "");
99 }
100 else if (strcmp(values[0], values[1]) != 0)
101 {
e1457ba0 102 errorbox(_("Passwords do not match."));
90c973a6
MT
103 done = 0;
104 strcpy(values[0], "");
105 strcpy(values[1], "");
106 }
107 else if (strchr(values[0], ' '))
108 {
e1457ba0 109 errorbox(_("Password cannot contain spaces."));
90c973a6
MT
110 done = 0;
111 strcpy(values[0], "");
112 strcpy(values[1], "");
113 }
114 }
115 }
116 while (!done);
117
118 strncpy(password, values[0], STRING_SIZE);
119
120 if (values[0]) free(values[0]);
121 if (values[1]) free(values[1]);
122
123 return rc;
124}