Skip to content

Commit

Permalink
core: change uv_get_password uid/gid to unsigned (#3476)
Browse files Browse the repository at this point in the history
Added in #742, these values are
typically defined as unsigned (since Linux 2.4). Only -1 is special,
representing an invalid id (e.g. see setreuid).
  • Loading branch information
vtjnash committed Feb 22, 2022
1 parent c2a345f commit f3e0bff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/uv.h
Expand Up @@ -1133,8 +1133,8 @@ struct uv_interface_address_s {

struct uv_passwd_s {
char* username;
long uid;
long gid;
unsigned long uid;
unsigned long gid;
char* shell;
char* homedir;
};
Expand Down
16 changes: 12 additions & 4 deletions test/test-get-passwd.c
Expand Up @@ -22,6 +22,10 @@
#include "uv.h"
#include "task.h"
#include <string.h>
#ifndef _WIN32
#include <unistd.h>
#include <sys/types.h>
#endif

TEST_IMPL(get_passwd) {
/* TODO(gengjiawen): Fix test on QEMU. */
Expand Down Expand Up @@ -64,11 +68,15 @@ TEST_IMPL(get_passwd) {
#endif

#ifdef _WIN32
ASSERT(pwd.uid == -1);
ASSERT(pwd.gid == -1);
ASSERT_EQ(pwd.uid, (unsigned)-1);
ASSERT_EQ(pwd.gid, (unsigned)-1);
#else
ASSERT(pwd.uid >= 0);
ASSERT(pwd.gid >= 0);
ASSERT_NE(pwd.uid, (unsigned)-1);
ASSERT_NE(pwd.gid, (unsigned)-1);
ASSERT_EQ(pwd.uid, geteuid());
if (pwd.uid != 0 && pwd.gid != getgid())
/* This will be likely true, as only root could have changed it. */
ASSERT_EQ(pwd.gid, getegid());
#endif

/* Test uv_os_free_passwd() */
Expand Down

0 comments on commit f3e0bff

Please sign in to comment.