Postfix3.3.1
flush_clnt.c
[詳解]
1 /*++
2 /* NAME
3 /* flush_clnt 3
4 /* SUMMARY
5 /* fast flush cache manager client interface
6 /* SYNOPSIS
7 /* #include <flush_clnt.h>
8 /*
9 /* void flush_init()
10 /*
11 /* int flush_add(site, queue_id)
12 /* const char *site;
13 /* const char *queue_id;
14 /*
15 /* int flush_send_site(site)
16 /* const char *site;
17 /*
18 /* int flush_send_file(queue_id)
19 /* const char *queue_id;
20 /*
21 /* int flush_refresh()
22 /*
23 /* int flush_purge()
24 /* DESCRIPTION
25 /* The following routines operate through the "fast flush" service.
26 /* This service maintains a cache of what mail is queued. The cache
27 /* is maintained for eligible destinations. A destination is the
28 /* right-hand side of a user@domain email address.
29 /*
30 /* flush_init() initializes. It must be called before dropping
31 /* privileges in a daemon process.
32 /*
33 /* flush_add() informs the "fast flush" cache manager that mail is
34 /* queued for the specified site with the specified queue ID.
35 /*
36 /* flush_send_site() requests delivery of all mail that is queued for
37 /* the specified destination.
38 /*
39 /* flush_send_file() requests delivery of mail with the specified
40 /* queue ID.
41 /*
42 /* flush_refresh() requests the "fast flush" cache manager to refresh
43 /* cached information that was not used for some configurable amount
44 /* time.
45 /*
46 /* flush_purge() requests the "fast flush" cache manager to refresh
47 /* all cached information. This is incredibly expensive, and is not
48 /* recommended.
49 /* DIAGNOSTICS
50 /* The result codes and their meanings are (see flush_clnt(5h)):
51 /* .IP MAIL_FLUSH_OK
52 /* The request completed successfully (in case of requests that
53 /* complete in the background: the request was accepted by the server).
54 /* .IP MAIL_FLUSH_FAIL
55 /* The request failed (the request could not be sent to the server,
56 /* or the server reported failure).
57 /* .IP MAIL_FLUSH_BAD
58 /* The "fast flush" server rejected the request (invalid request
59 /* parameter).
60 /* .IP MAIL_FLUSH_DENY
61 /* The specified domain is not eligible for "fast flush" service,
62 /* or the "fast flush" service is disabled.
63 /* SEE ALSO
64 /* flush(8) Postfix fast flush cache manager
65 /* LICENSE
66 /* .ad
67 /* .fi
68 /* The Secure Mailer license must be distributed with this software.
69 /* AUTHOR(S)
70 /* Wietse Venema
71 /* IBM T.J. Watson Research
72 /* P.O. Box 704
73 /* Yorktown Heights, NY 10598, USA
74 /*--*/
75 
76 /* System library. */
77 
78 #include "sys_defs.h"
79 #include <unistd.h>
80 #include <stdarg.h>
81 
82 /* Utility library. */
83 
84 #include <msg.h>
85 #include <vstream.h>
86 
87 /* Global library. */
88 
89 #include <mail_proto.h>
90 #include <mail_flush.h>
91 #include <mail_params.h>
92 #include <domain_list.h>
93 #include <match_parent_style.h>
94 #include <flush_clnt.h>
95 
96 /* Application-specific. */
97 
98 #define STR(x) vstring_str(x)
99 
100 static DOMAIN_LIST *flush_domains;
101 
102 /* flush_init - initialize */
103 
104 void flush_init(void)
105 {
109 }
110 
111 /* flush_purge - house keeping */
112 
113 int flush_purge(void)
114 {
115  const char *myname = "flush_purge";
116  int status;
117 
118  if (msg_verbose)
119  msg_info("%s", myname);
120 
121  /*
122  * Don't bother the server if the service is turned off.
123  */
124  if (*var_fflush_domains == 0)
125  status = FLUSH_STAT_DENY;
126  else
129  ATTR_TYPE_END);
130 
131  if (msg_verbose)
132  msg_info("%s: status %d", myname, status);
133 
134  return (status);
135 }
136 
137 /* flush_refresh - house keeping */
138 
139 int flush_refresh(void)
140 {
141  const char *myname = "flush_refresh";
142  int status;
143 
144  if (msg_verbose)
145  msg_info("%s", myname);
146 
147  /*
148  * Don't bother the server if the service is turned off.
149  */
150  if (*var_fflush_domains == 0)
151  status = FLUSH_STAT_DENY;
152  else
155  ATTR_TYPE_END);
156 
157  if (msg_verbose)
158  msg_info("%s: status %d", myname, status);
159 
160  return (status);
161 }
162 
163 /* flush_send_site - deliver mail queued for site */
164 
165 int flush_send_site(const char *site)
166 {
167  const char *myname = "flush_send_site";
168  int status;
169 
170  if (msg_verbose)
171  msg_info("%s: site %s", myname, site);
172 
173  /*
174  * Don't bother the server if the service is turned off, or if the site
175  * is not eligible.
176  */
177  if (flush_domains == 0)
178  msg_panic("missing flush client initialization");
179  if (domain_list_match(flush_domains, site) != 0) {
181  msg_info("using backwards-compatible default setting "
182  VAR_RELAY_DOMAINS "=$mydestination to flush "
183  "mail for domain \"%s\"", site);
187  ATTR_TYPE_END);
188  } else if (flush_domains->error == 0)
189  status = FLUSH_STAT_DENY;
190  else
191  status = FLUSH_STAT_FAIL;
192 
193  if (msg_verbose)
194  msg_info("%s: site %s status %d", myname, site, status);
195 
196  return (status);
197 }
198 
199 /* flush_send_file - deliver specific message */
200 
201 int flush_send_file(const char *queue_id)
202 {
203  const char *myname = "flush_send_file";
204  int status;
205 
206  if (msg_verbose)
207  msg_info("%s: queue_id %s", myname, queue_id);
208 
209  /*
210  * Require that the service is turned on.
211  */
214  SEND_ATTR_STR(MAIL_ATTR_QUEUEID, queue_id),
215  ATTR_TYPE_END);
216 
217  if (msg_verbose)
218  msg_info("%s: queue_id %s status %d", myname, queue_id, status);
219 
220  return (status);
221 }
222 
223 /* flush_add - inform "fast flush" cache manager */
224 
225 int flush_add(const char *site, const char *queue_id)
226 {
227  const char *myname = "flush_add";
228  int status;
229 
230  if (msg_verbose)
231  msg_info("%s: site %s id %s", myname, site, queue_id);
232 
233  /*
234  * Don't bother the server if the service is turned off, or if the site
235  * is not eligible.
236  */
237  if (flush_domains == 0)
238  msg_panic("missing flush client initialization");
239  if (domain_list_match(flush_domains, site) != 0) {
241  msg_info("using backwards-compatible default setting "
242  VAR_RELAY_DOMAINS "=$mydestination to update "
243  "fast-flush logfile for domain \"%s\"", site);
247  SEND_ATTR_STR(MAIL_ATTR_QUEUEID, queue_id),
248  ATTR_TYPE_END);
249  } else if (flush_domains->error == 0)
250  status = FLUSH_STAT_DENY;
251  else
252  status = FLUSH_STAT_FAIL;
253 
254  if (msg_verbose)
255  msg_info("%s: site %s id %s status %d", myname, site, queue_id,
256  status);
257 
258  return (status);
259 }
int msg_verbose
Definition: msg.c:177
#define MATCH_FLAG_RETURN
Definition: match_list.h:40
char * var_fflush_domains
Definition: mail_params.c:287
int match_parent_style(const char *name)
NORETURN msg_panic(const char *fmt,...)
Definition: msg.c:295
#define VAR_RELAY_DOMAINS
Definition: mail_params.h:2048
#define MAIL_ATTR_REQ
Definition: mail_proto.h:124
#define domain_list_match
Definition: domain_list.h:26
#define FLUSH_STAT_FAIL
Definition: flush_clnt.h:36
int flush_purge(void)
Definition: flush_clnt.c:113
#define ATTR_TYPE_END
Definition: attr.h:39
#define DOMAIN_LIST
Definition: domain_list.h:22
void flush_init(void)
Definition: flush_clnt.c:104
int flush_refresh(void)
Definition: flush_clnt.c:139
#define MAIL_CLASS_PUBLIC
Definition: mail_proto.h:95
int flush_add(const char *site, const char *queue_id)
Definition: flush_clnt.c:225
#define FLUSH_REQ_ADD
Definition: flush_clnt.h:27
#define FLUSH_REQ_SEND_SITE
Definition: flush_clnt.h:28
#define FLUSH_REQ_SEND_FILE
Definition: flush_clnt.h:29
int flush_send_file(const char *queue_id)
Definition: flush_clnt.c:201
#define FLUSH_STAT_DENY
Definition: flush_clnt.h:39
int mail_command_client(const char *class, const char *name,...)
#define domain_list_init(o, f, p)
Definition: domain_list.h:24
#define FLUSH_REQ_REFRESH
Definition: flush_clnt.h:30
char * var_flush_service
Definition: mail_params.c:309
#define FLUSH_REQ_PURGE
Definition: flush_clnt.h:31
#define MAIL_ATTR_QUEUEID
Definition: mail_proto.h:130
#define MAIL_ATTR_SITE
Definition: mail_proto.h:137
#define VAR_FFLUSH_DOMAINS
Definition: mail_params.h:2490
#define SEND_ATTR_STR(name, val)
Definition: attr.h:64
int flush_send_site(const char *site)
Definition: flush_clnt.c:165
int warn_compat_break_flush_domains
Definition: mail_params.c:357
void msg_info(const char *fmt,...)
Definition: msg.c:199