From: Stephan Bosch Date: Tue, 29 Nov 2022 22:32:13 +0000 (+0100) Subject: master: Add support for service listener type field. X-Git-Tag: 2.4.0~3306 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e15422a81ad3f290e5adca7ec7374610212fe93;p=thirdparty%2Fdovecot%2Fcore.git master: Add support for service listener type field. It is conveyed to the services along with the rest of the listener settings and alows distinguising listeners more reliably than parsing the purpose of the listener from the name, as it is now. --- diff --git a/src/lib-master/master-service-private.h b/src/lib-master/master-service-private.h index 3930a248f6..5a171ffa6a 100644 --- a/src/lib-master/master-service-private.h +++ b/src/lib-master/master-service-private.h @@ -11,6 +11,7 @@ struct master_service_haproxy_conn; struct master_service_listener { struct master_service *service; char *name; + char *type; /* settings */ bool ssl; diff --git a/src/lib-master/master-service.c b/src/lib-master/master-service.c index 61da738126..266e2ac29e 100644 --- a/src/lib-master/master-service.c +++ b/src/lib-master/master-service.c @@ -398,11 +398,24 @@ static void master_service_init_socket_listeners(struct master_service *service) settings++; } while (*settings != NULL) { - if (strcmp(*settings, "ssl") == 0) { + const char *sname, *svalue; + + svalue = strchr(*settings, '='); + if (svalue != NULL) { + sname = t_strdup_until(*settings, + svalue++); + } else { + sname = *settings; + svalue = ""; + } + if (strcmp(sname, "ssl") == 0) { l->ssl = TRUE; have_ssl_sockets = TRUE; - } else if (strcmp(*settings, "haproxy") == 0) { + } else if (strcmp(sname, "haproxy") == 0) { l->haproxy = TRUE; + } else if (strcmp(sname, "type") == 0) { + i_free(l->type); + l->type = i_strdup_empty(svalue); } settings++; } @@ -1076,6 +1089,19 @@ const char *master_service_get_socket_name(struct master_service *service, service->listeners[i].name : ""; } +const char * +master_service_get_socket_type(struct master_service *service, int listen_fd) +{ + unsigned int i; + + i_assert(listen_fd >= MASTER_LISTEN_FD_FIRST); + + i = listen_fd - MASTER_LISTEN_FD_FIRST; + i_assert(i < service->socket_count); + return service->listeners[i].type != NULL ? + service->listeners[i].type : ""; +} + void master_service_set_avail_overflow_callback(struct master_service *service, master_service_avail_overflow_callback_t *callback) { @@ -1506,8 +1532,10 @@ static void master_service_free(struct master_service *service) { unsigned int i; - for (i = 0; i < service->socket_count; i++) + for (i = 0; i < service->socket_count; i++) { i_free(service->listeners[i].name); + i_free(service->listeners[i].type); + } i_free(service->listeners); i_free(service->getopt_str); i_free(service->configured_name); @@ -1680,6 +1708,7 @@ master_service_accept(struct master_service_listener *l, const char *conn_name, } conn.ssl = l->ssl; conn.name = conn_name; + conn.type = (l->type != NULL ? l->type : ""); (void)net_getsockname(conn.fd, &conn.local_ip, &conn.local_port); conn.real_remote_ip = conn.remote_ip; diff --git a/src/lib-master/master-service.h b/src/lib-master/master-service.h index 403a0a2f2b..61059ddbc8 100644 --- a/src/lib-master/master-service.h +++ b/src/lib-master/master-service.h @@ -67,6 +67,9 @@ struct master_service_connection { int listen_fd; /* listener name as in configuration file, or "" if unnamed. */ const char *name; + /* listener type as in configuration file, or "" if no type is + specified */ + const char *type; /* Original client/server IP/port. Both of these may have been changed by the haproxy protocol. */ @@ -209,6 +212,9 @@ unsigned int master_service_get_socket_count(struct master_service *service); /* Returns the name of the listener socket, or "" if none is specified. */ const char *master_service_get_socket_name(struct master_service *service, int listen_fd); +/* Returns the type of the listener socket, or "" if none is specified. */ +const char * +master_service_get_socket_type(struct master_service *service, int listen_fd); /* Returns configuration file path. */ const char *master_service_get_config_path(struct master_service *service); diff --git a/src/lib-master/service-settings.h b/src/lib-master/service-settings.h index c0235856ae..259a535a99 100644 --- a/src/lib-master/service-settings.h +++ b/src/lib-master/service-settings.h @@ -26,6 +26,7 @@ enum service_type { struct file_listener_settings { const char *path; + const char *type; unsigned int mode; const char *user; const char *group; @@ -34,6 +35,7 @@ ARRAY_DEFINE_TYPE(file_listener_settings, struct file_listener_settings *); struct inet_listener_settings { const char *name; + const char *type; const char *address; in_port_t port; bool ssl; diff --git a/src/master/master-settings.c b/src/master/master-settings.c index a162bdd471..039bd22e42 100644 --- a/src/master/master-settings.c +++ b/src/master/master-settings.c @@ -30,6 +30,7 @@ extern const struct setting_parser_info service_setting_parser_info; static const struct setting_define file_listener_setting_defines[] = { DEF(STR, path), + DEF(STR, type), DEF(UINT_OCT, mode), DEF(STR, user), DEF(STR, group), @@ -61,6 +62,7 @@ static const struct setting_parser_info file_listener_setting_parser_info = { static const struct setting_define inet_listener_setting_defines[] = { DEF(STR, name), + DEF(STR, type), DEF(STR, address), DEF(IN_PORT, port), DEF(BOOL, ssl), diff --git a/src/master/service-process.c b/src/master/service-process.c index 59bf6ea1e7..be42627ae3 100644 --- a/src/master/service-process.c +++ b/src/master/service-process.c @@ -117,6 +117,23 @@ service_dup_fds(struct service *service) str_append(listener_settings, "\tssl"); if (listeners[i]->set.inetset.set->haproxy) str_append(listener_settings, "\thaproxy"); + if (listeners[i]->set.inetset.set->type != NULL && + *listeners[i]->set.inetset.set->type != '\0') { + str_append(listener_settings, "\ttype="); + str_append_tabescaped( + listener_settings, + listeners[i]->set.inetset.set->type); + } + } + if (listeners[i]->type == SERVICE_LISTENER_FIFO || + listeners[i]->type == SERVICE_LISTENER_UNIX) { + if (listeners[i]->set.fileset.set->type != NULL && + *listeners[i]->set.fileset.set->type != '\0') { + str_append(listener_settings, "\ttype="); + str_append_tabescaped( + listener_settings, + listeners[i]->set.fileset.set->type); + } } dup2_append(&dups, listeners[i]->fd, fd++);