~ubuntu-branches/ubuntu/vivid/postfix/vivid-proposed

« back to all changes in this revision

Viewing changes to src/postconf/postconf_builtin.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2012-03-20 13:47:16 UTC
  • mfrom: (1.1.33)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: package-import@ubuntu.com-20120320134716-v7ab94fmor2z9pvp
Tags: upstream-2.9.1
ImportĀ upstreamĀ versionĀ 2.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*++
 
2
/* NAME
 
3
/*      postconf_builtin 3
 
4
/* SUMMARY
 
5
/*      built-in parameter support
 
6
/* SYNOPSIS
 
7
/*      #include <postconf.h>
 
8
/*
 
9
/*      void    register_builtin_parameters()
 
10
/* DESCRIPTION
 
11
/*      register_builtin_parameters() initializes the global parameter
 
12
/*      name space and adds all built-in parameter information.
 
13
/* DIAGNOSTICS
 
14
/*      Problems are reported to the standard error stream.
 
15
/* LICENSE
 
16
/* .ad
 
17
/* .fi
 
18
/*      The Secure Mailer license must be distributed with this software.
 
19
/* AUTHOR(S)
 
20
/*      Wietse Venema
 
21
/*      IBM T.J. Watson Research
 
22
/*      P.O. Box 704
 
23
/*      Yorktown Heights, NY 10598, USA
 
24
/*--*/
 
25
 
 
26
/* System library. */
 
27
 
 
28
#include <sys_defs.h>
 
29
#include <string.h>
 
30
 
 
31
#ifdef USE_PATHS_H
 
32
#include <paths.h>
 
33
#endif
 
34
 
 
35
/* Utility library. */
 
36
 
 
37
#include <msg.h>
 
38
#include <mymalloc.h>
 
39
#include <htable.h>
 
40
#include <vstring.h>
 
41
#include <get_hostname.h>
 
42
#include <stringops.h>
 
43
 
 
44
/* Global library. */
 
45
 
 
46
#include <mynetworks.h>
 
47
#include <mail_conf.h>
 
48
#include <mail_params.h>
 
49
#include <mail_version.h>
 
50
#include <mail_proto.h>
 
51
#include <mail_addr.h>
 
52
#include <inet_proto.h>
 
53
#include <server_acl.h>
 
54
 
 
55
/* Application-specific. */
 
56
 
 
57
#include <postconf.h>
 
58
 
 
59
 /*
 
60
  * Support for built-in parameters: declarations generated by scanning
 
61
  * actual C source files.
 
62
  */
 
63
#include "time_vars.h"
 
64
#include "bool_vars.h"
 
65
#include "int_vars.h"
 
66
#include "str_vars.h"
 
67
#include "raw_vars.h"
 
68
#include "nint_vars.h"
 
69
#include "nbool_vars.h"
 
70
#include "long_vars.h"
 
71
 
 
72
 /*
 
73
  * Support for built-in parameters: manually extracted.
 
74
  */
 
75
#include "install_vars.h"
 
76
 
 
77
 /*
 
78
  * Support for built-in parameters: lookup tables generated by scanning
 
79
  * actual C source files.
 
80
  */
 
81
static const CONFIG_TIME_TABLE time_table[] = {
 
82
#include "time_table.h"
 
83
    0,
 
84
};
 
85
 
 
86
static const CONFIG_BOOL_TABLE bool_table[] = {
 
87
#include "bool_table.h"
 
88
    0,
 
89
};
 
90
 
 
91
static const CONFIG_INT_TABLE int_table[] = {
 
92
#include "int_table.h"
 
93
    0,
 
94
};
 
95
 
 
96
static const CONFIG_STR_TABLE str_table[] = {
 
97
#include "str_table.h"
 
98
#include "install_table.h"
 
99
    0,
 
100
};
 
101
 
 
102
static const CONFIG_RAW_TABLE raw_table[] = {
 
103
#include "raw_table.h"
 
104
    0,
 
105
};
 
106
 
 
107
static const CONFIG_NINT_TABLE nint_table[] = {
 
108
#include "nint_table.h"
 
109
    0,
 
110
};
 
