1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 *
26 * Copyright 2015 PALO, Richard
27 *
28 * Copyright (c) 2018, Joyent, Inc.
29 */
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 #include "list.h"
36 #include "exception_list.h"
37 #include "arch.h"
38
39 /*
40 * This is global so that the protodir reading functions can rely on the
41 * exception list to weed out innocuous problems in the IHV gate.
42 */
43 elem_list exception_list;
44
45 #define FS " \t\n"
46
47 static int
parse_exception_line(char * line,elem_list * list)48 parse_exception_line(char *line, elem_list *list)
49 {
50 char *name, *arch;
51 elem *e;
52
53 if ((name = strtok(line, FS)) == NULL) {
54 /* don't complain; this is only a blank line */
55 return (0);
56 }
57
58 if ((arch = strtok(NULL, FS)) == NULL) {
59 arch = "all";
60 }
61
62 e = (elem *) malloc(sizeof (elem));
63 if (e == NULL) {
64 perror("malloc");
65 exit(1);
66 }
67
68 e->inode = 0;
69 e->perm = 0;
70 e->ref_cnt = 0;
71 e->flag = 0;
72 e->major = 0;
73 e->minor = 0;
74 e->link_parent = NULL;
75 e->link_sib = NULL;
76 e->symsrc = NULL;
77 e->file_type = DIR_T;
78
79 while ((e->arch = assign_arch(arch)) == 0) {
80 if ((arch = strtok(NULL, FS)) == NULL) {
81 free(e);
82 return (0);
83 }
84 }
85
86 (void) strcpy(e->name, name);
87 add_elem(list, e);
88
89 return (1);
90 }
91
92 int
read_in_exceptions(const char * exception_file,int verbose)93 read_in_exceptions(const char *exception_file, int verbose)
94 {
95 FILE *except_fp;
96 char buf[BUFSIZ];
97 int count = 0;
98
99 exception_file = exception_file ? exception_file : EXCEPTION_FILE;
100
101 if (verbose) {
102 (void) printf("reading in exceptions from %s...\n",
103 exception_file);
104 }
105
106 if ((except_fp = fopen(exception_file, "r")) == NULL) {
107 perror(exception_file);
108 return (0);
109 }
110 while (fgets(buf, BUFSIZ, except_fp)) {
111 if (buf[0] != '#') /* allow for comments */
112 count += parse_exception_line(buf, &exception_list);
113 }
114 if (verbose)
115 (void) printf("read in %d exceptions...\n", count);
116
117 return (count);
118 }
119