1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci *
4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci */
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci#include <stdio.h>
11e1051a39Sopenharmony_ci#include <string.h>
12e1051a39Sopenharmony_ci#include <openssl/bio.h>
13e1051a39Sopenharmony_ci#include <openssl/conf.h>
14e1051a39Sopenharmony_ci#include <openssl/safestack.h>
15e1051a39Sopenharmony_ci#include <openssl/err.h>
16e1051a39Sopenharmony_ci
17e1051a39Sopenharmony_cistatic void dump_section(const char *name, const CONF *cnf)
18e1051a39Sopenharmony_ci{
19e1051a39Sopenharmony_ci    STACK_OF(CONF_VALUE) *sect = NCONF_get_section(cnf, name);
20e1051a39Sopenharmony_ci    int i;
21e1051a39Sopenharmony_ci
22e1051a39Sopenharmony_ci    printf("[ %s ]\n", name);
23e1051a39Sopenharmony_ci    for (i = 0; i < sk_CONF_VALUE_num(sect); i++) {
24e1051a39Sopenharmony_ci        CONF_VALUE *cv = sk_CONF_VALUE_value(sect, i);
25e1051a39Sopenharmony_ci
26e1051a39Sopenharmony_ci        printf("%s = %s\n", cv->name, cv->value);
27e1051a39Sopenharmony_ci    }
28e1051a39Sopenharmony_ci}
29e1051a39Sopenharmony_ci
30e1051a39Sopenharmony_ciint main(int argc, char **argv)
31e1051a39Sopenharmony_ci{
32e1051a39Sopenharmony_ci    long eline;
33e1051a39Sopenharmony_ci    CONF *conf = NCONF_new(NCONF_default());
34e1051a39Sopenharmony_ci    int ret = 1;
35e1051a39Sopenharmony_ci    STACK_OF(OPENSSL_CSTRING) *section_names = NULL;
36e1051a39Sopenharmony_ci
37e1051a39Sopenharmony_ci    if (conf != NULL && NCONF_load(conf, argv[1], &eline)) {
38e1051a39Sopenharmony_ci        int i;
39e1051a39Sopenharmony_ci
40e1051a39Sopenharmony_ci        section_names = NCONF_get_section_names(conf);
41e1051a39Sopenharmony_ci        for (i = 0; i < sk_OPENSSL_CSTRING_num(section_names); i++) {
42e1051a39Sopenharmony_ci            dump_section(sk_OPENSSL_CSTRING_value(section_names, i), conf);
43e1051a39Sopenharmony_ci        }
44e1051a39Sopenharmony_ci        sk_OPENSSL_CSTRING_free(section_names);
45e1051a39Sopenharmony_ci        ret = 0;
46e1051a39Sopenharmony_ci    } else {
47e1051a39Sopenharmony_ci        ERR_print_errors_fp(stderr);
48e1051a39Sopenharmony_ci    }
49e1051a39Sopenharmony_ci    NCONF_free(conf);
50e1051a39Sopenharmony_ci    return ret;
51e1051a39Sopenharmony_ci}
52