summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pw/grupd.c
diff options
context:
space:
mode:
authordavidn <davidn@FreeBSD.org>1999-02-23 07:15:11 +0000
committerdavidn <davidn@FreeBSD.org>1999-02-23 07:15:11 +0000
commitaea1f6bc3cb4963dbd48dcd9f051919520f70f2b (patch)
treeb3bd7501edb165799eda61bf2ac5d8202c789a5d /usr.sbin/pw/grupd.c
parentf6416f79a6b9a2eb5c485e8af421d3d570a95d25 (diff)
downloadFreeBSD-src-aea1f6bc3cb4963dbd48dcd9f051919520f70f2b.zip
FreeBSD-src-aea1f6bc3cb4963dbd48dcd9f051919520f70f2b.tar.gz
1) Do not blindly ignore file update errors which may occur due to concurrent
updating 2) Add -V <etcdir>, which allows maintaining user/group database in alternate locations other than /etc.
Diffstat (limited to 'usr.sbin/pw/grupd.c')
-rw-r--r--usr.sbin/pw/grupd.c47
1 files changed, 43 insertions, 4 deletions
diff --git a/usr.sbin/pw/grupd.c b/usr.sbin/pw/grupd.c
index feff430..e36c192 100644
--- a/usr.sbin/pw/grupd.c
+++ b/usr.sbin/pw/grupd.c
@@ -26,7 +26,7 @@
#ifndef lint
static const char rcsid[] =
- "$Id$";
+ "$Id: grupd.c,v 1.5 1997/10/10 06:23:32 charnier Exp $";
#endif /* not lint */
#include <stdio.h>
@@ -36,9 +36,46 @@ static const char rcsid[] =
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/param.h>
#include "pwupd.h"
+static char * grpath = _PATH_PWD;
+
+int
+setgrdir(const char * dir)
+{
+ if (dir == NULL)
+ return -1;
+ else {
+ char * d = malloc(strlen(dir)+1);
+ if (d == NULL)
+ return -1;
+ grpath = strcpy(d, dir);
+ }
+ return 0;
+}
+
+char *
+getgrpath(const char * file)
+{
+ static char pathbuf[MAXPATHLEN];
+
+ snprintf(pathbuf, sizeof pathbuf, "%s/%s", grpath, file);
+ return pathbuf;
+}
+
+int
+grdb(char *arg,...)
+{
+ /*
+ * This is a stub for now, but maybe eventually be functional
+ * if ever an indexed version of /etc/groups is implemented.
+ */
+ arg=arg;
+ return 0;
+}
+
int
fmtgrentry(char **buf, int * buflen, struct group * grp, int type)
{
@@ -96,7 +133,7 @@ gr_update(struct group * grp, char const * group, int mode)
int grbuflen = 0;
char *grbuf = NULL;
- endgrent();
+ ENDGRENT();
l = snprintf(pfx, sizeof pfx, "%s:", group);
/*
@@ -104,8 +141,10 @@ gr_update(struct group * grp, char const * group, int mode)
*/
if (grp != NULL && fmtgrentry(&grbuf, &grbuflen, grp, PWF_PASSWD) == -1)
l = -1;
- else
- l = fileupdate(_PATH_GROUP, 0644, grbuf, pfx, l, mode);
+ else {
+ if ((l = fileupdate(getgrpath(_GROUP), 0644, grbuf, pfx, l, mode)) != 0)
+ l = grdb(NULL) == 0;
+ }
if (grbuf != NULL)
free(grbuf);
return l;
OpenPOWER on IntegriCloud