~ubuntu-branches/ubuntu/raring/postfix/raring

« back to all changes in this revision

Viewing changes to src/sendmail/sendmail.c

Tags: upstream-2.2.6
ImportĀ upstreamĀ versionĀ 2.2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
/*      \fBnewaliases\fR
13
13
/*      \fBsendmail -I\fR
14
14
/* DESCRIPTION
15
 
/*      The Postfix \fBsendmail\fR command implements the Postfix to Sendmail
16
 
/*      compatibility interface.
 
15
/*      The Postfix \fBsendmail\fR(1) command implements the Postfix
 
16
/*      to Sendmail compatibility interface.
17
17
/*      For the sake of compatibility with existing applications, some
18
18
/*      Sendmail command-line options are recognized but silently ignored.
19
19
/*
20
 
/*      By default, Postfix \fBsendmail\fR reads a message from standard input
 
20
/*      By default, Postfix \fBsendmail\fR(1) reads a message from
 
21
/*      standard input
21
22
/*      until EOF or until it reads a line with only a \fB.\fR character,
22
 
/*      and arranges for delivery.  Postfix \fBsendmail\fR relies on the
 
23
/*      and arranges for delivery.  Postfix \fBsendmail\fR(1) relies on the
23
24
/*      \fBpostdrop\fR(1) command to create a queue file in the \fBmaildrop\fR
24
25
/*      directory.
25
26
/*
41
42
/*      command.
42
43
/* .sp
43
44
/*      Note: it may take a minute or so before an alias database update
44
 
/*      becomes visible. Use the \fBpostfix reload\fR command to eliminate
 
45
/*      becomes visible. Use the "\fBpostfix reload\fR" command to eliminate
45
46
/*      this delay.
46
47
/* .PP
47
48
/*      These and other features can be selected by specifying the
57
58
/*      The message body MIME type: \fB7BIT\fR or \fB8BITMIME\fR.
58
59
/* .IP \fB-bd\fR
59
60
/*      Go into daemon mode. This mode of operation is implemented by
60
 
/*      executing the \fBpostfix start\fR command.
 
61
/*      executing the "\fBpostfix start\fR" command.
61
62
/* .IP "\fB-bh\fR (ignored)"
62
63
/* .IP "\fB-bH\fR (ignored)"
63
64
/*      Postfix has no persistent host status database.
92
93
/*      have no \fBFrom:\fR message header.
93
94
/* .IP "\fB-f \fIsender\fR"
94
95
/*      Set the envelope sender address. This is the address where
95
 
/*      delivery problems are sent to, unless the message contains an
96
 
/*      \fBErrors-To:\fR message header.
 
96
/*      delivery problems are sent to. With Postfix versions before 2.1, the
 
97
/*      \fBErrors-To:\fR message header overrides the error return address.
97
98
/* .IP "\fB-G\fR (ignored)"
98
99
/*      Gateway (relay) submission, as opposed to initial user submission.
99
100
/* .IP "\fB-h \fIhop_count\fR (ignored)"
119
120
/*      Non-default alias database. Specify \fIpathname\fR or
120
121
/*      \fItype\fR:\fIpathname\fR. See \fBpostalias\fR(1) for
121
122
/*      details.
 
123
/* .IP "\fB-O \fIoption=value\fR (ignored)"
 
124
/*      Backwards compatibility.
122
125
/* .IP "\fB-o7\fR (ignored)"
123
126
/* .IP "\fB-o8\fR (ignored)"
124
127
/*      To send 8-bit or binary content, use an appropriate MIME encapsulation
133
136
/*      configuration parameter in \fBmain.cf\fR instead.
134
137
/* .IP "\fB-r \fIsender\fR"
135
138
/*      Set the envelope sender address. This is the address where
136
 
/*      delivery problems are sent to, unless the message contains an
137
 
/*      \fBErrors-To:\fR message header.
 
139
/*      delivery problems are sent to. With Postfix versions before 2.1, the
 
140
/*      \fBErrors-To:\fR message header overrides the error return address.
138
141
/* .IP "\fB-R \fIreturn_limit\fR (ignored)"
139
142
/*      Limit the size of bounced mail. Use the \fBbounce_size_limit\fR
140
143
/*      configuration parameter instead.
155
158
/*      See \fBflush\fR(8) for more information about the "fast flush"
156
159
/*      service.
157
160
/* .IP \fB-qS\fIsite\fR
158
 
/*      This command is not implemented. Use the slower \fBsendmail -q\fR
 
161
/*      This command is not implemented. Use the slower "\fBsendmail -q\fR"
159
162
/*      command instead.
160
163
/* .IP \fB-t\fR
161
164
/*      Extract recipients from message headers. These are added to any
215
218
/*      The following \fBmain.cf\fR parameters are especially relevant to
216
219
/*      this program.
217
220
/*      The text below provides only a parameter summary. See
218
 
/*      postconf(5) for more details including examples.
 
221
/*      \fBpostconf\fR(5) for more details including examples.
219
222
/* TROUBLE SHOOTING CONTROLS
220
223
/* .ad
221
224
/* .fi
231
234
/*      Optional list of remote client or server hostname or network
232
235
/*      address patterns that cause the verbose logging level to increase
233
236
/*      by the amount specified in $debug_peer_level.
 
237
/* ACCESS CONTROLS
 
238
/* .ad
 
239
/* .fi
 
240
/*      Available in Postfix version 2.2 and later:
 
241
/* .IP "\fBauthorized_flush_users (static:anyone)\fR"
 
242
/*      List of users who are authorized to flush the queue.
 
243
/* .IP "\fBauthorized_mailq_users (static:anyone)\fR"
 
244
/*      List of users who are authorized to view the queue.
 
245
/* .IP "\fBauthorized_submit_users (static:anyone)\fR"
 
246
/*      List of users who are authorized to submit mail with the \fBsendmail\fR(1)
 
247
/*      command (and with the privileged \fBpostdrop\fR(1) helper command).
234
248
/* RESOURCE AND RATE CONTROLS
235
249
/* .ad
236
250
/* .fi
264
278
/*      The two default VERP delimiter characters.
265
279
/* .IP "\fBverp_delimiter_filter (-=+)\fR"
266
280
/*      The characters Postfix accepts as VERP delimiter characters on the
267
 
/*      Postfix sendmail(1) command line and in SMTP commands.
 
281
/*      Postfix \fBsendmail\fR(1) command line and in SMTP commands.
268
282
/* MISCELLANEOUS CONTROLS
269
283
/* .ad
270
284
/* .fi
271
285
/* .IP "\fBalias_database (see 'postconf -d' output)\fR"
272
 
/*      The alias databases for local(8) delivery that are updated with
 
286
/*      The alias databases for \fBlocal\fR(8) delivery that are updated with
273
287
/*      "\fBnewaliases\fR" or with "\fBsendmail -bi\fR".
274
288
/* .IP "\fBcommand_directory (see 'postconf -d' output)\fR"
275
289
/*      The location of all postfix administrative commands.
279
293
/* .IP "\fBdaemon_directory (see 'postconf -d' output)\fR"
280
294
/*      The directory with Postfix support programs and daemon programs.
281
295
/* .IP "\fBdefault_database_type (see 'postconf -d' output)\fR"
282
 
/*      The default database type for use in newaliases(1), postalias(1)
283
 
/*      and postmap(1) commands.
 
296
/*      The default database type for use in \fBnewaliases\fR(1), \fBpostalias\fR(1)
 
297
/*      and \fBpostmap\fR(1) commands.
284
298
/* .IP "\fBdelay_warning_time (0h)\fR"
285
299
/*      The time after which the sender receives the message headers of
286
300
/*      mail that is still queued.
 
301
/* .IP "\fBenable_errors_to (no)\fR"
 
302
/*      Report mail delivery errors to the address specified with the
 
303
/*      non-standard Errors-To: message header, instead of the envelope
 
304
/*      sender address (this feature is removed with Postfix 2.2, is
 
305
/*      turned off by default with Postfix 2.1, and is always turned on
 
306
/*      with older Postfix versions).
287
307
/* .IP "\fBmail_owner (postfix)\fR"
288
308
/*      The UNIX system account that owns the Postfix queue and most Postfix
289
309
/*      daemon processes.
296
316
/*      records, so that "smtpd" becomes, for example, "postfix/smtpd".
297
317
/* .IP "\fBtrigger_timeout (10s)\fR"
298
318
/*      The time limit for sending a trigger to a Postfix daemon (for
299
 
/*      example, the pickup(8) or qmgr(8) daemon).
 
319
/*      example, the \fBpickup\fR(8) or \fBqmgr\fR(8) daemon).
300
320
/* FILES
301
321
/*      /var/spool/postfix, mail queue
302
322
/*      /etc/postfix, configuration files
383
403
#include <deliver_request.h>
384
404
#include <mime_state.h>
385
405
#include <header_opts.h>
 
406
#include <user_acl.h>
386
407
 
387
408
/* Application-specific. */
388
409
 
