Postfix3.3.1
virtual.h
[詳解]
1 /*++
2 /* NAME
3 /* virtual 3h
4 /* SUMMARY
5 /* virtual mail delivery
6 /* SYNOPSIS
7 /* #include "virtual.h"
8 /* DESCRIPTION
9 /* .nf
10 
11  /*
12  * System library.
13  */
14 #include <unistd.h>
15 
16  /*
17  * Utility library.
18  */
19 #include <vstream.h>
20 #include <vstring.h>
21 
22  /*
23  * Global library.
24  */
25 #include <deliver_request.h>
26 #include <maps.h>
27 #include <mbox_conf.h>
28 #include <dsn_buf.h>
29 #include <dsn.h>
30 
31  /*
32  * Mappings.
33  */
35 extern MAPS *virtual_uid_maps;
36 extern MAPS *virtual_gid_maps;
37 
38  /*
39  * User attributes: these control the privileges for delivery to external
40  * commands, external files, or mailboxes, and the initial environment of
41  * external commands.
42  */
43 typedef struct USER_ATTR {
44  uid_t uid; /* file/command access */
45  gid_t gid; /* file/command access */
46  char *mailbox; /* mailbox file or directory */
47 } USER_ATTR;
48 
49  /*
50  * Critical macros. Not for obscurity, but to ensure consistency.
51  */
52 #define RESET_USER_ATTR(usr_attr, level) { \
53  usr_attr.uid = 0; usr_attr.gid = 0; usr_attr.mailbox = 0; \
54  if (msg_verbose) \
55  msg_info("%s[%d]: reset user_attr", myname, level); \
56  }
57 
58  /*
59  * The delivery attributes are inherited from files, from aliases, and from
60  * whatnot. Some of the information is changed on the fly. DELIVER_ATTR
61  * structures are therefore passed by value, so there is no need to undo
62  * changes.
63  */
64 typedef struct DELIVER_ATTR {
65  int level; /* recursion level */
66  VSTREAM *fp; /* open queue file */
67  char *queue_name; /* mail queue id */
68  char *queue_id; /* mail queue id */
69  long offset; /* data offset */
70  const char *sender; /* taken from envelope */
71  char *dsn_envid; /* DSN envelope ID */
72  int dsn_ret; /* DSN headers/full */
73  RECIPIENT rcpt; /* from delivery request */
74  char *user; /* recipient lookup handle */
75  const char *delivered; /* for loop detection */
76  char *relay; /* relay host */
77  MSG_STATS msg_stats; /* time profile */
78  DSN_BUF *why; /* delivery status */
79 } DELIVER_ATTR;
80 
81 extern void deliver_attr_init(DELIVER_ATTR *);
82 extern void deliver_attr_dump(DELIVER_ATTR *);
83 extern void deliver_attr_free(DELIVER_ATTR *);
84 
85 #define FEATURE_NODELIVERED (1<<0) /* no delivered-to */
86 
87  /*
88  * Rather than schlepping around dozens of arguments, here is one that has
89  * all. Well, almost. The user attributes are just a bit too sensitive, so
90  * they are passed around separately.
91  */
92 typedef struct LOCAL_STATE {
93  int level; /* nesting level, for logging */
94  DELIVER_ATTR msg_attr; /* message/recipient attributes */
95  DELIVER_REQUEST *request; /* as from queue manager */
96 } LOCAL_STATE;
97 
98  /*
99  * Bundle up some often-user attributes.
100  */
101 #define BOUNCE_FLAGS(request) DEL_REQ_TRACE_FLAGS((request)->flags)
102 
103 #define BOUNCE_ATTR(attr) \
104  attr.queue_id, &attr.msg_stats, &attr.rcpt, attr.relay, \
105  DSN_FROM_DSN_BUF(attr.why)
106 #define SENT_ATTR(attr) \
107  attr.queue_id, &attr.msg_stats, &attr.rcpt, attr.relay, \
108  DSN_FROM_DSN_BUF(attr.why)
109 #define COPY_ATTR(attr) \
110  attr.sender, attr.rcpt.orig_addr, attr.delivered, attr.fp
111 
112 #define MSG_LOG_STATE(m, p) \
113  msg_info("%s[%d]: recip %s deliver %s", m, \
114  p.level, \
115  p.msg_attr.rcpt.address ? p.msg_attr.rcpt.address : "", \
116  p.msg_attr.delivered ? p.msg_attr.delivered : "")
117 
118  /*
119  * "inner" nodes of the delivery graph.
120  */
122 
123  /*
124  * "leaf" nodes of the delivery graph.
125  */
126 extern int deliver_mailbox(LOCAL_STATE, USER_ATTR, int *);
127 extern int deliver_file(LOCAL_STATE, USER_ATTR, char *);
129 extern int deliver_unknown(LOCAL_STATE);
130 
131  /*
132  * Mailbox lock protocol.
133  */
134 extern int virtual_mbox_lock_mask;
135 
136  /*
137  * Silly little macros.
138  */
139 #define STR(s) vstring_str(s)
140 
141 /* LICENSE
142 /* .ad
143 /* .fi
144 /* The Secure Mailer license must be distributed with this software.
145 /* AUTHOR(S)
146 /* Wietse Venema
147 /* IBM T.J. Watson Research
148 /* P.O. Box 704
149 /* Yorktown Heights, NY 10598, USA
150 /*--*/
int deliver_file(LOCAL_STATE, USER_ATTR, char *)
Definition: file.c:82
void deliver_attr_init(DELIVER_ATTR *)
Definition: deliver_attr.c:53
int deliver_maildir(LOCAL_STATE, USER_ATTR)
Definition: maildir.c:73
Definition: maps.h:22
struct USER_ATTR USER_ATTR
DELIVER_REQUEST * request
Definition: local.h:113
char * queue_name
Definition: local.h:71
int deliver_unknown(LOCAL_STATE)
Definition: unknown.c:50
char * user
Definition: local.h:82
int dsn_ret
Definition: local.h:78
char * mailbox
Definition: virtual.h:46
DELIVER_ATTR msg_attr
Definition: local.h:110
char * dsn_envid
Definition: local.h:77
MAPS * virtual_mailbox_maps
Definition: virtual.c:363
int deliver_recipient(LOCAL_STATE, USER_ATTR)
Definition: recipient.c:206
struct DELIVER_ATTR DELIVER_ATTR
VSTREAM * fp
Definition: local.h:70
gid_t gid
Definition: local.h:37
DSN_BUF * why
Definition: local.h:92
int level
Definition: local.h:69
const char * delivered
Definition: local.h:86
int level
Definition: local.h:109
MAPS * virtual_uid_maps
Definition: virtual.c:364
char * queue_id
Definition: local.h:72
uid_t uid
Definition: local.h:36
char * relay
Definition: local.h:87
void deliver_attr_dump(DELIVER_ATTR *)
Definition: deliver_attr.c:77
void deliver_attr_free(DELIVER_ATTR *)
Definition: deliver_attr.c:102
const char * sender
Definition: local.h:76
MSG_STATS msg_stats
Definition: local.h:88
int deliver_mailbox(LOCAL_STATE, USER_ATTR, int *)
Definition: mailbox.c:250
MAPS * virtual_gid_maps
Definition: virtual.c:365
struct LOCAL_STATE LOCAL_STATE
RECIPIENT rcpt
Definition: local.h:79
long offset
Definition: local.h:73
int virtual_mbox_lock_mask
Definition: virtual.c:370