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