]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
test_sigreceive: use ul_getuserpw_str() for user name/UID parsing
authorWanBingjiang <wanbingjiang@webray.com.cn>
Wed, 29 Apr 2026 07:01:23 +0000 (15:01 +0800)
committerWanBingjiang <wanbingjiang@webray.com.cn>
Wed, 29 Apr 2026 07:01:23 +0000 (15:01 +0800)
tests/helpers/test_sigreceive.c

index 8f83e05940c88dd5feab5e68767e98ae00cc6fd1..59a2f5111779a84d86b7eb781f4aedb4de9f6160 100644 (file)
@@ -16,7 +16,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#include "strutils.h"
+#include "pwdutils.h"
 
 #define TEST_SIGRECEIVE_FAILURE 0
 
@@ -63,14 +63,11 @@ int main(int argc, char **argv)
                }
 
        if (user) {
-               struct passwd *pw;
                uid_t uid;
 
-               pw = getpwnam(user);
-               if (pw)
-                       uid = pw->pw_uid;
-               else
-                       uid = strtou32_or_err(user, "failed to parse uid");
+               ul_getuserpw_str(user, &uid);
+               if (uid == (uid_t)-1)
+                       errx(TEST_SIGRECEIVE_FAILURE, "failed to parse uid: %s", user);
                if (setuid(uid) < 0)
                        err(TEST_SIGRECEIVE_FAILURE, "setuid failed");
        }