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 $
22 int getpassword(char *password
, char *text
);
25 int handlerootpassword(void)
27 char password
[STRING_SIZE
];
28 char commandstring
[STRING_SIZE
];
31 if (getpassword(password
, ctr
[TR_ENTER_ROOT_PASSWORD
]) == 2)
34 snprintf(commandstring
, STRING_SIZE
,
35 "/bin/echo 'root:%s' | /usr/sbin/chpasswd", password
);
36 if (runhiddencommandwithstatus(commandstring
, ctr
[TR_SETTING_ROOT_PASSWORD
]))
38 errorbox(ctr
[TR_PROBLEM_SETTING_ROOT_PASSWORD
]);
45 int handleadminpassword(void)
47 char password
[STRING_SIZE
];
48 char commandstring
[STRING_SIZE
];
51 /* web interface admin password. */
52 sprintf(message
, ctr
[TR_ENTER_ADMIN_PASSWORD
], NAME
, NAME
);
53 if (getpassword(password
, message
) == 2)
56 snprintf(commandstring
, STRING_SIZE
,
57 "/usr/bin/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
))
61 sprintf(message
, ctr
[TR_PROBLEM_SETTING_ADMIN_PASSWORD
], NAME
);
69 /* Taken from the cdrom one. */
70 int getpassword(char *password
, char *text
)
72 char *values
[] = { NULL
, NULL
, NULL
}; /* pointers for the values. */
73 struct newtWinEntry entries
[] =
75 { ctr
[TR_PASSWORD_PROMPT
], &values
[0], 2 },
76 { ctr
[TR_AGAIN_PROMPT
], &values
[1], 2 },
79 char title
[STRING_SIZE
];
86 sprintf (title
, "%s v%s - %s", NAME
, VERSION
, SLOGAN
);
87 rc
= newtWinEntries(title
, text
,
88 50, 5, 5, 20, entries
, ctr
[TR_OK
], ctr
[TR_CANCEL
], NULL
);
92 if (strlen(values
[0]) == 0 || strlen(values
[1]) == 0)
94 errorbox(ctr
[TR_PASSWORD_CANNOT_BE_BLANK
]);
96 strcpy(values
[0], "");
97 strcpy(values
[1], "");
99 else if (strcmp(values
[0], values
[1]) != 0)
101 errorbox(ctr
[TR_PASSWORDS_DO_NOT_MATCH
]);
103 strcpy(values
[0], "");
104 strcpy(values
[1], "");
106 else if (strchr(values
[0], ' '))
108 errorbox(ctr
[TR_PASSWORD_CANNOT_CONTAIN_SPACES
]);
110 strcpy(values
[0], "");
111 strcpy(values
[1], "");
117 strncpy(password
, values
[0], STRING_SIZE
);
119 if (values
[0]) free(values
[0]);
120 if (values
[1]) free(values
[1]);