]> andersk Git - nss_nonlocal.git/blobdiff - nonlocal-group.c
Document nss-nonlocal-users and nss-local-users
[nss_nonlocal.git] / nonlocal-group.c
index 09fa6f205d057fbc824839e7d1f0cf48a0ab87d1..e93a3a25de8225cc584b4dbf9364f5a93e4b28cd 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.
+ */
 #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"
 
 
@@ -325,7 +334,7 @@ _nss_nonlocal_initgroups_dyn(const char *user, gid_t group, long int *start,
     const __typeof__(&_nss_nonlocal_initgroups_dyn) self = NULL;
 
     struct group local_users_group, nonlocal_users_group;
-    int is_local = 0;
+    bool is_nonlocal = true;
     char *buffer;
     int in, out, i;
 
@@ -334,7 +343,7 @@ _nss_nonlocal_initgroups_dyn(const char *user, gid_t group, long int *start,
     if (status == NSS_STATUS_TRYAGAIN) {
        return status;
     } else if (status != NSS_STATUS_SUCCESS) {
-       is_local = 1;
+       is_nonlocal = false;
 
        status = get_local_group(MAGIC_LOCAL_GROUPNAME,
                                 &local_users_group, &buffer, errnop);
@@ -350,23 +359,26 @@ _nss_nonlocal_initgroups_dyn(const char *user, gid_t group, long int *start,
                   "nss_nonlocal: Group %s does not exist locally!",
                   MAGIC_LOCAL_GROUPNAME);
        }
-    } else {
-       status = get_local_group(MAGIC_NONLOCAL_GROUPNAME,
-                                &nonlocal_users_group, &buffer, errnop);
-       if (status == NSS_STATUS_SUCCESS) {
-           free(buffer);
+    }
+
+    status = get_local_group(MAGIC_NONLOCAL_GROUPNAME,
+                            &nonlocal_users_group, &buffer, errnop);
+    if (status == NSS_STATUS_SUCCESS) {
+       free(buffer);
+       if (is_nonlocal) {
            if (!add_group(nonlocal_users_group.gr_gid, start, size, groupsp,
                           limit, errnop, &status))
                return status;
-       } else if (status == NSS_STATUS_TRYAGAIN) {
-           return status;
-       } else {
-           syslog(LOG_WARNING, "nss_nonlocal: Group %s does not exist locally!",
-                  MAGIC_NONLOCAL_GROUPNAME);
        }
+    } else if (status == NSS_STATUS_TRYAGAIN) {
+       if (is_nonlocal)
+           return status;
+    } else {
+       syslog(LOG_WARNING, "nss_nonlocal: Group %s does not exist locally!",
+              MAGIC_NONLOCAL_GROUPNAME);
     }
 
-    if (is_local)
+    if (!is_nonlocal)
        return NSS_STATUS_SUCCESS;
 
     in = out = *start;
This page took 0.0612819999999999 seconds and 4 git commands to generate.