Postfix3.3.1
postconf.h
[詳解]
1 /*++
2 /* NAME
3 /* postconf 3h
4 /* SUMMARY
5 /* module interfaces
6 /* SYNOPSIS
7 /* #include <postconf.h>
8 /* DESCRIPTION
9 /* .nf
10 
11  /*
12  * System library.
13  */
14 #include <unistd.h>
15 
16  /*
17  * Utility library.
18  */
19 #include <htable.h>
20 #include <argv.h>
21 #include <dict.h>
22 #include <name_code.h>
23 
24  /*
25  * What we're supposed to be doing.
26  */
27 #define PCF_SHOW_NONDEF (1<<0) /* show main.cf non-default settings */
28 #define PCF_SHOW_DEFS (1<<1) /* show main.cf default setting */
29 #define PCF_HIDE_NAME (1<<2) /* hide main.cf parameter name */
30 #define PCF_SHOW_MAPS (1<<3) /* show map types */
31 #define PCF_EDIT_CONF (1<<4) /* edit main.cf or master.cf */
32 #define PCF_SHOW_LOCKS (1<<5) /* show mailbox lock methods */
33 #define PCF_SHOW_EVAL (1<<6) /* expand main.cf right-hand sides */
34 #define PCF_SHOW_SASL_SERV (1<<7) /* show server auth plugin types */
35 #define PCF_SHOW_SASL_CLNT (1<<8) /* show client auth plugin types */
36 #define PCF_COMMENT_OUT (1<<9) /* #-out selected main.cf entries */
37 #define PCF_MASTER_ENTRY (1<<10) /* manage master.cf entries */
38 #define PCF_FOLD_LINE (1<<11) /* fold long *.cf entries */
39 #define PCF_EDIT_EXCL (1<<12) /* exclude main.cf entries */
40 #define PCF_MASTER_FLD (1<<13) /* hierarchical pathname */
41 #define PCF_MAIN_PARAM (1<<14) /* manage main.cf entries */
42 #define PCF_EXP_DSN_TEMPL (1<<15) /* expand bounce templates */
43 #define PCF_PARAM_CLASS (1<<16) /* select parameter class */
44 #define PCF_MAIN_OVER (1<<17) /* override parameter values */
45 #define PCF_DUMP_DSN_TEMPL (1<<18) /* show bounce templates */
46 #define PCF_MASTER_PARAM (1<<19) /* manage master.cf -o name=value */
47 #define PCF_HIDE_VALUE (1<<20) /* hide main.cf/master.cf =value */
48 #define PCF_SHOW_TLS (1<<21) /* TLS support introspection */
49 
50 #define PCF_DEF_MODE 0
51 
52  /*
53  * Structure for one "valid parameter" (built-in, service-defined or valid
54  * user-defined). See the postconf_builtin, postconf_service and
55  * postconf_user modules for narrative text.
56  */
57 typedef struct {
58  int flags; /* see below */
59  void *param_data; /* mostly, the default value */
60  const char *(*convert_fn) (void *); /* value to string */
62 
63  /* Values for flags. See the postconf_node module for narrative text. */
64 #define PCF_PARAM_FLAG_RAW (1<<0) /* raw parameter value */
65 #define PCF_PARAM_FLAG_BUILTIN (1<<1) /* built-in parameter name */
66 #define PCF_PARAM_FLAG_SERVICE (1<<2) /* service-defined parameter name */
67 #define PCF_PARAM_FLAG_USER (1<<3) /* user-defined parameter name */
68 #define PCF_PARAM_FLAG_LEGACY (1<<4) /* legacy parameter name */
69 #define PCF_PARAM_FLAG_READONLY (1<<5) /* legacy parameter name */
70 #define PCF_PARAM_FLAG_DBMS (1<<6) /* dbms-defined parameter name */
71 
72 #define PCF_PARAM_MASK_CLASS \
73  (PCF_PARAM_FLAG_BUILTIN | PCF_PARAM_FLAG_SERVICE | PCF_PARAM_FLAG_USER)
74 #define PCF_PARAM_CLASS_OVERRIDE(node, class) \
75  ((node)->flags = (((node)->flags & ~PCF_PARAM_MASK_CLASS) | (class)))
76 
77 #define PCF_RAW_PARAMETER(node) ((node)->flags & PCF_PARAM_FLAG_RAW)
78 #define PCF_BUILTIN_PARAMETER(node) ((node)->flags & PCF_PARAM_FLAG_BUILTIN)
79 #define PCF_SERVICE_PARAMETER(node) ((node)->flags & PCF_PARAM_FLAG_SERVICE)
80 #define PCF_USER_PARAMETER(node) ((node)->flags & PCF_PARAM_FLAG_USER)
81 #define PCF_LEGACY_PARAMETER(node) ((node)->flags & PCF_PARAM_FLAG_LEGACY)
82 #define PCF_READONLY_PARAMETER(node) ((node)->flags & PCF_PARAM_FLAG_READONLY)
83 #define PCF_DBMS_PARAMETER(node) ((node)->flags & PCF_PARAM_FLAG_DBMS)
84 
85  /* Values for param_data. See postconf_node module for narrative text. */
86 #define PCF_PARAM_NO_DATA ((char *) 0)
87 
88  /*
89  * Lookup table for global "valid parameter" information.
90  */
91 #define PCF_PARAM_TABLE HTABLE
92 #define PCF_PARAM_INFO HTABLE_INFO
93 
95 
96  /*
97  * postconf_node.c.
98  */
99 #define PCF_PARAM_TABLE_CREATE(size) htable_create(size);
100 #define PCF_PARAM_NODE_CAST(ptr) ((PCF_PARAM_NODE *) (ptr))
101 
102 #define PCF_PARAM_TABLE_LIST(table) htable_list(table)
103 #define PCF_PARAM_INFO_NAME(ht) ((const char *) (ht)->key)
104 #define PCF_PARAM_INFO_NODE(ht) PCF_PARAM_NODE_CAST((ht)->value)
105 
106 #define PCF_PARAM_TABLE_FIND(table, name) \
107  PCF_PARAM_NODE_CAST(htable_find((table), (name)))
108 #define PCF_PARAM_TABLE_LOCATE(table, name) htable_locate((table), (name))
109 #define PCF_PARAM_TABLE_ENTER(table, name, flags, data, func) \
110  htable_enter((table), (name), (char *) pcf_make_param_node((flags), \
111  (data), (func)))
112 
113 extern PCF_PARAM_NODE *pcf_make_param_node(int, void *, const char *(*) (void *));
114 extern const char *pcf_convert_param_node(int, const char *, PCF_PARAM_NODE *);
116 
117  /*
118  * Structure of one master.cf entry.
119  */
120 typedef struct {
121  char *name_space; /* service/type, parameter name space */
122  ARGV *argv; /* null, or master.cf fields */
123  DICT *all_params; /* null, or all name=value entries */
124  DICT *ro_params; /* read-only name=value entries */
125  HTABLE *valid_names; /* null, or "valid" parameter names */
127 
128 #define PCF_MASTER_MIN_FIELDS 8 /* mandatory field minimum */
129 
130 #define PCF_MASTER_NAME_SERVICE "service"
131 #define PCF_MASTER_NAME_TYPE "type"
132 #define PCF_MASTER_NAME_PRIVATE "private"
133 #define PCF_MASTER_NAME_UNPRIV "unprivileged"
134 #define PCF_MASTER_NAME_CHROOT "chroot"
135 #define PCF_MASTER_NAME_WAKEUP "wakeup"
136 #define PCF_MASTER_NAME_MAXPROC "process_limit"
137 #define PCF_MASTER_NAME_CMD "command"
138 
139 #define PCF_MASTER_FLD_SERVICE 0 /* service name */
140 #define PCF_MASTER_FLD_TYPE 1 /* service type */
141 #define PCF_MASTER_FLD_PRIVATE 2 /* private service */
142 #define PCF_MASTER_FLD_UNPRIV 3 /* unprivileged service */
143 #define PCF_MASTER_FLD_CHROOT 4 /* chrooted service */
144 #define PCF_MASTER_FLD_WAKEUP 5 /* wakeup timer */
145 #define PCF_MASTER_FLD_MAXPROC 6 /* process limit */
146 #define PCF_MASTER_FLD_CMD 7 /* command */
147 
148 #define PCF_MASTER_FLD_WILDC -1 /* wild-card */
149 #define PCF_MASTER_FLD_NONE -2 /* not available */
150 
151  /*
152  * Lookup table for master.cf entries. The table is terminated with an entry
153  * that has a null argv member.
154  */
156 
157  /*
158  * Line-wrapping support.
159  */
160 #define PCF_LINE_LIMIT 80 /* try to fold longer lines */
161 #define PCF_SEPARATORS " \t\r\n"
162 #define PCF_INDENT_LEN 4 /* indent long text by 4 */
163 #define PCF_INDENT_TEXT " "
164 
165  /*
166  * XXX Global so that postconf_builtin.c call-backs can see it.
167  */
168 extern int pcf_cmd_mode;
169 
170  /*
171  * postconf_misc.c.
172  */
173 extern void pcf_set_config_dir(void);
174 
175  /*
176  * postconf_main.c
177  */
178 extern void pcf_read_parameters(void);
179 extern void pcf_set_parameters(char **);
180 extern void pcf_show_parameters(VSTREAM *, int, int, char **);
181 
182  /*
183  * postconf_edit.c
184  */
185 extern void pcf_edit_main(int, int, char **);
186 extern void pcf_edit_master(int, int, char **);
187 
188  /*
189  * postconf_master.c.
190  */
191 extern const char pcf_daemon_options_expecting_value[];
192 extern void pcf_read_master(int);
193 extern void pcf_show_master_entries(VSTREAM *, int, int, char **);
194 extern const char *pcf_parse_master_entry(PCF_MASTER_ENT *, const char *);
195 extern void pcf_print_master_entry(VSTREAM *, int, PCF_MASTER_ENT *);
197 extern void pcf_show_master_fields(VSTREAM *, int, int, char **);
198 extern void pcf_edit_master_field(PCF_MASTER_ENT *, int, const char *);
199 extern void pcf_show_master_params(VSTREAM *, int, int, char **);
200 extern void pcf_edit_master_param(PCF_MASTER_ENT *, int, const char *, const char *);
201 
202 #define PCF_WARN_ON_OPEN_ERROR 0
203 #define PCF_FAIL_ON_OPEN_ERROR 1
204 
205 #define PCF_MASTER_BLANKS " \t\r\n" /* XXX */
206 
207  /*
208  * Master.cf parameter namespace management. The idea is to manage master.cf
209  * "-o name=value" settings with other tools than text editors.
210  *
211  * The natural choice is to use "service-name.service-type.parameter-name", but
212  * unfortunately the '.' may appear in service and parameter names.
213  *
214  * For example, a spawn(8) listener can have a service name 127.0.0.1:10028.
215  * This service name becomes part of a service-dependent parameter name
216  * "127.0.0.1:10028_time_limit". All those '.' characters mean we can't use
217  * '.' as the parameter namespace delimiter.
218  *
219  * (We could require that such service names are specified as $foo:port with
220  * the value of "foo" defined in main.cf or at the top of master.cf.)
221  *
222  * But it is easier if we use '/' instead.
223  */
224 #define PCF_NAMESP_SEP_CH '/'
225 #define PCF_NAMESP_SEP_STR "/"
226 
227 #define PCF_LEGACY_SEP_CH '.'
228 
229  /*
230  * postconf_match.c.
231  */
232 #define PCF_MATCH_WILDC_STR "*"
233 #define PCF_MATCH_ANY(p) ((p)[0] == PCF_MATCH_WILDC_STR[0] && (p)[1] == 0)
234 #define PCF_MATCH_STRING(p, s) (PCF_MATCH_ANY(p) || strcmp((p), (s)) == 0)
235 
236 extern ARGV *pcf_parse_service_pattern(const char *, int, int);
237 extern int pcf_parse_field_pattern(const char *);
238 
239 #define PCF_IS_MAGIC_SERVICE_PATTERN(pat) \
240  (PCF_MATCH_ANY((pat)->argv[0]) || PCF_MATCH_ANY((pat)->argv[1]))
241 #define PCF_MATCH_SERVICE_PATTERN(pat, name, type) \
242  (PCF_MATCH_STRING((pat)->argv[0], (name)) \
243  && PCF_MATCH_STRING((pat)->argv[1], (type)))
244 
245 #define pcf_is_magic_field_pattern(pat) ((pat) == PCF_MASTER_FLD_WILDC)
246 #define pcf_str_field_pattern(pat) ((const char *) (pcf_field_name_offset[pat].name))
247 
248 #define PCF_IS_MAGIC_PARAM_PATTERN(pat) PCF_MATCH_ANY(pat)
249 #define PCF_MATCH_PARAM_PATTERN(pat, name) PCF_MATCH_STRING((pat), (name))
250 
251 /* The following is not part of the postconf_match API. */
253 
254  /*
255  * postconf_builtin.c.
256  */
257 extern void pcf_register_builtin_parameters(const char *, pid_t);
258 
259  /*
260  * postconf_service.c.
261  */
262 extern void pcf_register_service_parameters(void);
263 
264  /*
265  * Parameter context structure.
266  */
267 typedef struct {
270 } PCF_PARAM_CTX;
271 
272  /*
273  * postconf_user.c.
274  */
275 extern void pcf_register_user_parameters(void);
276 
277  /*
278  * postconf_dbms.c
279  */
280 extern void pcf_register_dbms_parameters(const char *,
281  const char *(*) (const char *, int, PCF_MASTER_ENT *),
282  PCF_MASTER_ENT *);
283 
284  /*
285  * postconf_lookup.c.
286  */
287 extern const char *pcf_lookup_parameter_value(int, const char *,
288  PCF_MASTER_ENT *,
289  PCF_PARAM_NODE *);
290 
291 extern char *pcf_expand_parameter_value(VSTRING *, int, const char *,
292  PCF_MASTER_ENT *);
293 
294  /*
295  * postconf_print.c.
296  */
297 extern void PRINTFLIKE(3, 4) pcf_print_line(VSTREAM *, int, const char *,...);
298 
299  /*
300  * postconf_unused.c.
301  */
302 extern void pcf_flag_unused_main_parameters(void);
303 extern void pcf_flag_unused_master_parameters(void);
304 
305  /*
306  * postconf_other.c.
307  */
308 extern void pcf_show_maps(void);
309 extern void pcf_show_locks(void);
310 extern void pcf_show_sasl(int);
311 extern void pcf_show_tls(const char *);
312 
313 /* LICENSE
314 /* .ad
315 /* .fi
316 /* The Secure Mailer license must be distributed with this software.
317 /* AUTHOR(S)
318 /* Wietse Venema
319 /* IBM T.J. Watson Research
320 /* P.O. Box 704
321 /* Yorktown Heights, NY 10598, USA
322 /*
323 /* Wietse Venema
324 /* Google, Inc.
325 /* 111 8th Avenue
326 /* New York, NY 10011, USA
327 /*--*/
char * name_space
Definition: postconf.h:121
void pcf_register_builtin_parameters(const char *, pid_t)
DICT * all_params
Definition: postconf.h:123
int param_class
Definition: postconf.h:269
PCF_MASTER_ENT * pcf_master_table
Definition: postconf.h:155
void * param_data
Definition: postconf.h:59
void pcf_edit_master_field(PCF_MASTER_ENT *, int, const char *)
Definition: argv.h:17
ARGV * pcf_parse_service_pattern(const char *, int, int)
void pcf_set_parameters(char **)
char * pcf_expand_parameter_value(VSTRING *, int, const char *, PCF_MASTER_ENT *)
void const char void pcf_flag_unused_main_parameters(void)
void pcf_show_master_params(VSTREAM *, int, int, char **)
void pcf_edit_master(int, int, char **)
PCF_MASTER_ENT * local_scope
Definition: postconf.h:268
Definition: htable.h:25
void pcf_show_master_fields(VSTREAM *, int, int, char **)
const char pcf_daemon_options_expecting_value[]
void pcf_print_master_entry(VSTREAM *, int, PCF_MASTER_ENT *)
void pcf_free_master_entry(PCF_MASTER_ENT *)
void pcf_show_sasl(int)
Definition: dict.h:78
void pcf_read_master(int)
HTABLE * valid_names
Definition: postconf.h:125
ARGV * argv
Definition: postconf.h:122
void pcf_show_locks(void)
DICT * ro_params
Definition: postconf.h:124
void PRINTFLIKE(3, 4) pcf_print_line(VSTREAM *
const char * pcf_convert_param_node(int, const char *, PCF_PARAM_NODE *)
const char * pcf_lookup_parameter_value(int, const char *, PCF_MASTER_ENT *, PCF_PARAM_NODE *)
void pcf_register_dbms_parameters(const char *, const char *(*)(const char *, int, PCF_MASTER_ENT *), PCF_MASTER_ENT *)
#define PCF_PARAM_TABLE
Definition: postconf.h:91
void pcf_read_parameters(void)
int pcf_parse_field_pattern(const char *)
void pcf_edit_main(int, int, char **)
void pcf_show_maps(void)
VSTRING * pcf_param_string_buf
void pcf_flag_unused_master_parameters(void)
void pcf_show_parameters(VSTREAM *, int, int, char **)
PCF_PARAM_TABLE * pcf_param_table
Definition: postconf.c:610
void pcf_set_config_dir(void)
Definition: postconf_misc.c:48
PCF_PARAM_NODE * pcf_make_param_node(int, void *, const char *(*)(void *))
void pcf_edit_master_param(PCF_MASTER_ENT *, int, const char *, const char *)
void pcf_register_user_parameters(void)
const char * pcf_parse_master_entry(PCF_MASTER_ENT *, const char *)
void pcf_print_line(VSTREAM *fp, int mode, const char *fmt,...)
void pcf_show_master_entries(VSTREAM *, int, int, char **)
int pcf_cmd_mode
Definition: postconf.c:612
NAME_CODE pcf_field_name_offset[]
void pcf_register_service_parameters(void)
void pcf_show_tls(const char *)