1 diff -urN sendmail-8.12.3/Makefile sendmail-8.12.3.patched/Makefile
2 --- sendmail-8.12.3/Makefile Thu Aug 23 22:44:39 2001
3 +++ sendmail-8.12.3.patched/Makefile Fri Apr 26 17:10:37 2002
7 SUBDIRS= libsm libsmutil libsmdb sendmail editmap mail.local \
8 - mailstats makemap praliases rmail smrsh vacation
9 + mailstats rmail smrsh vacation
10 # libmilter: requires pthread
12 OPTIONS= $(CONFIG) $(FLAGS)
13 diff -urN sendmail-8.12.3/bluelabs.mc sendmail-8.12.3.patched/bluelabs.mc
14 --- sendmail-8.12.3/bluelabs.mc Thu Jan 1 01:00:00 1970
15 +++ sendmail-8.12.3.patched/bluelabs.mc Fri Apr 26 17:10:37 2002
17 +######################################################################
18 +# This is the Blue Labs m4 file.
20 +# A work-in-progress website for building sendmail with this patch is
21 +# at http://blue-labs.org/clue/sendmail.php
23 +# !!! EDIT THE CONFIGURATION SETTINGS TO MATCH YOUR DESIRES !!!
25 +# NOTE: THIS IS A SPECIALISED .cf FOR THE POSTGRESQL PATCH ONLY
27 +VERSIONID(`(#) Blue Labs bluelabs.mc v 9.1 (Blue Labs) 10/13/2001')
28 +######################################################################
31 +# See http://blue-labs.org/clue/sendmail.php for detailed instructions
33 +# TODO: replace 'newaliases' and 'makemap' targets with "don't run this"
34 +# replace man pages also
40 +define(`confBLDVARIANT',`OPTIMIZED') # optimize the binary
41 +# note, there will be two -O flags as it compiles. According to the gcc
42 +# man page, the last one on the line is used in the compile
43 +define(`confCCOPTS',`-O3 -pipe -mcpu=i686 -march=i686')dnl
44 +APPENDDEF(`confENVDEF', `-DSM_CONF_SHM -DDNSMAP -DMILTER -DMAP_REGEX')dnl
46 +#####################################################################################
48 +# BIG BOLD WARNING. link -lcrypt BEFORE -lcrypto or your md5 salted
49 +# passwords will handled as DES passwords and FAIL TO WORK. Thank OpenSSL for
52 +#####################################################################################
55 +# SASL, be sure to link -lcrypt FIRST so it overrides the built-in crypt()
56 +# in openssl, !@#$!@% that is so frustrating
58 +APPENDDEF(`confENVDEF', `-DSASL')dnl
59 +APPENDDEF(`confINCDIRS', `-I/usr/local/include -I/usr/local/include/sasl')dnl
60 +APPENDDEF(`confLIBS', `-lsasl -lcrypt')dnl
61 +APPENDDEF(`confLIBDIRS', `-L/usr/local/lib/sasl')dnl
62 +define(`confDEF_AUTH_INFO', `/etc/mail/auth/auth-info')dnl
63 +define(`confAUTH_MECHANISMS', `DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
64 +TRUST_AUTH_MECH(`DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
69 +APPENDDEF(`confMAPDEF',`-DPGSQLMAP')dnl
70 +APPENDDEF(`confINCDIRS',`-I/usr/local/pgsql/include')dnl
71 +APPENDDEF(`confLIBDIRS',`-L/usr/local/pgsql/lib')dnl
72 +# if you have compiled/installed BIND, you need to add -lresolv
73 +APPENDDEF(`confLIBS',`-lpq -lresolv')dnl
78 +# Compile with -D_FFR_SASL_OPTS and set 'p' in AuthOptions. (p not done)
81 +APPENDDEF(`confENVDEF',`-DSTARTTLS -D_FFR_SASL_OPTS')dnl
82 +APPENDDEF(`confLIBS',`-lssl -lcrypto')dnl
83 +define(`SSL_DIR', `/usr/ssl')dnl
84 +define(`confCACERT_PATH', `SSL_DIR/certs')dnl
85 +define(`confCACERT', `SSL_DIR/certs/cacert.pem')dnl
86 +define(`confSERVER_CERT', `SSL_DIR/certs/mailcert.pem')dnl
87 +define(`confSERVER_KEY', `SSL_DIR/private/mailkey.pem')dnl
88 +define(`confCLIENT_CERT', `SSL_DIR/certs/mailcert.pem')dnl
89 +define(`confCLIENT_KEY', `SSL_DIR/private/mailkey.pem')dnl
90 +define(`confAUTH_OPTIONS',`p')
97 +# pgsql [-h <pgsql server>] -c <connection string> -s <query string>
100 +APPENDDEF(`DATABASE_MAP_TYPE', `pgsql')dnl
101 +define(`PG_WHERE', where s_in='%s')
102 +define(`PG_CONNSTR', "dbname=sendmail user=sendmail")
103 +define(`PG_SOUT', "select distinct s_out from)
104 +FEATURE(`pg_aliases', pgsql -c `PG_CONNSTR' -s `PG_SOUT' aliases `PG_WHERE'")dnl
105 +FEATURE(`pg_virtualusers', pgsql -c `PG_CONNSTR' -s `PG_SOUT' virtualusers `PG_WHERE'")dnl
106 +FEATURE(`pg_usersdb', pgsql -c `PG_CONNSTR' -s `PG_SOUT' userrewrite `PG_WHERE'")dnl
107 +FEATURE(`pg_accessdb', pgsql -c `PG_CONNSTR' -s `PG_SOUT' access `PG_WHERE'")dnl
108 +FEATURE(`pg_domaintable', pgsql -c `PG_CONNSTR' -s `PG_SOUT' domaintable `PG_WHERE'")dnl
109 +FEATURE(`pg_generics', pgsql -c `PG_CONNSTR' -s `PG_SOUT' genericstable `PG_WHERE'")dnl
110 +FEATURE(`pg_mailer', pgsql -c `PG_CONNSTR' -s `PG_SOUT' mailertable `PG_WHERE'")dnl
112 +define(`confPROCESS_TITLE_PREFIX', `[Blue-PgSQL]')dnl
113 +define(`confMAX_MESSAGE_SIZE', `52428800')dnl # 50 Megs
114 +define(`confFORWARD_PATH', `$z/.forward:/etc/mail/forward-files/$u')dnl
115 +define(`confHOST_STATUS_DIRECTORY', `/etc/mail/host-status/')dnl
116 +define(`confDEF_USER_ID', `mail')dnl
117 +define(`confMAX_DAEMON_CHILDREN', `40')dnl
118 +define(`confCONNECTION_RATE_THROTTLE', `20')dnl
119 +define(`confSINGLE_LINE_FROM_HEADER', `True')dnl
120 +define(`confSMTP_LOGIN_MSG', `$j Sendmail $v/$Z; $b\
122 + Spam is prohibited here and any detected spam may be used in prosecution\
123 + against the spammer. This sendmail setup uses PgSQL (postgres) for most of\
124 + it''`s tables, for information on this, see\
125 + http://blue-labs.org/clue/sendmail.php\
128 +define(`confDONT_PROBE_INTERFACES', `True')dnl
129 +define(`confREJECT_MSG', `550 Your mail is rejected.\
130 + Contact <admin@$m> to have this matter resolved.\
132 +define(`confTO_INITIAL', `1m')dnl
133 +define(`confTO_CONNECT', `15s')dnl
134 +define(`confTO_HELO', `4m')dnl
135 +define(`confTO_HOSTSTATUS', `1m')dnl
136 +define(`confTO_DATAINIT', `2m')dnl
137 +define(`confTO_DATABLOCK', `5m')dnl
138 +define(`confTO_DATAFINAL', `5m')dnl
139 +define(`confCONNECTION_RATE_THROTTLE', `40')dnl
140 +define(`confDIAL_DELAY', `15s')dnl
141 +define(`confNO_RCPT_ACTION', `add-apparently-to')dnl
142 +define(`confALIAS_WAIT', `0')dnl
143 +define(`confMAX_HOP', `35')dnl
144 +define(`confQUEUE_LA', `5')dnl
145 +define(`confREFUSE_LA', `12')dnl
146 +define(`confSEPARATE_PROC', `False')dnl
148 +define(`confCON_EXPENSIVE', `true')dnl
149 +define(`confWORK_RECIPIENT_FACTOR', `1000')dnl
150 +define(`confWORK_TIME_FACTOR', `3000')dnl
151 +define(`confQUEUE_SORT_ORDER', `Time')dnl
153 +define(`confDEAD_LETTER_DROP', `/var/tmp/dead.letter')dnl
154 +define(`confRRT_IMPLIES_DSN', `True')dnl
155 +define(`confCONTROL_SOCKET_NAME', `/var/spool/mqueue/.control')dnl
156 +define(`confMAX_HEADERS_LENGTH', `16384')dnl
157 +define(`confMAX_ALIAS_RECURSION', `10')dnl
158 +define(`confMAX_RCPTS_PER_MESSAGE', `50')dnl
159 +define(`confSHAREDMEMORYKEY', `42')dnl
160 +define(`confMCI_CACHE_SIZE', `4')dnl
161 +define(`PROCMAIL_MAILER_PATH', `/usr/bin/procmail')dnl
162 +define(`STATUS_FILE', `/etc/mail/sendmail-status')dnl
167 +FEATURE(`queuegroup')dnl
168 +define(`QUEUE_DIR', `/var/spool/mqueue')dnl
169 +define(`LOCAL_PROG_QGRP', `local')dnl
170 +define(`LOCAL_MAILER_QGRP', `local')dnl
171 +define(`ESMTP_MAILER_QGRP', `smtp')dnl
172 +define(`SMTP8_MAILER_QGRP', `smtp')dnl
173 +define(`DSMTP_MAILER_QGRP', `smtp')dnl
174 +define(`RELAY_MAILER_QGRP', `smtp')dnl
175 +dnl QUEUE_GROUP(`mqueue', `P=/var/spool/mqueue, r=5, F=f, R=2')dnl
177 +dnl Nice is the nice(2) increment for queue groups
178 +dnl Interval is the tiem between two queue runs
180 +dnl Runners is the number of parallel queue runners
181 +dnl Jobs is the max number of messages delivered per queue run
182 +dnl recipients is the max number of recipients per envelope
184 +QUEUE_GROUP(`local', `P=/var/spool/mqueue/local, N=0, I=30s, R=5, J=500, r=100, F=f')dnl
185 +QUEUE_GROUP(`smtp', `P=/var/spool/mqueue/smtp, N=5, I=30s, R=10, J=500, r=100, F=f')dnl
186 +QUEUE_GROUP(`relay', `P=/var/spool/mqueue/relay, N=10, I=1m, R=2, r=100, F=f')dnl
187 +QUEUE_GROUP(`lmtp', `P=/var/spool/mqueue/lmtp, N=0, I=30s, R=2, r=100, F=f')dnl
188 +QUEUE_GROUP(`expensive', `P=/var/spool/mqueue/expensive, F=e, N=19 I=5m R=1 r=200')dnl
190 +# HoldExpensive [c] If an outgoing mailer is marked as being expensive, don't connect
191 +# immediately. This requires that queueing be compiled in, since it will depend on a queue
192 +# run process to actually send the mail.
195 +# distinguish case on names, Blu3 is different from blu3
197 +MODIFY_MAILER_FLAGS(`LOCAL', `+u')dnl
199 +FEATURE(`always_add_domain')dnl
200 +FEATURE(`blacklist_recipients')dnl
201 +dnl FEATURE(`dnsbl',`rbl.maps.vix.com',` Mail from $&{client_addr} rejected; see http://mail-abuse.org/rbl/')dnl
202 +dnl FEATURE(`dnsbl',`dul.maps.vix.com')dnl
204 +FEATURE(`dnsbl',`blackholes.mail-abuse.org', `Mail from $&{client_addr} rejected; see http://mail-abuse.org/rbl/')dnl
205 +FEATURE(`dnsbl',`dialups.mail-abuse.org', `Mail from $&{client_addr} rejected; see http://mail-abuse.org/rbl/')dnl
206 +FEATURE(`dnsbl',`relays.mail-abuse.org', `Mail from $&{client_addr} rejected; see http://mail-abuse.org/rbl/')dnl
208 +FEATURE(`rhsbl',`dsn.rfc-ignorant.org', `550 You do not accept bounces violating RFC 821/2505/2821 - see http://www.rfc-ignorant.org/', `h')dnl
209 +FEATURE(`rhsbl',`postmaster.rfc-ignorant.org', `550 Mail rejected as your domain does not have a working postmaster address - see http://www.rfc-ignorant.org/', `h')dnl
210 +FEATURE(`rhsbl',`abuse.rfc-ignorant.org', `550 Mail rejected as your domain does not have a working abuse address - see http://www.rfc-ignorant.org/', `h')dnl
211 +FEATURE(`rhsbl',`whois.rfc-ignorant.org', `550 Mail rejected as your whois information does not exist or is obviously fictitous - see http://www.rfc-ignorant.org/', `h')dnl
213 +FEATURE(`delay_checks')dnl
214 +FEATURE(`generics_entire_domain')dnl
215 +FEATURE(`local_procmail')dnl
216 +FEATURE(`masquerade_envelope')dnl
217 +FEATURE(`nouucp',`reject')dnl
218 +FEATURE(`redirect')dnl
219 +FEATURE(`relay_based_on_MX')dnl
220 +FEATURE(`relay_entire_domain')dnl
221 +FEATURE(`use_ct_file')dnl
222 +FEATURE(`use_cw_file')dnl
223 +FEATURE(`virtuser_entire_domain')dnl
224 +FEATURE(`delay_checks',`friend')dnl
225 +FEATURE(`lookupdotdomain')
227 +MASQUERADE_DOMAIN_FILE(`/etc/mail/masquerade-these-as-me')dnl
240 +R$* <hahaha@sexyfun.net> $* $#error $: "553 Delivery blocked: Snow White virus"
245 +Kchkcontent regex -a@REJ Outlook_Express_message_boundary
246 +HContent-Type: $>CheckContent
248 +R$* $: $(chkcontent $&({currHeader} $)
249 +R@REJ $error $: "553 Delivery blocked --- SirCam virus detected"
253 +# subject encodings, non-ascii characters, and trailing numbers in subject
254 +# with lots of spaces are spam
255 +Kchksubject regex -a@REJ ^=\?|[
\80-ÿ]{3,}| {9,}[0-9]{3,}| {9,}\[[A-Za-z0-9]{3,}\]
256 +HSubject: $>CheckSubject
258 +R$* $: $(chksubject $&{currHeader} $)
259 +R@REJ $#error $: "553 Delivery blocked --- `Subject:' suggests spam"
260 diff -urN sendmail-8.12.3/cf/feature/pg_accessdb.m4 sendmail-8.12.3.patched/cf/feature/pg_accessdb.m4
261 --- sendmail-8.12.3/cf/feature/pg_accessdb.m4 Thu Jan 1 01:00:00 1970
262 +++ sendmail-8.12.3.patched/cf/feature/pg_accessdb.m4 Fri Apr 26 17:10:37 2002
265 +# By using this file, you agree to be cool and share your knowledge
267 +# David, http://blue-labs.org/clue/sendmail.php
274 +define(`_ACCESS_TABLE_', `')
275 +define(`_PG_ACCESS_TABLE_', `')
276 +define(`_TAG_DELIM_', `:')dnl should be in OperatorChars
279 +# PostgreSQL based access list
280 +Kaccess ifelse(defn(`_ARG_'), `',
281 + DATABASE_MAP_TYPE MAIL_SETTINGS_DIR`access',
283 diff -urN sendmail-8.12.3/cf/feature/pg_aliases.m4 sendmail-8.12.3.patched/cf/feature/pg_aliases.m4
284 --- sendmail-8.12.3/cf/feature/pg_aliases.m4 Thu Jan 1 01:00:00 1970
285 +++ sendmail-8.12.3.patched/cf/feature/pg_aliases.m4 Fri Apr 26 17:10:37 2002
288 +# By using this file, you agree to be cool and share your knowledge
290 +# David, http://blue-labs.org/clue/sendmail.php
297 +undefine(`ALIAS_FILE')
298 +define(`_ALIASES_TABLE_', `')
299 +define(`_PG_ALIASES_TABLE_', `')
302 +# PostgreSQL based local aliases
303 +Kaliases ifelse(defn(`_ARG_'), `',
304 + DATABASE_MAP_TYPE MAIL_SETTINGS_DIR`aliases',
306 diff -urN sendmail-8.12.3/cf/feature/pg_domaintable.m4 sendmail-8.12.3.patched/cf/feature/pg_domaintable.m4
307 --- sendmail-8.12.3/cf/feature/pg_domaintable.m4 Thu Jan 1 01:00:00 1970
308 +++ sendmail-8.12.3.patched/cf/feature/pg_domaintable.m4 Fri Apr 26 17:10:37 2002
311 +# By using this file, you agree to be cool and share your knowledge
313 +# David, http://blue-labs.org/clue/sendmail.php
320 +define(`_DOMAIN_TABLE_', `')
321 +define(`_PG_DOMAIN_TABLE', `')
324 +# PostgreSQL based domain rewriting table
325 +Kdomaintable ifelse(defn(`_ARG_'), `',
326 + DATABASE_MAP_TYPE MAIL_SETTINGS_DIR`domaintable',
328 diff -urN sendmail-8.12.3/cf/feature/pg_generics.m4 sendmail-8.12.3.patched/cf/feature/pg_generics.m4
329 --- sendmail-8.12.3/cf/feature/pg_generics.m4 Thu Jan 1 01:00:00 1970
330 +++ sendmail-8.12.3.patched/cf/feature/pg_generics.m4 Fri Apr 26 17:10:37 2002
333 +# By using this file, you agree to be cool and share your knowledge
335 +# David, http://blue-labs.org/clue/sendmail.php
342 +define(`_GENERICS_TABLE_', `')
343 +define(`_PG_GENERICS_TABLE', `')
346 +# PostgreSQL based generic domain mapping table, similar to userdb
347 +Kgenerics ifelse(defn(`_ARG_'), `',
348 + DATABASE_MAP_TYPE MAIL_SETTINGS_DIR`generics',
350 diff -urN sendmail-8.12.3/cf/feature/pg_mailer.m4 sendmail-8.12.3.patched/cf/feature/pg_mailer.m4
351 --- sendmail-8.12.3/cf/feature/pg_mailer.m4 Thu Jan 1 01:00:00 1970
352 +++ sendmail-8.12.3.patched/cf/feature/pg_mailer.m4 Fri Apr 26 17:10:37 2002
355 +# By using this file, you agree to be cool and share your knowledge
357 +# David, http://blue-labs.org/clue/sendmail.php
364 +define(`_MAILER_TABLE_', `')
365 +define(`_PG_MAILER_TABLE', `')
368 +# PostgreSQL based mailer table, for overriding domain and MX
369 +Kmailertable ifelse(defn(`_ARG_'), `',
370 + DATABASE_MAP_TYPE MAIL_SETTINGS_DIR`mailertable',
372 diff -urN sendmail-8.12.3/cf/feature/pg_usersdb.m4 sendmail-8.12.3.patched/cf/feature/pg_usersdb.m4
373 --- sendmail-8.12.3/cf/feature/pg_usersdb.m4 Thu Jan 1 01:00:00 1970
374 +++ sendmail-8.12.3.patched/cf/feature/pg_usersdb.m4 Fri Apr 26 17:10:37 2002
377 +# By using this file, you agree to be cool and share your knowledge
379 +# David, http://blue-labs.org/clue/sendmail.php
386 +define(`_REWRITE_TABLE_', `')
387 +define(`_PG_REWRITE_TABLE_', `')
390 +# PostgreSQL based user rewrite table (can turn "John.Doe" into "jdoe")
391 +Kusersdb ifelse(defn(`_ARG_'), `',
392 + DATABASE_MAP_TYPE MAIL_SETTINGS_DIR`usersdb',
394 diff -urN sendmail-8.12.3/cf/feature/pg_virtualusers.m4 sendmail-8.12.3.patched/cf/feature/pg_virtualusers.m4
395 --- sendmail-8.12.3/cf/feature/pg_virtualusers.m4 Thu Jan 1 01:00:00 1970
396 +++ sendmail-8.12.3.patched/cf/feature/pg_virtualusers.m4 Fri Apr 26 17:10:37 2002
399 +# By using this file, you agree to be cool and share your knowledge
401 +# David, http://blue-labs.org/clue/sendmail.php
408 +define(`_VIRTUSER_TABLE_', `')
409 +define(`_PG_VIRTUSER_TABLE_', `')
412 +# PostgreSQL based virtual user table (maps incoming users)
413 +Kvirtuser ifelse(defn(`_ARG_'), `',
414 + DATABASE_MAP_TYPE MAIL_SETTINGS_DIR`virtusertable',
416 diff -urN sendmail-8.12.3/cf/feature/rhsbl.m4 sendmail-8.12.3.patched/cf/feature/rhsbl.m4
417 --- sendmail-8.12.3/cf/feature/rhsbl.m4 Thu Jan 1 01:00:00 1970
418 +++ sendmail-8.12.3.patched/cf/feature/rhsbl.m4 Fri Apr 26 17:10:37 2002
422 +# Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
423 +# All rights reserved.
425 +# By using this file, you agree to the terms and conditions set
426 +# forth in the LICENSE file which can be found at the top level of
427 +# the sendmail distribution.
432 +ifdef(`_DNSBL_R_',`dnl',`dnl
434 +define(`_DNSBL_R_',`')
436 +# map for DNS based blacklist lookups
437 +Kdnsbl host -T<TMP>')
439 +define(`_DNSBL_SRV_', `ifelse(len(X`'_ARG_),`1',`blackholes.mail-abuse.org',_ARG_)')dnl
441 +define(`_DNSBL_LOOKUP_', `ifelse(_ARG4_,`h',`client_name',`client_addr')')dnl
443 +define(`_DNSBL_MSG_TMP_', `ifelse(_ARG3_,`t',`"451 Temporary lookup failure of "$`'&{_DNSBL_LOOKUP_} " at '_DNSBL_SRV_`"',`_ARG2_')')dnl
444 +define(`_DNSBL_MSG_', `ifelse(len(X`'_ARG2_),`1',`"550 Mail from " $`'&{_DNSBL_LOOKUP_} " refused by blackhole site '_DNSBL_SRV_`"',`_ARG2_')')dnl
448 +dnl the "dnsbl" listed below should be replaced with "host" on 8.11 systems
452 +`R$* $: $&{client_name}
453 +R[ $* ] $: $1 Get rid of square brackets
454 +R$* $: <?> $(dnsbl $1.'_DNSBL_SRV_`. $: OK $)',
455 +`R$* $: $&{client_addr}
456 +R$-.$-.$-.$- $: <?> $(dnsbl $4.$3.$2.$1.'_DNSBL_SRV_`. $: OK $)')
458 +ifelse(len(X`'_ARG3_),`1',
459 +`R<?>$+<TMP> $: TMPOK',
460 +`R<?>$+<TMP> $#error $@ 4.7.1 $: _DNSBL_MSG_TMP_')
461 +R<?>$+ $#error $@ 5.7.1 $: _DNSBL_MSG_
463 diff -urN sendmail-8.12.3/include/libsmdb/smdb.h sendmail-8.12.3.patched/include/libsmdb/smdb.h
464 --- sendmail-8.12.3/include/libsmdb/smdb.h Mon Nov 19 20:30:03 2001
465 +++ sendmail-8.12.3.patched/include/libsmdb/smdb.h Fri Apr 26 17:10:37 2002
468 # include <sm/errstring.h>
473 + ERROR NDBM or NEWDB must be defined.
474 +# endif /* ! NEWDB */
475 +# endif /* ! NDBM */
476 +# endif /* ! PGSQLMAP */
481 diff -urN sendmail-8.12.3/sendmail/Makefile.m4 sendmail-8.12.3.patched/sendmail/Makefile.m4
482 --- sendmail-8.12.3/sendmail/Makefile.m4 Sat Dec 1 00:32:02 2001
483 +++ sendmail-8.12.3.patched/sendmail/Makefile.m4 Fri Apr 26 17:10:37 2002
485 define(`bldTARGET_INST_DEP', ifdef(`confINST_DEP', `confINST_DEP',
486 `${DESTDIR}/etc/mail/submit.cf ${DESTDIR}${MSPQ}'))dnl
487 define(`bldTARGET_LINKS', ifdef(`confLINKS', `confLINKS',
488 -`${DESTDIR}${UBINDIR}/newaliases ${DESTDIR}${UBINDIR}/mailq ${DESTDIR}${UBINDIR}/hoststat ${DESTDIR}${UBINDIR}/purgestat')
489 +`${DESTDIR}${UBINDIR}/mailq ${DESTDIR}${UBINDIR}/hoststat ${DESTDIR}${UBINDIR}/purgestat')
492 # location of sendmail statistics file (usually /etc/mail/ or /var/log)
493 diff -urN sendmail-8.12.3/sendmail/README sendmail-8.12.3.patched/sendmail/README
494 --- sendmail-8.12.3/sendmail/README Thu Apr 4 23:39:33 2002
495 +++ sendmail-8.12.3.patched/sendmail/README Fri Apr 26 17:10:37 2002
497 have to install the UMich or OpenLDAP
498 (http://www.openldap.org/) ldap and lber libraries to use
500 +PGSQLMAP PostgreSQL SQL query support. You will need to have
501 + PostgreSQL include files and libraries installed to use this
502 + feature. Information on PostgreSQL can be found at
503 + http://www.postgresql.org
504 MAP_REGEX Regular Expression support. You will need to use an
505 operating system which comes with the POSIX regex()
506 routines or install a regexp library such as libregex from
507 diff -urN sendmail-8.12.3/sendmail/conf.c sendmail-8.12.3.patched/sendmail/conf.c
508 --- sendmail-8.12.3/sendmail/conf.c Thu Apr 4 23:32:14 2002
509 +++ sendmail-8.12.3.patched/sendmail/conf.c Fri Apr 26 17:10:37 2002
511 ldapmap_lookup, null_map_store);
515 + MAPDEF("pgsql", NULL, MCF_ALIASOK|MCF_NOTPERSIST,
516 + pgsql_map_parseargs, pgsql_map_open, pgsql_map_close,
517 + pgsql_map_lookup, null_map_store);
521 MAPDEF("ph", NULL, MCF_NOTPERSIST,
522 ph_map_parseargs, ph_map_open, ph_map_close,
523 @@ -5484,6 +5490,9 @@
533 diff -urN sendmail-8.12.3/sendmail/map.c sendmail-8.12.3.patched/sendmail/map.c
534 --- sendmail-8.12.3/sendmail/map.c Tue Mar 26 23:56:36 2002
535 +++ sendmail-8.12.3.patched/sendmail/map.c Fri Apr 26 17:10:37 2002
536 @@ -4839,6 +4839,482 @@
542 +#include <libpq-fe.h>
545 + struct pgsqlmap *p,*n;
553 + * search our structure for matching entries/add entry to struct
556 +PGconn *getconn(char *host, char *connstr)
564 + pgsqlmap=pgsqlmap->p;
567 + sm_syslog(LOG_MAIL, NOQID, " HostSearch (host:%s, cstr:%s, pid:%i)",
571 + // only return connections that match everything
573 + if(pgsqlmap->conn) {
574 + if (!strncmp(connstr, pgsqlmap->connstr, strlen(connstr)+1)) {
575 + if ((!host && !pgsqlmap->host) || !strncmp(host, pgsqlmap->host, strlen(host)+1)) {
576 + if (pgsqlmap->pid == p) {
577 + return pgsqlmap->conn;
584 + pgsqlmap=pgsqlmap->n;
592 +void addconn(char *host, char *connstr, PGconn *conn)
595 + // advance, then alloc
597 + pgsqlmap=pgsqlmap->n;
598 + pgsqlmap->n= (struct pgsqlmap *) xalloc(sizeof(struct pgsqlmap));
599 + bzero(pgsqlmap->n, sizeof(struct pgsqlmap));
600 + pgsqlmap->n->p=pgsqlmap;
601 + pgsqlmap=pgsqlmap->n;
604 + pgsqlmap= (struct pgsqlmap *) xalloc(sizeof(struct pgsqlmap));
605 + bzero(pgsqlmap, sizeof(struct pgsqlmap));
608 + pgsqlmap->host=host;
609 + pgsqlmap->connstr=connstr;
610 + pgsqlmap->conn=conn;
611 + pgsqlmap->pid=getpid();
614 + sm_syslog(LOG_MAIL, NOQID, " HostAdd (host:%s, cstr:%s, conn:%p, pid:%i)",
615 + host, connstr, conn, pgsqlmap->pid);
619 +int removeconn(PGconn *conn)
625 + pgsqlmap=pgsqlmap->p;
628 + if (pgsqlmap->conn==conn) {
630 + * no pressing desire to remove it from the structure, sendmail will
631 + * exit soon enough. just free the data and null the conn value
633 + if(pgsqlmap->host) {
634 + pgsqlmap->host=NULL;
636 + if(pgsqlmap->connstr) {
637 + pgsqlmap->connstr=NULL;
639 + pgsqlmap->conn=NULL;
645 + pgsqlmap=pgsqlmap->n;
654 + * PostgreSQL map functionality for Sendmail 8.12.0
655 + * Portions Copyright (C) 2000 Jonathan Yarden <jyarden@bluegrass.net>
656 + * Remainder copyright (c) 2000,2001 David Ford <david@blue-labs.org>
658 + * For information on PostgreSQL, visit http://www.pgsql.com/
659 + * Information on this patch and setup is at http://blue-labs.org/ under
662 + * This patch, because it integrates with and is based on the existing
663 + * prior work of Sendmail, is considered by me to be a "derivative
664 + * work" subject to the Sendmail licensing terms. Sendmail, Inc. in not
665 + * responsable for this code.
667 + * USE AT YOUR OWN RISK. NO WARRANTY OF ANY KIND IS PROVIDED. PLEASE
668 + * READ THE INSTRUCTIONS FOR USE OF THIS PATCH BEFORE CONTACTING THE
669 + * AUTHOR OR SENDMAIL, INC. NO SUPPORT OF ANY KIND WILL BE PROVIDED
670 + * BY SENDMAIL, INC. FOR THIS PATCH.
673 +char *skip_quotes(char *p)
684 + * Parse PostgreSQL map definition args.
686 + * Nothing really special here, since to be perfectly honest, I have never
687 + * seen or used almost all of these options. Most of this code was taken
688 + * directly from existing Sendmail source code.
691 +pgsql_map_parseargs(map,args)
695 + register char *p = args;
698 + map->map_mflags |= MF_TRY0NULL | MF_TRY1NULL;
700 + while (isascii(*p) && isspace(*p))
706 + map->map_mflags |= MF_INCLNULL;
707 + map->map_mflags &= ~MF_TRY0NULL;
711 + map->map_mflags &= ~MF_TRY1NULL;
715 + map->map_mflags |= MF_OPTIONAL;
719 + map->map_mflags |= MF_NOFOLDCASE;
723 + map->map_mflags |= MF_MATCHONLY;
727 + map->map_mflags |= MF_APPEND;
731 + map->map_mflags |= MF_KEEPQUOTES;
735 + map->map_mflags |= MF_NODEFER;
739 + map->map_app = ++p;
743 + map->map_tapp = ++p;
747 + * Start of PostgreSQL specific args. I cheat and use some existing
748 + * Sendmail variables here since this map class makes no other use of them.
751 + case 'c': /* connection string */
752 + map->map_keycolnm = ++p;
753 + p = skip_quotes(p);
756 + case 'h': /* host string */
757 + map->map_db2 = ++p;
758 + p = skip_quotes(p);
761 + case 's': /* select statement */
762 + map->map_valcolnm = ++p;
763 + p = skip_quotes(p);
771 + if (map->map_app != NULL)
772 + map->map_app = newstr(map->map_app);
774 + if (map->map_tapp != NULL)
775 + map->map_tapp = newstr(map->map_tapp);
777 + if(map->map_db2 != NULL) {
778 + map->map_db2 = newstr(map->map_db2);
779 + stripquotes(map->map_db2);
786 + if (map->map_keycolnm != NULL) { /* database connect string */
787 + map->map_keycolnm = newstr(map->map_keycolnm);
788 + stripquotes(map->map_keycolnm);
789 + p=map->map_keycolnm;
792 + map->map_keycolnm=p;
794 + syserr("No PostgreSQL connect string for %s map %s",
795 + map->map_class->map_cname, map->map_mname);
799 + if (map->map_valcolnm != NULL) { /* select statement */
800 + map->map_valcolnm = newstr(map->map_valcolnm);
801 + stripquotes(map->map_valcolnm);
802 + p=map->map_valcolnm;
805 + map->map_valcolnm=p;
807 + syserr("No PostgreSQL select statement for %s map %s",
808 + map->map_class->map_cname, map->map_mname);
813 + sm_syslog(LOG_MAIL, NOQID, "psqlinfo(%s, %s, %s)",
814 + map->map_db2, map->map_keycolnm, map->map_valcolnm);
820 + * Open a PostgreSQL database connection using the connection string.
822 + * Returns TRUE if the database was opened or FALSE if it choked.
824 + * - Changed to check return status better on open and save
825 + * PID to fix Broken pipes from child processes closing the
826 + * connection on us.
829 +pgsql_map_open(map, mode)
837 + conn=(PGconn *) map->map_db1;
840 + * check our list for an already established connection that
841 + * matches both the host and connection string
842 + * keycolnm is the connection string
843 + * file is the hostname
845 + conn=getconn(map->map_db2, map->map_keycolnm);
848 + * we already have a connection to the server
850 + if (PQstatus(conn) == CONNECTION_OK) {
852 + sm_syslog(LOG_MAIL, NOQID, "AlreadyExists (host:%s, cstr:%s, conn:%p)",
853 + map->map_db2, map->map_keycolnm, conn);
855 + map->map_db1 = (ARBPTR_T) conn;
860 + n+=strlen(map->map_db2);
861 + if(map->map_keycolnm)
862 + n+=strlen(map->map_keycolnm);
865 + sprintf(s, "%s %s",
866 + map->map_db2? map->map_db2:"",
867 + map->map_keycolnm? map->map_keycolnm:"");
869 + conn=PQconnectdb(s);
870 + if (!conn || PQstatus(conn) == CONNECTION_BAD) {
873 + syserr("Cannot open %s map \'%s\' using \"%s\" (%s)",
874 + map->map_class->map_cname,
877 + PQerrorMessage(conn));
883 + addconn(map->map_db2, map->map_keycolnm, conn);
884 + map->map_db1 = (ARBPTR_T) conn;
885 + map->map_pid = getpid(); /* save PID for check on close */
890 + * Close the PostgreSQL database connection, check that the opening process
891 + * is the closing process; ignore if not.
894 +pgsql_map_close(map)
900 + if (map->map_pid == getpid()) {
901 + conn= (PGconn *) map->map_db1;
902 + r=removeconn(conn);
906 + sm_syslog(LOG_MAIL, NOQID, "Closed map %s", map->map_mname);
912 +** PGSQL_MAP_LOOKUP -- look up a datum in a PGSQL map
914 +** Attempt to map an incoming key value with a PostgreSQL query.
916 +** This performs the query specified in the Sendmail config file and
917 +** uses the value of the first row and column as the map data value.
918 +** All other rows and columns are ignored.
922 +** - Modified to check the status of the PostgreSQL connection and reset it
923 +** if it looks like it has dropped. This was done to flush out an error,
924 +** but it's a good idea to do this anyway just in case.
928 +pgsql_map_lookup(map, name, av, statp)
936 + char sname[MAXNAME+1];
937 + char resbuf[MAXNAME+1];
938 + PGconn *conn = (PGconn *) map->map_db1;
941 + bzero(sname,sizeof sname);
942 + bzero(resbuf,sizeof resbuf);
944 + /* Buffer overflow check. */
945 + len = strlen(name);
948 + bcopy(name,sname,len);
950 + if (!bitset(MF_NOFOLDCASE, map->map_mflags))
953 + /* Allocate query buffer (select statement + key value) */
954 + len = strlen(map->map_valcolnm) + strlen(sname);
955 + sbuf = xalloc(len);
959 + * Check the backend to make sure it's still valid. If it's not, try and
960 + * reset the connection. This is a good idea anyway, just in case
961 + * the backend died. BTW this is how I discovered the "child close" bug.
964 + if (r == CONNECTION_BAD) {
966 + sm_syslog(LOG_MAIL, NOQID, "CNX Bad, resetting (%i)", r);
968 + PQreset(conn); /* does this block? I hope so */
969 + if (PQstatus(conn) == CONNECTION_BAD) {
971 + syserr("Unable to reestablish closed PGSQL connection %s",map->map_keycolnm);
976 + /* Create SQL query statement and execute it */
977 + sprintf(sbuf,map->map_valcolnm,sname);
979 + /*syserr("starting map lookup, pid: %i", map->map_pid);*/
980 + res = PQexec(conn,sbuf);
981 + if (PQresultStatus(res) != PGRES_TUPLES_OK) {
983 + syserr("Cannot query PGSQL database %s using %s",map->map_keycolnm,sbuf);
988 + * See if anything came back. If no rows were returned, nothing there for
991 + ntuples = PQntuples(res);
992 + if (ntuples <= 0) {
998 + * Get the result from column 0 and clear the rest of the result.
999 + * If the result data is too big, then it's truncated.
1001 + len = PQgetlength(res,0,0);
1002 + if (len > MAXNAME) len=MAXNAME;
1003 + bcopy(PQgetvalue(res,0,0),resbuf,len);
1007 + * Process results like the other map classes do.
1009 + /*syserr("finishing map lookup, pid: %i", map->map_pid);*/
1010 + if (bitset(MF_MATCHONLY, map->map_mflags))
1011 + return map_rewrite(map, name, strlen(name), NULL);
1013 + return map_rewrite(map, resbuf, len, av);
1015 +#endif /* PGSQLMAP */