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