111
 
 
112
static const CONFIG_NBOOL_TABLE nbool_table[] = {
 
113
#include "nbool_table.h"
 
114
    0,
 
115
};
 
116
 
 
117
static const CONFIG_LONG_TABLE long_table[] = {
 
118
#include "long_table.h"
 
119
    0,
 
120
};
 
121
 
 
122
 /*
 
123
  * Parameters with default values obtained via function calls.
 
124
  */
 
125
char   *var_myhostname;
 
126
char   *var_mydomain;
 
127
char   *var_mynetworks;
 
128
 
 
129
static const char *check_myhostname(void);
 
130
static const char *check_mydomainname(void);
 
131
static const char *check_mynetworks(void);
 
132
 
 
133
static const CONFIG_STR_FN_TABLE str_fn_table[] = {
 
134
    VAR_MYHOSTNAME, check_myhostname, &var_myhostname, 1, 0,
 
135
    VAR_MYDOMAIN, check_mydomainname, &var_mydomain, 1, 0,
 
136
    0,
 
137
};
 
138
static const CONFIG_STR_FN_TABLE str_fn_table_2[] = {
 
139
    VAR_MYNETWORKS, check_mynetworks, &var_mynetworks, 1, 0,
 
140
    0,
 
141
};
 
142
 
 
143
#define STR(x) vstring_str(x)
 
144
 
 
145
/* check_myhostname - lookup hostname and validate */
 
146
 
 
147
static const char *check_myhostname(void)
 
148
{
 
149
    static const char *name;
 
150
    const char *dot;
 
151
    const char *domain;
 
152
 
 
153
    /*
 
154
     * Use cached result.
 
155
     */
 
156
    if (name)
 
157
        return (name);
 
158
 
 
159
    /*
 
160
     * If the local machine name is not in FQDN form, try to append the
 
161
     * contents of $mydomain.
 
162
     */
 
163
    name = get_hostname();
 
164
    if ((dot = strchr(name, '.')) == 0) {
 
165
        if ((domain = mail_conf_lookup_eval(VAR_MYDOMAIN)) == 0)
 
166
            domain = DEF_MYDOMAIN;
 
167
        name = concatenate(name, ".", domain, (char *) 0);
 
168
    }
 
169
    return (name);
 
170
}
 
171
 
 
172
/* get_myhostname - look up and store my hostname */
 
173
 
 
174
static void get_myhostname(void)
 
175
{
 
176
    const char *name;
 
177
 
 
178
    if ((name = mail_conf_lookup_eval(VAR_MYHOSTNAME)) == 0)
 
179
        name = check_myhostname();
 
180
    var_myhostname = mystrdup(name);
 
181
}
 
182
 
 
183
/* check_mydomainname - lookup domain name and validate */
 
184
 
 
185
static const char *check_mydomainname(void)
 
186
{
 
187
    char   *dot;
 
188
 
 
189
    /*
 
190
     * Use the hostname when it is not a FQDN ("foo"), or when the hostname
 
191
     * actually is a domain name ("foo.com").
 
192
     */
 
193
    if (var_myhostname == 0)
 
194
        get_myhostname();
 
195
    if ((dot = strchr(var_myhostname, '.')) == 0 || strchr(dot + 1, '.') == 0)
 
196
        return (DEF_MYDOMAIN);
 
197
    return (dot + 1);
 
198
}
 
199
 
 
200
/* check_mynetworks - lookup network address list */
 
201
 
 
202
static const char *check_mynetworks(void)
 
