예제 #1
0
END_TEST

START_TEST(test_create_from_string_any_v6)
{
	host_t *host;

	host = host_create_from_string("%any6", 500);
	verify_any(host, AF_INET6, 500);
	host->destroy(host);

	host = host_create_from_string("::", 500);
	verify_any(host, AF_INET6, 500);
	host->destroy(host);

	host = host_create_from_string("fec1::1", 500);
	verify_address(host, addr_v6, AF_INET6, 500);
	host->destroy(host);

	host = host_create_from_string("fec1::1.500", 500);
	ck_assert(host == NULL);
	host = host_create_from_string("f::e::c::1::1", 500);
	ck_assert(host == NULL);
	host = host_create_from_string("foo::bar", 500);
	ck_assert(host == NULL);
}
예제 #2
0
static void test_create_from_string_and_family_addr(char *string, chunk_t addr,
													int family, int expected)
{
	host_t *host;

	host = host_create_from_string_and_family(string, family, 500);
	if (expected == AF_UNSPEC)
	{
		ck_assert(host == NULL);
	}
	else
	{
		verify_address(host, addr, expected, 500);
		host->destroy(host);
	}
}
예제 #3
0
파일: two_tree.c 프로젝트: bernardo5/ADRC-4
int AddressLookUp(node*root, char*address){
	if(verify_address(address)==-1) return -1;
	int bit=0;
	node*auxiliar=root;
	while(bit<strlen(address)){
				if(address[bit]=='0'){
					if((auxiliar->zero)==NULL){
						return auxiliar->next_hop;
					}
					auxiliar=auxiliar->zero;
				}else{
					if((auxiliar->one)==NULL){
						return auxiliar->next_hop;
					}	
					auxiliar=auxiliar->one;
				}
				bit++;
	}
	return -1;	
}
예제 #4
0
END_TEST

/*******************************************************************************
 * host_create_from_dns
 */

