]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/suauth.c: check_su_auth(): Use pointers to simplify
authorAlejandro Colomar <alx@kernel.org>
Wed, 3 Jul 2024 21:49:04 +0000 (23:49 +0200)
committerSerge Hallyn <serge@hallyn.com>
Mon, 14 Oct 2024 01:40:02 +0000 (20:40 -0500)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/suauth.c

index 895f1278ba834ec8e44c581702fa6c91ca9db37f..cbb33dc8da058372ab600db512fc0030fc4dc5cb 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "defines.h"
 #include "prototypes.h"
+#include "string/strchr/stpspn.h"
 #include "string/strchr/strrspn.h"
 #include "string/strtok/stpsep.h"
 
@@ -47,7 +48,6 @@ int check_su_auth (const char *actual_id,
                    const char *wanted_id,
                    bool su_to_root)
 {
-       int posn;
        const char field[] = ":";
        FILE *authfile_fd;
        char temp[1024];
@@ -73,6 +73,8 @@ int check_su_auth (const char *actual_id,
        }
 
        while (fgets (temp, sizeof (temp), authfile_fd) != NULL) {
+               char  *p;
+
                lines++;
 
                if (stpsep(temp, "\n") == NULL) {
@@ -84,12 +86,11 @@ int check_su_auth (const char *actual_id,
 
                stpcpy(strrspn(temp, " \t"), "");
 
-               posn = strspn(temp, " \t");
-
-               if (temp[posn] == '#' || temp[posn] == '\0') {
+               p = stpspn(temp, " \t");
+               if (*p == '#' || *p == '\0')
                        continue;
-               }
-               if (!(to_users = strtok (temp + posn, field))
+
+               if (!(to_users = strtok(p, field))
                    || !(from_users = strtok (NULL, field))
                    || !(action = strtok (NULL, field))
                    || strtok (NULL, field)) {