xref: /illumos-gate/usr/src/cmd/bart/bart.h (revision 7c478bd9)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_BART_H
28 #define	_BART_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <ctype.h>
39 #include <limits.h>
40 #include <sys/stat.h>
41 #include <strings.h>
42 #include <errno.h>
43 #include <fcntl.h>
44 #include <sys/types.h>
45 #include <md5.h>
46 #include <ftw.h>
47 #include <libintl.h>
48 #include "msgs.h"
49 
50 #define	EXIT		0
51 #define	WARNING_EXIT	1
52 #define	FATAL_EXIT	2
53 
54 #define	CHECK		0
55 #define	NOCHECK		1
56 
57 #define	CHECK_KEYWORD(s)	(strcmp(s, "CHECK") == 0)
58 #define	IGNORE_KEYWORD(s)	(strcmp(s, "IGNORE") == 0)
59 
60 #define	ALL_KEYWORD		"all"
61 #define	CONTENTS_KEYWORD	"contents"
62 #define	TYPE_KEYWORD		"type"
63 #define	SIZE_KEYWORD		"size"
64 #define	MODE_KEYWORD		"mode"
65 #define	ACL_KEYWORD		"acl"
66 #define	UID_KEYWORD		"uid"
67 #define	GID_KEYWORD		"gid"
68 #define	MTIME_KEYWORD		"mtime"
69 #define	LNMTIME_KEYWORD		"lnmtime"
70 #define	DIRMTIME_KEYWORD	"dirmtime"
71 #define	DEST_KEYWORD		"dest"
72 #define	DEVNODE_KEYWORD		"devnode"
73 #define	ADD_KEYWORD		"add"
74 #define	DELETE_KEYWORD		"delete"
75 
76 #define	MANIFEST_VER	"! Version 1.0\n"
77 #define	FORMAT_STR	"# Format:\n\
78 #fname D size mode acl dirmtime uid gid\n\
79 #fname P size mode acl mtime uid gid\n\
80 #fname S size mode acl mtime uid gid\n\
81 #fname F size mode acl mtime uid gid contents\n\
82 #fname L size mode acl lnmtime uid gid dest\n\
83 #fname B size mode acl mtime uid gid devnode\n\
84 #fname C size mode acl mtime uid gid devnode\n"
85 
86 /*
87  * size of buffer - used in several places
88  */
89 #define	BUF_SIZE	65536
90 
91 /*
92  * size of ACL buffer - used in several places
93  */
94 #define	ACL_SIZE	1024
95 
96 /*
97  * size of MISC buffer - used in several places
98  */
99 #define	MISC_SIZE	20
100 
101 /*
102  * size of TYPE buffer - used in several places
103  */
104 #define	TYPE_SIZE	2
105 
106 struct tree_modifier {
107 	char			*mod_str;
108 	int			include;
109 	struct tree_modifier	*next;
110 };
111 
112 struct attr_keyword {
113 	char    *ak_name;
114 	int	ak_flags;
115 };
116 
117 
118 #define	ATTR_ALL ((uint_t)~0)
119 #define	ATTR_CONTENTS 0x0001
120 #define	ATTR_TYPE 0x0002
121 #define	ATTR_SIZE 0x0004
122 #define	ATTR_MODE 0x0008
123 #define	ATTR_UID 0x0010
124 #define	ATTR_GID 0x0020
125 #define	ATTR_ACL 0x0040
126 #define	ATTR_DEST 0x0080
127 #define	ATTR_DEVNODE 0x0100
128 #define	ATTR_MTIME 0x0200
129 #define	ATTR_LNMTIME 0x0400
130 #define	ATTR_DIRMTIME 0x0800
131 #define	ATTR_ADD 0x1000
132 #define	ATTR_DELETE 0x2000
133 
134 struct rule {
135 	char			subtree[PATH_MAX];
136 	uint_t			attr_list;
137 	struct tree_modifier	*modifiers;
138 	struct rule		*next;
139 	struct rule		*prev;
140 	boolean_t		traversed;
141 };
142 
143 struct dir_component {
144 	char			dirname[PATH_MAX];
145 	struct dir_component	*next;
146 };
147 
148 
149 struct attr_keyword *attr_keylookup(char *);
150 void usage(void);
151 int bart_create(int, char **);
152 int bart_compare(int, char **);
153 struct rule *check_rules(const char *, char);
154 int exclude_fname(const char *, char, struct rule *);
155 struct rule *get_first_subtree(void);
156 struct rule *get_next_subtree(struct rule *);
157 void process_glob_ignores(char *, uint_t *);
158 void *safe_calloc(size_t);
159 char *safe_strdup(char *);
160 int read_rules(FILE *, char *, uint_t, int);
161 int read_line(FILE *, char *, int, int, char **, char *);
162 #ifdef	__cplusplus
163 }
164 #endif
165 
166 #endif	/* _BART_H */
167