1 /* $NetBSD: local.h,v 1.1.1.1 2009/06/23 10:08:48 tron Exp $ */ 2 3 /*++ 4 /* NAME 5 /* local 3h 6 /* SUMMARY 7 /* local mail delivery 8 /* SYNOPSIS 9 /* #include "local.h" 10 /* DESCRIPTION 11 /* .nf 12 13 /* 14 * Utility library. 15 */ 16 #include <htable.h> 17 #include <vstream.h> 18 #include <vstring.h> 19 20 /* 21 * Global library. 22 */ 23 #include <been_here.h> 24 #include <tok822.h> 25 #include <deliver_request.h> 26 #include <mbox_conf.h> 27 #include <maps.h> 28 #include <dsn_buf.h> 29 #include <dsn.h> 30 #include <delivered_hdr.h> 31 32 /* 33 * User attributes: these control the privileges for delivery to external 34 * commands, external files, or mailboxes, and the initial environment of 35 * external commands. 36 */ 37 typedef struct USER_ATTR { 38 uid_t uid; /* file/command access */ 39 gid_t gid; /* file/command access */ 40 char *home; /* null or home directory */ 41 char *logname; /* null or login name */ 42 char *shell; /* null or login shell */ 43 } USER_ATTR; 44 45 /* 46 * Critical macros. Not for obscurity, but to ensure consistency. 47 */ 48 #define RESET_USER_ATTR(usr_attr, level) { \ 49 usr_attr.uid = 0; usr_attr.gid = 0; usr_attr.home = 0; \ 50 usr_attr.logname = 0; usr_attr.shell = 0; \ 51 if (msg_verbose) \ 52 msg_info("%s[%d]: reset user_attr", myname, level); \ 53 } 54 55 #define SET_USER_ATTR(usr_attr, pwd, level) { \ 56 usr_attr.uid = pwd->pw_uid; usr_attr.gid = pwd->pw_gid; \ 57 usr_attr.home = pwd->pw_dir; usr_attr.logname = pwd->pw_name; \ 58 usr_attr.shell = pwd->pw_shell; \ 59 if (msg_verbose) \ 60 msg_info("%s[%d]: set user_attr: %s", \ 61 myname, level, pwd->pw_name); \ 62 } 63 64 /* 65 * The delivery attributes are inherited from files, from aliases, and from 66 * whatnot. Some of the information is changed on the fly. DELIVER_ATTR 67 * structures are therefore passed by value, so there is no need to undo 68 * changes. 69 */ 70 typedef struct DELIVER_ATTR { 71 int level; /* recursion level */ 72 VSTREAM *fp; /* open queue file */ 73 char *queue_name; /* mail queue id */ 74 char *queue_id; /* mail queue id */ 75 long offset; /* data offset */ 76 char *encoding; /* MIME encoding */ 77 const char *sender; /* taken from envelope */ 78 char *dsn_envid; /* DSN envelope ID */ 79 int dsn_ret; /* DSN headers/full */ 80 RECIPIENT rcpt; /* from delivery request */ 81 char *domain; /* recipient domain */ 82 char *local; /* recipient full localpart */ 83 char *user; /* recipient localpart, base name */ 84 char *extension; /* recipient localpart, extension */ 85 char *unmatched; /* unmatched extension */ 86 const char *owner; /* null or list owner */ 87 const char *delivered; /* for loop detection */ 88 char *relay; /* relay host */ 89 MSG_STATS msg_stats; /* time profile */ 90 int exp_type; /* expansion type. see below */ 91 char *exp_from; /* expanded_from */ 92 DELIVER_REQUEST *request; /* the kitchen sink */ 93 DSN_BUF *why; /* delivery status */ 94 } DELIVER_ATTR; 95 96 extern void deliver_attr_init(DELIVER_ATTR *); 97 extern void deliver_attr_dump(DELIVER_ATTR *); 98 extern void deliver_attr_free(DELIVER_ATTR *); 99 100 #define EXPAND_TYPE_ALIAS (1<<0) 101 #define EXPAND_TYPE_FWD (1<<1) 102 #define EXPAND_TYPE_INCL (1<<2) 103 104 /* 105 * Rather than schlepping around dozens of arguments, here is one that has 106 * all. Well, almost. The user attributes are just a bit too sensitive, so 107 * they are passed around separately. 108 */ 109 typedef struct LOCAL_STATE { 110 int level; /* nesting level, for logging */ 111 DELIVER_ATTR msg_attr; /* message attributes */ 112 BH_TABLE *dup_filter; /* internal duplicate filter */ 113 DELIVERED_HDR_INFO *loop_info; /* external loop filter */ 114 DELIVER_REQUEST *request; /* as from queue manager */ 115 } LOCAL_STATE; 116 117 #define RESET_OWNER_ATTR(msg_attr, level) { \ 118 msg_attr.owner = 0; \ 119 if (msg_verbose) \ 120 msg_info("%s[%d]: reset owner attr", myname, level); \ 121 } 122 123 #define SET_OWNER_ATTR(msg_attr, who, level) { \ 124 msg_attr.sender = msg_attr.owner = who; \ 125 if (msg_verbose) \ 126 msg_info("%s[%d]: set owner attr: %s", \ 127 myname, level, who); \ 128 } 129 130 /* 131 * Bundle up some often-user attributes. 132 */ 133 #define BOUNCE_FLAGS(request) DEL_REQ_TRACE_FLAGS((request)->flags) 134 135 #define BOUNCE_ATTR(attr) \ 136 attr.queue_id, &attr.msg_stats, &attr.rcpt, attr.relay, \ 137 DSN_FROM_DSN_BUF(attr.why) 138 #define BOUNCE_ONE_ATTR(attr) \ 139 attr.queue_name, attr.queue_id, attr.encoding, \ 140 attr.sender, attr.dsn_envid, attr.dsn_ret, \ 141 &attr.msg_stats, &attr.rcpt, attr.relay, \ 142 DSN_FROM_DSN_BUF(attr.why) 143 #define SENT_ATTR(attr) \ 144 attr.queue_id, &attr.msg_stats, &attr.rcpt, attr.relay, \ 145 DSN_FROM_DSN_BUF(attr.why) 146 #define OPENED_ATTR(attr) \ 147 attr.queue_id, attr.sender 148 #define COPY_ATTR(attr) \ 149 attr.sender, attr.rcpt.orig_addr, attr.delivered, attr.fp 150 151 #define MSG_LOG_STATE(m, p) \ 152 msg_info("%s[%d]: local %s recip %s exten %s deliver %s exp_from %s", \ 153 m, \ 154 p.level, \ 155 p.msg_attr.local ? p.msg_attr.local : "" , \ 156 p.msg_attr.rcpt.address ? p.msg_attr.rcpt.address : "", \ 157 p.msg_attr.extension ? p.msg_attr.extension : "", \ 158 p.msg_attr.delivered ? p.msg_attr.delivered : "", \ 159 p.msg_attr.exp_from ? p.msg_attr.exp_from : "") 160 161 /* 162 * "inner" nodes of the delivery graph. 163 */ 164 extern int deliver_recipient(LOCAL_STATE, USER_ATTR); 165 extern int deliver_alias(LOCAL_STATE, USER_ATTR, char *, int *); 166 extern int deliver_dotforward(LOCAL_STATE, USER_ATTR, int *); 167 extern int deliver_include(LOCAL_STATE, USER_ATTR, char *); 168 extern int deliver_token(LOCAL_STATE, USER_ATTR, TOK822 *); 169 extern int deliver_token_string(LOCAL_STATE, USER_ATTR, char *, int *); 170 extern int deliver_token_stream(LOCAL_STATE, USER_ATTR, VSTREAM *, int *); 171 extern int deliver_resolve_tree(LOCAL_STATE, USER_ATTR, TOK822 *); 172 extern int deliver_resolve_addr(LOCAL_STATE, USER_ATTR, char *); 173 174 /* 175 * "leaf" nodes of the delivery graph. 176 */ 177 extern int deliver_mailbox(LOCAL_STATE, USER_ATTR, int *); 178 extern int deliver_command(LOCAL_STATE, USER_ATTR, const char *); 179 extern int deliver_file(LOCAL_STATE, USER_ATTR, char *); 180 extern int deliver_indirect(LOCAL_STATE); 181 extern int deliver_maildir(LOCAL_STATE, USER_ATTR, char *); 182 extern int deliver_unknown(LOCAL_STATE, USER_ATTR); 183 184 /* 185 * Restrictions on delivery to sensitive destinations. 186 */ 187 extern int local_file_deliver_mask; 188 extern int local_cmd_deliver_mask; 189 190 /* 191 * Restrictions on extension propagation. 192 */ 193 extern int local_ext_prop_mask; 194 195 /* 196 * Mailbox lock protocol. 197 */ 198 extern int local_mbox_lock_mask; 199 200 /* 201 * When to prepend a Delivered-To: header upon external delivery. 202 */ 203 #define DELIVER_HDR_CMD (1<<0) 204 #define DELIVER_HDR_FILE (1<<1) 205 #define DELIVER_HDR_FWD (1<<2) 206 207 extern int local_deliver_hdr_mask; 208 209 /* 210 * forward.c 211 */ 212 extern int forward_init(void); 213 extern int forward_append(DELIVER_ATTR); 214 extern int forward_finish(DELIVER_REQUEST *, DELIVER_ATTR, int); 215 216 /* 217 * feature.c 218 */ 219 extern int feature_control(const char *); 220 221 /* 222 * local_expand.c 223 */ 224 int local_expand(VSTRING *, const char *, LOCAL_STATE *, USER_ATTR *, const char *); 225 226 #define LOCAL_EXP_EXTENSION_MATCHED (1<<MAC_PARSE_USER) 227 228 /* 229 * alias.c 230 */ 231 extern MAPS *alias_maps; 232 233 /* 234 * Silly little macros. 235 */ 236 #define STR(s) vstring_str(s) 237 238 /* LICENSE 239 /* .ad 240 /* .fi 241 /* The Secure Mailer license must be distributed with this software. 242 /* AUTHOR(S) 243 /* Wietse Venema 244 /* IBM T.J. Watson Research 245 /* P.O. Box 704 246 /* Yorktown Heights, NY 10598, USA 247 /*--*/ 248