408
429
 /*
409
430
  * VERP support.
410
431
  */
411
 
char   *verp_delims;
 
432
static char *verp_delims;
412
433
 
413
434
 /*
414
435
  * Callback context for extracting recipients.
424
445
} SM_STATE;
425
446
 
426
447
 /*
 
448
  * Mail submission ACL
 
449
  */
 
450
char   *var_submit_acl;
 
451
 
 
452
static CONFIG_STR_TABLE str_table[] = {
 
453
    VAR_SUBMIT_ACL, DEF_SUBMIT_ACL, &var_submit_acl, 0, 0,
 
454
    0,
 
455
};
 
456
 
 
457
 /*
427
458
  * Silly little macros (SLMs).
428
459
  */
429
460
#define STR     vstring_str
455
486
    char   *start;
456
487
    char   *line;
457
488
    char   *next_line;
 
489
    int     len;
458
490
 
459
491
    /*
460
492
     * Parse the header line, and save copies of recipient addresses in the
471
503
                state->resent = 1;
472
504
        } else
473
505
            rcpt = state->recipients;
474
 
        tree = tok822_parse(vstring_str(buf) + strlen(header_info->name) + 1);
 
506
        tree = tok822_parse(STR(buf) + strlen(header_info->name) + 1);
475
507
        addr_list = tok822_grep(tree, TOK822_ADDR);
476
508
        for (tpp = addr_list; *tpp; tpp++) {
477
509
            tok822_internalize(state->temp, tpp[0]->head, TOK822_STR_DEFL);
478
 
            argv_add(rcpt, vstring_str(state->temp), (char *) 0);
 
510
            argv_add(rcpt, STR(state->temp), (char *) 0);
479
511
        }
480
512
        myfree((char *) addr_list);
481
513
        tok822_free_tree(tree);
483
515
 
484
516
    /*
485
517
     * Pipe the unmodified message header through the header line folding
486
 
     * routine.
 
518
     * routine, and ensure that long lines are chopped appropriately.
487
519
     */
