diff options
author | Tobias Stoeckmann <tobias@stoeckmann.org> | 2024-01-15 23:12:54 +0100 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2024-01-16 08:00:00 +0000 |
commit | eab35ab04fae5f987260184563fcef75e206c7e3 (patch) | |
tree | 30748844a7107e695c55f01cf1ccf675035011ca /modules | |
parent | 584071ef780ad7f4dc7674183f45c0f1641baa80 (diff) | |
download | pam-eab35ab04fae5f987260184563fcef75e206c7e3.tar.gz pam-eab35ab04fae5f987260184563fcef75e206c7e3.tar.bz2 pam-eab35ab04fae5f987260184563fcef75e206c7e3.zip |
pam_pwhistory: use cp variable only when needed
Removes its usage from check_old_pass and reduces its
visibility in save_old_pass.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/pam_pwhistory/opasswd.c | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/modules/pam_pwhistory/opasswd.c b/modules/pam_pwhistory/opasswd.c index 4541d658..b7711e03 100644 --- a/modules/pam_pwhistory/opasswd.c +++ b/modules/pam_pwhistory/opasswd.c @@ -169,23 +169,20 @@ check_old_pass, const char *user, const char *newpass, const char *filename, int while (!feof (oldpf)) { - char *cp; ssize_t n = getline (&buf, &buflen, oldpf); - cp = buf; - if (n < 1) break; - cp[strcspn(cp, "\n")] = '\0'; - if (*cp == '\0') /* ignore empty lines */ + buf[strcspn(buf, "\n")] = '\0'; + if (buf[0] == '\0') /* ignore empty lines */ continue; - if (strncmp (cp, user, strlen (user)) == 0 && - cp[strlen (user)] == ':') + if (strncmp (buf, user, strlen (user)) == 0 && + buf[strlen (user)] == ':') { /* We found the line we needed */ - if (parse_entry (cp, &entry) == 0) + if (parse_entry (buf, &entry) == 0) { found = 1; break; @@ -353,13 +350,12 @@ save_old_pass, const char *user, int howmany, const char *filename, int debug UN if (!do_create) while (!feof (oldpf)) { - char *cp, *save; + char *save; ssize_t n = getline (&buf, &buflen, oldpf); if (n < 1) break; - cp = buf; save = strdup (buf); /* Copy to write the original data back. */ if (save == NULL) { @@ -369,17 +365,17 @@ save_old_pass, const char *user, int howmany, const char *filename, int debug UN goto error_opasswd; } - cp[strcspn(cp, "\n")] = '\0'; - if (*cp == '\0') /* ignore empty lines */ + buf[strcspn(buf, "\n")] = '\0'; + if (buf[0] == '\0') /* ignore empty lines */ goto write_old_data; - if (strncmp (cp, user, strlen (user)) == 0 && - cp[strlen (user)] == ':') + if (strncmp (buf, user, strlen (user)) == 0 && + buf[strlen (user)] == ':') { /* We found the line we needed */ opwd entry; - if (parse_entry (cp, &entry) == 0) + if (parse_entry (buf, &entry) == 0) { char *out = NULL; @@ -388,9 +384,9 @@ save_old_pass, const char *user, int howmany, const char *filename, int debug UN /* Don't save the current password twice */ if (entry.old_passwords && entry.old_passwords[0] != '\0') { - char *last = entry.old_passwords; + char *cp = entry.old_passwords; + char *last = cp; - cp = entry.old_passwords; entry.count = 1; /* Don't believe the count */ while ((cp = strchr (cp, ',')) != NULL) { |