Esempio n. 1
0
static int
radius_server_address_load(radius_req_setting *radius, int idx,
    const char *address, enum RADIUS_SERVER_TYPE type)
{
	struct addrinfo *ai;
	struct sockaddr_in *sin4;

	memset(&radius->server[idx], 0, sizeof(radius->server[0]));

	if (addrport_parse(address, IPPROTO_TCP, &ai) !=0)
		return 1;

	switch (ai->ai_family) {
	default:
		freeaddrinfo(ai);
		return 1;
	case AF_INET:
	case AF_INET6:
		break;
	}

	sin4 = (struct sockaddr_in *)(ai->ai_addr);
	if (sin4->sin_port == 0)
		sin4->sin_port = htons((type == RADIUS_SERVER_TYPE_AUTH)
		    ? DEFAULT_RADIUS_AUTH_PORT : DEFAULT_RADIUS_ACCT_PORT);

	memcpy(&radius->server[idx].peer, ai->ai_addr,
	    MIN(sizeof(radius->server[idx].peer), ai->ai_addrlen));

	freeaddrinfo(ai);
	radius->server[idx].enabled = 1;

	return 0;
}
Esempio n. 2
0
int
pptpd_reload(pptpd *_this, struct properties *config, const char *name,
    int default_enabled)
{
	int i, do_start, aierr;
	const char *val;
	char *tok, *cp, buf[PPTPD_CONFIG_BUFSIZ], *label;
	struct addrinfo *ai;

	ASSERT(_this != NULL);
	ASSERT(config != NULL);

	_this->config = config;
	do_start = 0;
	if (pptpd_config_str_equal(_this, CFG_KEY(name, "enabled"), "true",
	    default_enabled)) {
		/* avoid false-true flap */
		if (pptpd_is_shutting_down(_this))
			pptpd_stop_immediatly(_this);
		if (pptpd_is_stopped(_this))
			do_start = 1;
	} else {
		if (!pptpd_is_stopped(_this))
			pptpd_stop(_this);
		return 0;
	}
	if (do_start && pptpd_init(_this) != 0)
		return 1;
	/* set again as pptpd_init will reset it */
	_this->config = config;

	_this->ctrl_in_pktdump = pptpd_config_str_equal(_this,
	    "log.pptp.ctrl.in.pktdump", "true", 0);
	_this->data_in_pktdump = pptpd_config_str_equal(_this,
	    "log.pptp.data.in.pktdump", "true", 0);
	_this->ctrl_out_pktdump = pptpd_config_str_equal(_this,
	    "log.pptp.ctrl.out.pktdump", "true", 0);
	_this->data_out_pktdump = pptpd_config_str_equal(_this,
	    "log.pptp.data.out.pktdump", "true", 0);
	_this->phy_label_with_ifname = pptpd_config_str_equal(_this,
	    CFG_KEY(name, "label_with_ifname"), "true", 0);

	/* parse ip4_allow */
	in_addr_range_list_remove_all(&_this->ip4_allow);
	val = pptpd_config_str(_this, CFG_KEY(name, "ip4_allow"));
	if (val != NULL) {
		if (strlen(val) >= sizeof(buf)) {
			log_printf(LOG_ERR, "configuration error at "
			    "%s: too long", CFG_KEY(name, "ip4_allow"));
			return 1;
		}
		strlcpy(buf, val, sizeof(buf));
		for (cp = buf; (tok = strsep(&cp, VAL_SEP)) != NULL;) {
			if (*tok == '\0')
				continue;
			if (in_addr_range_list_add(&_this->ip4_allow, tok)
			    != 0) {
				pptpd_log(_this, LOG_ERR,
				    "configuration error at %s: %s",
				    CFG_KEY(name, "ip4_allow"), tok);
				return 1;
			}
		}
	}

	if (do_start) {
		/* in the case of 1) cold-booted and 2) pptpd.enable
		 * toggled "false" to "true" do this, because we can
		 * assume that all pptpd listner are initialized. */

		val = pptpd_config_str(_this, CFG_KEY(name, "listener_in"));
		if (val != NULL) {
			if (strlen(val) >= sizeof(buf)) {
				pptpd_log(_this, LOG_ERR,
				    "configuration error at "
				    "%s: too long", CFG_KEY(name, "listener"));
				return 1;
			}
			strlcpy(buf, val, sizeof(buf));

			label = NULL;
			/* it can accept multple velues with tab/space
			 * separation */
			for (i = 0, cp = buf;
			    (tok = strsep(&cp, VAL_SEP)) != NULL;) {
				if (*tok == '\0')
					continue;
				if (label == NULL) {
					label = tok;
					continue;
				}
				if ((aierr = addrport_parse(tok, IPPROTO_TCP,
				    &ai)) != 0) {
					pptpd_log(_this, LOG_ERR,
					    "configuration error at "
					    "%s: %s: %s",
					    CFG_KEY(name, "listener_in"), tok,
					    gai_strerror(aierr));
					return 1;
				}
				PPTPD_ASSERT(ai != NULL &&
				    ai->ai_family == AF_INET);
				if (pptpd_add_listener(_this, i, label,
				    ai->ai_addr) != 0) {
					freeaddrinfo(ai);
					label = NULL;
					break;
				}
				freeaddrinfo(ai);
				label = NULL;
				i++;
			}
			if (label != NULL) {
				pptpd_log(_this, LOG_ERR,
				    "configuration error at %s: %s",
				    CFG_KEY(name, "listner_in"), label);
				return 1;
			}
		}
		if (pptpd_start(_this) != 0)
			return 1;
	}

	return 0;
}