~ubuntu-branches/ubuntu/maverick/postfix/maverick-security

« back to all changes in this revision

Viewing changes to src/milter/test-milter.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones, Wietse Venema, LaMont Jones
  • Date: 2009-06-03 14:17:08 UTC
  • mfrom: (1.1.22 upstream)
  • Revision ID: james.westby@ubuntu.com-20090603141708-o9u59xlor7nmd2x1
[Wietse Venema]

* New upstream release: 2.6.2~rc1

[LaMont Jones]

* move postfix-add-{filter,policy} manpages to section 8, and deliver
* provide: default-mta on ubuntu

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
/* .IP "\fB-a accept|tempfail|reject|discard|skip|\fIddd x.y.z text\fR"
20
20
/*      Specifies a non-default reply for the MTA command specified
21
21
/*      with \fB-c\fR. The default is \fBtempfail\fR.
22
 
/* .IP "\fB-d\fI level\fR"
23
 
/*      Enable libmilter debugging at the specified level.
 
22
/* .IP "\fB-A address\fR"
 
23
/*      Add the specified recipient address. Multiple -A options
 
24
/*      are supported.
 
25
/* .IP "\fB-b pathname
 
26
/*      Replace the message body by the content of the specified file.
24
27
/* .IP "\fB-c connect|helo|mail|rcpt|data|header|eoh|body|eom|unknown|close|abort\fR"
25
28
/*      When to send the non-default reply specified with \fB-a\fR.
26
29
/*      The default protocol stage is \fBconnect\fR.
27
30
/* .IP "\fB-C\fI count\fR"
28
31
/*      Terminate after \fIcount\fR connections.
 
32
/* .IP "\fB-d\fI level\fR"
 
33
/*      Enable libmilter debugging at the specified level.
 
34
/* .IP "\fB-f \fIsender\fR
 
35
/*      Replace the sender by the specified address.
 
36
/* .IP "\fB-h \fI'index header-label header-value'\fR"
 
37
/*      Replace the message header at the specified position.
29
38
/* .IP "\fB-i \fI'index header-label header-value'\fR"
30
39
/*      Insert header at specified position.
31
40
/* .IP "\fB-l\fR"
43
52
/*      The event for which the filter will not reply.
44
53
/* .IP "\fB-p inet:\fIport\fB@\fIhost\fB|unix:\fIpathname\fR"
45
54
/*      The mail filter listen endpoint.
46
 
/* .IP "\fB-r \fI'index header-label header-value'\fR"
47
 
/*      Replace the message header at the specified position.
48
 
/* .IP "\fB-R pathname
49
 
/*      Replace the message body by the content of the specified file.
 
55
/* .IP "\fB-r\fR"
 
56
/*      Request rejected recipients from the MTA.
50
57
/* .IP "\fB-v\fR"
51
58
/*      Make the program more verbose.
52
59
/* LICENSE
127
134
static char *reply_dsn;
128
135
static char *reply_message;
129
136
 
 
137
#ifdef SMFIR_CHGFROM
 
138
static char *chg_from;
 
139
 
 
140
#endif
 
141
 
130
142
#ifdef SMFIR_INSHEADER
131
143
static char *ins_hdr;
132
144
static int ins_idx;
146
158
 
147
159
#endif
148
160
 
 
161
#define MAX_RCPT        10
 
162
int     rcpt_count = 0;
 
163
char   *rcpt_addr[MAX_RCPT];
 
164
 
 
165
static const char *macro_names[] = {
 
166
    "_",
 
167
    "i",
 
168
    "j",
 
169
    "v",
 
170
    "{auth_authen}",
 
171
    "{auth_author}",
 
172
    "{auth_type}",
 
173
    "{cert_issuer}",
 
174
    "{cert_subject}",
 
175
    "{cipher}",
 
176
    "{cipher_bits}",
 
177
    "{client_addr}",
 
178
    "{client_connections}",
 
179
    "{client_name}",
 
180
    "{client_port}",
 
181
    "{client_ptr}",
 
182
    "{client_resolve}",
 
183
    "{daemon_name}",
 
184
    "{if_addr}",
 
185
    "{if_name}",
 
186
    "{mail_addr}",
 
187
    "{mail_host}",
 
188
    "{mail_mailer}",
 
189
    "{rcpt_addr}",
 
190
    "{rcpt_host}",
 
191
    "{rcpt_mailer}",
 
192
    "{tls_version}",
 
193
    0,
 
194
};
 
195
 
149
196
static int test_reply(SMFICTX *ctx, int code)
150
197
{
151
 
    (void) fflush(stdout);              /* In case output redirected. */
 
