~ubuntu-branches/ubuntu/vivid/postfix/vivid-proposed

« back to all changes in this revision

Viewing changes to src/local/unknown.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2005-02-27 09:33:07 UTC
  • Revision ID: james.westby@ubuntu.com-20050227093307-cn789t27ibnlh6tf
Tags: upstream-2.1.5
ImportĀ upstreamĀ versionĀ 2.1.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*++
 
2
/* NAME
 
3
/*      unknown 3
 
4
/* SUMMARY
 
5
/*      delivery of unknown recipients
 
6
/* SYNOPSIS
 
7
/*      #include "local.h"
 
8
/*
 
9
/*      int     deliver_unknown(state, usr_attr)
 
10
/*      LOCAL_STATE state;
 
11
/*      USER_ATTR usr_attr;
 
12
/* DESCRIPTION
 
13
/*      deliver_unknown() delivers a message for unknown recipients.
 
14
/* .IP \(bu
 
15
/*      If an alternative message transport is specified via the
 
16
/*      fallback_transport parameter, delivery is delegated to the
 
17
/*      named transport.
 
18
/* .IP \(bu
 
19
/*      If an alternative address is specified via the luser_relay
 
20
/*      configuration parameter, mail is forwarded to that address.
 
21
/* .IP \(bu
 
22
/*      Otherwise the recipient is bounced.
 
23
/* .PP
 
24
/*      The luser_relay parameter is subjected to $name expansion of
 
25
/*      the standard message attributes: $user, $home, $shell, $domain,
 
26
/*      $recipient, $mailbox, $extension, $recipient_delimiter, not
 
27
/*      all of which actually make sense.
 
28
/*
 
29
/*      Arguments:
 
30
/* .IP state
 
31
/*      Message delivery attributes (sender, recipient etc.).
 
32
/*      Attributes describing alias, include or forward expansion.
 
33
/*      A table with the results from expanding aliases or lists.
 
34
/*      A table with delivered-to: addresses taken from the message.
 
35
/* .IP usr_attr
 
36
/*      Attributes describing user rights and environment.
 
37
/* DIAGNOSTICS
 
38
/*      The result status is non-zero when delivery should be tried again.
 
39
/* LICENSE
 
40
/* .ad
 
41
/* .fi
 
42
/*      The Secure Mailer license must be distributed with this software.
 
43
/* AUTHOR(S)
 
44
/*      Wietse Venema
 
45
/*      IBM T.J. Watson Research
 
46
/*      P.O. Box 704
 
47
/*      Yorktown Heights, NY 10598, USA
 
48
/*--*/
 
49
 
 
50
/* System library. */
 
51
 
 
52
#include <sys_defs.h>
 
53
#include <string.h>
 
54
 
 
55
#ifdef STRCASECMP_IN_STRINGS_H
 
56
#include <strings.h>
 
57
#endif
 
58
 
 
59
/* Utility library. */
 
60
 
 
61
#include <msg.h>
 
62
#include <stringops.h>
 
63
#include <mymalloc.h>
 
64
#include <vstring.h>
 
65
 
 
66
/* Global library. */
 
67
 
 
68
#include <been_here.h>
 
69
#include <mail_params.h>
 
70
#include <mail_proto.h>
 
71
#include <bounce.h>
 
72
#include <mail_addr.h>
 
73
#include <sent.h>
 
74
 
 
75
/* Application-specific. */
 
76
 
 
77
#include "local.h"
 
78
 
 
79
/* deliver_unknown - delivery for unknown recipients */
 
80
 
 
81
int     deliver_unknown(LOCAL_STATE state, USER_ATTR usr_attr)
 
82
{
 
83
    char   *myname = "deliver_unknown";
 
84
    int     status;
 
85
    VSTRING *expand_luser;
 
86
 
 
87
    /*
 
88
     * Make verbose logging easier to understand.
 
89
     */
 
90
    state.level++;
 
91
    if (msg_verbose)
 
92
        MSG_LOG_STATE(myname, state);
 
93
 
 
94
    /*
 
95
     * DUPLICATE/LOOP ELIMINATION
 
96
     * 
 
97
     * Don't deliver the same user twice.
 
98
     */
 
99
    if (been_here(state.dup_filter, "%s %s", myname, state.msg_attr.local))
 
100
        return (0);
 
101
 
 
102
    /*
 
103
     * The fall-back transport specifies a delivery machanism that handles
 
104
     * users not found in the aliases or UNIX passwd databases.
 
105
     */
 
106
    if (*var_fallback_transport)
 
107
        return (deliver_pass(MAIL_CLASS_PRIVATE, var_fallback_transport,
 
108
                             state.request, state.msg_attr.orig_rcpt,
 
109
                             state.msg_attr.recipient, -1L));
 
110
 
 
111
    /*
 
112
     * Subject the luser_relay address to $name expansion, disable
 
113
     * propagation of unmatched address extension, and re-inject the address
 
114
     * into the delivery machinery. Do not give special treatment to "|stuff"
 
115
     * or /stuff.
 
116
     */
 
117
    if (*var_luser_relay) {
 
118
        state.msg_attr.unmatched = 0;
 
119
        expand_luser = vstring_alloc(100);
 
120
        local_expand(expand_luser, var_luser_relay, &state, &usr_attr, (char *) 0);
 
121
        status = deliver_resolve_addr(state, usr_attr, vstring_str(expand_luser));
 
122
        vstring_free(expand_luser);
 
123
        return (status);
 
124
    }
 
125
 
 
126
    /*
 
127
     * If no alias was found for a required reserved name, toss the message
 
128
     * into the bit bucket, and issue a warning instead.
 
129
     */
 
130
#define STREQ(x,y) (strcasecmp(x,y) == 0)
 
131
 
 
132
    if (STREQ(state.msg_attr.local, MAIL_ADDR_MAIL_DAEMON)
 
133
        || STREQ(state.msg_attr.local, MAIL_ADDR_POSTMASTER)) {
 
134
        msg_warn("required alias not found: %s", state.msg_attr.local);
 
135
        return (sent(BOUNCE_FLAGS(state.request),
 
136
                     SENT_ATTR(state.msg_attr),
 
137
                     "discarded"));
 
138
    }
 
139
 
 
140
    /*
 
141
     * Bounce the message when no luser relay is specified.
 
142
     */
 
143
    return (bounce_append(BOUNCE_FLAGS(state.request),
 
144
                          BOUNCE_ATTR(state.msg_attr),
 
145
                          "unknown user: \"%s\"", state.msg_attr.local));
 
146
}