static void wpa_init_conf(struct wpa_supplicant *wpa_s, const char *authsrv, const char *secret) { struct hostapd_radius_server *as; int res; wpa_s->bssid[5] = 1; wpa_s->own_addr[5] = 2; wpa_s->own_ip_addr.s_addr = htonl((127 << 24) | 1); wpa_s->num_auth_servers = 1; as = malloc(sizeof(struct hostapd_radius_server)); assert(as != NULL); inet_aton(authsrv, &as->addr); as->port = 1812; as->shared_secret = strdup(secret); as->shared_secret_len = strlen(secret); wpa_s->auth_server = wpa_s->auth_servers = as; res = radius_client_init(wpa_s); assert(res == 0); res = radius_client_register(wpa_s, RADIUS_AUTH, ieee802_1x_receive_auth, NULL); assert(res == 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; }
static void wpa_init_conf(struct eapol_test_data *e, struct wpa_supplicant *wpa_s, const char *authsrv, int port, const char *secret, const char *cli_addr) { struct hostapd_radius_server *as; int res; wpa_s->bssid[5] = 1; os_memcpy(wpa_s->own_addr, e->own_addr, ETH_ALEN); e->own_ip_addr.s_addr = htonl((127 << 24) | 1); os_strlcpy(wpa_s->ifname, "test", sizeof(wpa_s->ifname)); e->radius_conf = os_zalloc(sizeof(struct hostapd_radius_servers)); assert(e->radius_conf != NULL); e->radius_conf->num_auth_servers = 1; as = os_zalloc(sizeof(struct hostapd_radius_server)); assert(as != NULL); #if defined(CONFIG_NATIVE_WINDOWS) || defined(CONFIG_ANSI_C_EXTRA) { int a[4]; u8 *pos; sscanf(authsrv, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]); pos = (u8 *) &as->addr.u.v4; *pos++ = a[0]; *pos++ = a[1]; *pos++ = a[2]; *pos++ = a[3]; } #else /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */ inet_aton(authsrv, &as->addr.u.v4); #endif /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */ as->addr.af = AF_INET; as->port = port; as->shared_secret = (u8 *) os_strdup(secret); as->shared_secret_len = os_strlen(secret); e->radius_conf->auth_server = as; e->radius_conf->auth_servers = as; e->radius_conf->msg_dumps = 1; if (cli_addr) { if (hostapd_parse_ip_addr(cli_addr, &e->radius_conf->client_addr) == 0) e->radius_conf->force_client_addr = 1; else { wpa_printf(MSG_ERROR, "Invalid IP address '%s'", cli_addr); assert(0); } } e->radius = radius_client_init(wpa_s, e->radius_conf); assert(e->radius != NULL); res = radius_client_register(e->radius, RADIUS_AUTH, ieee802_1x_receive_auth, e); assert(res == 0); }
int hostapd_acl_init(struct hostapd_data *hapd) { if (radius_client_register(hapd->radius, RADIUS_AUTH, hostapd_acl_recv_radius, hapd)) return -1; eloop_register_timeout(10, 0, hostapd_acl_expire, hapd, NULL); return 0; }
/** * hostapd_acl_init: Initialize IEEE 802.11 ACL * @hapd: hostapd BSS data * Returns: 0 on success, -1 on failure */ int hostapd_acl_init(struct hostapd_data *hapd) { #ifndef CONFIG_NO_RADIUS if (radius_client_register(hapd->radius, RADIUS_AUTH, hostapd_acl_recv_radius, hapd)) return -1; #endif /* CONFIG_NO_RADIUS */ return 0; }
/** * hostapd_acl_init: Initialize IEEE 802.11 ACL * @hapd: hostapd BSS data * Returns: 0 on success, -1 on failure */ int hostapd_acl_init(struct hostapd_data *hapd) { #ifndef CONFIG_NO_RADIUS if (radius_client_register(hapd->radius, RADIUS_AUTH, hostapd_acl_recv_radius, hapd)) return -1; eloop_register_timeout(10, 0, hostapd_acl_expire, hapd, NULL); #endif /* CONFIG_NO_RADIUS */ return 0; }
int accounting_init(hostapd *hapd) { /* Acct-Session-Id should be unique over reboots. If reliable clock is * not available, this could be replaced with reboot counter, etc. */ hapd->radius->acct_session_id_hi = time(NULL); if (radius_client_register(hapd, RADIUS_ACCT, accounting_receive, NULL)) return -1; return 0; }
static void wpa_init_conf(struct eapol_test_data *e, struct wpa_supplicant *wpa_s, const char *authsrv, int port, const char *secret) { struct hostapd_radius_server *as; int res; wpa_s->bssid[5] = 1; wpa_s->own_addr[5] = 2; e->own_ip_addr.s_addr = htonl((127 << 24) | 1); strncpy(wpa_s->ifname, "test", sizeof(wpa_s->ifname)); e->radius_conf = malloc(sizeof(struct hostapd_radius_servers)); assert(e->radius_conf != NULL); memset(e->radius_conf, 0, sizeof(struct hostapd_radius_servers)); e->radius_conf->num_auth_servers = 1; as = malloc(sizeof(struct hostapd_radius_server)); assert(as != NULL); memset(as, 0, sizeof(*as)); #ifdef CONFIG_NATIVE_WINDOWS { int a[4]; u8 *pos; sscanf(authsrv, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]); pos = (u8 *) &as->addr.u.v4; *pos++ = a[0]; *pos++ = a[1]; *pos++ = a[2]; *pos++ = a[3]; } #else /* CONFIG_NATIVE_WINDOWS */ inet_aton(authsrv, &as->addr.u.v4); #endif /* CONFIG_NATIVE_WINDOWS */ as->addr.af = AF_INET; as->port = port; as->shared_secret = (u8 *) strdup(secret); as->shared_secret_len = strlen(secret); e->radius_conf->auth_server = as; e->radius_conf->auth_servers = as; e->radius_conf->msg_dumps = 1; e->radius = radius_client_init(wpa_s, e->radius_conf); assert(e->radius != NULL); res = radius_client_register(e->radius, RADIUS_AUTH, ieee802_1x_receive_auth, e); assert(res == 0); }
/** * accounting_init: Initialize accounting * @hapd: hostapd BSS data * Returns: 0 on success, -1 on failure */ int accounting_init(struct hostapd_data *hapd) { struct os_time now; /* Acct-Session-Id should be unique over reboots. If reliable clock is * not available, this could be replaced with reboot counter, etc. */ os_get_time(&now); hapd->acct_session_id_hi = now.sec; if (radius_client_register(hapd->radius, RADIUS_ACCT, accounting_receive, hapd)) return -1; accounting_report_state(hapd, 1); return 0; }
/** * accounting_init: Initialize accounting * @hapd: hostapd BSS data * Returns: 0 on success, -1 on failure */ int accounting_init(struct hostapd_data *hapd) { struct os_time now; /* Acct-Session-Id should be unique over reboots. Using a random number * is preferred. If that is not available, take the current time. Mix * in microseconds to make this more likely to be unique. */ os_get_time(&now); if (os_get_random((u8 *) &hapd->acct_session_id_hi, sizeof(hapd->acct_session_id_hi)) < 0) hapd->acct_session_id_hi = now.sec; hapd->acct_session_id_hi ^= now.usec; if (radius_client_register(hapd->radius, RADIUS_ACCT, accounting_receive, hapd)) return -1; accounting_report_state(hapd, 1); return 0; }