master-settings.c revision f11de734327a7a4db80a16a493df0020d9bd4f16
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn/* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallynstatic bool master_settings_verify(void *_set, pool_t pool,
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn const char **error_r);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallynextern struct setting_parser_info service_setting_parser_info;
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moser { type, #name, offsetof(struct file_listener_settings, name), NULL }
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallynstatic struct setting_define file_listener_setting_defines[] = {
1aad9e44d65e7c20dabc4c99f57bcf532db66c68Serge Hallynstatic struct file_listener_settings file_listener_default_settings = {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallynstatic struct setting_parser_info file_listener_setting_parser_info = {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn MEMBER(defaults) &file_listener_default_settings,
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn MEMBER(struct_size) sizeof(struct file_listener_settings)
4759162d078d86628956cae4846c6efccf548e67Serge Hallyn { type, #name, offsetof(struct inet_listener_settings, name), NULL }
4759162d078d86628956cae4846c6efccf548e67Serge Hallynstatic struct setting_define inet_listener_setting_defines[] = {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallynstatic struct inet_listener_settings inet_listener_default_settings = {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallynstatic struct setting_parser_info inet_listener_setting_parser_info = {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn MEMBER(defaults) &inet_listener_default_settings,
f02ce27d4b1a9d01b88d0ffaf626e5bafa671bf0Stéphane Graber MEMBER(parent) &service_setting_parser_info,
b85ab7989ebe24629267048cb269b278eeb50490Serge Hallyn MEMBER(struct_size) sizeof(struct inet_listener_settings)
57d116ab501594c2e50ab45f1cf2fae48c5eab09Serge Hallyn { type, #name, offsetof(struct service_settings, name), NULL }
57d116ab501594c2e50ab45f1cf2fae48c5eab09Serge Hallyn { SET_DEFLIST, name, offsetof(struct service_settings, field), defines }
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallynstatic struct setting_define service_setting_defines[] = {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallynstatic struct service_settings service_default_settings = {
5ff337745e4a705293b056ab58f6ea7a92cabbc8Stéphane Graberstruct setting_parser_info service_setting_parser_info = {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn MEMBER(parent_offset) offsetof(struct service_settings, master_set),
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn MEMBER(type_offset) offsetof(struct service_settings, name),
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn MEMBER(struct_size) sizeof(struct service_settings)
4759162d078d86628956cae4846c6efccf548e67Serge Hallyn { type, #name, offsetof(struct master_auth_settings, name), NULL }
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallynstatic struct setting_define master_auth_setting_defines[] = {
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moserstatic struct master_auth_settings master_auth_default_settings = {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallynstruct setting_parser_info master_auth_setting_parser_info = {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn MEMBER(defaults) &master_auth_default_settings,
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn MEMBER(struct_size) sizeof(struct master_auth_settings)
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moser { type, #name, offsetof(struct master_settings, name), NULL }
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moser { SET_DEFLIST, name, offsetof(struct master_settings, field), defines }
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moserstatic struct setting_define master_setting_defines[] = {
3eecde703e9ac3af788ac17357f378d6b6d7c658Serge Hallyn DEFLIST(services, "service", &service_setting_parser_info),
b8bced69a80a8be95fdbbb6b4e9ad7fa85464b1eSerge Hallyn DEFLIST(auths, "auth", &master_auth_setting_parser_info),
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallynstatic struct master_settings master_default_settings = {
52c8f624b5f9ef665f33a7aa80e0aa18b91daa4aSerge Hallynstruct setting_parser_info master_setting_parser_info = {
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moser MEMBER(struct_size) sizeof(struct master_settings),
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn/* <settings checks> */
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallynstatic void fix_file_listener_paths(ARRAY_TYPE(file_listener_settings) *l,
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moser unsigned int i, count;
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn for (i = 0; i < count; i++) {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn sets[i]->path = p_strconcat(pool, base_dir, "/",
8a63c0a9d9089e6365e5a696455476febed39d6aStéphane Grabermaster_settings_verify(void *_set, pool_t pool, const char **error_r)
8a63c0a9d9089e6365e5a696455476febed39d6aStéphane Graber unsigned int i, j, count;
8a63c0a9d9089e6365e5a696455476febed39d6aStéphane Graber set->first_valid_uid > set->last_valid_uid) {
8a63c0a9d9089e6365e5a696455476febed39d6aStéphane Graber *error_r = "first_valid_uid can't be larger than last_valid_uid";
8a63c0a9d9089e6365e5a696455476febed39d6aStéphane Graber set->first_valid_gid > set->last_valid_gid) {
8a63c0a9d9089e6365e5a696455476febed39d6aStéphane Graber *error_r = "first_valid_gid can't be larger than last_valid_gid";
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn /* check that we have at least one service. the actual service
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn structure validity is checked later while creating them. */
427bffc7a10c9015dc78ef52543f7b8cb9414359Serge Hallyn for (i = 0; i < count; i++) {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn "Service #%d is missing name", i);
1881820ae4ff9004beef1bf7f04553580840441dSerge Hallyn strcmp(services[i]->type, "auth-source") != 0) {
1881820ae4ff9004beef1bf7f04553580840441dSerge Hallyn *error_r = t_strconcat("Unknown service type: ",
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn for (j = 0; j < i; j++) {
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn if (strcmp(services[i]->name, services[j]->name) == 0) {
1881820ae4ff9004beef1bf7f04553580840441dSerge Hallyn "Duplicate service name: %s",
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn for (i = 0; i < count; i++) {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn "drop_priv_before_exec=yes can't be "
f1ccde27c038e7fb7e538913505248b36ddd9e65Serge Hallyn fix_file_listener_paths(&services[i]->unix_listeners,
3eecde703e9ac3af788ac17357f378d6b6d7c658Serge Hallyn fix_file_listener_paths(&services[i]->fifo_listeners,
3eecde703e9ac3af788ac17357f378d6b6d7c658Serge Hallyn set->protocols_split = p_strsplit(pool, set->protocols, " ");
3eecde703e9ac3af788ac17357f378d6b6d7c658Serge Hallyn/* </settings checks> */
3eecde703e9ac3af788ac17357f378d6b6d7c658Serge Hallynlogin_want_core_dumps(const struct master_settings *set, gid_t *gid_r)
3eecde703e9ac3af788ac17357f378d6b6d7c658Serge Hallyn unsigned int i, count;
3eecde703e9ac3af788ac17357f378d6b6d7c658Serge Hallyn for (i = 0; i < count; i++) {
3eecde703e9ac3af788ac17357f378d6b6d7c658Serge Hallyn if (strcmp(services[i]->type, "auth-source") == 0 &&
3eecde703e9ac3af788ac17357f378d6b6d7c658Serge Hallyn if (strstr(services[i]->executable, " -D") != NULL)
9c3bc32c5789b76b8c42b75d7625377d61e052c1Stéphane Graber (void)get_uidgid(services[i]->user, &uid, gid_r, &error);
9c3bc32c5789b76b8c42b75d7625377d61e052c1Stéphane Graber (void)get_gid(services[i]->group, gid_r, &error);
f1ccde27c038e7fb7e538913505248b36ddd9e65Serge Hallynsettings_have_auth_unix_listeners_in(const struct master_settings *set,
f1ccde27c038e7fb7e538913505248b36ddd9e65Serge Hallyn const char *dir)
1aad9e44d65e7c20dabc4c99f57bcf532db66c68Serge Hallyn struct file_listener_settings *const *u;
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn for (i = 0; i < count; i++) {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn array_is_created(&services[i]->unix_listeners)) {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn u = array_get(&services[i]->unix_listeners, &count2);
f1ccde27c038e7fb7e538913505248b36ddd9e65Serge Hallyn for (j = 0; j < count2; j++) {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn if (strncmp(u[j]->path, dir, strlen(dir)) == 0)
3eecde703e9ac3af788ac17357f378d6b6d7c658Serge Hallynstatic void unlink_sockets(const char *path, const char *prefix)
42ff5f0f8767114d060f5031055038a1a1c3759aSerge Hallyn if (strncmp(dp->d_name, prefix, prefix_len) != 0)
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Graber i_error("lstat(%s) failed: %m", str_c(str));
b942e67226af9e690bd63ac440b99aedb6becbb3Scott Moser /* try to avoid unlinking sockets if someone's already
return FALSE;
return FALSE;
return FALSE;
return FALSE;
return FALSE;
return TRUE;