#include <openssl/conf.h>
#include <stdio.h>
#include <string.h>

char *tls_minprot= NULL;
unsigned int recursion_depth= 0;

void read_sect(CONF *nconf, const char *section)
{
  STACK_OF(CONF_VALUE) *sect = NULL;
  int i;
  CONF_VALUE *cnf;

  recursion_depth++;

  if (recursion_depth > 10 ||
     !(sect = NCONF_get_section(nconf, section)))
    goto end; 

  for (i = 0; i < sk_CONF_VALUE_num(sect); i++) {
     cnf = sk_CONF_VALUE_value(sect, i);
     if (!strcmp(cnf->name, "MinProtocol"))
     {
       if (tls_minprot)
         free(tls_minprot);
       tls_minprot= strdup(cnf->value);
     }
     else
       read_sect(nconf, cnf->value);
  }
end:
  recursion_depth--;
  return;
}

int main(int argc, char *argv[])
{
  CONF *nconf;
  long errline= -1;

  nconf= NCONF_new(NCONF_default());
  if (NCONF_load(nconf, CONF_get1_default_config_file(), &errline) < 0)
  {
    fprintf(stdout, "Couldn't open default configuration file %s", CONF_get1_default_config_file());
    exit(-1);
  }
  read_sect(nconf, "default");
  NCONF_free(nconf);
  if (tls_minprot)
    fprintf(stdout, "%s\n", tls_minprot); 
  return 0;
}


