]> andersk Git - nss_nonlocal.git/blobdiff - nonlocal-group.c
Add supplementary nonlocal gids to local users in MAGIC_NONLOCAL_GROUPNAME
[nss_nonlocal.git] / nonlocal-group.c
index 97ce4a66f62324fd64884f3630613aab6a923e75..aa9c588a9342073bf6bf337f8d769594ff3eb8b4 100644 (file)
 #include "nsswitch-internal.h"
 #include "nonlocal.h"
 
+/*
+ * If the MAGIC_NONLOCAL_GROUPNAME local group exists, then nonlocal
+ * users will be automatically added to it.  Furthermore, if a local
+ * user is added to this group, then that user will inherit any
+ * nonlocal supplementary gids from a nonlocal user of the same name.
+ */
 #define MAGIC_NONLOCAL_GROUPNAME "nss-nonlocal-users"
+
+/*
+ * If the MAGIC_LOCAL_GROUPNAME local group exists, then local users
+ * will be automatically added to it.
+ */
 #define MAGIC_LOCAL_GROUPNAME "nss-local-users"
 
 
@@ -329,7 +340,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;
@@ -360,6 +372,14 @@ _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;
+               }
+           }
        }
     } else if (status == NSS_STATUS_TRYAGAIN) {
        if (is_nonlocal)
This page took 0.105049 seconds and 4 git commands to generate.