- if (setuid(0)) {
- syslog(LOG_ERR, "can't setuid(0)");
- bb_error_msg_and_die( "Cannot change ID to root.\n");
- }
- if (!update_passwd(pw, crypt_passwd)) {
- syslog(LOG_INFO, "password for `%s' changed by user `%s'", name,
- myname);
- printf("Password changed.\n");
- } else {
- syslog(LOG_WARNING, "an error occurred updating the password file");
- bb_error_msg_and_die("An error occurred updating the password file.\n");
- }
- return (0);
-}
-
-
-
-static int create_backup(const char *backup, FILE * fp)
-{
- struct stat sb;
- struct utimbuf ub;
- FILE *bkfp;
- int c, mask;
-
- if (fstat(fileno(fp), &sb))
- /* return -1; */
- return 1;
-
- mask = umask(077);
- bkfp = fopen(backup, "w");
- umask(mask);
- if (!bkfp)
- /* return -1; */
- return 1;
-
- /* TODO: faster copy, not one-char-at-a-time. --marekm */
- rewind(fp);
- while ((c = getc(fp)) != EOF) {
- if (putc(c, bkfp) == EOF)
- break;
- }
- if (c != EOF || fflush(bkfp)) {
- fclose(bkfp);
- /* return -1; */
- return 1;
- }
- if (fclose(bkfp))
- /* return -1; */
- return 1;
-
- ub.actime = sb.st_atime;
- ub.modtime = sb.st_mtime;
- utime(backup, &ub);
- return 0;
-}
-
-static int i64c(int i)
-{
- if (i <= 0)
- return ('.');
- if (i == 1)
- return ('/');
- if (i >= 2 && i < 12)
- return ('0' - 2 + i);
- if (i >= 12 && i < 38)
- return ('A' - 12 + i);
- if (i >= 38 && i < 63)
- return ('a' - 38 + i);
- return ('z');
-}
-
-static char *crypt_make_salt(void)
-{
- time_t now;
- static unsigned long x;
- static char result[3];
-
- time(&now);
- x += now + getpid() + clock();
- result[0] = i64c(((x >> 18) ^ (x >> 6)) & 077);
- result[1] = i64c(((x >> 12) ^ x) & 077);
- result[2] = '\0';
- return result;
-}
-
-
-static int new_password(const struct passwd *pw, int amroot, int algo)
-{
- char *clear;
- char *cipher;
- char *cp;
- char orig[200];
- char pass[200];