1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved 24*0Sstevel@tonic-gate * 25*0Sstevel@tonic-gate * module: 26*0Sstevel@tonic-gate * database.h 27*0Sstevel@tonic-gate * 28*0Sstevel@tonic-gate * purpose: 29*0Sstevel@tonic-gate * definition of the baseline and rules data structures 30*0Sstevel@tonic-gate */ 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #ifndef _DATABASE_H 33*0Sstevel@tonic-gate #define _DATABASE_H 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gate #pragma ident "%W% %E% SMI" 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate #ifdef __cplusplus 38*0Sstevel@tonic-gate extern "C" { 39*0Sstevel@tonic-gate #endif 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate #include <sys/stat.h> 42*0Sstevel@tonic-gate #include <sys/acl.h> 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate #define ACL_UID_BUG 1 /* acl:SETACL sets owner to be caller */ 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate /* 47*0Sstevel@tonic-gate * flag bits describing what we know about an individual file, or in 48*0Sstevel@tonic-gate * some cases an entire base pair. These flags are found in the 49*0Sstevel@tonic-gate * base and file stuctures. 50*0Sstevel@tonic-gate */ 51*0Sstevel@tonic-gate typedef int fflags_t; /* type for file flags */ 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate #define F_NEW 0x01 /* newly allocated */ 54*0Sstevel@tonic-gate #define F_IN_BASELINE 0x02 /* file found in baseline */ 55*0Sstevel@tonic-gate #define F_IN_SOURCE 0x04 /* file found in source tree */ 56*0Sstevel@tonic-gate #define F_IN_DEST 0x08 /* file found in dest tree */ 57*0Sstevel@tonic-gate #define F_EVALUATE 0x10 /* include in analysis */ 58*0Sstevel@tonic-gate #define F_SPARSE 0x20 /* don't walk this directory */ 59*0Sstevel@tonic-gate #define F_REMOVE 0x40 /* remove from baseline */ 60*0Sstevel@tonic-gate #define F_CONFLICT 0x80 /* unresolvable conflict */ 61*0Sstevel@tonic-gate #define F_LISTED 0x100 /* file came from LIST */ 62*0Sstevel@tonic-gate #define F_STAT_ERROR 0x200 /* unable to stat file */ 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate #define F_WHEREFOUND (F_IN_BASELINE|F_IN_SOURCE|F_IN_DEST) 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate /* 67*0Sstevel@tonic-gate * a base is a pair of directories to be kept in sync 68*0Sstevel@tonic-gate * all rules and baseline data is stored beneath some base 69*0Sstevel@tonic-gate */ 70*0Sstevel@tonic-gate struct base { 71*0Sstevel@tonic-gate struct base *b_next; /* pointer to next base */ 72*0Sstevel@tonic-gate fflags_t b_flags; /* what I know about this base */ 73*0Sstevel@tonic-gate int b_ident; /* base sequence # (DBG) */ 74*0Sstevel@tonic-gate char *b_src_spec; /* spec name of source dir */ 75*0Sstevel@tonic-gate char *b_dst_spec; /* spec name of dest dir */ 76*0Sstevel@tonic-gate char *b_src_name; /* expanded name of source dir */ 77*0Sstevel@tonic-gate char *b_dst_name; /* expanded name of dest dir */ 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate struct rule *b_includes; /* chain of include rules */ 80*0Sstevel@tonic-gate struct rule *b_excludes; /* chain of exclude rules */ 81*0Sstevel@tonic-gate struct rule *b_restrictions; /* chain of restrictions */ 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate struct file *b_files; /* chain of files */ 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate /* statistics for wrap-up summary */ 86*0Sstevel@tonic-gate int b_totfiles; /* total files found in tree */ 87*0Sstevel@tonic-gate int b_src_copies; /* files copied to source */ 88*0Sstevel@tonic-gate int b_src_deletes; /* files deleted from source */ 89*0Sstevel@tonic-gate int b_src_misc; /* ownership changes on source */ 90*0Sstevel@tonic-gate int b_dst_copies; /* files copied to dest */ 91*0Sstevel@tonic-gate int b_dst_deletes; /* files deleted from dest */ 92*0Sstevel@tonic-gate int b_dst_misc; /* ownership changes on source */ 93*0Sstevel@tonic-gate int b_unresolved; /* unresolved conflicts */ 94*0Sstevel@tonic-gate }; 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate /* 97*0Sstevel@tonic-gate * flag bits describing what we know about a particular rule. 98*0Sstevel@tonic-gate * These flags are found in the rule structure 99*0Sstevel@tonic-gate */ 100*0Sstevel@tonic-gate typedef int rflags_t; /* type for rule flags */ 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gate #define R_NEW 0x01 /* newly added rule (=OPT_NEW) */ 103*0Sstevel@tonic-gate #define R_PROGRAM 0x02 /* program (vs literal names) */ 104*0Sstevel@tonic-gate #define R_IGNORE 0x04 /* IGNORE (vs INCLUDE) */ 105*0Sstevel@tonic-gate #define R_RESTRICT 0x08 /* restriction (-r argument) */ 106*0Sstevel@tonic-gate #define R_WILD 0x10 /* name involves wild cards */ 107*0Sstevel@tonic-gate #define R_BOGUS 0x20 /* fabricated rule */ 108*0Sstevel@tonic-gate 109*0Sstevel@tonic-gate /* 110*0Sstevel@tonic-gate * a rule describes files to be included or excluded 111*0Sstevel@tonic-gate * they are stored under bases 112*0Sstevel@tonic-gate */ 113*0Sstevel@tonic-gate struct rule { 114*0Sstevel@tonic-gate struct rule *r_next; /* pointer to next rule in base */ 115*0Sstevel@tonic-gate rflags_t r_flags; /* flags associated with rule */ 116*0Sstevel@tonic-gate char *r_file; /* file for this rule */ 117*0Sstevel@tonic-gate }; 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate /* 121*0Sstevel@tonic-gate * this is the information we keep track of for a file 122*0Sstevel@tonic-gate */ 123*0Sstevel@tonic-gate struct fileinfo { 124*0Sstevel@tonic-gate ino_t f_ino; /* inode number of this file */ 125*0Sstevel@tonic-gate long f_d_maj; /* maj dev on which it lives */ 126*0Sstevel@tonic-gate long f_d_min; /* minj dev on which it lives */ 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gate int f_type; /* file/dir/special ... */ 129*0Sstevel@tonic-gate int f_mode; /* protection */ 130*0Sstevel@tonic-gate int f_nlink; /* number of links to file */ 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate uid_t f_uid; /* owning UID */ 133*0Sstevel@tonic-gate gid_t f_gid; /* owning GID */ 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate off_t f_size; /* length in bytes */ 136*0Sstevel@tonic-gate long f_modtime; /* last modification time */ 137*0Sstevel@tonic-gate long f_modns; /* low order bits of modtime */ 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate long f_rd_maj; /* major dev for specials */ 140*0Sstevel@tonic-gate long f_rd_min; /* minor dev for specials */ 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gate int f_numacls; /* number of entries in acls */ 143*0Sstevel@tonic-gate aclent_t *f_acls; /* acl list (if any) */ 144*0Sstevel@tonic-gate }; 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate /* 147*0Sstevel@tonic-gate * flag bits describing the differences we have detected between a file 148*0Sstevel@tonic-gate * and the last time it was in sync (based on the baseline). 149*0Sstevel@tonic-gate * These flags are used in the srcdiffs and dstdiffs fields of the 150*0Sstevel@tonic-gate * file structure 151*0Sstevel@tonic-gate */ 152*0Sstevel@tonic-gate typedef int diffmask_t; /* type for difference masks */ 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate #define D_CREATE 0x01 /* file has been created */ 155*0Sstevel@tonic-gate #define D_DELETE 0x02 /* file has been deleted */ 156*0Sstevel@tonic-gate #define D_MTIME 0x04 /* file has been modified */ 157*0Sstevel@tonic-gate #define D_SIZE 0x08 /* file has changed size */ 158*0Sstevel@tonic-gate #define D_UID 0x10 /* file has changed user id */ 159*0Sstevel@tonic-gate #define D_GID 0x20 /* file has changed group id */ 160*0Sstevel@tonic-gate #define D_PROT 0x40 /* file has changed protection */ 161*0Sstevel@tonic-gate #define D_LINKS 0x80 /* file has changed link count */ 162*0Sstevel@tonic-gate #define D_TYPE 0x100 /* file has changed type */ 163*0Sstevel@tonic-gate #define D_FACLS 0x200 /* file has changed facls */ 164*0Sstevel@tonic-gate #define D_RENAME_TO 0x400 /* file came from a rename */ 165*0Sstevel@tonic-gate #define D_RENAME_FROM 0x800 /* file has been renamed */ 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate /* 168*0Sstevel@tonic-gate * these masks are used to determine how important potential changes are. 169*0Sstevel@tonic-gate * 170*0Sstevel@tonic-gate * D_CONTENTS there may be changes to the file's contents 171*0Sstevel@tonic-gate * D_ADMIN there may be changes to the ownership and protection 172*0Sstevel@tonic-gate * D_IMPORTANT there may be changes that should block a deletion 173*0Sstevel@tonic-gate * 174*0Sstevel@tonic-gate * Note: 175*0Sstevel@tonic-gate * I am torn on whether or not to include modtime in D_IMPORTANT. 176*0Sstevel@tonic-gate * Experience suggests that deleting one of many links affects the 177*0Sstevel@tonic-gate * file modification time. 178*0Sstevel@tonic-gate */ 179*0Sstevel@tonic-gate #define D_ADMIN (D_UID|D_GID|D_PROT|D_FACLS) 180*0Sstevel@tonic-gate #define D_CONTENTS (D_SIZE|D_TYPE|D_CREATE|D_MTIME) 181*0Sstevel@tonic-gate #define D_IMPORTANT (D_SIZE|D_TYPE|D_CREATE|D_MTIME|D_ADMIN) 182*0Sstevel@tonic-gate 183*0Sstevel@tonic-gate /* 184*0Sstevel@tonic-gate * a file is an instance that follows (under a base) from a rule 185*0Sstevel@tonic-gate * (for that base). A file structure may exist because of any 186*0Sstevel@tonic-gate * combination of a file under the source, destination, in a 187*0Sstevel@tonic-gate * baseline for historical reasons, or merely because a rule 188*0Sstevel@tonic-gate * calls it out (whether it exists or not). 189*0Sstevel@tonic-gate */ 190*0Sstevel@tonic-gate struct file { 191*0Sstevel@tonic-gate struct file *f_next; /* pointer to next file in base */ 192*0Sstevel@tonic-gate struct file *f_files; /* pointer to files in subdir */ 193*0Sstevel@tonic-gate struct base *f_base; /* pointer to owning base */ 194*0Sstevel@tonic-gate fflags_t f_flags; /* flags associated with file */ 195*0Sstevel@tonic-gate int f_depth; /* directory depth for file */ 196*0Sstevel@tonic-gate char *f_name; /* name of this file */ 197*0Sstevel@tonic-gate 198*0Sstevel@tonic-gate /* 199*0Sstevel@tonic-gate * these fields capture information, gleaned from the baseline 200*0Sstevel@tonic-gate * that is side-specific, and should not be expected to be in 201*0Sstevel@tonic-gate * agreement between the two sides. As a result, this info can 202*0Sstevel@tonic-gate * not be properly captured in f_info[OPT_BASE] and needs to 203*0Sstevel@tonic-gate * be kept somewhere else. 204*0Sstevel@tonic-gate */ 205*0Sstevel@tonic-gate long f_s_modtime; /* baseline source mod time */ 206*0Sstevel@tonic-gate ino_t f_s_inum; /* baseline source inode # */ 207*0Sstevel@tonic-gate long f_s_nlink; /* baseline source link count */ 208*0Sstevel@tonic-gate long f_s_maj; /* baseline source dev maj */ 209*0Sstevel@tonic-gate long f_s_min; /* baseline source dev min */ 210*0Sstevel@tonic-gate long f_d_modtime; /* baseline target mod time */ 211*0Sstevel@tonic-gate ino_t f_d_inum; /* baseline target inode # */ 212*0Sstevel@tonic-gate long f_d_nlink; /* baseline target link count */ 213*0Sstevel@tonic-gate long f_d_maj; /* baseline target dev maj */ 214*0Sstevel@tonic-gate long f_d_min; /* baseline target dev min */ 215*0Sstevel@tonic-gate 216*0Sstevel@tonic-gate /* stat information from baseline file and evaluation */ 217*0Sstevel@tonic-gate struct fileinfo f_info[3]; /* baseline, source, dest */ 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate /* summary of changes discovered in analysis */ 220*0Sstevel@tonic-gate diffmask_t f_srcdiffs; /* changes on source side */ 221*0Sstevel@tonic-gate diffmask_t f_dstdiffs; /* changes on dest side */ 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate /* this field is only valid for a renamed file */ 224*0Sstevel@tonic-gate struct file * f_previous; /* node for previous filename */ 225*0Sstevel@tonic-gate 226*0Sstevel@tonic-gate /* 227*0Sstevel@tonic-gate * these fields are only valid for a file that has been added 228*0Sstevel@tonic-gate * to the reconciliation list 229*0Sstevel@tonic-gate */ 230*0Sstevel@tonic-gate struct file *f_rnext; /* reconciliation chain ptr */ 231*0Sstevel@tonic-gate char *f_fullname; /* full name for reconciling */ 232*0Sstevel@tonic-gate long f_modtime; /* modtime for ordering purpose */ 233*0Sstevel@tonic-gate long f_modns; /* low order modtime */ 234*0Sstevel@tonic-gate 235*0Sstevel@tonic-gate /* this field is only valid for a file with a hard conflict */ 236*0Sstevel@tonic-gate char *f_problem; /* description of conflict */ 237*0Sstevel@tonic-gate }; 238*0Sstevel@tonic-gate 239*0Sstevel@tonic-gate /* 240*0Sstevel@tonic-gate * globals 241*0Sstevel@tonic-gate */ 242*0Sstevel@tonic-gate extern struct base omnibase; /* base for global rules */ 243*0Sstevel@tonic-gate extern struct base *bases; /* base for the main list */ 244*0Sstevel@tonic-gate extern int inum_changes; /* LISTed dirs with i# changes */ 245*0Sstevel@tonic-gate 246*0Sstevel@tonic-gate /* routines to manage base nodes, file nodes, and file infor */ 247*0Sstevel@tonic-gate errmask_t read_baseline(char *); 248*0Sstevel@tonic-gate errmask_t write_baseline(char *); 249*0Sstevel@tonic-gate struct file *add_file_to_base(struct base *, const char *); 250*0Sstevel@tonic-gate struct file *add_file_to_dir(struct file *, const char *); 251*0Sstevel@tonic-gate struct base *add_base(const char *src, const char *dst); 252*0Sstevel@tonic-gate void note_info(struct file *, const struct stat *, side_t); 253*0Sstevel@tonic-gate void update_info(struct file *, side_t); 254*0Sstevel@tonic-gate 255*0Sstevel@tonic-gate /* routines to manage rules */ 256*0Sstevel@tonic-gate errmask_t read_rules(char *); 257*0Sstevel@tonic-gate errmask_t write_rules(char *); 258*0Sstevel@tonic-gate errmask_t add_include(struct base *, char *); 259*0Sstevel@tonic-gate errmask_t add_ignore(struct base *, char *); 260*0Sstevel@tonic-gate 261*0Sstevel@tonic-gate /* routines to manage and querry restriction lists */ 262*0Sstevel@tonic-gate errmask_t add_restr(char *); 263*0Sstevel@tonic-gate bool_t check_restr(struct base *, const char *); 264*0Sstevel@tonic-gate 265*0Sstevel@tonic-gate /* routines for dealing with ignore lists */ 266*0Sstevel@tonic-gate void ignore_reset(); 267*0Sstevel@tonic-gate void ignore_pgm(const char *); 268*0Sstevel@tonic-gate void ignore_expr(const char *); 269*0Sstevel@tonic-gate void ignore_file(const char *); 270*0Sstevel@tonic-gate bool_t ignore_check(const char *); 271*0Sstevel@tonic-gate 272*0Sstevel@tonic-gate /* database processing routines for the primary passes */ 273*0Sstevel@tonic-gate errmask_t evaluate(struct base *, side_t, bool_t); 274*0Sstevel@tonic-gate errmask_t analyze(void); 275*0Sstevel@tonic-gate errmask_t find_renames(struct file *); 276*0Sstevel@tonic-gate errmask_t reconcile(struct file *); 277*0Sstevel@tonic-gate int prune(void); 278*0Sstevel@tonic-gate void summary(void); 279*0Sstevel@tonic-gate char *full_name(struct file *, side_t, side_t); 280*0Sstevel@tonic-gate 281*0Sstevel@tonic-gate /* routines in action.c to carry out reconciliation */ 282*0Sstevel@tonic-gate errmask_t do_copy(struct file *, side_t); 283*0Sstevel@tonic-gate errmask_t do_remove(struct file *, side_t); 284*0Sstevel@tonic-gate errmask_t do_rename(struct file *, side_t); 285*0Sstevel@tonic-gate errmask_t do_like(struct file *, side_t, bool_t); 286*0Sstevel@tonic-gate 287*0Sstevel@tonic-gate /* routines to deal with links in the reconciliation list */ 288*0Sstevel@tonic-gate struct file *find_link(struct file *, side_t); 289*0Sstevel@tonic-gate void link_update(struct file *, side_t); 290*0Sstevel@tonic-gate bool_t has_other_links(struct file *, side_t); 291*0Sstevel@tonic-gate 292*0Sstevel@tonic-gate /* maintain a name stack during directory tree traversal */ 293*0Sstevel@tonic-gate void push_name(const char *); 294*0Sstevel@tonic-gate void pop_name(); 295*0Sstevel@tonic-gate char *get_name(struct file *); 296*0Sstevel@tonic-gate 297*0Sstevel@tonic-gate /* acl manipulation functions */ 298*0Sstevel@tonic-gate int get_acls(const char *, struct fileinfo *); 299*0Sstevel@tonic-gate int set_acls(const char *, struct fileinfo *); 300*0Sstevel@tonic-gate int cmp_acls(struct fileinfo *, struct fileinfo *); 301*0Sstevel@tonic-gate char *show_acls(int, aclent_t *); 302*0Sstevel@tonic-gate 303*0Sstevel@tonic-gate #ifdef __cplusplus 304*0Sstevel@tonic-gate } 305*0Sstevel@tonic-gate #endif 306*0Sstevel@tonic-gate 307*0Sstevel@tonic-gate #endif /* _DATABASE_H */ 308