summaryrefslogtreecommitdiffstats
path: root/login-utils/newgrp.c
diff options
context:
space:
mode:
authorSami Kerola2014-09-14 18:29:54 +0200
committerSami Kerola2014-09-19 20:31:02 +0200
commitc829aebc397f75f24762ed046fc8e3402762b60f (patch)
treea5b0280dc53c0303e5b39692abc54ef5b1383ea6 /login-utils/newgrp.c
parentsetarch: use personality() system call when it is available (diff)
downloadkernel-qcow2-util-linux-c829aebc397f75f24762ed046fc8e3402762b60f.tar.gz
kernel-qcow2-util-linux-c829aebc397f75f24762ed046fc8e3402762b60f.tar.xz
kernel-qcow2-util-linux-c829aebc397f75f24762ed046fc8e3402762b60f.zip
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 <kerolasa@iki.fi>
Diffstat (limited to 'login-utils/newgrp.c')
-rw-r--r--login-utils/newgrp.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/login-utils/newgrp.c b/login-utils/newgrp.c
index 55dad1bb4..d492f23ff 100644
--- a/login-utils/newgrp.c
+++ b/login-utils/newgrp.c
@@ -28,6 +28,10 @@
# include <crypt.h>
#endif
+#ifdef HAVE_GETSGNAM
+# include <gshadow.h>
+#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)