From: Sami Kerola Date: Sun, 14 Sep 2014 16:29:54 +0000 (+0100) Subject: newgrp: use libc function to read gshadow if it is available X-Git-Tag: v2.26-rc1~447^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c829aebc397f75f24762ed046fc8e3402762b60f;p=thirdparty%2Futil-linux.git newgrp: use libc function to read gshadow if it is available The glib versionf of getsgnam() is using /etc/nsswitch.conf, allowing the group passwords to come from external database. Signed-off-by: Sami Kerola --- diff --git a/configure.ac b/configure.ac index 387372fd9e..8cf17cc118 100644 --- a/configure.ac +++ b/configure.ac @@ -310,6 +310,7 @@ AC_CHECK_FUNCS([ \ getexecname \ getmntinfo \ getrlimit \ + getsgnam \ inotify_init \ inotify_init1 \ jrand48 \ diff --git a/login-utils/newgrp.c b/login-utils/newgrp.c index 55dad1bb44..d492f23ffe 100644 --- a/login-utils/newgrp.c +++ b/login-utils/newgrp.c @@ -28,6 +28,10 @@ # include #endif +#ifdef HAVE_GETSGNAM +# include +#endif + #include "c.h" #include "closestream.h" #include "nls.h" @@ -37,6 +41,12 @@ /* 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)