Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.sbin / ctm / ctm / ctm.h
1 /*
2  * ----------------------------------------------------------------------------
3  * "THE BEER-WARE LICENSE" (Revision 42):
4  * <phk@login.dknet.dk> wrote this file.  As long as you retain this notice you
5  * can do whatever you want with this stuff. If we meet some day, and you think
6  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
7  * ----------------------------------------------------------------------------
8  *
9  * $FreeBSD: src/usr.sbin/ctm/ctm/ctm.h,v 1.14.2.2 2001/07/05 02:30:52 kris Exp $
10  *
11  */
12
13 #include <ctype.h>
14 #include <err.h>
15 #include <errno.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <time.h>
20 #include <unistd.h>
21 #include <md5.h>
22 #include <regex.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <sys/file.h>
26 #include <sys/time.h>
27
28 #define VERSION "2.0"
29 #define MAXSIZE (1024*1024*40)
30
31 #define SUBSUFF ".ctm"
32 #define TMPSUFF ".ctmtmp"
33 #define TARCMD  "tar -rf %s -T -"
34
35 /* The fields... */
36 #define CTM_F_MASK              0xff
37 #define CTM_F_Name              0x01
38 #define CTM_F_Uid               0x02
39 #define CTM_F_Gid               0x03
40 #define CTM_F_Mode              0x04
41 #define CTM_F_MD5               0x05
42 #define CTM_F_Count             0x06
43 #define CTM_F_Bytes             0x07
44
45 /* The qualifiers... */
46 #define CTM_Q_MASK              0xff00
47 #define CTM_Q_Name_File         0x0100
48 #define CTM_Q_Name_Dir          0x0200
49 #define CTM_Q_Name_New          0x0400
50 #define CTM_Q_Name_Subst        0x0800
51 #define CTM_Q_MD5_After         0x0100
52 #define CTM_Q_MD5_Before        0x0200
53 #define CTM_Q_MD5_Chunk         0x0400
54 #define CTM_Q_MD5_Force         0x0800
55
56 struct CTM_Syntax {
57     char        *Key;           /* CTM key for operation */
58     int         *List;          /* List of operations */
59     };
60
61 extern struct CTM_Syntax Syntax[];
62
63 struct CTM_Filter {
64     struct CTM_Filter   *Next;  /* next filter in the list */
65     int                 Action; /* enable or disable */
66     regex_t             CompiledRegex;  /* compiled regex */
67 };
68
69 #define CTM_FILTER_DISABLE      0
70 #define CTM_FILTER_ENABLE       1
71
72 #define Malloc malloc
73 #define Free free
74 #define Delete(foo) if (!foo) ; else {Free(foo); foo = 0; }
75 #define String(foo) strdup(foo)
76
77 #ifndef EXTERN
78 #  define EXTERN extern
79 #endif
80 EXTERN u_char *Version;
81 EXTERN u_char *Name;
82 EXTERN u_char *Nbr;
83 EXTERN u_char *TimeStamp;
84 EXTERN u_char *Prefix;
85 EXTERN u_char *FileName;
86 EXTERN u_char *TmpDir;
87 EXTERN u_char *CatPtr;
88 EXTERN u_char *Buffer;
89 EXTERN u_char *BackupFile;
90 EXTERN u_char *TarCmd;
91
92 /*
93  * Paranoid -- Just in case they should be after us...
94  *  0 not at all.
95  *  1 normal.
96  *  2 somewhat.
97  *  3 you bet!.
98  *
99  * Verbose -- What to tell mom...
100  *  0 Nothing which wouldn't surprise.
101  *  1 Normal.
102  *  2 Show progress '.'.
103  *  3 Show progress names, and actions.
104  *  4 even more...
105  *  and so on
106  *
107  * ExitCode -- our Epitaph
108  *  0 Perfect, all input digested, no problems
109  *  1 Bad input, no point in retrying.
110  *  2 Pilot error, commandline problem &c
111  *  4 Out of resources.
112  *  8 Destination-tree not correct.
113  * 16 Destination-tree not correct, can force.
114  * 32 Internal problems.
115  *
116  */
117
118 EXTERN int Paranoid;
119 EXTERN int Verbose;
120 EXTERN int Exit;
121 EXTERN int Force;
122 EXTERN int CheckIt;
123 EXTERN int KeepIt;
124 EXTERN int ListIt;
125 EXTERN int SetTime;
126 EXTERN struct timeval Times[2];
127 EXTERN struct CTM_Filter        *FilterList;
128 EXTERN struct CTM_Filter        *LastFilter;
129
130 #define Exit_OK         0
131 #define Exit_Garbage    1
132 #define Exit_Pilot      2
133 #define Exit_Broke      4
134 #define Exit_NotOK      8
135 #define Exit_Forcible   16
136 #define Exit_Mess       32
137 #define Exit_Done       64
138 #define Exit_Version    128
139 #define Exit_NoMatch    256
140
141 void Fatal_(int ln, char *fn, char *kind);
142 #define Fatal(foo) Fatal_(__LINE__,__FILE__,foo)
143 #define Assert() Fatal_(__LINE__,__FILE__,"Assert failed.")
144 #define WRONG {Assert(); return Exit_Mess;}
145
146 u_char * Ffield(FILE *fd, MD5_CTX *ctx,u_char term);
147 u_char * Fname(FILE *fd, MD5_CTX *ctx,u_char term,int qual, int verbose);
148
149 int Fbytecnt(FILE *fd, MD5_CTX *ctx, u_char term);
150
151 u_char * Fdata(FILE *fd, int u_chars, MD5_CTX *ctx);
152
153 #define GETFIELD(p,q) if(!((p)=Ffield(fd,&ctx,(q)))) return BADREAD
154 #define GETFIELDCOPY(p,q) if(!((p)=Ffield(fd,&ctx,(q)))) return BADREAD; else p=String(p)
155 #define GETBYTECNT(p,q) if(0 >((p)= Fbytecnt(fd,&ctx,(q)))) return BADREAD
156 #define GETDATA(p,q) if(!((p) = Fdata(fd,(q),&ctx))) return BADREAD
157 #define GETNAMECOPY(p,q,r,v) if(!((p)=Fname(fd,&ctx,(q),(r),(v)))) return BADREAD; else p=String(p)
158
159 int Pass1(FILE *fd, unsigned applied);
160 int Pass2(FILE *fd);
161 int PassB(FILE *fd);
162 int Pass3(FILE *fd);
163
164 int ctm_edit(u_char *script, int length, char *filein, char *fileout);