488
520
    for (line = start = STR(buf); line; line = next_line) {
489
521
        next_line = split_at(line, '\n');
490
 
        output_text(context, REC_TYPE_NORM, line, next_line ?
491
 
                    next_line - line - 1 : strlen(line), offset);
 
522
        len = next_line ? next_line - line - 1 : strlen(line);
 
523
        do {
 
524
            if (len > var_line_limit) {
 
525
                output_text(context, REC_TYPE_CONT, line, var_line_limit, offset);
 
526
                line += var_line_limit;
 
527
                len -= var_line_limit;
 
528
                offset += var_line_limit;
 
529
            } else {
 
530
                output_text(context, REC_TYPE_NORM, line, len, offset);
 
531
                offset += len;
 
532
                break;
 
533
            }
 
534
        } while (len > 0);
 
535
        offset += 1;
492
536
    }
493
537
}
494
538
 
506
550
    int     skip_from_;
507
551
    TOK822 *tree;
508
552
    TOK822 *tp;
 
553
    int     rcpt_count = 0;
509
554
    enum {
510
555
        STRIP_CR_DUNNO, STRIP_CR_DO, STRIP_CR_DONT
511
556
    }       strip_cr;
518
563
    MIME_STATE *mime_state = 0;
519
564
    SM_STATE state;
520
565
    int     mime_errs;
 
566
    const char *errstr;
 
567
    int     addr_count;
 
568
 
 
569
    /*
 
570
     * Access control is enforced in the postdrop command. The code here
 
571
     * merely produces a more user-friendly interface.
 
572
     */
 
573
    if ((errstr = check_user_acl_byuid(var_submit_acl, uid)) != 0)
 
574
        msg_fatal_status(EX_NOPERM,
 
575
          "User %s(%ld) is not allowed to submit mail", errstr, (long) uid);
521
576
 
