X-Git-Url: http://andersk.mit.edu/gitweb/nss_nonlocal.git/blobdiff_plain/6ca16423b9b7ddcb37b86eac892e58e73ce7a14c..775f7dc3865d6ddfa74d88e77c132f78e0667ac9:/nonlocal-group.c diff --git a/nonlocal-group.c b/nonlocal-group.c index e93a3a2..8ceeb23 100644 --- a/nonlocal-group.c +++ b/nonlocal-group.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include "nsswitch-internal.h" @@ -40,7 +41,10 @@ /* * If the MAGIC_NONLOCAL_GROUPNAME local group exists, then nonlocal - * users will be automatically added to it. + * users will be automatically added to it. Furthermore, if a local + * user is added to this group, then that user will inherit any + * nonlocal gids from a nonlocal user of the same name, as + * supplementary gids. */ #define MAGIC_NONLOCAL_GROUPNAME "nss-nonlocal-users" @@ -338,7 +342,8 @@ _nss_nonlocal_initgroups_dyn(const char *user, gid_t group, long int *start, char *buffer; int in, out, i; - /* Check that the user is a nonlocal user before adding any groups. */ + /* Check that the user is a nonlocal user, or a member of the + * MAGIC_NONLOCAL_GROUPNAME group, before adding any groups. */ status = check_nonlocal_user(user, errnop); if (status == NSS_STATUS_TRYAGAIN) { return status; @@ -369,6 +374,37 @@ _nss_nonlocal_initgroups_dyn(const char *user, gid_t group, long int *start, if (!add_group(nonlocal_users_group.gr_gid, start, size, groupsp, limit, errnop, &status)) return status; + } else { + int i; + for (i = 0; i < *start; ++i) { + if ((*groupsp)[i] == nonlocal_users_group.gr_gid) { + is_nonlocal = true; + break; + } + } + + if (is_nonlocal) { + struct passwd pwbuf; + char *buf; + int nonlocal_errno = *errnop; + status = get_nonlocal_passwd(user, &pwbuf, &buf, errnop); + + if (status == NSS_STATUS_SUCCESS) { + nonlocal_errno = *errnop; + status = check_nonlocal_gid(user, pwbuf.pw_gid, + &nonlocal_errno); + free(buf); + } + + if (status == NSS_STATUS_SUCCESS) { + if (!add_group(pwbuf.pw_gid, start, size, groupsp, limit, + errnop, &status)) + return status; + } else if (status == NSS_STATUS_TRYAGAIN) { + *errnop = nonlocal_errno; + return status; + } + } } } else if (status == NSS_STATUS_TRYAGAIN) { if (is_nonlocal)