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 8, 2021
1 parent f39f02a commit 4737815
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
34 changes: 33 additions & 1 deletion ci/libnss_whatami.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
#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)
{
if (strcmp(name, "whatami") == 0) {
if (strcmp(name, "whatami") == 0 || strncmp(name, "am_i_", 5) == 0) {
if (buflen < 16) {
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
Expand All @@ -42,3 +43,34 @@ _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)
{
char buffer[21] = "am_i_";
prctl(PR_GET_NAME, buffer + 5);
if (strcmp(user, buffer) != 0) {
return NSS_STATUS_SUCCESS;
}

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;
}
7 changes: 4 additions & 3 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

set -ex

debian/rules vendor
dpkg-buildpackage --no-sign
#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 am_i_nsncd | grep '100001.*100020'

0 comments on commit 4737815

Please sign in to comment.