1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
27*7c478bd9Sstevel@tonic-gate
28*7c478bd9Sstevel@tonic-gate #include <unistd.h>
29*7c478bd9Sstevel@tonic-gate #include "bart.h"
30*7c478bd9Sstevel@tonic-gate
31*7c478bd9Sstevel@tonic-gate static int compare_manifests(FILE *rulesfile, char *control, char *test,
32*7c478bd9Sstevel@tonic-gate boolean_t prog_fmt, uint_t flags);
33*7c478bd9Sstevel@tonic-gate static void extract_fname_ftype(char *line, char *fname, char *type);
34*7c478bd9Sstevel@tonic-gate static int report_add(char *fname, char *type);
35*7c478bd9Sstevel@tonic-gate static int report_delete(char *fname, char *type);
36*7c478bd9Sstevel@tonic-gate static int evaluate_differences(char *control_line, char *test_line,
37*7c478bd9Sstevel@tonic-gate boolean_t prog_fmt, int flags);
38*7c478bd9Sstevel@tonic-gate static void report_error(char *fname, char *type, char *ctrl_val,
39*7c478bd9Sstevel@tonic-gate char *test_val, boolean_t prog_fmt);
40*7c478bd9Sstevel@tonic-gate static int read_manifest_line(FILE *fd, char *buf, int buf_size, int start_pos,
41*7c478bd9Sstevel@tonic-gate char **line, char *fname);
42*7c478bd9Sstevel@tonic-gate static void parse_line(char *line, char *fname, char *type, char *size,
43*7c478bd9Sstevel@tonic-gate char *mode, char *acl, char *mtime, char *uid, char *gid, char *contents,
44*7c478bd9Sstevel@tonic-gate char *devnode, char *dest);
45*7c478bd9Sstevel@tonic-gate static void init_default_flags(uint_t *flags);
46*7c478bd9Sstevel@tonic-gate static void get_token(char *line, int *curr_pos, int line_len, char *buf,
47*7c478bd9Sstevel@tonic-gate int buf_size);
48*7c478bd9Sstevel@tonic-gate
49*7c478bd9Sstevel@tonic-gate int
bart_compare(int argc,char ** argv)50*7c478bd9Sstevel@tonic-gate bart_compare(int argc, char **argv)
51*7c478bd9Sstevel@tonic-gate {
52*7c478bd9Sstevel@tonic-gate char *control_fname, *test_fname;
53*7c478bd9Sstevel@tonic-gate int c;
54*7c478bd9Sstevel@tonic-gate FILE *rules_fd = NULL;
55*7c478bd9Sstevel@tonic-gate uint_t glob_flags;
56*7c478bd9Sstevel@tonic-gate boolean_t prog_fmt = B_FALSE;
57*7c478bd9Sstevel@tonic-gate
58*7c478bd9Sstevel@tonic-gate init_default_flags(&glob_flags);
59*7c478bd9Sstevel@tonic-gate
60*7c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "pr:i:")) != EOF) {
61*7c478bd9Sstevel@tonic-gate switch (c) {
62*7c478bd9Sstevel@tonic-gate case 'p':
63*7c478bd9Sstevel@tonic-gate prog_fmt = B_TRUE;
64*7c478bd9Sstevel@tonic-gate break;
65*7c478bd9Sstevel@tonic-gate
66*7c478bd9Sstevel@tonic-gate case 'r':
67*7c478bd9Sstevel@tonic-gate if (optarg == NULL)
68*7c478bd9Sstevel@tonic-gate usage();
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gate if (strcmp(optarg, "-") == 0)
71*7c478bd9Sstevel@tonic-gate rules_fd = stdin;
72*7c478bd9Sstevel@tonic-gate else
73*7c478bd9Sstevel@tonic-gate rules_fd = fopen(optarg, "r");
74*7c478bd9Sstevel@tonic-gate if (rules_fd == NULL) {
75*7c478bd9Sstevel@tonic-gate perror(optarg);
76*7c478bd9Sstevel@tonic-gate usage();
77*7c478bd9Sstevel@tonic-gate }
78*7c478bd9Sstevel@tonic-gate break;
79*7c478bd9Sstevel@tonic-gate
80*7c478bd9Sstevel@tonic-gate case 'i':
81*7c478bd9Sstevel@tonic-gate process_glob_ignores(optarg, &glob_flags);
82*7c478bd9Sstevel@tonic-gate break;
83*7c478bd9Sstevel@tonic-gate
84*7c478bd9Sstevel@tonic-gate case '?':
85*7c478bd9Sstevel@tonic-gate default:
86*7c478bd9Sstevel@tonic-gate usage();
87*7c478bd9Sstevel@tonic-gate }
88*7c478bd9Sstevel@tonic-gate }
89*7c478bd9Sstevel@tonic-gate
90*7c478bd9Sstevel@tonic-gate /* Make sure we have the right number of args */
91*7c478bd9Sstevel@tonic-gate if ((optind + 2) != argc)
92*7c478bd9Sstevel@tonic-gate usage();
93*7c478bd9Sstevel@tonic-gate argv += optind;
94*7c478bd9Sstevel@tonic-gate control_fname = argv[0];
95*7c478bd9Sstevel@tonic-gate test_fname = argv[1];
96*7c478bd9Sstevel@tonic-gate /* At this point, the filenames are sane, so do the comparison */
97*7c478bd9Sstevel@tonic-gate return (compare_manifests(rules_fd, control_fname, test_fname,
98*7c478bd9Sstevel@tonic-gate prog_fmt, glob_flags));
99*7c478bd9Sstevel@tonic-gate }
100*7c478bd9Sstevel@tonic-gate
101*7c478bd9Sstevel@tonic-gate static int
compare_manifests(FILE * rulesfile,char * control,char * test,boolean_t prog_fmt,uint_t flags)102*7c478bd9Sstevel@tonic-gate compare_manifests(FILE *rulesfile, char *control, char *test,
103*7c478bd9Sstevel@tonic-gate boolean_t prog_fmt, uint_t flags)
104*7c478bd9Sstevel@tonic-gate {
105*7c478bd9Sstevel@tonic-gate FILE *control_fd, *test_fd;
106*7c478bd9Sstevel@tonic-gate char *control_line, *test_line, control_buf[BUF_SIZE],
107*7c478bd9Sstevel@tonic-gate test_buf[BUF_SIZE], control_fname[PATH_MAX],
108*7c478bd9Sstevel@tonic-gate control_type[TYPE_SIZE], test_fname[PATH_MAX],
109*7c478bd9Sstevel@tonic-gate test_type[TYPE_SIZE];
110*7c478bd9Sstevel@tonic-gate int control_pos, test_pos, ret, fname_cmp, return_status;
111*7c478bd9Sstevel@tonic-gate
112*7c478bd9Sstevel@tonic-gate return_status = EXIT;
113*7c478bd9Sstevel@tonic-gate
114*7c478bd9Sstevel@tonic-gate return_status = read_rules(rulesfile, "", flags, 0);
115*7c478bd9Sstevel@tonic-gate
116*7c478bd9Sstevel@tonic-gate control_fd = fopen(control, "r");
117*7c478bd9Sstevel@tonic-gate if (control_fd == NULL) {
118*7c478bd9Sstevel@tonic-gate perror(control);
119*7c478bd9Sstevel@tonic-gate return (FATAL_EXIT);
120*7c478bd9Sstevel@tonic-gate }
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate test_fd = fopen(test, "r");
123*7c478bd9Sstevel@tonic-gate if (test_fd == NULL) {
124*7c478bd9Sstevel@tonic-gate perror(test);
125*7c478bd9Sstevel@tonic-gate return (FATAL_EXIT);
126*7c478bd9Sstevel@tonic-gate }
127*7c478bd9Sstevel@tonic-gate
128*7c478bd9Sstevel@tonic-gate control_pos = read_manifest_line(control_fd, control_buf,
129*7c478bd9Sstevel@tonic-gate BUF_SIZE, 0, &control_line, control);
130*7c478bd9Sstevel@tonic-gate test_pos = read_manifest_line(test_fd, test_buf, BUF_SIZE, 0,
131*7c478bd9Sstevel@tonic-gate &test_line, test);
132*7c478bd9Sstevel@tonic-gate
133*7c478bd9Sstevel@tonic-gate while ((control_pos != -1) && (test_pos != -1)) {
134*7c478bd9Sstevel@tonic-gate ret = strcmp(control_line, test_line);
135*7c478bd9Sstevel@tonic-gate if (ret == 0) {
136*7c478bd9Sstevel@tonic-gate /* Lines compare OK, just read the next lines.... */
137*7c478bd9Sstevel@tonic-gate control_pos = read_manifest_line(control_fd,
138*7c478bd9Sstevel@tonic-gate control_buf, BUF_SIZE, control_pos, &control_line,
139*7c478bd9Sstevel@tonic-gate control);
140*7c478bd9Sstevel@tonic-gate test_pos = read_manifest_line(test_fd, test_buf,
141*7c478bd9Sstevel@tonic-gate BUF_SIZE, test_pos, &test_line, test);
142*7c478bd9Sstevel@tonic-gate continue;
143*7c478bd9Sstevel@tonic-gate }
144*7c478bd9Sstevel@tonic-gate
145*7c478bd9Sstevel@tonic-gate /*
146*7c478bd9Sstevel@tonic-gate * Something didn't compare properly.
147*7c478bd9Sstevel@tonic-gate */
148*7c478bd9Sstevel@tonic-gate extract_fname_ftype(control_line, control_fname, control_type);
149*7c478bd9Sstevel@tonic-gate extract_fname_ftype(test_line, test_fname, test_type);
150*7c478bd9Sstevel@tonic-gate fname_cmp = strcmp(control_fname, test_fname);
151*7c478bd9Sstevel@tonic-gate
152*7c478bd9Sstevel@tonic-gate if (fname_cmp == 0) {
153*7c478bd9Sstevel@tonic-gate /*
154*7c478bd9Sstevel@tonic-gate * Filenames were the same, see what was
155*7c478bd9Sstevel@tonic-gate * different and continue.
156*7c478bd9Sstevel@tonic-gate */
157*7c478bd9Sstevel@tonic-gate if (evaluate_differences(control_line, test_line,
158*7c478bd9Sstevel@tonic-gate prog_fmt, flags) != 0)
159*7c478bd9Sstevel@tonic-gate return_status = WARNING_EXIT;
160*7c478bd9Sstevel@tonic-gate
161*7c478bd9Sstevel@tonic-gate control_pos = read_manifest_line(control_fd,
162*7c478bd9Sstevel@tonic-gate control_buf, BUF_SIZE, control_pos, &control_line,
163*7c478bd9Sstevel@tonic-gate control);
164*7c478bd9Sstevel@tonic-gate test_pos = read_manifest_line(test_fd, test_buf,
165*7c478bd9Sstevel@tonic-gate BUF_SIZE, test_pos, &test_line, test);
166*7c478bd9Sstevel@tonic-gate } else if (fname_cmp > 0) {
167*7c478bd9Sstevel@tonic-gate /* Filenames were different, a files was ADDED */
168*7c478bd9Sstevel@tonic-gate if (report_add(test_fname, test_type)) {
169*7c478bd9Sstevel@tonic-gate report_error(test_fname, ADD_KEYWORD, NULL,
170*7c478bd9Sstevel@tonic-gate NULL, prog_fmt);
171*7c478bd9Sstevel@tonic-gate return_status = WARNING_EXIT;
172*7c478bd9Sstevel@tonic-gate }
173*7c478bd9Sstevel@tonic-gate test_pos = read_manifest_line(test_fd, test_buf,
174*7c478bd9Sstevel@tonic-gate BUF_SIZE, test_pos, &test_line, test);
175*7c478bd9Sstevel@tonic-gate } else if (fname_cmp < 0) {
176*7c478bd9Sstevel@tonic-gate /* Filenames were different, a files was DELETED */
177*7c478bd9Sstevel@tonic-gate if (report_delete(control_fname, control_type)) {
178*7c478bd9Sstevel@tonic-gate report_error(control_fname, DELETE_KEYWORD,
179*7c478bd9Sstevel@tonic-gate NULL, NULL, prog_fmt);
180*7c478bd9Sstevel@tonic-gate return_status = WARNING_EXIT;
181*7c478bd9Sstevel@tonic-gate }
182*7c478bd9Sstevel@tonic-gate control_pos = read_manifest_line(control_fd,
183*7c478bd9Sstevel@tonic-gate control_buf, BUF_SIZE, control_pos, &control_line,
184*7c478bd9Sstevel@tonic-gate control);
185*7c478bd9Sstevel@tonic-gate }
186*7c478bd9Sstevel@tonic-gate }
187*7c478bd9Sstevel@tonic-gate
188*7c478bd9Sstevel@tonic-gate /*
189*7c478bd9Sstevel@tonic-gate * Entering this while loop means files were DELETED from the test
190*7c478bd9Sstevel@tonic-gate * manifest.
191*7c478bd9Sstevel@tonic-gate */
192*7c478bd9Sstevel@tonic-gate while (control_pos != -1) {
193*7c478bd9Sstevel@tonic-gate (void) sscanf(control_line, "%1023s", control_fname);
194*7c478bd9Sstevel@tonic-gate if (report_delete(control_fname, control_type)) {
195*7c478bd9Sstevel@tonic-gate report_error(control_fname, DELETE_KEYWORD, NULL,
196*7c478bd9Sstevel@tonic-gate NULL, prog_fmt);
197*7c478bd9Sstevel@tonic-gate return_status = WARNING_EXIT;
198*7c478bd9Sstevel@tonic-gate }
199*7c478bd9Sstevel@tonic-gate control_pos = read_manifest_line(control_fd, control_buf,
200*7c478bd9Sstevel@tonic-gate BUF_SIZE, control_pos, &control_line, control);
201*7c478bd9Sstevel@tonic-gate }
202*7c478bd9Sstevel@tonic-gate
203*7c478bd9Sstevel@tonic-gate /*
204*7c478bd9Sstevel@tonic-gate * Entering this while loop means files were ADDED to the test
205*7c478bd9Sstevel@tonic-gate * manifest.
206*7c478bd9Sstevel@tonic-gate */
207*7c478bd9Sstevel@tonic-gate while (test_pos != -1) {
208*7c478bd9Sstevel@tonic-gate (void) sscanf(test_line, "%1023s", test_fname);
209*7c478bd9Sstevel@tonic-gate if (report_add(test_fname, test_type)) {
210*7c478bd9Sstevel@tonic-gate report_error(test_fname, ADD_KEYWORD, NULL,
211*7c478bd9Sstevel@tonic-gate NULL, prog_fmt);
212*7c478bd9Sstevel@tonic-gate return_status = WARNING_EXIT;
213*7c478bd9Sstevel@tonic-gate }
214*7c478bd9Sstevel@tonic-gate test_pos = read_manifest_line(test_fd, test_buf,
215*7c478bd9Sstevel@tonic-gate BUF_SIZE, test_pos, &test_line, test);
216*7c478bd9Sstevel@tonic-gate }
217*7c478bd9Sstevel@tonic-gate
218*7c478bd9Sstevel@tonic-gate (void) fclose(control_fd);
219*7c478bd9Sstevel@tonic-gate (void) fclose(test_fd);
220*7c478bd9Sstevel@tonic-gate
221*7c478bd9Sstevel@tonic-gate /* For programmatic mode, add a newline for cosmetic reasons */
222*7c478bd9Sstevel@tonic-gate if (prog_fmt && (return_status != 0))
223*7c478bd9Sstevel@tonic-gate (void) printf("\n");
224*7c478bd9Sstevel@tonic-gate
225*7c478bd9Sstevel@tonic-gate return (return_status);
226*7c478bd9Sstevel@tonic-gate }
227*7c478bd9Sstevel@tonic-gate
228*7c478bd9Sstevel@tonic-gate static void
parse_line(char * line,char * fname,char * type,char * size,char * mode,char * acl,char * mtime,char * uid,char * gid,char * contents,char * devnode,char * dest)229*7c478bd9Sstevel@tonic-gate parse_line(char *line, char *fname, char *type, char *size, char *mode,
230*7c478bd9Sstevel@tonic-gate char *acl, char *mtime, char *uid, char *gid, char *contents, char *devnode,
231*7c478bd9Sstevel@tonic-gate char *dest)
232*7c478bd9Sstevel@tonic-gate {
233*7c478bd9Sstevel@tonic-gate int pos, line_len;
234*7c478bd9Sstevel@tonic-gate
235*7c478bd9Sstevel@tonic-gate line_len = strlen(line);
236*7c478bd9Sstevel@tonic-gate pos = 0;
237*7c478bd9Sstevel@tonic-gate
238*7c478bd9Sstevel@tonic-gate get_token(line, &pos, line_len, fname, PATH_MAX);
239*7c478bd9Sstevel@tonic-gate get_token(line, &pos, line_len, type, TYPE_SIZE);
240*7c478bd9Sstevel@tonic-gate get_token(line, &pos, line_len, size, MISC_SIZE);
241*7c478bd9Sstevel@tonic-gate get_token(line, &pos, line_len, mode, MISC_SIZE);
242*7c478bd9Sstevel@tonic-gate get_token(line, &pos, line_len, acl, ACL_SIZE);
243*7c478bd9Sstevel@tonic-gate get_token(line, &pos, line_len, mtime, MISC_SIZE);
244*7c478bd9Sstevel@tonic-gate get_token(line, &pos, line_len, uid, MISC_SIZE);
245*7c478bd9Sstevel@tonic-gate get_token(line, &pos, line_len, gid, MISC_SIZE);
246*7c478bd9Sstevel@tonic-gate
247*7c478bd9Sstevel@tonic-gate /* Reset these fields... */
248*7c478bd9Sstevel@tonic-gate
249*7c478bd9Sstevel@tonic-gate *contents = NULL;
250*7c478bd9Sstevel@tonic-gate *devnode = '\0';
251*7c478bd9Sstevel@tonic-gate *dest = '\0';
252*7c478bd9Sstevel@tonic-gate
253*7c478bd9Sstevel@tonic-gate /* Handle filetypes which have a last field..... */
254*7c478bd9Sstevel@tonic-gate if (type[0] == 'F')
255*7c478bd9Sstevel@tonic-gate get_token(line, &pos, line_len, contents, PATH_MAX);
256*7c478bd9Sstevel@tonic-gate else if ((type[0] == 'B') || (type[0] == 'C'))
257*7c478bd9Sstevel@tonic-gate get_token(line, &pos, line_len, devnode, PATH_MAX);
258*7c478bd9Sstevel@tonic-gate else if (type[0] == 'L')
259*7c478bd9Sstevel@tonic-gate get_token(line, &pos, line_len, dest, PATH_MAX);
260*7c478bd9Sstevel@tonic-gate }
261*7c478bd9Sstevel@tonic-gate
262*7c478bd9Sstevel@tonic-gate static void
get_token(char * line,int * curr_pos,int line_len,char * buf,int buf_size)263*7c478bd9Sstevel@tonic-gate get_token(char *line, int *curr_pos, int line_len, char *buf, int buf_size)
264*7c478bd9Sstevel@tonic-gate {
265*7c478bd9Sstevel@tonic-gate int cnt = 0;
266*7c478bd9Sstevel@tonic-gate
267*7c478bd9Sstevel@tonic-gate while (isspace(line[*curr_pos]) && (*curr_pos < line_len))
268*7c478bd9Sstevel@tonic-gate (*curr_pos)++;
269*7c478bd9Sstevel@tonic-gate
270*7c478bd9Sstevel@tonic-gate while (!isspace(line[*curr_pos]) &&
271*7c478bd9Sstevel@tonic-gate (*curr_pos < line_len) && (cnt < (buf_size-1))) {
272*7c478bd9Sstevel@tonic-gate buf[cnt] = line[*curr_pos];
273*7c478bd9Sstevel@tonic-gate (*curr_pos)++;
274*7c478bd9Sstevel@tonic-gate cnt++;
275*7c478bd9Sstevel@tonic-gate }
276*7c478bd9Sstevel@tonic-gate buf[cnt] = '\0';
277*7c478bd9Sstevel@tonic-gate }
278*7c478bd9Sstevel@tonic-gate
279*7c478bd9Sstevel@tonic-gate /*
280*7c478bd9Sstevel@tonic-gate * Utility function: extract fname and type from this line
281*7c478bd9Sstevel@tonic-gate */
282*7c478bd9Sstevel@tonic-gate static void
extract_fname_ftype(char * line,char * fname,char * type)283*7c478bd9Sstevel@tonic-gate extract_fname_ftype(char *line, char *fname, char *type)
284*7c478bd9Sstevel@tonic-gate {
285*7c478bd9Sstevel@tonic-gate int line_len, pos;
286*7c478bd9Sstevel@tonic-gate
287*7c478bd9Sstevel@tonic-gate pos = 0;
288*7c478bd9Sstevel@tonic-gate line_len = strlen(line);
289*7c478bd9Sstevel@tonic-gate
290*7c478bd9Sstevel@tonic-gate get_token(line, &pos, line_len, fname, PATH_MAX);
291*7c478bd9Sstevel@tonic-gate get_token(line, &pos, line_len, type, TYPE_SIZE);
292*7c478bd9Sstevel@tonic-gate }
293*7c478bd9Sstevel@tonic-gate
294*7c478bd9Sstevel@tonic-gate /*
295*7c478bd9Sstevel@tonic-gate * Utility function: tells us whether or not this addition should be reported
296*7c478bd9Sstevel@tonic-gate *
297*7c478bd9Sstevel@tonic-gate * Returns 0 if the discrepancy is ignored, non-zero if the discrepancy is
298*7c478bd9Sstevel@tonic-gate * reported.
299*7c478bd9Sstevel@tonic-gate */
300*7c478bd9Sstevel@tonic-gate static int
report_add(char * fname,char * type)301*7c478bd9Sstevel@tonic-gate report_add(char *fname, char *type)
302*7c478bd9Sstevel@tonic-gate {
303*7c478bd9Sstevel@tonic-gate struct rule *rule_ptr;
304*7c478bd9Sstevel@tonic-gate
305*7c478bd9Sstevel@tonic-gate rule_ptr = check_rules(fname, type[0]);
306*7c478bd9Sstevel@tonic-gate if ((rule_ptr != NULL) && (rule_ptr->attr_list & ATTR_ADD))
307*7c478bd9Sstevel@tonic-gate return (1);
308*7c478bd9Sstevel@tonic-gate else
309*7c478bd9Sstevel@tonic-gate return (0);
310*7c478bd9Sstevel@tonic-gate }
311*7c478bd9Sstevel@tonic-gate
312*7c478bd9Sstevel@tonic-gate /*
313*7c478bd9Sstevel@tonic-gate * Utility function: tells us whether or not this deletion should be reported
314*7c478bd9Sstevel@tonic-gate *
315*7c478bd9Sstevel@tonic-gate * Returns 0 if the discrepancy is ignored, non-zero if the discrepancy is
316*7c478bd9Sstevel@tonic-gate * reported.
317*7c478bd9Sstevel@tonic-gate */
318*7c478bd9Sstevel@tonic-gate static int
report_delete(char * fname,char * type)319*7c478bd9Sstevel@tonic-gate report_delete(char *fname, char *type)
320*7c478bd9Sstevel@tonic-gate {
321*7c478bd9Sstevel@tonic-gate struct rule *rule_ptr;
322*7c478bd9Sstevel@tonic-gate
323*7c478bd9Sstevel@tonic-gate rule_ptr = check_rules(fname, type[0]);
324*7c478bd9Sstevel@tonic-gate
325*7c478bd9Sstevel@tonic-gate if ((rule_ptr != NULL) && (rule_ptr->attr_list & ATTR_DELETE))
326*7c478bd9Sstevel@tonic-gate return (1);
327*7c478bd9Sstevel@tonic-gate else
328*7c478bd9Sstevel@tonic-gate return (0);
329*7c478bd9Sstevel@tonic-gate }
330*7c478bd9Sstevel@tonic-gate
331*7c478bd9Sstevel@tonic-gate /*
332*7c478bd9Sstevel@tonic-gate * This function takes in the two entries, which have been flagged as
333*7c478bd9Sstevel@tonic-gate * different, breaks them up and reports discrepancies. Note, discrepancies
334*7c478bd9Sstevel@tonic-gate * are affected by the 'CHECK' and 'IGNORE' stanzas which may apply to
335*7c478bd9Sstevel@tonic-gate * these entries.
336*7c478bd9Sstevel@tonic-gate *
337*7c478bd9Sstevel@tonic-gate * Returns the number of discrepancies reported.
338*7c478bd9Sstevel@tonic-gate */
339*7c478bd9Sstevel@tonic-gate static int
evaluate_differences(char * control_line,char * test_line,boolean_t prog_fmt,int flags)340*7c478bd9Sstevel@tonic-gate evaluate_differences(char *control_line, char *test_line,
341*7c478bd9Sstevel@tonic-gate boolean_t prog_fmt, int flags)
342*7c478bd9Sstevel@tonic-gate {
343*7c478bd9Sstevel@tonic-gate char ctrl_fname[PATH_MAX], test_fname[PATH_MAX],
344*7c478bd9Sstevel@tonic-gate ctrl_type[TYPE_SIZE], test_type[TYPE_SIZE],
345*7c478bd9Sstevel@tonic-gate ctrl_size[MISC_SIZE], ctrl_mode[MISC_SIZE],
346*7c478bd9Sstevel@tonic-gate ctrl_acl[ACL_SIZE], ctrl_mtime[MISC_SIZE],
347*7c478bd9Sstevel@tonic-gate ctrl_uid[MISC_SIZE], ctrl_gid[MISC_SIZE],
348*7c478bd9Sstevel@tonic-gate ctrl_dest[PATH_MAX], ctrl_contents[PATH_MAX],
349*7c478bd9Sstevel@tonic-gate ctrl_devnode[PATH_MAX], test_size[MISC_SIZE],
350*7c478bd9Sstevel@tonic-gate test_mode[MISC_SIZE], test_acl[ACL_SIZE],
351*7c478bd9Sstevel@tonic-gate test_mtime[MISC_SIZE], test_uid[MISC_SIZE],
352*7c478bd9Sstevel@tonic-gate test_gid[MISC_SIZE], test_dest[PATH_MAX],
353*7c478bd9Sstevel@tonic-gate test_contents[PATH_MAX], test_devnode[PATH_MAX],
354*7c478bd9Sstevel@tonic-gate *tag;
355*7c478bd9Sstevel@tonic-gate int ret_val;
356*7c478bd9Sstevel@tonic-gate struct rule *rule_ptr;
357*7c478bd9Sstevel@tonic-gate
358*7c478bd9Sstevel@tonic-gate ret_val = 0;
359*7c478bd9Sstevel@tonic-gate
360*7c478bd9Sstevel@tonic-gate parse_line(control_line, ctrl_fname, ctrl_type, ctrl_size, ctrl_mode,
361*7c478bd9Sstevel@tonic-gate ctrl_acl, ctrl_mtime, ctrl_uid, ctrl_gid, ctrl_contents,
362*7c478bd9Sstevel@tonic-gate ctrl_devnode, ctrl_dest);
363*7c478bd9Sstevel@tonic-gate
364*7c478bd9Sstevel@tonic-gate /*
365*7c478bd9Sstevel@tonic-gate * Now we know the fname and type, let's get the rule that matches this
366*7c478bd9Sstevel@tonic-gate * manifest entry. If there is a match, make sure to setup the
367*7c478bd9Sstevel@tonic-gate * correct reporting flags.
368*7c478bd9Sstevel@tonic-gate */
369*7c478bd9Sstevel@tonic-gate rule_ptr = check_rules(ctrl_fname, ctrl_type[0]);
370*7c478bd9Sstevel@tonic-gate if (rule_ptr != NULL)
371*7c478bd9Sstevel@tonic-gate flags = rule_ptr->attr_list;
372*7c478bd9Sstevel@tonic-gate
373*7c478bd9Sstevel@tonic-gate parse_line(test_line, test_fname, test_type, test_size, test_mode,
374*7c478bd9Sstevel@tonic-gate test_acl, test_mtime, test_uid, test_gid, test_contents,
375*7c478bd9Sstevel@tonic-gate test_devnode, test_dest);
376*7c478bd9Sstevel@tonic-gate
377*7c478bd9Sstevel@tonic-gate /*
378*7c478bd9Sstevel@tonic-gate * Report the errors based upon which keywords have been set by
379*7c478bd9Sstevel@tonic-gate * the user.
380*7c478bd9Sstevel@tonic-gate */
381*7c478bd9Sstevel@tonic-gate if ((flags & ATTR_TYPE) && (ctrl_type[0] != test_type[0])) {
382*7c478bd9Sstevel@tonic-gate report_error(ctrl_fname, TYPE_KEYWORD, ctrl_type,
383*7c478bd9Sstevel@tonic-gate test_type, prog_fmt);
384*7c478bd9Sstevel@tonic-gate ret_val++;
385*7c478bd9Sstevel@tonic-gate }
386*7c478bd9Sstevel@tonic-gate
387*7c478bd9Sstevel@tonic-gate if ((flags & ATTR_SIZE) && (strcmp(ctrl_size, test_size) != 0)) {
388*7c478bd9Sstevel@tonic-gate report_error(ctrl_fname, SIZE_KEYWORD, ctrl_size,
389*7c478bd9Sstevel@tonic-gate test_size, prog_fmt);
390*7c478bd9Sstevel@tonic-gate ret_val++;
391*7c478bd9Sstevel@tonic-gate }
392*7c478bd9Sstevel@tonic-gate
393*7c478bd9Sstevel@tonic-gate if ((flags & ATTR_MODE) && (strcmp(ctrl_mode, test_mode) != 0)) {
394*7c478bd9Sstevel@tonic-gate report_error(ctrl_fname, MODE_KEYWORD, ctrl_mode,
395*7c478bd9Sstevel@tonic-gate test_mode, prog_fmt);
396*7c478bd9Sstevel@tonic-gate ret_val++;
397*7c478bd9Sstevel@tonic-gate }
398*7c478bd9Sstevel@tonic-gate
399*7c478bd9Sstevel@tonic-gate if ((flags & ATTR_ACL) && (strcmp(ctrl_acl, test_acl) != 0)) {
400*7c478bd9Sstevel@tonic-gate report_error(ctrl_fname, ACL_KEYWORD, ctrl_acl,
401*7c478bd9Sstevel@tonic-gate test_acl, prog_fmt);
402*7c478bd9Sstevel@tonic-gate ret_val++;
403*7c478bd9Sstevel@tonic-gate }
404*7c478bd9Sstevel@tonic-gate
405*7c478bd9Sstevel@tonic-gate if ((flags & ATTR_MTIME) && (ctrl_type[0] == test_type[0])) {
406*7c478bd9Sstevel@tonic-gate if (strcmp(ctrl_mtime, test_mtime) != 0) {
407*7c478bd9Sstevel@tonic-gate switch (ctrl_type[0]) {
408*7c478bd9Sstevel@tonic-gate case 'D':
409*7c478bd9Sstevel@tonic-gate tag = "dirmtime";
410*7c478bd9Sstevel@tonic-gate break;
411*7c478bd9Sstevel@tonic-gate case 'L':
412*7c478bd9Sstevel@tonic-gate tag = "lnmtime";
413*7c478bd9Sstevel@tonic-gate break;
414*7c478bd9Sstevel@tonic-gate default:
415*7c478bd9Sstevel@tonic-gate tag = "mtime";
416*7c478bd9Sstevel@tonic-gate break;
417*7c478bd9Sstevel@tonic-gate }
418*7c478bd9Sstevel@tonic-gate if (flags == 0) {
419*7c478bd9Sstevel@tonic-gate report_error(ctrl_fname, tag, ctrl_mtime,
420*7c478bd9Sstevel@tonic-gate test_mtime, prog_fmt);
421*7c478bd9Sstevel@tonic-gate ret_val++;
422*7c478bd9Sstevel@tonic-gate }
423*7c478bd9Sstevel@tonic-gate }
424*7c478bd9Sstevel@tonic-gate
425*7c478bd9Sstevel@tonic-gate if ((ctrl_type[0] == 'F') && (flags & ATTR_MTIME) &&
426*7c478bd9Sstevel@tonic-gate (strcmp(ctrl_mtime, test_mtime) != 0)) {
427*7c478bd9Sstevel@tonic-gate report_error(ctrl_fname, MTIME_KEYWORD, ctrl_mtime, test_mtime,
428*7c478bd9Sstevel@tonic-gate prog_fmt);
429*7c478bd9Sstevel@tonic-gate ret_val++;
430*7c478bd9Sstevel@tonic-gate }
431*7c478bd9Sstevel@tonic-gate
432*7c478bd9Sstevel@tonic-gate if ((ctrl_type[0] == 'D') && (flags & ATTR_DIRMTIME) &&
433*7c478bd9Sstevel@tonic-gate (strcmp(ctrl_mtime, test_mtime) != 0)) {
434*7c478bd9Sstevel@tonic-gate report_error(ctrl_fname, DIRMTIME_KEYWORD, ctrl_mtime,
435*7c478bd9Sstevel@tonic-gate test_mtime, prog_fmt);
436*7c478bd9Sstevel@tonic-gate ret_val++;
437*7c478bd9Sstevel@tonic-gate }
438*7c478bd9Sstevel@tonic-gate
439*7c478bd9Sstevel@tonic-gate if ((ctrl_type[0] == 'L') && (flags & ATTR_LNMTIME) &&
440*7c478bd9Sstevel@tonic-gate (strcmp(ctrl_mtime, test_mtime) != 0)) {
441*7c478bd9Sstevel@tonic-gate report_error(ctrl_fname, LNMTIME_KEYWORD, ctrl_mtime,
442*7c478bd9Sstevel@tonic-gate test_mtime, prog_fmt);
443*7c478bd9Sstevel@tonic-gate ret_val++;
444*7c478bd9Sstevel@tonic-gate }
445*7c478bd9Sstevel@tonic-gate } else if ((flags & ATTR_MTIME) &&
446*7c478bd9Sstevel@tonic-gate (strcmp(ctrl_mtime, test_mtime) != 0)) {
447*7c478bd9Sstevel@tonic-gate report_error(ctrl_fname, MTIME_KEYWORD, ctrl_mtime,
448*7c478bd9Sstevel@tonic-gate test_mtime, prog_fmt);
449*7c478bd9Sstevel@tonic-gate ret_val++;
450*7c478bd9Sstevel@tonic-gate }
451*7c478bd9Sstevel@tonic-gate
452*7c478bd9Sstevel@tonic-gate if ((flags & ATTR_UID) && (strcmp(ctrl_uid, test_uid) != 0)) {
453*7c478bd9Sstevel@tonic-gate report_error(ctrl_fname, UID_KEYWORD, ctrl_uid,
454*7c478bd9Sstevel@tonic-gate test_uid, prog_fmt);
455*7c478bd9Sstevel@tonic-gate ret_val++;
456*7c478bd9Sstevel@tonic-gate }
457*7c478bd9Sstevel@tonic-gate
458*7c478bd9Sstevel@tonic-gate if ((flags & ATTR_GID) && (strcmp(ctrl_gid, test_gid) != 0)) {
459*7c478bd9Sstevel@tonic-gate report_error(ctrl_fname, GID_KEYWORD, ctrl_gid,
460*7c478bd9Sstevel@tonic-gate test_gid, prog_fmt);
461*7c478bd9Sstevel@tonic-gate ret_val++;
462*7c478bd9Sstevel@tonic-gate }
463*7c478bd9Sstevel@tonic-gate
464*7c478bd9Sstevel@tonic-gate if ((flags & ATTR_DEVNODE) &&
465*7c478bd9Sstevel@tonic-gate (strcmp(ctrl_devnode, test_devnode) != 0)) {
466*7c478bd9Sstevel@tonic-gate report_error(ctrl_fname, DEVNODE_KEYWORD, ctrl_devnode,
467*7c478bd9Sstevel@tonic-gate test_devnode, prog_fmt);
468*7c478bd9Sstevel@tonic-gate ret_val++;
469*7c478bd9Sstevel@tonic-gate }
470*7c478bd9Sstevel@tonic-gate
471*7c478bd9Sstevel@tonic-gate if ((flags & ATTR_DEST) && (strcmp(ctrl_dest, test_dest) != 0)) {
472*7c478bd9Sstevel@tonic-gate report_error(ctrl_fname, DEST_KEYWORD, ctrl_dest,
473*7c478bd9Sstevel@tonic-gate test_dest, prog_fmt);
474*7c478bd9Sstevel@tonic-gate ret_val++;
475*7c478bd9Sstevel@tonic-gate }
476*7c478bd9Sstevel@tonic-gate
477*7c478bd9Sstevel@tonic-gate if ((flags & ATTR_CONTENTS) &&
478*7c478bd9Sstevel@tonic-gate (strcmp(ctrl_contents, test_contents)) != 0) {
479*7c478bd9Sstevel@tonic-gate report_error(ctrl_fname, CONTENTS_KEYWORD, ctrl_contents,
480*7c478bd9Sstevel@tonic-gate test_contents, prog_fmt);
481*7c478bd9Sstevel@tonic-gate ret_val++;
482*7c478bd9Sstevel@tonic-gate }
483*7c478bd9Sstevel@tonic-gate
484*7c478bd9Sstevel@tonic-gate return (ret_val);
485*7c478bd9Sstevel@tonic-gate }
486*7c478bd9Sstevel@tonic-gate
487*7c478bd9Sstevel@tonic-gate /*
488*7c478bd9Sstevel@tonic-gate * Function responsible for reporting errors.
489*7c478bd9Sstevel@tonic-gate */
490*7c478bd9Sstevel@tonic-gate static void
report_error(char * fname,char * type,char * ctrl_val,char * test_val,boolean_t prog_fmt)491*7c478bd9Sstevel@tonic-gate report_error(char *fname, char *type, char *ctrl_val, char *test_val,
492*7c478bd9Sstevel@tonic-gate boolean_t prog_fmt)
493*7c478bd9Sstevel@tonic-gate {
494*7c478bd9Sstevel@tonic-gate static char last_fname[PATH_MAX] = "";
495*7c478bd9Sstevel@tonic-gate
496*7c478bd9Sstevel@tonic-gate if (!prog_fmt) {
497*7c478bd9Sstevel@tonic-gate /* Verbose mode */
498*7c478bd9Sstevel@tonic-gate if (strcmp(fname, last_fname) != 0) {
499*7c478bd9Sstevel@tonic-gate (void) printf("%s:\n", fname);
500*7c478bd9Sstevel@tonic-gate (void) strlcpy(last_fname, fname, sizeof (last_fname));
501*7c478bd9Sstevel@tonic-gate }
502*7c478bd9Sstevel@tonic-gate
503*7c478bd9Sstevel@tonic-gate if (strcmp(type, ADD_KEYWORD) == 0 ||
504*7c478bd9Sstevel@tonic-gate strcmp(type, DELETE_KEYWORD) == 0)
505*7c478bd9Sstevel@tonic-gate (void) printf(" %s\n", type);
506*7c478bd9Sstevel@tonic-gate else
507*7c478bd9Sstevel@tonic-gate (void) printf(" %s control:%s test:%s\n", type,
508*7c478bd9Sstevel@tonic-gate ctrl_val, test_val);
509*7c478bd9Sstevel@tonic-gate } else {
510*7c478bd9Sstevel@tonic-gate /* Programmatic mode */
511*7c478bd9Sstevel@tonic-gate if (strcmp(fname, last_fname) != 0) {
512*7c478bd9Sstevel@tonic-gate /* Ensure a line is not printed for the initial case */
513*7c478bd9Sstevel@tonic-gate if (strlen(last_fname) != 0)
514*7c478bd9Sstevel@tonic-gate (void) printf("\n");
515*7c478bd9Sstevel@tonic-gate (void) strlcpy(last_fname, fname, sizeof (last_fname));
516*7c478bd9Sstevel@tonic-gate (void) printf("%s ", fname);
517*7c478bd9Sstevel@tonic-gate }
518*7c478bd9Sstevel@tonic-gate
519*7c478bd9Sstevel@tonic-gate (void) printf("%s ", type);
520*7c478bd9Sstevel@tonic-gate if (strcmp(type, ADD_KEYWORD) != 0 &&
521*7c478bd9Sstevel@tonic-gate strcmp(type, DELETE_KEYWORD) != 0) {
522*7c478bd9Sstevel@tonic-gate (void) printf("%s ", ctrl_val);
523*7c478bd9Sstevel@tonic-gate (void) printf("%s ", test_val);
524*7c478bd9Sstevel@tonic-gate }
525*7c478bd9Sstevel@tonic-gate }
526*7c478bd9Sstevel@tonic-gate }
527*7c478bd9Sstevel@tonic-gate
528*7c478bd9Sstevel@tonic-gate /*
529*7c478bd9Sstevel@tonic-gate * Function responsible for reading in a line from the manifest.
530*7c478bd9Sstevel@tonic-gate * Takes in the file ptr and a buffer, parses the buffer and sets the 'line'
531*7c478bd9Sstevel@tonic-gate * ptr correctly. In the case when the buffer is fully parsed, this function
532*7c478bd9Sstevel@tonic-gate * reads more data from the file ptr and refills the buffer.
533*7c478bd9Sstevel@tonic-gate */
534*7c478bd9Sstevel@tonic-gate static int
read_manifest_line(FILE * fd,char * buf,int buf_size,int start_pos,char ** line,char * fname)535*7c478bd9Sstevel@tonic-gate read_manifest_line(FILE *fd, char *buf, int buf_size, int start_pos,
536*7c478bd9Sstevel@tonic-gate char **line, char *fname)
537*7c478bd9Sstevel@tonic-gate {
538*7c478bd9Sstevel@tonic-gate int end_pos, len, iscomment = 0, filepos;
539*7c478bd9Sstevel@tonic-gate
540*7c478bd9Sstevel@tonic-gate /*
541*7c478bd9Sstevel@tonic-gate * Initialization case: make sure the manifest version is OK
542*7c478bd9Sstevel@tonic-gate */
543*7c478bd9Sstevel@tonic-gate if (start_pos == 0) {
544*7c478bd9Sstevel@tonic-gate end_pos = 0;
545*7c478bd9Sstevel@tonic-gate buf[0] = '\0';
546*7c478bd9Sstevel@tonic-gate filepos = ftell(fd);
547*7c478bd9Sstevel@tonic-gate (void) fread((void *) buf, (size_t)buf_size, (size_t)1, fd);
548*7c478bd9Sstevel@tonic-gate
549*7c478bd9Sstevel@tonic-gate *line = buf;
550*7c478bd9Sstevel@tonic-gate
551*7c478bd9Sstevel@tonic-gate if (filepos == 0) {
552*7c478bd9Sstevel@tonic-gate if (strncmp(buf, MANIFEST_VER,
553*7c478bd9Sstevel@tonic-gate strlen(MANIFEST_VER)) != 0)
554*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MISSING_VER, fname);
555*7c478bd9Sstevel@tonic-gate if ((*line[0] == '!') || (*line[0] == '#'))
556*7c478bd9Sstevel@tonic-gate iscomment++;
557*7c478bd9Sstevel@tonic-gate
558*7c478bd9Sstevel@tonic-gate while (iscomment) {
559*7c478bd9Sstevel@tonic-gate while ((buf[end_pos] != '\n') &&
560*7c478bd9Sstevel@tonic-gate (buf[end_pos] != '\0') &&
561*7c478bd9Sstevel@tonic-gate (end_pos < buf_size))
562*7c478bd9Sstevel@tonic-gate end_pos++;
563*7c478bd9Sstevel@tonic-gate
564*7c478bd9Sstevel@tonic-gate if (end_pos >= buf_size)
565*7c478bd9Sstevel@tonic-gate return (-1);
566*7c478bd9Sstevel@tonic-gate
567*7c478bd9Sstevel@tonic-gate end_pos++;
568*7c478bd9Sstevel@tonic-gate *line = &(buf[end_pos]);
569*7c478bd9Sstevel@tonic-gate iscomment = 0;
570*7c478bd9Sstevel@tonic-gate if ((*line[0] == '!') || (*line[0] == '#'))
571*7c478bd9Sstevel@tonic-gate iscomment++;
572*7c478bd9Sstevel@tonic-gate }
573*7c478bd9Sstevel@tonic-gate }
574*7c478bd9Sstevel@tonic-gate
575*7c478bd9Sstevel@tonic-gate while ((buf[end_pos] != '\n') && (buf[end_pos] != '\0') &&
576*7c478bd9Sstevel@tonic-gate (end_pos < buf_size))
577*7c478bd9Sstevel@tonic-gate end_pos++;
578*7c478bd9Sstevel@tonic-gate
579*7c478bd9Sstevel@tonic-gate if (end_pos < buf_size) {
580*7c478bd9Sstevel@tonic-gate if (buf[end_pos] == '\n') {
581*7c478bd9Sstevel@tonic-gate buf[end_pos] = '\0';
582*7c478bd9Sstevel@tonic-gate return (end_pos);
583*7c478bd9Sstevel@tonic-gate }
584*7c478bd9Sstevel@tonic-gate
585*7c478bd9Sstevel@tonic-gate if (buf[end_pos] == '\0')
586*7c478bd9Sstevel@tonic-gate return (-1);
587*7c478bd9Sstevel@tonic-gate }
588*7c478bd9Sstevel@tonic-gate
589*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MANIFEST_ERR);
590*7c478bd9Sstevel@tonic-gate exit(FATAL_EXIT);
591*7c478bd9Sstevel@tonic-gate }
592*7c478bd9Sstevel@tonic-gate
593*7c478bd9Sstevel@tonic-gate end_pos = (start_pos+1);
594*7c478bd9Sstevel@tonic-gate *line = &(buf[end_pos]);
595*7c478bd9Sstevel@tonic-gate
596*7c478bd9Sstevel@tonic-gate /* Read the buffer until EOL or the buffer is empty */
597*7c478bd9Sstevel@tonic-gate while ((buf[end_pos] != '\n') && (buf[end_pos] != '\0') &&
598*7c478bd9Sstevel@tonic-gate (end_pos < buf_size))
599*7c478bd9Sstevel@tonic-gate end_pos++;
600*7c478bd9Sstevel@tonic-gate
601*7c478bd9Sstevel@tonic-gate if (end_pos < buf_size) {
602*7c478bd9Sstevel@tonic-gate /* Found the end of the line, normal exit */
603*7c478bd9Sstevel@tonic-gate if (buf[end_pos] == '\n') {
604*7c478bd9Sstevel@tonic-gate buf[end_pos] = '\0';
605*7c478bd9Sstevel@tonic-gate return (end_pos);
606*7c478bd9Sstevel@tonic-gate }
607*7c478bd9Sstevel@tonic-gate
608*7c478bd9Sstevel@tonic-gate /* No more input to read */
609*7c478bd9Sstevel@tonic-gate if (buf[end_pos] == '\0')
610*7c478bd9Sstevel@tonic-gate return (-1);
611*7c478bd9Sstevel@tonic-gate }
612*7c478bd9Sstevel@tonic-gate
613*7c478bd9Sstevel@tonic-gate /*
614*7c478bd9Sstevel@tonic-gate * The following code takes the remainder of the buffer and
615*7c478bd9Sstevel@tonic-gate * puts it at the beginning. The space after the remainder, which
616*7c478bd9Sstevel@tonic-gate * is now at the beginning, is blanked.
617*7c478bd9Sstevel@tonic-gate * At this point, read in more data and continue to find the EOL....
618*7c478bd9Sstevel@tonic-gate */
619*7c478bd9Sstevel@tonic-gate len = end_pos - (start_pos + 1);
620*7c478bd9Sstevel@tonic-gate (void) memcpy(buf, &(buf[start_pos+1]), (size_t)len);
621*7c478bd9Sstevel@tonic-gate (void) memset(&buf[len], '\0', (buf_size - len));
622*7c478bd9Sstevel@tonic-gate (void) fread((void *) &buf[len], (size_t)(buf_size-len), (size_t)1, fd);
623*7c478bd9Sstevel@tonic-gate *line = buf;
624*7c478bd9Sstevel@tonic-gate end_pos = len;
625*7c478bd9Sstevel@tonic-gate
626*7c478bd9Sstevel@tonic-gate /* Read the buffer until EOL or the buffer is empty */
627*7c478bd9Sstevel@tonic-gate while ((buf[end_pos] != '\n') && (buf[end_pos] != '\0') &&
628*7c478bd9Sstevel@tonic-gate (end_pos < buf_size))
629*7c478bd9Sstevel@tonic-gate end_pos++;
630*7c478bd9Sstevel@tonic-gate
631*7c478bd9Sstevel@tonic-gate if (end_pos < buf_size) {
632*7c478bd9Sstevel@tonic-gate /* Found the end of the line, normal exit */
633*7c478bd9Sstevel@tonic-gate if (buf[end_pos] == '\n') {
634*7c478bd9Sstevel@tonic-gate buf[end_pos] = '\0';
635*7c478bd9Sstevel@tonic-gate return (end_pos);
636*7c478bd9Sstevel@tonic-gate }
637*7c478bd9Sstevel@tonic-gate
638*7c478bd9Sstevel@tonic-gate /* No more input to read */
639*7c478bd9Sstevel@tonic-gate if (buf[end_pos] == '\0')
640*7c478bd9Sstevel@tonic-gate return (-1);
641*7c478bd9Sstevel@tonic-gate }
642*7c478bd9Sstevel@tonic-gate
643*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MANIFEST_ERR);
644*7c478bd9Sstevel@tonic-gate exit(FATAL_EXIT);
645*7c478bd9Sstevel@tonic-gate
646*7c478bd9Sstevel@tonic-gate /* NOTREACHED */
647*7c478bd9Sstevel@tonic-gate }
648*7c478bd9Sstevel@tonic-gate
649*7c478bd9Sstevel@tonic-gate static void
init_default_flags(uint_t * flags)650*7c478bd9Sstevel@tonic-gate init_default_flags(uint_t *flags)
651*7c478bd9Sstevel@tonic-gate {
652*7c478bd9Sstevel@tonic-gate /* Default behavior: everything is checked *except* dirmtime */
653*7c478bd9Sstevel@tonic-gate *flags = ATTR_ALL & ~(ATTR_DIRMTIME);
654*7c478bd9Sstevel@tonic-gate }
655