]> andersk Git - nss_nonlocal.git/commitdiff
Add the primary nonlocal gid to local users in MAGIC_NONLOCAL_GROUPNAME
authorAnders Kaseorg <andersk@mit.edu>
Sat, 26 Jun 2010 22:47:45 +0000 (18:47 -0400)
committerAnders Kaseorg <andersk@mit.edu>
Wed, 30 Mar 2011 08:56:27 +0000 (04:56 -0400)
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
README
nonlocal-group.c
nonlocal-passwd.c
nonlocal.h

diff --git a/README b/README
index 7125dc18103fdc5b836bfcc8b945af960cb176dd..6dc464b02ff67a569f791895af36a1c7265396d0 100644 (file)
--- a/README
+++ b/README
@@ -14,8 +14,8 @@ they exist:
 
 • If the local group ‘nss-nonlocal-users’ 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.
+  added to this group, then that user will inherit any nonlocal gids
+  from a nonlocal user of the same name, as supplementary gids.
 
 • If the local group ‘nss-local-users’ exists, then local users will
   be automatically added to it.
index aa9c588a9342073bf6bf337f8d769594ff3eb8b4..8ceeb237ddac4830b442516fe55025e1e52955a0 100644 (file)
@@ -33,6 +33,7 @@
 #include <stdio.h>
 #include <syslog.h>
 #include <errno.h>
+#include <pwd.h>
 #include <grp.h>
 #include <nss.h>
 #include "nsswitch-internal.h"
@@ -42,7 +43,8 @@
  * 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.
+ * nonlocal gids from a nonlocal user of the same name, as
+ * supplementary gids.
  */
 #define MAGIC_NONLOCAL_GROUPNAME "nss-nonlocal-users"
 
@@ -380,6 +382,29 @@ _nss_nonlocal_initgroups_dyn(const char *user, gid_t group, long int *start,
                    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)
index 052af95e0a498f1686255ec268ef878b8340dfee..a401c49320e95c3c5b9a7cb2333ff109cf8dcd62 100644 (file)
@@ -143,6 +143,23 @@ check_nonlocal_user(const char *user, int *errnop)
     return status;
 }
 
+enum nss_status
+get_nonlocal_passwd(const char *name, struct passwd *pwd, char **buffer,
+                   int *errnop)
+{
+    enum nss_status status;
+    size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
+    const struct walk_nss w = {
+       .lookup = __nss_passwd_nonlocal_lookup, .fct_name = "getpwnam_r",
+       .status = &status, .errnop = errnop, .buf = buffer, .buflen = &buflen
+    };
+    const __typeof__(&_nss_nonlocal_getpwnam_r) self = NULL;
+#define args (name, pwd, *buffer, buflen, errnop)
+#include "walk_nss.h"
+#undef args
+    return status;
+}
+
 
 static service_user *pwent_startp, *pwent_nip;
 static void *pwent_fct_start;
index b31a9a93ef09b50de38372dca7639e66c8e5372d..da9294c7d8471d39cdfed478dc3dabf4150b782f 100644 (file)
@@ -45,6 +45,7 @@ typedef bool _Bool;
 #endif
 
 #include "nsswitch-internal.h"
+#include <pwd.h>
 
 struct walk_nss {
     enum nss_status *status;
@@ -59,6 +60,8 @@ struct walk_nss {
 enum nss_status check_nonlocal_uid(const char *user, uid_t uid, int *errnop);
 enum nss_status check_nonlocal_gid(const char *user, gid_t gid, int *errnop);
 enum nss_status check_nonlocal_user(const char *user, int *errnop);
+enum nss_status get_nonlocal_passwd(const char *name, struct passwd *pwd,
+                                   char **buffer, int *errnop);
 
 #define NONLOCAL_IGNORE_ENV "NSS_NONLOCAL_IGNORE"
 
This page took 0.751596 seconds and 5 git commands to generate.