File: | src/usr.sbin/vipw/vipw.c |
Warning: | line 61, column 2 Value stored to 'argv' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* $OpenBSD: vipw.c,v 1.26 2021/10/24 21:24:19 deraadt Exp $ */ |
2 | |
3 | /* |
4 | * Copyright (c) 1987, 1993, 1994 |
5 | * The Regents of the University of California. All rights reserved. |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions |
9 | * are met: |
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. |
18 | * |
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 |
29 | * SUCH DAMAGE. |
30 | */ |
31 | |
32 | #include <sys/time.h> |
33 | #include <sys/stat.h> |
34 | |
35 | #include <err.h> |
36 | #include <fcntl.h> |
37 | #include <paths.h> |
38 | #include <pwd.h> |
39 | #include <stdio.h> |
40 | #include <stdlib.h> |
41 | #include <unistd.h> |
42 | #include <util.h> |
43 | |
44 | void copyfile(int, int, struct stat *); |
45 | __dead__attribute__((__noreturn__)) void usage(void); |
46 | |
47 | int |
48 | main(int argc, char *argv[]) |
49 | { |
50 | int pfd, tfd; |
51 | struct stat begin, end; |
52 | int ch; |
53 | |
54 | while ((ch = getopt(argc, argv, "")) != -1) { |
55 | switch (ch) { |
56 | default: |
57 | usage(); |
58 | } |
59 | } |
60 | argc -= optind; |
61 | argv += optind; |
Value stored to 'argv' is never read | |
62 | |
63 | if (argc != 0) |
64 | usage(); |
65 | |
66 | if (unveil(_PATH_MASTERPASSWD_LOCK"/etc/ptmp", "rwc") == -1) |
67 | err(1, "unveil %s", _PATH_MASTERPASSWD_LOCK"/etc/ptmp"); |
68 | if (unveil(_PATH_MASTERPASSWD"/etc/master.passwd", "r") == -1) |
69 | err(1, "unveil %s", _PATH_MASTERPASSWD"/etc/master.passwd"); |
70 | if (unveil(_PATH_BSHELL"/bin/sh", "x") == -1) |
71 | err(1, "unveil %s", _PATH_BSHELL"/bin/sh"); |
72 | if (unveil(_PATH_PWD_MKDB"/usr/sbin/pwd_mkdb", "x") == -1) |
73 | err(1, "unveil %s", _PATH_PWD_MKDB"/usr/sbin/pwd_mkdb"); |
74 | if (pledge("stdio rpath wpath cpath fattr proc exec", NULL((void *)0)) == -1) |
75 | err(1, "pledge"); |
76 | |
77 | pw_init(); |
78 | tfd = pw_lock(0); |
79 | if (tfd == -1) |
80 | errx(1, "the passwd file is busy or you cannot lock."); |
81 | pfd = open(_PATH_MASTERPASSWD"/etc/master.passwd", O_RDONLY0x0000); |
82 | if (pfd == -1) |
83 | pw_error(_PATH_MASTERPASSWD"/etc/master.passwd", 1, 1); |
84 | copyfile(pfd, tfd, &begin); |
85 | (void)close(tfd); |
86 | |
87 | for (;;) { |
88 | pw_edit(0, NULL((void *)0)); |
89 | if (stat(_PATH_MASTERPASSWD_LOCK"/etc/ptmp", &end)) |
90 | pw_error(_PATH_MASTERPASSWD_LOCK"/etc/ptmp", 1, 1); |
91 | if (timespeccmp(&begin.st_mtimespec, &end.st_mtimespec, ==)(((&begin.st_mtim)->tv_sec == (&end.st_mtim)->tv_sec ) ? ((&begin.st_mtim)->tv_nsec == (&end.st_mtim)-> tv_nsec) : ((&begin.st_mtim)->tv_sec == (&end.st_mtim )->tv_sec)) && |
92 | begin.st_size == end.st_size) { |
93 | warnx("no changes made"); |
94 | pw_error((char *)NULL((void *)0), 0, 0); |
95 | } |
96 | if (pw_mkdb(NULL((void *)0), 0) == 0) |
97 | break; |
98 | pw_prompt(); |
99 | } |
100 | |
101 | return 0; |
102 | } |
103 | |
104 | void |
105 | copyfile(int from, int to, struct stat *sb) |
106 | { |
107 | int nr, nw, off; |
108 | char buf[8*1024]; |
109 | struct timespec ts[2]; |
110 | |
111 | if (fstat(from, sb) == -1) |
112 | pw_error(_PATH_MASTERPASSWD"/etc/master.passwd", 1, 1); |
113 | while ((nr = read(from, buf, sizeof(buf))) > 0) |
114 | for (off = 0; nr > 0; nr -= nw, off += nw) |
115 | if ((nw = write(to, buf + off, nr)) == -1) |
116 | pw_error(_PATH_MASTERPASSWD_LOCK"/etc/ptmp", 1, 1); |
117 | if (nr == -1) |
118 | pw_error(_PATH_MASTERPASSWD"/etc/master.passwd", 1, 1); |
119 | |
120 | ts[0] = sb->st_atim; |
121 | ts[1] = sb->st_mtim; |
122 | (void)futimens(to, ts); |
123 | } |
124 | |
125 | __dead__attribute__((__noreturn__)) void |
126 | usage(void) |
127 | { |
128 | extern char *__progname; |
129 | |
130 | (void)fprintf(stderr(&__sF[2]), "usage: %s\n", __progname); |
131 | exit(1); |
132 | } |