Пример #1
0
struct radius_client_data * radius_client_init(struct hostapd_data *hapd)
{
    struct radius_client_data *radius;

    radius = malloc(sizeof(struct radius_client_data));
    if (radius == NULL)
        return NULL;

    memset(radius, 0, sizeof(struct radius_client_data));
    radius->hapd = hapd;
    radius->auth_serv_sock = radius->acct_serv_sock = -1;

    if (hapd->conf->auth_server && radius_client_init_auth(radius)) {
        radius_client_deinit(radius);
        return NULL;
    }

    if (hapd->conf->acct_server && radius_client_init_acct(radius)) {
        radius_client_deinit(radius);
        return NULL;
    }

    if (hapd->conf->radius_retry_primary_interval)
        eloop_register_timeout(hapd->conf->
                               radius_retry_primary_interval, 0,
                               radius_retry_primary_timer, radius,
                               NULL);

    return radius;
}
Пример #2
0
/**
 * radius_client_init - Initialize RADIUS client
 * @ctx: Callback context to be used in hostapd_logger() calls
 * @conf: RADIUS client configuration (RADIUS servers)
 * Returns: Pointer to private RADIUS client context or %NULL on failure
 *
 * The caller is responsible for keeping the configuration data available for
 * the lifetime of the RADIUS client, i.e., until radius_client_deinit() is
 * called for the returned context pointer.
 */
struct radius_client_data *
radius_client_init(void *ctx, struct hostapd_radius_servers *conf)
{
	struct radius_client_data *radius;

	radius = os_zalloc(sizeof(struct radius_client_data));
	if (radius == NULL)
		return NULL;

	radius->ctx = ctx;
	radius->conf = conf;
	radius->auth_serv_sock = radius->acct_serv_sock =
		radius->auth_serv_sock6 = radius->acct_serv_sock6 =
		radius->auth_sock = radius->acct_sock = -1;

	if (conf->auth_server && radius_client_init_auth(radius)) {
		radius_client_deinit(radius);
		return NULL;
	}

	if (conf->acct_server && radius_client_init_acct(radius)) {
		radius_client_deinit(radius);
		return NULL;
	}

	if (conf->retry_primary_interval)
		eloop_register_timeout(conf->retry_primary_interval, 0,
				       radius_retry_primary_timer, radius,
				       NULL);

	return radius;
}
Пример #3
0
static void test_eapol_clean(struct eapol_test_data *e,
			     struct wpa_supplicant *wpa_s)
{
	struct extra_radius_attr *p, *prev;

	radius_client_deinit(e->radius);
	os_free(e->last_eap_radius);
	radius_msg_free(e->last_recv_radius);
	e->last_recv_radius = NULL;
	os_free(e->eap_identity);
	e->eap_identity = NULL;
	eapol_sm_deinit(wpa_s->eapol);
	wpa_s->eapol = NULL;
	if (e->radius_conf && e->radius_conf->auth_server) {
		os_free(e->radius_conf->auth_server->shared_secret);
		os_free(e->radius_conf->auth_server);
	}
	os_free(e->radius_conf);
	e->radius_conf = NULL;
	scard_deinit(wpa_s->scard);
	if (wpa_s->ctrl_iface) {
		wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
		wpa_s->ctrl_iface = NULL;
	}
	wpa_config_free(wpa_s->conf);