522
577
    /*
523
578
     * Initialize.
597
652
    if (recipients) {
598
653
        for (cpp = recipients; *cpp != 0; cpp++) {
599
654
            tree = tok822_parse(*cpp);
600
 
            for (tp = tree; tp != 0; tp = tp->next) {
 
655
            for (addr_count = 0, tp = tree; tp != 0; tp = tp->next) {
601
656
                if (tp->type == TOK822_ADDR) {
602
657
                    tok822_internalize(buf, tp->head, TOK822_STR_DEFL);
603
658
                    if (REC_PUT_BUF(dst, REC_TYPE_RCPT, buf) < 0)
604
659
                        msg_fatal_status(EX_TEMPFAIL,
605
660
                                    "%s(%ld): error writing queue file: %m",
606
661
                                         saved_sender, (long) uid);
 
662
                    ++rcpt_count;
 
663
                    ++addr_count;
607
664
                }
608
665
            }
609
666
            tok822_free_tree(tree);
 
667
            if (addr_count == 0) {
 
668
                if (rec_put(dst, REC_TYPE_RCPT, "", 0) < 0)
 
669
                    msg_fatal_status(EX_TEMPFAIL,
 
670
                                     "%s(%ld): error writing queue file: %m",
 
671
                                     saved_sender, (long) uid);
 
672
                ++rcpt_count;
 
673
            }
610
674
        }
611
675
    }
612
676
 
621
685
     */
622
686
    rec_fputs(dst, REC_TYPE_MESG, "");
623
687
    if (DEL_REQ_TRACE_ONLY(flags) != 0) {
 
688
        if (flags & SM_FLAG_XRCPT)
 
689
            msg_fatal_status(EX_USAGE, "-t option cannot be used with -bv");
 
690
        if (*saved_sender)
 
691
            rec_fprintf(dst, REC_TYPE_NORM, "From: %s", saved_sender);
624
692
        rec_fprintf(dst, REC_TYPE_NORM, "Subject: probe");
625
693
        if (recipients) {
626
694
            rec_fprintf(dst, REC_TYPE_NORM, "To:");
667
735
            }
668
736
            if (skip_from_) {
669
737
                if (type == REC_TYPE_NORM) {
670
 
                    start = vstring_str(buf);
 
738
                    start = STR(buf);
671
739
                    if (strncmp(start + strspn(start, ">"), "From ", 5) == 0)
672
740
                        continue;
673
741
                }
722
790
                msg_fatal_status(EX_TEMPFAIL,
723
791
                                 "%s(%ld): error writing queue file: %m",
724
792
                                 saved_sender, (long) uid);
 
793
            ++rcpt_count;
725
794
        }
726
795
        argv_free(state.recipients);
727
796
        argv_free(state.resent_recip);
728
797
        vstring_free(state.temp);
729
798
    }
 
799
    if (rcpt_count == 0)
 
800
        msg_fatal_status(EX_USAGE, (flags & SM_FLAG_XRCPT) ?
 
801
                         "No recipient addresses found in message header" :
 
802
                         "Recipient addresses must be specified on"
 
803
                         " the command line or via the -t option");
730
804
 
731
805
    /*
732
806
     * Identify the end of the queue file.
784
858
    char   *site_to_flush = 0;
785
859
    char   *encoding = 0;
786
860
    char   *qtime = 0;
 
861
    const char *errstr;
 
862
    uid_t   uid;
787
863
 
788
864
    /*
789
865
     * Be consistent with file permissions.
845
921
     * Further initialization...
846
922
     */
847
923
    mail_conf_read();
 
924
    get_mail_conf_str_table(str_table);
848
925
 
849
926
    if (chdir(var_queue_dir))
850
927
        msg_fatal_status(EX_UNAVAILABLE, "chdir %s: %m", var_queue_dir);
895
972
            optind++;
896
973
            continue;
897
974
        }
898
 
        if ((c = GETOPT(argc, argv, "A:B:C:F:GIL:N:R:UV:X:b:ce:f:h:imno:p:r:q:tvx")) <= 0)
 
975
        if ((c = GETOPT(argc, argv, "A:B:C:F:GIL:N:O:R:UV:X:b:ce:f:h:imno:p:r:q:tvx")) <= 0)
899
976
            break;
900
977
        switch (c) {
901
978
        default:
1104
1181
        if (argv[OPTIND])
1105
1182
            msg_fatal_status(EX_USAGE,
1106
1183
                             "stand-alone mode requires no recipient");
 
1184
        /* The actual enforcement happens in the postdrop command. */
 
1185
        if ((errstr = check_user_acl_byuid(var_submit_acl, uid = getuid())) != 0)
 
1186
            msg_fatal_status(EX_NOPERM,
 
1187
                             "User %s(%ld) is not allowed to submit mail",
 
1188
                             errstr, (long) uid);
1107
1189
        ext_argv = argv_alloc(2);
1108
1190
        argv_add(ext_argv, "smtpd", "-S", (char *) 0);
1109
1191
        for (n = 0; n < msg_verbose; n++)