#include "master-service-ssl.h"
#include "master-service-settings.h"
#include "iostream-ssl.h"
+#include "var-expand.h"
#include <getopt.h>
#include <unistd.h>
{
const char *const *envs, *key, *value;
ARRAY_TYPE(const_string) keys;
+ const char *error;
+ string_t *expanded;
+
+ static const struct var_expand_table table[] = {
+ { '\0', NULL, NULL },
+ };
if (*import_environment == '\0')
return;
#endif
/* add new environments */
envs = t_strsplit_spaces(import_environment, " ");
+ expanded = t_str_new(64);
for (; *envs != NULL; envs++) {
value = strchr(*envs, '=');
if (value == NULL)
key = *envs;
else {
key = t_strdup_until(*envs, value++);
- env_put(key, value);
+ if (var_expand(expanded, value, table, &error) <= 0)
+ i_fatal("Cannot expand variable %s", value);
+ if (str_len(expanded) > 0) {
+ value = str_c(expanded);
+ env_put(key, value);
+ str_clear(expanded);
+ }
}
array_push_back(&keys, &key);
}
void master_service_init_finish(struct master_service *service);
/* import_environment is a space-separated list of environment keys or
- key=values. The key=values are immediately added to the environment.
- All the keys are added to DOVECOT_PRESERVE_ENVS environment so they're
- preserved by master_service_env_clean(). */
+ key=values. If the values contain %variables they are expanded and
+ immediately added to the environment, this can i_fatal() if the %variables
+ are invalid. All the keys are added to DOVECOT_PRESERVE_ENVS environment so
+ they're preserved by master_service_env_clean(). */
void master_service_import_environment(const char *import_environment);
/* Clean environment from everything except the ones listed in
DOVECOT_PRESERVE_ENVS environment. */