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