diff -ur ../../postfix/postfix-1.1.11/src/smtp/Makefile.in src/smtp/Makefile.in
--- ../../postfix/postfix-1.1.11/src/smtp/Makefile.in	Thu Jul 11 15:09:52 2002
+++ src/smtp/Makefile.in	Thu Jul 11 18:02:22 2002
@@ -10,12 +10,12 @@
 WARN	= -W -Wformat -Wimplicit -Wmissing-prototypes \
 	-Wparentheses -Wstrict-prototypes -Wswitch -Wuninitialized \
 	-Wunused
-DEFS	= -I. -I$(INC_DIR) -D$(SYSTYPE)
+DEFS	= -I. -I$(INC_DIR) -I/usr/include/postfix -D$(SYSTYPE)
 CFLAGS	= $(DEBUG) $(OPT) $(DEFS)
 TESTPROG= smtp_unalias
 PROG	= smtp
-INC_DIR	= ../../include
-LIBS	= ../../lib/libmaster.a ../../lib/libglobal.a ../../lib/libdns.a ../../lib/libutil.a
+INC_DIR	= /usr/include/postfix
+LIBS	= -lpostfix-master -lpostfix-global -lpostfix-dns -lpostfix-util ../../lib/libtlsglobal.a
 
 .c.o:;	$(CC) $(CFLAGS) -c $*.c
 
@@ -38,7 +38,7 @@
 	cp *.h printfck
 	sed '1,/^# do not edit/!d' Makefile >printfck/Makefile
 	set -e; for i in *.c; do printfck -f .printfck $$i >printfck/$$i; done
-	cd printfck; make "INC_DIR=../../../include" `cd ..; ls *.o`
+	cd printfck; make "INC_DIR=/usr/include/postfix" `cd ..; ls *.o`
 
 lint:
 	lint $(DEFS) $(SRCS) $(LINTFIX)
@@ -62,198 +62,198 @@
 
 # do not edit below this line - it is generated by 'make depend'
 smtp.o: smtp.c
-smtp.o: ../../include/sys_defs.h
-smtp.o: ../../include/dict.h
-smtp.o: ../../include/vstream.h
-smtp.o: ../../include/vbuf.h
-smtp.o: ../../include/argv.h
-smtp.o: ../../include/msg.h
-smtp.o: ../../include/mymalloc.h
-smtp.o: ../../include/name_mask.h
-smtp.o: ../../include/deliver_request.h
-smtp.o: ../../include/vstring.h
-smtp.o: ../../include/recipient_list.h
-smtp.o: ../../include/mail_params.h
-smtp.o: ../../include/mail_conf.h
-smtp.o: ../../include/debug_peer.h
-smtp.o: ../../include/mail_error.h
-smtp.o: ../../include/deliver_pass.h
-smtp.o: ../../include/mail_proto.h
-smtp.o: ../../include/iostuff.h
-smtp.o: ../../include/attr.h
-smtp.o: ../../include/mail_server.h
+smtp.o: /usr/include/postfix/sys_defs.h
+smtp.o: /usr/include/postfix/dict.h
+smtp.o: /usr/include/postfix/vstream.h
+smtp.o: /usr/include/postfix/vbuf.h
+smtp.o: /usr/include/postfix/argv.h
+smtp.o: /usr/include/postfix/msg.h
+smtp.o: /usr/include/postfix/mymalloc.h
+smtp.o: /usr/include/postfix/name_mask.h
+smtp.o: /usr/include/postfix/deliver_request.h
+smtp.o: /usr/include/postfix/vstring.h
+smtp.o: /usr/include/postfix/recipient_list.h
+smtp.o: /usr/include/postfix/mail_params.h
+smtp.o: /usr/include/postfix/mail_conf.h
+smtp.o: /usr/include/postfix/debug_peer.h
+smtp.o: /usr/include/postfix/mail_error.h
+smtp.o: /usr/include/postfix/deliver_pass.h
+smtp.o: /usr/include/postfix/mail_proto.h
+smtp.o: /usr/include/postfix/iostuff.h
+smtp.o: /usr/include/postfix/attr.h
+smtp.o: /usr/include/postfix/mail_server.h
 smtp.o: smtp.h
 smtp.o: smtp_sasl.h
 smtp_addr.o: smtp_addr.c
-smtp_addr.o: ../../include/sys_defs.h
-smtp_addr.o: ../../include/msg.h
-smtp_addr.o: ../../include/vstring.h
-smtp_addr.o: ../../include/vbuf.h
-smtp_addr.o: ../../include/mymalloc.h
-smtp_addr.o: ../../include/inet_addr_list.h
-smtp_addr.o: ../../include/stringops.h
-smtp_addr.o: ../../include/myrand.h
-smtp_addr.o: ../../include/mail_params.h
-smtp_addr.o: ../../include/own_inet_addr.h
-smtp_addr.o: ../../include/dns.h
+smtp_addr.o: /usr/include/postfix/sys_defs.h
+smtp_addr.o: /usr/include/postfix/msg.h
+smtp_addr.o: /usr/include/postfix/vstring.h
+smtp_addr.o: /usr/include/postfix/vbuf.h
+smtp_addr.o: /usr/include/postfix/mymalloc.h
+smtp_addr.o: /usr/include/postfix/inet_addr_list.h
+smtp_addr.o: /usr/include/postfix/stringops.h
+smtp_addr.o: /usr/include/postfix/myrand.h
+smtp_addr.o: /usr/include/postfix/mail_params.h
+smtp_addr.o: /usr/include/postfix/own_inet_addr.h
+smtp_addr.o: /usr/include/postfix/dns.h
 smtp_addr.o: smtp.h
-smtp_addr.o: ../../include/vstream.h
-smtp_addr.o: ../../include/argv.h
-smtp_addr.o: ../../include/deliver_request.h
-smtp_addr.o: ../../include/recipient_list.h
+smtp_addr.o: /usr/include/postfix/vstream.h
+smtp_addr.o: /usr/include/postfix/argv.h
+smtp_addr.o: /usr/include/postfix/deliver_request.h
+smtp_addr.o: /usr/include/postfix/recipient_list.h
 smtp_addr.o: smtp_addr.h
 smtp_chat.o: smtp_chat.c
