7 /* global configuration parameter management
9 /* #include <mail_conf.h>
11 /* void mail_conf_read()
13 /* void mail_conf_suck()
15 /* void mail_conf_flush()
17 /* void mail_conf_update(name, value)
21 /* const char *mail_conf_lookup(name)
24 /* const char *mail_conf_eval(string)
25 /* const char *string;
27 /* const char *mail_conf_lookup_eval(name)
30 /* mail_conf_suck() reads the global Postfix configuration file, and
31 /* stores its values into a global configuration dictionary.
33 /* mail_conf_read() invokes mail_conf_suck() and assigns the values
34 /* to global variables by calling mail_params_init().
36 /* mail_conf_flush() discards the global configuration dictionary.
37 /* This is needed in programs that read main.cf multiple times, to
38 /* ensure that deleted parameter settings are handled properly.
40 /* The following routines are wrappers around the generic dictionary
43 /* mail_conf_update() updates the named global parameter. This has
44 /* no effect on parameters whose value has already been looked up.
45 /* The update succeeds or the program terminates with fatal error.
47 /* mail_conf_lookup() looks up the value of the named parameter.
48 /* A null pointer result means the parameter was not found.
49 /* The result is volatile and should be copied if it is to be
50 /* used for any appreciable amount of time.
52 /* mail_conf_eval() recursively expands any $parameters in the
53 /* string argument. The result is volatile and should be copied
54 /* if it is to be used for any appreciable amount of time.
56 /* mail_conf_lookup_eval() looks up the named parameter, and expands any
57 /* $parameters in the result. The result is volatile and should be
58 /* copied if it is to be used for any appreciable amount of time.
60 /* Fatal errors: malformed numerical value.
62 /* MAIL_CONFIG, non-default configuration database
63 /* MAIL_VERBOSE, enable verbose mode
65 /* /etc/postfix: default Postfix configuration directory.
67 /* dict(3) generic dictionary manager
68 /* mail_conf_int(3) integer-valued parameters
69 /* mail_conf_str(3) string-valued parameters
73 /* The Secure Mailer license must be distributed with this software.
76 /* IBM T.J. Watson Research
78 /* Yorktown Heights, NY 10598, USA
88 /* Utility library. */
96 #include <stringops.h>
97 #include <readlline.h>
101 #include "mail_params.h"
102 #include "mail_conf.h"
104 /* mail_conf_checkdir - authorize non-default directory */
106 static void mail_conf_checkdir(const char *config_dir
)
117 * If running set-[ug]id, require that a non-default configuration
118 * directory name is blessed as a bona fide configuration directory in
119 * the default main.cf file.
121 path
= concatenate(DEF_CONFIG_DIR
, "/", "main.cf", (char *) 0);
122 if ((fp
= vstream_fopen(path
, O_RDONLY
, 0)) == 0)
123 msg_fatal("open file %s: %m", path
);
125 buf
= vstring_alloc(1);
126 while (found
== 0 && readlline(buf
, fp
, (int *) 0)) {
127 if (split_nameval(vstring_str(buf
), &name
, &value
) == 0
128 && (strcmp(name
, VAR_CONFIG_DIRS
) == 0
129 || strcmp(name
, VAR_MULTI_CONF_DIRS
) == 0)) {
130 while (found
== 0 && (cp
= mystrtok(&value
, ", \t\r\n")) != 0)
131 if (strcmp(cp
, config_dir
) == 0)
135 if (vstream_fclose(fp
))
136 msg_fatal("read file %s: %m", path
);
140 msg_error("untrusted configuration directory name: %s", config_dir
);
141 msg_fatal("specify \"%s = %s\" in %s",
142 VAR_CONFIG_DIRS
, config_dir
, path
);
147 /* mail_conf_read - read global configuration file */
149 void mail_conf_read(void)
155 /* mail_conf_suck - suck in the global configuration file */
157 void mail_conf_suck(void)
163 * Permit references to unknown configuration variable names. We rely on
164 * a separate configuration checking tool to spot misspelled names and
165 * other kinds of trouble. Enter the configuration directory into the
166 * default dictionary.
168 dict_unknown_allowed
= 1;
170 myfree(var_config_dir
);
171 if ((config_dir
= getenv(CONF_ENV_PATH
)) == 0)
172 config_dir
= DEF_CONFIG_DIR
;
173 var_config_dir
= mystrdup(config_dir
);
174 set_mail_conf_str(VAR_CONFIG_DIR
, var_config_dir
);
177 * If the configuration directory name comes from a different trust
178 * domain, require that it is listed in the default main.cf file.
180 if (strcmp(var_config_dir
, DEF_CONFIG_DIR
) != 0 /* non-default */
181 && safe_getenv(CONF_ENV_PATH
) == 0 /* non-default */
182 && geteuid() != 0) /* untrusted */
183 mail_conf_checkdir(var_config_dir
);
184 path
= concatenate(var_config_dir
, "/", "main.cf", (char *) 0);
185 dict_load_file(CONFIG_DICT
, path
);
189 /* mail_conf_flush - discard configuration dictionary */
191 void mail_conf_flush(void)
193 if (dict_handle(CONFIG_DICT
) != 0)
194 dict_unregister(CONFIG_DICT
);
197 /* mail_conf_eval - expand macros in string */
199 const char *mail_conf_eval(const char *string
)
203 return (dict_eval(CONFIG_DICT
, string
, RECURSIVE
));
206 /* mail_conf_lookup - lookup named variable */
208 const char *mail_conf_lookup(const char *name
)
210 return (dict_lookup(CONFIG_DICT
, name
));
213 /* mail_conf_lookup_eval - expand named variable */
215 const char *mail_conf_lookup_eval(const char *name
)
221 if ((value
= dict_lookup(CONFIG_DICT
, name
)) != 0)
222 value
= dict_eval(CONFIG_DICT
, value
, RECURSIVE
);
226 /* mail_conf_update - update parameter */
228 void mail_conf_update(const char *key
, const char *value
)
230 dict_update(CONFIG_DICT
, key
, value
);