1 /*
2  * Copyright (C) 2001, 2002, and 2003  Roy Keene
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  *
18  *      email: dact@rkeene.org
19  */
20 
21 #ifndef _DACT_H
22 #define _DACT_H
23 
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27 
28 #include "win32.h"
29 
30 #ifndef DACT_CONTACT
31 #define DACT_CONTACT "<dact@rkeene.org>"
32 #endif
33 
34 #ifndef DACT_KEY_SIZE
35 #define DACT_KEY_SIZE 2048
36 #endif
37 
38 #define DACT_VER_MAJOR 0
39 #define DACT_VER_MINOR 8
40 #define DACT_VER_REVISION 42
41 #define DACT_VERSION "0.8.42"
42 #ifdef DEBUG
43 #define DACT_VER_SUB	"dev"
44 #else
45 #define DACT_VER_SUB	"rel"
46 #endif
47 
48 #define DACT_MODE_COMPR 1
49 #define DACT_MODE_DECMP 2
50 #define DACT_MODE_STAT  3
51 #define DACT_MODE_RET   4
52 #define DACT_MODE_CINIT	5
53 #define DACT_MODE_CENC	6
54 #define DACT_MODE_CDEC	7
55 #define DACT_MODE_CIENC 11   /* CINIT+CENC */
56 #define DACT_MODE_DIDEC 12   /* CINIT+CDEC */
57 
58 #define DACT_OPT_FORCE	0
59 #define DACT_OPT_STDOUT	1
60 #define DACT_OPT_VERB	2
61 #define DACT_OPT_COMPLN	3
62 #define DACT_OPT_VERCHK	4
63 #define DACT_OPT_BINCHK	5
64 #define DACT_OPT_TIME	6
65 #define DACT_OPT_PERM	7
66 #define DACT_OPT_ORIG	8
67 #define DACT_OPT_HDONLY	9
68 #define DACT_OPT_SZSPD	10
69 #define DACT_OPT_NOCRC	11
70 #define DACT_OPT_NETWORK 12
71 #define DACT_OPT_URL	13
72 #define DACT_OPT_UPGRADE 14
73 #define DACT_OPT_SFX	15
74 
75 /* These should only be changed at the risk of breaking files.
76  * (in other words, they should not be changed if possible.
77  *  Adding on to them is fine.)
78  */
79 #define DACT_HDR_CRC0	0
80 #define DACT_HDR_CRC1	1
81 #define DACT_HDR_TIME	2
82 #define DACT_HDR_PERM	3
83 #define DACT_HDR_NAME	4
84 #define DACT_HDR_MD5SUM	5
85 #define DACT_HDR_DESC	6
86 #define DACT_HDR_URL	7
87 #define DACT_HDR_URLFILE	8
88 #define DACT_HDR_CIPHER	9
89 #define DACT_HDR_NOP	10
90 #define DACT_HDR_IDXDATA	11
91 #define DACT_HDR_SFXLEN	12
92 
93 #ifndef DACT_BLK_SIZE_MAX
94 #define DACT_BLK_SIZE_MAX 4194304
95 #endif
96 
97 #ifndef DACT_BLK_SIZE_ABSMAX
98 #define DACT_BLK_SIZE_ABSMAX 2147483647
99 #endif
100 
101 #ifndef DACT_BLK_SIZE_DEF
102 #define DACT_BLK_SIZE_DEF 8192
103 #endif
104 
105 #ifdef HAVE_GETOPT_H
106 #include <getopt.h>
107 #else
108 #include "getopt.h"
109 #endif
110 
111 #ifndef HAVE_STRSEP
112 #include "strsep.h"
113 #endif
114 #ifndef HAVE_GETPASS
115 #include "getpass.h"
116 #endif
117 #ifndef HAVE_MKSTEMP
118 #include "mkstemp.h"
119 #endif
120 #ifndef HAVE_UNAME
121 #include "uname.h"
122 #endif
123 
124 #ifdef HAVE_STDINT_H
125 #include <stdint.h>
126 #endif
127 #ifdef HAVE_INTTYPES_H
128 #include <inttypes.h>
129 #endif
130 #ifdef HAVE_STRING_H
131 #include <string.h>
132 #endif
133 #ifdef HAVE_STDIO_H
134 #include <stdio.h>
135 #endif
136 #ifdef HAVE_ERRNO_H
137 #include <errno.h>
138 #endif
139 #ifdef HAVE_UNISTD_H
140 #include <unistd.h>
141 #endif
142 
143 #include "comp_fail.h"
144 #include "dact_common.h"
145 
146 #define DACT_MAGIC_NUMBER 0x444354C3
147 #define DACT_MAGIC_OFFSET 0
148 #define DACT_MAGIC_SIZE   4
149 #define DACT_MAGIC_PEOF   0xFF3FDE08
150 
151 #if defined(__FILE__) && defined(__LINE__) && defined(DEBUG)
152 #define PRINT_LINE fprintf(stderr, "%s:%07i:%s(): ", __FILE__, __LINE__, __func__)
153 #else
154 #define PRINT_LINE /**/
155 #endif
156 
157 #define PERROR_L(errnum, error) { PRINT_LINE; fprintf(stderr, "dact: %s: %s\n", error, strerror(abs(errnum))); }
158 #define PRINTERR(error) { PRINT_LINE; fprintf(stderr, "dact: " error "\n"); }
159 #define PERROR(error) PERROR_L(errno, error)
160 /* #define PERROR(error) { PRINT_LINE; perror("dact: " error); } */
161 
162 #ifdef DEBUG
163 #define SPOTVAR_NUM(x) { PRINT_LINE; fprintf(stderr, "dact: %s=%li\n", #x, (long) x); }
164 #define SPOTVAR_STR(x) { PRINT_LINE; fprintf(stderr, "dact: %s=\"%s\"\n", #x, x); }
165 #define CHECKPOINT PRINTERR("Checkpoint reached.")
166 #else
167 #define SPOTVAR_NUM(x) /**/
168 #define SPOTVAR_STR(x) /**/
169 #define CHECKPOINT /**/
170 #endif
171 
172 #ifndef DACT_FAILED_ALGO
173 #define DACT_FAILED_ALGO comp_fail_algo
174 #endif
175 
176 #ifdef HAVE_DEV_URANDOM
177 #define RANDOM_DEV "/dev/urandom"
178 #endif
179 
180 #ifndef DACT_VER_PARTS
181 #define DACT_VER_PARTS(x) ((x&0xff0000)>>16),((x&0xff00)>>8),(x&0xff)
182 #endif
183 
184 #ifndef DACT_VERS
185 #define DACT_VERS(x,y,z) (((x)<<16)|((y)<<8)|(z))
186 #endif
187 
188 #ifndef DACT_BIN_URL
189 #define DACT_BIN_URL "http://www.rkeene.org/projects/compression/dact/@@OSNM@@-@@ARCH@@/dact.bin"
190 #endif
191 #ifndef DACT_BIN_URL_VER
192 #define DACT_BIN_URL_VER "http://www.rkeene.org/projects/compression/dact/@@OSNM@@-@@ARCH@@/dact.ver"
193 #endif
194 #ifndef DACT_BIN_DIR
195 #define DACT_BIN_DIR "@@HOME@@/.dact/@@OSNM@@-@@ARCH@@/"
196 #endif
197 #ifndef DACT_BIN
198 #ifndef EXEEXT
199 #define EXEEXT ".bin"
200 #endif
201 #define DACT_BIN DACT_BIN_DIR "dact" EXEEXT
202 #endif
203 #define DACT_BIN_VER ((DACT_VER_MAJOR<<16)|(DACT_VER_MINOR<<8)|DACT_VER_REVISION)
204 
205 /* We need to determine when we have network support */
206 #if !defined(HAVE_SOCKET) || !defined(HAVE_GETHOSTBYNAME) || (!defined(HAVE_INET_ATON) && !defined(HAVE_INET_ADDR))
207 #ifndef NO_NETWORK
208 #define NO_NETWORK 1
209 #endif
210 #endif
211 
212 
213 int print_help(int argc, char **argv);
214 int dact_upgrade_file_checkver(const char *name, const char *url_ver, const unsigned char *options);
215 int dact_upgrade_file(const char *name, const char *url_get, const char *url_ver, uint32_t version, const char *dest, const unsigned char *options);
216 int dact_shutdown(int retval);
217 char *dact_getoutfilename(const char *orig, const int mode, const char *ext);
218 int main(int argc, char **argv);
219 
220 #endif/*_DACT_H*/
221