static void test_create_from_dns(int family, chunk_t addr)
{
	host_t *host;

	host = host_create_from_dns("localhost", family, 500);
	if (family != AF_INET6)
	{
		ck_assert(host != NULL);
	}
	if (host)
	{
		if (family != AF_UNSPEC)
		{
			verify_address(host, addr, family, 500);
		}
		host->destroy(host);
	}
}
예제 #5
0
int
rf_get_errors_address(address_item *addr, router_instance *rblock,
  int verify, uschar **errors_to)
{
uschar *s;

*errors_to = addr->prop.errors_address;
if (rblock->errors_to == NULL) return OK;

s = expand_string(rblock->errors_to);

if (s == NULL)
  {
  if (f.expand_string_forcedfail)
    {
    DEBUG(D_route)
      debug_printf("forced expansion failure - ignoring errors_to\n");
    return OK;
    }
  addr->message = string_sprintf("%s router failed to expand \"%s\": %s",
    rblock->name, rblock->errors_to, expand_string_message);
  return DEFER;
  }

/* If the errors_to address is empty, it means "ignore errors" */

if (*s == 0)
  {
  addr->prop.ignore_error = TRUE;   /* For locally detected errors */
  *errors_to = US"";                   /* Return path for SMTP */
  return OK;
  }

/* If we are already verifying, do not check the errors address, in order to
save effort (but we do verify when testing an address). When we do verify, set
the sender address to null, because that's what it will be when sending an
error message, and there are now configuration options that control the running
of routers by checking the sender address. When testing an address, there may
not be a sender address. We also need to save and restore the expansion values
associated with an address. */

if (verify != v_none)
  {
  *errors_to = s;
  DEBUG(D_route)
    debug_printf("skipped verify errors_to address: already verifying\n");
  }
else
  {
  BOOL save_address_test_mode = f.address_test_mode;
  int save1 = 0;
  int i;
  const uschar ***p;
  const uschar *address_expansions_save[ADDRESS_EXPANSIONS_COUNT];
  address_item *snew = deliver_make_addr(s, FALSE);

  if (sender_address != NULL)
    {
    save1 = sender_address[0];
    sender_address[0] = 0;
    }

  for (i = 0, p = address_expansions; *p != NULL;)
    address_expansions_save[i++] = **p++;
  f.address_test_mode = FALSE;

  /* NOTE: the address is verified as a recipient, not a sender. This is
  perhaps confusing. It isn't immediately obvious what to do: we want to have
  some confidence that we can deliver to the address, in which case it will be
  a recipient, but on the other hand, it will be passed on in SMTP deliveries
  as a sender. However, I think on balance recipient is right because sender
  verification is really about the *incoming* sender of the message.

  If this code is changed, note that you must set vopt_fake_sender instead of
  vopt_is_recipient, as otherwise sender_address may be altered because
  verify_address() thinks it is dealing with *the* sender of the message. */

  DEBUG(D_route|D_verify)
    debug_printf("------ Verifying errors address %s ------\n", s);
  if (verify_address(snew, NULL,
      vopt_is_recipient /* vopt_fake_sender is the alternative */
      | vopt_qualify, -1, -1, -1, NULL, NULL, NULL) == OK)
    *errors_to = snew->address;
  DEBUG(D_route|D_verify)
    debug_printf("------ End verifying errors address %s ------\n", s);

  f.address_test_mode = save_address_test_mode;
  for (i = 0, p = address_expansions; *p != NULL;)
    **p++ = address_expansions_save[i++];

  if (sender_address != NULL) sender_address[0] = save1;
  }

return OK;
}
예제 #6
0
int owfd_dhcp_parse_argv(struct owfd_dhcp_config *conf, int argc, char **argv)
{
	int c;
	bool help = false;
	char *t;
	int r;

	opterr = 0;
	while (1) {
		c = getopt_long(argc, argv, short_options, long_options, NULL);
		if (c <= 0) {
			break;
		} else if (c == ':') {
			fprintf(stderr, "missing argument for: %s\n",
				argv[optind - 1]);
			return -EINVAL;
		} else if (c == '?') {
			if (optopt && optopt < LONG_OPT_OFFSET)
				fprintf(stderr, "unknown argument: -%c\n",
					optopt);
			else if (!optopt)
				fprintf(stderr, "unknown argument: %s\n",
					argv[optind - 1]);
			else
				fprintf(stderr, "option takes no arg: %s\n",
					argv[optind - 1]);
			return -EINVAL;
		}

#define OPT(_num) LONG_OPT_OFFSET + _num
		switch (c) {
		case 'h':
		case OPT(OPT_HELP):
			help = true;
			break;
		case 'v':
		case OPT(OPT_VERBOSE):
			conf->verbose = 1;
			break;
		case OPT(OPT_SILENT):
			conf->silent = 1;
			break;
		case OPT(OPT_DEBUG):
			conf->debug = 1;
			break;

		case 'c':
		case OPT(OPT_CLIENT):
			conf->server = 0;
			conf->client = 1;
			break;
		case 's':
		case OPT(OPT_SERVER):
			conf->client = 0;
			conf->server = 1;
			break;
		case '4':
		case OPT(OPT_IPV4):
			conf->ipv6 = 0;
			conf->ipv4 = 1;
			break;
		case '6':
		case OPT(OPT_IPV6):
			conf->ipv4 = 0;
			conf->ipv6 = 1;
			break;

		case 'i':
		case OPT(OPT_INTERFACE):
			t = strdup(optarg);
			if (!t)
				return OOM();
			free(conf->interface);
			conf->interface = t;
			break;
		case OPT(OPT_IP_BINARY):
			t = strdup(optarg);
			if (!t)
				return OOM();
			free(conf->ip_binary);
			conf->ip_binary = t;
			break;

		case OPT(OPT_LOCAL):
			t = strdup(optarg);
			if (!t)
				return OOM();
			free(conf->local);
			conf->local = t;
			break;
		case OPT(OPT_GATEWAY):
			t = strdup(optarg);
			if (!t)
				return OOM();
			free(conf->gateway);
			conf->gateway = t;
			break;
		case OPT(OPT_DNS):
			t = strdup(optarg);
			if (!t)
				return OOM();
			free(conf->dns);
			conf->dns = t;
			break;
		case OPT(OPT_SUBNET):
			t = strdup(optarg);
			if (!t)
				return OOM();
			free(conf->subnet);
			conf->subnet = t;
			break;
		case OPT(OPT_IP_FROM):
			t = strdup(optarg);
			if (!t)
				return OOM();
			free(conf->ip_from);
			conf->ip_from = t;
			break;
		case OPT(OPT_IP_TO):
			t = strdup(optarg);
			if (!t)
				return OOM();
			free(conf->ip_to);
			conf->ip_to = t;
			break;
		}
#undef OPT
	}

	if (help) {
		show_help();
		return -EAGAIN;
	}

	if (optind < argc) {
		fprintf(stderr,
			"unparsed remaining arguments starting with: %s\n",
			argv[optind]);
		return -EINVAL;
	}

	if (!conf->client && !conf->server) {
		fprintf(stderr,
			"no --client or --server given\n");
		return -EINVAL;
	}

	if (!conf->ipv4 && !conf->ipv6) {
		fprintf(stderr, "no --ipv4 or --ipv6 given\n");
		return -EINVAL;
	}

	if (conf->ipv6) {
		fprintf(stderr, "--ipv6 not implemented by gdhcp, yet\n");
		return -EINVAL;
	}

	if (!conf->interface) {
		fprintf(stderr, "no interface given, use: -i <iface>\n");
		return -EINVAL;
	}

	if (!conf->ip_binary) {
		conf->ip_binary = strdup(BUILD_BINDIR_IP "/ip");
		if (!conf->ip_binary)
			return OOM();
	}

	if (conf->server) {
		r = verify_address("--local", conf->local, conf->ipv4);
		if (r >= 0 && conf->ipv4)
			r = make_ipv4(&conf->local);
		if (r < 0)
			return r;

		r = verify_address("--gateway", conf->gateway, conf->ipv4);
		if (r >= 0 && conf->ipv4)
			r = make_ipv4(&conf->gateway);
		if (r < 0)
			return r;

		r = verify_address("--dns", conf->dns, conf->ipv4);
		if (r >= 0 && conf->ipv4)
			r = make_ipv4(&conf->dns);
		if (r < 0)
			return r;

		r = verify_address("--subnet", conf->subnet, conf->ipv4);
		if (r >= 0 && conf->ipv4)
			r = make_ipv4(&conf->subnet);
		if (r < 0)
			return r;

		r = verify_address("--ip-from", conf->ip_from, conf->ipv4);
		if (r >= 0 && conf->ipv4)
			r = make_ipv4(&conf->ip_from);
		if (r < 0)
			return r;

		r = verify_address("--ip-to", conf->ip_to, conf->ipv4);
		if (r >= 0 && conf->ipv4)
			r = make_ipv4(&conf->ip_to);
		if (r < 0)
			return r;
	}

	return 0;
}