Track tainted data and refuse to expand it
[exim.git] / src / src / moan.c
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) University of Cambridge 1995 - 2018 */
6 /* See the file NOTICE for conditions of use and distribution. */
7
8 /* Functions for sending messages to sender or to mailmaster. */
9
10
11 #include "exim.h"
12
13
14
15 /*************************************************
16 *            Write From: line for DSN            *
17 *************************************************/
18
19 /* This function is called to write the From: line in automatically generated
20 messages - bounces, warnings, etc. It expands a configuration item in order to
21 get the text. If the expansion fails, a panic is logged and the default value
22 for the option is used.
23
24 Argument:   the FILE to write to
25 Returns:    nothing
26 */
27
28 void
29 moan_write_from(FILE *f)
30 {
31 uschar *s = expand_string(dsn_from);
32 if (!s)
33   {
34   log_write(0, LOG_MAIN|LOG_PANIC,
35     "Failed to expand dsn_from (using default): %s", expand_string_message);
36   s = expand_string(US DEFAULT_DSN_FROM);
37   }
38 fprintf(f, "From: %s\n", s);
39 }
40
41
42
43 /*************************************************
44 *              Send error message                *
45 *************************************************/
46
47 /* This function sends an error message by opening a pipe to a new process
48 running Exim, and writing a message to it using the "-t" option. This is not
49 used for delivery failures, which have their own code for handing failed
50 addresses.
51
52 Arguments:
53   recipient      addressee for the message
54   ident          identifies the type of error
55   eblock         chain of error_blocks containing data about the error
56   headers        the message's headers
57   message_file   FILE containing the body of the message
58   firstline      contains first line of file, if it was read to check for
59                    "From ", but it turned out not to be
60
61 Returns:         TRUE if message successfully sent
62 */
63
64 BOOL
65 moan_send_message(uschar *recipient, int ident, error_block *eblock,
66   header_line *headers, FILE *message_file, uschar *firstline)
67 {
68 int written = 0;
69 int fd;
70 int status;
71 int count = 0;
72 int size_limit = bounce_return_size_limit;
73 FILE * fp;
74 int pid;
75
76 #ifdef EXPERIMENTAL_DMARC
77 uschar * s, * s2;
78
79 /* For DMARC if there is a specific sender set, expand the variable for the
80 header From: and grab the address from that for the envelope FROM. */
81
82 if (  ident == ERRMESS_DMARC_FORENSIC
83    && dmarc_forensic_sender
84    && (s = expand_string(dmarc_forensic_sender))
85    && *s
86    && (s2 = expand_string(string_sprintf("${address:%s}", s)))
87    && *s2
88    )
89   pid = child_open_exim2(&fd, s2, bounce_sender_authentication);
90 else
91   {
92   s = NULL;
93   pid = child_open_exim(&fd);
94   }
95
96 #else
97 pid = child_open_exim(&fd);
98 #endif
99
100 if (pid < 0)
101   {
102   DEBUG(D_any) debug_printf("Failed to create child to send message: %s\n",
103     strerror(errno));
104   return FALSE;
105   }
106 else DEBUG(D_any) debug_printf("Child process %d for sending message\n", pid);
107
108 /* Creation of child succeeded */
109
110 fp = fdopen(fd, "wb");
111 if (errors_reply_to) fprintf(fp, "Reply-To: %s\n", errors_reply_to);
112 fprintf(fp, "Auto-Submitted: auto-replied\n");
113
114 #ifdef EXPERIMENTAL_DMARC
115 if (s)
116   fprintf(fp, "From: %s\n", s);
117 else
118 #endif
119   moan_write_from(fp);
120
121 fprintf(fp, "To: %s\n", recipient);
122
123 switch(ident)
124   {
125   case ERRMESS_BADARGADDRESS:
126     fprintf(fp,
127       "Subject: Mail failure - malformed recipient address\n\n");
128     fprintf(fp,
129       "A message that you sent contained a recipient address that was incorrectly\n"
130       "constructed:\n\n");
131     fprintf(fp, "  %s  %s\n", eblock->text1, eblock->text2);
132     count = Ustrlen(eblock->text1);
133     if (count > 0 && eblock->text1[count-1] == '.')
134       fprintf(fp,
135         "\nRecipient addresses must not end with a '.' character.\n");
136     fprintf(fp,
137       "\nThe message has not been delivered to any recipients.\n");
138     break;
139
140   case ERRMESS_BADNOADDRESS:
141   case ERRMESS_BADADDRESS:
142     fprintf(fp,
143       "Subject: Mail failure - malformed recipient address\n\n");
144     fprintf(fp,
145       "A message that you sent contained one or more recipient addresses that were\n"
146       "incorrectly constructed:\n\n");
147
148     while (eblock != NULL)
149       {
150       fprintf(fp, "  %s: %s\n", eblock->text1, eblock->text2);
151       count++;
152       eblock = eblock->next;
153       }
154
155     fprintf(fp, (count == 1)? "\nThis address has been ignored. " :
156       "\nThese addresses have been ignored. ");
157
158     fprintf(fp, (ident == ERRMESS_BADADDRESS)?
159       "The other addresses in the message were\n"
160       "syntactically valid and have been passed on for an attempt at delivery.\n" :
161
162       "There were no other addresses in your\n"
163       "message, and so no attempt at delivery was possible.\n");
164     break;
165
166   case ERRMESS_IGADDRESS:
167     fprintf(fp, "Subject: Mail failure - no recipient addresses\n\n");
168     fprintf(fp,
169       "A message that you sent using the -t command line option contained no\n"
170       "addresses that were not also on the command line, and were therefore\n"
171       "suppressed. This left no recipient addresses, and so no delivery could\n"
172       "be attempted.\n");
173     break;
174
175   case ERRMESS_NOADDRESS:
176     fprintf(fp, "Subject: Mail failure - no recipient addresses\n\n");
177     fprintf(fp,
178       "A message that you sent contained no recipient addresses, and therefore no\n"
179       "delivery could be attempted.\n");
180     break;
181
182   case ERRMESS_IOERR:
183     fprintf(fp, "Subject: Mail failure - system failure\n\n");
184     fprintf(fp,
185       "A system failure was encountered while processing a message that you sent,\n"
186       "so it has not been possible to deliver it. The error was:\n\n%s\n",
187       eblock->text1);
188     break;
189
190   case ERRMESS_VLONGHEADER:
191     fprintf(fp, "Subject: Mail failure - overlong header section\n\n");
192     fprintf(fp,
193       "A message that you sent contained a header section that was excessively\n"
194       "long and could not be handled by the mail transmission software. The\n"
195       "message has not been delivered to any recipients.\n");
196     break;
197
198   case ERRMESS_VLONGHDRLINE:
199     fprintf(fp, "Subject: Mail failure - overlong header line\n\n");
200     fprintf(fp,
201       "A message that you sent contained a header line that was excessively\n"
202       "long and could not be handled by the mail transmission software. The\n"
203       "message has not been delivered to any recipients.\n");
204     break;
205
206   case ERRMESS_TOOBIG:
207     fprintf(fp, "Subject: Mail failure - message too big\n\n");
208     fprintf(fp,
209       "A message that you sent was longer than the maximum size allowed on this\n"
210       "system. It was not delivered to any recipients.\n");
211     break;
212
213   case ERRMESS_TOOMANYRECIP:
214     fprintf(fp, "Subject: Mail failure - too many recipients\n\n");
215     fprintf(fp,
216       "A message that you sent contained more recipients than allowed on this\n"
217       "system. It was not delivered to any recipients.\n");
218     break;
219
220   case ERRMESS_LOCAL_SCAN:
221   case ERRMESS_LOCAL_ACL:
222     fprintf(fp, "Subject: Mail failure - rejected by local scanning code\n\n");
223     fprintf(fp,
224       "A message that you sent was rejected by the local scanning code that\n"
225       "checks incoming messages on this system.");
226       if (eblock->text1)
227         fprintf(fp, " The following error was given:\n\n  %s", eblock->text1);
228   fprintf(fp, "\n");
229   break;
230
231 #ifdef EXPERIMENTAL_DMARC
232   case ERRMESS_DMARC_FORENSIC:
233     bounce_return_message = TRUE;
234     bounce_return_body    = FALSE;
235     fprintf(fp, "Subject: DMARC Forensic Report for %s from IP %s\n\n",
236           eblock ? eblock->text2 : US"Unknown",
237           sender_host_address);
238     fprintf(fp,
239       "A message claiming to be from you has failed the published DMARC\n"
240       "policy for your domain.\n\n");
241     while (eblock)
242       {
243       fprintf(fp, "  %s: %s\n", eblock->text1, eblock->text2);
244       count++;
245       eblock = eblock->next;
246       }
247   break;
248 #endif
249
250   default:
251     fprintf(fp, "Subject: Mail failure\n\n");
252     fprintf(fp,
253       "A message that you sent has caused the error routine to be entered with\n"
254       "an unknown error number (%d).\n", ident);
255     break;
256   }
257
258 /* Now, if configured, copy the message; first the headers and then the rest of
259 the input if available, up to the configured limit, if the option for including
260 message bodies in bounces is set. */
261
262 if (bounce_return_message)
263   {
264   if (bounce_return_body)
265     {
266     fprintf(fp, "\n"
267       "------ This is a copy of your message, including all the headers.");
268     if (size_limit == 0 || size_limit > thismessage_size_limit)
269       size_limit = thismessage_size_limit;
270     if (size_limit > 0 && size_limit < message_size)
271       {
272       int x = size_limit;
273       uschar *k = US"";
274       if ((x & 1023) == 0)
275         {
276         k = US"K";
277         x >>= 10;
278         }
279       fprintf(fp, "\n"
280         "------ No more than %d%s characters of the body are included.\n\n",
281           x, k);
282       }
283     else fprintf(fp, " ------\n\n");
284     }
285   else
286     {
287     fprintf(fp, "\n"
288       "------ This is a copy of the headers that were received before the "
289       "error\n       was detected.\n\n");
290     }
291
292   /* If the error occurred before the Received: header was created, its text
293   field will still be NULL; just omit such a header line. */
294
295   while (headers)
296     {
297     if (headers->text != NULL) fprintf(fp, "%s", CS headers->text);
298     headers = headers->next;
299     }
300
301   if (ident != ERRMESS_VLONGHEADER && ident != ERRMESS_VLONGHDRLINE)
302     fputc('\n', fp);
303
304   /* After early detection of an error, the message file may be STDIN,
305   in which case we might have to terminate on a line containing just "."
306   as well as on EOF. We may already have the first line in memory. */
307
308   if (bounce_return_body && message_file)
309     {
310     BOOL enddot = f.dot_ends && message_file == stdin;
311     uschar * buf = store_get(bounce_return_linesize_limit+2, TRUE);
312
313     if (firstline) fprintf(fp, "%s", CS firstline);
314
315     while (fgets(CS buf, bounce_return_linesize_limit+2, message_file))
316       {
317       int len;
318
319       if (enddot && *buf == '.' && buf[1] == '\n')
320         {
321         fputc('.', fp);
322         break;
323         }
324
325       len = Ustrlen(buf);
326       if (buf[len-1] != '\n')
327         {       /* eat rest of partial line */
328         int ch;
329         while ((ch = fgetc(message_file)) != EOF && ch != '\n') ;
330         }
331
332       if (size_limit > 0 && len > size_limit - written)
333         {
334         buf[size_limit - written] = '\0';
335         fputs(CS buf, fp);
336         break;
337         }
338
339       fputs(CS buf, fp);
340       }
341     }
342 #ifdef EXPERIMENTAL_DMARC
343   /* Overkill, but use exact test in case future code gets inserted */
344   else if (bounce_return_body && message_file == NULL)
345     {
346     /*XXX limit line length here? */
347     /* This doesn't print newlines, disable until can parse and fix
348      * output to be legible.  */
349     fprintf(fp, "%s", expand_string(US"$message_body"));
350     }
351 #endif
352   }
353 /* Close the file, which should send an EOF to the child process
354 that is receiving the message. Wait for it to finish, without a timeout. */
355
356 (void)fclose(fp);
357 status = child_close(pid, 0);  /* Waits for child to close */
358 if (status != 0)
359   {
360   uschar *msg = US"Child mail process returned status";
361   if (status == -257)
362     log_write(0, LOG_MAIN, "%s %d: errno=%d: %s", msg, status, errno,
363       strerror(errno));
364   else
365     log_write(0, LOG_MAIN, "%s %d", msg, status);
366   return FALSE;
367   }
368
369 return TRUE;
370 }
371
372
373
374 /*************************************************
375 *          Send message to sender                *
376 *************************************************/
377
378 /* This function is called when errors are detected during the receipt of a
379 message. Delivery failures are handled separately in deliver.c.
380
381 If there is a valid sender_address, and the failing message is not a local
382 error message, then this function calls moan_send_message to send a message to
383 that person. If the sender's address is null, then an error has occurred with a
384 message that was generated by a mailer daemon. All we can do is to write
385 information to log files. The same action is taken if local_error_message is
386 set - this can happen for non null-senders in certain configurations where exim
387 doesn't run setuid root.
388
389 Arguments:
390   ident         identifies the particular error
391   eblock        chain of error_blocks containing data about the error
392   headers       message's headers (chain)
393   message_file  a FILE where the body of the message can be read
394   check_sender  if TRUE, read the first line of the file for a possible
395                   "From " sender (if a trusted caller)
396
397 Returns:        FALSE if there is no sender_address to send to;
398                 else the return from moan_send_message()
399 */
400
401 BOOL
402 moan_to_sender(int ident, error_block *eblock, header_line *headers,
403   FILE *message_file, BOOL check_sender)
404 {
405 uschar *firstline = NULL;
406 uschar *msg = US"Error while reading message with no usable sender address";
407
408 if (message_reference)
409   msg = string_sprintf("%s (R=%s)", msg, message_reference);
410
411 /* Find the sender from a From line if permitted and possible */
412
413 if (check_sender && message_file && f.trusted_caller &&
414     Ufgets(big_buffer, BIG_BUFFER_SIZE, message_file) != NULL)
415   {
416   uschar *new_sender = NULL;
417   if (regex_match_and_setup(regex_From, big_buffer, 0, -1))
418     new_sender = expand_string(uucp_from_sender);
419   if (new_sender) sender_address = new_sender;
420     else firstline = big_buffer;
421   }
422
423 /* If viable sender address, send a message */
424
425 if (sender_address && sender_address[0] && !f.local_error_message)
426   return moan_send_message(sender_address, ident, eblock, headers,
427     message_file, firstline);
428
429 /* Otherwise, we can only log */
430
431 switch(ident)
432   {
433   case ERRMESS_BADARGADDRESS:
434   case ERRMESS_BADNOADDRESS:
435   case ERRMESS_BADADDRESS:
436   log_write(0, LOG_MAIN, "%s: at least one malformed recipient address: "
437     "%s - %s", msg, eblock->text1, eblock->text2);
438   break;
439
440   case ERRMESS_IGADDRESS:
441   case ERRMESS_NOADDRESS:
442   log_write(0, LOG_MAIN, "%s: no recipient addresses", msg);
443   break;
444
445   /* This error has already been logged. */
446   case ERRMESS_IOERR:
447   break;
448
449   case ERRMESS_VLONGHEADER:
450   log_write(0, LOG_MAIN, "%s: excessively long message header section read "
451     "(more than %d characters)", msg, header_maxsize);
452   break;
453
454   case ERRMESS_VLONGHDRLINE:
455   log_write(0, LOG_MAIN, "%s: excessively long message header line read "
456     "(more than %d characters)", msg, header_line_maxsize);
457   break;
458
459   case ERRMESS_TOOBIG:
460   log_write(0, LOG_MAIN, "%s: message too big (limit set to %d)", msg,
461     thismessage_size_limit);
462   break;
463
464   case ERRMESS_TOOMANYRECIP:
465   log_write(0, LOG_MAIN, "%s: too many recipients (max set to %d)", msg,
466     recipients_max);
467   break;
468
469   case ERRMESS_LOCAL_SCAN:
470   log_write(0, LOG_MAIN, "%s: rejected by local_scan: %s", msg, eblock->text1);
471   break;
472
473   case ERRMESS_LOCAL_ACL:
474   log_write(0, LOG_MAIN, "%s: rejected by non-SMTP ACL: %s", msg, eblock->text1);
475   break;
476
477   default:
478   log_write(0, LOG_MAIN|LOG_PANIC, "%s: unknown error number %d", msg,
479     ident);
480   break;
481   }
482
483 return FALSE;
484 }
485
486
487
488 /*************************************************
489 *            Send message to someone             *
490 *************************************************/
491
492 /* This is called when exim is configured to tell someone (often the
493 mailmaster) about some incident.
494
495 Arguments:
496   who           address to send mail to
497   addr          chain of deferred addresses whose details are to be included
498   subject       subject text for the message
499   format        a printf() format for the body of the message
500   ...           arguments for the format
501
502 Returns:        nothing
503 */
504
505 void
506 moan_tell_someone(uschar *who, address_item *addr,
507   const uschar *subject, const char *format, ...)
508 {
509 FILE *f;
510 va_list ap;
511 int fd;
512 int pid = child_open_exim(&fd);
513
514 if (pid < 0)
515   {
516   DEBUG(D_any) debug_printf("Failed to create child to send message: %s\n",
517     strerror(errno));
518   return;
519   }
520
521 f = fdopen(fd, "wb");
522 fprintf(f, "Auto-Submitted: auto-replied\n");
523 moan_write_from(f);
524 fprintf(f, "To: %s\n", who);
525 fprintf(f, "Subject: %s\n\n", subject);
526 va_start(ap, format);
527 vfprintf(f, format, ap);
528 va_end(ap);
529
530 if (addr)
531   {
532   fprintf(f, "\nThe following address(es) have yet to be delivered:\n");
533   for (; addr; addr = addr->next)
534     {
535     uschar * parent = addr->parent ? addr->parent->address : NULL;
536     fprintf(f, "  %s", addr->address);
537     if (parent) fprintf(f, " <%s>", parent);
538     if (addr->basic_errno > 0) fprintf(f, ": %s", strerror(addr->basic_errno));
539     if (addr->message) fprintf(f, ": %s", addr->message);
540     fprintf(f, "\n");
541     }
542   }
543
544 (void)fclose(f);
545 child_close(pid, 0);  /* Waits for child to close; no timeout */
546 }
547
548
549
550 /*************************************************
551 *            Handle SMTP batch error             *
552 *************************************************/
553
554 /* This is called when something goes wrong in batched (-bS) SMTP input.
555 Information is written to stdout and/or stderr, and Exim exits with a non-zero
556 completion code. BSMTP is almost always called by some other program, so it is
557 up to that program to interpret the return code and do something with the error
558 information, and also to preserve the batch input file for human analysis.
559
560 Formerly, Exim used to attempt to continue after some errors, but this strategy
561 has been abandoned as it can lead to loss of messages.
562
563 Arguments:
564   cmd_buffer   the command causing the error, or NULL
565   format       a printf() format
566   ...          arguments for the format
567
568 Returns:       does not return; exits from the program
569                exit code = 1 if some messages were accepted
570                exit code = 2 if no messages were accepted
571 */
572
573 void
574 moan_smtp_batch(uschar *cmd_buffer, const char *format, ...)
575 {
576 va_list ap;
577 int yield = (receive_messagecount > 0)? 1 : 2;
578
579 DEBUG(D_any) debug_printf("Handling error in batched SMTP input\n");
580
581 /* On stdout, write stuff that a program could parse fairly easily. */
582
583 va_start(ap, format);
584 vfprintf(stdout, format, ap);
585 va_end(ap);
586
587 fprintf(stdout, "\nTransaction started in line %d\n",
588   bsmtp_transaction_linecount);
589 fprintf(stdout,   "Error detected in line %d\n", receive_linecount);
590 if (cmd_buffer != NULL) fprintf(stdout, "%s\n", cmd_buffer);
591
592 /* On stderr, write stuff for human consumption */
593
594 fprintf(stderr,
595   "An error was detected while processing a file of BSMTP input.\n"
596   "The error message was:\n\n  ");
597
598 va_start(ap, format);
599 vfprintf(stderr, format, ap);
600 va_end(ap);
601
602 fprintf(stderr,
603   "\n\nThe SMTP transaction started in line %d.\n"
604       "The error was detected in line %d.\n",
605   bsmtp_transaction_linecount, receive_linecount);
606
607 if (cmd_buffer != NULL)
608   {
609   fprintf(stderr, "The SMTP command at fault was:\n\n   %s\n\n",
610     cmd_buffer);
611   }
612
613 fprintf(stderr, "%d previous message%s successfully processed.\n",
614   receive_messagecount, (receive_messagecount == 1)? " was" : "s were");
615
616 fprintf(stderr, "The rest of the batch was abandoned.\n");
617
618 exim_exit(yield, US"batch");
619 }
620
621
622
623
624 /*************************************************
625 *         Check for error copies                 *
626 *************************************************/
627
628 /* This function is passed the recipient of an error message, and must check
629 the error_copies string to see whether there is an additional recipient list to
630 which errors for this recipient must be bcc'd. The incoming recipient is always
631 fully qualified.
632
633 Argument:   recipient address
634 Returns:    additional recipient list or NULL
635 */
636
637 uschar *
638 moan_check_errorcopy(uschar *recipient)
639 {
640 uschar *item, *localpart, *domain;
641 const uschar *listptr = errors_copy;
642 uschar *yield = NULL;
643 uschar buffer[256];
644 int sep = 0;
645 int llen;
646
647 if (errors_copy == NULL) return NULL;
648
649 /* Set up pointer to the local part and domain, and compute the
650 length of the local part. */
651
652 localpart = recipient;
653 domain = Ustrrchr(recipient, '@');
654 if (domain == NULL) return NULL;  /* should not occur, but avoid crash */
655 llen = domain++ - recipient;
656
657 /* Scan through the configured items */
658
659 while ((item = string_nextinlist(&listptr, &sep, buffer, sizeof(buffer)))
660        != NULL)
661   {
662   const uschar *newaddress = item;
663   const uschar *pattern = string_dequote(&newaddress);
664
665   /* If no new address found, just skip this item. */
666
667   while (isspace(*newaddress)) newaddress++;
668   if (*newaddress == 0) continue;
669
670   /* We now have an item to match as an address in item, and the additional
671   address in newaddress. If the pattern matches, expand the new address string
672   and return it. During expansion, make local part and domain available for
673   insertion. This requires a copy to be made; we can't just temporarily
674   terminate it, as the whole address is required for $0. */
675
676   if (match_address_list(recipient, TRUE, TRUE, &pattern, NULL, 0, UCHAR_MAX+1,
677         NULL) == OK)
678     {
679     deliver_localpart = string_copyn(localpart, llen);
680     deliver_domain = domain;
681     yield = expand_string_copy(newaddress);
682     deliver_domain = deliver_localpart = NULL;
683     if (yield == NULL)
684       log_write(0, LOG_MAIN|LOG_PANIC, "Failed to expand %s when processing "
685         "errors_copy: %s", newaddress, expand_string_message);
686     break;
687     }
688   }
689
690 DEBUG(D_any) debug_printf("errors_copy check returned %s\n",
691   (yield == NULL)? US"NULL" : yield);
692
693 expand_nmax = -1;
694 return yield;
695 }
696
697
698
699 /************************************************
700 *        Handle skipped syntax errors           *
701 ************************************************/
702
703 /* This function is called by the redirect router when it has skipped over one
704 or more syntax errors in the list of addresses. If there is an address to mail
705 to, send a message, and always write the information to the log. In the case of
706 a filter file, a "syntax error" might actually be something else, such as the
707 inability to open a log file. Thus, the wording of the error message is
708 general.
709
710 Arguments:
711   rname             the router name
712   eblock            chain of error blocks
713   syntax_errors_to  address to send mail to, or NULL
714   some              TRUE if some addresses were generated; FALSE if none were
715   custom            custom message text
716
717 Returns:            FALSE if string expansion failed; TRUE otherwise
718 */
719
720 BOOL
721 moan_skipped_syntax_errors(uschar *rname, error_block *eblock,
722   uschar *syntax_errors_to, BOOL some, uschar *custom)
723 {
724 int pid, fd;
725 uschar *s, *t;
726 FILE *f;
727
728 for (error_block * e = eblock; e; e = e->next)
729   if (e->text2 != NULL)
730     log_write(0, LOG_MAIN, "%s router: skipped error: %s in \"%s\"",
731       rname, e->text1, e->text2);
732   else
733     log_write(0, LOG_MAIN, "%s router: skipped error: %s", rname,
734       e->text1);
735
736 if (!syntax_errors_to) return TRUE;
737
738 if (!(s = expand_string(syntax_errors_to)))
739   {
740   log_write(0, LOG_MAIN, "%s router failed to expand %s: %s", rname,
741     syntax_errors_to, expand_string_message);
742   return FALSE;
743   }
744
745 /* If we can't create a process to send the message, just forget about
746 it. */
747
748 pid = child_open_exim(&fd);
749
750 if (pid < 0)
751   {
752   DEBUG(D_any) debug_printf("Failed to create child to send message: %s\n",
753     strerror(errno));
754   return TRUE;
755   }
756
757 f = fdopen(fd, "wb");
758 fprintf(f, "Auto-Submitted: auto-replied\n");
759 moan_write_from(f);
760 fprintf(f, "To: %s\n", s);
761 fprintf(f, "Subject: error(s) in forwarding or filtering\n\n");
762
763 if (custom)
764   {
765   if (!(t = expand_string(custom)))
766     {
767     log_write(0, LOG_MAIN, "%s router failed to expand %s: %s", rname,
768       custom, expand_string_message);
769     return FALSE;
770     }
771   fprintf(f, "%s\n\n", t);
772   }
773
774 fprintf(f, "The %s router encountered the following error(s):\n\n",
775   rname);
776
777 for (error_block * e = eblock; e; e = e->next)
778   {
779   fprintf(f, "  %s", e->text1);
780   if (e->text2 != NULL)
781     fprintf(f, " in the address\n  \"%s\"", e->text2);
782   fprintf(f, "\n\n");
783   }
784
785 if (some)
786   fprintf(f, "Other addresses were processed normally.\n");
787 else
788   fprintf(f, "No valid addresses were generated.\n");
789
790 (void)fclose(f);
791 child_close(pid, 0);  /* Waits for child to close; no timeout */
792
793 return TRUE;
794 }
795
796 /* End of moan.c */