-smtp_chat.o: ../../include/sys_defs.h
-smtp_chat.o: ../../include/msg.h
-smtp_chat.o: ../../include/vstring.h
-smtp_chat.o: ../../include/vbuf.h
-smtp_chat.o: ../../include/vstream.h
-smtp_chat.o: ../../include/argv.h
-smtp_chat.o: ../../include/stringops.h
-smtp_chat.o: ../../include/line_wrap.h
-smtp_chat.o: ../../include/mymalloc.h
-smtp_chat.o: ../../include/recipient_list.h
-smtp_chat.o: ../../include/deliver_request.h
-smtp_chat.o: ../../include/smtp_stream.h
-smtp_chat.o: ../../include/mail_params.h
-smtp_chat.o: ../../include/mail_addr.h
-smtp_chat.o: ../../include/post_mail.h
-smtp_chat.o: ../../include/cleanup_user.h
-smtp_chat.o: ../../include/mail_error.h
-smtp_chat.o: ../../include/name_mask.h
+smtp_chat.o: /usr/include/postfix/sys_defs.h
+smtp_chat.o: /usr/include/postfix/msg.h
+smtp_chat.o: /usr/include/postfix/vstring.h
+smtp_chat.o: /usr/include/postfix/vbuf.h
+smtp_chat.o: /usr/include/postfix/vstream.h
+smtp_chat.o: /usr/include/postfix/argv.h
+smtp_chat.o: /usr/include/postfix/stringops.h
+smtp_chat.o: /usr/include/postfix/line_wrap.h
+smtp_chat.o: /usr/include/postfix/mymalloc.h
+smtp_chat.o: /usr/include/postfix/recipient_list.h
+smtp_chat.o: /usr/include/postfix/deliver_request.h
+smtp_chat.o: /usr/include/postfix/smtp_stream.h
+smtp_chat.o: /usr/include/postfix/mail_params.h
+smtp_chat.o: /usr/include/postfix/mail_addr.h
+smtp_chat.o: /usr/include/postfix/post_mail.h
+smtp_chat.o: /usr/include/postfix/cleanup_user.h
+smtp_chat.o: /usr/include/postfix/mail_error.h
+smtp_chat.o: /usr/include/postfix/name_mask.h
 smtp_chat.o: smtp.h
 smtp_connect.o: smtp_connect.c
-smtp_connect.o: ../../include/sys_defs.h
-smtp_connect.o: ../../include/msg.h
-smtp_connect.o: ../../include/vstream.h
-smtp_connect.o: ../../include/vbuf.h
-smtp_connect.o: ../../include/vstring.h
-smtp_connect.o: ../../include/split_at.h
-smtp_connect.o: ../../include/mymalloc.h
-smtp_connect.o: ../../include/inet_addr_list.h
-smtp_connect.o: ../../include/iostuff.h
-smtp_connect.o: ../../include/timed_connect.h
-smtp_connect.o: ../../include/stringops.h
-smtp_connect.o: ../../include/mail_params.h
-smtp_connect.o: ../../include/own_inet_addr.h
-smtp_connect.o: ../../include/dns.h
+smtp_connect.o: /usr/include/postfix/sys_defs.h
+smtp_connect.o: /usr/include/postfix/msg.h
+smtp_connect.o: /usr/include/postfix/vstream.h
+smtp_connect.o: /usr/include/postfix/vbuf.h
+smtp_connect.o: /usr/include/postfix/vstring.h
+smtp_connect.o: /usr/include/postfix/split_at.h
+smtp_connect.o: /usr/include/postfix/mymalloc.h
+smtp_connect.o: /usr/include/postfix/inet_addr_list.h
+smtp_connect.o: /usr/include/postfix/iostuff.h
+smtp_connect.o: /usr/include/postfix/timed_connect.h
+smtp_connect.o: /usr/include/postfix/stringops.h
+smtp_connect.o: /usr/include/postfix/mail_params.h
+smtp_connect.o: /usr/include/postfix/own_inet_addr.h
+smtp_connect.o: /usr/include/postfix/dns.h
 smtp_connect.o: smtp.h
-smtp_connect.o: ../../include/argv.h
-smtp_connect.o: ../../include/deliver_request.h
-smtp_connect.o: ../../include/recipient_list.h
+smtp_connect.o: /usr/include/postfix/argv.h
+smtp_connect.o: /usr/include/postfix/deliver_request.h
+smtp_connect.o: /usr/include/postfix/recipient_list.h
 smtp_connect.o: smtp_addr.h
 smtp_proto.o: smtp_proto.c
-smtp_proto.o: ../../include/sys_defs.h
-smtp_proto.o: ../../include/msg.h
-smtp_proto.o: ../../include/vstring.h
-smtp_proto.o: ../../include/vbuf.h
-smtp_proto.o: ../../include/vstream.h
-smtp_proto.o: ../../include/vstring_vstream.h
-smtp_proto.o: ../../include/stringops.h
-smtp_proto.o: ../../include/mymalloc.h
-smtp_proto.o: ../../include/iostuff.h
-smtp_proto.o: ../../include/mail_params.h
-smtp_proto.o: ../../include/smtp_stream.h
-smtp_proto.o: ../../include/mail_queue.h
-smtp_proto.o: ../../include/recipient_list.h
-smtp_proto.o: ../../include/deliver_request.h
-smtp_proto.o: ../../include/deliver_completed.h
-smtp_proto.o: ../../include/defer.h
-smtp_proto.o: ../../include/bounce.h
-smtp_proto.o: ../../include/sent.h
-smtp_proto.o: ../../include/record.h
-smtp_proto.o: ../../include/rec_type.h
-smtp_proto.o: ../../include/off_cvt.h
-smtp_proto.o: ../../include/mark_corrupt.h
-smtp_proto.o: ../../include/quote_821_local.h
-smtp_proto.o: ../../include/quote_flags.h
+smtp_proto.o: /usr/include/postfix/sys_defs.h
+smtp_proto.o: /usr/include/postfix/msg.h
+smtp_proto.o: /usr/include/postfix/vstring.h
+smtp_proto.o: /usr/include/postfix/vbuf.h
+smtp_proto.o: /usr/include/postfix/vstream.h
+smtp_proto.o: /usr/include/postfix/vstring_vstream.h
+smtp_proto.o: /usr/include/postfix/stringops.h
+smtp_proto.o: /usr/include/postfix/mymalloc.h
+smtp_proto.o: /usr/include/postfix/iostuff.h
+smtp_proto.o: /usr/include/postfix/mail_params.h
+smtp_proto.o: /usr/include/postfix/smtp_stream.h
+smtp_proto.o: /usr/include/postfix/mail_queue.h
+smtp_proto.o: /usr/include/postfix/recipient_list.h
+smtp_proto.o: /usr/include/postfix/deliver_request.h
+smtp_proto.o: /usr/include/postfix/deliver_completed.h
+smtp_proto.o: /usr/include/postfix/defer.h
+smtp_proto.o: /usr/include/postfix/bounce.h
+smtp_proto.o: /usr/include/postfix/sent.h
+smtp_proto.o: /usr/include/postfix/record.h
+smtp_proto.o: /usr/include/postfix/rec_type.h
+smtp_proto.o: /usr/include/postfix/off_cvt.h
+smtp_proto.o: /usr/include/postfix/mark_corrupt.h
+smtp_proto.o: /usr/include/postfix/quote_821_local.h
+smtp_proto.o: /usr/include/postfix/quote_flags.h
 smtp_proto.o: smtp.h
