コード例 #1
0
ファイル: proto.c プロジェクト: Oryon/bird-ext-lsa
static void
proto_init_instance(struct proto *p)
{
  /* Here we cannot use p->cf->name since it won't survive reconfiguration */
  p->pool = rp_new(proto_pool, p->proto->name);
  p->attn = ev_new(p->pool);
  p->attn->data = p;

  if (! p->proto->multitable)
    rt_lock_table(p->table);
}
コード例 #2
0
ファイル: conf.c プロジェクト: Oryon/bird-ext-lsa
/**
 * config_alloc - allocate a new configuration
 * @name: name of the config
 *
 * This function creates new &config structure, attaches a resource
 * pool and a linear memory pool to it and makes it available for
 * further use. Returns a pointer to the structure.
 */
struct config *
config_alloc(byte *name)
{
  pool *p = rp_new(&root_pool, "Config");
  linpool *l = lp_new(p, 4080);
  struct config *c = lp_allocz(l, sizeof(struct config));

  c->mrtdump_file = -1; /* Hack, this should be sysdep-specific */
  c->pool = p;
  cfg_mem = c->mem = l;
  c->file_name = cfg_strdup(name);
  c->load_time = now;
  c->tf_base.fmt1 = c->tf_log.fmt1 = "%d-%m-%Y %T";

  return c;
}
コード例 #3
0
ファイル: cli.c プロジェクト: yubo/bird
struct cli *
cli_new(void *priv)
{
  struct pool *p = rp_new(cli_pool, "CLI");
  struct cli *c = mb_alloc(p, sizeof(struct cli));

  bzero(c, sizeof(struct cli));
  c->pool = p;
  c->priv = priv;
  c->event = ev_new(p);
  c->event->hook = cli_event;
  c->event->data = c;
  c->cont = cli_hello;
  c->parser_pool = lp_new(c->pool, 4096);
  c->rx_buf = mb_alloc(c->pool, CLI_RX_BUF_SIZE);
  ev_schedule(c->event);
  return c;
}
コード例 #4
0
ファイル: conf.c プロジェクト: BIRD/bird
/**
 * config_alloc - allocate a new configuration
 * @name: name of the config
 *
 * This function creates new &config structure, attaches a resource
 * pool and a linear memory pool to it and makes it available for
 * further use. Returns a pointer to the structure.
 */
struct config *
config_alloc(const byte *name)
{
  pool *p = rp_new(&root_pool, "Config");
  linpool *l = lp_new(p, 4080);
  struct config *c = lp_allocz(l, sizeof(struct config));

  /* Duplication of name string in local linear pool */
  uint nlen = strlen(name) + 1;
  char *ndup = lp_allocu(l, nlen);
  memcpy(ndup, name, nlen);

  c->mrtdump_file = -1; /* Hack, this should be sysdep-specific */
  c->pool = p;
  c->mem = l;
  c->file_name = ndup;
  c->load_time = now;
  c->tf_route = c->tf_proto = (struct timeformat){"%T", "%F", 20*3600};
  c->tf_base = c->tf_log = (struct timeformat){"%F %T", NULL, 0};
  c->gr_wait = DEFAULT_GR_WAIT;

  return c;
}

/**
 * config_parse - parse a configuration
 * @c: configuration
 *
 * config_parse() reads input by calling a hook function pointed to
 * by @cf_read_hook and parses it according to the configuration
 * grammar. It also calls all the preconfig and postconfig hooks
 * before, resp. after parsing.
 *
 * Result: 1 if the config has been parsed successfully, 0 if any
 * error has occurred (such as anybody calling cf_error()) and
 * the @err_msg field has been set to the error message.
 */
int
config_parse(struct config *c)
{
  int done = 0;
  DBG("Parsing configuration file `%s'\n", c->file_name);
  new_config = c;
  cfg_mem = c->mem;
  if (setjmp(conf_jmpbuf))
    goto cleanup;

  cf_lex_init(0, c);
  sysdep_preconfig(c);
  protos_preconfig(c);
  rt_preconfig(c);
  roa_preconfig(c);
  cf_parse();
  protos_postconfig(c);
  if (EMPTY_LIST(c->protos))
    cf_error("No protocol is specified in the config file");
#ifdef IPV6
  if (!c->router_id)
    cf_error("Router ID must be configured manually on IPv6 routers");
#endif
  done = 1;

cleanup:
  new_config = NULL;
  cfg_mem = NULL;
  return done;
}

/**
 * cli_parse - parse a CLI command
 * @c: temporary config structure
 *
 * cli_parse() is similar to config_parse(), but instead of a configuration,
 * it parses a CLI command. See the CLI module for more information.
 */
