]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
master: Add support for service listener type field.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Tue, 29 Nov 2022 22:32:13 +0000 (23:32 +0100)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Sun, 11 Dec 2022 21:58:50 +0000 (21:58 +0000)
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.

src/lib-master/master-service-private.h
src/lib-master/master-service.c
src/lib-master/master-service.h
src/lib-master/service-settings.h
src/master/master-settings.c
src/master/service-process.c

index 3930a248f63254c9a49ccc6562a7a1479af430be..5a171ffa6a276f08048ed37e1660935b245d0d0f 100644 (file)
@@ -11,6 +11,7 @@ struct master_service_haproxy_conn;
 struct master_service_listener {
        struct master_service *service;
        char *name;
+       char *type;
 
        /* settings */
        bool ssl;
index 61da738126323b320243018ef23142fefef0df3b..266e2ac29e9f73b06752eb6f2b75f0a880ff9e83 100644 (file)
@@ -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;
index 403a0a2f2b4220e95957d4545266c9a332821e1f..61059ddbc83074fb76abc3c371eb39d11d298439 100644 (file)
@@ -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);
index c0235856ae39d1ea547c3f81c779adf9c9f01727..259a535a99d7d463f855e5175314f6e4cf083da4 100644 (file)
@@ -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;
index a162bdd471be628a413de40d7242622c97115f67..039bd22e42f7ea745bc076d361aca2333fdab389 100644 (file)
@@ -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),
index 59bf6ea1e75970eeabb7a3b8ec1a41050e8d1091..be42627ae356c0696b7effcbba95ac872c876920 100644 (file)
@@ -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++);