Ejemplo n.º 1
0
void CONF_set_nconf(CONF *conf, LHASH *hash)
  {
  if (default_CONF_method == NULL)
    default_CONF_method = NCONF_default();

  default_CONF_method->init(conf);
  conf->data = hash;
  }
Ejemplo n.º 2
0
CONF *NCONF_new(CONF_METHOD *meth)
  {
  CONF *ret;

  if (meth == NULL)
    meth = NCONF_default();

  ret = meth->create(meth);
  if (ret == NULL)
    {
    CONFerr(CONF_F_NCONF_NEW,ERR_R_MALLOC_FAILURE);
    return(NULL);
    }

  return ret;
  }
Ejemplo n.º 3
0
long CONF_get_number(LHASH_OF(CONF_VALUE) *conf, const char *group,
		const char *name);
void CONF_free(LHASH_OF(CONF_VALUE) *conf);
int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out);
int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out);


#ifdef __cplusplus
}
#endif /* ifdef __cplusplus */


void CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash)
{
	if (default_CONF_method == NULL)
		default_CONF_method = NCONF_default();

	default_CONF_method->init(conf);
	conf->data = hash;
}

LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file,
		long *eline)
{
	LHASH_OF(CONF_VALUE) *ltmp;
	BIO *in = NULL;

#ifdef OPENSSL_SYS_VMS
	in = BIO_new_file(file, "r");
#else  /* ifdef OPENSSL_SYS_VMS */
	in = BIO_new_file(file, "rb");
Ejemplo n.º 4
0
int CertCfgOpenConfigFile(const char *configFile, const char *configName)
{
  const char *pConfigFile = configFile;
  char *dirName;
  long err = 0;
  int len;
  CONF *conf;
  
  if (NULL == pConfigFile)
    {
      // first check the environment
      pConfigFile = getenv("OPENSSL_CONF");
      
      // if it didn't find it we'll use the default
      if (NULL == pConfigFile)
        pConfigFile = CERT_DEF_CONF_FILE;
    }
  
  // keep a copy in case of error
  CertCfgSetObjectStrValue(CERTCFG_CONFIG_FILE, pConfigFile);
  
  // make sure it's reasonable
  
  if (MAX_CERT_PATH <= (len = strlen(pConfigFile)))
    {
      return CERT_PATH_LIMIT_EXCEEDED;
    }
  conf = NCONF_new(NCONF_default());
  if (!NCONF_load(conf, pConfigFile, &err))
    {
      if (err == 0)
        {
          PRINT_RETURN_CODE(CERT_OPEN_FILE_FAILED);
          return CERT_OPEN_FILE_FAILED;
        }
      else
        {
          PRINT_RETURN_CODE(CERT_ILLFORMED_CONFIG_FILE);
          return CERT_ILLFORMED_CONFIG_FILE;
        }
    }
  
  /* Figure out the configuration inside the designate file that we want 
   * to use
   */
  if (NULL == configName)
    {
      if (!(configName = NCONF_get_string (conf, "ca", "default_ca")))
        return CERT_CONFIG_UNAVAILABLE;
    }
  
  
  /*
   * Let's find out if there is anything reasonable
   */
  if (!(dirName = NCONF_get_string (conf, configName, "dir")))
    {
      PRINT_RETURN_CODE(CERT_ILLFORMED_CONFIG_FILE);
      err = CERT_ILLFORMED_CONFIG_FILE;
    }
  else
    {
      struct stat statBuf;
      if (0 != stat(dirName, &statBuf))
        {
          fprintf(stdout, "Can't find %s\n", dirName);
          err = CERT_UNDEFINED_ROOT_DIR;
        }
    }
  
  // Cache it away
  CertCfgSetObjectStrValue(CERTCFG_CONFIG_NAME, (const char *)configName);
  configObject.conf = conf;
	
  // Now resolve the rest of the defaults from the config file
  // We are asuming that the file is well formed or this might have problems.
  // if we can't resolve the directory then fail.
  // if we can't resolve the subdirectories, don't fail put them under dir.
	
  populateConfig();

  return err;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
  int                  i;
  long                 i_val, err = 0;
  char                 *key, *s_val;
  STACK_OF(CONF_VALUE) *sec;
  CONF_VALUE           *item;
  CONF                 *conf;
 
  conf = NCONF_new(NCONF_default(  ));
  if (!NCONF_load(conf, CONFFILE, &err))
    {
      if (err == 0)
	int_error("Error opening configuration file");
      else
        {
	  fprintf(stderr, "Error in %s on line %li\n", CONFFILE, err);
	  int_error("Errors parsing configuration file");
        }
    }
  if (!(s_val = NCONF_get_string(conf, NULL, GLOB_VAR)))
    {
      fprintf(stderr, "Error finding \"%s\" in [%s]\n", GLOB_VAR, NULL);
      int_error("Error finding string");
    }
  printf("Sec: %s, Key: %s, Val: %s\n", NULL, GLOB_VAR, s_val);
#if (OPENSSL_VERSION_NUMBER > 0x00907000L)
  if (!(err = NCONF_get_number_e(conf, NULL, GLOB_NUM, &i_val)))
    {
      fprintf(stderr, "Error finding \"%s\" in [%s]\n", GLOB_NUM, NULL);
      int_error("Error finding number");
    }
#else
  if (!(s_val = NCONF_get_string(conf, NULL, GLOB_NUM)))
    {
      fprintf(stderr, "Error finding \"%s\" in [%s]\n", GLOB_VAR, NULL);
      int_error("Error finding number");
    }
  i_val = atoi(s_val);
#endif
  printf("Sec: %s, Key: %s, Val: %i\n", NULL, GLOB_VAR, i_val);
  if (!(key = NCONF_get_string(conf, PARAMS, SEC_NAME)))
    {
      fprintf(stderr, "Error finding \"%s\" in [%s]\n", SEC_NAME, PARAMS);
      int_error("Error finding string");
    }
  printf("Sec: %s, Key: %s, Val: %s\n", PARAMS, SEC_NAME, key);
  if (!(sec = NCONF_get_section(conf, key)))
    {
      fprintf(stderr, "Error finding [%s]\n", key);
      int_error("Error finding string");
    }
  for (i = 0;  i < sk_CONF_VALUE_num(sec);  i++)
    {
      item = sk_CONF_VALUE_value(sec, i);
      printf("Sec: %s, Key: %s, Val: %s\n",
	     item->section, item->name, item->value);
    }
 
  NCONF_free(conf);
  return 0;
}