]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/suauth.c: check_su_auth(): Use stpsep() to simplify
authorAlejandro Colomar <alx@kernel.org>
Wed, 3 Jul 2024 21:41:16 +0000 (23:41 +0200)
committerSerge Hallyn <serge@hallyn.com>
Tue, 9 Jul 2024 01:25:01 +0000 (20:25 -0500)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/suauth.c

index ac9af264f539d720d9d601db9e8f39270996ef6a..9def76c0ed049726c5b8285447fc174145614ee4 100644 (file)
 #include <grp.h>
 #include <pwd.h>
 #include <stdio.h>
+#include <string.h>
 #include <sys/types.h>
 
 #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))