mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-24 14:22:28 +00:00
parent
97bb5a3a80
commit
40991ec992
3 changed files with 17 additions and 27 deletions
|
@ -25,7 +25,7 @@
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get list of supplementary group IDs
|
* Gets list of supplementary group IDs
|
||||||
*
|
*
|
||||||
* @param size - maximum number of items that can be stored in list
|
* @param size - maximum number of items that can be stored in list
|
||||||
* @param list - buffer to store output gid_t
|
* @param list - buffer to store output gid_t
|
||||||
|
|
|
@ -25,10 +25,16 @@
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set list of supplementary group IDs
|
* Sets list of supplementary group IDs.
|
||||||
*
|
*
|
||||||
* @param size - number of items in list
|
* On recent versions of Linux only, it's possible to say:
|
||||||
* @param list - input set of gid_t to set
|
*
|
||||||
|
* setgroups(0, NULL);
|
||||||
|
*
|
||||||
|
* Which will cause subsequent calls to `EPERM`.
|
||||||
|
*
|
||||||
|
* @param size number of items in list
|
||||||
|
* @param list input set of gid_t to set
|
||||||
* @return -1 w/ EFAULT
|
* @return -1 w/ EFAULT
|
||||||
*/
|
*/
|
||||||
int setgroups(size_t size, const uint32_t list[]) {
|
int setgroups(size_t size, const uint32_t list[]) {
|
||||||
|
|
|
@ -18,30 +18,14 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/errno.h"
|
#include "libc/macros.internal.h"
|
||||||
#include "libc/testlib/testlib.h"
|
#include "libc/testlib/testlib.h"
|
||||||
|
|
||||||
TEST(getgroups, test) {
|
TEST(getgroups, test) {
|
||||||
int rc;
|
int n;
|
||||||
uint32_t res[1000];
|
if (IsWindows()) return;
|
||||||
rc = getgroups(0, NULL);
|
uint32_t G[500];
|
||||||
if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) {
|
EXPECT_GT((n = getgroups(ARRAYLEN(G), G)), 0);
|
||||||
EXPECT_NE(-1, rc);
|
if (getuid()) return; // this needs root
|
||||||
EXPECT_NE(-1, getgroups(sizeof(res) / sizeof(res[0]), res));
|
EXPECT_SYS(0, 0, setgroups(n, G));
|
||||||
} else {
|
|
||||||
EXPECT_EQ(-1, rc);
|
|
||||||
EXPECT_EQ(ENOSYS, errno);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(setgroups, test) {
|
|
||||||
int rc;
|
|
||||||
uint32_t src[5];
|
|
||||||
EXPECT_EQ(-1, setgroups(0, NULL));
|
|
||||||
if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) {
|
|
||||||
EXPECT_EQ(EPERM, errno);
|
|
||||||
EXPECT_EQ(-1, setgroups(sizeof(src) / sizeof(src[0]), src));
|
|
||||||
} else {
|
|
||||||
EXPECT_EQ(ENOSYS, errno);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue