aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toys/pending/chsh.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/toys/pending/chsh.c b/toys/pending/chsh.c
index c34660f7..bf409783 100644
--- a/toys/pending/chsh.c
+++ b/toys/pending/chsh.c
@@ -32,7 +32,6 @@ void chsh_main()
char *user, *line, *shell, *encrypted;
struct passwd *passwd_info;
struct spwd *shadow_info;
- int i;
// Get uid user information, may be discarded later
@@ -48,7 +47,7 @@ void chsh_main()
// Get a password, encrypt it, wipe it, and check it
if (mlock(toybuf, sizeof(toybuf))) perror_exit("mlock");
if (!(shadow_info = getspnam(passwd_info->pw_name))) perror_exit("getspnam");
- if (!read_password(toybuf, sizeof(toybuf), "Password: ")) xexit();
+ if (read_password(toybuf, sizeof(toybuf), "Password: ")) perror_exit("woaj"); //xexit();
if (!(encrypted = crypt(toybuf, shadow_info->sp_pwdp))) perror_exit("crypt");
memset(toybuf, 0, sizeof(toybuf));
munlock(toybuf, sizeof(toybuf)); // prevents memset from "optimizing" away.
@@ -70,18 +69,9 @@ void chsh_main()
else do line = xgetline(file); while (line && *line != '/');
if (!line) error_exit("Shell not found in '/etc/shells'");
- // Update shell and write passwd entry to tempfile
+ // Update /etc/passwd
passwd_info->pw_shell = line;
- if (!(file = tmpfile())) perror_exit("tmpfile");
- if (!putpwent(passwd_info, file)) perror_exit("putpwent");
-
- // Move passwd entry from file to string
- if (-1 == (i = ftell(file))) perror_exit("Failed to get tempfile offset");
- if (sizeof(toybuf) < i && !realloc(line, i)) perror_exit("Failed to reallocate memory");
- rewind(file);
- if (fread(line, 1, i, file) < i) perror_exit("Failed to read from tempfile");
-
- // Update /etc/passwd using that string
if (-1 == update_password("/etc/passwd", user, NULL)) perror_exit("Failed to remove passwd entry");
- if (-1 == update_password("/etc/passwd", user, line)) perror_exit("Failed to add passwd entry");
+ file = xfopen("/etc/passwd", "a");
+ if (putpwent(passwd_info, file)) perror_exit("putwent");
}