1 /*-
2  * Copyright (c) 2001-2003 Allan Saddi <allan@saddi.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY ALLAN SADDI AND HIS CONTRIBUTORS ``AS IS''
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL ALLAN SADDI OR HIS CONTRIBUTORS BE
18  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  * POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $Id: yafic.h 906 2003-12-06 00:05:14Z asaddi $
27  */
28 
29 #ifndef _YAFIC_H
30 #define _YAFIC_H
31 
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 
35 #if HAVE_INTTYPES_H
36 # include <inttypes.h>
37 #else
38 # if HAVE_STDINT_H
39 #  include <stdint.h>
40 # endif
41 #endif
42 
43 #define DEFAULT_CONF "yafic.conf"
44 #define DEFAULT_ROOT ""
45 #define DEFAULT_CHECK_DB "yafic.db"
46 #define DEFAULT_UPDATE_DB "yafic_new.db"
47 
48 #define RULESET_TABLE_SIZE 1021
49 
50 #define RFLAG_PERM	1
51 #define RFLAG_INODE	2
52 #define RFLAG_NLINK	4
53 #define RFLAG_UID	8
54 #define RFLAG_GID	16
55 #define RFLAG_SIZE	32
56 #define RFLAG_ATIME	64
57 #define RFLAG_MTIME	128
58 #define RFLAG_CTIME	256
59 #define RFLAG_HASH	512
60 
61 #define RFLAG_IGNORE	1024
62 #define RFLAG_UPDATE	2048
63 
64 #define RFLAG_DEFAULT	(RFLAG_PERM | RFLAG_INODE | RFLAG_NLINK | \
65 			 RFLAG_UID | RFLAG_GID | RFLAG_MTIME | \
66 			 RFLAG_CTIME | RFLAG_HASH)
67 
68 #define RFLAG_MAX	10
69 
70 enum {
71   RMASK_DIR = 0,
72   RMASK_FILE,
73   RMASK_LINK,
74   RMASK_SPECIAL,
75 
76   RMASK_MAX
77 };
78 
79 #define RMASK_DEFAULT	(RFLAG_PERM | RFLAG_INODE | RFLAG_NLINK | \
80 			 RFLAG_UID | RFLAG_GID | RFLAG_SIZE | RFLAG_ATIME | \
81 			 RFLAG_MTIME | RFLAG_CTIME | RFLAG_HASH)
82 
83 typedef unsigned short rflag_t;
84 
85 struct RuleEntry {
86   struct RuleEntry *next; /* Next entry in hash chain. */
87 
88   char *path; /* Pathname of entry. */
89   rflag_t entryFlags; /* Entry's flags. */
90   rflag_t descFlags; /* Flags of any descendents. */
91   rflag_t masks[RMASK_MAX]; /* Per-type masks for descendents. */
92 };
93 
94 #define CONFIG_DIRMASK "%dirmask"
95 #define CONFIG_FILEMASK "%filemask"
96 #define CONFIG_LINKMASK "%linkmask"
97 #define CONFIG_SPECIALMASK "%specialmask"
98 
99 /* yafic.c */
100 extern int Verbosity;
101 extern int DisplayHashes;
102 extern int SignVerifyFiles;
103 
104 /* yafic.c */
105 const char *ToHexStr (const uint8_t *data, int len);
106 void DisplayFileHash (int fd, const char *filename);
107 
108 /* ruleset.c */
109 void InitRuleSet (void);
110 int ParseRuleSet (const char *conf);
111 struct RuleEntry *FindRuleEntry (const char *path);
112 struct RuleEntry *FindClosestRuleEntry (const char *path);
113 void ApplyRuleSet (void (*func) (struct RuleEntry *re));
114 void DumpClassFlags (void);
115 void DumpRuleEntry (struct RuleEntry *re);
116 void CleanRuleSet (void);
117 
118 /* view.c */
119 void ViewDB (const char *root, const char *dbName, const char *type);
120 
121 /* statpack.c */
122 void PackStat (struct stat *sb, uint8_t *buf);
123 void UnpackStat (uint8_t *buf, struct stat *sb);
124 
125 #endif /* !_YAFIC_H */
126