-smtp_proto.o: ../../include/argv.h
+smtp_proto.o: /usr/include/postfix/argv.h
 smtp_proto.o: smtp_sasl.h
 smtp_sasl_glue.o: smtp_sasl_glue.c
-smtp_sasl_glue.o: ../../include/sys_defs.h
-smtp_sasl_glue.o: ../../include/msg.h
-smtp_sasl_glue.o: ../../include/mymalloc.h
-smtp_sasl_glue.o: ../../include/stringops.h
-smtp_sasl_glue.o: ../../include/vstring.h
-smtp_sasl_glue.o: ../../include/vbuf.h
-smtp_sasl_glue.o: ../../include/split_at.h
-smtp_sasl_glue.o: ../../include/name_mask.h
-smtp_sasl_glue.o: ../../include/mail_params.h
-smtp_sasl_glue.o: ../../include/string_list.h
-smtp_sasl_glue.o: ../../include/match_list.h
-smtp_sasl_glue.o: ../../include/match_ops.h
-smtp_sasl_glue.o: ../../include/maps.h
-smtp_sasl_glue.o: ../../include/dict.h
-smtp_sasl_glue.o: ../../include/vstream.h
-smtp_sasl_glue.o: ../../include/argv.h
+smtp_sasl_glue.o: /usr/include/postfix/sys_defs.h
+smtp_sasl_glue.o: /usr/include/postfix/msg.h
+smtp_sasl_glue.o: /usr/include/postfix/mymalloc.h
+smtp_sasl_glue.o: /usr/include/postfix/stringops.h
+smtp_sasl_glue.o: /usr/include/postfix/vstring.h
+smtp_sasl_glue.o: /usr/include/postfix/vbuf.h
+smtp_sasl_glue.o: /usr/include/postfix/split_at.h
+smtp_sasl_glue.o: /usr/include/postfix/name_mask.h
+smtp_sasl_glue.o: /usr/include/postfix/mail_params.h
+smtp_sasl_glue.o: /usr/include/postfix/string_list.h
+smtp_sasl_glue.o: /usr/include/postfix/match_list.h
+smtp_sasl_glue.o: /usr/include/postfix/match_ops.h
+smtp_sasl_glue.o: /usr/include/postfix/maps.h
+smtp_sasl_glue.o: /usr/include/postfix/dict.h
+smtp_sasl_glue.o: /usr/include/postfix/vstream.h
+smtp_sasl_glue.o: /usr/include/postfix/argv.h
 smtp_sasl_glue.o: smtp.h
-smtp_sasl_glue.o: ../../include/deliver_request.h
-smtp_sasl_glue.o: ../../include/recipient_list.h
+smtp_sasl_glue.o: /usr/include/postfix/deliver_request.h
+smtp_sasl_glue.o: /usr/include/postfix/recipient_list.h
 smtp_sasl_glue.o: smtp_sasl.h
 smtp_sasl_proto.o: smtp_sasl_proto.c
-smtp_sasl_proto.o: ../../include/sys_defs.h
-smtp_sasl_proto.o: ../../include/msg.h
-smtp_sasl_proto.o: ../../include/mymalloc.h
-smtp_sasl_proto.o: ../../include/mail_params.h
+smtp_sasl_proto.o: /usr/include/postfix/sys_defs.h
+smtp_sasl_proto.o: /usr/include/postfix/msg.h
+smtp_sasl_proto.o: /usr/include/postfix/mymalloc.h
+smtp_sasl_proto.o: /usr/include/postfix/mail_params.h
 smtp_sasl_proto.o: smtp.h
-smtp_sasl_proto.o: ../../include/vstream.h
-smtp_sasl_proto.o: ../../include/vbuf.h
-smtp_sasl_proto.o: ../../include/vstring.h
-smtp_sasl_proto.o: ../../include/argv.h
-smtp_sasl_proto.o: ../../include/deliver_request.h
-smtp_sasl_proto.o: ../../include/recipient_list.h
+smtp_sasl_proto.o: /usr/include/postfix/vstream.h
+smtp_sasl_proto.o: /usr/include/postfix/vbuf.h
+smtp_sasl_proto.o: /usr/include/postfix/vstring.h
+smtp_sasl_proto.o: /usr/include/postfix/argv.h
+smtp_sasl_proto.o: /usr/include/postfix/deliver_request.h
+smtp_sasl_proto.o: /usr/include/postfix/recipient_list.h
 smtp_sasl_proto.o: smtp_sasl.h
 smtp_session.o: smtp_session.c
-smtp_session.o: ../../include/sys_defs.h
-smtp_session.o: ../../include/mymalloc.h
-smtp_session.o: ../../include/vstream.h
-smtp_session.o: ../../include/vbuf.h
-smtp_session.o: ../../include/stringops.h
-smtp_session.o: ../../include/vstring.h
+smtp_session.o: /usr/include/postfix/sys_defs.h
+smtp_session.o: /usr/include/postfix/mymalloc.h
+smtp_session.o: /usr/include/postfix/vstream.h
+smtp_session.o: /usr/include/postfix/vbuf.h
+smtp_session.o: /usr/include/postfix/stringops.h
+smtp_session.o: /usr/include/postfix/vstring.h
 smtp_session.o: smtp.h
