From: Alejandro Colomar Date: Wed, 3 Jul 2024 21:41:16 +0000 (+0200) Subject: src/suauth.c: check_su_auth(): Use stpsep() to simplify X-Git-Tag: 4.17.0-rc1~127 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8714ac0cd6c9d18770c14d76d3daa2f2a87513db;p=thirdparty%2Fshadow.git src/suauth.c: check_su_auth(): Use stpsep() to simplify Signed-off-by: Alejandro Colomar --- diff --git a/src/suauth.c b/src/suauth.c index ac9af264f..9def76c0e 100644 --- a/src/suauth.c +++ b/src/suauth.c @@ -13,11 +13,13 @@ #include #include #include +#include #include #include "defines.h" #include "prototypes.h" #include "string/strchr/strrspn.h" +#include "string/strtok/stpsep.h" #ifndef SUAUTHFILE @@ -45,7 +47,7 @@ int check_su_auth (const char *actual_id, const char *wanted_id, bool su_to_root) { - int posn, endline; + int posn; const char field[] = ":"; FILE *authfile_fd; char temp[1024]; @@ -72,23 +74,21 @@ int check_su_auth (const char *actual_id, while (fgets (temp, sizeof (temp), authfile_fd) != NULL) { lines++; - endline = strlen(temp) - 1; - if (temp[0] == '\0' || temp[endline] != '\n') { + if (stpsep(temp, "\n") == NULL) { SYSLOG ((LOG_ERR, "%s, line %d: line too long or missing newline", SUAUTHFILE, lines)); continue; } - stpcpy(strrspn(temp, " \t\n"), ""); + stpcpy(strrspn(temp, " \t"), ""); posn = 0; while (temp[posn] == ' ' || temp[posn] == '\t') posn++; - if (temp[posn] == '\n' || temp[posn] == '#' - || temp[posn] == '\0') { + if (temp[posn] == '#' || temp[posn] == '\0') { continue; } if (!(to_users = strtok (temp + posn, field))