示例#1
0
static void
service_process_setup_environment(struct service *service, unsigned int uid)
{
	master_service_env_clean();

	env_put(MASTER_IS_PARENT_ENV"=1");
	service_process_setup_config_environment(service);
	env_put(t_strdup_printf(MASTER_CLIENT_LIMIT_ENV"=%u",
				service->client_limit));
	env_put(t_strdup_printf(MASTER_PROCESS_LIMIT_ENV"=%u",
				service->process_limit));
	env_put(t_strdup_printf(MASTER_SERVICE_IDLE_KILL_ENV"=%u",
				service->idle_kill));
	if (service->set->service_count != 0) {
		env_put(t_strdup_printf(MASTER_SERVICE_COUNT_ENV"=%u",
					service->set->service_count));
	}
	env_put(t_strdup_printf(MASTER_UID_ENV"=%u", uid));
	env_put(t_strdup_printf(MY_HOSTNAME_ENV"=%s", my_hostname));
	env_put(t_strdup_printf(MY_HOSTDOMAIN_ENV"=%s", my_hostdomain()));

	if (!service->set->master_set->version_ignore)
		env_put(MASTER_DOVECOT_VERSION_ENV"="PACKAGE_VERSION);

	if (ssl_manual_key_password != NULL && service->have_inet_listeners) {
		/* manually given SSL password. give it only to services
		   that have inet listeners. */
		env_put(t_strconcat(MASTER_SSL_KEY_PASSWORD_ENV"=",
				    ssl_manual_key_password, NULL));
	}
	if (service->type == SERVICE_TYPE_ANVIL &&
	    service_anvil_global->restarted)
		env_put("ANVIL_RESTARTED=1");
}
示例#2
0
static void ATTR_NORETURN
master_service_exec_config(struct master_service *service,
			   const struct master_service_settings_input *input)
{
	const char **conf_argv, *binary_path = service->argv[0];
	const char *home = NULL, *user = NULL, *timestamp = NULL;
	unsigned int i, argv_max_count;

	(void)t_binary_abspath(&binary_path);

	if (!service->keep_environment && !input->preserve_environment) {
		if (input->preserve_home)
			home = getenv("HOME");
		if (input->preserve_user)
			user = getenv("USER");
		if ((service->flags & MASTER_SERVICE_FLAG_STANDALONE) != 0)
			timestamp = getenv("LOG_STDERR_TIMESTAMP");
		master_service_env_clean();
		if (home != NULL)
			env_put(t_strconcat("HOME=", home, NULL));
		if (user != NULL)
			env_put(t_strconcat("USER="******"LOG_STDERR_TIMESTAMP=", timestamp, NULL));
	}
	if (input->use_sysexits)
		env_put("USE_SYSEXITS=1");

	/* @UNSAFE */
	i = 0;
	argv_max_count = 11 + (service->argc + 1) + 1;
	conf_argv = t_new(const char *, argv_max_count);
	conf_argv[i++] = DOVECOT_CONFIG_BIN_PATH;
	if (input->service != NULL) {
		conf_argv[i++] = "-f";
		conf_argv[i++] = t_strconcat("service=", input->service, NULL);
	}
	conf_argv[i++] = "-c";
	conf_argv[i++] = service->config_path;
	if (input->module != NULL) {
		conf_argv[i++] = "-m";
		conf_argv[i++] = input->module;
		if (service->want_ssl_settings) {
			conf_argv[i++] = "-m";
			conf_argv[i++] = "ssl";
		}
	}
	if (input->parse_full_config)
		conf_argv[i++] = "-p";

	conf_argv[i++] = "-e";
	conf_argv[i++] = binary_path;
	memcpy(conf_argv+i, service->argv + 1,
	       (service->argc) * sizeof(conf_argv[0]));
	i += service->argc;

	i_assert(i < argv_max_count);
	execv_const(conf_argv[0], conf_argv);
}