-smtp_session.o: ../../include/argv.h
-smtp_session.o: ../../include/deliver_request.h
-smtp_session.o: ../../include/recipient_list.h
+smtp_session.o: /usr/include/postfix/argv.h
+smtp_session.o: /usr/include/postfix/deliver_request.h
+smtp_session.o: /usr/include/postfix/recipient_list.h
 smtp_state.o: smtp_state.c
-smtp_state.o: ../../include/sys_defs.h
-smtp_state.o: ../../include/mymalloc.h
-smtp_state.o: ../../include/vstring.h
-smtp_state.o: ../../include/vbuf.h
-smtp_state.o: ../../include/vstream.h
-smtp_state.o: ../../include/mail_conf.h
+smtp_state.o: /usr/include/postfix/sys_defs.h
+smtp_state.o: /usr/include/postfix/mymalloc.h
+smtp_state.o: /usr/include/postfix/vstring.h
+smtp_state.o: /usr/include/postfix/vbuf.h
+smtp_state.o: /usr/include/postfix/vstream.h
+smtp_state.o: /usr/include/postfix/mail_conf.h
 smtp_state.o: smtp.h
-smtp_state.o: ../../include/argv.h
-smtp_state.o: ../../include/deliver_request.h
-smtp_state.o: ../../include/recipient_list.h
+smtp_state.o: /usr/include/postfix/argv.h
+smtp_state.o: /usr/include/postfix/deliver_request.h
+smtp_state.o: /usr/include/postfix/recipient_list.h
 smtp_state.o: smtp_sasl.h
 smtp_trouble.o: smtp_trouble.c
-smtp_trouble.o: ../../include/sys_defs.h
-smtp_trouble.o: ../../include/msg.h
-smtp_trouble.o: ../../include/vstring.h
-smtp_trouble.o: ../../include/vbuf.h
-smtp_trouble.o: ../../include/stringops.h
-smtp_trouble.o: ../../include/mymalloc.h
-smtp_trouble.o: ../../include/smtp_stream.h
-smtp_trouble.o: ../../include/vstream.h
-smtp_trouble.o: ../../include/deliver_request.h
-smtp_trouble.o: ../../include/recipient_list.h
-smtp_trouble.o: ../../include/deliver_completed.h
-smtp_trouble.o: ../../include/bounce.h
-smtp_trouble.o: ../../include/defer.h
-smtp_trouble.o: ../../include/mail_error.h
-smtp_trouble.o: ../../include/name_mask.h
+smtp_trouble.o: /usr/include/postfix/sys_defs.h
+smtp_trouble.o: /usr/include/postfix/msg.h
+smtp_trouble.o: /usr/include/postfix/vstring.h
+smtp_trouble.o: /usr/include/postfix/vbuf.h
+smtp_trouble.o: /usr/include/postfix/stringops.h
+smtp_trouble.o: /usr/include/postfix/mymalloc.h
+smtp_trouble.o: /usr/include/postfix/smtp_stream.h
+smtp_trouble.o: /usr/include/postfix/vstream.h
+smtp_trouble.o: /usr/include/postfix/deliver_request.h
+smtp_trouble.o: /usr/include/postfix/recipient_list.h
+smtp_trouble.o: /usr/include/postfix/deliver_completed.h
+smtp_trouble.o: /usr/include/postfix/bounce.h
+smtp_trouble.o: /usr/include/postfix/defer.h
+smtp_trouble.o: /usr/include/postfix/mail_error.h
+smtp_trouble.o: /usr/include/postfix/name_mask.h
 smtp_trouble.o: smtp.h
-smtp_trouble.o: ../../include/argv.h
+smtp_trouble.o: /usr/include/postfix/argv.h
 smtp_unalias.o: smtp_unalias.c
-smtp_unalias.o: ../../include/sys_defs.h
-smtp_unalias.o: ../../include/htable.h
-smtp_unalias.o: ../../include/vstring.h
-smtp_unalias.o: ../../include/vbuf.h
-smtp_unalias.o: ../../include/msg.h
-smtp_unalias.o: ../../include/dns.h
+smtp_unalias.o: /usr/include/postfix/sys_defs.h
+smtp_unalias.o: /usr/include/postfix/htable.h
+smtp_unalias.o: /usr/include/postfix/vstring.h
+smtp_unalias.o: /usr/include/postfix/vbuf.h
+smtp_unalias.o: /usr/include/postfix/msg.h
+smtp_unalias.o: /usr/include/postfix/dns.h
 smtp_unalias.o: smtp.h
-smtp_unalias.o: ../../include/vstream.h
-smtp_unalias.o: ../../include/argv.h
-smtp_unalias.o: ../../include/deliver_request.h
-smtp_unalias.o: ../../include/recipient_list.h
+smtp_unalias.o: /usr/include/postfix/vstream.h
+smtp_unalias.o: /usr/include/postfix/argv.h
+smtp_unalias.o: /usr/include/postfix/deliver_request.h
+smtp_unalias.o: /usr/include/postfix/recipient_list.h
diff -ur ../../postfix/postfix-1.1.11/src/smtp/smtp.c src/smtp/smtp.c
--- ../../postfix/postfix-1.1.11/src/smtp/smtp.c	Thu Mar 28 12:28:04 2002
+++ src/smtp/smtp.c	Thu Jul 11 17:48:38 2002
@@ -216,11 +216,12 @@
 /* Global library. */
 
 #include <deliver_request.h>
-#include <mail_params.h>
+#include <tls_mail_params.h>
 #include <mail_conf.h>
 #include <debug_peer.h>
 #include <mail_error.h>
 #include <deliver_pass.h>
+#include <pfixtls.h>
 
 /* Single server skeleton. */
 
@@ -237,6 +238,7 @@
   */
 int     var_smtp_conn_tmout;
 int     var_smtp_helo_tmout;
+int     var_smtp_starttls_tmout;
 int     var_smtp_mail_tmout;
 int     var_smtp_rcpt_tmout;
 int     var_smtp_data0_tmout;
