]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-settings, global: Add prefix parameter to settings_parse_read_file()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 29 Jul 2025 09:59:37 +0000 (12:59 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Sun, 3 Aug 2025 17:22:44 +0000 (17:22 +0000)
src/config/config-parser.c
src/lib-http/test-http-client.c
src/lib-settings/settings-parser.c
src/lib-settings/settings-parser.h
src/lib-settings/settings.c

index c860baf93037b19cc205a878ecea3f208bbf74a0..4ee7cb1f73b542341649509796ded46fb05613bd 100644 (file)
@@ -702,7 +702,7 @@ static int config_apply_file(struct config_parser_context *ctx,
        if (full_path != path && ctx->expand_values)
                path = full_path;
        if (settings_parse_read_file(full_path, path, ctx->pool, &st,
-                                    output_r, &error) < 0) {
+                                    "", output_r, &error) < 0) {
                ctx->error = p_strdup(ctx->pool, error);
                if (config_apply_error(ctx, line->key) < 0)
                        return -1;
index 87577c21ec65d2dfc8a30916313ece38f2def83f..9d98da3608ea535fbc596eb1efa16395736fed57 100644 (file)
@@ -413,7 +413,7 @@ int main(int argc, char *argv[])
                if (settings_parse_read_file("/etc/pki/tls/cert.pem",
                                             "/etc/pki/tls/cert.pem",
                                             unsafe_data_stack_pool, NULL,
-                                            &ca_value, &error) < 0)
+                                            "", &ca_value, &error) < 0)
                        i_fatal("%s", error);
                settings_file_get(ca_value, unsafe_data_stack_pool,
                                  &ssl_set.ca);
index 05a93819228f78c239061cfd2e1f028260c7bd04..a6531278e3894baf91dc2447cd25cba342d1f2ba 100644 (file)
@@ -277,7 +277,7 @@ get_file(struct setting_parser_context *ctx, bool dup_value, const char **value)
 
        const char *error;
        if (settings_parse_read_file(*value, *value, ctx->set_pool, NULL,
-                                    value, &error) < 0) {
+                                    "", value, &error) < 0) {
                settings_parser_set_error(ctx, error);
                return -1;
        }
@@ -298,7 +298,8 @@ get_in_port_zero(struct setting_parser_context *ctx, const char *value,
 
 int settings_parse_read_file(const char *path, const char *value_path,
                             pool_t pool, struct stat *st_r,
-                            const char **output_r, const char **error_r)
+                            const char *prefix, const char **output_r,
+                            const char **error_r)
 {
        struct stat st;
        int fd;
@@ -312,12 +313,16 @@ int settings_parse_read_file(const char *path, const char *value_path,
                i_close_fd(&fd);
                return -1;
        }
+       size_t prefix_len = strlen(prefix);
        size_t value_path_len = strlen(value_path);
-       char *buf = p_malloc(pool, value_path_len + 1 + st.st_size + 1);
-       memcpy(buf, value_path, value_path_len);
-       buf[value_path_len] = '\n';
-
-       int ret = read_full(fd, buf + value_path_len + 1, st.st_size);
+       char *buf = p_malloc(pool, prefix_len + value_path_len + 1 +
+                            st.st_size + 1);
+       memcpy(buf, prefix, prefix_len);
+       memcpy(buf + prefix_len, value_path, value_path_len);
+       buf[prefix_len + value_path_len] = '\n';
+
+       int ret = read_full(fd, buf + prefix_len + value_path_len + 1,
+                           st.st_size);
        i_close_fd(&fd);
        if (ret < 0) {
                *error_r = t_strdup_printf("read(%s) failed: %m", path);
@@ -328,7 +333,7 @@ int settings_parse_read_file(const char *path, const char *value_path,
                        "read(%s) failed: Unexpected EOF", path);
                return -1;
        }
-       if (memchr(buf + value_path_len + 1, '\0', st.st_size) != NULL) {
+       if (memchr(buf + prefix_len + value_path_len + 1, '\0', st.st_size) != NULL) {
                *error_r = t_strdup_printf(
                        "%s contains NUL characters - This is not supported",
                        path);
index 3af52dda7fe39e764990f17b63f5e9bd55dcb6c8..4a205becfd53d1e685242bfa9045e1083806758f 100644 (file)
@@ -272,11 +272,13 @@ bool settings_parser_check(struct setting_parser_context *ctx, pool_t pool,
 bool settings_check(struct event *event, const struct setting_parser_info *info,
                    pool_t pool, void *set, const char **error_r);
 
-/* Read a SET_FILE from the given path and write "value_path\ncontents" to
-   output_r. Returns 0 on success, -1 on error. */
+/* Read a SET_FILE from the given path and write
+   "<prefix><value_path>\n<contents>" to output_r. Returns 0 on success,
+   -1 on error. */
 int settings_parse_read_file(const char *path, const char *value_path,
                             pool_t pool, struct stat *st_r,
-                            const char **output_r, const char **error_r);
+                            const char *prefix, const char **output_r,
+                            const char **error_r);
 int settings_parse_boollist_string(const char *value, pool_t pool,
                                   ARRAY_TYPE(const_string) *dest,
                                   const char **error_r);
index 64880c6fb9b17b8a40ffe21555c488720415be95..347a26c65f5117e9cf8091e53025c6faaef7605a 100644 (file)
@@ -874,7 +874,7 @@ settings_var_expand(struct settings_apply_ctx *ctx, unsigned int key_idx,
                file.path = str_c(ctx->str);
                if (settings_parse_read_file(file.path, file.path,
                                             &ctx->mpool->pool, NULL,
-                                            value, error_r) < 0)
+                                            "", value, error_r) < 0)
                        return -1;
        } else {
                *value = p_strdup(&ctx->mpool->pool, str_c(ctx->str));