From: Timo Sirainen Date: Tue, 29 Jul 2025 09:59:37 +0000 (+0300) Subject: lib-settings, global: Add prefix parameter to settings_parse_read_file() X-Git-Tag: 2.4.2~594 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=085db5099937b0587d8c7282b901c3e8ab65ad84;p=thirdparty%2Fdovecot%2Fcore.git lib-settings, global: Add prefix parameter to settings_parse_read_file() --- diff --git a/src/config/config-parser.c b/src/config/config-parser.c index c860baf930..4ee7cb1f73 100644 --- a/src/config/config-parser.c +++ b/src/config/config-parser.c @@ -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; diff --git a/src/lib-http/test-http-client.c b/src/lib-http/test-http-client.c index 87577c21ec..9d98da3608 100644 --- a/src/lib-http/test-http-client.c +++ b/src/lib-http/test-http-client.c @@ -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); diff --git a/src/lib-settings/settings-parser.c b/src/lib-settings/settings-parser.c index 05a9381922..a6531278e3 100644 --- a/src/lib-settings/settings-parser.c +++ b/src/lib-settings/settings-parser.c @@ -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); diff --git a/src/lib-settings/settings-parser.h b/src/lib-settings/settings-parser.h index 3af52dda7f..4a205becfd 100644 --- a/src/lib-settings/settings-parser.h +++ b/src/lib-settings/settings-parser.h @@ -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 + "\n" 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); diff --git a/src/lib-settings/settings.c b/src/lib-settings/settings.c index 64880c6fb9..347a26c65f 100644 --- a/src/lib-settings/settings.c +++ b/src/lib-settings/settings.c @@ -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));