	p = e->extra_attrs;
	while (p) {
		prev = p;
		p = p->next;
		os_free(prev);
	}
}
Пример #4
0
static void test_eapol_clean(struct eapol_test_data *e,
			     struct wpa_supplicant *wpa_s)
{
	radius_client_deinit(e->radius);
	os_free(e->last_eap_radius);
	if (e->last_recv_radius) {
		radius_msg_free(e->last_recv_radius);
		os_free(e->last_recv_radius);
	}
	os_free(e->eap_identity);
	e->eap_identity = NULL;
	eapol_sm_deinit(wpa_s->eapol);
	wpa_s->eapol = NULL;
	if (e->radius_conf && e->radius_conf->auth_server) {
		os_free(e->radius_conf->auth_server->shared_secret);
		os_free(e->radius_conf->auth_server);
	}
	os_free(e->radius_conf);
	e->radius_conf = NULL;
	scard_deinit(wpa_s->scard);
	if (wpa_s->ctrl_iface) {
		wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
		wpa_s->ctrl_iface = NULL;
	}
	wpa_config_free(wpa_s->conf);
}
static void test_eapol_clean(struct eapol_test_data *e,
			     struct wpa_supplicant *wpa_s)
{

// this block was moved to eap_radius.c (eap_radius_open())
#ifdef UNUSED_CODE
	radius_client_deinit(e->radius);
	free(e->last_eap_radius);
	if (e->last_recv_radius) {
		radius_msg_free(e->last_recv_radius);
		free(e->last_recv_radius);
	}
#endif
	free(e->eap_identity);
	e->eap_identity = NULL;
	free(e->user_identity);
	e->user_identity = NULL;
	free(e->user_password);
	e->user_password = NULL;
	eapol_sm_deinit(wpa_s->eapol);
	wpa_s->eapol = NULL;
	if (e->radius_conf && e->radius_conf->auth_server) {
		free(e->radius_conf->auth_server->shared_secret);
		free(e->radius_conf->auth_server);
	}
	free(e->radius_conf);
	e->radius_conf = NULL;
	//scard_deinit(wpa_s->scard);
	//wpa_supplicant_ctrl_iface_deinit(wpa_s);
	// printf("Calling wpa_config_free\n");
	wpa_config_free(wpa_s->conf);
	// printf("Out of wpa_config_free\n");
}
Пример #6
0
int main(int argc, char *argv[])
{
    struct radius_ctx ctx;
    struct hostapd_radius_server *srv;

    if (os_program_init())
        return -1;

    hostapd_logger_register_cb(hostapd_logger_cb);

    os_memset(&ctx, 0, sizeof(ctx));
    inet_aton("127.0.0.1", &ctx.own_ip_addr);

    if (eloop_init()) {
        printf("Failed to initialize event loop\n");
        return -1;
    }

    srv = os_zalloc(sizeof(*srv));
    if (srv == NULL)
        return -1;

    srv->addr.af = AF_INET;
    srv->port = 1812;
    if (hostapd_parse_ip_addr("127.0.0.1", &srv->addr) < 0) {
        printf("Failed to parse IP address\n");
        return -1;
    }
    srv->shared_secret = (u8 *) os_strdup("radius");
    srv->shared_secret_len = 6;

    ctx.conf.auth_server = ctx.conf.auth_servers = srv;
    ctx.conf.num_auth_servers = 1;
    ctx.conf.msg_dumps = 1;

    ctx.radius = radius_client_init(&ctx, &ctx.conf);
    if (ctx.radius == NULL) {
        printf("Failed to initialize RADIUS client\n");
        return -1;
    }

    if (radius_client_register(ctx.radius, RADIUS_AUTH, receive_auth,
                               &ctx) < 0) {
        printf("Failed to register RADIUS authentication handler\n");
        return -1;
    }

    eloop_register_timeout(0, 0, start_example, &ctx, NULL);

    eloop_run();

    radius_client_deinit(ctx.radius);
    os_free(srv->shared_secret);
    os_free(srv);

    eloop_destroy();
    os_program_deinit();

    return 0;
}
Пример #7
0
/*******************************************************************************
 函数名称  : radius_data_free
 功能描述  : 初始化radius data
 输入参数  :
 输出参数  : 无
 返 回 值     : 无
------------------------------------------------------------
 最近一次修改记录 :
 修改作者   : 王群
 修改目的   : 新增函数
 修改日期   : 2011年04月02日
*******************************************************************************/
void radius_data_free(struct eapol_state_machine *sm)
{
	struct radius_data_info *data = sm->radius_sm->radius_data;

	if (NULL == data)
	{
		return;
	}
	/*从radius重传链表中删除*/
	radius_client_deinit(data->client);
	data->client = NULL;
	free(data);

	return;
}
Пример #8
0
static void hostapd_free_hapd_data(struct hostapd_data *hapd)
{
	iapp_deinit(hapd->iapp);
	hapd->iapp = NULL;
	accounting_deinit(hapd);
	hostapd_deinit_wpa(hapd);
	vlan_deinit(hapd);
	hostapd_acl_deinit(hapd);
#ifndef CONFIG_NO_RADIUS
	radius_client_deinit(hapd->radius);
	hapd->radius = NULL;
	radius_das_deinit(hapd->radius_das);
	hapd->radius_das = NULL;
#endif /* CONFIG_NO_RADIUS */

	hostapd_deinit_wps(hapd);

	authsrv_deinit(hapd);

	if (hapd->interface_added &&
	    hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) {
		wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s",
			   hapd->conf->iface);
	}

	os_free(hapd->probereq_cb);
	hapd->probereq_cb = NULL;

#ifdef CONFIG_P2P
	wpabuf_free(hapd->p2p_beacon_ie);
	hapd->p2p_beacon_ie = NULL;
	wpabuf_free(hapd->p2p_probe_resp_ie);
	hapd->p2p_probe_resp_ie = NULL;
#endif /* CONFIG_P2P */

	wpabuf_free(hapd->time_adv);

#ifdef CONFIG_INTERWORKING
	gas_serv_deinit(hapd);
#endif /* CONFIG_INTERWORKING */

#ifdef CONFIG_SQLITE
	os_free(hapd->tmp_eap_user.identity);
	os_free(hapd->tmp_eap_user.password);
