--- /dev/null
+/* SmoothWall setup program.\r
+ *\r
+ * This program is distributed under the terms of the GNU General Public\r
+ * Licence. See the file COPYING for details.\r
+ *\r
+ * (c) Lawrence Manning, 2001\r
+ * Password stuff.\r
+ * \r
+ * $Id: passwords.c,v 1.5.2.1 2004/04/14 22:05:41 gespinasse Exp $\r
+ * \r
+ */\r
+\r
+#include "setup.h"\r
+\r
+extern FILE *flog;\r
+extern char *mylog;\r
+\r
+extern char **ctr;\r
+\r
+extern int automode;\r
+\r
+int getpassword(char *password, char *text);\r
+\r
+/* Root password. */\r
+int handlerootpassword(void)\r
+{\r
+ char password[STRING_SIZE];\r
+ char commandstring[STRING_SIZE];\r
+ \r
+ /* Root password. */\r
+ if (getpassword(password, ctr[TR_ENTER_ROOT_PASSWORD]) == 2)\r
+ return 0;\r
+ \r
+ snprintf(commandstring, STRING_SIZE,\r
+ "/bin/echo 'root:%s' | /usr/sbin/chpasswd", password);\r
+ if (runhiddencommandwithstatus(commandstring, ctr[TR_SETTING_ROOT_PASSWORD]))\r
+ {\r
+ errorbox(ctr[TR_PROBLEM_SETTING_ROOT_PASSWORD]);\r
+ return 0;\r
+ }\r
+ \r
+ return 1;\r
+}\r
+\r
+int handleadminpassword(void)\r
+{\r
+ char password[STRING_SIZE];\r
+ char commandstring[STRING_SIZE];\r
+ char message[1000];\r
+ \r
+ /* web interface admin password. */\r
+ sprintf(message, ctr[TR_ENTER_ADMIN_PASSWORD], NAME, NAME);\r
+ if (getpassword(password, message) == 2)\r
+ return 0;\r
+ \r
+ snprintf(commandstring, STRING_SIZE,\r
+ "/usr/bin/htpasswd -c -m -b " CONFIG_ROOT "/auth/users admin '%s'", password);\r
+ sprintf(message, ctr[TR_SETTING_ADMIN_PASSWORD], NAME);\r
+ if (runhiddencommandwithstatus(commandstring, message))\r
+ {\r
+ sprintf(message, ctr[TR_PROBLEM_SETTING_ADMIN_PASSWORD], NAME);\r
+ errorbox(message);\r
+ return 0;\r
+ }\r
+\r
+ return 1;\r
+}\r
+\r
+/* Taken from the cdrom one. */\r
+int getpassword(char *password, char *text)\r
+{\r
+ char *values[] = { NULL, NULL, NULL }; /* pointers for the values. */\r
+ struct newtWinEntry entries[] =\r
+ { \r
+ { ctr[TR_PASSWORD_PROMPT], &values[0], 2 },\r
+ { ctr[TR_AGAIN_PROMPT], &values[1], 2 },\r
+ { NULL, NULL, 0 }\r
+ };\r
+ char title[STRING_SIZE];\r
+ int rc;\r
+ int done;\r
+ \r
+ do\r
+ {\r
+ done = 1;\r
+ sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);\r
+ rc = newtWinEntries(title, text,\r
+ 50, 5, 5, 20, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);\r
+\r
+ if (rc != 2)\r
+ {\r
+ if (strlen(values[0]) == 0 || strlen(values[1]) == 0)\r
+ {\r
+ errorbox(ctr[TR_PASSWORD_CANNOT_BE_BLANK]);\r
+ done = 0;\r
+ strcpy(values[0], "");\r
+ strcpy(values[1], "");\r
+ }\r
+ else if (strcmp(values[0], values[1]) != 0)\r
+ {\r
+ errorbox(ctr[TR_PASSWORDS_DO_NOT_MATCH]);\r
+ done = 0;\r
+ strcpy(values[0], "");\r
+ strcpy(values[1], "");\r
+ }\r
+ else if (strchr(values[0], ' '))\r
+ {\r
+ errorbox(ctr[TR_PASSWORD_CANNOT_CONTAIN_SPACES]);\r
+ done = 0;\r
+ strcpy(values[0], "");\r
+ strcpy(values[1], "");\r
+ }\r
+ }\r
+ }\r
+ while (!done);\r
+\r
+ strncpy(password, values[0], STRING_SIZE);\r
+\r
+ if (values[0]) free(values[0]);\r
+ if (values[1]) free(values[1]);\r
+\r
+ return rc;\r
+}\r