203
{
 
204
    INET_PROTO_INFO *proto_info;
 
205
    const char *junk;
 
206
 
 
207
    if (var_inet_interfaces == 0) {
 
208
        if ((cmd_mode & SHOW_DEFS)
 
209
            || (junk = mail_conf_lookup_eval(VAR_INET_INTERFACES)) == 0)
 
210
            junk = DEF_INET_INTERFACES;
 
211
        var_inet_interfaces = mystrdup(junk);
 
212
    }
 
213
    if (var_mynetworks_style == 0) {
 
214
        if ((cmd_mode & SHOW_DEFS)
 
215
            || (junk = mail_conf_lookup_eval(VAR_MYNETWORKS_STYLE)) == 0)
 
216
            junk = DEF_MYNETWORKS_STYLE;
 
217
        var_mynetworks_style = mystrdup(junk);
 
218
    }
 
219
    if (var_inet_protocols == 0) {
 
220
        if ((cmd_mode & SHOW_DEFS)
 
221
            || (junk = mail_conf_lookup_eval(VAR_INET_PROTOCOLS)) == 0)
 
222
            junk = DEF_INET_PROTOCOLS;
 
223
        var_inet_protocols = mystrdup(junk);
 
224
        proto_info = inet_proto_init(VAR_INET_PROTOCOLS, var_inet_protocols);
 
225
    }
 
226
    return (mynetworks());
 
227
}
 
228
 
 
229
/* convert_bool_parameter - get boolean parameter string value */
 
230
 
 
231
static const char *convert_bool_parameter(char *ptr)
 
232
{
 
233
    CONFIG_BOOL_TABLE *cbt = (CONFIG_BOOL_TABLE *) ptr;
 
234
 
 
235
    return (cbt->defval ? "yes" : "no");
 
236
}
 
237
 
 
238
/* convert_time_parameter - get relative time parameter string value */
 
239
 
 
240
static const char *convert_time_parameter(char *ptr)
 
241
{
 
242
    CONFIG_TIME_TABLE *ctt = (CONFIG_TIME_TABLE *) ptr;
 
243
 
 
244
    return (ctt->defval);
 
245
}
 
246
 
 
247
/* convert_int_parameter - get integer parameter string value */
 
248
 
 
249
static const char *convert_int_parameter(char *ptr)
 
250
{
 
251
    CONFIG_INT_TABLE *cit = (CONFIG_INT_TABLE *) ptr;
 
252
 
 
253
    return (STR(vstring_sprintf(param_string_buf, "%d", cit->defval)));
 
254
}
 
255
 
 
256
/* convert_str_parameter - get string parameter string value */
 
257
 
 
258
static const char *convert_str_parameter(char *ptr)
 
259
{
 
260
    CONFIG_STR_TABLE *cst = (CONFIG_STR_TABLE *) ptr;
 
261
 
 
262
    return (cst->defval);
 
263
}
 
264
 
 
265
/* convert_str_fn_parameter - get string-function parameter string value */
 
266
 
 
267
static const char *convert_str_fn_parameter(char *ptr)
 
268
{
 
269
    CONFIG_STR_FN_TABLE *cft = (CONFIG_STR_FN_TABLE *) ptr;
 
270
 
 
271
    return (cft->defval());
 
272
}
 
273
 
 
274
/* convert_raw_parameter - get raw string parameter string value */
 
275
 
 
276
static const char *convert_raw_parameter(char *ptr)
 
277
{
 
278
    CONFIG_RAW_TABLE *rst = (CONFIG_RAW_TABLE *) ptr;
 
279
 
 
280
    return (rst->defval);
 
281
}
 
282
 
 
283
/* convert_nint_parameter - get new integer parameter string value */
 
284
 
 
285
static const char *convert_nint_parameter(char *ptr)
 
286
{
 
287
    CONFIG_NINT_TABLE *rst = (CONFIG_NINT_TABLE *) ptr;
 
288
 
 
289
    return (rst->defval);
 
290
}
 
291
 
 
292
/* convert_nbool_parameter - get new boolean parameter string value */
 
293
 
 
294
static const char *convert_nbool_parameter(char *ptr)
 
295
{
 
296
    CONFIG_NBOOL_TABLE *bst = (CONFIG_NBOOL_TABLE *) ptr;
 
297
 
 
298
    return (bst->defval);
 
299
}
 
300
 
 
301
/* convert_long_parameter - get long parameter string value */
 
302
 
 
303
static const char *convert_long_parameter(char *ptr)
 
304
{
 
305
    CONFIG_LONG_TABLE *clt = (CONFIG_LONG_TABLE *) ptr;
 
306
 
 
307
    return (STR(vstring_sprintf(param_string_buf, "%ld", clt->defval)));
 
308
}
 
