1 /*++
2 /* NAME
3 /*	postdrop 1
4 /* SUMMARY
5 /*	Postfix mail posting utility
6 /* SYNOPSIS
7 /*	\fBpostdrop\fR [\fB-rv\fR] [\fB-c \fIconfig_dir\fR]
8 /* DESCRIPTION
9 /*	The \fBpostdrop\fR(1) command creates a file in the \fBmaildrop\fR
10 /*	directory and copies its standard input to the file.
11 /*
12 /*	Options:
13 /* .IP "\fB-c \fIconfig_dir\fR"
14 /*	The \fBmain.cf\fR configuration file is in the named directory
15 /*	instead of the default configuration directory. See also the
16 /*	MAIL_CONFIG environment setting below.
17 /* .IP \fB-r\fR
18 /*	Use a Postfix-internal protocol for reading the message from
19 /*	standard input, and for reporting status information on standard
20 /*	output. This is currently the only supported method.
21 /* .IP \fB-v\fR
22 /*	Enable verbose logging for debugging purposes. Multiple \fB-v\fR
23 /*	options make the software increasingly verbose. As of Postfix 2.3,
24 /*	this option is available for the super-user only.
25 /* SECURITY
26 /* .ad
27 /* .fi
28 /*	The command is designed to run with set-group ID privileges, so
29 /*	that it can write to the \fBmaildrop\fR queue directory and so that
30 /*	it can connect to Postfix daemon processes.
31 /* DIAGNOSTICS
32 /*	Fatal errors: malformed input, I/O error, out of memory. Problems
33 /*	are logged to \fBsyslogd\fR(8) or \fBpostlogd\fR(8) and to
34 /*	the standard error stream.
35 /*	When the input is incomplete, or when the process receives a HUP,
36 /*	INT, QUIT or TERM signal, the queue file is deleted.
37 /* ENVIRONMENT
38 /* .ad
39 /* .fi
40 /* .IP MAIL_CONFIG
41 /*	Directory with the \fBmain.cf\fR file. In order to avoid exploitation
42 /*	of set-group ID privileges, a non-standard directory is allowed only
43 /*	if:
44 /* .RS
45 /* .IP \(bu
46 /*	The name is listed in the standard \fBmain.cf\fR file with the
47 /*	\fBalternate_config_directories\fR configuration parameter.
48 /* .IP \(bu
49 /*	The command is invoked by the super-user.
50 /* .RE
51 /* CONFIGURATION PARAMETERS
52 /* .ad
53 /* .fi
54 /*	The following \fBmain.cf\fR parameters are especially relevant to
55 /*	this program.
56 /*	The text below provides only a parameter summary. See
57 /*	\fBpostconf\fR(5) for more details including examples.
58 /* .IP "\fBalternate_config_directories (empty)\fR"
59 /*	A list of non-default Postfix configuration directories that may
60 /*	be specified with "-c config_directory" on the command line (in the
61 /*	case of \fBsendmail\fR(1), with the "-C" option), or via the MAIL_CONFIG
62 /*	environment parameter.
63 /* .IP "\fBconfig_directory (see 'postconf -d' output)\fR"
64 /*	The default location of the Postfix main.cf and master.cf
65 /*	configuration files.
66 /* .IP "\fBimport_environment (see 'postconf -d' output)\fR"
67 /*	The list of environment parameters that a privileged Postfix
68 /*	process will import from a non-Postfix parent process, or name=value
69 /*	environment overrides.
70 /* .IP "\fBqueue_directory (see 'postconf -d' output)\fR"
71 /*	The location of the Postfix top-level queue directory.
72 /* .IP "\fBsyslog_facility (mail)\fR"
73 /*	The syslog facility of Postfix logging.
74 /* .IP "\fBsyslog_name (see 'postconf -d' output)\fR"
75 /*	A prefix that is prepended to the process name in syslog
76 /*	records, so that, for example, "smtpd" becomes "prefix/smtpd".
77 /* .IP "\fBtrigger_timeout (10s)\fR"
78 /*	The time limit for sending a trigger to a Postfix daemon (for
79 /*	example, the \fBpickup\fR(8) or \fBqmgr\fR(8) daemon).
80 /* .PP
81 /*	Available in Postfix version 2.2 and later:
82 /* .IP "\fBauthorized_submit_users (static:anyone)\fR"
83 /*	List of users who are authorized to submit mail with the \fBsendmail\fR(1)
84 /*	command (and with the privileged \fBpostdrop\fR(1) helper command).
85 /* .PP
86 /*	Available in Postfix version 3.6 and later:
87 /* .IP "\fBlocal_login_sender_maps (static:*)\fR"
88 /*	A list of lookup tables that are searched by the UNIX login name,
89 /*	and that return a list of allowed envelope sender patterns separated
90 /*	by space or comma.
91 /* .IP "\fBempty_address_local_login_sender_maps_lookup_key (<>)\fR"
92 /*	The lookup key to be used in local_login_sender_maps tables, instead
93 /*	of the null sender address.
94 /* .IP "\fBrecipient_delimiter (empty)\fR"
95 /*	The set of characters that can separate an email address
96 /*	localpart, user name, or a .forward file name from its extension.
97 /* FILES
98 /*	/var/spool/postfix/maildrop, maildrop queue
99 /* SEE ALSO
100 /*	sendmail(1), compatibility interface
101 /*	postconf(5), configuration parameters
102 /*	postlogd(8), Postfix logging
103 /*	syslogd(8), system logging
104 /* LICENSE
105 /* .ad
106 /* .fi
107 /*	The Secure Mailer license must be distributed with this software.
108 /* AUTHOR(S)
109 /*	Wietse Venema
110 /*	IBM T.J. Watson Research
111 /*	P.O. Box 704
112 /*	Yorktown Heights, NY 10598, USA
113 /*
114 /*	Wietse Venema
115 /*	Google, Inc.
116 /*	111 8th Avenue
117 /*	New York, NY 10011, USA
118 /*--*/
119 
120 /* System library. */
121 
122 #include <sys_defs.h>
123 #include <sys/stat.h>
124 #include <unistd.h>
125 #include <stdlib.h>
126 #include <stdio.h>			/* remove() */
127 #include <string.h>
128 #include <stdlib.h>
129 #include <signal.h>
130 #include <errno.h>
131 #include <warn_stat.h>
132 
133 /* Utility library. */
134 
135 #include <msg.h>
136 #include <mymalloc.h>
137 #include <vstream.h>
138 #include <vstring.h>
139 #include <msg_vstream.h>
140 #include <argv.h>
141 #include <iostuff.h>
142 #include <stringops.h>
143 #include <mypwd.h>
144 
145 /* Global library. */
146 
147 #include <mail_proto.h>
148 #include <mail_queue.h>
149 #include <mail_params.h>
150 #include <mail_version.h>
151 #include <mail_conf.h>
152 #include <mail_task.h>
153 #include <clean_env.h>
154 #include <mail_stream.h>
155 #include <cleanup_user.h>
156 #include <record.h>
157 #include <rec_type.h>
158 #include <mail_dict.h>
159 #include <user_acl.h>
160 #include <rec_attr_map.h>
161 #include <mail_parm_split.h>
162 #include <maillog_client.h>
163 #include <login_sender_match.h>
164 
165 /* Application-specific. */
166 
167  /*
168   * WARNING WARNING WARNING
169   *
170   * This software is designed to run set-gid. In order to avoid exploitation of
171   * privilege, this software should not run any external commands, nor should
172   * it take any information from the user unless that information can be
173   * properly sanitized. To get an idea of how much information a process can
174   * inherit from a potentially hostile user, examine all the members of the
175   * process structure (typically, in /usr/include/sys/proc.h): the current
176   * directory, open files, timers, signals, environment, command line, umask,
177   * and so on.
178   */
179 
180  /*
181   * Local mail submission access list.
182   */
183 char   *var_submit_acl;
184 char   *var_local_login_snd_maps;
185 char   *var_null_local_login_snd_maps_key;
186 
187 static const CONFIG_STR_TABLE str_table[] = {
188     VAR_SUBMIT_ACL, DEF_SUBMIT_ACL, &var_submit_acl, 0, 0,
189     VAR_LOCAL_LOGIN_SND_MAPS, DEF_LOCAL_LOGIN_SND_MAPS, &var_local_login_snd_maps, 0, 0,
190     VAR_NULL_LOCAL_LOGIN_SND_MAPS_KEY, DEF_NULL_LOCAL_LOGIN_SND_MAPS_KEY, &var_null_local_login_snd_maps_key, 0, 0,
191     0,
192 };
193 
194  /*
195   * Queue file name. Global, so that the cleanup routine can find it when
196   * called by the run-time error handler.
197   */
198 static char *postdrop_path;
199 
200 /* postdrop_sig - catch signal and clean up */
201 
postdrop_sig(int sig)202 static void postdrop_sig(int sig)
203 {
204 
205     /*
206      * This is the fatal error handler. Don't try to do anything fancy.
207      *
208      * To avoid privilege escalation in a set-gid program, Postfix logging
209      * functions must not be called from a user-triggered signal handler,
210      * because Postfix logging functions may allocate memory on the fly (as
211      * does the syslog() library function), and the memory allocator is not
212      * reentrant.
213      *
214      * Assume atomic signal() updates, even when emulated with sigaction(). We
215      * use the in-kernel SIGINT handler address as an atomic variable to
216      * prevent nested postdrop_sig() calls. For this reason, main() must
217      * configure postdrop_sig() as SIGINT handler before other signal
218      * handlers are allowed to invoke postdrop_sig().
219      */
220     if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
221 	(void) signal(SIGQUIT, SIG_IGN);
222 	(void) signal(SIGTERM, SIG_IGN);
223 	(void) signal(SIGHUP, SIG_IGN);
224 	if (postdrop_path) {
225 	    (void) remove(postdrop_path);
226 	    postdrop_path = 0;
227 	}
228 	/* Future proofing. If you need exit() here then you broke Postfix. */
229 	if (sig)
230 	    _exit(sig);
231     }
232 }
233 
234 /* postdrop_cleanup - callback for the runtime error handler */
235 
postdrop_cleanup(void)236 static void postdrop_cleanup(void)
237 {
238     postdrop_sig(0);
239 }
240 
241 /* check_login_sender_acl - check if a user is authorized to use this sender */
242 
check_login_sender_acl(uid_t uid,VSTRING * sender_buf,VSTRING * reason)243 static int check_login_sender_acl(uid_t uid, VSTRING *sender_buf,
244 				          VSTRING *reason)
245 {
246     const char myname[] = "check_login_sender_acl";
247     struct mypasswd *user_info;
248     char   *user_name;
249     VSTRING *user_name_buf = 0;
250     LOGIN_SENDER_MATCH *lsm;
251     int     res;
252 
253     /*
254      * Sanity checks.
255      */
256     if (vstring_memchr(sender_buf, '\0') != 0) {
257 	vstring_sprintf(reason, "NUL in FROM record");
258 	return (CLEANUP_STAT_BAD);
259     }
260 
261     /*
262      * Optimization.
263      */
264 #ifndef SNAPSHOT
265     if (strcmp(var_local_login_snd_maps, DEF_LOCAL_LOGIN_SND_MAPS) == 0)
266 	return (CLEANUP_STAT_OK);
267 #endif
268 
269     /*
270      * Get the username.
271      */
272     if ((user_info = mypwuid(uid)) != 0) {
273 	user_name = user_info->pw_name;
274     } else {
275 	user_name_buf = vstring_alloc(10);
276 	vstring_sprintf(user_name_buf, "uid:%ld", (long) uid);
277 	user_name = vstring_str(user_name_buf);
278     }
279 
280 
281     /*
282      * Apply the a login-sender matcher. TODO: add DICT flags.
283      */
284     lsm = login_sender_create(VAR_LOCAL_LOGIN_SND_MAPS,
285 			      var_local_login_snd_maps,
286 			      var_rcpt_delim,
287 			      var_null_local_login_snd_maps_key, "*");
288     res = login_sender_match(lsm, user_name, vstring_str(sender_buf));
289     login_sender_free(lsm);
290     if (user_name_buf)
291 	vstring_free(user_name_buf);
292     switch (res) {
293     case LSM_STAT_FOUND:
294 	return (CLEANUP_STAT_OK);
295     case LSM_STAT_NOTFOUND:
296 	vstring_sprintf(reason, "not authorized to use sender='%s'",
297 			vstring_str(sender_buf));
298 	return (CLEANUP_STAT_NOPERM);
299     case LSM_STAT_RETRY:
300     case LSM_STAT_CONFIG:
301 	vstring_sprintf(reason, "%s table lookup error for '%s'",
302 			VAR_LOCAL_LOGIN_SND_MAPS, var_local_login_snd_maps);
303 	return (CLEANUP_STAT_WRITE);
304     default:
305 	msg_panic("%s: bad login_sender_match() result: %d", myname, res);
306     }
307 }
308 
309 MAIL_VERSION_STAMP_DECLARE;
310 
311 /* main - the main program */
312 
main(int argc,char ** argv)313 int     main(int argc, char **argv)
314 {
315     struct stat st;
316     int     fd;
317     int     c;
318     VSTRING *buf;
319     int     status = CLEANUP_STAT_OK;
320     VSTRING *reason = vstring_alloc(100);
321     MAIL_STREAM *dst;
322     int     rec_type;
323     static char *segment_info[] = {
324 	REC_TYPE_POST_ENVELOPE, REC_TYPE_POST_CONTENT, REC_TYPE_POST_EXTRACT, ""
325     };
326     char  **expected;
327     uid_t   uid = getuid();
328     ARGV   *import_env;
329     const char *error_text;
330     char   *attr_name;
331     char   *attr_value;
332     const char *errstr;
333     char   *junk;
334     struct timeval start;
335     int     saved_errno;
336     int     from_count = 0;
337     int     rcpt_count = 0;
338     int     validate_input = 1;
339 
340     /*
341      * Fingerprint executables and core dumps.
342      */
343     MAIL_VERSION_STAMP_ALLOCATE;
344 
345     /*
346      * Be consistent with file permissions.
347      */
348     umask(022);
349 
350     /*
351      * To minimize confusion, make sure that the standard file descriptors
352      * are open before opening anything else. XXX Work around for 44BSD where
353      * fstat can return EBADF on an open file descriptor.
354      */
355     for (fd = 0; fd < 3; fd++)
356 	if (fstat(fd, &st) == -1
357 	    && (close(fd), open("/dev/null", O_RDWR, 0)) != fd)
358 	    msg_fatal("open /dev/null: %m");
359 
360     /*
361      * Set up logging. Censor the process name: it is provided by the user.
362      */
363     argv[0] = "postdrop";
364     msg_vstream_init(argv[0], VSTREAM_ERR);
365     maillog_client_init(mail_task("postdrop"), MAILLOG_CLIENT_FLAG_NONE);
366     set_mail_conf_str(VAR_PROCNAME, var_procname = mystrdup(argv[0]));
367 
368     /*
369      * Check the Postfix library version as soon as we enable logging.
370      */
371     MAIL_VERSION_CHECK;
372 
373     /*
374      * Parse JCL. This program is set-gid and must sanitize all command-line
375      * arguments. The configuration directory argument is validated by the
376      * mail configuration read routine. Don't do complex things until we have
377      * completed initializations.
378      */
379     while ((c = GETOPT(argc, argv, "c:rv")) > 0) {
380 	switch (c) {
381 	case 'c':
382 	    if (setenv(CONF_ENV_PATH, optarg, 1) < 0)
383 		msg_fatal("out of memory");
384 	    break;
385 	case 'r':				/* forward compatibility */
386 	    break;
387 	case 'v':
388 	    if (geteuid() == 0)
389 		msg_verbose++;
390 	    break;
391 	default:
392 	    msg_fatal("usage: %s [-c config_dir] [-v]", argv[0]);
393 	}
394     }
395 
396     /*
397      * Read the global configuration file and extract configuration
398      * information.
399      */
400     mail_conf_read();
401     /* Re-evaluate mail_task() after reading main.cf. */
402     maillog_client_init(mail_task("postdrop"), MAILLOG_CLIENT_FLAG_NONE);
403     get_mail_conf_str_table(str_table);
404 
405     /*
406      * Stop run-away process accidents by limiting the queue file size. This
407      * is not a defense against DOS attack.
408      */
409     if (ENFORCING_SIZE_LIMIT(var_message_limit)
410 	&& get_file_limit() > var_message_limit)
411 	set_file_limit((off_t) var_message_limit);
412 
413     /*
414      * This program is installed with setgid privileges. Strip the process
415      * environment so that we don't have to trust the C library.
416      */
417     import_env = mail_parm_split(VAR_IMPORT_ENVIRON, var_import_environ);
418     clean_env(import_env->argv);
419     argv_free(import_env);
420 
421     if (chdir(var_queue_dir))
422 	msg_fatal("chdir %s: %m", var_queue_dir);
423     if (msg_verbose)
424 	msg_info("chdir %s", var_queue_dir);
425 
426     /*
427      * Set up signal handlers and a runtime error handler so that we can
428      * clean up incomplete output.
429      *
430      * postdrop_sig() uses the in-kernel SIGINT handler address as an atomic
431      * variable to prevent nested postdrop_sig() calls. For this reason, the
432      * SIGINT handler must be configured before other signal handlers are
433      * allowed to invoke postdrop_sig().
434      */
435     signal(SIGPIPE, SIG_IGN);
436     signal(SIGXFSZ, SIG_IGN);
437 
438     signal(SIGINT, postdrop_sig);
439     signal(SIGQUIT, postdrop_sig);
440     if (signal(SIGTERM, SIG_IGN) == SIG_DFL)
441 	signal(SIGTERM, postdrop_sig);
442     if (signal(SIGHUP, SIG_IGN) == SIG_DFL)
443 	signal(SIGHUP, postdrop_sig);
444     msg_cleanup(postdrop_cleanup);
445 
446     /* End of initializations. */
447 
448     /*
449      * Mail submission access control. Should this be in the user-land gate,
450      * or in the daemon process?
451      */
452     mail_dict_init();
453     if ((errstr = check_user_acl_byuid(VAR_SUBMIT_ACL, var_submit_acl,
454 				       uid)) != 0)
455 	msg_fatal("User %s(%ld) is not allowed to submit mail",
456 		  errstr, (long) uid);
457 
458     /*
459      * Don't trust the caller's time information.
460      */
461     GETTIMEOFDAY(&start);
462 
463     /*
464      * Create queue file. mail_stream_file() never fails. Send the queue ID
465      * to the caller. Stash away a copy of the queue file name so we can
466      * clean up in case of a fatal error or an interrupt.
467      */
468     dst = mail_stream_file(MAIL_QUEUE_MAILDROP, MAIL_CLASS_PUBLIC,
469 			   var_pickup_service, 0444);
470     attr_print(VSTREAM_OUT, ATTR_FLAG_NONE,
471 	       SEND_ATTR_STR(MAIL_ATTR_PROTO, MAIL_ATTR_PROTO_POSTDROP),
472 	       SEND_ATTR_STR(MAIL_ATTR_QUEUEID, dst->id),
473 	       ATTR_TYPE_END);
474     vstream_fflush(VSTREAM_OUT);
475     postdrop_path = mystrdup(VSTREAM_PATH(dst->stream));
476 
477     /*
478      * Copy stdin to file. The format is checked so that we can recognize
479      * incomplete input and cancel the operation. With the sanity checks
480      * applied here, the pickup daemon could skip format checks and pass a
481      * file descriptor to the cleanup daemon. These are by no means all
482      * sanity checks - the cleanup service and queue manager services will
483      * reject messages that lack required information.
484      *
485      * If something goes wrong, slurp up the input before responding to the
486      * client, otherwise the client will give up after detecting SIGPIPE.
487      *
488      * Allow attribute records if the attribute specifies the MIME body type
489      * (sendmail -B).
490      */
491     vstream_control(VSTREAM_IN, CA_VSTREAM_CTL_PATH("stdin"), CA_VSTREAM_CTL_END);
492     buf = vstring_alloc(100);
493     expected = segment_info;
494     /* Override time information from the untrusted caller. */
495     rec_fprintf(dst->stream, REC_TYPE_TIME, REC_TYPE_TIME_FORMAT,
496 		REC_TYPE_TIME_ARG(start));
497     for (;;) {
498 	/* Don't allow PTR records. */
499 	rec_type = rec_get_raw(VSTREAM_IN, buf, var_line_limit, REC_FLAG_NONE);
500 	if (rec_type == REC_TYPE_EOF) {		/* request cancelled */
501 	    mail_stream_cleanup(dst);
502 	    if (remove(postdrop_path))
503 		msg_warn("uid=%ld: remove %s: %m", (long) uid, postdrop_path);
504 	    else if (msg_verbose)
505 		msg_info("remove %s", postdrop_path);
506 	    myfree(postdrop_path);
507 	    postdrop_path = 0;
508 	    exit(0);
509 	}
510 	if (rec_type == REC_TYPE_ERROR)
511 	    msg_fatal("uid=%ld: malformed input", (long) uid);
512 	if (strchr(*expected, rec_type) == 0)
513 	    msg_fatal("uid=%ld: unexpected record type: %d", (long) uid, rec_type);
514 	if (rec_type == **expected)
515 	    expected++;
516 	/* Override time information from the untrusted caller. */
517 	if (rec_type == REC_TYPE_TIME)
518 	    continue;
519 	/* Check these at submission time instead of pickup time. */
520 	if (rec_type == REC_TYPE_FROM) {
521 	    status |= check_login_sender_acl(uid, buf, reason);
522 	    from_count++;
523 	}
524 	if (rec_type == REC_TYPE_RCPT)
525 	    rcpt_count++;
526 	/* Limit the attribute types that users may specify. */
527 	if (rec_type == REC_TYPE_ATTR) {
528 	    if ((error_text = split_nameval(vstring_str(buf), &attr_name,
529 					    &attr_value)) != 0) {
530 		msg_warn("uid=%ld: ignoring malformed record: %s: %.200s",
531 			 (long) uid, error_text, vstring_str(buf));
532 		continue;
533 	    }
534 #define STREQ(x,y) (strcmp(x,y) == 0)
535 
536 	    if ((STREQ(attr_name, MAIL_ATTR_ENCODING)
537 		 && (STREQ(attr_value, MAIL_ATTR_ENC_7BIT)
538 		     || STREQ(attr_value, MAIL_ATTR_ENC_8BIT)
539 		     || STREQ(attr_value, MAIL_ATTR_ENC_NONE)))
540 		|| STREQ(attr_name, MAIL_ATTR_DSN_ENVID)
541 		|| STREQ(attr_name, MAIL_ATTR_DSN_NOTIFY)
542 		|| rec_attr_map(attr_name)
543 		|| (STREQ(attr_name, MAIL_ATTR_RWR_CONTEXT)
544 		    && (STREQ(attr_value, MAIL_ATTR_RWR_LOCAL)
545 			|| STREQ(attr_value, MAIL_ATTR_RWR_REMOTE)))
546 		|| STREQ(attr_name, MAIL_ATTR_TRACE_FLAGS)) {	/* XXX */
547 		rec_fprintf(dst->stream, REC_TYPE_ATTR, "%s=%s",
548 			    attr_name, attr_value);
549 	    } else {
550 		msg_warn("uid=%ld: ignoring attribute record: %.200s=%.200s",
551 			 (long) uid, attr_name, attr_value);
552 	    }
553 	    continue;
554 	}
555 	if (status != CLEANUP_STAT_OK
556 	    || REC_PUT_BUF(dst->stream, rec_type, buf) < 0) {
557 	    /* rec_get() errors must not clobber errno. */
558 	    saved_errno = errno;
559 	    while ((rec_type = rec_get_raw(VSTREAM_IN, buf, var_line_limit,
560 					   REC_FLAG_NONE)) != REC_TYPE_END
561 		   && rec_type != REC_TYPE_EOF)
562 		if (rec_type == REC_TYPE_ERROR)
563 		    msg_fatal("uid=%ld: malformed input", (long) uid);
564 	    validate_input = 0;
565 	    errno = saved_errno;
566 	    break;
567 	}
568 	if (rec_type == REC_TYPE_END)
569 	    break;
570     }
571     vstring_free(buf);
572 
573     /*
574      * As of Postfix 2.7 the pickup daemon discards mail without recipients.
575      * Such mail may enter the maildrop queue when "postsuper -r" is invoked
576      * before the queue manager deletes an already delivered message. Looking
577      * at file ownership is not a good way to make decisions on what mail to
578      * discard. Instead, the pickup server now requires that new submissions
579      * always have at least one recipient record.
580      *
581      * The Postfix sendmail command already rejects mail without recipients.
582      * However, in the future postdrop may receive mail via other programs,
583      * so we add a redundant recipient check here for future proofing.
584      *
585      * The test for the sender address is just for consistency of error
586      * reporting (report at submission time instead of pickup time). Besides
587      * the segment terminator records, there aren't any other mandatory
588      * records in a Postfix submission queue file.
589      *
590      * TODO: return an informative reason for missing sender, too many senders,
591      * or missing recipient.
592      */
593     if (validate_input && (from_count == 0 || rcpt_count == 0))
594 	status |= CLEANUP_STAT_BAD;
595     if (status != CLEANUP_STAT_OK) {
596 	mail_stream_cleanup(dst);
597     }
598 
599     /*
600      * Finish the file.
601      */
602     else if ((status = mail_stream_finish(dst, reason)) != 0) {
603 	msg_warn("uid=%ld: %m", (long) uid);
604 	postdrop_cleanup();
605     }
606 
607     /*
608      * Disable deletion on fatal error before reporting success, so the file
609      * will not be deleted after we have taken responsibility for delivery.
610      */
611     if (postdrop_path) {
612 	junk = postdrop_path;
613 	postdrop_path = 0;
614 	myfree(junk);
615     }
616 
617     /*
618      * Send the completion status to the caller and terminate.
619      */
620     attr_print(VSTREAM_OUT, ATTR_FLAG_NONE,
621 	       SEND_ATTR_INT(MAIL_ATTR_STATUS, status),
622 	       SEND_ATTR_STR(MAIL_ATTR_WHY, status != CLEANUP_STAT_OK
623 			     && VSTRING_LEN(reason) > 0 ?
624 			     vstring_str(reason) : ""),
625 	       ATTR_TYPE_END);
626     vstream_fflush(VSTREAM_OUT);
627     exit(status);
628 }
629