aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorNate Williams <nate@FreeBSD.org>1998-08-04 22:31:26 +0000
committerNate Williams <nate@FreeBSD.org>1998-08-04 22:31:26 +0000
commit5e91a8ac91d5bebdc04ba523badf92ec7a38b1ab (patch)
tree9d843266fce5976f3f3d574cefe7c3f63d630b31 /usr.sbin
parent2a6797aae26ec29978f70d796a703e7da89457dd (diff)
downloadsrc-5e91a8ac91d5bebdc04ba523badf92ec7a38b1ab.tar.gz
src-5e91a8ac91d5bebdc04ba523badf92ec7a38b1ab.zip
- On second thought, attempt to get the read-only lock, but don't
consider it a exit failure if it doesn't work. This means that root processes can safely get the lock, but normal processes can still use the 'pw' utility to get information (which may change out from under them.)
Notes
Notes: svn path=/head/; revision=38112
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pw/pw.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/usr.sbin/pw/pw.c b/usr.sbin/pw/pw.c
index 184f5e24ee99..3dc9276d518d 100644
--- a/usr.sbin/pw/pw.c
+++ b/usr.sbin/pw/pw.c
@@ -26,11 +26,12 @@
#ifndef lint
static const char rcsid[] =
- "$Id: pw.c,v 1.7 1997/10/10 06:23:34 charnier Exp $";
+ "$Id: pw.c,v 1.8 1998/07/16 17:18:25 nate Exp $";
#endif /* not lint */
#include "pw.h"
#include <err.h>
+#include <fcntl.h>
#include <paths.h>
#include <sys/wait.h>
@@ -49,6 +50,7 @@ static struct cargs arglist;
static int getindex(const char *words[], const char *word);
static void cmdhelp(int mode, int which);
+static void filelock(const char *filename);
int
@@ -147,6 +149,13 @@ main(int argc, char *argv[])
* Now, let's do the common initialisation
*/
cnf = read_userconfig(getarg(&arglist, 'C') ? getarg(&arglist, 'C')->val : NULL);
+
+ /*
+ * Try to lock the master passowrd and group files right away (we
+ * don't care if it works, since this is just advisory locking.
+ */
+ filelock(_PATH_GROUP);
+ filelock(_PATH_MASTERPASSWD);
ch = funcs[which] (cnf, mode, &arglist);
/*
@@ -177,6 +186,12 @@ main(int argc, char *argv[])
return ch;
}
+static void
+filelock(const char *filename)
+{
+ open(filename, O_RDONLY | O_EXLOCK, 0);
+}
+
static int
getindex(const char *words[], const char *word)
{