File: common.h

package info (click to toggle)
smtpfeed 1.02-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 824 kB
  • ctags: 765
  • sloc: ansic: 13,150; sh: 230; perl: 133; makefile: 97
file content (408 lines) | stat: -rw-r--r-- 12,395 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/*
 * Copyright (c) 1997,1998 Motonori Nakamura <motonori@econ.kyoto-u.ac.jp>
 * Copyright (c) 1997,1998 WIDE Project
 * Copyright (c) 1997,1998 Kyoto University
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by WIDE Project and
 *      its contributors.
 * 4. Neither the name of the Project, the University nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Id: common.h,v 1.55 1999/03/02 21:59:57 motonori Exp $
 */

# include "compat.h"

#if HAVE_PORT_BEFORE_H
# include "port_before.h"
#endif

# include <stdio.h>
# include <unistd.h>
#ifdef EX_OK
/* to avoid macroname collision on SGI box */
#  undef EX_OK
#endif
# include <stdlib.h>
# include <string.h>
# include <time.h>
# include <sys/time.h>
# include <sys/types.h>
# include <ctype.h>
# include <sys/param.h>
# include <sys/resource.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# include <arpa/nameser.h>
# include <sys/socket.h>
# include <sys/stat.h>
# include <setjmp.h>
# include <resolv.h>
# include <netdb.h>
# include <syslog.h>
# include <sysexits.h>
# include <fcntl.h>
# include <signal.h>
# include <errno.h>
#ifndef FD_SET
# include <sys/select.h>
#endif

#ifdef __STDC__
# include <stdarg.h>
# define VA_LOCAL_DECL		va_list ap;
# define VA_START(f)		va_start(ap, f)
# define VA_END			va_end(ap)
#else
# include <varargs.h>
# define VA_LOCAL_DECL		va_list ap;
# define VA_START(f)		va_start(ap)
# define VA_END			va_end(ap)
#endif

/* Missing macro definitions */
#ifndef HFIXEDSZ
# define HFIXEDSZ	12		/* arpa/nameser.h */
#endif
#ifndef QFIXEDSZ
# define QFIXEDSZ	4		/* arpa/nameser.h */
#endif
#ifndef INT16SZ
# define INT16SZ	2		/* arpa/nameser.h */
#endif
#ifndef INT32SZ
# define INT32SZ	4		/* arpa/nameser.h */
#endif
#ifndef INADDR_NONE
# define INADDR_NONE	0xffffffff	/* netinet/in.h */
#endif
#ifndef EX_CONFIG
# define EX_CONFIG	78		/* sysexit.h */
#endif

#ifndef MAXHOSTNAMELEN
# define MAXHOSTNAMELEN	256		/* sys/param.h */
#endif

#if HAVE_PORT_AFTER_H
# include "port_after.h"
#endif

/* bind8 modification on FreeBSD 2.2.x */
#ifdef NS_NOTIFY_OP
# ifndef NS_UPDATE_OP
#  define NS_UPDATE_OP	5
# endif
#else
# define NS_UPDATE_OP	ns_o_update
#endif
#define GET16	_getshort

/* See conf.h of sendmail to determine size */
#ifdef ultrix
#  define SYSLOG_BUFSIZE	256
#endif
#ifdef sgi
/* how can I detect IRIX 6 ? */
#  define SYSLOG_BUFSIZE	512	/* IRIX 6 only */
#endif
#ifndef SYSLOG_BUFSIZE
#  define SYSLOG_BUFSIZE	1024
#endif


# define LOG_DEFAULT		LOG_LOCAL5
# define LOG_NONE		-1	/* (must be < 0) */
# define LOG_STDERR		-2	/* (must be < 0) */

# define MAXLINE		1024
# define CHUNKSIZE		1024*50
# define SMTPBUFSIZE		2048

#ifndef MAX_SOCK
# define MAX_SOCK		(FD_SETSIZE - 1)
#endif

# define SECONDS		*1
# define MINUTES		*60

# define SMTP_ERROR(x)		(500+x)
# define SMTP_TEMPFAIL(x)	(400+x)

# define RR_ANY			0x01
# define RR_MX			0x02
# define RR_CNAME		0x04
# define RR_A			0x08
#ifdef INET6
# define RR_AAAA		0x10
#endif
# define RR_ALL			0x1f

# define MALLOC(x)		((sti.mem += (x)), malloc(x))