@@ -259,6 +261,12 @@
 bool    var_smtp_sasl_enable;
 char   *var_smtp_bind_addr;
 bool    var_smtp_rand_addr;
+int     var_smtp_use_tls;
+int     var_smtp_enforce_tls;
+int     var_smtp_tls_enforce_peername;
+char   *var_smtp_tls_per_site;
+int     var_smtp_tls_scert_vd;
+int     var_smtp_tls_note_starttls_offer;
 int     var_smtp_pix_thresh;
 int     var_smtp_pix_delay;
 int     var_smtp_line_limit;
@@ -370,6 +378,7 @@
 
 static void pre_init(char *unused_name, char **unused_argv)
 {
+
     debug_peer_init();
 
     if (var_smtp_sasl_enable)
@@ -379,6 +388,14 @@
 	msg_warn("%s is true, but SASL support is not compiled in",
 		 VAR_SMTP_SASL_ENABLE);
 #endif
+    /*
+     * Initialize the TLS data before entering the chroot jail
+     */
+#ifdef HAS_SSL
+    if (var_smtp_use_tls || var_smtp_enforce_tls || var_smtp_tls_per_site[0])
+	pfixtls_init_clientengine(var_smtp_tls_scert_vd);
+    smtp_tls_list_init();
+#endif
 }
 
 /* pre_accept - see if tables have changed */
@@ -413,6 +430,17 @@
 	VAR_SMTP_SASL_PASSWD, DEF_SMTP_SASL_PASSWD, &var_smtp_sasl_passwd, 0, 0,
 	VAR_SMTP_SASL_OPTS, DEF_SMTP_SASL_OPTS, &var_smtp_sasl_opts, 0, 0,
 	VAR_SMTP_BIND_ADDR, DEF_SMTP_BIND_ADDR, &var_smtp_bind_addr, 0, 0,
+	VAR_SMTP_TLS_PER_SITE, DEF_SMTP_TLS_PER_SITE, &var_smtp_tls_per_site, 0, 0,
+	VAR_SMTP_TLS_CERT_FILE, DEF_SMTP_TLS_CERT_FILE, &var_smtp_tls_cert_file, 0, 0,
+	VAR_SMTP_TLS_KEY_FILE, DEF_SMTP_TLS_KEY_FILE, &var_smtp_tls_key_file, 0, 0,
+	VAR_SMTP_TLS_DCERT_FILE, DEF_SMTP_TLS_DCERT_FILE, &var_smtp_tls_dcert_file, 0, 0,
+	VAR_SMTP_TLS_DKEY_FILE, DEF_SMTP_TLS_DKEY_FILE, &var_smtp_tls_dkey_file, 0, 0,
+	VAR_SMTP_TLS_CA_FILE, DEF_SMTP_TLS_CA_FILE, &var_smtp_tls_CAfile, 0, 0,
+	VAR_SMTP_TLS_CA_PATH, DEF_SMTP_TLS_CA_PATH, &var_smtp_tls_CApath, 0, 0,
+	VAR_SMTP_TLS_CLIST, DEF_SMTP_TLS_CLIST, &var_smtp_tls_cipherlist, 0, 0,
+	VAR_SMTP_TLS_SCACHE_DB, DEF_SMTP_TLS_SCACHE_DB, &var_smtp_tls_scache_db, 0, 0,
+	VAR_TLS_RAND_EXCH_NAME, DEF_TLS_RAND_EXCH_NAME, &var_tls_rand_exch_name, 0, 0,
+	VAR_TLS_DAEMON_RAND_SOURCE, DEF_TLS_DAEMON_RAND_SOURCE, &var_tls_daemon_rand_source, 0, 0,
 	0,
     };
     static CONFIG_TIME_TABLE time_table[] = {
@@ -423,16 +451,24 @@
 	VAR_SMTP_DATA0_TMOUT, DEF_SMTP_DATA0_TMOUT, &var_smtp_data0_tmout, 1, 0,
 	VAR_SMTP_DATA1_TMOUT, DEF_SMTP_DATA1_TMOUT, &var_smtp_data1_tmout, 1, 0,
 	VAR_SMTP_DATA2_TMOUT, DEF_SMTP_DATA2_TMOUT, &var_smtp_data2_tmout, 1, 0,
+	VAR_SMTP_STARTTLS_TMOUT, DEF_SMTP_STARTTLS_TMOUT, &var_smtp_starttls_tmout, 1, 0,
+	VAR_SMTP_TLS_SCACHTIME, DEF_SMTP_TLS_SCACHTIME, &var_smtp_tls_scache_timeout, 0, 0,
 	VAR_SMTP_QUIT_TMOUT, DEF_SMTP_QUIT_TMOUT, &var_smtp_quit_tmout, 1, 0,
 	VAR_SMTP_PIX_THRESH, DEF_SMTP_PIX_THRESH, &var_smtp_pix_thresh, 0, 0,
 	VAR_SMTP_PIX_DELAY, DEF_SMTP_PIX_DELAY, &var_smtp_pix_delay, 1, 0,
 	0,
     };
     static CONFIG_INT_TABLE int_table[] = {
+	VAR_SMTP_TLS_LOGLEVEL, DEF_SMTP_TLS_LOGLEVEL, &var_smtp_tls_loglevel, 0, 0,
+	VAR_TLS_DAEMON_RAND_BYTES, DEF_TLS_DAEMON_RAND_BYTES, &var_tls_daemon_rand_bytes, 0, 0,
 	VAR_SMTP_LINE_LIMIT, DEF_SMTP_LINE_LIMIT, &var_smtp_line_limit, 0, 0,
 	0,
     };
     static CONFIG_BOOL_TABLE bool_table[] = {
+	VAR_SMTP_USE_TLS, DEF_SMTP_USE_TLS, &var_smtp_use_tls,
+	VAR_SMTP_ENFORCE_TLS, DEF_SMTP_ENFORCE_TLS, &var_smtp_enforce_tls,
+	VAR_SMTP_TLS_ENFORCE_PN, DEF_SMTP_TLS_ENFORCE_PN, &var_smtp_tls_enforce_peername,
+	VAR_SMTP_TLS_NOTEOFFER, DEF_SMTP_TLS_NOTEOFFER, &var_smtp_tls_note_starttls_offer,
 	VAR_SMTP_SKIP_4XX, DEF_SMTP_SKIP_4XX, &var_smtp_skip_4xx_greeting,
 	VAR_SMTP_SKIP_5XX, DEF_SMTP_SKIP_5XX, &var_smtp_skip_5xx_greeting,
 	VAR_IGN_MX_LOOKUP_ERR, DEF_IGN_MX_LOOKUP_ERR, &var_ign_mx_lookup_err,
diff -ur ../../postfix/postfix-1.1.11/src/smtp/smtp.h src/smtp/smtp.h
--- ../../postfix/postfix-1.1.11/src/smtp/smtp.h	Sun Dec 23 09:42:28 2001
+++ src/smtp/smtp.h	Thu Jul 11 17:48:38 2002
@@ -27,6 +27,7 @@
   * Global library.
   */
 #include <deliver_request.h>
+#include <pfixtls.h>
 
  /*
   * State information associated with each SMTP delivery. We're bundling the
@@ -77,9 +78,14 @@
     char   *addr;			/* mail exchanger */
     char   *namaddr;			/* mail exchanger */
     int     best;			/* most preferred host */
+    int     tls_use_tls;		/* can do TLS */
+    int     tls_enforce_tls;		/* must do TLS */
+    int     tls_enforce_peername;	/* cert must match */
+    tls_info_t tls_info;		/* TLS connection state */
 } SMTP_SESSION;
 
