Use ISO C99 / POSIX types. Should fix PR 40416.diff -r1.5 -r1.6 pkgsrc/pkgtools/mtree/files/compare.c
(joerg)
@@ -1,538 +1,538 @@ | @@ -1,538 +1,538 @@ | |||
1 | /* $NetBSD: compare.c,v 1.5 2008/11/06 02:14:52 jschauma Exp $ */ | 1 | /* $NetBSD: compare.c,v 1.6 2010/03/21 16:30:17 joerg Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1989, 1993 | 4 | * Copyright (c) 1989, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3. Neither the name of the University nor the names of its contributors | 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 | 16 | * may be used to endorse or promote products derived from this software | |
17 | * without specific prior written permission. | 17 | * without specific prior written permission. | |
18 | * | 18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #if HAVE_CONFIG_H | 32 | #if HAVE_CONFIG_H | |
33 | #include "config.h" | 33 | #include "config.h" | |
34 | #endif | 34 | #endif | |
35 | #if HAVE_NBTOOL_CONFIG_H | 35 | #if HAVE_NBTOOL_CONFIG_H | |
36 | #include "nbtool_config.h" | 36 | #include "nbtool_config.h" | |
37 | #endif | 37 | #endif | |
38 | 38 | |||
39 | #include <nbcompat.h> | 39 | #include <nbcompat.h> | |
40 | #if HAVE_SYS_CDEFS_H | 40 | #if HAVE_SYS_CDEFS_H | |
41 | #include <sys/cdefs.h> | 41 | #include <sys/cdefs.h> | |
42 | #endif | 42 | #endif | |
43 | #if defined(__RCSID) && !defined(lint) | 43 | #if defined(__RCSID) && !defined(lint) | |
44 | #if 0 | 44 | #if 0 | |
45 | static char sccsid[] = "@(#)compare.c 8.1 (Berkeley) 6/6/93"; | 45 | static char sccsid[] = "@(#)compare.c 8.1 (Berkeley) 6/6/93"; | |
46 | #else | 46 | #else | |
47 | __RCSID("$NetBSD: compare.c,v 1.5 2008/11/06 02:14:52 jschauma Exp $"); | 47 | __RCSID("$NetBSD: compare.c,v 1.6 2010/03/21 16:30:17 joerg Exp $"); | |
48 | #endif | 48 | #endif | |
49 | #endif /* not lint */ | 49 | #endif /* not lint */ | |
50 | 50 | |||
51 | #if HAVE_SYS_PARAM_H | 51 | #if HAVE_SYS_PARAM_H | |
52 | #include <sys/param.h> | 52 | #include <sys/param.h> | |
53 | #endif | 53 | #endif | |
54 | 54 | |||
55 | #if HAVE_ERRNO_H | 55 | #if HAVE_ERRNO_H | |
56 | #include <errno.h> | 56 | #include <errno.h> | |
57 | #endif | 57 | #endif | |
58 | #if HAVE_FCNTL_H | 58 | #if HAVE_FCNTL_H | |
59 | #include <fcntl.h> | 59 | #include <fcntl.h> | |
60 | #endif | 60 | #endif | |
61 | #if HAVE_STDIO_H | 61 | #if HAVE_STDIO_H | |
62 | #include <stdio.h> | 62 | #include <stdio.h> | |
63 | #endif | 63 | #endif | |
64 | #if HAVE_STRING_H | 64 | #if HAVE_STRING_H | |
65 | #include <string.h> | 65 | #include <string.h> | |
66 | #endif | 66 | #endif | |
67 | #if HAVE_TIME_H | 67 | #if HAVE_TIME_H | |
68 | #include <time.h> | 68 | #include <time.h> | |
69 | #endif | 69 | #endif | |
70 | #if HAVE_UNISTD_H | 70 | #if HAVE_UNISTD_H | |
71 | #include <unistd.h> | 71 | #include <unistd.h> | |
72 | #endif | 72 | #endif | |
73 | 73 | |||
74 | #ifndef NO_MD5 | 74 | #ifndef NO_MD5 | |
75 | #if HAVE_MD5_H | 75 | #if HAVE_MD5_H | |
76 | #include <md5.h> | 76 | #include <md5.h> | |
77 | #endif | 77 | #endif | |
78 | #endif | 78 | #endif | |
79 | #ifndef NO_RMD160 | 79 | #ifndef NO_RMD160 | |
80 | #if HAVE_RMD160_H | 80 | #if HAVE_RMD160_H | |
81 | #include <rmd160.h> | 81 | #include <rmd160.h> | |
82 | #endif | 82 | #endif | |
83 | #endif | 83 | #endif | |
84 | #ifndef NO_SHA1 | 84 | #ifndef NO_SHA1 | |
85 | #if HAVE_SHA1_H | 85 | #if HAVE_SHA1_H | |
86 | #include <sha1.h> | 86 | #include <sha1.h> | |
87 | #endif | 87 | #endif | |
88 | #endif | 88 | #endif | |
89 | #ifndef NO_SHA2 | 89 | #ifndef NO_SHA2 | |
90 | #if HAVE_SHA2_H | 90 | #if HAVE_SHA2_H | |
91 | #include <sha2.h> | 91 | #include <sha2.h> | |
92 | #endif | 92 | #endif | |
93 | #endif | 93 | #endif | |
94 | 94 | |||
95 | #include "extern.h" | 95 | #include "extern.h" | |
96 | 96 | |||
97 | #define INDENTNAMELEN 8 | 97 | #define INDENTNAMELEN 8 | |
98 | #define MARK \ | 98 | #define MARK \ | |
99 | do { \ | 99 | do { \ | |
100 | len = printf("%s: ", RP(p)); \ | 100 | len = printf("%s: ", RP(p)); \ | |
101 | if (len > INDENTNAMELEN) { \ | 101 | if (len > INDENTNAMELEN) { \ | |
102 | tab = "\t"; \ | 102 | tab = "\t"; \ | |
103 | printf("\n"); \ | 103 | printf("\n"); \ | |
104 | } else { \ | 104 | } else { \ | |
105 | tab = ""; \ | 105 | tab = ""; \ | |
106 | printf("%*s", INDENTNAMELEN - (int)len, ""); \ | 106 | printf("%*s", INDENTNAMELEN - (int)len, ""); \ | |
107 | } \ | 107 | } \ | |
108 | } while (0) | 108 | } while (0) | |
109 | #define LABEL if (!label++) MARK | 109 | #define LABEL if (!label++) MARK | |
110 | 110 | |||
111 | #if HAVE_STRUCT_STAT_ST_FLAGS | 111 | #if HAVE_STRUCT_STAT_ST_FLAGS | |
112 | 112 | |||
113 | 113 | |||
114 | #define CHANGEFLAGS \ | 114 | #define CHANGEFLAGS \ | |
115 | if (flags != p->fts_statp->st_flags) { \ | 115 | if (flags != p->fts_statp->st_flags) { \ | |
116 | if (!label) { \ | 116 | if (!label) { \ | |
117 | MARK; \ | 117 | MARK; \ | |
118 | printf("%sflags (\"%s\"", tab, \ | 118 | printf("%sflags (\"%s\"", tab, \ | |
119 | flags_to_string(p->fts_statp->st_flags, "none")); \ | 119 | flags_to_string(p->fts_statp->st_flags, "none")); \ | |
120 | } \ | 120 | } \ | |
121 | if (lchflags(p->fts_accpath, flags)) { \ | 121 | if (lchflags(p->fts_accpath, flags)) { \ | |
122 | label++; \ | 122 | label++; \ | |
123 | printf(", not modified: %s)\n", \ | 123 | printf(", not modified: %s)\n", \ | |
124 | strerror(errno)); \ | 124 | strerror(errno)); \ | |
125 | } else \ | 125 | } else \ | |
126 | printf(", modified to \"%s\")\n", \ | 126 | printf(", modified to \"%s\")\n", \ | |
127 | flags_to_string(flags, "none")); \ | 127 | flags_to_string(flags, "none")); \ | |
128 | } | 128 | } | |
129 | 129 | |||
130 | /* SETFLAGS: | 130 | /* SETFLAGS: | |
131 | * given pflags, additionally set those flags specified in s->st_flags and | 131 | * given pflags, additionally set those flags specified in s->st_flags and | |
132 | * selected by mask (the other flags are left unchanged). | 132 | * selected by mask (the other flags are left unchanged). | |
133 | */ | 133 | */ | |
134 | #define SETFLAGS(pflags, mask) \ | 134 | #define SETFLAGS(pflags, mask) \ | |
135 | do { \ | 135 | do { \ | |
136 | flags = (s->st_flags & (mask)) | (pflags); \ | 136 | flags = (s->st_flags & (mask)) | (pflags); \ | |
137 | CHANGEFLAGS; \ | 137 | CHANGEFLAGS; \ | |
138 | } while (0) | 138 | } while (0) | |
139 | 139 | |||
140 | /* CLEARFLAGS: | 140 | /* CLEARFLAGS: | |
141 | * given pflags, reset the flags specified in s->st_flags and selected by mask | 141 | * given pflags, reset the flags specified in s->st_flags and selected by mask | |
142 | * (the other flags are left unchanged). | 142 | * (the other flags are left unchanged). | |
143 | */ | 143 | */ | |
144 | #define CLEARFLAGS(pflags, mask) \ | 144 | #define CLEARFLAGS(pflags, mask) \ | |
145 | do { \ | 145 | do { \ | |
146 | flags = (~(s->st_flags & (mask)) & CH_MASK) & (pflags); \ | 146 | flags = (~(s->st_flags & (mask)) & CH_MASK) & (pflags); \ | |
147 | CHANGEFLAGS; \ | 147 | CHANGEFLAGS; \ | |
148 | } while (0) | 148 | } while (0) | |
149 | #endif /* HAVE_STRUCT_STAT_ST_FLAGS */ | 149 | #endif /* HAVE_STRUCT_STAT_ST_FLAGS */ | |
150 | 150 | |||
151 | int | 151 | int | |
152 | compare(NODE *s, FTSENT *p) | 152 | compare(NODE *s, FTSENT *p) | |
153 | { | 153 | { | |
154 | u_int32_t len, val, flags; | 154 | uint32_t len, val, flags; | |
155 | int fd, label; | 155 | int fd, label; | |
156 | const char *cp, *tab; | 156 | const char *cp, *tab; | |
157 | #if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1) || !defined(NO_SHA2) | 157 | #if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1) || !defined(NO_SHA2) | |
158 | char digestbuf[MAXHASHLEN + 1]; | 158 | char digestbuf[MAXHASHLEN + 1]; | |
159 | #endif | 159 | #endif | |
160 | 160 | |||
161 | tab = NULL; | 161 | tab = NULL; | |
162 | label = 0; | 162 | label = 0; | |
163 | switch(s->type) { | 163 | switch(s->type) { | |
164 | case F_BLOCK: | 164 | case F_BLOCK: | |
165 | if (!S_ISBLK(p->fts_statp->st_mode)) | 165 | if (!S_ISBLK(p->fts_statp->st_mode)) | |
166 | goto typeerr; | 166 | goto typeerr; | |
167 | break; | 167 | break; | |
168 | case F_CHAR: | 168 | case F_CHAR: | |
169 | if (!S_ISCHR(p->fts_statp->st_mode)) | 169 | if (!S_ISCHR(p->fts_statp->st_mode)) | |
170 | goto typeerr; | 170 | goto typeerr; | |
171 | break; | 171 | break; | |
172 | case F_DIR: | 172 | case F_DIR: | |
173 | if (!S_ISDIR(p->fts_statp->st_mode)) | 173 | if (!S_ISDIR(p->fts_statp->st_mode)) | |
174 | goto typeerr; | 174 | goto typeerr; | |
175 | break; | 175 | break; | |
176 | case F_FIFO: | 176 | case F_FIFO: | |
177 | if (!S_ISFIFO(p->fts_statp->st_mode)) | 177 | if (!S_ISFIFO(p->fts_statp->st_mode)) | |
178 | goto typeerr; | 178 | goto typeerr; | |
179 | break; | 179 | break; | |
180 | case F_FILE: | 180 | case F_FILE: | |
181 | if (!S_ISREG(p->fts_statp->st_mode)) | 181 | if (!S_ISREG(p->fts_statp->st_mode)) | |
182 | goto typeerr; | 182 | goto typeerr; | |
183 | break; | 183 | break; | |
184 | case F_LINK: | 184 | case F_LINK: | |
185 | if (!S_ISLNK(p->fts_statp->st_mode)) | 185 | if (!S_ISLNK(p->fts_statp->st_mode)) | |
186 | goto typeerr; | 186 | goto typeerr; | |
187 | break; | 187 | break; | |
188 | #ifdef S_ISSOCK | 188 | #ifdef S_ISSOCK | |
189 | case F_SOCK: | 189 | case F_SOCK: | |
190 | if (!S_ISSOCK(p->fts_statp->st_mode)) | 190 | if (!S_ISSOCK(p->fts_statp->st_mode)) | |
191 | goto typeerr; | 191 | goto typeerr; | |
192 | break; | 192 | break; | |
193 | #endif | 193 | #endif | |
194 | typeerr: LABEL; | 194 | typeerr: LABEL; | |
195 | printf("\ttype (%s, %s)\n", | 195 | printf("\ttype (%s, %s)\n", | |
196 | nodetype(s->type), inotype(p->fts_statp->st_mode)); | 196 | nodetype(s->type), inotype(p->fts_statp->st_mode)); | |
197 | return (label); | 197 | return (label); | |
198 | } | 198 | } | |
199 | if (mtree_Wflag) | 199 | if (mtree_Wflag) | |
200 | goto afterpermwhack; | 200 | goto afterpermwhack; | |
201 | #if HAVE_STRUCT_STAT_ST_FLAGS | 201 | #if HAVE_STRUCT_STAT_ST_FLAGS | |
202 | if (iflag && !uflag) { | 202 | if (iflag && !uflag) { | |
203 | if (s->flags & F_FLAGS) | 203 | if (s->flags & F_FLAGS) | |
204 | SETFLAGS(p->fts_statp->st_flags, SP_FLGS); | 204 | SETFLAGS(p->fts_statp->st_flags, SP_FLGS); | |
205 | return (label); | 205 | return (label); | |
206 | } | 206 | } | |
207 | if (mflag && !uflag) { | 207 | if (mflag && !uflag) { | |
208 | if (s->flags & F_FLAGS) | 208 | if (s->flags & F_FLAGS) | |
209 | CLEARFLAGS(p->fts_statp->st_flags, SP_FLGS); | 209 | CLEARFLAGS(p->fts_statp->st_flags, SP_FLGS); | |
210 | return (label); | 210 | return (label); | |
211 | } | 211 | } | |
212 | #endif | 212 | #endif | |
213 | if (s->flags & F_DEV && | 213 | if (s->flags & F_DEV && | |
214 | (s->type == F_BLOCK || s->type == F_CHAR) && | 214 | (s->type == F_BLOCK || s->type == F_CHAR) && | |
215 | s->st_rdev != p->fts_statp->st_rdev) { | 215 | s->st_rdev != p->fts_statp->st_rdev) { | |
216 | LABEL; | 216 | LABEL; | |
217 | printf("%sdevice (%#x, %#x", | 217 | printf("%sdevice (%#x, %#x", | |
218 | tab, s->st_rdev, p->fts_statp->st_rdev); | 218 | tab, s->st_rdev, p->fts_statp->st_rdev); | |
219 | if (uflag) { | 219 | if (uflag) { | |
220 | if ((unlink(p->fts_accpath) == -1) || | 220 | if ((unlink(p->fts_accpath) == -1) || | |
221 | (mknod(p->fts_accpath, | 221 | (mknod(p->fts_accpath, | |
222 | s->st_mode | nodetoino(s->type), | 222 | s->st_mode | nodetoino(s->type), | |
223 | s->st_rdev) == -1) || | 223 | s->st_rdev) == -1) || | |
224 | (lchown(p->fts_accpath, p->fts_statp->st_uid, | 224 | (lchown(p->fts_accpath, p->fts_statp->st_uid, | |
225 | p->fts_statp->st_gid) == -1) ) | 225 | p->fts_statp->st_gid) == -1) ) | |
226 | printf(", not modified: %s)\n", | 226 | printf(", not modified: %s)\n", | |
227 | strerror(errno)); | 227 | strerror(errno)); | |
228 | else | 228 | else | |
229 | printf(", modified)\n"); | 229 | printf(", modified)\n"); | |
230 | } else | 230 | } else | |
231 | printf(")\n"); | 231 | printf(")\n"); | |
232 | tab = "\t"; | 232 | tab = "\t"; | |
233 | } | 233 | } | |
234 | /* Set the uid/gid first, then set the mode. */ | 234 | /* Set the uid/gid first, then set the mode. */ | |
235 | if (s->flags & (F_UID | F_UNAME) && s->st_uid != p->fts_statp->st_uid) { | 235 | if (s->flags & (F_UID | F_UNAME) && s->st_uid != p->fts_statp->st_uid) { | |
236 | LABEL; | 236 | LABEL; | |
237 | printf("%suser (%lu, %lu", | 237 | printf("%suser (%lu, %lu", | |
238 | tab, (u_long)s->st_uid, (u_long)p->fts_statp->st_uid); | 238 | tab, (u_long)s->st_uid, (u_long)p->fts_statp->st_uid); | |
239 | if (uflag) { | 239 | if (uflag) { | |
240 | if (lchown(p->fts_accpath, s->st_uid, -1)) | 240 | if (lchown(p->fts_accpath, s->st_uid, -1)) | |
241 | printf(", not modified: %s)\n", | 241 | printf(", not modified: %s)\n", | |
242 | strerror(errno)); | 242 | strerror(errno)); | |
243 | else | 243 | else | |
244 | printf(", modified)\n"); | 244 | printf(", modified)\n"); | |
245 | } else | 245 | } else | |
246 | printf(")\n"); | 246 | printf(")\n"); | |
247 | tab = "\t"; | 247 | tab = "\t"; | |
248 | } | 248 | } | |
249 | if (s->flags & (F_GID | F_GNAME) && s->st_gid != p->fts_statp->st_gid) { | 249 | if (s->flags & (F_GID | F_GNAME) && s->st_gid != p->fts_statp->st_gid) { | |
250 | LABEL; | 250 | LABEL; | |
251 | printf("%sgid (%lu, %lu", | 251 | printf("%sgid (%lu, %lu", | |
252 | tab, (u_long)s->st_gid, (u_long)p->fts_statp->st_gid); | 252 | tab, (u_long)s->st_gid, (u_long)p->fts_statp->st_gid); | |
253 | if (uflag) { | 253 | if (uflag) { | |
254 | if (lchown(p->fts_accpath, -1, s->st_gid)) | 254 | if (lchown(p->fts_accpath, -1, s->st_gid)) | |
255 | printf(", not modified: %s)\n", | 255 | printf(", not modified: %s)\n", | |
256 | strerror(errno)); | 256 | strerror(errno)); | |
257 | else | 257 | else | |
258 | printf(", modified)\n"); | 258 | printf(", modified)\n"); | |
259 | } | 259 | } | |
260 | else | 260 | else | |
261 | printf(")\n"); | 261 | printf(")\n"); | |
262 | tab = "\t"; | 262 | tab = "\t"; | |
263 | } | 263 | } | |
264 | if (s->flags & F_MODE && | 264 | if (s->flags & F_MODE && | |
265 | s->st_mode != (p->fts_statp->st_mode & MBITS)) { | 265 | s->st_mode != (p->fts_statp->st_mode & MBITS)) { | |
266 | if (lflag) { | 266 | if (lflag) { | |
267 | mode_t tmode, mode; | 267 | mode_t tmode, mode; | |
268 | 268 | |||
269 | tmode = s->st_mode; | 269 | tmode = s->st_mode; | |
270 | mode = p->fts_statp->st_mode & MBITS; | 270 | mode = p->fts_statp->st_mode & MBITS; | |
271 | /* | 271 | /* | |
272 | * if none of the suid/sgid/etc bits are set, | 272 | * if none of the suid/sgid/etc bits are set, | |
273 | * then if the mode is a subset of the target, | 273 | * then if the mode is a subset of the target, | |
274 | * skip. | 274 | * skip. | |
275 | */ | 275 | */ | |
276 | if (!((tmode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) || | 276 | if (!((tmode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) || | |
277 | (mode & ~(S_IRWXU|S_IRWXG|S_IRWXO)))) | 277 | (mode & ~(S_IRWXU|S_IRWXG|S_IRWXO)))) | |
278 | if ((mode | tmode) == tmode) | 278 | if ((mode | tmode) == tmode) | |
279 | goto skip; | 279 | goto skip; | |
280 | } | 280 | } | |
281 | 281 | |||
282 | LABEL; | 282 | LABEL; | |
283 | printf("%spermissions (%#lo, %#lo", | 283 | printf("%spermissions (%#lo, %#lo", | |
284 | tab, (u_long)s->st_mode, | 284 | tab, (u_long)s->st_mode, | |
285 | (u_long)p->fts_statp->st_mode & MBITS); | 285 | (u_long)p->fts_statp->st_mode & MBITS); | |
286 | if (uflag) { | 286 | if (uflag) { | |
287 | if (lchmod(p->fts_accpath, s->st_mode)) | 287 | if (lchmod(p->fts_accpath, s->st_mode)) | |
288 | printf(", not modified: %s)\n", | 288 | printf(", not modified: %s)\n", | |
289 | strerror(errno)); | 289 | strerror(errno)); | |
290 | else | 290 | else | |
291 | printf(", modified)\n"); | 291 | printf(", modified)\n"); | |
292 | } | 292 | } | |
293 | else | 293 | else | |
294 | printf(")\n"); | 294 | printf(")\n"); | |
295 | tab = "\t"; | 295 | tab = "\t"; | |
296 | skip: ; | 296 | skip: ; | |
297 | } | 297 | } | |
298 | if (s->flags & F_NLINK && s->type != F_DIR && | 298 | if (s->flags & F_NLINK && s->type != F_DIR && | |
299 | s->st_nlink != p->fts_statp->st_nlink) { | 299 | s->st_nlink != p->fts_statp->st_nlink) { | |
300 | LABEL; | 300 | LABEL; | |
301 | printf("%slink count (%lu, %lu)\n", | 301 | printf("%slink count (%lu, %lu)\n", | |
302 | tab, (u_long)s->st_nlink, (u_long)p->fts_statp->st_nlink); | 302 | tab, (u_long)s->st_nlink, (u_long)p->fts_statp->st_nlink); | |
303 | tab = "\t"; | 303 | tab = "\t"; | |
304 | } | 304 | } | |
305 | if (s->flags & F_SIZE && s->st_size != p->fts_statp->st_size) { | 305 | if (s->flags & F_SIZE && s->st_size != p->fts_statp->st_size) { | |
306 | LABEL; | 306 | LABEL; | |
307 | printf("%ssize (%lld, %lld)\n", | 307 | printf("%ssize (%lld, %lld)\n", | |
308 | tab, (long long)s->st_size, | 308 | tab, (long long)s->st_size, | |
309 | (long long)p->fts_statp->st_size); | 309 | (long long)p->fts_statp->st_size); | |
310 | tab = "\t"; | 310 | tab = "\t"; | |
311 | } | 311 | } | |
312 | /* | 312 | /* | |
313 | * XXX | 313 | * XXX | |
314 | * Since utimes(2) only takes a timeval, there's no point in | 314 | * Since utimes(2) only takes a timeval, there's no point in | |
315 | * comparing the low bits of the timespec nanosecond field. This | 315 | * comparing the low bits of the timespec nanosecond field. This | |
316 | * will only result in mismatches that we can never fix. | 316 | * will only result in mismatches that we can never fix. | |
317 | * | 317 | * | |
318 | * Doesn't display microsecond differences. | 318 | * Doesn't display microsecond differences. | |
319 | */ | 319 | */ | |
320 | if (s->flags & F_TIME) { | 320 | if (s->flags & F_TIME) { | |
321 | struct timeval tv[2]; | 321 | struct timeval tv[2]; | |
322 | struct stat *ps = p->fts_statp; | 322 | struct stat *ps = p->fts_statp; | |
323 | time_t smtime = s->st_mtimespec.tv_sec; | 323 | time_t smtime = s->st_mtimespec.tv_sec; | |
324 | 324 | |||
325 | #if defined(BSD4_4) && !defined(HAVE_NBTOOL_CONFIG_H) | 325 | #if defined(BSD4_4) && !defined(HAVE_NBTOOL_CONFIG_H) | |
326 | time_t pmtime = ps->st_mtimespec.tv_sec; | 326 | time_t pmtime = ps->st_mtimespec.tv_sec; | |
327 | 327 | |||
328 | TIMESPEC_TO_TIMEVAL(&tv[0], &s->st_mtimespec); | 328 | TIMESPEC_TO_TIMEVAL(&tv[0], &s->st_mtimespec); | |
329 | TIMESPEC_TO_TIMEVAL(&tv[1], &ps->st_mtimespec); | 329 | TIMESPEC_TO_TIMEVAL(&tv[1], &ps->st_mtimespec); | |
330 | #else | 330 | #else | |
331 | time_t pmtime = (time_t)ps->st_mtime; | 331 | time_t pmtime = (time_t)ps->st_mtime; | |
332 | 332 | |||
333 | tv[0].tv_sec = smtime; | 333 | tv[0].tv_sec = smtime; | |
334 | tv[0].tv_usec = 0; | 334 | tv[0].tv_usec = 0; | |
335 | tv[1].tv_sec = pmtime; | 335 | tv[1].tv_sec = pmtime; | |
336 | tv[1].tv_usec = 0; | 336 | tv[1].tv_usec = 0; | |
337 | #endif | 337 | #endif | |
338 | 338 | |||
339 | if (tv[0].tv_sec != tv[1].tv_sec || | 339 | if (tv[0].tv_sec != tv[1].tv_sec || | |
340 | tv[0].tv_usec != tv[1].tv_usec) { | 340 | tv[0].tv_usec != tv[1].tv_usec) { | |
341 | LABEL; | 341 | LABEL; | |
342 | printf("%smodification time (%.24s, ", | 342 | printf("%smodification time (%.24s, ", | |
343 | tab, ctime(&smtime)); | 343 | tab, ctime(&smtime)); | |
344 | printf("%.24s", ctime(&pmtime)); | 344 | printf("%.24s", ctime(&pmtime)); | |
345 | if (tflag) { | 345 | if (tflag) { | |
346 | tv[1] = tv[0]; | 346 | tv[1] = tv[0]; | |
347 | if (utimes(p->fts_accpath, tv)) | 347 | if (utimes(p->fts_accpath, tv)) | |
348 | printf(", not modified: %s)\n", | 348 | printf(", not modified: %s)\n", | |
349 | strerror(errno)); | 349 | strerror(errno)); | |
350 | else | 350 | else | |
351 | printf(", modified)\n"); | 351 | printf(", modified)\n"); | |
352 | } else | 352 | } else | |
353 | printf(")\n"); | 353 | printf(")\n"); | |
354 | tab = "\t"; | 354 | tab = "\t"; | |
355 | } | 355 | } | |
356 | } | 356 | } | |
357 | #if HAVE_STRUCT_STAT_ST_FLAGS | 357 | #if HAVE_STRUCT_STAT_ST_FLAGS | |
358 | /* | 358 | /* | |
359 | * XXX | 359 | * XXX | |
360 | * since lchflags(2) will reset file times, the utimes() above | 360 | * since lchflags(2) will reset file times, the utimes() above | |
361 | * may have been useless! oh well, we'd rather have correct | 361 | * may have been useless! oh well, we'd rather have correct | |
362 | * flags, rather than times? | 362 | * flags, rather than times? | |
363 | */ | 363 | */ | |
364 | if ((s->flags & F_FLAGS) && ((s->st_flags != p->fts_statp->st_flags) | 364 | if ((s->flags & F_FLAGS) && ((s->st_flags != p->fts_statp->st_flags) | |
365 | || mflag || iflag)) { | 365 | || mflag || iflag)) { | |
366 | if (s->st_flags != p->fts_statp->st_flags) { | 366 | if (s->st_flags != p->fts_statp->st_flags) { | |
367 | LABEL; | 367 | LABEL; | |
368 | printf("%sflags (\"%s\" is not ", tab, | 368 | printf("%sflags (\"%s\" is not ", tab, | |
369 | flags_to_string(s->st_flags, "none")); | 369 | flags_to_string(s->st_flags, "none")); | |
370 | printf("\"%s\"", | 370 | printf("\"%s\"", | |
371 | flags_to_string(p->fts_statp->st_flags, "none")); | 371 | flags_to_string(p->fts_statp->st_flags, "none")); | |
372 | } | 372 | } | |
373 | if (uflag) { | 373 | if (uflag) { | |
374 | if (iflag) | 374 | if (iflag) | |
375 | SETFLAGS(0, CH_MASK); | 375 | SETFLAGS(0, CH_MASK); | |
376 | else if (mflag) | 376 | else if (mflag) | |
377 | CLEARFLAGS(0, SP_FLGS); | 377 | CLEARFLAGS(0, SP_FLGS); | |
378 | else | 378 | else | |
379 | SETFLAGS(0, (~SP_FLGS & CH_MASK)); | 379 | SETFLAGS(0, (~SP_FLGS & CH_MASK)); | |
380 | } else | 380 | } else | |
381 | printf(")\n"); | 381 | printf(")\n"); | |
382 | tab = "\t"; | 382 | tab = "\t"; | |
383 | } | 383 | } | |
384 | #endif /* HAVE_STRUCT_STAT_ST_FLAGS */ | 384 | #endif /* HAVE_STRUCT_STAT_ST_FLAGS */ | |
385 | 385 | |||
386 | /* | 386 | /* | |
387 | * from this point, no more permission checking or whacking | 387 | * from this point, no more permission checking or whacking | |
388 | * occurs, only checking of stuff like checksums and symlinks. | 388 | * occurs, only checking of stuff like checksums and symlinks. | |
389 | */ | 389 | */ | |
390 | afterpermwhack: | 390 | afterpermwhack: | |
391 | if (s->flags & F_CKSUM) { | 391 | if (s->flags & F_CKSUM) { | |
392 | if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0) { | 392 | if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0) { | |
393 | LABEL; | 393 | LABEL; | |
394 | printf("%scksum: %s: %s\n", | 394 | printf("%scksum: %s: %s\n", | |
395 | tab, p->fts_accpath, strerror(errno)); | 395 | tab, p->fts_accpath, strerror(errno)); | |
396 | tab = "\t"; | 396 | tab = "\t"; | |
397 | } else if (crc(fd, &val, &len)) { | 397 | } else if (crc(fd, &val, &len)) { | |
398 | close(fd); | 398 | close(fd); | |
399 | LABEL; | 399 | LABEL; | |
400 | printf("%scksum: %s: %s\n", | 400 | printf("%scksum: %s: %s\n", | |
401 | tab, p->fts_accpath, strerror(errno)); | 401 | tab, p->fts_accpath, strerror(errno)); | |
402 | tab = "\t"; | 402 | tab = "\t"; | |
403 | } else { | 403 | } else { | |
404 | close(fd); | 404 | close(fd); | |
405 | if (s->cksum != val) { | 405 | if (s->cksum != val) { | |
406 | LABEL; | 406 | LABEL; | |
407 | printf("%scksum (%lu, %lu)\n", | 407 | printf("%scksum (%lu, %lu)\n", | |
408 | tab, s->cksum, (unsigned long)val); | 408 | tab, s->cksum, (unsigned long)val); | |
409 | } | 409 | } | |
410 | tab = "\t"; | 410 | tab = "\t"; | |
411 | } | 411 | } | |
412 | } | 412 | } | |
413 | #ifndef NO_MD5 | 413 | #ifndef NO_MD5 | |
414 | if (s->flags & F_MD5) { | 414 | if (s->flags & F_MD5) { | |
415 | if (MD5File(p->fts_accpath, digestbuf) == NULL) { | 415 | if (MD5File(p->fts_accpath, digestbuf) == NULL) { | |
416 | LABEL; | 416 | LABEL; | |
417 | printf("%smd5: %s: %s\n", | 417 | printf("%smd5: %s: %s\n", | |
418 | tab, p->fts_accpath, strerror(errno)); | 418 | tab, p->fts_accpath, strerror(errno)); | |
419 | tab = "\t"; | 419 | tab = "\t"; | |
420 | } else { | 420 | } else { | |
421 | if (strcmp(s->md5digest, digestbuf)) { | 421 | if (strcmp(s->md5digest, digestbuf)) { | |
422 | LABEL; | 422 | LABEL; | |
423 | printf("%smd5 (0x%s, 0x%s)\n", | 423 | printf("%smd5 (0x%s, 0x%s)\n", | |
424 | tab, s->md5digest, digestbuf); | 424 | tab, s->md5digest, digestbuf); | |
425 | } | 425 | } | |
426 | tab = "\t"; | 426 | tab = "\t"; | |
427 | } | 427 | } | |
428 | } | 428 | } | |
429 | #endif /* ! NO_MD5 */ | 429 | #endif /* ! NO_MD5 */ | |
430 | #ifndef NO_RMD160 | 430 | #ifndef NO_RMD160 | |
431 | if (s->flags & F_RMD160) { | 431 | if (s->flags & F_RMD160) { | |
432 | if (RMD160File(p->fts_accpath, digestbuf) == NULL) { | 432 | if (RMD160File(p->fts_accpath, digestbuf) == NULL) { | |
433 | LABEL; | 433 | LABEL; | |
434 | printf("%srmd160: %s: %s\n", | 434 | printf("%srmd160: %s: %s\n", | |
435 | tab, p->fts_accpath, strerror(errno)); | 435 | tab, p->fts_accpath, strerror(errno)); | |
436 | tab = "\t"; | 436 | tab = "\t"; | |
437 | } else { | 437 | } else { | |
438 | if (strcmp(s->rmd160digest, digestbuf)) { | 438 | if (strcmp(s->rmd160digest, digestbuf)) { | |
439 | LABEL; | 439 | LABEL; | |
440 | printf("%srmd160 (0x%s, 0x%s)\n", | 440 | printf("%srmd160 (0x%s, 0x%s)\n", | |
441 | tab, s->rmd160digest, digestbuf); | 441 | tab, s->rmd160digest, digestbuf); | |
442 | } | 442 | } | |
443 | tab = "\t"; | 443 | tab = "\t"; | |
444 | } | 444 | } | |
445 | } | 445 | } | |
446 | #endif /* ! NO_RMD160 */ | 446 | #endif /* ! NO_RMD160 */ | |
447 | #ifndef NO_SHA1 | 447 | #ifndef NO_SHA1 | |
448 | if (s->flags & F_SHA1) { | 448 | if (s->flags & F_SHA1) { | |
449 | if (SHA1File(p->fts_accpath, digestbuf) == NULL) { | 449 | if (SHA1File(p->fts_accpath, digestbuf) == NULL) { | |
450 | LABEL; | 450 | LABEL; | |
451 | printf("%ssha1: %s: %s\n", | 451 | printf("%ssha1: %s: %s\n", | |
452 | tab, p->fts_accpath, strerror(errno)); | 452 | tab, p->fts_accpath, strerror(errno)); | |
453 | tab = "\t"; | 453 | tab = "\t"; | |
454 | } else { | 454 | } else { | |
455 | if (strcmp(s->sha1digest, digestbuf)) { | 455 | if (strcmp(s->sha1digest, digestbuf)) { | |
456 | LABEL; | 456 | LABEL; | |
457 | printf("%ssha1 (0x%s, 0x%s)\n", | 457 | printf("%ssha1 (0x%s, 0x%s)\n", | |
458 | tab, s->sha1digest, digestbuf); | 458 | tab, s->sha1digest, digestbuf); | |
459 | } | 459 | } | |
460 | tab = "\t"; | 460 | tab = "\t"; | |
461 | } | 461 | } | |
462 | } | 462 | } | |
463 | #endif /* ! NO_SHA1 */ | 463 | #endif /* ! NO_SHA1 */ | |
464 | #ifndef NO_SHA2 | 464 | #ifndef NO_SHA2 | |
465 | if (s->flags & F_SHA256) { | 465 | if (s->flags & F_SHA256) { | |
466 | if (SHA256_File(p->fts_accpath, digestbuf) == NULL) { | 466 | if (SHA256_File(p->fts_accpath, digestbuf) == NULL) { | |
467 | LABEL; | 467 | LABEL; | |
468 | printf("%ssha256: %s: %s\n", | 468 | printf("%ssha256: %s: %s\n", | |
469 | tab, p->fts_accpath, strerror(errno)); | 469 | tab, p->fts_accpath, strerror(errno)); | |
470 | tab = "\t"; | 470 | tab = "\t"; | |
471 | } else { | 471 | } else { | |
472 | if (strcmp(s->sha256digest, digestbuf)) { | 472 | if (strcmp(s->sha256digest, digestbuf)) { | |
473 | LABEL; | 473 | LABEL; | |
474 | printf("%ssha256 (0x%s, 0x%s)\n", | 474 | printf("%ssha256 (0x%s, 0x%s)\n", | |
475 | tab, s->sha256digest, digestbuf); | 475 | tab, s->sha256digest, digestbuf); | |
476 | } | 476 | } | |
477 | tab = "\t"; | 477 | tab = "\t"; | |
478 | } | 478 | } | |
479 | } | 479 | } | |
480 | if (s->flags & F_SHA384) { | 480 | if (s->flags & F_SHA384) { | |
481 | if (SHA384_File(p->fts_accpath, digestbuf) == NULL) { | 481 | if (SHA384_File(p->fts_accpath, digestbuf) == NULL) { | |
482 | LABEL; | 482 | LABEL; | |
483 | printf("%ssha384: %s: %s\n", | 483 | printf("%ssha384: %s: %s\n", | |
484 | tab, p->fts_accpath, strerror(errno)); | 484 | tab, p->fts_accpath, strerror(errno)); | |
485 | tab = "\t"; | 485 | tab = "\t"; | |
486 | } else { | 486 | } else { | |
487 | if (strcmp(s->sha384digest, digestbuf)) { | 487 | if (strcmp(s->sha384digest, digestbuf)) { | |
488 | LABEL; | 488 | LABEL; | |
489 | printf("%ssha384 (0x%s, 0x%s)\n", | 489 | printf("%ssha384 (0x%s, 0x%s)\n", | |
490 | tab, s->sha384digest, digestbuf); | 490 | tab, s->sha384digest, digestbuf); | |
491 | } | 491 | } | |
492 | tab = "\t"; | 492 | tab = "\t"; | |
493 | } | 493 | } | |
494 | } | 494 | } | |
495 | if (s->flags & F_SHA512) { | 495 | if (s->flags & F_SHA512) { | |
496 | if (SHA512_File(p->fts_accpath, digestbuf) == NULL) { | 496 | if (SHA512_File(p->fts_accpath, digestbuf) == NULL) { | |
497 | LABEL; | 497 | LABEL; | |
498 | printf("%ssha512: %s: %s\n", | 498 | printf("%ssha512: %s: %s\n", | |
499 | tab, p->fts_accpath, strerror(errno)); | 499 | tab, p->fts_accpath, strerror(errno)); | |
500 | tab = "\t"; | 500 | tab = "\t"; | |
501 | } else { | 501 | } else { | |
502 | if (strcmp(s->sha512digest, digestbuf)) { | 502 | if (strcmp(s->sha512digest, digestbuf)) { | |
503 | LABEL; | 503 | LABEL; | |
504 | printf("%ssha512 (0x%s, 0x%s)\n", | 504 | printf("%ssha512 (0x%s, 0x%s)\n", | |
505 | tab, s->sha512digest, digestbuf); | 505 | tab, s->sha512digest, digestbuf); | |
506 | } | 506 | } | |
507 | tab = "\t"; | 507 | tab = "\t"; | |
508 | } | 508 | } | |
509 | } | 509 | } | |
510 | #endif /* ! NO_SHA2 */ | 510 | #endif /* ! NO_SHA2 */ | |
511 | if (s->flags & F_SLINK && | 511 | if (s->flags & F_SLINK && | |
512 | strcmp(cp = rlink(p->fts_accpath), s->slink)) { | 512 | strcmp(cp = rlink(p->fts_accpath), s->slink)) { | |
513 | LABEL; | 513 | LABEL; | |
514 | printf("%slink ref (%s, %s", tab, cp, s->slink); | 514 | printf("%slink ref (%s, %s", tab, cp, s->slink); | |
515 | if (uflag) { | 515 | if (uflag) { | |
516 | if ((unlink(p->fts_accpath) == -1) || | 516 | if ((unlink(p->fts_accpath) == -1) || | |
517 | (symlink(s->slink, p->fts_accpath) == -1) ) | 517 | (symlink(s->slink, p->fts_accpath) == -1) ) | |
518 | printf(", not modified: %s)\n", | 518 | printf(", not modified: %s)\n", | |
519 | strerror(errno)); | 519 | strerror(errno)); | |
520 | else | 520 | else | |
521 | printf(", modified)\n"); | 521 | printf(", modified)\n"); | |
522 | } else | 522 | } else | |
523 | printf(")\n"); | 523 | printf(")\n"); | |
524 | } | 524 | } | |
525 | return (label); | 525 | return (label); | |
526 | } | 526 | } | |
527 | 527 | |||
528 | const char * | 528 | const char * | |
529 | rlink(const char *name) | 529 | rlink(const char *name) | |
530 | { | 530 | { | |
531 | static char lbuf[MAXPATHLEN]; | 531 | static char lbuf[MAXPATHLEN]; | |
532 | int len; | 532 | int len; | |
533 | 533 | |||
534 | if ((len = readlink(name, lbuf, sizeof(lbuf) - 1)) == -1) | 534 | if ((len = readlink(name, lbuf, sizeof(lbuf) - 1)) == -1) | |
535 | mtree_err("%s: %s", name, strerror(errno)); | 535 | mtree_err("%s: %s", name, strerror(errno)); | |
536 | lbuf[len] = '\0'; | 536 | lbuf[len] = '\0'; | |
537 | return (lbuf); | 537 | return (lbuf); | |
538 | } | 538 | } |
@@ -1,315 +1,315 @@ | @@ -1,315 +1,315 @@ | |||
1 | /* $NetBSD: verify.c,v 1.5 2008/11/06 02:14:52 jschauma Exp $ */ | 1 | /* $NetBSD: verify.c,v 1.6 2010/03/21 16:30:17 joerg Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1990, 1993 | 4 | * Copyright (c) 1990, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3. Neither the name of the University nor the names of its contributors | 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 | 16 | * may be used to endorse or promote products derived from this software | |
17 | * without specific prior written permission. | 17 | * without specific prior written permission. | |
18 | * | 18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #if HAVE_CONFIG_H | 32 | #if HAVE_CONFIG_H | |
33 | #include "config.h" | 33 | #include "config.h" | |
34 | #endif | 34 | #endif | |
35 | #if HAVE_NBTOOL_CONFIG_H | 35 | #if HAVE_NBTOOL_CONFIG_H | |
36 | #include "nbtool_config.h" | 36 | #include "nbtool_config.h" | |
37 | #endif | 37 | #endif | |
38 | 38 | |||
39 | #include <nbcompat.h> | 39 | #include <nbcompat.h> | |
40 | #if HAVE_SYS_CDEFS_H | 40 | #if HAVE_SYS_CDEFS_H | |
41 | #include <sys/cdefs.h> | 41 | #include <sys/cdefs.h> | |
42 | #endif | 42 | #endif | |
43 | #if defined(__RCSID) && !defined(lint) | 43 | #if defined(__RCSID) && !defined(lint) | |
44 | #if 0 | 44 | #if 0 | |
45 | static char sccsid[] = "@(#)verify.c 8.1 (Berkeley) 6/6/93"; | 45 | static char sccsid[] = "@(#)verify.c 8.1 (Berkeley) 6/6/93"; | |
46 | #else | 46 | #else | |
47 | __RCSID("$NetBSD: verify.c,v 1.5 2008/11/06 02:14:52 jschauma Exp $"); | 47 | __RCSID("$NetBSD: verify.c,v 1.6 2010/03/21 16:30:17 joerg Exp $"); | |
48 | #endif | 48 | #endif | |
49 | #endif /* not lint */ | 49 | #endif /* not lint */ | |
50 | 50 | |||
51 | #if HAVE_SYS_PARAM_H | 51 | #if HAVE_SYS_PARAM_H | |
52 | #include <sys/param.h> | 52 | #include <sys/param.h> | |
53 | #endif | 53 | #endif | |
54 | #if HAVE_SYS_STAT_H | 54 | #if HAVE_SYS_STAT_H | |
55 | #include <sys/stat.h> | 55 | #include <sys/stat.h> | |
56 | #endif | 56 | #endif | |
57 | 57 | |||
58 | #if ! HAVE_NBTOOL_CONFIG_H | 58 | #if ! HAVE_NBTOOL_CONFIG_H | |
59 | #if HAVE_DIRENT_H | 59 | #if HAVE_DIRENT_H | |
60 | #include <dirent.h> | 60 | #include <dirent.h> | |
61 | #endif | 61 | #endif | |
62 | #endif | 62 | #endif | |
63 | 63 | |||
64 | #if HAVE_ERRNO_H | 64 | #if HAVE_ERRNO_H | |
65 | #include <errno.h> | 65 | #include <errno.h> | |
66 | #endif | 66 | #endif | |
67 | #if HAVE_FNMATCH_H | 67 | #if HAVE_FNMATCH_H | |
68 | #include <fnmatch.h> | 68 | #include <fnmatch.h> | |
69 | #endif | 69 | #endif | |
70 | #if HAVE_STDIO_H | 70 | #if HAVE_STDIO_H | |
71 | #include <stdio.h> | 71 | #include <stdio.h> | |
72 | #endif | 72 | #endif | |
73 | #if HAVE_STRING_H | 73 | #if HAVE_STRING_H | |
74 | #include <string.h> | 74 | #include <string.h> | |
75 | #endif | 75 | #endif | |
76 | #if HAVE_UNISTD_H | 76 | #if HAVE_UNISTD_H | |
77 | #include <unistd.h> | 77 | #include <unistd.h> | |
78 | #endif | 78 | #endif | |
79 | 79 | |||
80 | #include "extern.h" | 80 | #include "extern.h" | |
81 | 81 | |||
82 | static NODE *root; | 82 | static NODE *root; | |
83 | static char path[MAXPATHLEN]; | 83 | static char path[MAXPATHLEN]; | |
84 | 84 | |||
85 | static void miss(NODE *, char *); | 85 | static void miss(NODE *, char *); | |
86 | static int vwalk(void); | 86 | static int vwalk(void); | |
87 | 87 | |||
88 | int | 88 | int | |
89 | verify(void) | 89 | verify(void) | |
90 | { | 90 | { | |
91 | int rval; | 91 | int rval; | |
92 | 92 | |||
93 | root = spec(stdin); | 93 | root = spec(stdin); | |
94 | rval = vwalk(); | 94 | rval = vwalk(); | |
95 | miss(root, path); | 95 | miss(root, path); | |
96 | return (rval); | 96 | return (rval); | |
97 | } | 97 | } | |
98 | 98 | |||
99 | static int | 99 | static int | |
100 | vwalk(void) | 100 | vwalk(void) | |
101 | { | 101 | { | |
102 | FTS *t; | 102 | FTS *t; | |
103 | FTSENT *p; | 103 | FTSENT *p; | |
104 | NODE *ep, *level; | 104 | NODE *ep, *level; | |
105 | int specdepth, rval; | 105 | int specdepth, rval; | |
106 | char *argv[2]; | 106 | char *argv[2]; | |
107 | char dot[] = "."; | 107 | char dot[] = "."; | |
108 | argv[0] = dot; | 108 | argv[0] = dot; | |
109 | argv[1] = NULL; | 109 | argv[1] = NULL; | |
110 | 110 | |||
111 | if ((t = fts_open(argv, ftsoptions, NULL)) == NULL) | 111 | if ((t = fts_open(argv, ftsoptions, NULL)) == NULL) | |
112 | mtree_err("fts_open: %s", strerror(errno)); | 112 | mtree_err("fts_open: %s", strerror(errno)); | |
113 | level = root; | 113 | level = root; | |
114 | specdepth = rval = 0; | 114 | specdepth = rval = 0; | |
115 | while ((p = fts_read(t)) != NULL) { | 115 | while ((p = fts_read(t)) != NULL) { | |
116 | if (check_excludes(p->fts_name, p->fts_path)) { | 116 | if (check_excludes(p->fts_name, p->fts_path)) { | |
117 | fts_set(t, p, FTS_SKIP); | 117 | fts_set(t, p, FTS_SKIP); | |
118 | continue; | 118 | continue; | |
119 | } | 119 | } | |
120 | switch(p->fts_info) { | 120 | switch(p->fts_info) { | |
121 | case FTS_D: | 121 | case FTS_D: | |
122 | case FTS_SL: | 122 | case FTS_SL: | |
123 | break; | 123 | break; | |
124 | case FTS_DP: | 124 | case FTS_DP: | |
125 | if (specdepth > p->fts_level) { | 125 | if (specdepth > p->fts_level) { | |
126 | for (level = level->parent; level->prev; | 126 | for (level = level->parent; level->prev; | |
127 | level = level->prev) | 127 | level = level->prev) | |
128 | continue; | 128 | continue; | |
129 | --specdepth; | 129 | --specdepth; | |
130 | } | 130 | } | |
131 | continue; | 131 | continue; | |
132 | case FTS_DNR: | 132 | case FTS_DNR: | |
133 | case FTS_ERR: | 133 | case FTS_ERR: | |
134 | case FTS_NS: | 134 | case FTS_NS: | |
135 | warnx("%s: %s", RP(p), strerror(p->fts_errno)); | 135 | warnx("%s: %s", RP(p), strerror(p->fts_errno)); | |
136 | continue; | 136 | continue; | |
137 | default: | 137 | default: | |
138 | if (dflag) | 138 | if (dflag) | |
139 | continue; | 139 | continue; | |
140 | } | 140 | } | |
141 | 141 | |||
142 | if (specdepth != p->fts_level) | 142 | if (specdepth != p->fts_level) | |
143 | goto extra; | 143 | goto extra; | |
144 | for (ep = level; ep; ep = ep->next) | 144 | for (ep = level; ep; ep = ep->next) | |
145 | if ((ep->flags & F_MAGIC && | 145 | if ((ep->flags & F_MAGIC && | |
146 | !fnmatch(ep->name, p->fts_name, FNM_PATHNAME)) || | 146 | !fnmatch(ep->name, p->fts_name, FNM_PATHNAME)) || | |
147 | !strcmp(ep->name, p->fts_name)) { | 147 | !strcmp(ep->name, p->fts_name)) { | |
148 | ep->flags |= F_VISIT; | 148 | ep->flags |= F_VISIT; | |
149 | if (compare(ep, p)) | 149 | if (compare(ep, p)) | |
150 | rval = MISMATCHEXIT; | 150 | rval = MISMATCHEXIT; | |
151 | if (!(ep->flags & F_IGN) && | 151 | if (!(ep->flags & F_IGN) && | |
152 | ep->type == F_DIR && | 152 | ep->type == F_DIR && | |
153 | p->fts_info == FTS_D) { | 153 | p->fts_info == FTS_D) { | |
154 | if (ep->child) { | 154 | if (ep->child) { | |
155 | level = ep->child; | 155 | level = ep->child; | |
156 | ++specdepth; | 156 | ++specdepth; | |
157 | } | 157 | } | |
158 | } else | 158 | } else | |
159 | fts_set(t, p, FTS_SKIP); | 159 | fts_set(t, p, FTS_SKIP); | |
160 | break; | 160 | break; | |
161 | } | 161 | } | |
162 | 162 | |||
163 | if (ep) | 163 | if (ep) | |
164 | continue; | 164 | continue; | |
165 | extra: | 165 | extra: | |
166 | if (!eflag) { | 166 | if (!eflag) { | |
167 | printf("extra: %s", RP(p)); | 167 | printf("extra: %s", RP(p)); | |
168 | if (rflag) { | 168 | if (rflag) { | |
169 | if ((S_ISDIR(p->fts_statp->st_mode) | 169 | if ((S_ISDIR(p->fts_statp->st_mode) | |
170 | ? rmdir : unlink)(p->fts_accpath)) { | 170 | ? rmdir : unlink)(p->fts_accpath)) { | |
171 | printf(", not removed: %s", | 171 | printf(", not removed: %s", | |
172 | strerror(errno)); | 172 | strerror(errno)); | |
173 | } else | 173 | } else | |
174 | printf(", removed"); | 174 | printf(", removed"); | |
175 | } | 175 | } | |
176 | putchar('\n'); | 176 | putchar('\n'); | |
177 | } | 177 | } | |
178 | fts_set(t, p, FTS_SKIP); | 178 | fts_set(t, p, FTS_SKIP); | |
179 | } | 179 | } | |
180 | fts_close(t); | 180 | fts_close(t); | |
181 | if (sflag) | 181 | if (sflag) | |
182 | warnx("%s checksum: %u", fullpath, crc_total); | 182 | warnx("%s checksum: %u", fullpath, crc_total); | |
183 | return (rval); | 183 | return (rval); | |
184 | } | 184 | } | |
185 | 185 | |||
186 | static void | 186 | static void | |
187 | miss(NODE *p, char *tail) | 187 | miss(NODE *p, char *tail) | |
188 | { | 188 | { | |
189 | int create; | 189 | int create; | |
190 | char *tp; | 190 | char *tp; | |
191 | const char *type; | 191 | const char *type; | |
192 | u_int32_t flags; | 192 | uint32_t flags; | |
193 | 193 | |||
194 | for (; p; p = p->next) { | 194 | for (; p; p = p->next) { | |
195 | if (p->flags & F_OPT && !(p->flags & F_VISIT)) | 195 | if (p->flags & F_OPT && !(p->flags & F_VISIT)) | |
196 | continue; | 196 | continue; | |
197 | if (p->type != F_DIR && (dflag || p->flags & F_VISIT)) | 197 | if (p->type != F_DIR && (dflag || p->flags & F_VISIT)) | |
198 | continue; | 198 | continue; | |
199 | strcpy(tail, p->name); | 199 | strcpy(tail, p->name); | |
200 | if (!(p->flags & F_VISIT)) | 200 | if (!(p->flags & F_VISIT)) | |
201 | printf("missing: %s", path); | 201 | printf("missing: %s", path); | |
202 | switch (p->type) { | 202 | switch (p->type) { | |
203 | case F_BLOCK: | 203 | case F_BLOCK: | |
204 | case F_CHAR: | 204 | case F_CHAR: | |
205 | type = "device"; | 205 | type = "device"; | |
206 | break; | 206 | break; | |
207 | case F_DIR: | 207 | case F_DIR: | |
208 | type = "directory"; | 208 | type = "directory"; | |
209 | break; | 209 | break; | |
210 | case F_LINK: | 210 | case F_LINK: | |
211 | type = "symlink"; | 211 | type = "symlink"; | |
212 | break; | 212 | break; | |
213 | default: | 213 | default: | |
214 | putchar('\n'); | 214 | putchar('\n'); | |
215 | continue; | 215 | continue; | |
216 | } | 216 | } | |
217 | 217 | |||
218 | create = 0; | 218 | create = 0; | |
219 | if (!(p->flags & F_VISIT) && uflag) { | 219 | if (!(p->flags & F_VISIT) && uflag) { | |
220 | if (mtree_Wflag || p->type == F_LINK) | 220 | if (mtree_Wflag || p->type == F_LINK) | |
221 | goto createit; | 221 | goto createit; | |
222 | if (!(p->flags & (F_UID | F_UNAME))) | 222 | if (!(p->flags & (F_UID | F_UNAME))) | |
223 | printf( | 223 | printf( | |
224 | " (%s not created: user not specified)", type); | 224 | " (%s not created: user not specified)", type); | |
225 | else if (!(p->flags & (F_GID | F_GNAME))) | 225 | else if (!(p->flags & (F_GID | F_GNAME))) | |
226 | printf( | 226 | printf( | |
227 | " (%s not created: group not specified)", type); | 227 | " (%s not created: group not specified)", type); | |
228 | else if (!(p->flags & F_MODE)) | 228 | else if (!(p->flags & F_MODE)) | |
229 | printf( | 229 | printf( | |
230 | " (%s not created: mode not specified)", type); | 230 | " (%s not created: mode not specified)", type); | |
231 | else | 231 | else | |
232 | createit: | 232 | createit: | |
233 | switch (p->type) { | 233 | switch (p->type) { | |
234 | case F_BLOCK: | 234 | case F_BLOCK: | |
235 | case F_CHAR: | 235 | case F_CHAR: | |
236 | if (mtree_Wflag) | 236 | if (mtree_Wflag) | |
237 | continue; | 237 | continue; | |
238 | if (!(p->flags & F_DEV)) | 238 | if (!(p->flags & F_DEV)) | |
239 | printf( | 239 | printf( | |
240 | " (%s not created: device not specified)", | 240 | " (%s not created: device not specified)", | |
241 | type); | 241 | type); | |
242 | else if (mknod(path, | 242 | else if (mknod(path, | |
243 | p->st_mode | nodetoino(p->type), | 243 | p->st_mode | nodetoino(p->type), | |
244 | p->st_rdev) == -1) | 244 | p->st_rdev) == -1) | |
245 | printf(" (%s not created: %s)\n", | 245 | printf(" (%s not created: %s)\n", | |
246 | type, strerror(errno)); | 246 | type, strerror(errno)); | |
247 | else | 247 | else | |
248 | create = 1; | 248 | create = 1; | |
249 | break; | 249 | break; | |
250 | case F_LINK: | 250 | case F_LINK: | |
251 | if (!(p->flags & F_SLINK)) | 251 | if (!(p->flags & F_SLINK)) | |
252 | printf( | 252 | printf( | |
253 | " (%s not created: link not specified)\n", | 253 | " (%s not created: link not specified)\n", | |
254 | type); | 254 | type); | |
255 | else if (symlink(p->slink, path)) | 255 | else if (symlink(p->slink, path)) | |
256 | printf( | 256 | printf( | |
257 | " (%s not created: %s)\n", | 257 | " (%s not created: %s)\n", | |
258 | type, strerror(errno)); | 258 | type, strerror(errno)); | |
259 | else | 259 | else | |
260 | create = 1; | 260 | create = 1; | |
261 | break; | 261 | break; | |
262 | case F_DIR: | 262 | case F_DIR: | |
263 | if (mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO)) | 263 | if (mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO)) | |
264 | printf(" (not created: %s)", | 264 | printf(" (not created: %s)", | |
265 | strerror(errno)); | 265 | strerror(errno)); | |
266 | else | 266 | else | |
267 | create = 1; | 267 | create = 1; | |
268 | break; | 268 | break; | |
269 | default: | 269 | default: | |
270 | mtree_err("can't create create %s", | 270 | mtree_err("can't create create %s", | |
271 | nodetype(p->type)); | 271 | nodetype(p->type)); | |
272 | } | 272 | } | |
273 | } | 273 | } | |
274 | if (create) | 274 | if (create) | |
275 | printf(" (created)"); | 275 | printf(" (created)"); | |
276 | if (p->type == F_DIR) { | 276 | if (p->type == F_DIR) { | |
277 | if (!(p->flags & F_VISIT)) | 277 | if (!(p->flags & F_VISIT)) | |
278 | putchar('\n'); | 278 | putchar('\n'); | |
279 | for (tp = tail; *tp; ++tp) | 279 | for (tp = tail; *tp; ++tp) | |
280 | continue; | 280 | continue; | |
281 | *tp = '/'; | 281 | *tp = '/'; | |
282 | miss(p->child, tp + 1); | 282 | miss(p->child, tp + 1); | |
283 | *tp = '\0'; | 283 | *tp = '\0'; | |
284 | } else | 284 | } else | |
285 | putchar('\n'); | 285 | putchar('\n'); | |
286 | 286 | |||
287 | if (!create || mtree_Wflag) | 287 | if (!create || mtree_Wflag) | |
288 | continue; | 288 | continue; | |
289 | if ((p->flags & (F_UID | F_UNAME)) && | 289 | if ((p->flags & (F_UID | F_UNAME)) && | |
290 | (p->flags & (F_GID | F_GNAME)) && | 290 | (p->flags & (F_GID | F_GNAME)) && | |
291 | (lchown(path, p->st_uid, p->st_gid))) { | 291 | (lchown(path, p->st_uid, p->st_gid))) { | |
292 | printf("%s: user/group/mode not modified: %s\n", | 292 | printf("%s: user/group/mode not modified: %s\n", | |
293 | path, strerror(errno)); | 293 | path, strerror(errno)); | |
294 | printf("%s: warning: file mode %snot set\n", path, | 294 | printf("%s: warning: file mode %snot set\n", path, | |
295 | (p->flags & F_FLAGS) ? "and file flags " : ""); | 295 | (p->flags & F_FLAGS) ? "and file flags " : ""); | |
296 | continue; | 296 | continue; | |
297 | } | 297 | } | |
298 | if (p->flags & F_MODE) { | 298 | if (p->flags & F_MODE) { | |
299 | if (lchmod(path, p->st_mode)) | 299 | if (lchmod(path, p->st_mode)) | |
300 | printf("%s: permissions not set: %s\n", | 300 | printf("%s: permissions not set: %s\n", | |
301 | path, strerror(errno)); | 301 | path, strerror(errno)); | |
302 | } | 302 | } | |
303 | #if HAVE_STRUCT_STAT_ST_FLAGS | 303 | #if HAVE_STRUCT_STAT_ST_FLAGS | |
304 | if ((p->flags & F_FLAGS) && p->st_flags) { | 304 | if ((p->flags & F_FLAGS) && p->st_flags) { | |
305 | if (iflag) | 305 | if (iflag) | |
306 | flags = p->st_flags; | 306 | flags = p->st_flags; | |
307 | else | 307 | else | |
308 | flags = p->st_flags & ~SP_FLGS; | 308 | flags = p->st_flags & ~SP_FLGS; | |
309 | if (lchflags(path, flags)) | 309 | if (lchflags(path, flags)) | |
310 | printf("%s: file flags not set: %s\n", | 310 | printf("%s: file flags not set: %s\n", | |
311 | path, strerror(errno)); | 311 | path, strerror(errno)); | |
312 | } | 312 | } | |
313 | #endif /* HAVE_STRUCT_STAT_ST_FLAGS */ | 313 | #endif /* HAVE_STRUCT_STAT_ST_FLAGS */ | |
314 | } | 314 | } | |
315 | } | 315 | } |
@@ -1,178 +1,178 @@ | @@ -1,178 +1,178 @@ | |||
1 | /* $NetBSD: crc.c,v 1.4 2008/11/06 02:14:52 jschauma Exp $ */ | 1 | /* $NetBSD: crc.c,v 1.5 2010/03/21 16:30:17 joerg Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1991, 1993 | 4 | * Copyright (c) 1991, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * James W. Williams of NASA Goddard Space Flight Center. | 8 | * James W. Williams of NASA Goddard Space Flight Center. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright | |
16 | * notice, this list of conditions and the following disclaimer in the | 16 | * notice, this list of conditions and the following disclaimer in the | |
17 | * documentation and/or other materials provided with the distribution. | 17 | * documentation and/or other materials provided with the distribution. | |
18 | * 3. Neither the name of the University nor the names of its contributors | 18 | * 3. Neither the name of the University nor the names of its contributors | |
19 | * may be used to endorse or promote products derived from this software | 19 | * may be used to endorse or promote products derived from this software | |
20 | * without specific prior written permission. | 20 | * without specific prior written permission. | |
21 | * | 21 | * | |
22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | * SUCH DAMAGE. | 32 | * SUCH DAMAGE. | |
33 | */ | 33 | */ | |
34 | 34 | |||
35 | #if HAVE_CONFIG_H | 35 | #if HAVE_CONFIG_H | |
36 | #include "config.h" | 36 | #include "config.h" | |
37 | #endif | 37 | #endif | |
38 | #if HAVE_NBTOOL_CONFIG_H | 38 | #if HAVE_NBTOOL_CONFIG_H | |
39 | #include "nbtool_config.h" | 39 | #include "nbtool_config.h" | |
40 | #endif | 40 | #endif | |
41 | 41 | |||
42 | #include <nbcompat.h> | 42 | #include <nbcompat.h> | |
43 | #if HAVE_SYS_CDEFS_H | 43 | #if HAVE_SYS_CDEFS_H | |
44 | #include <sys/cdefs.h> | 44 | #include <sys/cdefs.h> | |
45 | #endif | 45 | #endif | |
46 | #if defined(__RCSID) && !defined(lint) | 46 | #if defined(__RCSID) && !defined(lint) | |
47 | #if 0 | 47 | #if 0 | |
48 | static char sccsid[] = "@(#)crc.c 8.1 (Berkeley) 6/17/93"; | 48 | static char sccsid[] = "@(#)crc.c 8.1 (Berkeley) 6/17/93"; | |
49 | #else | 49 | #else | |
50 | __RCSID("$NetBSD: crc.c,v 1.4 2008/11/06 02:14:52 jschauma Exp $"); | 50 | __RCSID("$NetBSD: crc.c,v 1.5 2010/03/21 16:30:17 joerg Exp $"); | |
51 | #endif | 51 | #endif | |
52 | #endif /* not lint */ | 52 | #endif /* not lint */ | |
53 | 53 | |||
54 | #if HAVE_SYS_TYPES_H | 54 | #if HAVE_SYS_TYPES_H | |
55 | #include <sys/types.h> | 55 | #include <sys/types.h> | |
56 | #endif | 56 | #endif | |
57 | 57 | |||
58 | #if HAVE_STDIO_H | 58 | #if HAVE_STDIO_H | |
59 | #include <stdio.h> | 59 | #include <stdio.h> | |
60 | #endif | 60 | #endif | |
61 | #if HAVE_TIME_H | 61 | #if HAVE_TIME_H | |
62 | #include <time.h> | 62 | #include <time.h> | |
63 | #endif | 63 | #endif | |
64 | #if HAVE_UNISTD_H | 64 | #if HAVE_UNISTD_H | |
65 | #include <unistd.h> | 65 | #include <unistd.h> | |
66 | #endif | 66 | #endif | |
67 | 67 | |||
68 | #include "extern.h" | 68 | #include "extern.h" | |
69 | 69 | |||
70 | static const u_int32_t crctab[] = { | 70 | static const uint32_t crctab[] = { | |
71 | 0x0, | 71 | 0x0, | |
72 | 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, | 72 | 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, | |
73 | 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, | 73 | 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, | |
74 | 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, | 74 | 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, | |
75 | 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, | 75 | 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, | |
76 | 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f, | 76 | 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f, | |
77 | 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, | 77 | 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, | |
78 | 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, | 78 | 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, | |
79 | 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, | 79 | 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, | |
80 | 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, | 80 | 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, | |
81 | 0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe, | 81 | 0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe, | |
82 | 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95, | 82 | 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95, | |
83 | 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, | 83 | 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, | |
84 | 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, | 84 | 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, | |
85 | 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, | 85 | 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, | |
86 | 0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, | 86 | 0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, | |
87 | 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07, | 87 | 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07, | |
88 | 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, | 88 | 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, | |
89 | 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, | 89 | 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, | |
90 | 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, | 90 | 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, | |
91 | 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, | 91 | 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, | |
92 | 0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, | 92 | 0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, | |
93 | 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, | 93 | 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, | |
94 | 0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, | 94 | 0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, | |
95 | 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f, | 95 | 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f, | |
96 | 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, | 96 | 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, | |
97 | 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, | 97 | 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, | |
98 | 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, | 98 | 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, | |
99 | 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, | 99 | 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, | |
100 | 0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629, | 100 | 0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629, | |
101 | 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, | 101 | 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, | |
102 | 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, | 102 | 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, | |
103 | 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, | 103 | 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, | |
104 | 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, | 104 | 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, | |
105 | 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8, | 105 | 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8, | |
106 | 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, | 106 | 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, | |
107 | 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, | 107 | 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, | |
108 | 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, | 108 | 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, | |
109 | 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, | 109 | 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, | |
110 | 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, | 110 | 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, | |
111 | 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21, | 111 | 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21, | |
112 | 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, | 112 | 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, | |
113 | 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087, | 113 | 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087, | |
114 | 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, | 114 | 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, | |
115 | 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, | 115 | 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, | |
116 | 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, | 116 | 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, | |
117 | 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, | 117 | 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, | |
118 | 0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, | 118 | 0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, | |
119 | 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09, | 119 | 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09, | |
120 | 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, | 120 | 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, | |
121 | 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, | 121 | 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, | |
122 | 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 | 122 | 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 | |
123 | }; | 123 | }; | |
124 | 124 | |||
125 | /* | 125 | /* | |
126 | * Compute a POSIX 1003.2 checksum. This routine has been broken out so that | 126 | * Compute a POSIX 1003.2 checksum. This routine has been broken out so that | |
127 | * other programs can use it. It takes a file descriptor to read from and | 127 | * other programs can use it. It takes a file descriptor to read from and | |
128 | * locations to store the crc and the number of bytes read. It returns 0 on | 128 | * locations to store the crc and the number of bytes read. It returns 0 on | |
129 | * success and 1 on failure. Errno is set on failure. | 129 | * success and 1 on failure. Errno is set on failure. | |
130 | */ | 130 | */ | |
131 | extern int sflag; | 131 | extern int sflag; | |
132 | u_int32_t crc_total = ~0; /* The crc over a number of files. */ | 132 | uint32_t crc_total = ~0; /* The crc over a number of files. */ | |
133 | 133 | |||
134 | int | 134 | int | |
135 | crc(int fd, u_int32_t *cval, u_int32_t *clen) | 135 | crc(int fd, uint32_t *cval, uint32_t *clen) | |
136 | { | 136 | { | |
137 | u_char *p; | 137 | u_char *p; | |
138 | int nr; | 138 | int nr; | |
139 | u_int32_t thecrc, len; | 139 | uint32_t thecrc, len; | |
140 | u_int32_t crctot; | 140 | uint32_t crctot; | |
141 | u_char buf[16 * 1024]; | 141 | u_char buf[16 * 1024]; | |
142 | 142 | |||
143 | #define COMPUTE(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)] | 143 | #define COMPUTE(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)] | |
144 | 144 | |||
145 | thecrc = len = crctot = 0; | 145 | thecrc = len = crctot = 0; | |
146 | if (sflag) | 146 | if (sflag) | |
147 | crctot = ~crc_total; | 147 | crctot = ~crc_total; | |
148 | while ((nr = read(fd, buf, sizeof(buf))) > 0) | 148 | while ((nr = read(fd, buf, sizeof(buf))) > 0) | |
149 | if (sflag) { | 149 | if (sflag) { | |
150 | for (len += nr, p = buf; nr--; ++p) { | 150 | for (len += nr, p = buf; nr--; ++p) { | |
151 | COMPUTE(thecrc, *p); | 151 | COMPUTE(thecrc, *p); | |
152 | COMPUTE(crctot, *p); | 152 | COMPUTE(crctot, *p); | |
153 | } | 153 | } | |
154 | } else { | 154 | } else { | |
155 | for (len += nr, p = buf; nr--; ++p) | 155 | for (len += nr, p = buf; nr--; ++p) | |
156 | COMPUTE(thecrc, *p); | 156 | COMPUTE(thecrc, *p); | |
157 | } | 157 | } | |
158 | if (nr < 0) | 158 | if (nr < 0) | |
159 | return 1; | 159 | return 1; | |
160 | 160 | |||
161 | *clen = len; | 161 | *clen = len; | |
162 | 162 | |||
163 | /* Include the length of the file. */ | 163 | /* Include the length of the file. */ | |
164 | if (sflag) { | 164 | if (sflag) { | |
165 | for (; len != 0; len >>= 8) { | 165 | for (; len != 0; len >>= 8) { | |
166 | COMPUTE(thecrc, len & 0xff); | 166 | COMPUTE(thecrc, len & 0xff); | |
167 | COMPUTE(crctot, len & 0xff); | 167 | COMPUTE(crctot, len & 0xff); | |
168 | } | 168 | } | |
169 | } else { | 169 | } else { | |
170 | for (; len != 0; len >>= 8) | 170 | for (; len != 0; len >>= 8) | |
171 | COMPUTE(thecrc, len & 0xff); | 171 | COMPUTE(thecrc, len & 0xff); | |
172 | } | 172 | } | |
173 | 173 | |||
174 | *cval = ~thecrc; | 174 | *cval = ~thecrc; | |
175 | if (sflag) | 175 | if (sflag) | |
176 | crc_total = ~crctot; | 176 | crc_total = ~crctot; | |
177 | return 0; | 177 | return 0; | |
178 | } | 178 | } |
@@ -1,439 +1,439 @@ | @@ -1,439 +1,439 @@ | |||
1 | /* $NetBSD: create.c,v 1.6 2008/11/06 02:14:52 jschauma Exp $ */ | 1 | /* $NetBSD: create.c,v 1.7 2010/03/21 16:30:17 joerg Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1989, 1993 | 4 | * Copyright (c) 1989, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3. Neither the name of the University nor the names of its contributors | 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 | 16 | * may be used to endorse or promote products derived from this software | |
17 | * without specific prior written permission. | 17 | * without specific prior written permission. | |
18 | * | 18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #if HAVE_CONFIG_H | 32 | #if HAVE_CONFIG_H | |
33 | #include "config.h" | 33 | #include "config.h" | |
34 | #endif | 34 | #endif | |
35 | #if HAVE_NBTOOL_CONFIG_H | 35 | #if HAVE_NBTOOL_CONFIG_H | |
36 | #include "nbtool_config.h" | 36 | #include "nbtool_config.h" | |
37 | #endif | 37 | #endif | |
38 | 38 | |||
39 | #include <nbcompat.h> | 39 | #include <nbcompat.h> | |
40 | #if HAVE_SYS_CDEFS_H | 40 | #if HAVE_SYS_CDEFS_H | |
41 | #include <sys/cdefs.h> | 41 | #include <sys/cdefs.h> | |
42 | #endif | 42 | #endif | |
43 | #if defined(__RCSID) && !defined(lint) | 43 | #if defined(__RCSID) && !defined(lint) | |
44 | #if 0 | 44 | #if 0 | |
45 | static char sccsid[] = "@(#)create.c 8.1 (Berkeley) 6/6/93"; | 45 | static char sccsid[] = "@(#)create.c 8.1 (Berkeley) 6/6/93"; | |
46 | #else | 46 | #else | |
47 | __RCSID("$NetBSD: create.c,v 1.6 2008/11/06 02:14:52 jschauma Exp $"); | 47 | __RCSID("$NetBSD: create.c,v 1.7 2010/03/21 16:30:17 joerg Exp $"); | |
48 | #endif | 48 | #endif | |
49 | #endif /* not lint */ | 49 | #endif /* not lint */ | |
50 | 50 | |||
51 | #if HAVE_SYS_PARAM_H | 51 | #if HAVE_SYS_PARAM_H | |
52 | #include <sys/param.h> | 52 | #include <sys/param.h> | |
53 | #endif | 53 | #endif | |
54 | #if HAVE_SYS_STAT_H | 54 | #if HAVE_SYS_STAT_H | |
55 | #include <sys/stat.h> | 55 | #include <sys/stat.h> | |
56 | #endif | 56 | #endif | |
57 | 57 | |||
58 | #if ! HAVE_NBTOOL_CONFIG_H | 58 | #if ! HAVE_NBTOOL_CONFIG_H | |
59 | #if HAVE_DIRENT_H | 59 | #if HAVE_DIRENT_H | |
60 | #include <dirent.h> | 60 | #include <dirent.h> | |
61 | #endif | 61 | #endif | |
62 | #endif | 62 | #endif | |
63 | 63 | |||
64 | #if HAVE_ERRNO_H | 64 | #if HAVE_ERRNO_H | |
65 | #include <errno.h> | 65 | #include <errno.h> | |
66 | #endif | 66 | #endif | |
67 | #if HAVE_FCNTL_H | 67 | #if HAVE_FCNTL_H | |
68 | #include <fcntl.h> | 68 | #include <fcntl.h> | |
69 | #endif | 69 | #endif | |
70 | #if HAVE_GRP_H | 70 | #if HAVE_GRP_H | |
71 | #include <grp.h> | 71 | #include <grp.h> | |
72 | #endif | 72 | #endif | |
73 | #if HAVE_PWD_H | 73 | #if HAVE_PWD_H | |
74 | #include <pwd.h> | 74 | #include <pwd.h> | |
75 | #endif | 75 | #endif | |
76 | #if HAVE_STDIO_H | 76 | #if HAVE_STDIO_H | |
77 | #include <stdio.h> | 77 | #include <stdio.h> | |
78 | #endif | 78 | #endif | |
79 | #if HAVE_STDARG_H | 79 | #if HAVE_STDARG_H | |
80 | #include <stdarg.h> | 80 | #include <stdarg.h> | |
81 | #endif | 81 | #endif | |
82 | #if HAVE_STDLIB_H | 82 | #if HAVE_STDLIB_H | |
83 | #include <stdlib.h> | 83 | #include <stdlib.h> | |
84 | #endif | 84 | #endif | |
85 | #if HAVE_STRING_H | 85 | #if HAVE_STRING_H | |
86 | #include <string.h> | 86 | #include <string.h> | |
87 | #endif | 87 | #endif | |
88 | #if HAVE_TIME_H | 88 | #if HAVE_TIME_H | |
89 | #include <time.h> | 89 | #include <time.h> | |
90 | #endif | 90 | #endif | |
91 | #if HAVE_UNISTD_H | 91 | #if HAVE_UNISTD_H | |
92 | #include <unistd.h> | 92 | #include <unistd.h> | |
93 | #endif | 93 | #endif | |
94 | 94 | |||
95 | #ifndef NO_MD5 | 95 | #ifndef NO_MD5 | |
96 | #if HAVE_MD5_H | 96 | #if HAVE_MD5_H | |
97 | #include <md5.h> | 97 | #include <md5.h> | |
98 | #endif | 98 | #endif | |
99 | #endif | 99 | #endif | |
100 | #ifndef NO_RMD160 | 100 | #ifndef NO_RMD160 | |
101 | #if HAVE_RMD160_H | 101 | #if HAVE_RMD160_H | |
102 | #include <rmd160.h> | 102 | #include <rmd160.h> | |
103 | #endif | 103 | #endif | |
104 | #endif | 104 | #endif | |
105 | #ifndef NO_SHA1 | 105 | #ifndef NO_SHA1 | |
106 | #if HAVE_SHA1_H | 106 | #if HAVE_SHA1_H | |
107 | #include <sha1.h> | 107 | #include <sha1.h> | |
108 | #endif | 108 | #endif | |
109 | #endif | 109 | #endif | |
110 | #ifndef NO_SHA2 | 110 | #ifndef NO_SHA2 | |
111 | #if HAVE_SHA2_H | 111 | #if HAVE_SHA2_H | |
112 | #include <sha2.h> | 112 | #include <sha2.h> | |
113 | #endif | 113 | #endif | |
114 | #endif | 114 | #endif | |
115 | 115 | |||
116 | #include "extern.h" | 116 | #include "extern.h" | |
117 | 117 | |||
118 | #define INDENTNAMELEN 15 | 118 | #define INDENTNAMELEN 15 | |
119 | #define MAXLINELEN 80 | 119 | #define MAXLINELEN 80 | |
120 | 120 | |||
121 | static gid_t gid; | 121 | static gid_t gid; | |
122 | static uid_t uid; | 122 | static uid_t uid; | |
123 | static mode_t mode; | 123 | static mode_t mode; | |
124 | static u_long flags; | 124 | static u_long flags; | |
125 | 125 | |||
126 | static int dsort(const FTSENT **, const FTSENT **); | 126 | static int dsort(const FTSENT **, const FTSENT **); | |
127 | static void output(int *, const char *, ...) | 127 | static void output(int *, const char *, ...) | |
128 | __attribute__((__format__(__printf__, 2, 3))); | 128 | __attribute__((__format__(__printf__, 2, 3))); | |
129 | static int statd(FTS *, FTSENT *, uid_t *, gid_t *, mode_t *, u_long *); | 129 | static int statd(FTS *, FTSENT *, uid_t *, gid_t *, mode_t *, u_long *); | |
130 | static void statf(FTSENT *); | 130 | static void statf(FTSENT *); | |
131 | 131 | |||
132 | void | 132 | void | |
133 | cwalk(void) | 133 | cwalk(void) | |
134 | { | 134 | { | |
135 | FTS *t; | 135 | FTS *t; | |
136 | FTSENT *p; | 136 | FTSENT *p; | |
137 | time_t clocktime; | 137 | time_t clocktime; | |
138 | char host[MAXHOSTNAMELEN + 1]; | 138 | char host[MAXHOSTNAMELEN + 1]; | |
139 | char *argv[2]; | 139 | char *argv[2]; | |
140 | char dot[] = "."; | 140 | char dot[] = "."; | |
141 | argv[0] = dot; | 141 | argv[0] = dot; | |
142 | argv[1] = NULL; | 142 | argv[1] = NULL; | |
143 | 143 | |||
144 | time(&clocktime); | 144 | time(&clocktime); | |
145 | gethostname(host, sizeof(host)); | 145 | gethostname(host, sizeof(host)); | |
146 | host[sizeof(host) - 1] = '\0'; | 146 | host[sizeof(host) - 1] = '\0'; | |
147 | printf( | 147 | printf( | |
148 | "#\t user: %s\n#\tmachine: %s\n#\t tree: %s\n#\t date: %s", | 148 | "#\t user: %s\n#\tmachine: %s\n#\t tree: %s\n#\t date: %s", | |
149 | getlogin(), host, fullpath, ctime(&clocktime)); | 149 | getlogin(), host, fullpath, ctime(&clocktime)); | |
150 | 150 | |||
151 | if ((t = fts_open(argv, ftsoptions, dsort)) == NULL) | 151 | if ((t = fts_open(argv, ftsoptions, dsort)) == NULL) | |
152 | mtree_err("fts_open: %s", strerror(errno)); | 152 | mtree_err("fts_open: %s", strerror(errno)); | |
153 | while ((p = fts_read(t)) != NULL) { | 153 | while ((p = fts_read(t)) != NULL) { | |
154 | if (check_excludes(p->fts_name, p->fts_path)) { | 154 | if (check_excludes(p->fts_name, p->fts_path)) { | |
155 | fts_set(t, p, FTS_SKIP); | 155 | fts_set(t, p, FTS_SKIP); | |
156 | continue; | 156 | continue; | |
157 | } | 157 | } | |
158 | switch(p->fts_info) { | 158 | switch(p->fts_info) { | |
159 | case FTS_D: | 159 | case FTS_D: | |
160 | printf("\n# %s\n", p->fts_path); | 160 | printf("\n# %s\n", p->fts_path); | |
161 | statd(t, p, &uid, &gid, &mode, &flags); | 161 | statd(t, p, &uid, &gid, &mode, &flags); | |
162 | statf(p); | 162 | statf(p); | |
163 | break; | 163 | break; | |
164 | case FTS_DP: | 164 | case FTS_DP: | |
165 | if (p->fts_level > 0) | 165 | if (p->fts_level > 0) | |
166 | printf("# %s\n..\n\n", p->fts_path); | 166 | printf("# %s\n..\n\n", p->fts_path); | |
167 | break; | 167 | break; | |
168 | case FTS_DNR: | 168 | case FTS_DNR: | |
169 | case FTS_ERR: | 169 | case FTS_ERR: | |
170 | case FTS_NS: | 170 | case FTS_NS: | |
171 | mtree_err("%s: %s", | 171 | mtree_err("%s: %s", | |
172 | p->fts_path, strerror(p->fts_errno)); | 172 | p->fts_path, strerror(p->fts_errno)); | |
173 | break; | 173 | break; | |
174 | default: | 174 | default: | |
175 | if (!dflag) | 175 | if (!dflag) | |
176 | statf(p); | 176 | statf(p); | |
177 | break; | 177 | break; | |
178 | 178 | |||
179 | } | 179 | } | |
180 | } | 180 | } | |
181 | fts_close(t); | 181 | fts_close(t); | |
182 | if (sflag && keys & F_CKSUM) | 182 | if (sflag && keys & F_CKSUM) | |
183 | mtree_err("%s checksum: %u", fullpath, crc_total); | 183 | mtree_err("%s checksum: %u", fullpath, crc_total); | |
184 | } | 184 | } | |
185 | 185 | |||
186 | static void | 186 | static void | |
187 | statf(FTSENT *p) | 187 | statf(FTSENT *p) | |
188 | { | 188 | { | |
189 | u_int32_t len, val; | 189 | uint32_t len, val; | |
190 | int fd, indent; | 190 | int fd, indent; | |
191 | const char *name; | 191 | const char *name; | |
192 | #if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1) || !defined(NO_SHA2) | 192 | #if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1) || !defined(NO_SHA2) | |
193 | char digestbuf[MAXHASHLEN + 1]; | 193 | char digestbuf[MAXHASHLEN + 1]; | |
194 | #endif | 194 | #endif | |
195 | 195 | |||
196 | indent = printf("%s%s", | 196 | indent = printf("%s%s", | |
197 | S_ISDIR(p->fts_statp->st_mode) ? "" : " ", vispath(p->fts_name)); | 197 | S_ISDIR(p->fts_statp->st_mode) ? "" : " ", vispath(p->fts_name)); | |
198 | 198 | |||
199 | if (indent > INDENTNAMELEN) | 199 | if (indent > INDENTNAMELEN) | |
200 | indent = MAXLINELEN; | 200 | indent = MAXLINELEN; | |
201 | else | 201 | else | |
202 | indent += printf("%*s", INDENTNAMELEN - indent, ""); | 202 | indent += printf("%*s", INDENTNAMELEN - indent, ""); | |
203 | 203 | |||
204 | if (!S_ISREG(p->fts_statp->st_mode)) | 204 | if (!S_ISREG(p->fts_statp->st_mode)) | |
205 | output(&indent, "type=%s", inotype(p->fts_statp->st_mode)); | 205 | output(&indent, "type=%s", inotype(p->fts_statp->st_mode)); | |
206 | if (keys & (F_UID | F_UNAME) && p->fts_statp->st_uid != uid) { | 206 | if (keys & (F_UID | F_UNAME) && p->fts_statp->st_uid != uid) { | |
207 | if (keys & F_UNAME && | 207 | if (keys & F_UNAME && | |
208 | (name = user_from_uid(p->fts_statp->st_uid, 1)) != NULL) | 208 | (name = user_from_uid(p->fts_statp->st_uid, 1)) != NULL) | |
209 | output(&indent, "uname=%s", name); | 209 | output(&indent, "uname=%s", name); | |
210 | else /* if (keys & F_UID) */ | 210 | else /* if (keys & F_UID) */ | |
211 | output(&indent, "uid=%u", p->fts_statp->st_uid); | 211 | output(&indent, "uid=%u", p->fts_statp->st_uid); | |
212 | } | 212 | } | |
213 | if (keys & (F_GID | F_GNAME) && p->fts_statp->st_gid != gid) { | 213 | if (keys & (F_GID | F_GNAME) && p->fts_statp->st_gid != gid) { | |
214 | if (keys & F_GNAME && | 214 | if (keys & F_GNAME && | |
215 | (name = group_from_gid(p->fts_statp->st_gid, 1)) != NULL) | 215 | (name = group_from_gid(p->fts_statp->st_gid, 1)) != NULL) | |
216 | output(&indent, "gname=%s", name); | 216 | output(&indent, "gname=%s", name); | |
217 | else /* if (keys & F_GID) */ | 217 | else /* if (keys & F_GID) */ | |
218 | output(&indent, "gid=%u", p->fts_statp->st_gid); | 218 | output(&indent, "gid=%u", p->fts_statp->st_gid); | |
219 | } | 219 | } | |
220 | if (keys & F_MODE && (p->fts_statp->st_mode & MBITS) != mode) | 220 | if (keys & F_MODE && (p->fts_statp->st_mode & MBITS) != mode) | |
221 | output(&indent, "mode=%#o", p->fts_statp->st_mode & MBITS); | 221 | output(&indent, "mode=%#o", p->fts_statp->st_mode & MBITS); | |
222 | if (keys & F_DEV && | 222 | if (keys & F_DEV && | |
223 | (S_ISBLK(p->fts_statp->st_mode) || S_ISCHR(p->fts_statp->st_mode))) | 223 | (S_ISBLK(p->fts_statp->st_mode) || S_ISCHR(p->fts_statp->st_mode))) | |
224 | output(&indent, "device=%#x", p->fts_statp->st_rdev); | 224 | output(&indent, "device=%#x", p->fts_statp->st_rdev); | |
225 | if (keys & F_NLINK && p->fts_statp->st_nlink != 1) | 225 | if (keys & F_NLINK && p->fts_statp->st_nlink != 1) | |
226 | output(&indent, "nlink=%u", p->fts_statp->st_nlink); | 226 | output(&indent, "nlink=%u", p->fts_statp->st_nlink); | |
227 | if (keys & F_SIZE && S_ISREG(p->fts_statp->st_mode)) | 227 | if (keys & F_SIZE && S_ISREG(p->fts_statp->st_mode)) | |
228 | output(&indent, "size=%lld", (long long)p->fts_statp->st_size); | 228 | output(&indent, "size=%lld", (long long)p->fts_statp->st_size); | |
229 | #if defined(BSD4_4) && !defined(HAVE_NBTOOL_CONFIG_H) | 229 | #if defined(BSD4_4) && !defined(HAVE_NBTOOL_CONFIG_H) | |
230 | if (keys & F_TIME) | 230 | if (keys & F_TIME) | |
231 | output(&indent, "time=%ld.%ld", | 231 | output(&indent, "time=%ld.%ld", | |
232 | (long)p->fts_statp->st_mtimespec.tv_sec, | 232 | (long)p->fts_statp->st_mtimespec.tv_sec, | |
233 | p->fts_statp->st_mtimespec.tv_nsec); | 233 | p->fts_statp->st_mtimespec.tv_nsec); | |
234 | #else | 234 | #else | |
235 | output(&indent, "time=%ld.%ld", | 235 | output(&indent, "time=%ld.%ld", | |
236 | p->fts_statp->st_mtime, 0); | 236 | p->fts_statp->st_mtime, 0); | |
237 | #endif | 237 | #endif | |
238 | if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) { | 238 | if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) { | |
239 | if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 || | 239 | if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 || | |
240 | crc(fd, &val, &len)) | 240 | crc(fd, &val, &len)) | |
241 | mtree_err("%s: %s", p->fts_accpath, strerror(errno)); | 241 | mtree_err("%s: %s", p->fts_accpath, strerror(errno)); | |
242 | close(fd); | 242 | close(fd); | |
243 | output(&indent, "cksum=%lu", (long)val); | 243 | output(&indent, "cksum=%lu", (long)val); | |
244 | } | 244 | } | |
245 | #ifndef NO_MD5 | 245 | #ifndef NO_MD5 | |
246 | if (keys & F_MD5 && S_ISREG(p->fts_statp->st_mode)) { | 246 | if (keys & F_MD5 && S_ISREG(p->fts_statp->st_mode)) { | |
247 | if (MD5File(p->fts_accpath, digestbuf) == NULL) | 247 | if (MD5File(p->fts_accpath, digestbuf) == NULL) | |
248 | mtree_err("%s: %s", p->fts_accpath, "MD5File"); | 248 | mtree_err("%s: %s", p->fts_accpath, "MD5File"); | |
249 | output(&indent, "md5=%s", digestbuf); | 249 | output(&indent, "md5=%s", digestbuf); | |
250 | } | 250 | } | |
251 | #endif /* ! NO_MD5 */ | 251 | #endif /* ! NO_MD5 */ | |
252 | #ifndef NO_RMD160 | 252 | #ifndef NO_RMD160 | |
253 | if (keys & F_RMD160 && S_ISREG(p->fts_statp->st_mode)) { | 253 | if (keys & F_RMD160 && S_ISREG(p->fts_statp->st_mode)) { | |
254 | if (RMD160File(p->fts_accpath, digestbuf) == NULL) | 254 | if (RMD160File(p->fts_accpath, digestbuf) == NULL) | |
255 | mtree_err("%s: %s", p->fts_accpath, "RMD160File"); | 255 | mtree_err("%s: %s", p->fts_accpath, "RMD160File"); | |
256 | output(&indent, "rmd160=%s", digestbuf); | 256 | output(&indent, "rmd160=%s", digestbuf); | |
257 | } | 257 | } | |
258 | #endif /* ! NO_RMD160 */ | 258 | #endif /* ! NO_RMD160 */ | |
259 | #ifndef NO_SHA1 | 259 | #ifndef NO_SHA1 | |
260 | if (keys & F_SHA1 && S_ISREG(p->fts_statp->st_mode)) { | 260 | if (keys & F_SHA1 && S_ISREG(p->fts_statp->st_mode)) { | |
261 | if (SHA1File(p->fts_accpath, digestbuf) == NULL) | 261 | if (SHA1File(p->fts_accpath, digestbuf) == NULL) | |
262 | mtree_err("%s: %s", p->fts_accpath, "SHA1File"); | 262 | mtree_err("%s: %s", p->fts_accpath, "SHA1File"); | |
263 | output(&indent, "sha1=%s", digestbuf); | 263 | output(&indent, "sha1=%s", digestbuf); | |
264 | } | 264 | } | |
265 | #endif /* ! NO_SHA1 */ | 265 | #endif /* ! NO_SHA1 */ | |
266 | #ifndef NO_SHA2 | 266 | #ifndef NO_SHA2 | |
267 | if (keys & F_SHA256 && S_ISREG(p->fts_statp->st_mode)) { | 267 | if (keys & F_SHA256 && S_ISREG(p->fts_statp->st_mode)) { | |
268 | if (SHA256_File(p->fts_accpath, digestbuf) == NULL) | 268 | if (SHA256_File(p->fts_accpath, digestbuf) == NULL) | |
269 | mtree_err("%s: %s", p->fts_accpath, "SHA256_File"); | 269 | mtree_err("%s: %s", p->fts_accpath, "SHA256_File"); | |
270 | output(&indent, "sha256=%s", digestbuf); | 270 | output(&indent, "sha256=%s", digestbuf); | |
271 | } | 271 | } | |
272 | if (keys & F_SHA384 && S_ISREG(p->fts_statp->st_mode)) { | 272 | if (keys & F_SHA384 && S_ISREG(p->fts_statp->st_mode)) { | |
273 | if (SHA384_File(p->fts_accpath, digestbuf) == NULL) | 273 | if (SHA384_File(p->fts_accpath, digestbuf) == NULL) | |
274 | mtree_err("%s: %s", p->fts_accpath, "SHA384_File"); | 274 | mtree_err("%s: %s", p->fts_accpath, "SHA384_File"); | |
275 | output(&indent, "sha384=%s", digestbuf); | 275 | output(&indent, "sha384=%s", digestbuf); | |
276 | } | 276 | } | |
277 | if (keys & F_SHA512 && S_ISREG(p->fts_statp->st_mode)) { | 277 | if (keys & F_SHA512 && S_ISREG(p->fts_statp->st_mode)) { | |
278 | if (SHA512_File(p->fts_accpath, digestbuf) == NULL) | 278 | if (SHA512_File(p->fts_accpath, digestbuf) == NULL) | |
279 | mtree_err("%s: %s", p->fts_accpath, "SHA512_File"); | 279 | mtree_err("%s: %s", p->fts_accpath, "SHA512_File"); | |
280 | output(&indent, "sha512=%s", digestbuf); | 280 | output(&indent, "sha512=%s", digestbuf); | |
281 | } | 281 | } | |
282 | #endif /* ! NO_SHA2 */ | 282 | #endif /* ! NO_SHA2 */ | |
283 | if (keys & F_SLINK && | 283 | if (keys & F_SLINK && | |
284 | (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) | 284 | (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) | |
285 | output(&indent, "link=%s", vispath(rlink(p->fts_accpath))); | 285 | output(&indent, "link=%s", vispath(rlink(p->fts_accpath))); | |
286 | #if HAVE_STRUCT_STAT_ST_FLAGS | 286 | #if HAVE_STRUCT_STAT_ST_FLAGS | |
287 | if (keys & F_FLAGS && p->fts_statp->st_flags != flags) | 287 | if (keys & F_FLAGS && p->fts_statp->st_flags != flags) | |
288 | output(&indent, "flags=%s", | 288 | output(&indent, "flags=%s", | |
289 | flags_to_string(p->fts_statp->st_flags, "none")); | 289 | flags_to_string(p->fts_statp->st_flags, "none")); | |
290 | #endif | 290 | #endif | |
291 | putchar('\n'); | 291 | putchar('\n'); | |
292 | } | 292 | } | |
293 | 293 | |||
294 | /* XXX | 294 | /* XXX | |
295 | * FLAGS2INDEX will fail once the user and system settable bits need more | 295 | * FLAGS2INDEX will fail once the user and system settable bits need more | |
296 | * than one byte, respectively. | 296 | * than one byte, respectively. | |
297 | */ | 297 | */ | |
298 | #define FLAGS2INDEX(x) (((x >> 8) & 0x0000ff00) | (x & 0x000000ff)) | 298 | #define FLAGS2INDEX(x) (((x >> 8) & 0x0000ff00) | (x & 0x000000ff)) | |
299 | 299 | |||
300 | #define MTREE_MAXGID 5000 | 300 | #define MTREE_MAXGID 5000 | |
301 | #define MTREE_MAXUID 5000 | 301 | #define MTREE_MAXUID 5000 | |
302 | #define MTREE_MAXMODE (MBITS + 1) | 302 | #define MTREE_MAXMODE (MBITS + 1) | |
303 | #if HAVE_STRUCT_STAT_ST_FLAGS | 303 | #if HAVE_STRUCT_STAT_ST_FLAGS | |
304 | #define MTREE_MAXFLAGS (FLAGS2INDEX(CH_MASK) + 1) /* 1808 */ | 304 | #define MTREE_MAXFLAGS (FLAGS2INDEX(CH_MASK) + 1) /* 1808 */ | |
305 | #else | 305 | #else | |
306 | #define MTREE_MAXFLAGS 1 | 306 | #define MTREE_MAXFLAGS 1 | |
307 | #endif | 307 | #endif | |
308 | #define MTREE_MAXS 16 | 308 | #define MTREE_MAXS 16 | |
309 | 309 | |||
310 | static int | 310 | static int | |
311 | statd(FTS *t, FTSENT *parent, uid_t *puid, gid_t *pgid, mode_t *pmode, | 311 | statd(FTS *t, FTSENT *parent, uid_t *puid, gid_t *pgid, mode_t *pmode, | |
312 | u_long *pflags) | 312 | u_long *pflags) | |
313 | { | 313 | { | |
314 | FTSENT *p; | 314 | FTSENT *p; | |
315 | gid_t sgid; | 315 | gid_t sgid; | |
316 | uid_t suid; | 316 | uid_t suid; | |
317 | mode_t smode; | 317 | mode_t smode; | |
318 | u_long sflags = 0; | 318 | u_long sflags = 0; | |
319 | const char *name; | 319 | const char *name; | |
320 | gid_t savegid; | 320 | gid_t savegid; | |
321 | uid_t saveuid; | 321 | uid_t saveuid; | |
322 | mode_t savemode; | 322 | mode_t savemode; | |
323 | u_long saveflags; | 323 | u_long saveflags; | |
324 | u_short maxgid, maxuid, maxmode, maxflags; | 324 | u_short maxgid, maxuid, maxmode, maxflags; | |
325 | u_short g[MTREE_MAXGID], u[MTREE_MAXUID], | 325 | u_short g[MTREE_MAXGID], u[MTREE_MAXUID], | |
326 | m[MTREE_MAXMODE], f[MTREE_MAXFLAGS]; | 326 | m[MTREE_MAXMODE], f[MTREE_MAXFLAGS]; | |
327 | static int first = 1; | 327 | static int first = 1; | |
328 | 328 | |||
329 | savegid = *pgid; | 329 | savegid = *pgid; | |
330 | saveuid = *puid; | 330 | saveuid = *puid; | |
331 | savemode = *pmode; | 331 | savemode = *pmode; | |
332 | saveflags = *pflags; | 332 | saveflags = *pflags; | |
333 | if ((p = fts_children(t, 0)) == NULL) { | 333 | if ((p = fts_children(t, 0)) == NULL) { | |
334 | if (errno) | 334 | if (errno) | |
335 | mtree_err("%s: %s", RP(parent), strerror(errno)); | 335 | mtree_err("%s: %s", RP(parent), strerror(errno)); | |
336 | return (1); | 336 | return (1); | |
337 | } | 337 | } | |
338 | 338 | |||
339 | memset(g, 0, sizeof(g)); | 339 | memset(g, 0, sizeof(g)); | |
340 | memset(u, 0, sizeof(u)); | 340 | memset(u, 0, sizeof(u)); | |
341 | memset(m, 0, sizeof(m)); | 341 | memset(m, 0, sizeof(m)); | |
342 | memset(f, 0, sizeof(f)); | 342 | memset(f, 0, sizeof(f)); | |
343 | 343 | |||
344 | maxuid = maxgid = maxmode = maxflags = 0; | 344 | maxuid = maxgid = maxmode = maxflags = 0; | |
345 | for (; p; p = p->fts_link) { | 345 | for (; p; p = p->fts_link) { | |
346 | smode = p->fts_statp->st_mode & MBITS; | 346 | smode = p->fts_statp->st_mode & MBITS; | |
347 | if (smode < MTREE_MAXMODE && ++m[smode] > maxmode) { | 347 | if (smode < MTREE_MAXMODE && ++m[smode] > maxmode) { | |
348 | savemode = smode; | 348 | savemode = smode; | |
349 | maxmode = m[smode]; | 349 | maxmode = m[smode]; | |
350 | } | 350 | } | |
351 | sgid = p->fts_statp->st_gid; | 351 | sgid = p->fts_statp->st_gid; | |
352 | if (sgid < MTREE_MAXGID && ++g[sgid] > maxgid) { | 352 | if (sgid < MTREE_MAXGID && ++g[sgid] > maxgid) { | |
353 | savegid = sgid; | 353 | savegid = sgid; | |
354 | maxgid = g[sgid]; | 354 | maxgid = g[sgid]; | |
355 | } | 355 | } | |
356 | suid = p->fts_statp->st_uid; | 356 | suid = p->fts_statp->st_uid; | |
357 | if (suid < MTREE_MAXUID && ++u[suid] > maxuid) { | 357 | if (suid < MTREE_MAXUID && ++u[suid] > maxuid) { | |
358 | saveuid = suid; | 358 | saveuid = suid; | |
359 | maxuid = u[suid]; | 359 | maxuid = u[suid]; | |
360 | } | 360 | } | |
361 | 361 | |||
362 | #if HAVE_STRUCT_STAT_ST_FLAGS | 362 | #if HAVE_STRUCT_STAT_ST_FLAGS | |
363 | sflags = FLAGS2INDEX(p->fts_statp->st_flags); | 363 | sflags = FLAGS2INDEX(p->fts_statp->st_flags); | |
364 | if (sflags < MTREE_MAXFLAGS && ++f[sflags] > maxflags) { | 364 | if (sflags < MTREE_MAXFLAGS && ++f[sflags] > maxflags) { | |
365 | saveflags = p->fts_statp->st_flags; | 365 | saveflags = p->fts_statp->st_flags; | |
366 | maxflags = f[sflags]; | 366 | maxflags = f[sflags]; | |
367 | } | 367 | } | |
368 | #endif | 368 | #endif | |
369 | } | 369 | } | |
370 | /* | 370 | /* | |
371 | * If the /set record is the same as the last one we do not need to | 371 | * If the /set record is the same as the last one we do not need to | |
372 | * output a new one. So first we check to see if anything changed. | 372 | * output a new one. So first we check to see if anything changed. | |
373 | * Note that we always output a /set record for the first directory. | 373 | * Note that we always output a /set record for the first directory. | |
374 | */ | 374 | */ | |
375 | if (((keys & (F_UNAME | F_UID)) && (*puid != saveuid)) || | 375 | if (((keys & (F_UNAME | F_UID)) && (*puid != saveuid)) || | |
376 | ((keys & (F_GNAME | F_GID)) && (*pgid != savegid)) || | 376 | ((keys & (F_GNAME | F_GID)) && (*pgid != savegid)) || | |
377 | ((keys & F_MODE) && (*pmode != savemode)) || | 377 | ((keys & F_MODE) && (*pmode != savemode)) || | |
378 | ((keys & F_FLAGS) && (*pflags != saveflags)) || | 378 | ((keys & F_FLAGS) && (*pflags != saveflags)) || | |
379 | first) { | 379 | first) { | |
380 | first = 0; | 380 | first = 0; | |
381 | printf("/set type=file"); | 381 | printf("/set type=file"); | |
382 | if (keys & (F_UID | F_UNAME)) { | 382 | if (keys & (F_UID | F_UNAME)) { | |
383 | if (keys & F_UNAME && | 383 | if (keys & F_UNAME && | |
384 | (name = user_from_uid(saveuid, 1)) != NULL) | 384 | (name = user_from_uid(saveuid, 1)) != NULL) | |
385 | printf(" uname=%s", name); | 385 | printf(" uname=%s", name); | |
386 | else /* if (keys & F_UID) */ | 386 | else /* if (keys & F_UID) */ | |
387 | printf(" uid=%lu", (u_long)saveuid); | 387 | printf(" uid=%lu", (u_long)saveuid); | |
388 | } | 388 | } | |
389 | if (keys & (F_GID | F_GNAME)) { | 389 | if (keys & (F_GID | F_GNAME)) { | |
390 | if (keys & F_GNAME && | 390 | if (keys & F_GNAME && | |
391 | (name = group_from_gid(savegid, 1)) != NULL) | 391 | (name = group_from_gid(savegid, 1)) != NULL) | |
392 | printf(" gname=%s", name); | 392 | printf(" gname=%s", name); | |
393 | else /* if (keys & F_UID) */ | 393 | else /* if (keys & F_UID) */ | |
394 | printf(" gid=%lu", (u_long)savegid); | 394 | printf(" gid=%lu", (u_long)savegid); | |
395 | } | 395 | } | |
396 | if (keys & F_MODE) | 396 | if (keys & F_MODE) | |
397 | printf(" mode=%#lo", (u_long)savemode); | 397 | printf(" mode=%#lo", (u_long)savemode); | |
398 | if (keys & F_NLINK) | 398 | if (keys & F_NLINK) | |
399 | printf(" nlink=1"); | 399 | printf(" nlink=1"); | |
400 | if (keys & F_FLAGS) | 400 | if (keys & F_FLAGS) | |
401 | printf(" flags=%s", | 401 | printf(" flags=%s", | |
402 | flags_to_string(saveflags, "none")); | 402 | flags_to_string(saveflags, "none")); | |
403 | printf("\n"); | 403 | printf("\n"); | |
404 | *puid = saveuid; | 404 | *puid = saveuid; | |
405 | *pgid = savegid; | 405 | *pgid = savegid; | |
406 | *pmode = savemode; | 406 | *pmode = savemode; | |
407 | *pflags = saveflags; | 407 | *pflags = saveflags; | |
408 | } | 408 | } | |
409 | return (0); | 409 | return (0); | |
410 | } | 410 | } | |
411 | 411 | |||
412 | static int | 412 | static int | |
413 | dsort(const FTSENT **a, const FTSENT **b) | 413 | dsort(const FTSENT **a, const FTSENT **b) | |
414 | { | 414 | { | |
415 | 415 | |||
416 | if (S_ISDIR((*a)->fts_statp->st_mode)) { | 416 | if (S_ISDIR((*a)->fts_statp->st_mode)) { | |
417 | if (!S_ISDIR((*b)->fts_statp->st_mode)) | 417 | if (!S_ISDIR((*b)->fts_statp->st_mode)) | |
418 | return (1); | 418 | return (1); | |
419 | } else if (S_ISDIR((*b)->fts_statp->st_mode)) | 419 | } else if (S_ISDIR((*b)->fts_statp->st_mode)) | |
420 | return (-1); | 420 | return (-1); | |
421 | return (strcmp((*a)->fts_name, (*b)->fts_name)); | 421 | return (strcmp((*a)->fts_name, (*b)->fts_name)); | |
422 | } | 422 | } | |
423 | 423 | |||
424 | void | 424 | void | |
425 | output(int *offset, const char *fmt, ...) | 425 | output(int *offset, const char *fmt, ...) | |
426 | { | 426 | { | |
427 | va_list ap; | 427 | va_list ap; | |
428 | char buf[1024]; | 428 | char buf[1024]; | |
429 | 429 | |||
430 | va_start(ap, fmt); | 430 | va_start(ap, fmt); | |
431 | vsnprintf(buf, sizeof(buf), fmt, ap); | 431 | vsnprintf(buf, sizeof(buf), fmt, ap); | |
432 | va_end(ap); | 432 | va_end(ap); | |
433 | 433 | |||
434 | if (*offset + strlen(buf) > MAXLINELEN - 3) { | 434 | if (*offset + strlen(buf) > MAXLINELEN - 3) { | |
435 | printf(" \\\n%*s", INDENTNAMELEN, ""); | 435 | printf(" \\\n%*s", INDENTNAMELEN, ""); | |
436 | *offset = INDENTNAMELEN; | 436 | *offset = INDENTNAMELEN; | |
437 | } | 437 | } | |
438 | *offset += printf(" %s", buf) + 1; | 438 | *offset += printf(" %s", buf) + 1; | |
439 | } | 439 | } |
@@ -1,91 +1,91 @@ | @@ -1,91 +1,91 @@ | |||
1 | /* $NetBSD: extern.h,v 1.3 2008/11/06 02:14:52 jschauma Exp $ */ | 1 | /* $NetBSD: extern.h,v 1.4 2010/03/21 16:30:17 joerg Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1991, 1993 | 4 | * Copyright (c) 1991, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3. Neither the name of the University nor the names of its contributors | 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 | 16 | * may be used to endorse or promote products derived from this software | |
17 | * without specific prior written permission. | 17 | * without specific prior written permission. | |
18 | * | 18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | * | 30 | * | |
31 | * @(#)extern.h 8.1 (Berkeley) 6/6/93 | 31 | * @(#)extern.h 8.1 (Berkeley) 6/6/93 | |
32 | */ | 32 | */ | |
33 | 33 | |||
34 | #if HAVE_CONFIG_H | 34 | #if HAVE_CONFIG_H | |
35 | #include "config.h" | 35 | #include "config.h" | |
36 | #endif | 36 | #endif | |
37 | #include "mtree.h" | 37 | #include "mtree.h" | |
38 | 38 | |||
39 | #if HAVE_NBTOOL_CONFIG_H | 39 | #if HAVE_NBTOOL_CONFIG_H | |
40 | #include "nbtool_config.h" | 40 | #include "nbtool_config.h" | |
41 | #else | 41 | #else | |
42 | #define HAVE_STRUCT_STAT_ST_FLAGS 1 | 42 | #define HAVE_STRUCT_STAT_ST_FLAGS 1 | |
43 | #endif | 43 | #endif | |
44 | 44 | |||
45 | #include <nbcompat.h> | 45 | #include <nbcompat.h> | |
46 | #if HAVE_ERR_H | 46 | #if HAVE_ERR_H | |
47 | #include <err.h> | 47 | #include <err.h> | |
48 | #endif | 48 | #endif | |
49 | #if HAVE_FTS_H | 49 | #if HAVE_FTS_H | |
50 | #include <fts.h> | 50 | #include <fts.h> | |
51 | #endif | 51 | #endif | |
52 | 52 | |||
53 | #if HAVE_NETDB_H | 53 | #if HAVE_NETDB_H | |
54 | /* For MAXHOSTNAMELEN on some platforms. */ | 54 | /* For MAXHOSTNAMELEN on some platforms. */ | |
55 | #if HAVE_NETDB_H | 55 | #if HAVE_NETDB_H | |
56 | #include <netdb.h> | 56 | #include <netdb.h> | |
57 | #endif | 57 | #endif | |
58 | #endif | 58 | #endif | |
59 | 59 | |||
60 | #ifndef MAXHOSTNAMELEN | 60 | #ifndef MAXHOSTNAMELEN | |
61 | #define MAXHOSTNAMELEN 256 | 61 | #define MAXHOSTNAMELEN 256 | |
62 | #endif | 62 | #endif | |
63 | 63 | |||
64 | void addtag(slist_t *, char *); | 64 | void addtag(slist_t *, char *); | |
65 | int check_excludes(const char *, const char *); | 65 | int check_excludes(const char *, const char *); | |
66 | int compare(NODE *, FTSENT *); | 66 | int compare(NODE *, FTSENT *); | |
67 | int crc(int, u_int32_t *, u_int32_t *); | 67 | int crc(int, uint32_t *, uint32_t *); | |
68 | void cwalk(void); | 68 | void cwalk(void); | |
69 | void dump_nodes(const char *, NODE *, int); | 69 | void dump_nodes(const char *, NODE *, int); | |
70 | void init_excludes(void); | 70 | void init_excludes(void); | |
71 | int matchtags(NODE *); | 71 | int matchtags(NODE *); | |
72 | void mtree_err(const char *, ...) | 72 | void mtree_err(const char *, ...) | |
73 | __attribute__((__format__(__printf__, 1, 2))); | 73 | __attribute__((__format__(__printf__, 1, 2))); | |
74 | const char *nodetype(u_int); | 74 | const char *nodetype(u_int); | |
75 | u_int parsekey(const char *, int *); | 75 | u_int parsekey(const char *, int *); | |
76 | void parsetags(slist_t *, char *); | 76 | void parsetags(slist_t *, char *); | |
77 | u_int parsetype(const char *); | 77 | u_int parsetype(const char *); | |
78 | void read_excludes_file(const char *); | 78 | void read_excludes_file(const char *); | |
79 | const char *rlink(const char *); | 79 | const char *rlink(const char *); | |
80 | int verify(void); | 80 | int verify(void); | |
81 | 81 | |||
82 | extern int dflag, eflag, iflag, lflag, mflag, rflag, sflag, tflag, uflag; | 82 | extern int dflag, eflag, iflag, lflag, mflag, rflag, sflag, tflag, uflag; | |
83 | extern int mtree_Mflag, mtree_Wflag; | 83 | extern int mtree_Mflag, mtree_Wflag; | |
84 | extern size_t mtree_lineno; | 84 | extern size_t mtree_lineno; | |
85 | extern u_int32_t crc_total; | 85 | extern uint32_t crc_total; | |
86 | extern int ftsoptions, keys; | 86 | extern int ftsoptions, keys; | |
87 | extern char fullpath[]; | 87 | extern char fullpath[]; | |
88 | extern slist_t includetags, excludetags; | 88 | extern slist_t includetags, excludetags; | |
89 | 89 | |||
90 | 90 | |||
91 | #include "stat_flags.h" | 91 | #include "stat_flags.h" |