diff options
author | Tobias Stoeckmann <tobias@stoeckmann.org> | 2023-12-12 15:51:13 +0100 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2023-12-12 20:05:08 +0000 |
commit | 525a62a643f0bf18b12643dd4e8a3dc3d4c63fcd (patch) | |
tree | bdb6f5beb61f8ab0f5f8fe46c2f1b0533e161b7b /modules/pam_unix/passverify.c | |
parent | cf492d0cedf10d4128c5cf211998dff2260acb6a (diff) | |
download | pam-525a62a643f0bf18b12643dd4e8a3dc3d4c63fcd.tar.gz pam-525a62a643f0bf18b12643dd4e8a3dc3d4c63fcd.tar.bz2 pam-525a62a643f0bf18b12643dd4e8a3dc3d4c63fcd.zip |
pam_unix: simplify save_old_password
The combination of snprintf and fputs is not needed. It is possible to
call fprintf directly. The previously ignored return value of snprintf
is covered this way as well.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Diffstat (limited to 'modules/pam_unix/passverify.c')
-rw-r--r-- | modules/pam_unix/passverify.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/modules/pam_unix/passverify.c b/modules/pam_unix/passverify.c index 366f244c..d5155b4c 100644 --- a/modules/pam_unix/passverify.c +++ b/modules/pam_unix/passverify.c @@ -647,7 +647,6 @@ save_old_password(pam_handle_t *pamh, const char *forwho, const char *oldpass, #endif { static char buf[16384]; - static char nbuf[16384]; char *s_luser, *s_uid, *s_npas, *s_pas, *pass; int npas; FILE *pwfile, *opwfile; @@ -760,16 +759,14 @@ save_old_password(pam_handle_t *pamh, const char *forwho, const char *oldpass, } pass = crypt_md5_wrapper(oldpass); if (s_pas == NULL) - snprintf(nbuf, sizeof(nbuf), "%s:%s:%d:%s\n", - s_luser, s_uid, npas, pass); + err = fprintf(pwfile, "%s:%s:%d:%s\n", + s_luser, s_uid, npas, pass) < 0; else - snprintf(nbuf, sizeof(nbuf),"%s:%s:%d:%s,%s\n", - s_luser, s_uid, npas, s_pas, pass); + err = fprintf(pwfile, "%s:%s:%d:%s,%s\n", + s_luser, s_uid, npas, s_pas, pass) < 0; _pam_delete(pass); - if (fputs(nbuf, pwfile) < 0) { - err = 1; + if (err) break; - } } else if (fputs(buf, pwfile) < 0) { err = 1; break; @@ -783,12 +780,9 @@ save_old_password(pam_handle_t *pamh, const char *forwho, const char *oldpass, err = 1; } else { pass = crypt_md5_wrapper(oldpass); - snprintf(nbuf, sizeof(nbuf), "%s:%lu:1:%s\n", - forwho, (unsigned long)pwd->pw_uid, pass); + err = fprintf(pwfile, "%s:%lu:1:%s\n", + forwho, (unsigned long)pwd->pw_uid, pass) < 0; _pam_delete(pass); - if (fputs(nbuf, pwfile) < 0) { - err = 1; - } } } |