#endif /* CONFIG_SQLITE */
}
Пример #9
0
static void test_eapol_clean(struct wpa_supplicant *wpa_s)
{
	radius_client_deinit(wpa_s);
	free(wpa_s->last_eap_radius);
	if (wpa_s->last_recv_radius) {
		radius_msg_free(wpa_s->last_recv_radius);
		free(wpa_s->last_recv_radius);
	}
	eapol_sm_deinit(wpa_s->eapol);
	wpa_s->eapol = NULL;
	if (wpa_s->auth_server) {
		free(wpa_s->auth_server->shared_secret);
		free(wpa_s->auth_server);
	}
	scard_deinit(wpa_s->scard);
	wpa_supplicant_ctrl_iface_deinit(wpa_s);
	wpa_config_free(wpa_s->conf);
}
Пример #10
0
static void hostapd_cleanup(hostapd *hapd)
{
	free(hapd->default_wep_key);
	if (hapd->conf->ieee802_11f)
		iapp_deinit(hapd);
	accounting_deinit(hapd);
	wpa_deinit(hapd);
	ieee802_1x_deinit(hapd);
	hostapd_acl_deinit(hapd);
	radius_client_deinit(hapd);

	hostapd_wireless_event_deinit(hapd->driver.data);

	hostapd_driver_deinit(hapd);

	hostapd_config_free(hapd->conf);
	hapd->conf = NULL;

	free(hapd->config_fname);
}
static void hostapd_cleanup(struct hostapd_data *hapd)
{
	hostapd_ctrl_iface_deinit(hapd);

	free(hapd->default_wep_key);
	hapd->default_wep_key = NULL;
	iapp_deinit(hapd->iapp);
	accounting_deinit(hapd);
	wpa_deinit(hapd);
#ifdef SIMPLE_CONFIG
	wsc_ie_deinit(hapd);
#endif
	ieee802_1x_deinit(hapd);
	hostapd_acl_deinit(hapd);
	radius_client_deinit(hapd->radius);
	hapd->radius = NULL;
	radius_server_deinit(hapd->radius_srv);
	hapd->radius_srv = NULL;

	hostapd_wireless_event_deinit(hapd);

	if (hapd->driver)
		hostapd_driver_deinit(hapd);

	hostapd_config_free(hapd->conf);
	hapd->conf = NULL;

	free(hapd->config_fname);

#ifdef EAP_TLS_FUNCS
	if (hapd->ssl_ctx) {
		tls_deinit(hapd->ssl_ctx);
		hapd->ssl_ctx = NULL;
	}
#endif /* EAP_TLS_FUNCS */

	if (hapd->eap_sim_db_priv)
		eap_sim_db_deinit(hapd->eap_sim_db_priv);
}
Пример #12
0
/**
 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
 * @hapd: Pointer to BSS data
 *
 * This function is used to free all per-BSS data structures and resources.
 * This gets called in a loop for each BSS between calls to
 * hostapd_cleanup_iface_pre() and hostapd_cleanup_iface() when an interface
 * is deinitialized. Most of the modules that are initialized in
 * hostapd_setup_bss() are deinitialized here.
 */
static void hostapd_cleanup(struct hostapd_data *hapd)
{
	if (hapd->iface->ctrl_iface_deinit)
		hapd->iface->ctrl_iface_deinit(hapd);

	iapp_deinit(hapd->iapp);
	hapd->iapp = NULL;
	accounting_deinit(hapd);
	hostapd_deinit_wpa(hapd);
	vlan_deinit(hapd);
	hostapd_acl_deinit(hapd);
#ifndef CONFIG_NO_RADIUS
	radius_client_deinit(hapd->radius);
	hapd->radius = NULL;
#endif /* CONFIG_NO_RADIUS */

	hostapd_deinit_wps(hapd);

	authsrv_deinit(hapd);

	if (hapd->interface_added &&
	    hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) {
		wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s",
			   hapd->conf->iface);
	}

	os_free(hapd->probereq_cb);
	hapd->probereq_cb = NULL;

#ifdef CONFIG_P2P
	wpabuf_free(hapd->p2p_beacon_ie);
	hapd->p2p_beacon_ie = NULL;
	wpabuf_free(hapd->p2p_probe_resp_ie);
	hapd->p2p_probe_resp_ie = NULL;
#endif /* CONFIG_P2P */

	wpabuf_free(hapd->time_adv);
}
Пример #13
0
struct radius_client_data *
radius_client_reconfig(struct radius_client_data *old, void *ctx,
		       struct hostapd_radius_servers *oldconf,
		       struct hostapd_radius_servers *newconf)
{
	radius_client_flush(old, 0);

	if (newconf->retry_primary_interval !=
	    oldconf->retry_primary_interval ||
	    newconf->num_auth_servers != oldconf->num_auth_servers ||
	    newconf->num_acct_servers != oldconf->num_acct_servers ||
	    radius_servers_diff(newconf->auth_servers, oldconf->auth_servers,
				newconf->num_auth_servers) ||
	    radius_servers_diff(newconf->acct_servers, oldconf->acct_servers,
				newconf->num_acct_servers)) {
		hostapd_logger(ctx, NULL, HOSTAPD_MODULE_RADIUS,
			       HOSTAPD_LEVEL_DEBUG,
			       "Reconfiguring RADIUS client");
		radius_client_deinit(old);
		return radius_client_init(ctx, newconf);
	}

	return old;
}