548f70dbd60f9ce7648711130965e6d6a1f13fad
[exim.git] / src / src / local_scan.h
1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
4
5 /* Copyright (c) University of Cambridge 1995 - 2018 */
6 /* See the file NOTICE for conditions of use and distribution. */
7
8 /* This file is the header that is the only Exim header to be included in the
9 source for the local_scan.c() function. It contains definitions that are made
10 available for use in that function, and which are documented.
11
12 This API is also used for functions called by the ${dlfunc expansion item.
13 Coders of dlfunc routines should read the notes on tainting at the start of
14 store.c
15 */
16
17
18 /* Some basic types that make some things easier, the Exim configuration
19 settings, and the store functions. */
20
21 #include <stdarg.h>
22 #include <sys/types.h>
23 #include "config.h"
24 #include "mytypes.h"
25 #include "store.h"
26
27
28 /* The function and its return codes. */
29
30 extern int local_scan(int, uschar **);
31
32 enum {
33 LOCAL_SCAN_ACCEPT, /* Accept */
34 LOCAL_SCAN_ACCEPT_FREEZE, /* Accept, but freeze */
35 LOCAL_SCAN_ACCEPT_QUEUE, /* Accept, but no immediate delivery */
36 LOCAL_SCAN_REJECT, /* Permanent rejection */
37 LOCAL_SCAN_REJECT_NOLOGHDR, /* Permanent rejection, no log header */
38 LOCAL_SCAN_TEMPREJECT, /* Temporary rejection */
39 LOCAL_SCAN_TEMPREJECT_NOLOGHDR /* Temporary rejection, no log header */
40 };
41
42
43 /* Functions called by ${dlfunc{file}{func}{arg}...} return one of the five
44 status codes defined immediately below. The function's first argument is either
45 the result of expansion, or the error message in case of failure. The second
46 and third arguments are standard argument count and vector, comprising the
47 {arg} values specified in the expansion item. */
48
49 typedef int exim_dlfunc_t(uschar **yield, int argc, uschar *argv[]);
50
51
52 /* Return codes from the support functions lss_match_xxx(). These are also the
53 codes that dynamically-loaded ${dlfunc functions must return. */
54
55 #define OK 0 /* Successful match */
56 #define DEFER 1 /* Defer - some problem */
57 #define FAIL 2 /* Matching failed */
58 #define ERROR 3 /* Internal or config error */
59
60 /* Extra return code for ${dlfunc functions */
61
62 #define FAIL_FORCED 4 /* "Forced" failure */
63
64
65 /* Available logging destinations */
66
67 #define LOG_MAIN 1 /* Write to the main log */
68 #define LOG_PANIC 2 /* Write to the panic log */
69 #define LOG_REJECT 16 /* Write to the reject log, with headers */
70
71
72 /* Accessible debugging bits */
73
74 #define D_v 0x00000001
75 #define D_local_scan 0x00000002
76
77
78 /* Option types that can be used for local_scan_options. The boolean ones
79 MUST be last so that they are contiguous with the internal boolean specials. */
80
81 enum { opt_stringptr, opt_int, opt_octint, opt_mkint, opt_Kint, opt_fixed,
82 opt_time, opt_bool };
83
84
85 /* The length of message identification strings. This is the id used internally
86 by exim. The external version for use in Received: strings has a leading 'E'
87 added to ensure it starts with a letter. */
88
89 #define MESSAGE_ID_LENGTH 16
90
91 /* The offset to the start of the data in the data file - this allows for
92 the name of the data file to be present in the first line. */
93
94 #define SPOOL_DATA_START_OFFSET (MESSAGE_ID_LENGTH+3)
95
96 /* Some people (Marc Merlin et al) are maintaining a patch that allows for
97 dynamic local_scan() libraries. This code is not yet in Exim proper, but it
98 helps the maintainers if we keep their ABI version numbers here. This may
99 mutate into more general support later. The major number is increased when the
100 ABI is changed in a non backward compatible way. The minor number is increased
101 each time a new feature is added (in a way that doesn't break backward
102 compatibility). */
103
104 #define LOCAL_SCAN_ABI_VERSION_MAJOR 3
105 #define LOCAL_SCAN_ABI_VERSION_MINOR 1
106 #define LOCAL_SCAN_ABI_VERSION \
107 LOCAL_SCAN_ABI_VERSION_MAJOR.LOCAL_SCAN_ABI_VERSION_MINOR
108
109 /* Structure definitions that are documented as visible in the function. */
110
111 typedef struct header_line {
112 struct header_line *next;
113 int type;
114 int slen;
115 uschar *text;
116 } header_line;
117
118 /* Entries in lists options are in this form. */
119
120 typedef struct {
121 const char *name; /* should have been uschar but too late now */
122 int type;
123 void *value;
124 } optionlist;
125
126 /* Structure for holding information about an envelope address. The errors_to
127 field is always NULL except for one_time aliases that had errors_to on the
128 routers that generated them. */
129
130 typedef struct recipient_item {
131 uschar *address; /* the recipient address */
132 int pno; /* parent number for "one_time" alias, or -1 */
133 uschar *errors_to; /* the errors_to address or NULL */
134 uschar *orcpt; /* DSN orcpt */
135 int dsn_flags; /* DSN flags */
136 #ifdef EXPERIMENTAL_BRIGHTMAIL
137 uschar *bmi_optin;
138 #endif
139 } recipient_item;
140
141
142 /* Global variables that are documented as visible in the function. */
143
144 extern unsigned int debug_selector; /* Debugging bits */
145
146 extern int body_linecount; /* Line count in body */
147 extern int body_zerocount; /* Binary zero count in body */
148 extern uschar *expand_string_message; /* Error info for failing expansion */
149 extern uschar *headers_charset; /* Charset for RFC 2047 decoding */
150 extern header_line *header_last; /* Final header */
151 extern header_line *header_list; /* First header */
152 extern BOOL host_checking; /* Set when checking a host */
153 extern uschar *interface_address; /* Interface for incoming call */
154 extern int interface_port; /* Port number for incoming call */
155 extern uschar *message_id; /* Internal id of message being handled */
156 extern uschar *received_protocol; /* Name of incoming protocol */
157 extern int recipients_count; /* Number of recipients */
158 extern recipient_item *recipients_list;/* List of recipient addresses */
159 extern unsigned char *sender_address; /* Sender address */
160 extern uschar *sender_host_address; /* IP address of sender, as chars */
161 extern uschar *sender_host_authenticated; /* Name of authentication mechanism */
162 extern uschar *sender_host_name; /* Host name from lookup */
163 extern int sender_host_port; /* Port number of sender */
164 extern BOOL smtp_batched_input; /* TRUE if SMTP batch (no interaction) */
165 extern BOOL smtp_input; /* TRUE if input is via SMTP */
166
167
168 /* Functions that are documented as visible in local_scan(). */
169
170 extern int child_close(pid_t, int);
171 extern pid_t child_open(uschar **, uschar **, int, int *, int *, BOOL);
172 extern pid_t child_open_exim(int *);
173 extern pid_t child_open_exim2(int *, uschar *, uschar *);
174 extern void debug_printf(const char *, ...) PRINTF_FUNCTION(1,2);
175 extern uschar *expand_string(uschar *);
176 extern void header_add(int, const char *, ...);
177 extern void header_add_at_position(BOOL, uschar *, BOOL, int, const char *, ...);
178 extern void header_remove(int, const uschar *);
179 extern BOOL header_testname(header_line *, const uschar *, int, BOOL);
180 extern BOOL header_testname_incomplete(header_line *, const uschar *, int, BOOL);
181 extern void log_write(unsigned int, int, const char *format, ...) PRINTF_FUNCTION(3,4);
182 extern int lss_b64decode(uschar *, uschar **);
183 extern uschar *lss_b64encode(uschar *, int);
184 extern int lss_match_domain(uschar *, uschar *);
185 extern int lss_match_local_part(uschar *, uschar *, BOOL);
186 extern int lss_match_address(uschar *, uschar *, BOOL);
187 extern int lss_match_host(uschar *, uschar *, uschar *);
188 extern void receive_add_recipient(uschar *, int);
189 extern BOOL receive_remove_recipient(uschar *);
190 extern uschar *rfc2047_decode(uschar *, BOOL, uschar *, int, int *, uschar **);
191 extern int smtp_fflush(void);
192 extern void smtp_printf(const char *, BOOL, ...) PRINTF_FUNCTION(1,3);
193 extern void smtp_vprintf(const char *, BOOL, va_list);
194
195 #define string_sprintf(fmt, ...) \
196 string_sprintf_trc(fmt, US __FUNCTION__, __LINE__, __VA_ARGS__)
197 extern uschar *string_sprintf_trc(const char *, const uschar *, unsigned, ...) ALMOST_PRINTF(1,4);
198
199 #define store_get(size, tainted) \
200 store_get_3(size, tainted, __FUNCTION__, __LINE__)
201 extern void *store_get_3(int, BOOL, const char *, int) ALLOC ALLOC_SIZE(1) WARN_UNUSED_RESULT;
202 #define store_get_perm(size, tainted) \
203 store_get_perm_3(size, tainted, __FUNCTION__, __LINE__)
204 extern void *store_get_perm_3(int, BOOL, const char *, int) ALLOC ALLOC_SIZE(1) WARN_UNUSED_RESULT;
205
206
207 #if defined(LOCAL_SCAN) || defined(DLFUNC_IMPL)
208 /* When compiling a local_scan() file we want to rename a published API, so that
209 we can use an inlined implementation in the compiles of the main Exim files,
210 with the original name. */
211
212 # define string_copy(s) string_copy_function(s)
213 # define string_copyn(s, n) string_copyn_function((s), (n))
214 # define string_copy_taint(s, t) string_copy_taint_function((s), (t))
215
216 extern uschar * string_copy_function(const uschar *);
217 extern uschar * string_copyn_function(const uschar *, int n);
218 extern uschar * string_copy_taint_function(const uschar *, BOOL tainted);
219 #endif
220
221 /* End of local_scan.h */