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