5
/* global configuration parameter management
7
/* #include <mail_conf.h>
9
/* void mail_conf_read()
11
/* void mail_conf_suck()
13
/* void mail_conf_update(name, value)
17
/* const char *mail_conf_lookup(name)
20
/* const char *mail_conf_eval(string)
21
/* const char *string;
23
/* const char *mail_conf_lookup_eval(name)
26
/* mail_conf_suck() reads the global Postfix configuration file, and
27
/* stores its values into a global configuration dictionary.
29
/* mail_conf_read() invokes mail_conf_suck() and assigns the values
30
/* to global variables by calling mail_params_init().
32
/* The following routines are wrappers around the generic dictionary
35
/* mail_conf_update() updates the named global parameter. This has
36
/* no effect on parameters whose value has already been looked up.
37
/* The update succeeds or the program terminates with fatal error.
39
/* mail_conf_lookup() looks up the value of the named parameter.
40
/* A null pointer result means the parameter was not found.
41
/* The result is volatile and should be copied if it is to be
42
/* used for any appreciable amount of time.
44
/* mail_conf_eval() recursively expands any $parameters in the
45
/* string argument. The result is volatile and should be copied
46
/* if it is to be used for any appreciable amount of time.
48
/* mail_conf_lookup_eval() looks up the named parameter, and expands any
49
/* $parameters in the result. The result is volatile and should be
50
/* copied if it is to be used for any appreciable amount of time.
52
/* Fatal errors: malformed numerical value.
54
/* MAIL_CONFIG, non-default configuration database
55
/* MAIL_VERBOSE, enable verbose mode
57
/* /etc/postfix: default Postfix configuration directory.
59
/* dict(3) generic dictionary manager
60
/* mail_conf_int(3) integer-valued parameters
61
/* mail_conf_str(3) string-valued parameters
65
/* The Secure Mailer license must be distributed with this software.
68
/* IBM T.J. Watson Research
70
/* Yorktown Heights, NY 10598, USA
80
/* Utility library. */
88
#include <stringops.h>
89
#include <readlline.h>
93
#include "mail_params.h"
94
#include "mail_conf.h"
96
/* mail_conf_checkdir - authorize non-default directory */
98
static void mail_conf_checkdir(const char *config_dir)
109
* If running set-[ug]id, require that a non-default configuration
110
* directory name is blessed as a bona fide configuration directory in
111
* the default main.cf file.
113
path = concatenate(DEF_CONFIG_DIR, "/", "main.cf", (char *) 0);
114
if ((fp = vstream_fopen(path, O_RDONLY, 0)) == 0)
115
msg_fatal("open file %s: %m", path);
117
buf = vstring_alloc(1);
118
while (found == 0 && readlline(buf, fp, (int *) 0)) {
119
if (split_nameval(vstring_str(buf), &name, &value) == 0
120
&& strcmp(name, VAR_CONFIG_DIRS) == 0) {
121
while (found == 0 && (cp = mystrtok(&value, ", \t\r\n")) != 0)
122
if (strcmp(cp, config_dir) == 0)
126
if (vstream_fclose(fp))
127
msg_fatal("read file %s: %m", path);
131
msg_error("untrusted configuration directory name: %s", config_dir);
132
msg_fatal("specify \"%s = %s\" in %s",
133
VAR_CONFIG_DIRS, config_dir, path);
138
/* mail_conf_read - read global configuration file */
140
void mail_conf_read(void)
146
/* mail_conf_suck - suck in the global configuration file */
148
void mail_conf_suck(void)
154
* Permit references to unknown configuration variable names. We rely on
155
* a separate configuration checking tool to spot misspelled names and
156
* other kinds of trouble. Enter the configuration directory into the
157
* default dictionary.
159
dict_unknown_allowed = 1;
161
myfree(var_config_dir);
162
if ((config_dir = getenv(CONF_ENV_PATH)) == 0)
163
config_dir = DEF_CONFIG_DIR;
164
var_config_dir = mystrdup(config_dir);
165
set_mail_conf_str(VAR_CONFIG_DIR, var_config_dir);
168
* If the configuration directory name comes from a different trust
169
* domain, require that it is listed in the default main.cf file.
171
if (strcmp(var_config_dir, DEF_CONFIG_DIR) != 0 /* non-default */
172
&& safe_getenv(CONF_ENV_PATH) == 0 /* non-default */
173
&& geteuid() != 0) /* untrusted */
174
mail_conf_checkdir(var_config_dir);
175
path = concatenate(var_config_dir, "/", "main.cf", (char *) 0);
176
dict_load_file(CONFIG_DICT, path);
180
/* mail_conf_eval - expand macros in string */
182
const char *mail_conf_eval(const char *string)
186
return (dict_eval(CONFIG_DICT, string, RECURSIVE));
189
/* mail_conf_lookup - lookup named variable */
191
const char *mail_conf_lookup(const char *name)
193
return (dict_lookup(CONFIG_DICT, name));
196
/* mail_conf_lookup_eval - expand named variable */
198
const char *mail_conf_lookup_eval(const char *name)
204
if ((value = dict_lookup(CONFIG_DICT, name)) != 0)
205
value = dict_eval(CONFIG_DICT, value, RECURSIVE);
209
/* mail_conf_update - update parameter */
211
void mail_conf_update(const char *key, const char *value)
213
dict_update(CONFIG_DICT, key, value);