1 /*
2 **
3 ** Copyright (C) 1993 Swedish University Network (SUNET)
4 **
5 **
6 ** This program is developed by UDAC, Uppsala University by commission
7 ** of the Swedish University Network (SUNET).
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITTNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 **
23 **
24 **                                           Martin.Wendel@its.uu.se
25 ** 				             Torbjorn.Wictorin@its.uu.se
26 **
27 **                                           ITS
28 **                                           P.O. Box 887
29 **                                           S-751 08 Uppsala
30 **                                           Sweden
31 **
32 */
33 #include "config.h"
34 
35 /*
36  * ifdefs, used for portability
37  */
38 
39 #if STDC_HEADERS || HAVE_STRING_H
40 #include <string.h>
41 /* An ANSI string.h and pre-ANSI memory.h might conflict */
42 #if !STDC_HEADERS && HAVE_MEMORY_H
43 #include <memory.h>
44 #endif /* not STDC_HEADERS && HAVE_MEMORY_H */
45 #ifndef	RINDEX_DEFINED
46 #define index strchr
47 #define rindex strrchr
48 #endif
49 #define bcopy(s, d, n) memcpy((d), (s), (n))
50 #define bcmp(s1, s2, n) memcmp((s1), (s2), (n))
51 #define bzero(s, n) memset((s), 0, (n))
52 #else /* not STDC_HEADERS and not HAVE_STRING_H */
53 #include <strings.h>
54 /* memory.h and strings.h conflict on some systems */
55 #endif /* not STDC_HEADERS and not HAVE_STRING_H */
56 
57 #ifdef HAVE_SYSEXITS_H
58 #include <sysexits.h>
59 #else
60 #define EX_OK     0
61 #define EX_NOINPUT 66
62 #define EX_UNAVAILABLE 69
63 #define EX_SOFTWARE 70
64 #define EX_OSERR 71
65 #define EX_OSFILE 72
66 #define EX_CANTCREAT 73
67 #define EX_IOERR 74
68 #define EX_TEMPFAIL 75
69 #define EX_NOHOST 76
70 #define EX_NOPERM 77
71 #define EX_NOUSER 78
72 #define EX_USAGE 79
73 #endif
74 
75 #ifndef	__P
76 #if defined(__STDC__)
77 #define __P(protos) protos   /* Full-blown ANSI C */
78 #else
79 #define __P(protos) ()       /* Traditional C preprocessor */
80 #endif /* !__STDC__ */
81 #endif
82 
83 
84 
85 
86 /*
87  * Standard includes
88  */
89 #include <stdio.h>
90 #include <sys/types.h>
91 #include <syslog.h>
92 #include <stdlib.h>
93 #include <ctype.h>
94 #ifdef	HAVE_UNISTD_H
95 #include <unistd.h>
96 #endif
97 #include <assert.h>
98 #include <fcntl.h>
99 
100 /*
101  * C function definitions
102 */
103 
104 #ifndef	STRCASECMP_DEFINED
105 int	strcasecmp(char *, char *);
106 #endif
107 #ifndef	STRNCASECMP_DEFINED
108 int	strncasecmp(char *, char *, int);
109 #endif
110 
111 
112 #ifdef NAMED_BIND
113 #ifdef USE_MX
114 struct mxlist {
115   char *host;
116   int preference;
117   struct mxlist *next;
118 };
119 #endif
120 #endif
121 
122 /*
123  * Configuration parameters
124 */
125 
126 struct	config_struct {
127 	struct	config_struct * gg;
128 	char	* name,
129 		* charset,
130 	        * appletype,
131 		* format,
132  	        * text,
133                 * header,
134 		* bin;
135 	int     iformat,
136 	        ibin,
137 	        itext,
138 	        iapple,
139 	        htext;
140 };
141 
142 /*
143  * Macros
144  */
145 
146 #define APPEND_LINE(L1, L2) strcat(L1, L2)
147 #define NEWSTR(S) S!=NULL?strcpy((char *)malloc(strlen(S) + 1), S):NULL
148 
149 
150 /*
151  * Defines
152  */
153 
154 /* General status */
155 #define OK 0
156 #define NOK -1
157 #define TRUE 1
158 #define FALSE 0
159 #define FAIL -1
160 #define SKIP -2
161 #define DONE -3
162 #define CONT -4
163 
164 /* Used for delimiter matches */
165 #define E7BIT     0x001
166 #define E8BIT     0x002
167 #define EBINARY   0x004
168 #define EBINHEX   0x008
169 #define EUUENCODE 0x010
170 #define EMULTI    0x020
171 #define EBASE64   0x040
172 #define EQP       0x080
173 #define ESE       0x100
174 
175 
176 /* Applefile type specifications */
177 #define ABINHEX   0x001  /* BinHexed applefile */
178 #define AMDOUBLE  0x002  /* Multipart Appledouble */
179 #define ADOUBLE   0x004  /* Appledouble */
180 #define ASINGLE   0x008  /* Applesingle */
181 #define AFILE     0x010  /* Applefile */
182 #define AMFILE    0x020  /* Multipart Applefile */
183 #define ARESOURCE 0x040  /* Resource fork */
184 
185 /* Main types */
186 #define RFC822 0      /* Default */
187 #define MIME 1
188 #define MAILTOOL 2
189 #define TRANSPARENT 3 /* Transparent delivery (no conversion) */
190 
191 /*
192  * Sizes
193  */
194 
195 #define HDRLEN 2048
196 #define MIMEBOUNDLEN 60
197 #define HEAD_BUF 16
198 #define MED_BUF 256
199 
200 /* Pseudos */
201 #define UNQUOTE 1
202 #define UNSPACE 2
203 
204 /* Header fields */
205 #define UNKNOWN    0
206 #define COMMENT    1
207 #define HQSTRING   2
208 #define DLITERAL   4
209 #define RADDR      8
210 #define RFC1522   16
211 #define ATOM      32
212 #define DELIMITER 64
213 #define TEXT     128
214 #define TOP      256
215 /*
216  * Externals
217  */
218 extern long alloc_total;
219 extern int want_unix_from;
220 extern off_t pz;
221 extern char ebuf[1024];
222 extern char *sender;
223 extern char *hostname;
224 extern char *recipient;
225 extern char *rmx;
226 extern short det_sket_sig;
227 extern struct body *currbody;
228 extern struct message *rootmess;
229 extern struct config_struct *source;
230 extern struct config_struct *target;
231 extern char **mailer;
232 extern int process;
233 #ifdef DEBUG
234 extern int edebug;
235 #endif
236 #include "attr.h"
237 #include "func.h"
238 #ifdef	hpux
239 /* pagesize if a bit uncertain */
240 #define	getpagesize()	4096
241 #else
242 #ifdef	aix
243 size_t	getpagesize();	/* Should really be in unistd.h */
244 #endif
245 #endif
246 
247