27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
237c478bdstevel@tonic-gate * Copyright (c) 1996 Sun Microsystems, Inc.  All Rights Reserved
247c478bdstevel@tonic-gate *
257c478bdstevel@tonic-gate * module:
267c478bdstevel@tonic-gate *	database.h
277c478bdstevel@tonic-gate *
287c478bdstevel@tonic-gate * purpose:
297c478bdstevel@tonic-gate *	definition of the baseline and rules data structures
307c478bdstevel@tonic-gate */
327c478bdstevel@tonic-gate#ifndef	_DATABASE_H
337c478bdstevel@tonic-gate#define	_DATABASE_H
357c478bdstevel@tonic-gate#pragma ident	"%W%	%E% SMI"
377c478bdstevel@tonic-gate#ifdef	__cplusplus
387c478bdstevel@tonic-gateextern "C" {
417c478bdstevel@tonic-gate#include <sys/stat.h>
427c478bdstevel@tonic-gate#include <sys/acl.h>
447c478bdstevel@tonic-gate#define	ACL_UID_BUG	1	/* acl:SETACL sets owner to be caller	*/
477c478bdstevel@tonic-gate * flag bits describing what we know about an individual file, or in
487c478bdstevel@tonic-gate * some cases an entire base pair.  These flags are found in the
497c478bdstevel@tonic-gate * base and file stuctures.
507c478bdstevel@tonic-gate */
517c478bdstevel@tonic-gatetypedef int fflags_t;			/* type for file flags		*/
537c478bdstevel@tonic-gate#define	F_NEW		0x01		/* newly allocated		*/
547c478bdstevel@tonic-gate#define	F_IN_BASELINE	0x02		/* file found in baseline	*/
557c478bdstevel@tonic-gate#define	F_IN_SOURCE	0x04		/* file found in source tree	*/
567c478bdstevel@tonic-gate#define	F_IN_DEST	0x08		/* file found in dest tree	*/
577c478bdstevel@tonic-gate#define	F_EVALUATE	0x10		/* include in analysis		*/
587c478bdstevel@tonic-gate#define	F_SPARSE	0x20		/* don't walk this directory	*/
597c478bdstevel@tonic-gate#define	F_REMOVE	0x40		/* remove from baseline		*/
607c478bdstevel@tonic-gate#define	F_CONFLICT	0x80		/* unresolvable conflict	*/
617c478bdstevel@tonic-gate#define	F_LISTED	0x100		/* file came from LIST		*/
627c478bdstevel@tonic-gate#define	F_STAT_ERROR	0x200		/* unable to stat file		*/
647c478bdstevel@tonic-gate#define	F_WHEREFOUND	(F_IN_BASELINE|F_IN_SOURCE|F_IN_DEST)
677c478bdstevel@tonic-gate * a base is a pair of directories to be kept in sync
687c478bdstevel@tonic-gate * 	all rules and baseline data is stored beneath some base
697c478bdstevel@tonic-gate */
707c478bdstevel@tonic-gatestruct base {
717c478bdstevel@tonic-gate	struct base *b_next;		/* pointer to next base		*/
727c478bdstevel@tonic-gate	fflags_t   b_flags;		/* what I know about this base	*/
737c478bdstevel@tonic-gate	int   b_ident;			/* base sequence # (DBG)	*/
747c478bdstevel@tonic-gate	char *b_src_spec;		/* spec name of source dir	*/
757c478bdstevel@tonic-gate	char *b_dst_spec;		/* spec name of dest dir	*/
767c478bdstevel@tonic-gate	char *b_src_name;		/* expanded name of source dir	*/
777c478bdstevel@tonic-gate	char *b_dst_name;		/* expanded name of dest dir	*/
797c478bdstevel@tonic-gate	struct rule *b_includes;	/* chain of include rules	*/
807c478bdstevel@tonic-gate	struct rule *b_excludes;	/* chain of exclude rules	*/
817c478bdstevel@tonic-gate	struct rule *b_restrictions;	/* chain of restrictions	*/
837c478bdstevel@tonic-gate	struct file *b_files;		/* chain of files		*/
857c478bdstevel@tonic-gate	/* statistics for wrap-up summary				*/
867c478bdstevel@tonic-gate	int b_totfiles;			/* total files found in tree	*/
877c478bdstevel@tonic-gate	int b_src_copies;		/* files copied to source	*/
887c478bdstevel@tonic-gate	int b_src_deletes;		/* files deleted from source	*/
897c478bdstevel@tonic-gate	int b_src_misc;			/* ownership changes on source	*/
907c478bdstevel@tonic-gate	int b_dst_copies;		/* files copied to dest		*/
917c478bdstevel@tonic-gate	int b_dst_deletes;		/* files deleted from dest	*/
927c478bdstevel@tonic-gate	int b_dst_misc;			/* ownership changes on source	*/
937c478bdstevel@tonic-gate	int b_unresolved;		/* unresolved conflicts		*/
977c478bdstevel@tonic-gate * flag bits describing what we know about a particular rule.
987c478bdstevel@tonic-gate * These flags are found in the rule structure
997c478bdstevel@tonic-gate */
1007c478bdstevel@tonic-gatetypedef	int rflags_t;			/* type for rule flags		*/
1027c478bdstevel@tonic-gate#define	R_NEW		0x01		/* newly added rule (=OPT_NEW)	*/
1037c478bdstevel@tonic-gate#define	R_PROGRAM	0x02		/* program (vs literal names)	*/
1047c478bdstevel@tonic-gate#define	R_IGNORE	0x04		/* IGNORE (vs INCLUDE)		*/
1057c478bdstevel@tonic-gate#define	R_RESTRICT	0x08		/* restriction (-r argument)	*/
1067c478bdstevel@tonic-gate#define	R_WILD		0x10		/* name involves wild cards	*/
1077c478bdstevel@tonic-gate#define	R_BOGUS		0x20		/* fabricated rule		*/
1107c478bdstevel@tonic-gate * a rule describes files to be included or excluded
1117c478bdstevel@tonic-gate *	they are stored under bases
1127c478bdstevel@tonic-gate */
1137c478bdstevel@tonic-gatestruct rule {
1147c478bdstevel@tonic-gate	struct rule *r_next;		/* pointer to next rule in base	*/
1157c478bdstevel@tonic-gate	rflags_t r_flags;		/* flags associated with rule	*/
1167c478bdstevel@tonic-gate	char   *r_file;			/* file for this rule		*/
1217c478bdstevel@tonic-gate * this is the information we keep track of for a file
1227c478bdstevel@tonic-gate */
1237c478bdstevel@tonic-gatestruct fileinfo {
1247c478bdstevel@tonic-gate	ino_t	f_ino;			/* inode number of this file	*/
1257c478bdstevel@tonic-gate	long	f_d_maj;		/* maj dev on which it lives	*/
1267c478bdstevel@tonic-gate	long	f_d_min;		/* minj dev on which it lives	*/
1287c478bdstevel@tonic-gate	int 	f_type;			/* file/dir/special ...		*/
1297c478bdstevel@tonic-gate	int	f_mode;			/* protection			*/
1307c478bdstevel@tonic-gate	int	f_nlink;		/* number of links to file	*/
1327c478bdstevel@tonic-gate	uid_t	f_uid;			/* owning UID			*/
1337c478bdstevel@tonic-gate	gid_t	f_gid;			/* owning GID			*/
1357c478bdstevel@tonic-gate	off_t	f_size;			/* length in bytes		*/
1367c478bdstevel@tonic-gate	long	f_modtime;		/* last modification time	*/
1377c478bdstevel@tonic-gate	long	f_modns;		/* low order bits of modtime	*/
1397c478bdstevel@tonic-gate	long	f_rd_maj;		/* major dev for specials	*/
1407c478bdstevel@tonic-gate	long	f_rd_min;		/* minor dev for specials	*/
1427c478bdstevel@tonic-gate	int	f_numacls;		/* number of entries in acls	*/
1437c478bdstevel@tonic-gate	aclent_t *f_acls;		/* acl list (if any)		*/
1477c478bdstevel@tonic-gate * flag bits describing the differences we have detected between a file
1487c478bdstevel@tonic-gate * and the last time it was in sync (based on the baseline).
1497c478bdstevel@tonic-gate * These flags are used in the srcdiffs and dstdiffs fields of the
1507c478bdstevel@tonic-gate * file structure
1517c478bdstevel@tonic-gate */
1527c478bdstevel@tonic-gatetypedef int diffmask_t;			/* type for difference masks	*/
1547c478bdstevel@tonic-gate#define	D_CREATE	0x01		/* file has been created	*/
1557c478bdstevel@tonic-gate#define	D_DELETE	0x02		/* file has been deleted	*/
1567c478bdstevel@tonic-gate#define	D_MTIME		0x04		/* file has been modified	*/
1577c478bdstevel@tonic-gate#define	D_SIZE		0x08		/* file has changed size	*/
1587c478bdstevel@tonic-gate#define	D_UID		0x10		/* file has changed user id	*/
1597c478bdstevel@tonic-gate#define	D_GID		0x20		/* file has changed group id	*/
1607c478bdstevel@tonic-gate#define	D_PROT		0x40		/* file has changed protection	*/
1617c478bdstevel@tonic-gate#define	D_LINKS		0x80		/* file has changed link count	*/
1627c478bdstevel@tonic-gate#define	D_TYPE		0x100		/* file has changed type	*/
1637c478bdstevel@tonic-gate#define	D_FACLS		0x200		/* file has changed facls	*/
1647c478bdstevel@tonic-gate#define	D_RENAME_TO	0x400		/* file came from a rename	*/
1657c478bdstevel@tonic-gate#define	D_RENAME_FROM	0x800		/* file has been renamed	*/
1687c478bdstevel@tonic-gate * these masks are used to determine how important potential changes are.
1697c478bdstevel@tonic-gate *
1707c478bdstevel@tonic-gate *	D_CONTENTS	there may be changes to the file's contents
1717c478bdstevel@tonic-gate *	D_ADMIN		there may be changes to the ownership and protection
1727c478bdstevel@tonic-gate *	D_IMPORTANT	there may be changes that should block a deletion
1737c478bdstevel@tonic-gate *
1747c478bdstevel@tonic-gate * Note:
1757c478bdstevel@tonic-gate *	I am torn on whether or not to include modtime in D_IMPORTANT.
1767c478bdstevel@tonic-gate *	Experience suggests that deleting one of many links affects the
1777c478bdstevel@tonic-gate *	file modification time.
1787c478bdstevel@tonic-gate */
1797c478bdstevel@tonic-gate#define	D_ADMIN		(D_UID|D_GID|D_PROT|D_FACLS)
1807c478bdstevel@tonic-gate#define	D_CONTENTS	(D_SIZE|D_TYPE|D_CREATE|D_MTIME)
1817c478bdstevel@tonic-gate#define	D_IMPORTANT	(D_SIZE|D_TYPE|D_CREATE|D_MTIME|D_ADMIN)
1847c478bdstevel@tonic-gate * a file is an instance that follows (under a base) from a rule
1857c478bdstevel@tonic-gate * (for that base).  A file structure may exist because of any
1867c478bdstevel@tonic-gate * combination of a file under the source, destination, in a
1877c478bdstevel@tonic-gate * baseline for historical reasons, or merely because a rule
1887c478bdstevel@tonic-gate * calls it out (whether it exists or not).
1897c478bdstevel@tonic-gate */
1907c478bdstevel@tonic-gatestruct file {
1917c478bdstevel@tonic-gate	struct file *f_next;		/* pointer to next file in base	*/
1927c478bdstevel@tonic-gate	struct file *f_files;		/* pointer to files in subdir	*/
1937c478bdstevel@tonic-gate	struct base *f_base;		/* pointer to owning base	*/
1947c478bdstevel@tonic-gate	fflags_t f_flags;		/* flags associated with file	*/
1957c478bdstevel@tonic-gate	int	f_depth;		/* directory depth for file	*/
1967c478bdstevel@tonic-gate	char   *f_name;			/* name of this file		*/
1987c478bdstevel@tonic-gate	/*
1997c478bdstevel@tonic-gate	 * these fields capture information, gleaned from the baseline
2007c478bdstevel@tonic-gate	 * that is side-specific, and should not be expected to be in
2017c478bdstevel@tonic-gate	 * agreement between the two sides.  As a result, this info can
2027c478bdstevel@tonic-gate	 * not be properly captured in f_info[OPT_BASE] and needs to
2037c478bdstevel@tonic-gate	 * be kept somewhere else.
2047c478bdstevel@tonic-gate	 */
2057c478bdstevel@tonic-gate	long	f_s_modtime;		/* baseline source mod time	*/
2067c478bdstevel@tonic-gate	ino_t	f_s_inum;		/* baseline source inode #	*/
2077c478bdstevel@tonic-gate	long	f_s_nlink;		/* baseline source link count	*/
2087c478bdstevel@tonic-gate	long	f_s_maj;		/* baseline source dev maj	*/
2097c478bdstevel@tonic-gate	long	f_s_min;		/* baseline source dev min	*/
2107c478bdstevel@tonic-gate	long	f_d_modtime;		/* baseline target mod time	*/
2117c478bdstevel@tonic-gate	ino_t	f_d_inum;		/* baseline target inode #	*/
2127c478bdstevel@tonic-gate	long	f_d_nlink;		/* baseline target link count	*/
2137c478bdstevel@tonic-gate	long	f_d_maj;		/* baseline target dev maj	*/
2147c478bdstevel@tonic-gate	long	f_d_min;		/* baseline target dev min	*/
2167c478bdstevel@tonic-gate	/* stat information from baseline file and evaluation		*/
2177c478bdstevel@tonic-gate	struct fileinfo f_info[3];	/* baseline, source, dest	*/
2197c478bdstevel@tonic-gate	/* summary of changes discovered in analysis			*/
2207c478bdstevel@tonic-gate	diffmask_t f_srcdiffs;		/* changes on source side	*/
2217c478bdstevel@tonic-gate	diffmask_t f_dstdiffs;		/* changes on dest side		*/
2237c478bdstevel@tonic-gate	/* this field is only valid for a renamed file			*/
2247c478bdstevel@tonic-gate	struct file * f_previous;	/* node for previous filename	*/
2267c478bdstevel@tonic-gate	/*
2277c478bdstevel@tonic-gate	 * these fields are only valid for a file that has been added
2287c478bdstevel@tonic-gate	 * to the reconciliation list
2297c478bdstevel@tonic-gate	 */
2307c478bdstevel@tonic-gate	struct file *f_rnext;		/* reconciliation chain ptr	*/
2317c478bdstevel@tonic-gate	char	*f_fullname;		/* full name for reconciling	*/
2327c478bdstevel@tonic-gate	long	f_modtime;		/* modtime for ordering purpose	*/
2337c478bdstevel@tonic-gate	long	f_modns;		/* low order modtime 		*/
2357c478bdstevel@tonic-gate	/* this field is only valid for a file with a hard conflict	*/
2367c478bdstevel@tonic-gate	char 	*f_problem;		/* description of conflict	*/
2407c478bdstevel@tonic-gate * globals
2417c478bdstevel@tonic-gate */
2427c478bdstevel@tonic-gateextern struct base omnibase;		/* base for global rules	*/
2437c478bdstevel@tonic-gateextern struct base *bases;		/* base for the main list	*/
2447c478bdstevel@tonic-gateextern int inum_changes;		/* LISTed dirs with i# changes	*/
2467c478bdstevel@tonic-gate/* routines to manage base nodes, file nodes, and file infor	*/
2477c478bdstevel@tonic-gateerrmask_t read_baseline(char *);
2487c478bdstevel@tonic-gateerrmask_t write_baseline(char *);
2497c478bdstevel@tonic-gatestruct file *add_file_to_base(struct base *, const char *);
2507c478bdstevel@tonic-gatestruct file *add_file_to_dir(struct file *, const char *);
2517c478bdstevel@tonic-gatestruct base *add_base(const char *src, const char *dst);
2527c478bdstevel@tonic-gatevoid note_info(struct file *, const struct stat *, side_t);
2537c478bdstevel@tonic-gatevoid update_info(struct file *, side_t);
2557c478bdstevel@tonic-gate/* routines to manage rules					*/
2567c478bdstevel@tonic-gateerrmask_t read_rules(char *);
2577c478bdstevel@tonic-gateerrmask_t write_rules(char *);
2587c478bdstevel@tonic-gateerrmask_t add_include(struct base *, char *);
2597c478bdstevel@tonic-gateerrmask_t add_ignore(struct base *, char *);
2617c478bdstevel@tonic-gate/* routines to manage and querry restriction lists		*/
2627c478bdstevel@tonic-gateerrmask_t add_restr(char *);
2637c478bdstevel@tonic-gatebool_t check_restr(struct base *, const char *);
2657c478bdstevel@tonic-gate/* routines for dealing with ignore lists			*/
2667c478bdstevel@tonic-gatevoid ignore_reset();
2677c478bdstevel@tonic-gatevoid ignore_pgm(const char *);
2687c478bdstevel@tonic-gatevoid ignore_expr(const char *);
2697c478bdstevel@tonic-gatevoid ignore_file(const char *);
2707c478bdstevel@tonic-gatebool_t ignore_check(const char *);
2727c478bdstevel@tonic-gate/* database processing routines for the primary passes		*/
2737c478bdstevel@tonic-gateerrmask_t evaluate(struct base *, side_t, bool_t);
2747c478bdstevel@tonic-gateerrmask_t analyze(void);
2757c478bdstevel@tonic-gateerrmask_t find_renames(struct file *);
2767c478bdstevel@tonic-gateerrmask_t reconcile(struct file *);
2777c478bdstevel@tonic-gateint prune(void);
2787c478bdstevel@tonic-gatevoid summary(void);
2797c478bdstevel@tonic-gatechar *full_name(struct file *, side_t, side_t);
2817c478bdstevel@tonic-gate/* routines in action.c to carry out reconciliation		*/
2827c478bdstevel@tonic-gateerrmask_t do_copy(struct file *, side_t);
2837c478bdstevel@tonic-gateerrmask_t do_remove(struct file *, side_t);
2847c478bdstevel@tonic-gateerrmask_t do_rename(struct file *, side_t);
2857c478bdstevel@tonic-gateerrmask_t do_like(struct file *, side_t, bool_t);
2877c478bdstevel@tonic-gate/* routines to deal with links in the reconciliation list	*/
2887c478bdstevel@tonic-gatestruct file *find_link(struct file *, side_t);
2897c478bdstevel@tonic-gatevoid link_update(struct file *, side_t);
2907c478bdstevel@tonic-gatebool_t has_other_links(struct file *, side_t);
2927c478bdstevel@tonic-gate/* maintain a name stack during directory tree traversal	*/
2937c478bdstevel@tonic-gatevoid push_name(const char *);
2947c478bdstevel@tonic-gatevoid pop_name();
2957c478bdstevel@tonic-gatechar *get_name(struct file *);
2977c478bdstevel@tonic-gate/* acl manipulation functions					*/
2987c478bdstevel@tonic-gateint get_acls(const char *, struct fileinfo *);
2997c478bdstevel@tonic-gateint set_acls(const char *, struct fileinfo *);
3007c478bdstevel@tonic-gateint cmp_acls(struct fileinfo *, struct fileinfo *);
3017c478bdstevel@tonic-gatechar *show_acls(int, aclent_t *);
3037c478bdstevel@tonic-gate#ifdef	__cplusplus
3077c478bdstevel@tonic-gate#endif	/* _DATABASE_H */