示例#1
0
long NCONF_get_number(CONF *conf,char *group,char *name)
  {
  int status;
  long ret=0;

  status = NCONF_get_number_e(conf, group, name, &ret);
  if (status == 0)
    {
    /* This function does not believe in errors... */
    ERR_get_error();
    }
  return ret;
  }
示例#2
0
long CONF_get_number(LHASH *conf,const char *group,const char *name)
  {
  int status;
  long result = 0;

  if (conf == NULL)
    {
    status = NCONF_get_number_e(NULL, group, name, &result);
    }
  else
    {
    CONF ctmp;
    CONF_set_nconf(&ctmp, conf);
    status = NCONF_get_number_e(&ctmp, group, name, &result);
    }

  if (status == 0)
    {
    /* This function does not believe in errors... */
    ERR_clear_error();
    }
  return result;
  }
示例#3
0
int main(int argc, char **argv)
{
    int result = 0;
    long num_tests;

    if (argc != 2)
        return 1;

    conf = NCONF_new(NULL);
    OPENSSL_assert(conf != NULL);

    /* argv[1] should point to the test conf file */
    OPENSSL_assert(NCONF_load(conf, argv[1], NULL) > 0);

    OPENSSL_assert(NCONF_get_number_e(conf, NULL, "num_tests", &num_tests));

    ADD_ALL_TESTS(test_handshake, (int)(num_tests));
    result = run_tests(argv[0]);

    return result;
}
示例#4
0
int TS_CONF_set_clock_precision_digits(CONF *conf, const char *section,
				       TS_RESP_CTX *ctx)
	{
	int ret = 0;
	long digits = 0;
	
	/* If not specified, set the default value to 0, i.e. sec  precision */
	if (!NCONF_get_number_e(conf, section, ENV_CLOCK_PRECISION_DIGITS,
				&digits))
		digits = 0;
	if (digits < 0 || digits > TS_MAX_CLOCK_PRECISION_DIGITS)
		{
		TS_CONF_invalid(section, ENV_CLOCK_PRECISION_DIGITS);
		goto err;
		}

	if (!TS_RESP_CTX_set_clock_precision_digits(ctx, digits))
		goto err;

	return 1;
 err:
	return ret;
	}
示例#5
0
static int int_engine_configure(char *name, char *value, const CONF *cnf)
	{
	int i;
	int ret = 0;
	long do_init = -1;
	STACK_OF(CONF_VALUE) *ecmds;
	CONF_VALUE *ecmd;
	char *ctrlname, *ctrlvalue;
	ENGINE *e = NULL;
	name = skip_dot(name);
#ifdef ENGINE_CONF_DEBUG
	fprintf(stderr, "Configuring engine %s\n", name);
#endif
	/* Value is a section containing ENGINE commands */
	ecmds = NCONF_get_section(cnf, value);

	if (!ecmds)
		{
		ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_ENGINE_SECTION_ERROR);
		return 0;
		}

	for (i = 0; i < sk_CONF_VALUE_num(ecmds); i++)
		{
		ecmd = sk_CONF_VALUE_value(ecmds, i);
		ctrlname = skip_dot(ecmd->name);
		ctrlvalue = ecmd->value;
#ifdef ENGINE_CONF_DEBUG
	fprintf(stderr, "ENGINE conf: doing ctrl(%s,%s)\n", ctrlname, ctrlvalue);
#endif

		/* First handle some special pseudo ctrls */

		/* Override engine name to use */
		if (!strcmp(ctrlname, "engine_id"))
			name = ctrlvalue;
		/* Load a dynamic ENGINE */
		else if (!strcmp(ctrlname, "dynamic_path"))
			{
			e = ENGINE_by_id("dynamic");
			if (!e)
				goto err;
			if (!ENGINE_ctrl_cmd_string(e, "SO_PATH", ctrlvalue, 0))
				goto err;
			if (!ENGINE_ctrl_cmd_string(e, "LIST_ADD", "2", 0))
				goto err;
			if (!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0))
				goto err;
			}
		/* ... add other pseudos here ... */
		else
			{
			/* At this point we need an ENGINE structural reference
			 * if we don't already have one.
			 */
			if (!e)
				{
				e = ENGINE_by_id(name);
				if (!e)
					return 0;
				}
			/* Allow "EMPTY" to mean no value: this allows a valid
			 * "value" to be passed to ctrls of type NO_INPUT
		 	 */
			if (!strcmp(ctrlvalue, "EMPTY"))
				ctrlvalue = NULL;
			if (!strcmp(ctrlname, "init"))
				{
				if (!NCONF_get_number_e(cnf, value, "init", &do_init))
					goto err;
				if (do_init == 1)
					{
					if (!int_engine_init(e))
						goto err;
					}
				else if (do_init != 0)
					{
					ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_INVALID_INIT_VALUE);
					goto err;
					}
				}
			else if (!strcmp(ctrlname, "default_algorithms"))
				{
				if (!ENGINE_set_default_string(e, ctrlvalue))
					goto err;
				}
			else if (!ENGINE_ctrl_cmd_string(e,
					ctrlname, ctrlvalue, 0))
				return 0;
			}



		}
	if (e && (do_init == -1) && !int_engine_init(e))
		goto err;
	ret = 1;
	err:
	if (e)
		ENGINE_free(e);
	return ret;
	}
示例#6
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;
}
示例#7
0
/* launch a service */
pid_t launch_svc(CONF *conf, const char *name)
{
    int fds[2], i;
    pid_t pid;
    char *cmd, *args, *argv[32] = {0}, **ap, *dir;
    char *groups;
    long uid, gid;

    if (nsvcs)
        warnx("Launching service %d: %s", nsvcs, name);
    else
        warnx("Launching %s", name);

    if (!(cmd = NCONF_get_string(conf, name, "cmd")))
        errx(1, "`cmd' missing in [%s]", name);

    if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds))
        err(1, "socketpair");

    switch ((pid = fork()))
    {
    case -1: /* error */
        err(1, "fork");
    case 0:  /* child */
        close(fds[0]);
        break;
    default: /* parent */
        warnx("%s: pid %d", name, pid);
        close(fds[1]);
        svcfds[nsvcs] = fds[0];
        ++nsvcs;
        return pid;
    }

    /* child */
    argv[0] = cmd;
    /* argv[1] is used by svc to receive data from zookd */
    asprintf(&argv[1], "%d", fds[1]);

    /* split extra arguments */
    if ((args = NCONF_get_string(conf, name, "args")))
    {
        for (ap = &argv[2]; (*ap = strsep(&args, " \t")) != NULL; )
            if (**ap != '\0')
                if (++ap >= &argv[31])
                    break;
    }

    if (NCONF_get_number_e(conf, name, "uid", &uid))
    {
        /* change real, effective, and saved uid to uid */
        warnx("setuid %ld", uid);
    }

    if (NCONF_get_number_e(conf, name, "gid", &gid))
    {
        /* change real, effective, and saved gid to gid */
        warnx("setgid %ld", gid);
    }

    if ((groups = NCONF_get_string(conf, name, "extra_gids")))
    {
        ngids = 0;
        CONF_parse_list(groups, ',', 1, &group_parse_cb, NULL);
        /* set the grouplist to gids */
        for (i = 0; i < ngids; i++)
            warnx("extra gid %d", gids[i]);
    }

    if ((dir = NCONF_get_string(conf, name, "dir")))
    {
        /* chroot into dir */
    }

    signal(SIGCHLD, SIG_DFL);
    signal(SIGPIPE, SIG_DFL);

    execv(argv[0], argv);
    err(1, "execv %s %s", argv[0], argv[1]);
}