confdump.c 1.4 KB

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