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