-extern SMTP_SESSION *smtp_session_alloc(VSTREAM *, char *, char *);
+extern void smtp_tls_list_init(void);
+extern SMTP_SESSION *smtp_session_alloc(char *, VSTREAM *, char *, char *);
 extern void smtp_session_free(SMTP_SESSION *);
 
  /*
diff -ur ../../postfix/postfix-1.1.11/src/smtp/smtp_addr.c src/smtp/smtp_addr.c
--- ../../postfix/postfix-1.1.11/src/smtp/smtp_addr.c	Wed Aug  1 11:03:48 2001
+++ src/smtp/smtp_addr.c	Thu Jul 11 17:48:38 2002
@@ -117,7 +117,7 @@
 
 /* Global library. */
 
-#include <mail_params.h>
+#include <tls_mail_params.h>
 #include <own_inet_addr.h>
 
 /* DNS library. */
diff -ur ../../postfix/postfix-1.1.11/src/smtp/smtp_chat.c src/smtp/smtp_chat.c
--- ../../postfix/postfix-1.1.11/src/smtp/smtp_chat.c	Wed May 30 21:55:35 2001
+++ src/smtp/smtp_chat.c	Thu Jul 11 17:48:38 2002
@@ -88,7 +88,7 @@
 #include <recipient_list.h>
 #include <deliver_request.h>
 #include <smtp_stream.h>
-#include <mail_params.h>
+#include <tls_mail_params.h>
 #include <mail_addr.h>
 #include <post_mail.h>
 #include <mail_error.h>
diff -ur ../../postfix/postfix-1.1.11/src/smtp/smtp_connect.c src/smtp/smtp_connect.c
--- ../../postfix/postfix-1.1.11/src/smtp/smtp_connect.c	Wed Aug  1 11:03:48 2001
+++ src/smtp/smtp_connect.c	Thu Jul 11 17:48:38 2002
@@ -114,8 +114,9 @@
 
 /* Global library. */
 
-#include <mail_params.h>
+#include <tls_mail_params.h>
 #include <own_inet_addr.h>
+#include <pfixtls.h>
 
 /* DNS library. */
 
@@ -128,7 +129,7 @@
 
 /* smtp_connect_addr - connect to explicit address */
 
-static SMTP_SESSION *smtp_connect_addr(DNS_RR *addr, unsigned port,
+static SMTP_SESSION *smtp_connect_addr(char *dest, DNS_RR *addr, unsigned port,
 				               VSTRING *why)
 {
     char   *myname = "smtp_connect_addr";
@@ -262,7 +263,7 @@
 	vstream_fclose(stream);
 	return (0);
     }
-    return (smtp_session_alloc(stream, addr->name, inet_ntoa(sin.sin_addr)));
+    return (smtp_session_alloc(dest, stream, addr->name, inet_ntoa(sin.sin_addr)));
 }
 
 /* smtp_connect_host - direct connection to host */
