Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
docs/ | H | - | - | 5,506 | 4,555 | |
Makefile | H A D | 16-Jul-2020 | 346 | 20 | 14 | |
Makefile.m4 | H A D | 19-Aug-2014 | 1.4 KiB | 41 | 32 | |
README | H A D | 01-Feb-2024 | 8.6 KiB | 229 | 170 | |
comm.c | H A D | 16-Jul-2020 | 6.5 KiB | 358 | 259 | |
engine.c | H A D | 01-Feb-2024 | 42 KiB | 1,924 | 1,314 | |
example.c | H A D | 16-Jul-2020 | 5.6 KiB | 299 | 225 | |
handler.c | H A D | 16-Jul-2020 | 1,014 | 51 | 21 | |
libmilter.h | H A D | 16-Jul-2020 | 9.5 KiB | 336 | 221 | |
listener.c | H A D | 15-Jan-2023 | 20.9 KiB | 992 | 796 | |
main.c | H A D | 16-Jul-2020 | 4.3 KiB | 248 | 120 | |
monitor.c | H A D | 16-Jul-2020 | 4.6 KiB | 228 | 121 | |
signal.c | H A D | 12-Sep-2015 | 3.9 KiB | 226 | 125 | |
sm_gethost.c | H A D | 15-Jan-2023 | 4.3 KiB | 190 | 125 | |
smfi.c | H A D | 16-Jul-2020 | 17.2 KiB | 889 | 547 | |
worker.c | H A D | 16-Jul-2020 | 16.4 KiB | 830 | 515 |
README
1 This directory contains the source files for libmilter. 2 3 The sendmail Mail Filter API (Milter) is designed to allow third-party 4 programs access to mail messages as they are being processed in order to 5 filter meta-information and content. 6 7 This README file describes the steps needed to compile and run a filter, 8 through reference to a sample filter which is attached at the end of this 9 file. It is necessary to first build libmilter.a, which can be done by 10 issuing the './Build' command in SRCDIR/libmilter . 11 12 Starting with 8.13 sendmail is compiled by default with support for 13 the milter API. 14 15 Note: if you want to write a milter in Java, then see 16 http://sendmail-jilter.sourceforge.net/ 17 18 19 +----------------+ 20 | SECURITY HINTS | 21 +----------------+ 22 23 Note: we strongly recommend not to run any milter as root. Libmilter 24 does not need root access to communicate with sendmail. It is a 25 good security practice to run a program only with root privileges 26 if really necessary. A milter should probably check first whether 27 it runs as root and refuse to start in that case. libmilter will 28 not unlink a socket when running as root. 29 30 31 +----------------------+ 32 | CONFIGURATION MACROS | 33 +----------------------+ 34 35 Libmilter uses a set of C preprocessor macros to specify platform specific 36 features of the C compiler and standard C libraries. 37 38 SM_CONF_POLL 39 Set to 1 if poll(2) should be used instead of select(2). 40 41 42 +-------------------+ 43 | BUILDING A FILTER | 44 +-------------------+ 45 46 The following command presumes that the sample code from the end of this 47 README is saved to a file named 'sample.c' and built in the local platform- 48 specific build subdirectory (SRCDIR/obj.*/libmilter). 49 50 cc -I../../include -o sample sample.c libmilter.a ../libsm/libsm.a -pthread 51 52 It is recommended that you build your filters in a location outside of 53 the sendmail source tree. Modify the compiler include references (-I) 54 and the library locations accordingly. Also, some operating systems may 55 require additional libraries. For example, SunOS 5.X requires '-lresolv 56 -lsocket -lnsl'. Depending on your operating system you may need a library 57 instead of the option -pthread, e.g., -lpthread. 58 59 Filters must be thread-safe! Many operating systems now provide support for 60 POSIX threads in the standard C libraries. The compiler flag to link with 61 threading support differs according to the compiler and linker used. Check 62 the Makefile in your appropriate obj.*/libmilter build subdirectory if you 63 are unsure of the local flag used. 64 65 Note that since filters use threads, it may be necessary to alter per 66 process limits in your filter. For example, you might look at using 67 setrlimit() to increase the number of open file descriptors if your filter 68 is going to be busy. 69 70 71 +----------------------------------------+ 72 | SPECIFYING FILTERS IN SENDMAIL CONFIGS | 73 +----------------------------------------+ 74 75 Filters are specified with a key letter ``X'' (for ``eXternal''). 76 77 For example: 78 79 Xfilter1, S=local:/var/run/f1.sock, F=R 80 Xfilter2, S=inet6:999@localhost, F=T, T=C:10m;S:1s;R:1s;E:5m 81 Xfilter3, S=inet:3333@localhost 82 83 specifies three filters. Filters can be specified in your .mc file using 84 the following: 85 86 INPUT_MAIL_FILTER(`filter1', `S=local:/var/run/f1.sock, F=R') 87 INPUT_MAIL_FILTER(`filter2', `S=inet6:999@localhost, F=T, T=C:10m;S:1s;R:1s;E:5m') 88 INPUT_MAIL_FILTER(`filter3', `S=inet:3333@localhost') 89 90 The first attaches to a Unix-domain socket in the /var/run directory; the 91 second uses an IPv6 socket on port 999 of localhost, and the third uses an 92 IPv4 socket on port 3333 of localhost. The current flags (F=) are: 93 94 R Reject connection if filter unavailable 95 T Temporary fail connection if filter unavailable 96 4 Shut down connection if filter unavailable 97 (with a 421 temporary error). 98 99 If none of these is specified, the message is passed through sendmail 100 in case of filter errors as if the failing filters were not present. 101 102 Finally, you can override the default timeouts used by sendmail when 103 talking to the filters using the T= equate. There are four fields inside 104 of the T= equate: 105 106 Letter Meaning 107 C Timeout for connecting to a filter (if 0, use system timeout) 108 S Timeout for sending information from the MTA to a filter 109 R Timeout for reading reply from the filter 110 E Overall timeout between sending end-of-message to filter 111 and waiting for the final acknowledgment 112 113 Note the separator between each is a ';' as a ',' already separates equates 114 and therefore can't separate timeouts. The default values (if not set in 115 the config) are: 116 117 T=C:5m;S:10s;R:10s;E:5m 118 119 where 's' is seconds and 'm' is minutes. 120 121 Which filters are invoked and their sequencing is handled by the 122 InputMailFilters option. Note: if InputMailFilters is not defined no filters 123 will be used. 124 125 O InputMailFilters=filter1, filter2, filter3 126 127 This is is set automatically according to the order of the 128 INPUT_MAIL_FILTER commands in your .mc file. Alternatively, you can 129 reset its value by setting confINPUT_MAIL_FILTERS in your .mc file. 130 This options causes the three filters to be called in the same order 131 they were specified. It allows for possible future filtering on output 132 (although this is not intended for this release). 133 134 Also note that a filter can be defined without adding it to the input 135 filter list by using MAIL_FILTER() instead of INPUT_MAIL_FILTER() in your 136 .mc file. 137 138 To test sendmail with the sample filter, the following might be added (in 139 the appropriate locations) to your .mc file: 140 141 INPUT_MAIL_FILTER(`sample', `S=local:/var/run/f1.sock') 142 143 144 +------------------+ 145 | TESTING A FILTER | 146 +------------------+ 147 148 Once you have compiled a filter, modified your .mc file and restarted 149 the sendmail process, you will want to test that the filter performs as 150 intended. 151 152 The sample filter takes one argument -p, which indicates the local port 153 on which to create a listening socket for the filter. Maintaining 154 consistency with the suggested options for sendmail.cf, this would be the 155 UNIX domain socket located in /var/run/f1.sock. 156 157 % ./sample -p local:/var/run/f1.sock 158 159 If the sample filter returns immediately to a command line, there was either 160 an error with your command or a problem creating the specified socket. 161 Further logging can be captured through the syslogd daemon. Using the 162 'netstat -a' command can ensure that your filter process is listening on 163 the appropriate local socket. 164 165 Email messages must be injected via SMTP to be filtered. There are two 166 simple means of doing this; either using the 'sendmail -bs' command, or 167 by telnetting to port 25 of the machine configured for milter. Once 168 connected via one of these options, the session can be continued through 169 the use of standard SMTP commands. 170 171 % sendmail -bs 172 220 test.sendmail.com ESMTP Sendmail 8.14.0/8.14.0; Thu, 22 Jun 2006 13:05:23 -0500 (EST) 173 HELO localhost 174 250 test.sendmail.com Hello testy@localhost, pleased to meet you 175 MAIL From:<testy> 176 250 2.1.0 <testy>... Sender ok 177 RCPT To:<root> 178 250 2.1.5 <root>... Recipient ok 179 DATA 180 354 Enter mail, end with "." on a line by itself 181 From: testy@test.sendmail.com 182 To: root@test.sendmail.com 183 Subject: testing sample filter 184 185 Sample body 186 . 187 250 2.0.0 dB73Zxi25236 Message accepted for delivery 188 QUIT 189 221 2.0.0 test.sendmail.com closing connection 190 191 In the above example, the lines beginning with numbers are output by the 192 mail server, and those without are your input. If everything is working 193 properly, you will find a file in /tmp by the name of msg.XXXXXXXX (where 194 the Xs represent any combination of letters and numbers). This file should 195 contain the message body and headers from the test email entered above. 196 197 If the sample filter did not log your test email, there are a number of 198 methods to narrow down the source of the problem. Check your system 199 logs written by syslogd and see if there are any pertinent lines. You 200 may need to reconfigure syslogd to capture all relevant data. Additionally, 201 the logging level of sendmail can be raised with the LogLevel option. 202 See the sendmail(8) manual page for more information. 203 204 205 +--------------+ 206 | REQUIREMENTS | 207 +--------------+ 208 209 libmilter requires pthread support in the operating system. Moreover, it 210 requires that the library functions it uses are thread safe; which is true 211 for the operating systems libmilter has been developed and tested on. On 212 some operating systems this requires special compile time options (e.g., 213 not just -pthread). 214 215 So far, libmilter is not supported on: 216 IRIX 6.x 217 Ultrix 218 219 Feedback about problems (and possible fixes) is welcome. 220 221 222 +--------------------------+ 223 | SOURCE FOR SAMPLE FILTER | 224 +--------------------------+ 225 226 Note that the filter example.c may not be thread safe on some operating 227 systems. You should check your system man pages for the functions used 228 to verify they are thread safe. 229