]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
newgrp: use libc function to read gshadow if it is available
authorSami Kerola <kerolasa@iki.fi>
Sun, 14 Sep 2014 16:29:54 +0000 (17:29 +0100)
committerSami Kerola <kerolasa@iki.fi>
Fri, 19 Sep 2014 18:31:02 +0000 (19:31 +0100)
The glib versionf of getsgnam() is using /etc/nsswitch.conf, allowing the
group passwords to come from external database.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
configure.ac
login-utils/newgrp.c

index 387372fd9efeb695b667b714407361dff73fbf03..8cf17cc118b14f6f91e1f2d627b69e57578b8c09 100644 (file)
@@ -310,6 +310,7 @@ AC_CHECK_FUNCS([ \
        getexecname \
        getmntinfo \
        getrlimit \
+       getsgnam \
        inotify_init \
        inotify_init1 \
        jrand48 \
index 55dad1bb44eada9705c97c30645d2b821c3c3743..d492f23ffea690e138cb22794c911b788961dd49 100644 (file)
 # include <crypt.h>
 #endif
 
+#ifdef HAVE_GETSGNAM
+# include <gshadow.h>
+#endif
+
 #include "c.h"
 #include "closestream.h"
 #include "nls.h"
 /* try to read password from gshadow */
 static char *get_gshadow_pwd(char *groupname)
 {
+#ifdef HAVE_GETSGNAM
+       struct sgrp *sgrp;
+
+       sgrp = getsgnam(groupname);
+       return sgrp ? xstrdup(sgrp->sg_passwd) : NULL;
+#else
        char buf[BUFSIZ];
        char *pwd = NULL;
        FILE *f;
@@ -69,6 +79,7 @@ static char *get_gshadow_pwd(char *groupname)
        }
        fclose(f);
        return pwd ? xstrdup(pwd) : NULL;
+#endif /* HAVE_GETSGNAM */
 }
 
 static int allow_setgid(struct passwd *pe, struct group *ge)