]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/setup/passwords.c
1 /* SmoothWall setup program.
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
6 * (c) Lawrence Manning, 2001
9 * $Id: passwords.c,v 1.5.2.1 2004/04/14 22:05:41 gespinasse Exp $
15 #define _(x) dgettext("setup", x)
24 int getpassword(char *password
, char *text
);
27 int handlerootpassword(void)
29 char password
[STRING_SIZE
];
30 char commandstring
[STRING_SIZE
];
33 if (getpassword(password
, _("Enter the 'root' user password. Login as this user for commandline access.")) == 2)
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."));
46 int handleadminpassword(void)
48 char password
[STRING_SIZE
];
49 char commandstring
[STRING_SIZE
];
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)
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
);
70 /* Taken from the cdrom one. */
71 int getpassword(char *password
, char *text
)
73 char *values
[] = { NULL
, NULL
, NULL
}; /* pointers for the values. */
74 struct newtWinEntry entries
[] =
76 { _("Password:"), &values
[0], 2 },
77 { _("Again:"), &values
[1], 2 },
80 char title
[STRING_SIZE
];
87 sprintf (title
, "%s - %s", NAME
, SLOGAN
);
88 rc
= newtWinEntries(title
, text
,
89 65, 5, 5, 50, entries
, _("OK"), _("Cancel"), NULL
);
93 if (strlen(values
[0]) == 0 || strlen(values
[1]) == 0)
95 errorbox(_("Password cannot be blank."));
97 strcpy(values
[0], "");
98 strcpy(values
[1], "");
100 else if (strcmp(values
[0], values
[1]) != 0)
102 errorbox(_("Passwords do not match."));
104 strcpy(values
[0], "");
105 strcpy(values
[1], "");
107 else if (strchr(values
[0], ' '))
109 errorbox(_("Password cannot contain spaces."));
111 strcpy(values
[0], "");
112 strcpy(values
[1], "");
118 strncpy(password
, values
[0], STRING_SIZE
);
120 if (values
[0]) free(values
[0]);
121 if (values
[1]) free(values
[1]);