198
    const char **cpp;
 
199
    const char *symval;
 
200
 
 
201
    for (cpp = macro_names; *cpp; cpp++)
 
202
        if ((symval = smfi_getsymval(ctx, (char *) *cpp)) != 0)
 
203
            printf("macro: %s=\"%s\"\n", *cpp, symval);
 
204
    (void) fflush(stdout);                      /* In case output redirected. */
152
205
 
153
206
    if (code == SMFIR_REPLYCODE) {
154
 
        if (smfi_setreply(ctx, reply_code, reply_dsn, reply_message) == MI_FAILURE)
155
 
            fprintf(stderr, "smfi_setreply failed\n");
 
207
        if (smfi_setmlreply(ctx, reply_code, reply_dsn, reply_message, reply_message, (char *) 0) == MI_FAILURE)
 
208
            fprintf(stderr, "smfi_setmlreply failed\n");
156
209
        printf("test_reply %s\n", reply_code);
157
210
        return (reply_code[0] == '4' ? SMFIS_TEMPFAIL : SMFIS_REJECT);
158
211
    } else {
286
339
        }
287
340
    }
288
341
#endif
 
342
#ifdef SMFIR_CHGFROM
 
343
    if (chg_from != 0 && smfi_chgfrom(ctx, chg_from, "whatever") == MI_FAILURE)
 
344
        fprintf(stderr, "smfi_chgfrom failed\n");
 
345
    else
 
346
        printf("smfi_chgfrom OK\n");
 
347
#endif
289
348
#ifdef SMFIR_INSHEADER
290
349
    if (ins_hdr && smfi_insheader(ctx, ins_idx, ins_hdr, ins_val) == MI_FAILURE)
291
 
        fprintf(stderr, "smfi_insheader failed");
 
350
        fprintf(stderr, "smfi_insheader failed\n");
292
351
#endif
293
352
#ifdef SMFIR_CHGHEADER
294
353
    if (chg_hdr && smfi_chgheader(ctx, chg_hdr, chg_idx, chg_val) == MI_FAILURE)
295
 
        fprintf(stderr, "smfi_chgheader failed");
 
354
        fprintf(stderr, "smfi_chgheader failed\n");
296
355
#endif
 
356
    {
 
357
        int     count;
 
358
 
 
359
        for (count = 0; count < rcpt_count; count++)
 
360
            if (smfi_addrcpt(ctx, rcpt_addr[count]) == MI_FAILURE)
 
361
                fprintf(stderr, "smfi_addrcpt `%s' failed\n", rcpt_addr[count]);
 
362
    }
297
363
    return (test_reply(ctx, test_eom_reply));
298
364
}
299
365
 
