diff options
author | Tobias Stoeckmann <tobias@stoeckmann.org> | 2024-01-11 23:21:54 +0100 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2024-01-12 17:01:04 +0000 |
commit | d9494352c571d332cf92bdadcd898894f0af12df (patch) | |
tree | ef1b99c51a3b7d3f8fdcb87803fe957f95a7dafc /modules | |
parent | cf80332ddb98c109c5abc35c74d6dd371ca7fa5b (diff) | |
download | pam-d9494352c571d332cf92bdadcd898894f0af12df.tar.gz pam-d9494352c571d332cf92bdadcd898894f0af12df.tar.bz2 pam-d9494352c571d332cf92bdadcd898894f0af12df.zip |
modules: simplify newline removal
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/pam_exec/pam_exec.c | 5 | ||||
-rw-r--r-- | modules/pam_pwhistory/opasswd.c | 6 | ||||
-rw-r--r-- | modules/pam_securetty/pam_securetty.c | 11 |
3 files changed, 5 insertions, 17 deletions
diff --git a/modules/pam_exec/pam_exec.c b/modules/pam_exec/pam_exec.c index 653fe3aa..5468e179 100644 --- a/modules/pam_exec/pam_exec.c +++ b/modules/pam_exec/pam_exec.c @@ -273,10 +273,7 @@ call_exec (const char *pam_type, pam_handle_t *pamh, close(stdout_fds[1]); while (getline(&buf, &n, stdout_file) != -1) { - size_t len; - len = strlen(buf); - if (len > 0 && buf[len-1] == '\n') - buf[len-1] = '\0'; + buf[strcspn(buf, "\n")] = '\0'; pam_info(pamh, "%s", buf); } free(buf); diff --git a/modules/pam_pwhistory/opasswd.c b/modules/pam_pwhistory/opasswd.c index f1f62aaf..58b386bd 100644 --- a/modules/pam_pwhistory/opasswd.c +++ b/modules/pam_pwhistory/opasswd.c @@ -188,8 +188,7 @@ check_old_pass, const char *user, const char *newpass, const char *filename, int if (*cp == '\0') /* ignore empty lines */ continue; - if (cp[strlen (cp) - 1] == '\n') - cp[strlen (cp) - 1] = '\0'; + cp[strcspn(cp, "\n")] = '\0'; if (strncmp (cp, user, strlen (user)) == 0 && cp[strlen (user)] == ':') @@ -387,8 +386,7 @@ save_old_pass, const char *user, int howmany, const char *filename, int debug UN if (*cp == '\0') /* ignore empty lines */ goto write_old_data; - if (cp[strlen (cp) - 1] == '\n') - cp[strlen (cp) - 1] = '\0'; + cp[strcspn(cp, "\n")] = '\0'; if (strncmp (cp, user, strlen (user)) == 0 && cp[strlen (user)] == ':') diff --git a/modules/pam_securetty/pam_securetty.c b/modules/pam_securetty/pam_securetty.c index f60cf32a..617af679 100644 --- a/modules/pam_securetty/pam_securetty.c +++ b/modules/pam_securetty/pam_securetty.c @@ -159,10 +159,7 @@ securetty_perform_check (pam_handle_t *pamh, int ctrl, while ((getline(&ttyfileline, &ttyfilelinelen, ttyfile) != -1) && retval) { - size_t len; - len = strlen(ttyfileline); - if (len > 0 && ttyfileline[len - 1] == '\n') - ttyfileline[len - 1] = '\0'; + ttyfileline[strcspn(ttyfileline, "\n")] = '\0'; retval = ( strcmp(ttyfileline, uttyname) && (!ptname[0] || strcmp(ptname, uttyname)) ); @@ -226,12 +223,8 @@ securetty_perform_check (pam_handle_t *pamh, int ctrl, fclose(consoleactivefile); if (p) { - size_t len; - /* remove the newline character at end */ - len = strlen(line); - if (len && line[len-1] == '\n') - line[len-1] = 0; + line[strcspn(line, "\n")] = '\0'; for (n = p; n != NULL; p = n+1) { if ((n = strchr(p, ' ')) != NULL) |