bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */
ca7e608c21bdfd7b6a2e7fcb2678ade4c1c1972cTimo Sirainenstatic void config_export_size(string_t *str, uoff_t size)
ca7e608c21bdfd7b6a2e7fcb2678ade4c1c1972cTimo Sirainen static const char suffixes[] = { 'B', 'k', 'M', 'G', 'T' };
ca7e608c21bdfd7b6a2e7fcb2678ade4c1c1972cTimo Sirainen unsigned int i;
ca7e608c21bdfd7b6a2e7fcb2678ade4c1c1972cTimo Sirainen for (i = 1; i < N_ELEMENTS(suffixes) && (size % 1024) == 0; i++) {
47a5a7e8296f3b8f2fac9a0659d4de3f2723ba4aMartti Rannanjärvi str_printfa(str, "%"PRIuUOFF_T" %c", size, suffix);
ca7e608c21bdfd7b6a2e7fcb2678ade4c1c1972cTimo Sirainenstatic void config_export_time(string_t *str, unsigned int stamp)
2ed05ea827dc49e715a4859a2ca485dc1934f1a3Timo Sirainenstatic void config_export_time_msecs(string_t *str, unsigned int stamp_msecs)
7a5e2e937f0f388465c2938645ee971b4fd01bf1Timo Sirainenbool config_export_type(string_t *str, const void *value,
7a5e2e937f0f388465c2938645ee971b4fd01bf1Timo Sirainen const bool *val = value, *dval = default_value;
7a5e2e937f0f388465c2938645ee971b4fd01bf1Timo Sirainen if (dump_default || dval == NULL || *val != *dval)
7a5e2e937f0f388465c2938645ee971b4fd01bf1Timo Sirainen const uoff_t *val = value, *dval = default_value;
7a5e2e937f0f388465c2938645ee971b4fd01bf1Timo Sirainen if (dump_default || dval == NULL || *val != *dval)
7a5e2e937f0f388465c2938645ee971b4fd01bf1Timo Sirainen const unsigned int *val = value, *dval = default_value;
7a5e2e937f0f388465c2938645ee971b4fd01bf1Timo Sirainen if (dump_default || dval == NULL || *val != *dval) {
009217abb57a24a4076092e8e4e165545747839eStephan Bosch const in_port_t *val = value, *dval = default_value;
009217abb57a24a4076092e8e4e165545747839eStephan Bosch if (dump_default || dval == NULL || *val != *dval)
7a5e2e937f0f388465c2938645ee971b4fd01bf1Timo Sirainen const char *dval = _dval == NULL ? NULL : *_dval;
7a5e2e937f0f388465c2938645ee971b4fd01bf1Timo Sirainen if ((dump_default || null_strcmp(sval, dval) != 0) &&
7a5e2e937f0f388465c2938645ee971b4fd01bf1Timo Sirainen const char *dval = _dval == NULL ? NULL : *_dval;
7a5e2e937f0f388465c2938645ee971b4fd01bf1Timo Sirainen if ((dump_default || null_strcmp(*val, dval) != 0) &&
b879ed8dd4b5850987e6b89a92f794d87c6be7d7Timo Sirainen const char *dval = _dval == NULL ? NULL : *_dval;
d1d425c3ed541dde4ae11e88291a0044e6c55f88Timo Sirainensetting_export_section_name(string_t *str, const struct setting_define *def,
d1d425c3ed541dde4ae11e88291a0044e6c55f88Timo Sirainen /* not unique, use the index */
d1d425c3ed541dde4ae11e88291a0044e6c55f88Timo Sirainen /* no name, this one isn't unique. use the index. */
d1d425c3ed541dde4ae11e88291a0044e6c55f88Timo Sirainen str_append(str, settings_section_escape(*name));
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainensettings_export(struct config_export_context *ctx,
56439f2879ad690d9ac637e2b90b612760d2f219Timo Sirainen const void *value, *default_value, *change_value;
25f959d63f5379702f44f5ae125eb3b70a6a47d7Timo Sirainen void *const *children, *const *change_children = NULL;
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen for (def = info->defines; def->key != NULL; def++) {
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen default_value = info->defaults == NULL ? NULL :
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen CONST_PTR_OFFSET(info->defaults, def->offset);
56439f2879ad690d9ac637e2b90b612760d2f219Timo Sirainen change_value = CONST_PTR_OFFSET(change_set, def->offset);
56439f2879ad690d9ac637e2b90b612760d2f219Timo Sirainen dump_default = *((const char *)change_value) != 0;
50fe5e053d565b40b0ed2cc7a64b6b98971c0305Timo Sirainen (ctx->flags & CONFIG_DUMP_FLAG_HIDE_LIST_DEFAULTS) == 0) {
50fe5e053d565b40b0ed2cc7a64b6b98971c0305Timo Sirainen } else if (*((const char *)change_value) == 0 &&
6899af0c40f5e1ef80bd18961cea3a192134a4a4Timo Sirainen /* this is mainly for service {} blocks. if value
6899af0c40f5e1ef80bd18961cea3a192134a4a4Timo Sirainen hasn't changed, it's the default. even if
6899af0c40f5e1ef80bd18961cea3a192134a4a4Timo Sirainen info->defaults has a different value. */
d84c270231a617298088f597474a73f4a14921aeTimo Sirainen /* value is set explicitly, but we don't know the
d84c270231a617298088f597474a73f4a14921aeTimo Sirainen default here. assume it's not the default. */
56439f2879ad690d9ac637e2b90b612760d2f219Timo Sirainen const ARRAY_TYPE(void_array) *change_val = change_value;
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen for (i = 0; i < count; i++) {
d1d425c3ed541dde4ae11e88291a0044e6c55f88Timo Sirainen setting_export_section_name(ctx->value, def, children[i], i);
56439f2879ad690d9ac637e2b90b612760d2f219Timo Sirainen change_children = array_get(change_val, &count2);
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen key = p_strconcat(ctx->pool, str_c(ctx->prefix),
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen if (hash_table_lookup(ctx->keys, key) != NULL) {
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen /* already added all of these */
c84c0d4cb7f16aedbcb3d5db6b2d41851cc572c9Timo Sirainen /* for doveconf -n to see this KEY_LIST */
c84c0d4cb7f16aedbcb3d5db6b2d41851cc572c9Timo Sirainen ctx->callback(key, "", CONFIG_KEY_LIST, ctx->context);
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen key = p_strconcat(ctx->pool, str_c(ctx->prefix),
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen if (hash_table_lookup(ctx->keys, key) == NULL) {
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen for (i = 0; i < count; i++) {
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen str_append_c(ctx->prefix, SETTINGS_SEPARATOR);
d1d425c3ed541dde4ae11e88291a0044e6c55f88Timo Sirainen setting_export_section_name(ctx->prefix, def, children[i], i);
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen str_append_c(ctx->prefix, SETTINGS_SEPARATOR);
633a3da9d3e9a5befd3405f6651043a6bdd327cbTimo Sirainenconfig_export_init(const char *const *modules, enum config_dump_scope scope,
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainen config_request_callback_t *callback, void *context)
acb0236a7a1242f567cec83480c1efc9fc352f63Timo Sirainen pool = pool_alloconly_create(MEMPOOL_GROWING"config export", 1024*64);
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainen ctx = p_new(pool, struct config_export_context, 1);
3b3a70990ab21c97140fcc2d1e3eb84c17d90388Timo Sirainen ctx->modules = modules == NULL ? NULL : p_strarray_dup(pool, modules);
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainen hash_table_create(&ctx->keys, ctx->pool, 0, str_hash, strcmp);
c0787d6ab19f4a17ec08699d0bbc77f13a9b02a9Timo Sirainenvoid config_export_by_filter(struct config_export_context *ctx,
194755bdfb97c07ca8b9df071099f68947b971e3Timo Sirainen if (config_filter_parsers_get(config_filter, ctx->pool,
c0787d6ab19f4a17ec08699d0bbc77f13a9b02a9Timo Sirainenvoid config_export_parsers(struct config_export_context *ctx,
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainenvoid config_export_get_output(struct config_export_context *ctx,
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainen struct master_service_settings_output *output_r)
4ecee121e141083faf1db165f0ee3bc0cd232d7eTimo Sirainenconfig_export_get_import_environment(struct config_export_context *ctx)
4ecee121e141083faf1db165f0ee3bc0cd232d7eTimo Sirainen unsigned int i;
4ecee121e141083faf1db165f0ee3bc0cd232d7eTimo Sirainen for (i = 0; ctx->parsers[i].root != NULL; i++) {
4ecee121e141083faf1db165f0ee3bc0cd232d7eTimo Sirainen if (ctx->parsers[i].root == &master_service_setting_parser_info) {
4ecee121e141083faf1db165f0ee3bc0cd232d7eTimo Sirainen settings_parse_get_value(ctx->parsers[i].parser,
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainenstatic void config_export_free(struct config_export_context *ctx)
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainenint config_export_finish(struct config_export_context **_ctx)
6ed1e82824590b514201d9db84ba96bdfc832dd5Timo Sirainen unsigned int i;
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainen for (i = 0; ctx->parsers[i].root != NULL; i++) {
633a3da9d3e9a5befd3405f6651043a6bdd327cbTimo Sirainen if (!config_module_want_parser(config_module_parsers,
de4869f239d3cae00f4ddab43edb01f8b0223f7dAki Tuomi const char *const *value = settings_parse_get_value(parser->parser, "ssl", &stype);
63e9db4f938bec812ec1b2b447c7de45183a4f43Aki Tuomi if ((ctx->flags & CONFIG_DUMP_FLAG_IN_SECTION) == 0 &&
de4869f239d3cae00f4ddab43edb01f8b0223f7dAki Tuomi settings_parse_is_valid_key(parser->parser, "ssl_dh")) {
551f3b2ebd588ca125c01f49b54c4103fbd5b2c5Aki Tuomi settings_parse_line(parser->parser, t_strdup_printf("%s=%s", "ssl_dh", newval));
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainen if ((ctx->flags & CONFIG_DUMP_FLAG_CHECK_SETTINGS) != 0) {
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainen if (!settings_parser_check(parser->parser, ctx->pool,