struct query_chain {
	char			*request;
	u_char			type;
	u_char			need;
	int			reqlen;
	u_char			try;
	u_char			ns;
	u_char			badns;
	u_char			nocache;
	time_t			time;
	struct dns_stat		*stat;
	struct query_chain	*chain;
	struct query_chain	*next;
	struct query_chain	*prev;
};

/* DNS query history hash entry */
struct dns_stat {
	struct dns_stat		*next;
	char			*name;		/* name for query */
	u_char			rr_sent;
	u_char			rr_need;
	u_char			rr_got;
	u_char			rr_timeout;
	u_char			rr_noex;
	struct mx		*mx;
	struct dns_stat		*cname;
	struct query_chain	*requests;
};

/* alias names for this host to eliminate lower MX hosts */
struct hostalias {
	char			*name;		/* alias name */
	struct hostalias	*next;		/* next alias */
};

/* address information for a host */
struct inetaddr {
	int			domain;		/* INET or INET6 or ... */
	int			len;		/* address length */
	char			*address;	/* address */
	int			stat;		/* error status for TCP */
	struct inetaddr		*next;		/* next address for the host */
};

struct host {
	char			*name;		/* host name */
	struct host		*next;		/* chain just for management */
	struct inetaddr		*addr;		/* top of address list */
	struct inetaddr		*current;	/* working address */
	int			proto;
	int			state;		/* state of SMTP connection */
	time_t			time;
	int			stat;		/* error status for SMTP */
	char			*response;	/* response code of SMTP */
	time_t			start;		/* start time of transaction */
	struct mx		*mx_ref;	/* MX reference list */
	struct host		*hash;		/* host chain in hash table */
};

struct mx {
	char			*name;		/* MX name */
#if 0
	int			stat;		/* error status for A query */
	char			*response;	/* error response */
#endif
	int			pref;		/* preference */
	int			weight;		/* random value for same pref */
	struct host		*host;		/* address information */
	struct mx		*next;		/* next MX */
	struct mx		*mx_ref;	/* MX reference list */
	struct domain		*domain;	/* reverse link to domain */
};

struct host_map {
	char			*name;		/* destination domain */
	char			**arg;		/* way of host lookup */
	struct host_map		*next;		/* map chain */
	struct host_map		*hash;		/* chain in hash table */
};

struct domain {
	char			*name;		/* domain part of mail addr */
	int			stat;		/* error status for MX query */
	char			*response;	/* error response */
	struct mx		*firstmx;	/* first MX */
	struct mx		*curmx;		/* working MX */
	int			checked;	/* temporary local flag */
	struct domain		*next;		/* chain just for management */
	struct recipient	*rcpt_top;	/* recipient list to domain */
	struct recipient	*rcpt_tail;	/* recipient list to domain */
	struct domain		*workchain;	/* domain chain with job */
	struct domain		*hash;		/* domain chain in hash table */
	char			**map_arg;	/* way of host lookup */
};

# define RCPT_NOOP	0
# define RCPT_RETRY	1
# define RCPT_WORK	2
# define RCPT_DONE	3

struct recipient {
	char			*address;	/* mail address */
	char			*notify;	/* NOTIFY= parameter */
	char			*orcpt;		/* ORCPT= parameter */
	int			stat;		/* current status */
	int			result;		/* final result */
	char			*response;	/* final response */
	struct domain		*domain;	/* domain part */
	struct host		*final;
	struct recipient	*next;		/* next recipient */
	struct recipient	*chain;		/* chain for the same host */
	struct recipient	*dom_chain;	/* chain for the same domain */
};

struct message {
	char			*data;		/* data chunk */
	int			offset;		/* length of this chunk */
	struct message		*next;		/* next chunk */
};

struct envelope {
	char			*sender;	/* sender address */
	char			*envid;		/* ENVID= parameter */
	char			*size;		/* SIZE= parameter */
	char			*body;		/* BODY= parameter */
	char			*ret;		/* RET= parameter */
	char			*mid;		/* Message-Id */
	char			*queueid;	/* queie-id from sendmail */
	int			keepqueueid;	/* no purge flag on queueid */
	int			realsize;	/* size of message */
	struct recipient	*rcpt_list;	/* recipient list */
	struct recipient	*rcpt_tail;	/* tail of recipient list */
	struct recipient	*resp_ptr;	/* LMTP response pointer */
	struct message		*msg;		/* data body */
	struct domain		*work_domain;	/* working domain list */
	struct domain		*work_dom_ptr;	/* working domain pointer */
};

