23 #include <been_here.h>
25 #include <deliver_request.h>
26 #include <mbox_conf.h>
30 #include <delivered_hdr.h>
33 * User attributes: these control the privileges for delivery to external
34 * commands, external files, or mailboxes, and the initial environment of
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 */
46 * Critical macros. Not for obscurity, but to ensure consistency.
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; \
52 msg_info("%s[%d]: reset user_attr", myname, level); \
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; \
60 msg_info("%s[%d]: set user_attr: %s", \
61 myname, level, pwd->pw_name); \
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
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 */
96 extern void deliver_attr_init(DELIVER_ATTR
*);
97 extern void deliver_attr_dump(DELIVER_ATTR
*);
98 extern void deliver_attr_free(DELIVER_ATTR
*);
100 #define EXPAND_TYPE_ALIAS (1<<0)
101 #define EXPAND_TYPE_FWD (1<<1)
102 #define EXPAND_TYPE_INCL (1<<2)
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.
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 */
117 #define RESET_OWNER_ATTR(msg_attr, level) { \
118 msg_attr.owner = 0; \
120 msg_info("%s[%d]: reset owner attr", myname, level); \
123 #define SET_OWNER_ATTR(msg_attr, who, level) { \
124 msg_attr.sender = msg_attr.owner = who; \
126 msg_info("%s[%d]: set owner attr: %s", \
127 myname, level, who); \
131 * Bundle up some often-user attributes.
133 #define BOUNCE_FLAGS(request) DEL_REQ_TRACE_FLAGS((request)->flags)
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
151 #define MSG_LOG_STATE(m, p) \
152 msg_info("%s[%d]: local %s recip %s exten %s deliver %s exp_from %s", \
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 : "")
162 * "inner" nodes of the delivery graph.
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 *);
175 * "leaf" nodes of the delivery graph.
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
);
185 * Restrictions on delivery to sensitive destinations.
187 extern int local_file_deliver_mask
;
188 extern int local_cmd_deliver_mask
;
191 * Restrictions on extension propagation.
193 extern int local_ext_prop_mask
;
196 * Mailbox lock protocol.
198 extern int local_mbox_lock_mask
;
201 * When to prepend a Delivered-To: header upon external delivery.
203 #define DELIVER_HDR_CMD (1<<0)
204 #define DELIVER_HDR_FILE (1<<1)
205 #define DELIVER_HDR_FWD (1<<2)
207 extern int local_deliver_hdr_mask
;
212 extern int forward_init(void);
213 extern int forward_append(DELIVER_ATTR
);
214 extern int forward_finish(DELIVER_REQUEST
*, DELIVER_ATTR
, int);
219 extern int feature_control(const char *);
224 int local_expand(VSTRING
*, const char *, LOCAL_STATE
*, USER_ATTR
*, const char *);
226 #define LOCAL_EXP_EXTENSION_MATCHED (1<<MAC_PARSE_USER)
231 extern MAPS
*alias_maps
;
234 * Silly little macros.
236 #define STR(s) vstring_str(s)
241 /* The Secure Mailer license must be distributed with this software.
244 /* IBM T.J. Watson Research
246 /* Yorktown Heights, NY 10598, USA