309
 
 
310
/* register_builtin_parameters - add built-ins to the global name space */
 
311
 
 
312
void    register_builtin_parameters(void)
 
313
{
 
314
    const char *myname = "register_builtin_parameters";
 
315
    const CONFIG_TIME_TABLE *ctt;
 
316
    const CONFIG_BOOL_TABLE *cbt;
 
317
    const CONFIG_INT_TABLE *cit;
 
318
    const CONFIG_STR_TABLE *cst;
 
319
    const CONFIG_STR_FN_TABLE *cft;
 
320
    const CONFIG_RAW_TABLE *rst;
 
321
    const CONFIG_NINT_TABLE *nst;
 
322
    const CONFIG_NBOOL_TABLE *bst;
 
323
    const CONFIG_LONG_TABLE *lst;
 
324
 
 
325
    /*
 
326
     * Sanity checks.
 
327
     */
 
328
    if (param_table != 0)
 
329
        msg_panic("%s: global parameter table is already initialized", myname);
 
330
 
 
331
    /*
 
332
     * Initialize the global parameter table.
 
333
     */
 
334
    param_table = PC_PARAM_TABLE_CREATE(100);
 
335
 
 
336
    /*
 
337
     * Add the built-in parameters to the global name space. The class
 
338
     * (built-in) is tentative; some parameters are actually service-defined,
 
339
     * but they have their own default value.
 
340
     */
 
341
    for (ctt = time_table; ctt->name; ctt++)
 
342
        PC_PARAM_TABLE_ENTER(param_table, ctt->name, PC_PARAM_FLAG_BUILTIN,
 
343
                             (char *) ctt, convert_time_parameter);
 
344
    for (cbt = bool_table; cbt->name; cbt++)
 
345
        PC_PARAM_TABLE_ENTER(param_table, cbt->name, PC_PARAM_FLAG_BUILTIN,
 
346
                             (char *) cbt, convert_bool_parameter);
 
347
    for (cit = int_table; cit->name; cit++)
 
348
        PC_PARAM_TABLE_ENTER(param_table, cit->name, PC_PARAM_FLAG_BUILTIN,
 
349
                             (char *) cit, convert_int_parameter);
 
350
    for (cst = str_table; cst->name; cst++)
 
351
        PC_PARAM_TABLE_ENTER(param_table, cst->name, PC_PARAM_FLAG_BUILTIN,
 
352
                             (char *) cst, convert_str_parameter);
 
353
    for (cft = str_fn_table; cft->name; cft++)
 
354
        PC_PARAM_TABLE_ENTER(param_table, cft->name, PC_PARAM_FLAG_BUILTIN,
 
355
                             (char *) cft, convert_str_fn_parameter);
 
356
    for (cft = str_fn_table_2; cft->name; cft++)
 
357
        PC_PARAM_TABLE_ENTER(param_table, cft->name, PC_PARAM_FLAG_BUILTIN,
 
358
                             (char *) cft, convert_str_fn_parameter);
 
359
    for (rst = raw_table; rst->name; rst++)
 
360
        PC_PARAM_TABLE_ENTER(param_table, rst->name,
 
361
                             PC_PARAM_FLAG_BUILTIN | PC_PARAM_FLAG_RAW,
 
362
                             (char *) rst, convert_raw_parameter);
 
363
    for (nst = nint_table; nst->name; nst++)
 
364
        PC_PARAM_TABLE_ENTER(param_table, nst->name, PC_PARAM_FLAG_BUILTIN,
 
365
                             (char *) nst, convert_nint_parameter);
 
366
    for (bst = nbool_table; bst->name; bst++)
 
367
        PC_PARAM_TABLE_ENTER(param_table, bst->name, PC_PARAM_FLAG_BUILTIN,
 
368
                             (char *) bst, convert_nbool_parameter);
 
369
    for (lst = long_table; lst->name; lst++)
 
370
        PC_PARAM_TABLE_ENTER(param_table, lst->name, PC_PARAM_FLAG_BUILTIN,
 
371
                             (char *) lst, convert_long_parameter);
 
372
}