int
cli_parse(struct config *c)
{
  int done = 0;
  c->fallback = config;
  new_config = c;
  cfg_mem = c->mem;
  if (setjmp(conf_jmpbuf))
    goto cleanup;

  cf_lex_init(1, c);
  cf_parse();
  done = 1;

cleanup:
  c->fallback = NULL;
  new_config = NULL;
  cfg_mem = NULL;
  return done;
}
コード例 #5
0
ファイル: rpowsign.c プロジェクト: NakamotoInstitute/RPOW
/* Implement the rpow signature function */
int
dosign (sccRequestHeader_t *req, sccOA_CKO_Name_t *certname,
		sccRSAKeyToken_t *commkey, unsigned long commkeylen,
		sccRSAKeyToken_t *key, unsigned long keylen)
{
	long rc;
	struct encstate encdata;
	rpow **rp = NULL;
	rpowpend **rpend = NULL;
	rpowio *rpio;
	gbignum *reply = NULL;
	gbignum tmp1;
	gbignum invalue;
	gbignum outvalue;
	int rpicount, rpocount;
	int i;
	int found;
	unsigned char stat;
	unsigned char *buf = NULL;
	unsigned long buflen;
	unsigned char signkeyid[KEYID_LENGTH];

	gbig_init (&tmp1);
	gbig_init (&invalue);
	gbig_init (&outvalue);

	/* First do the RSA decryption on input data */
	if ((rc = decryptmaster (&encdata, req, commkey, commkeylen, 0)) < 0)
		return rc;

	/* Then the TDES decryption on the rest */
	if ((rc = decryptinput (&buf, &buflen, &encdata, req, 1)) < 0)
		return rc;

	stat = RPOW_STAT_BADFORMAT;

	if (buflen == 0)
	{
		if (buf)
			free (buf);
		goto input_error1;
	}

	/* Create our pointer for reading from this buffer */
	/* buf now belongs to this rpio */
	rpio = rp_new_from_malloc_buf (buf, buflen);

	if (rp_read (rpio, &signkeyid, sizeof(signkeyid)) != sizeof(signkeyid))
		goto input_error;

	if (memcmp (signkeyid, rpowsignpk.keyid, sizeof(signkeyid)) != 0)
	{
		stat = RPOW_STAT_WRONGKEY;
		goto input_error;
	}

	if (rp_read (rpio, &rpicount, sizeof(rpicount)) != sizeof(rpicount))
		goto input_error;
	rpicount = ntohl(rpicount);
	if (rpicount > MAXCOUNT || rpicount <= 0)
		goto input_error;
	rp = calloc (rpicount * sizeof (rpow *), 1);
	if (rp == NULL)
		goto input_error;
	gbig_from_word (&invalue, 0);

	/* Read and verify the incoming rpows */
	for (i=0; i<rpicount; i++)
	{
		rp[i] = rpow_read (rpio);
		if (rp[i] == NULL)
			goto input_error;
		stat = rpow_validate (rp[i]);
		if (stat == RPOW_STAT_OK)
		{
			/* Check the seen-rpow database */
			if ((rc = testdbandset (&found, req, rp[i]->id, rp[i]->idlen,
					rp[i]->fileid)) != 0)
				return rc;			/* host lied, should not happen */
			if (found)
				stat = RPOW_STAT_REUSED;
		}

		if (stat != RPOW_STAT_OK)
			goto input_error;
		stat = RPOW_STAT_BADFORMAT;
		gbig_from_word (&tmp1, 0);
		gbig_set_bit (&tmp1, rp[i]->value);
		gbig_add (&invalue, &invalue, &tmp1);
	}
	if (rp_read (rpio, &rpocount, sizeof(rpocount)) != sizeof(rpocount))
		goto input_error;
	rpocount = ntohl(rpocount);
	if (rpocount > MAXCOUNT || rpocount <= 0)
		goto input_error;
	rpend = calloc (rpocount * sizeof (rpowpend *), 1);
	if (rpend == NULL)
		goto input_error;
	reply = calloc (rpocount * sizeof (gbignum), 1);
	if (reply == NULL)
		goto input_error;
	for (i=0; i<rpocount; i++)
		gbig_init (&reply[i]);
	gbig_from_word (&outvalue, 0);

	/* Read the outgoing rpowpend values to be signed */
	for (i=0; i<rpocount; i++)
	{
		rpend[i] = rpowpend_read (rpio);
		if (rpend[i] == NULL)
			goto input_error;
		gbig_from_word (&tmp1, 0);
		gbig_set_bit (&tmp1, rpend[i]->value);
		gbig_add (&outvalue, &outvalue, &tmp1);
	}

	/* Make sure the incoming value == outgoing */
	if (gbig_cmp (&invalue, &outvalue) != 0)
	{
		stat = RPOW_STAT_MISMATCH;
		goto input_error;
	}

	/* Everything is OK, sign the requested values */
	for (i=0; i<rpocount; i++)
	{
		/* Compute rpend[i]->rpow^d mod n using the CRT */
		if ((rc = privkey_rawsign (&reply[i], &rpend[i]->rpow, key, keylen,
						rpend[i]->value-RPOW_VALUE_MIN)) != 0)
		{
			stat = RPOW_STAT_BADRPEND;
			goto input_error;
		}
	}

	stat = RPOW_STAT_OK;

input_error:

	/* Prepare to write results to caller */
	rp_free (rpio);
input_error1:
	rpio = rp_new ();

	if (rp_write (rpio, &stat, 1) < 0)
	{
		rc = ERR_NOMEM;
		goto done;
	}
	if (stat == RPOW_STAT_OK)
	{
		for (i=0; i<rpocount; i++)
		{
			if (bnwrite (&reply[i], rpio) < 0)
			{
				rc = ERR_NOMEM;
				goto done;
			}
		}
	}

	buf = rp_buf (rpio, (unsigned *)&buflen);

	if ((rc = encryptoutput (&encdata, buf, buflen, req, 0)) != 0)
		goto done;

	rc = 0;
	
done:
	rp_free (rpio);

	if (rp)
	{
		for (i=0; i<rpicount; i++)
		{
			if (rp[i])
				rpow_free (rp[i]);
		}
		free (rp);
	}
	if (rpend)
	{
		for (i=0; i<rpocount; i++)
		{
			if (rpend[i])
				rpowpend_free (rpend[i]);
		}
		free (rpend);
	}
	if (reply)
	{
		for (i=0; i<rpocount; i++)
		{
			gbig_free (&reply[i]);
		}
		free (reply);
	}
	gbig_free (&tmp1);
	gbig_free (&invalue);
	gbig_free (&outvalue);

	return rc;
}