xref: /titanic_41/usr/src/cmd/bart/bart.h (revision 6a634c9dca3093f3922e4b7ab826d7bdf17bf78e)
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
59c84d166Srm88369  * Common Development and Distribution License (the "License").
69c84d166Srm88369  * 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  */
217c478bd9Sstevel@tonic-gate /*
22*99389cdeSJan Parcel  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #ifndef	_BART_H
267c478bd9Sstevel@tonic-gate #define	_BART_H
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
297c478bd9Sstevel@tonic-gate extern "C" {
307c478bd9Sstevel@tonic-gate #endif
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <stdio.h>
337c478bd9Sstevel@tonic-gate #include <stdlib.h>
347c478bd9Sstevel@tonic-gate #include <ctype.h>
357c478bd9Sstevel@tonic-gate #include <limits.h>
367c478bd9Sstevel@tonic-gate #include <sys/stat.h>
377c478bd9Sstevel@tonic-gate #include <strings.h>
387c478bd9Sstevel@tonic-gate #include <errno.h>
397c478bd9Sstevel@tonic-gate #include <fcntl.h>
407c478bd9Sstevel@tonic-gate #include <sys/types.h>
417c478bd9Sstevel@tonic-gate #include <md5.h>
427c478bd9Sstevel@tonic-gate #include <ftw.h>
437c478bd9Sstevel@tonic-gate #include <libintl.h>
447c478bd9Sstevel@tonic-gate #include "msgs.h"
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #define	EXIT		0
477c478bd9Sstevel@tonic-gate #define	WARNING_EXIT	1
487c478bd9Sstevel@tonic-gate #define	FATAL_EXIT	2
497c478bd9Sstevel@tonic-gate 
50*99389cdeSJan Parcel #define	NO_EXCLUDE	0
51*99389cdeSJan Parcel #define	EXCLUDE_SKIP	1
52*99389cdeSJan Parcel #define	EXCLUDE_PRUNE	2
53*99389cdeSJan Parcel 
547c478bd9Sstevel@tonic-gate #define	CHECK		0
557c478bd9Sstevel@tonic-gate #define	NOCHECK		1
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #define	CHECK_KEYWORD(s)	(strcmp(s, "CHECK") == 0)
587c478bd9Sstevel@tonic-gate #define	IGNORE_KEYWORD(s)	(strcmp(s, "IGNORE") == 0)
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #define	ALL_KEYWORD		"all"
617c478bd9Sstevel@tonic-gate #define	CONTENTS_KEYWORD	"contents"
627c478bd9Sstevel@tonic-gate #define	TYPE_KEYWORD		"type"
637c478bd9Sstevel@tonic-gate #define	SIZE_KEYWORD		"size"
647c478bd9Sstevel@tonic-gate #define	MODE_KEYWORD		"mode"
657c478bd9Sstevel@tonic-gate #define	ACL_KEYWORD		"acl"
667c478bd9Sstevel@tonic-gate #define	UID_KEYWORD		"uid"
677c478bd9Sstevel@tonic-gate #define	GID_KEYWORD		"gid"
687c478bd9Sstevel@tonic-gate #define	MTIME_KEYWORD		"mtime"
697c478bd9Sstevel@tonic-gate #define	LNMTIME_KEYWORD		"lnmtime"
707c478bd9Sstevel@tonic-gate #define	DIRMTIME_KEYWORD	"dirmtime"
717c478bd9Sstevel@tonic-gate #define	DEST_KEYWORD		"dest"
727c478bd9Sstevel@tonic-gate #define	DEVNODE_KEYWORD		"devnode"
737c478bd9Sstevel@tonic-gate #define	ADD_KEYWORD		"add"
747c478bd9Sstevel@tonic-gate #define	DELETE_KEYWORD		"delete"
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #define	MANIFEST_VER	"! Version 1.0\n"
777c478bd9Sstevel@tonic-gate #define	FORMAT_STR	"# Format:\n\
787c478bd9Sstevel@tonic-gate #fname D size mode acl dirmtime uid gid\n\
797c478bd9Sstevel@tonic-gate #fname P size mode acl mtime uid gid\n\
807c478bd9Sstevel@tonic-gate #fname S size mode acl mtime uid gid\n\
817c478bd9Sstevel@tonic-gate #fname F size mode acl mtime uid gid contents\n\
827c478bd9Sstevel@tonic-gate #fname L size mode acl lnmtime uid gid dest\n\
837c478bd9Sstevel@tonic-gate #fname B size mode acl mtime uid gid devnode\n\
847c478bd9Sstevel@tonic-gate #fname C size mode acl mtime uid gid devnode\n"
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /*
877c478bd9Sstevel@tonic-gate  * size of buffer - used in several places
887c478bd9Sstevel@tonic-gate  */
897c478bd9Sstevel@tonic-gate #define	BUF_SIZE	65536
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * size of ACL buffer - used in several places
937c478bd9Sstevel@tonic-gate  */
947c478bd9Sstevel@tonic-gate #define	ACL_SIZE	1024
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * size of MISC buffer - used in several places
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate #define	MISC_SIZE	20
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  * size of TYPE buffer - used in several places
1037c478bd9Sstevel@tonic-gate  */
1047c478bd9Sstevel@tonic-gate #define	TYPE_SIZE	2
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate struct tree_modifier {
1077c478bd9Sstevel@tonic-gate 	char			*mod_str;
108*99389cdeSJan Parcel 	boolean_t		include;
109*99389cdeSJan Parcel 	boolean_t		is_dir;
1107c478bd9Sstevel@tonic-gate 	struct tree_modifier	*next;
1117c478bd9Sstevel@tonic-gate };
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate struct attr_keyword {
1147c478bd9Sstevel@tonic-gate 	char    *ak_name;
1157c478bd9Sstevel@tonic-gate 	int	ak_flags;
1167c478bd9Sstevel@tonic-gate };
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #define	ATTR_ALL ((uint_t)~0)
1207c478bd9Sstevel@tonic-gate #define	ATTR_CONTENTS 0x0001
1217c478bd9Sstevel@tonic-gate #define	ATTR_TYPE 0x0002
1227c478bd9Sstevel@tonic-gate #define	ATTR_SIZE 0x0004
1237c478bd9Sstevel@tonic-gate #define	ATTR_MODE 0x0008
1247c478bd9Sstevel@tonic-gate #define	ATTR_UID 0x0010
1257c478bd9Sstevel@tonic-gate #define	ATTR_GID 0x0020
1267c478bd9Sstevel@tonic-gate #define	ATTR_ACL 0x0040
1277c478bd9Sstevel@tonic-gate #define	ATTR_DEST 0x0080
1287c478bd9Sstevel@tonic-gate #define	ATTR_DEVNODE 0x0100
1297c478bd9Sstevel@tonic-gate #define	ATTR_MTIME 0x0200
1307c478bd9Sstevel@tonic-gate #define	ATTR_LNMTIME 0x0400
1317c478bd9Sstevel@tonic-gate #define	ATTR_DIRMTIME 0x0800
1327c478bd9Sstevel@tonic-gate #define	ATTR_ADD 0x1000
1337c478bd9Sstevel@tonic-gate #define	ATTR_DELETE 0x2000
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate struct rule {
1367c478bd9Sstevel@tonic-gate 	char			subtree[PATH_MAX];
1377c478bd9Sstevel@tonic-gate 	uint_t			attr_list;
1387c478bd9Sstevel@tonic-gate 	struct tree_modifier	*modifiers;
1397c478bd9Sstevel@tonic-gate 	struct rule		*next;
1407c478bd9Sstevel@tonic-gate 	struct rule		*prev;
1417c478bd9Sstevel@tonic-gate };
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate struct dir_component {
1447c478bd9Sstevel@tonic-gate 	char			dirname[PATH_MAX];
1457c478bd9Sstevel@tonic-gate 	struct dir_component	*next;
1467c478bd9Sstevel@tonic-gate };
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate struct attr_keyword *attr_keylookup(char *);
1507c478bd9Sstevel@tonic-gate void usage(void);
1517c478bd9Sstevel@tonic-gate int bart_create(int, char **);
1527c478bd9Sstevel@tonic-gate int bart_compare(int, char **);
1537c478bd9Sstevel@tonic-gate struct rule *check_rules(const char *, char);
1547c478bd9Sstevel@tonic-gate int exclude_fname(const char *, char, struct rule *);
1557c478bd9Sstevel@tonic-gate struct rule *get_first_subtree(void);
1567c478bd9Sstevel@tonic-gate struct rule *get_next_subtree(struct rule *);
1577c478bd9Sstevel@tonic-gate void process_glob_ignores(char *, uint_t *);
1587c478bd9Sstevel@tonic-gate void *safe_calloc(size_t);
1597c478bd9Sstevel@tonic-gate char *safe_strdup(char *);
1607c478bd9Sstevel@tonic-gate int read_rules(FILE *, char *, uint_t, int);
1617c478bd9Sstevel@tonic-gate int read_line(FILE *, char *, int, int, char **, char *);
1627c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate #endif
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate #endif	/* _BART_H */
167