342
408
{
343
409
    "test-milter",
344
410
    SMFI_VERSION,
345
 
    SMFIF_ADDRCPT | SMFIF_DELRCPT | SMFIF_ADDHDRS | SMFIF_CHGHDRS | SMFIF_CHGBODY,
 
411
    SMFIF_ADDRCPT | SMFIF_DELRCPT | SMFIF_ADDHDRS | SMFIF_CHGHDRS | SMFIF_CHGBODY | SMFIF_CHGFROM,
346
412
    test_connect,
347
413
    test_helo,
348
414
    test_mail,
464
530
    char   *noreply = 0;
465
531
    const struct noproto_map *np;
466
532
 
467
 
    while ((ch = getopt(argc, argv, "a:c:C:d:i:lm:M:n:N:p:r:R:v")) > 0) {
 
533
    while ((ch = getopt(argc, argv, "a:A:b:c:C:d:f:h:i:lm:M:n:N:p:rv")) > 0) {
468
534
        switch (ch) {
469
535
        case 'a':
470
536
            action = optarg;
471
537
            break;
 
538
        case 'A':
 
539
            if (rcpt_count >= MAX_RCPT) {
 
540
                fprintf(stderr, "too many -A options\n");
 
541
                exit(1);
 
542
            }
 
543
            rcpt_addr[rcpt_count++] = optarg;
 
544
            break;
 
545
        case 'b':
 
546
#ifdef SMFIR_REPLBODY
 
547
            if (body_file) {
 
548
                fprintf(stderr, "too many -b options\n");
 
549
                exit(1);
 
550
            }
 
551
            body_file = optarg;
 
552
#else
 
553
            fprintf(stderr, "no libmilter support to replace body\n");
 
554
#endif
 
555
            break;
472
556
        case 'c':
473
557
            command = optarg;
474
558
            break;
478
562
                exit(1);
479
563
            }
480
564
            break;
 
565
        case 'f':
 
566
#ifdef SMFIR_CHGFROM
 
567
            if (chg_from) {
 
568
                fprintf(stderr, "too many -f options\n");
 
569
                exit(1);
 
570
            }
 
571
            chg_from = optarg;
 
572
#else
 
573
            fprintf(stderr, "no libmilter support to change sender\n");
 
574
            exit(1);
 
575
#endif
 
576
            break;
 
577
        case 'h':
 
578
#ifdef SMFIR_CHGHEADER
 
579
            if (chg_hdr) {
 
580
                fprintf(stderr, "too many -h options\n");
 
581
                exit(1);
 
582
            }
 
583
            parse_hdr_info(optarg, &chg_idx, &chg_hdr, &chg_val);
 
584
#else
 
585
            fprintf(stderr, "no libmilter support to change header\n");
 
586
            exit(1);
 
587
#endif
 
588
            break;
481
589
        case 'i':
482
590
#ifdef SMFIR_INSHEADER
483
591
            if (ins_hdr) {
554
662
            }
555
663
            break;
556
664
        case 'r':
557
 
#ifdef SMFIR_CHGHEADER
558
 
            if (chg_hdr) {
559
 
                fprintf(stderr, "too many -r options\n");
560
 
                exit(1);
561
 
            }
562
 
            parse_hdr_info(optarg, &chg_idx, &chg_hdr, &chg_val);
 
665
#ifdef SMFIP_RCPT_REJ
 
666
            misc_mask |= SMFIP_RCPT_REJ;
563
667
#else
564
 
            fprintf(stderr, "no libmilter support to change header\n");
565
 
            exit(1);
 
668
            fprintf(stderr, "no libmilter support for rejected recipients\n");
566
669
#endif
567
670
            break;
568
671
        case 'v':
571
674
        case 'C':
572
675
            conn_count = atoi(optarg);
573
676
            break;
574
 
#ifdef SMFIR_REPLBODY
575
 
        case 'R':
576
 
            if (body_file) {
577
 
                fprintf(stderr, "too many -R options\n");
578
 
                exit(1);
579
 
            }
580
 
            body_file = optarg;
581
 
#endif
582
 
            break;
583
677
        default:
584
678
            fprintf(stderr,
585
679
                    "usage: %s [-dv] \n"
586
680
                    "\t[-a action]              non-default action\n"
 
681
                    "\t[-b body_text]           replace body\n",
587
682
                    "\t[-c command]             non-default action trigger\n"
 
683
                    "\t[-h 'index label value'] replace header\n"
588
684
                    "\t[-i 'index label value'] insert header\n"
589
685
                    "\t[-m macro_state]         non-default macro state\n"
590
686
                    "\t[-M macro_list]          non-default macro list\n"
591
687
                    "\t[-n events]              don't receive these events\n"
592
688
                  "\t[-N events]                don't reply to these events\n"
593
689
                    "\t-p port                  milter application\n"
594
 
                    "\t[-r 'index label value'] replace header\n"
 
690
                  "\t-r                       request rejected recipients\n"
595
691
                    "\t[-C conn_count]          when to exit\n",
596
 
                    "\t[-R body_text]           replace body\n",
597
692
                    argv[0]);
598
693
            exit(1);
599
694
        }