Skip to content

Commit

Permalink
Add failing test for nix-rust/nix#1541
Browse files Browse the repository at this point in the history
  • Loading branch information
geofft committed Oct 7, 2021
1 parent f39f02a commit 71f4120
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions ci/libnss_whatami.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <nss.h>
#include <pwd.h>
#include <string.h>
#include <stdlib.h>

enum nss_status
_nss_whatami_getpwnam_r(const char *name, struct passwd *result, char *buffer, size_t buflen, int *errnop)
Expand All @@ -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;
}
3 changes: 2 additions & 1 deletion ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 71f4120

Please sign in to comment.