From 71f41209946e99386f2adeb93d1e0d6c5e48b23e Mon Sep 17 00:00:00 2001 From: Geoffrey Thomas Date: Thu, 7 Oct 2021 17:14:21 -0400 Subject: [PATCH] Add failing test for nix-rust/nix#1541 --- ci/libnss_whatami.c | 28 ++++++++++++++++++++++++++++ ci/test.sh | 3 ++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ci/libnss_whatami.c b/ci/libnss_whatami.c index 47b312c..57ced1b 100644 --- a/ci/libnss_whatami.c +++ b/ci/libnss_whatami.c @@ -20,6 +20,7 @@ #include #include #include +#include enum nss_status _nss_whatami_getpwnam_r(const char *name, struct passwd *result, char *buffer, size_t buflen, int *errnop) @@ -42,3 +43,30 @@ _nss_whatami_getpwnam_r(const char *name, struct passwd *result, char *buffer, s return NSS_STATUS_NOTFOUND; } } + +enum nss_status +_nss_whatami_initgroups_dyn(const char *user, gid_t group, long int *start, long int *size, gid_t **groups, long int limit, int *errnop) +{ + if (strcmp(user, "whatami") == 0) { + if (*size - *start < 20) { + if (limit > 0 && *size + 20 > limit) { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } + gid_t *newgroups = realloc(*groups, (*size + 20) * sizeof(**groups)); + if (newgroups == NULL) { + *errnop = ENOMEM; + return NSS_STATUS_TRYAGAIN; + } + *groups = newgroups; + *size += 20; + } + + for (int i = 0; i < 20; i++) { + (*groups)[*start + i] = 100001 + i; + } + *start += 20; + } + + return NSS_STATUS_SUCCESS; +} diff --git a/ci/test.sh b/ci/test.sh index fc17079..1caa6c0 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -20,6 +20,7 @@ debian/rules vendor dpkg-buildpackage --no-sign gcc -fPIC -shared -o ci/libnss_whatami.so.2 ci/libnss_whatami.c sudo cp ci/libnss_whatami.so.2 /lib -sudo sed -i 's/passwd:/& whatami/' /etc/nsswitch.conf +sudo sed -i 's/\(passwd\|group\):/& whatami/' /etc/nsswitch.conf sudo dpkg -i ../nsncd*.deb getent passwd whatami | grep nsncd +getent initgroups whatami | grep '100001.*100020'