struct connection {
	int			seq;		/* seq. number of this trans. */
	int			socket;		/* socket descriptor */
	char			*inbuf;		/* input buffer */
	int			inlen;		/* data length in input buf */
	char			*outbuf;	/* output buffer */
	int			outlen;		/* data length in output buf */
	int			bufsize;	/* allocated size of buffers */
	struct host		*host;		/* destination host */
	struct recipient	*rcpt;		/* sending recipient */
	struct recipient	*crcpts;	/* current sending recipient */
	struct recipient	*crcptr;	/* current waiting response */
	int			goodrcpt;	/* at least 1 good address */
	int			goodmail;	/* MAIL is OK on PIPELINING */
	int			datasent;	/* DATA sent on PIPELINING */
	struct message		*msg;		/* sending data chunk */
	int			offset;		/* start pos to be sent next */
	int			reuse;		/* this conn. must be reused */
};

struct statinfo {
	int			nrcpt;		/* total recipients */
	int			nqueries;	/* total DNS queries */
	int			nanswers;	/* total DNS answers */
	int			nconnect;	/* total count of connect() */
	int			nquitok;	/* total successful conns */
	int			ntimeout;	/* total timed out conn.s */
	int			ntrans;		/* total transactions */
	int			noktrans;	/* total successful trans. */
	int			nsent;		/* total sent recps */
	int			ndeferred;	/* total deferred recps */
	int			nnsfailed;	/* total recps w/ err. (NS) */
	int			nsmtpfailed;	/* total recps w/ err. (SMTP) */
	int			minsock;	/* min# of used sockets */
	int			maxsock;	/* max# of used sockets */
	int			dns_inb;	/* total incoming DNS traffic */
	int			dns_outb;	/* total outgoing DNS traffic */
	int			inbounds;	/* total incoming traffic */
	int			outbounds;	/* total outgoing traffic */
	int			mem;		/* total allocated memory */
	time_t			time_sm_start;	/* start time of sendmail */
	time_t			time_start;	/* start time of delivery */
	time_t			time_mxgot;	/* time all MX got */
	time_t			time_almostfinish;	/* finished time of delivery */
	time_t			time_finish;	/* finished time of delivery */
	time_t			max_delay;	/* longest transaction */
};

# define DEBUG_ADDRESS		0x0001
# define DEBUG_CONNECT		0x0002
# define DEBUG_EVENT		0x0004
# define DEBUG_LMTP		0x0008
# define DEBUG_DNS		0x0010
# define DEBUG_TRANS		0x0020
# define DEBUG_SMTP		0x0040
# define DEBUG_RESUSE		0x0080
# define DEBUG_HASH		0x0100
# define DEBUG_MAP		0x0200
# define DEBUG_ALL		0x03FF
# define DEBUG_NODELIVERY	0x1000
# define DEBUG_QUERYONLY	0x2000

#ifdef INET6			/* flags */
# define SMTP_V4		0x1
# define SMTP_V6		0x2
#endif

struct confparam {
#ifdef INET6
	int			inetdom;	/* internet domain */
#endif
	int			sd_max;		/* max of socket descriptor */
	int			rcpt_min;	/* recipient lower limit */
	int			sendbufsize;	/* TCP send buffer size */
	int			data_max;	/* max size of message */
	int			src_port;	/* SMTP source port */
	int			dst_port;	/* SMTP destination port */
	int			useAfirstMX;	/* use A RR if first MX */
	int			nopipelining;	/* surpress SMTP pipelining */
	int			tryANYfirst;	/* try T_ANY query first */
	int			debug;		/* debug flags */
	int			log_facility;	/* logging facility */
	int			rcpts_trans;	/* recipients per transaction */
	int			parsequeueid;	/* get queue-id info. */
	int			showversion;	/* show version info. */
	int			showrecipient;	/* show recipient info. */
	int			smtp_reuse;	/* reuse SMTP connection */
	time_t			t_timeout;	/* total timeout */
	char			*map;		/* path of map file */
	char			*fallbackmx;	/* name of fallback MX host */
	char			*sourceIP;	/* source address for SMTP */
	char			*src_mod_path;	/* addr. list file to modify */
	char			*src_mod_ptn;	/* modification pattern */
};

union SockAddrUnion {
	struct sockaddr_in	in;
#ifdef INET6
	struct sockaddr_in6	in6;
#endif
};
typedef union SockAddrUnion SockAddr;