No empty .Rs/.Re
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / local / unknown.c
blob00861cdf4627239a88bdc6ae4f41a696ef3a69bc
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* unknown 3
6 /* SUMMARY
7 /* delivery of unknown recipients
8 /* SYNOPSIS
9 /* #include "local.h"
11 /* int deliver_unknown(state, usr_attr)
12 /* LOCAL_STATE state;
13 /* USER_ATTR usr_attr;
14 /* DESCRIPTION
15 /* deliver_unknown() delivers a message for unknown recipients.
16 /* .IP \(bu
17 /* If an alternative message transport is specified via the
18 /* fallback_transport parameter, delivery is delegated to the
19 /* named transport.
20 /* .IP \(bu
21 /* If an alternative address is specified via the luser_relay
22 /* configuration parameter, mail is forwarded to that address.
23 /* .IP \(bu
24 /* Otherwise the recipient is bounced.
25 /* .PP
26 /* The luser_relay parameter is subjected to $name expansion of
27 /* the standard message attributes: $user, $home, $shell, $domain,
28 /* $recipient, $mailbox, $extension, $recipient_delimiter, not
29 /* all of which actually make sense.
31 /* Arguments:
32 /* .IP state
33 /* Message delivery attributes (sender, recipient etc.).
34 /* Attributes describing alias, include or forward expansion.
35 /* A table with the results from expanding aliases or lists.
36 /* A table with delivered-to: addresses taken from the message.
37 /* .IP usr_attr
38 /* Attributes describing user rights and environment.
39 /* DIAGNOSTICS
40 /* The result status is non-zero when delivery should be tried again.
41 /* LICENSE
42 /* .ad
43 /* .fi
44 /* The Secure Mailer license must be distributed with this software.
45 /* AUTHOR(S)
46 /* Wietse Venema
47 /* IBM T.J. Watson Research
48 /* P.O. Box 704
49 /* Yorktown Heights, NY 10598, USA
50 /*--*/
52 /* System library. */
54 #include <sys_defs.h>
55 #include <string.h>
57 #ifdef STRCASECMP_IN_STRINGS_H
58 #include <strings.h>
59 #endif
61 /* Utility library. */
63 #include <msg.h>
64 #include <stringops.h>
65 #include <mymalloc.h>
66 #include <vstring.h>
68 /* Global library. */
70 #include <been_here.h>
71 #include <mail_params.h>
72 #include <mail_proto.h>
73 #include <bounce.h>
74 #include <mail_addr.h>
75 #include <sent.h>
76 #include <deliver_pass.h>
78 /* Application-specific. */
80 #include "local.h"
82 /* deliver_unknown - delivery for unknown recipients */
84 int deliver_unknown(LOCAL_STATE state, USER_ATTR usr_attr)
86 const char *myname = "deliver_unknown";
87 int status;
88 VSTRING *expand_luser;
89 static MAPS *transp_maps;
90 const char *map_transport;
93 * Make verbose logging easier to understand.
95 state.level++;
96 if (msg_verbose)
97 MSG_LOG_STATE(myname, state);
100 * DUPLICATE/LOOP ELIMINATION
102 * Don't deliver the same user twice.
104 if (been_here(state.dup_filter, "%s %s", myname, state.msg_attr.local))
105 return (0);
108 * The fall-back transport specifies a delivery machanism that handles
109 * users not found in the aliases or UNIX passwd databases.
111 if (*var_fbck_transp_maps && transp_maps == 0)
112 transp_maps = maps_create(VAR_FBCK_TRANSP_MAPS, var_fbck_transp_maps,
113 DICT_FLAG_LOCK | DICT_FLAG_NO_REGSUB);
114 /* The -1 is a hint for the down-stream deliver_completed() function. */
115 if (*var_fbck_transp_maps
116 && (map_transport = maps_find(transp_maps, state.msg_attr.user,
117 DICT_FLAG_NONE)) != 0) {
118 state.msg_attr.rcpt.offset = -1L;
119 return (deliver_pass(MAIL_CLASS_PRIVATE, map_transport,
120 state.request, &state.msg_attr.rcpt));
122 if (*var_fallback_transport) {
123 state.msg_attr.rcpt.offset = -1L;
124 return (deliver_pass(MAIL_CLASS_PRIVATE, var_fallback_transport,
125 state.request, &state.msg_attr.rcpt));
129 * Subject the luser_relay address to $name expansion, disable
130 * propagation of unmatched address extension, and re-inject the address
131 * into the delivery machinery. Do not give special treatment to "|stuff"
132 * or /stuff.
134 if (*var_luser_relay) {
135 state.msg_attr.unmatched = 0;
136 expand_luser = vstring_alloc(100);
137 local_expand(expand_luser, var_luser_relay, &state, &usr_attr, (char *) 0);
138 status = deliver_resolve_addr(state, usr_attr, STR(expand_luser));
139 vstring_free(expand_luser);
140 return (status);
144 * If no alias was found for a required reserved name, toss the message
145 * into the bit bucket, and issue a warning instead.
147 #define STREQ(x,y) (strcasecmp(x,y) == 0)
149 if (STREQ(state.msg_attr.local, MAIL_ADDR_MAIL_DAEMON)
150 || STREQ(state.msg_attr.local, MAIL_ADDR_POSTMASTER)) {
151 msg_warn("required alias not found: %s", state.msg_attr.local);
152 dsb_simple(state.msg_attr.why, "2.0.0", "discarded");
153 return (sent(BOUNCE_FLAGS(state.request), SENT_ATTR(state.msg_attr)));
157 * Bounce the message when no luser relay is specified.
159 dsb_simple(state.msg_attr.why, "5.1.1",
160 "unknown user: \"%s\"", state.msg_attr.local);
161 return (bounce_append(BOUNCE_FLAGS(state.request),
162 BOUNCE_ATTR(state.msg_attr)));