diff options
author | Tobias Stoeckmann <tobias@stoeckmann.org> | 2024-01-15 22:43:32 +0100 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2024-01-16 08:00:00 +0000 |
commit | 584071ef780ad7f4dc7674183f45c0f1641baa80 (patch) | |
tree | 5b2798ed689252ea40bcbd97301d0ff439f27bcf /modules/pam_pwhistory | |
parent | c25a858bb548b4eb881dabbf10aed4a08b11e973 (diff) | |
download | pam-584071ef780ad7f4dc7674183f45c0f1641baa80.tar.gz pam-584071ef780ad7f4dc7674183f45c0f1641baa80.tar.bz2 pam-584071ef780ad7f4dc7674183f45c0f1641baa80.zip |
pam_pwhistory: parse opasswd lines verbatim
Users may have a hash character in their name, which would be removed.
This in turn effectively defeats the purpose of pam_pwhistory for the
user.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Diffstat (limited to 'modules/pam_pwhistory')
-rw-r--r-- | modules/pam_pwhistory/opasswd.c | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/modules/pam_pwhistory/opasswd.c b/modules/pam_pwhistory/opasswd.c index 165cf5df..4541d658 100644 --- a/modules/pam_pwhistory/opasswd.c +++ b/modules/pam_pwhistory/opasswd.c @@ -169,7 +169,7 @@ check_old_pass, const char *user, const char *newpass, const char *filename, int while (!feof (oldpf)) { - char *cp, *tmp; + char *cp; ssize_t n = getline (&buf, &buflen, oldpf); cp = buf; @@ -177,16 +177,10 @@ check_old_pass, const char *user, const char *newpass, const char *filename, int if (n < 1) break; - tmp = strchr (cp, '#'); /* remove comments */ - if (tmp) - *tmp = '\0'; - while (isspace ((unsigned char)*cp)) /* remove spaces and tabs */ - ++cp; + cp[strcspn(cp, "\n")] = '\0'; if (*cp == '\0') /* ignore empty lines */ continue; - cp[strcspn(cp, "\n")] = '\0'; - if (strncmp (cp, user, strlen (user)) == 0 && cp[strlen (user)] == ':') { @@ -359,7 +353,7 @@ save_old_pass, const char *user, int howmany, const char *filename, int debug UN if (!do_create) while (!feof (oldpf)) { - char *cp, *tmp, *save; + char *cp, *save; ssize_t n = getline (&buf, &buflen, oldpf); if (n < 1) @@ -375,16 +369,10 @@ save_old_pass, const char *user, int howmany, const char *filename, int debug UN goto error_opasswd; } - tmp = strchr (cp, '#'); /* remove comments */ - if (tmp) - *tmp = '\0'; - while (isspace ((unsigned char)*cp)) /* remove spaces and tabs */ - ++cp; + cp[strcspn(cp, "\n")] = '\0'; if (*cp == '\0') /* ignore empty lines */ goto write_old_data; - cp[strcspn(cp, "\n")] = '\0'; - if (strncmp (cp, user, strlen (user)) == 0 && cp[strlen (user)] == ':') { |