1 /* $NetBSD: vipw.c,v 1.16 2011/08/31 16:25:00 plunky Exp $ */
4 * Copyright (c) 1987, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
34 __COPYRIGHT("@(#) Copyright (c) 1987, 1993, 1994\
35 The Regents of the University of California. All rights reserved.");
40 static char sccsid
[] = "@(#)vipw.c 8.3 (Berkeley) 4/2/94";
42 __RCSID("$NetBSD: vipw.c,v 1.16 2011/08/31 16:25:00 plunky Exp $");
46 #include <sys/types.h>
47 #include <sys/param.h>
60 static void copyfile(int, int);
61 __dead
static void usage(void);
63 static char mpwd
[MAXPATHLEN
], mpwdl
[MAXPATHLEN
];
66 main(int argc
, char *argv
[])
70 struct stat begin
, end
;
74 while ((ch
= getopt(argc
, argv
, "d:")) != -1) {
78 if (pw_setprefix(prefix
) < 0)
92 (void)snprintf(mpwd
, sizeof(mpwd
), "%s%s", prefix
, _PATH_MASTERPASSWD
);
93 (void)snprintf(mpwdl
, sizeof(mpwdl
), "%s%s", prefix
,
94 _PATH_MASTERPASSWD_LOCK
);
100 errx(1, "the passwd file is busy.");
105 pfd
= open(mpwd
, O_RDONLY
, 0);
107 pw_error(mpwd
, 1, 1);
112 if (stat(mpwdl
, &begin
))
113 pw_error(mpwdl
, 1, 1);
115 if (stat(mpwdl
, &end
))
116 pw_error(mpwdl
, 1, 1);
117 if (begin
.st_mtime
== end
.st_mtime
&&
118 begin
.st_mtimensec
== end
.st_mtimensec
) {
119 warnx("no changes made");
120 pw_error(NULL
, 0, 0);
122 if (pw_mkdb(NULL
, 0) == 0)
130 copyfile(int from
, int to
)
135 while ((nr
= read(from
, buf
, sizeof(buf
))) > 0)
136 for (off
= 0; off
< nr
; nr
-= nw
, off
+= nw
)
137 if ((nw
= write(to
, buf
+ off
, nr
)) < 0)
138 pw_error(mpwdl
, 1, 1);
140 pw_error(mpwd
, 1, 1);
147 (void)fprintf(stderr
, "usage: %s [-d directory]\n", getprogname());