2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 static char sccsid[] = "@(#)spec.c 8.1 (Berkeley) 6/6/93";
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <sys/types.h>
52 int lineno; /* Current spec line number. */
54 static void set(char *, NODE *);
55 static void unset(char *, NODE *);
58 mtree_readspec(FILE *fi)
66 centry = last = root = NULL;
67 bzero(&ginfo, sizeof(ginfo));
69 for (lineno = 1; fgets(buf, sizeof(buf), fi);
70 ++lineno, c_cur = c_next, c_next = 0) {
71 /* Skip empty lines. */
75 /* Find end of line. */
76 if ((p = strchr(buf, '\n')) == NULL)
77 errx(1, "line %d too long", lineno);
79 /* See if next line is continuation line. */
85 /* Null-terminate the line. */
88 /* Skip leading whitespace. */
89 for (p = buf; *p && isspace(*p); ++p);
91 /* If nothing but whitespace or comment char, continue. */
96 (void)fprintf(stderr, "line %d: {%s}\n", lineno, p);
103 /* Grab file name, "$", "set", or "unset". */
104 if ((p = strtok(p, "\n\t ")) == NULL)
105 errx(1, "line %d: missing field", lineno);
110 if (strcmp(p + 1, "set"))
115 if (strcmp(p + 1, "unset"))
122 errx(1, "line %d: slash character in file name",
125 if (!strcmp(p, "..")) {
126 /* Don't go up, if haven't gone down. */
129 if (last->type != F_DIR || last->flags & F_DONE) {
134 last->flags |= F_DONE;
137 noparent: errx(1, "line %d: no parent node", lineno);
140 if ((centry = calloc(1, sizeof(NODE) + strlen(p))) == NULL)
144 if (strpbrk(p, MAGIC))
145 centry->flags |= F_MAGIC;
146 if (strunvis(centry->name, p) == -1)
147 errx(1, "filename %s is ill-encoded", p);
151 last = root = centry;
153 } else if (last->type == F_DIR && !(last->flags & F_DONE)) {
154 centry->parent = last;
155 last = last->child = centry;
157 centry->parent = last->parent;
159 last = last->next = centry;
166 set(char *t, NODE *ip)
169 char *kw, *val = NULL;
176 for (; (kw = strtok(t, "= \t\n")); t = NULL) {
177 ip->flags |= type = parsekey(kw, &value);
178 if (value && (val = strtok(NULL, " \t\n")) == NULL)
179 errx(1, "line %d: missing value", lineno);
182 ip->cksum = strtoul(val, &ep, 10);
184 errx(1, "line %d: invalid checksum %s",
188 ip->md5digest = strdup(val);
193 ip->sha1digest = strdup(val);
198 ip->sha256digest = strdup(val);
199 if(!ip->sha256digest)
203 ip->rmd160digest = strdup(val);
204 if(!ip->rmd160digest)
208 if (strcmp("none", val) == 0)
210 else if (strtofflags(&val, &ip->st_flags, NULL) != 0)
211 errx(1, "line %d: invalid flag %s",lineno, val);
214 ip->st_gid = strtoul(val, &ep, 10);
216 errx(1, "line %d: invalid gid %s", lineno, val);
219 if ((gr = getgrnam(val)) == NULL)
220 errx(1, "line %d: unknown group %s", lineno, val);
221 ip->st_gid = gr->gr_gid;
224 /* just set flag bit */
227 if ((m = setmode(val)) == NULL)
228 errx(1, "line %d: invalid file mode %s",
230 ip->st_mode = getmode(m, 0);
234 ip->st_nlink = strtoul(val, &ep, 10);
236 errx(1, "line %d: invalid link count %s",
240 /* just set flag bit */
243 ip->st_size = strtoq(val, &ep, 10);
245 errx(1, "line %d: invalid size %s",
249 ip->slink = malloc(strlen(val) + 1);
250 if (ip->slink == NULL)
252 if (strunvis(ip->slink, val) == -1)
253 errx(1, "symlink %s is ill-encoded", val);
256 ip->st_mtimespec.tv_sec = strtoul(val, &ep, 10);
258 /* Note: we require exactly nine
259 * digits after the decimal point. */
261 ip->st_mtimespec.tv_nsec
262 = strtoul(val, &ep, 10);
264 ip->st_mtimespec.tv_nsec = 0;
266 errx(1, "line %d: invalid time %s",
272 if (!strcmp(val, "block"))
276 if (!strcmp(val, "char"))
280 if (!strcmp(val, "dir"))
284 if (!strcmp(val, "file"))
286 if (!strcmp(val, "fifo"))
290 if (!strcmp(val, "link"))
294 if (!strcmp(val, "socket"))
298 errx(1, "line %d: unknown file type %s",
303 ip->st_uid = strtoul(val, &ep, 10);
305 errx(1, "line %d: invalid uid %s", lineno, val);
308 if ((pw = getpwnam(val)) == NULL)
309 errx(1, "line %d: unknown user %s", lineno, val);
310 ip->st_uid = pw->pw_uid;
317 unset(char *t, NODE *ip)
321 while ((p = strtok(t, "\n\t ")))
322 ip->flags &= ~parsekey(p, NULL);