user-util: sysconf_ngroups_max
This hides the iffy interface of sysconf(_SC_NGROUPS_MAX) to simplify the calllers.
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
#include "strv.h"
|
||||
#include "sysctl-util.h"
|
||||
#include "tmpfile-util.h"
|
||||
#include "user-util.h"
|
||||
#include "xattr-util.h"
|
||||
|
||||
#if ENABLE_IDN
|
||||
@@ -914,7 +915,7 @@ int getpeergroups(int fd, gid_t **ret) {
|
||||
assert(fd >= 0);
|
||||
assert(ret);
|
||||
|
||||
long ngroups_max = sysconf(_SC_NGROUPS_MAX);
|
||||
int ngroups_max = sysconf_ngroups_max();
|
||||
if (ngroups_max > 0)
|
||||
n = MAX(n, sizeof(gid_t) * (socklen_t) ngroups_max);
|
||||
|
||||
|
||||
@@ -1353,6 +1353,19 @@ int lookup_grent_in_files(
|
||||
return -ESRCH;
|
||||
}
|
||||
|
||||
int sysconf_ngroups_max(void) {
|
||||
/* Query sysconf _SC_NGROUPS_MAX. Returns an int because the expected value is 64k
|
||||
* and later on this is used as an int with various glibc consumers. */
|
||||
|
||||
errno = 0;
|
||||
long ngroups_max = sysconf(_SC_NGROUPS_MAX);
|
||||
if (ngroups_max <= 0)
|
||||
return errno_or_else(EOPNOTSUPP);
|
||||
if (ngroups_max > INT_MAX)
|
||||
return -ERANGE;
|
||||
return ngroups_max;
|
||||
}
|
||||
|
||||
static size_t getgr_buffer_size(void) {
|
||||
long bufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
|
||||
return bufsize <= 0 ? 4096U : (size_t) bufsize;
|
||||
|
||||
@@ -173,6 +173,8 @@ static inline bool hashed_password_is_locked_or_invalid(const char *password) {
|
||||
*/
|
||||
#define PASSWORD_UNPROVISIONED "!unprovisioned"
|
||||
|
||||
int sysconf_ngroups_max(void);
|
||||
|
||||
int lookup_pwent_in_files(
|
||||
char * const *files,
|
||||
const char *name,
|
||||
|
||||
Reference in New Issue
Block a user