@@ -280,7 +281,7 @@
      */
     addr_list = smtp_host_addr(host, why);
     for (addr = addr_list; addr; addr = addr->next) {
-	if ((session = smtp_connect_addr(addr, port, why)) != 0) {
+	if ((session = smtp_connect_addr(host, addr, port, why)) != 0) {
 	    session->best = 1;
 	    break;
 	}
@@ -309,7 +310,7 @@
      */
     addr_list = smtp_domain_addr(name, why, found_myself);
     for (addr = addr_list; addr; addr = addr->next) {
-	if ((session = smtp_connect_addr(addr, port, why)) != 0) {
+	if ((session = smtp_connect_addr(name, addr, port, why)) != 0) {
 	    session->best = (addr->pref == addr_list->pref);
 	    break;
 	}
diff -ur ../../postfix/postfix-1.1.11/src/smtp/smtp_proto.c src/smtp/smtp_proto.c
--- ../../postfix/postfix-1.1.11/src/smtp/smtp_proto.c	Thu Jul 11 15:09:52 2002
+++ src/smtp/smtp_proto.c	Thu Jul 11 17:48:38 2002
@@ -86,7 +86,7 @@
 
 /* Global library. */
 
-#include <mail_params.h>
+#include <tls_mail_params.h>
 #include <smtp_stream.h>
 #include <mail_queue.h>
 #include <recipient_list.h>
@@ -100,6 +100,7 @@
 #include <off_cvt.h>
 #include <mark_corrupt.h>
 #include <quote_821_local.h>
+#include <pfixtls.h>
 
 /* Application-specific. */
 
@@ -158,6 +159,8 @@
     char   *words;
     char   *word;
     int     n;
+    int     oldfeatures;
+    int     rval;
 
     /*
      * Prepare for disaster.
@@ -219,7 +222,8 @@
 				   session->namaddr,
 				   translit(resp->str, "\n", " ")));
     }
-
+    if (var_smtp_always_ehlo)
+	state->features |= SMTP_FEATURE_ESMTP;
     /*
      * Pick up some useful features offered by the SMTP server. XXX Until we
      * have a portable routine to convert from string to off_t with proper
@@ -231,6 +235,7 @@
      * MicroSoft implemented AUTH based on an old draft.
      */
     lines = resp->str;
+    oldfeatures = state->features;		/* remember */
     while ((words = mystrtok(&lines, "\n")) != 0) {
 	if (mystrtok(&words, "- ") && (word = mystrtok(&words, " \t=")) != 0) {
 	    if (strcasecmp(word, "8BITMIME") == 0)
@@ -247,6 +252,8 @@
 			state->size_limit = off_cvt_string(word);
 		}
 	    }
+	    else if (strcasecmp(word, "STARTTLS") == 0)
+		state->features |= SMTP_FEATURE_STARTTLS;
 #ifdef USE_SASL_AUTH
 	    else if (var_smtp_sasl_enable && strcasecmp(word, "AUTH") == 0)
 		smtp_sasl_helo_auth(state, words);
@@ -264,6 +271,121 @@
 	msg_info("server features: 0x%x size %.0f",
 		 state->features, (double) state->size_limit);
 
+#ifdef HAS_SSL
+    if ((state->features & SMTP_FEATURE_STARTTLS) &&
+	(var_smtp_tls_note_starttls_offer) &&
+	(!(session->tls_enforce_tls || session->tls_use_tls)))
+ 	msg_info("Host offered STARTTLS: [%s]", session->host);
+    if ((session->tls_enforce_tls) &&
+	!(state->features & SMTP_FEATURE_STARTTLS))
+    {
+	/*
+	 * We are enforced to use TLS but it is not offered, so we will give
+	 * up on this host. We won't even try STARTTLS, because we could
+	 * receive a "500 command unrecognized" which would bounce the
+	 * message. We instead want to delay until STARTTLS becomes
+	 * available.
+	 */
+	return (smtp_site_fail(state, 450, "Could not start TLS: not offered"));
+    }
+    if ((session->tls_enforce_tls) && !pfixtls_clientengine) {
+	/*
+	 * We would like to start client TLS, but our own TLS-engine is
+	 * not running.
+	 */
+	return (smtp_site_fail(state, 450,
+		 "Could not start TLS: our TLS-engine not running"));
+    }
+    if ((state->features & SMTP_FEATURE_STARTTLS) &&
+	((session->tls_use_tls && pfixtls_clientengine) ||
+	 (session->tls_enforce_tls))) {
+	/*
+         * Try to use the TLS feature
+         */
+	smtp_chat_cmd(state, "STARTTLS");
+	if ((resp = smtp_chat_resp(state))->code / 100 != 2) {
+	    state->features &= ~SMTP_FEATURE_STARTTLS;
+	    /*
+	     * At this point a political decision is necessary. If we
+	     * enforce usage of tls, we have to close the connection
+	     * now.
+	     */
+	    if (session->tls_enforce_tls)
+		return (smtp_site_fail(state, resp->code,
+					 "host %s refused to start TLS: %s",
+					   session->host,
+					   translit(resp->str, "\n", " ")));
+	} else {
+	    if (rval = pfixtls_start_clienttls(session->stream,
+					       var_smtp_starttls_tmout,
+					       session->tls_enforce_peername,
+					       session->host,
+					       &(session->tls_info)))
+		return (smtp_site_fail(state, 450,
+				 "Could not start TLS: client failure"));
+
+
+	    /*
+	     * Now the connection is established and maybe we do have a
+	     * validated cert with a CommonName in it.
+	     * In enforce_peername state, the handshake would already have
+	     * been terminated so the check here is for logging only!
+	     */
+	    if (session->tls_info.peer_CN != NULL) {
+		if (!session->tls_info.peer_verified) {
+		    msg_info("Peer certficate could not be verified");
+		    if (session->tls_enforce_tls) {
+			pfixtls_stop_clienttls(session->stream,
+					       var_smtp_starttls_tmout, 1,
+					       &(session->tls_info));
+			return(smtp_site_fail(state, 450, "TLS-failure: Could not verify certificate"));
+		    }
+		}
+	    } else if (session->tls_enforce_tls) {
+		pfixtls_stop_clienttls(session->stream,
+				       var_smtp_starttls_tmout, 1,
+				       &(session->tls_info));
+		return (smtp_site_fail(state, 450, "TLS-failure: Cannot verify hostname"));
+	    }
+
+	    /*
+	     * At this point we have to re-negotiate the "EHLO" to reget
+	     * the feature-list
+	     */
+	    state->features = oldfeatures;
+	    if (state->features & SMTP_FEATURE_ESMTP) {
+		smtp_chat_cmd(state, "EHLO %s", var_myhostname);
+		if ((resp = smtp_chat_resp(state))->code / 100 != 2)
+		    state->features &= ~SMTP_FEATURE_ESMTP;
+	    }
+	    lines = resp->str;
+	    (void) mystrtok(&lines, "\n");
+	    while ((words = mystrtok(&lines, "\n")) != 0) {
+		if (mystrtok(&words, "- ") &&
+		    (word = mystrtok(&words, " \t")) != 0) {
+		    if (strcasecmp(word, "8BITMIME") == 0)
+			state->features |= SMTP_FEATURE_8BITMIME;
+		    else if (strcasecmp(word, "PIPELINING") == 0)
+			state->features |= SMTP_FEATURE_PIPELINING;
+		    else if (strcasecmp(word, "SIZE") == 0)
+			state->features |= SMTP_FEATURE_SIZE;
+		    else if (strcasecmp(word, "STARTTLS") == 0)
+			state->features |= SMTP_FEATURE_STARTTLS;
+#ifdef USE_SASL_AUTH
+		    else if (var_smtp_sasl_enable && strcasecmp(word, "AUTH") == 0)
+			smtp_sasl_helo_auth(state, words);
+#endif
+		}
+	    }
+	    /*
+	     * Actually, at this point STARTTLS should not be offered
+	     * anymore, so we could check for a protocol violation, but
+	     * what should we do then?
+	     */
+
+	}
+    }
+#endif
 #ifdef USE_SASL_AUTH
     if (var_smtp_sasl_enable && (state->features & SMTP_FEATURE_AUTH))
 	return (smtp_sasl_helo_login(state));
diff -ur ../../postfix/postfix-1.1.11/src/smtp/smtp_sasl_glue.c src/smtp/smtp_sasl_glue.c
--- ../../postfix/postfix-1.1.11/src/smtp/smtp_sasl_glue.c	Mon Apr 22 21:58:54 2002
+++ src/smtp/smtp_sasl_glue.c	Thu Jul 11 17:48:38 2002
@@ -96,7 +96,7 @@
  /*
   * Global library
   */
-#include <mail_params.h>
+#include <tls_mail_params.h>
 #include <string_list.h>
 #include <maps.h>
 
diff -ur ../../postfix/postfix-1.1.11/src/smtp/smtp_sasl_proto.c src/smtp/smtp_sasl_proto.c
--- ../../postfix/postfix-1.1.11/src/smtp/smtp_sasl_proto.c	Wed May 30 21:55:35 2001
+++ src/smtp/smtp_sasl_proto.c	Thu Jul 11 17:48:38 2002
@@ -64,7 +64,7 @@
 
 /* Global library. */
 
-#include <mail_params.h>
+#include <tls_mail_params.h>
 
 /* Application-specific. */
 
diff -ur ../../postfix/postfix-1.1.11/src/smtp/smtp_session.c src/smtp/smtp_session.c
--- ../../postfix/postfix-1.1.11/src/smtp/smtp_session.c	Mon Nov 20 11:06:05 2000
+++ src/smtp/smtp_session.c	Thu Jul 11 17:48:38 2002
@@ -42,15 +42,42 @@
 #include <vstream.h>
 #include <stringops.h>
 
+#include <tls_mail_params.h>
+#include <maps.h>
+#include <pfixtls.h>
+
 /* Application-specific. */
 
 #include "smtp.h"
 
+#ifdef HAS_SSL
+/* static lists */
+static MAPS *tls_per_site;
+
+/* smtp_tls_list_init - initialize lists */
+
+void smtp_tls_list_init(void)
+{
+    tls_per_site = maps_create(VAR_SMTP_TLS_PER_SITE, var_smtp_tls_per_site,
+			       DICT_FLAG_LOCK);
+}
+#endif
+
 /* smtp_session_alloc - allocate and initialize SMTP_SESSION structure */
 
-SMTP_SESSION *smtp_session_alloc(VSTREAM *stream, char *host, char *addr)
+SMTP_SESSION *smtp_session_alloc(char *dest, VSTREAM *stream, char *host, char *addr)
 {
     SMTP_SESSION *session;
+    const char *lookup;
+    char *lookup_key;
+    int host_dont_use = 0;
+    int host_use = 0;
+    int host_enforce = 0;
+    int host_enforce_peername = 0;
+    int recipient_dont_use = 0;
+    int recipient_use = 0;
+    int recipient_enforce = 0;
+    int recipient_enforce_peername = 0;
 
     session = (SMTP_SESSION *) mymalloc(sizeof(*session));
     session->stream = stream;
@@ -58,6 +85,61 @@
     session->addr = mystrdup(addr);
     session->namaddr = concatenate(host, "[", addr, "]", (char *) 0);
     session->best = 1;
+    session->tls_use_tls = session->tls_enforce_tls = 0;
+    session->tls_enforce_peername = 0;
+#ifdef HAS_SSL
+    lookup_key = lowercase(mystrdup(host));
+    if (lookup = maps_find(tls_per_site, lookup_key, 0)) {
+	if (!strcasecmp(lookup, "NONE"))
+	    host_dont_use = 1;
+	else if (!strcasecmp(lookup, "MAY"))
+	    host_use = 1;
+	else if (!strcasecmp(lookup, "MUST"))
+	    host_enforce = host_enforce_peername = 1;
+	else if (!strcasecmp(lookup, "MUST_NOPEERMATCH"))
+	    host_enforce = 1;
+	else
+	    msg_warn("Unknown TLS state for receiving host %s: '%s', using default policy", session->host, lookup);
+    }
+    myfree(lookup_key);
+    lookup_key = lowercase(mystrdup(dest));
+    if (lookup = maps_find(tls_per_site, dest, 0)) {
+	if (!strcasecmp(lookup, "NONE"))
+	    recipient_dont_use = 1;
+	else if (!strcasecmp(lookup, "MAY"))
+	    recipient_use = 1;
+	else if (!strcasecmp(lookup, "MUST"))
+	    recipient_enforce = recipient_enforce_peername = 1;
+	else if (!strcasecmp(lookup, "MUST_NOPEERMATCH"))
+	    recipient_enforce = 1;
+	else
+	    msg_warn("Unknown TLS state for recipient domain %s: '%s', using default policy", dest, lookup);
+    }
+    myfree(lookup_key);
+
+    if ((var_smtp_enforce_tls && !host_dont_use) || host_enforce ||
+	 recipient_enforce)
+	session->tls_enforce_tls = session->tls_use_tls = 1;
+
+    /*
+     * Set up peername checking. We want to make sure that a MUST* entry in
+     * the tls_per_site table always has precedence. MUST always must lead to
+     * a peername check, MUST_NOPEERMATCH must always disable it. Only when
+     * no explicit setting has been found, the default will be used.
+     * There is the case left, that both "host" and "recipient" settings
+     * conflict. In this case, the "host" setting wins.
+     */
+    if (host_enforce && host_enforce_peername)
+	session->tls_enforce_peername = 1;
+    else if (recipient_enforce && recipient_enforce_peername)
+	session->tls_enforce_peername = 1;
+    else if (var_smtp_enforce_tls && var_smtp_tls_enforce_peername)
+	session->tls_enforce_peername = 1;
+
+    else if ((var_smtp_use_tls && !host_dont_use) || host_use || recipient_use)
+      session->tls_use_tls = 1;
+#endif
+    session->tls_info = tls_info_zero;
     return (session);
 }
 
@@ -65,6 +147,11 @@
 
 void    smtp_session_free(SMTP_SESSION *session)
 {
+#ifdef HAS_SSL
+    vstream_fflush(session->stream);
+    pfixtls_stop_clienttls(session->stream, var_smtp_starttls_tmout, 0,
+			   &(session->tls_info));
+#endif
     vstream_fclose(session->stream);
     myfree(session->host);
     myfree(session->addr);
