1 /* $NetBSD: unknown.c,v 1.1.1.2 2011/07/31 10:02:41 tron Exp $ */ 2 3 /*++ 4 /* NAME 5 /* unknown 3 6 /* SUMMARY 7 /* delivery of unknown recipients 8 /* SYNOPSIS 9 /* #include "local.h" 10 /* 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. 30 /* 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 /*--*/ 51 52 /* System library. */ 53 54 #include <sys_defs.h> 55 #include <string.h> 56 57 #ifdef STRCASECMP_IN_STRINGS_H 58 #include <strings.h> 59 #endif 60 61 /* Utility library. */ 62 63 #include <msg.h> 64 #include <stringops.h> 65 #include <mymalloc.h> 66 #include <vstring.h> 67 68 /* Global library. */ 69 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> 77 78 /* Application-specific. */ 79 80 #include "local.h" 81 82 /* deliver_unknown - delivery for unknown recipients */ 83 84 int deliver_unknown(LOCAL_STATE state, USER_ATTR usr_attr) 85 { 86 const char *myname = "deliver_unknown"; 87 int status; 88 VSTRING *expand_luser; 89 static MAPS *transp_maps; 90 const char *map_transport; 91 92 /* 93 * Make verbose logging easier to understand. 94 */ 95 state.level++; 96 if (msg_verbose) 97 MSG_LOG_STATE(myname, state); 98 99 /* 100 * DUPLICATE/LOOP ELIMINATION 101 * 102 * Don't deliver the same user twice. 103 */ 104 if (been_here(state.dup_filter, "%s %s", myname, state.msg_attr.local)) 105 return (0); 106 107 /* 108 * The fall-back transport specifies a delivery machanism that handles 109 * users not found in the aliases or UNIX passwd databases. 110 */ 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 dict_errno = 0; 116 if (*var_fbck_transp_maps 117 && (map_transport = maps_find(transp_maps, state.msg_attr.user, 118 DICT_FLAG_NONE)) != 0) { 119 state.msg_attr.rcpt.offset = -1L; 120 return (deliver_pass(MAIL_CLASS_PRIVATE, map_transport, 121 state.request, &state.msg_attr.rcpt)); 122 } else if (dict_errno != 0) { 123 /* Details in the logfile. */ 124 dsb_simple(state.msg_attr.why, "4.3.0", "table lookup failure"); 125 return (DEL_STAT_DEFER); 126 } 127 if (*var_fallback_transport) { 128 state.msg_attr.rcpt.offset = -1L; 129 return (deliver_pass(MAIL_CLASS_PRIVATE, var_fallback_transport, 130 state.request, &state.msg_attr.rcpt)); 131 } 132 133 /* 134 * Subject the luser_relay address to $name expansion, disable 135 * propagation of unmatched address extension, and re-inject the address 136 * into the delivery machinery. Do not give special treatment to "|stuff" 137 * or /stuff. 138 */ 139 if (*var_luser_relay) { 140 state.msg_attr.unmatched = 0; 141 expand_luser = vstring_alloc(100); 142 local_expand(expand_luser, var_luser_relay, &state, &usr_attr, (char *) 0); 143 status = deliver_resolve_addr(state, usr_attr, STR(expand_luser)); 144 vstring_free(expand_luser); 145 return (status); 146 } 147 148 /* 149 * If no alias was found for a required reserved name, toss the message 150 * into the bit bucket, and issue a warning instead. 151 */ 152 #define STREQ(x,y) (strcasecmp(x,y) == 0) 153 154 if (STREQ(state.msg_attr.local, MAIL_ADDR_MAIL_DAEMON) 155 || STREQ(state.msg_attr.local, MAIL_ADDR_POSTMASTER)) { 156 msg_warn("required alias not found: %s", state.msg_attr.local); 157 dsb_simple(state.msg_attr.why, "2.0.0", "discarded"); 158 return (sent(BOUNCE_FLAGS(state.request), SENT_ATTR(state.msg_attr))); 159 } 160 161 /* 162 * Bounce the message when no luser relay is specified. 163 */ 164 dsb_simple(state.msg_attr.why, "5.1.1", 165 "unknown user: \"%s\"", state.msg_attr.local); 166 return (bounce_append(BOUNCE_FLAGS(state.request), 167 BOUNCE_ATTR(state.msg_attr))); 168 } 169