17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5ead1f93eSLiane Praza  * Common Development and Distribution License (the "License").
6ead1f93eSLiane Praza  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21ead1f93eSLiane Praza 
227c478bd9Sstevel@tonic-gate /*
23ead1f93eSLiane Praza  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25ed159168SRichard PALO  *
26ed159168SRichard PALO  * Copyright 2015 PALO, Richard
27*93b88728SJohn Levon  *
28*93b88728SJohn Levon  * Copyright (c) 2018, Joyent, Inc.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <stdio.h>
327c478bd9Sstevel@tonic-gate #include <stdlib.h>
337c478bd9Sstevel@tonic-gate #include <string.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include "list.h"
367c478bd9Sstevel@tonic-gate #include "exception_list.h"
377c478bd9Sstevel@tonic-gate #include "arch.h"
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * This is global so that the protodir reading functions can rely on the
417c478bd9Sstevel@tonic-gate  * exception list to weed out innocuous problems in the IHV gate.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate elem_list exception_list;
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #define	FS	" \t\n"
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate static int
parse_exception_line(char * line,elem_list * list)487c478bd9Sstevel@tonic-gate parse_exception_line(char *line, elem_list *list)
497c478bd9Sstevel@tonic-gate {
507c478bd9Sstevel@tonic-gate 	char	*name, *arch;
517c478bd9Sstevel@tonic-gate 	elem	*e;
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 	if ((name = strtok(line, FS)) == NULL) {
547c478bd9Sstevel@tonic-gate 		/* don't complain; this is only a blank line */
557c478bd9Sstevel@tonic-gate 		return (0);
567c478bd9Sstevel@tonic-gate 	}
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	if ((arch = strtok(NULL, FS)) == NULL) {
59ead1f93eSLiane Praza 		arch = "all";
607c478bd9Sstevel@tonic-gate 	}
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 	e = (elem *) malloc(sizeof (elem));
63ed159168SRichard PALO 	if (e == NULL) {
64ed159168SRichard PALO 		perror("malloc");
65ed159168SRichard PALO 		exit(1);
66ed159168SRichard PALO 	}
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate 	e->inode = 0;
697c478bd9Sstevel@tonic-gate 	e->perm = 0;
707c478bd9Sstevel@tonic-gate 	e->ref_cnt = 0;
717c478bd9Sstevel@tonic-gate 	e->flag = 0;
727c478bd9Sstevel@tonic-gate 	e->major = 0;
737c478bd9Sstevel@tonic-gate 	e->minor = 0;
747c478bd9Sstevel@tonic-gate 	e->link_parent = NULL;
757c478bd9Sstevel@tonic-gate 	e->link_sib = NULL;
767c478bd9Sstevel@tonic-gate 	e->symsrc = NULL;
777c478bd9Sstevel@tonic-gate 	e->file_type = DIR_T;
787c478bd9Sstevel@tonic-gate 
79ed159168SRichard PALO 	while ((e->arch = assign_arch(arch)) == 0) {
80ead1f93eSLiane Praza 		if ((arch = strtok(NULL, FS)) == NULL) {
81*93b88728SJohn Levon 			free(e);
82ead1f93eSLiane Praza 			return (0);
83ead1f93eSLiane Praza 		}
847c478bd9Sstevel@tonic-gate 	}
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 	(void) strcpy(e->name, name);
877c478bd9Sstevel@tonic-gate 	add_elem(list, e);
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	return (1);
907c478bd9Sstevel@tonic-gate }
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate int
read_in_exceptions(const char * exception_file,int verbose)937c478bd9Sstevel@tonic-gate read_in_exceptions(const char *exception_file, int verbose)
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate 	FILE	*except_fp;
967c478bd9Sstevel@tonic-gate 	char	buf[BUFSIZ];
977c478bd9Sstevel@tonic-gate 	int	count = 0;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	exception_file = exception_file ? exception_file : EXCEPTION_FILE;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	if (verbose) {
1027c478bd9Sstevel@tonic-gate 		(void) printf("reading in exceptions from %s...\n",
1037c478bd9Sstevel@tonic-gate 		    exception_file);
1047c478bd9Sstevel@tonic-gate 	}
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	if ((except_fp = fopen(exception_file, "r")) == NULL) {
1077c478bd9Sstevel@tonic-gate 		perror(exception_file);
1087c478bd9Sstevel@tonic-gate 		return (0);
1097c478bd9Sstevel@tonic-gate 	}
1107c478bd9Sstevel@tonic-gate 	while (fgets(buf, BUFSIZ, except_fp)) {
1117c478bd9Sstevel@tonic-gate 		if (buf[0] != '#')	/* allow for comments */
1127c478bd9Sstevel@tonic-gate 			count += parse_exception_line(buf, &exception_list);
1137c478bd9Sstevel@tonic-gate 	}
1147c478bd9Sstevel@tonic-gate 	if (verbose)
1157c478bd9Sstevel@tonic-gate 		(void) printf("read in %d exceptions...\n", count);
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	return (count);
1187c478bd9Sstevel@tonic-gate }
119