LCOV - code coverage report
Current view: top level - src/ap - ieee802_11_auth.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1443382998 Lines: 214 298 71.8 %
Date: 2015-09-27 Functions: 15 15 100.0 %

          Line data    Source code
       1             : /*
       2             :  * hostapd / IEEE 802.11 authentication (ACL)
       3             :  * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
       4             :  *
       5             :  * This software may be distributed under the terms of the BSD license.
       6             :  * See README for more details.
       7             :  *
       8             :  * Access control list for IEEE 802.11 authentication can uses statically
       9             :  * configured ACL from configuration files or an external RADIUS server.
      10             :  * Results from external RADIUS queries are cached to allow faster
      11             :  * authentication frame processing.
      12             :  */
      13             : 
      14             : #include "utils/includes.h"
      15             : 
      16             : #include "utils/common.h"
      17             : #include "utils/eloop.h"
      18             : #include "crypto/sha1.h"
      19             : #include "radius/radius.h"
      20             : #include "radius/radius_client.h"
      21             : #include "hostapd.h"
      22             : #include "ap_config.h"
      23             : #include "ap_drv_ops.h"
      24             : #include "ieee802_11.h"
      25             : #include "ieee802_1x.h"
      26             : #include "ieee802_11_auth.h"
      27             : 
      28             : #define RADIUS_ACL_TIMEOUT 30
      29             : 
      30             : 
      31             : struct hostapd_cached_radius_acl {
      32             :         struct os_reltime timestamp;
      33             :         macaddr addr;
      34             :         int accepted; /* HOSTAPD_ACL_* */
      35             :         struct hostapd_cached_radius_acl *next;
      36             :         u32 session_timeout;
      37             :         u32 acct_interim_interval;
      38             :         int vlan_id;
      39             :         struct hostapd_sta_wpa_psk_short *psk;
      40             :         char *identity;
      41             :         char *radius_cui;
      42             : };
      43             : 
      44             : 
      45             : struct hostapd_acl_query_data {
      46             :         struct os_reltime timestamp;
      47             :         u8 radius_id;
      48             :         macaddr addr;
      49             :         u8 *auth_msg; /* IEEE 802.11 authentication frame from station */
      50             :         size_t auth_msg_len;
      51             :         struct hostapd_acl_query_data *next;
      52             : };
      53             : 
      54             : 
      55             : #ifndef CONFIG_NO_RADIUS
      56           9 : static void hostapd_acl_cache_free_entry(struct hostapd_cached_radius_acl *e)
      57             : {
      58           9 :         os_free(e->identity);
      59           9 :         os_free(e->radius_cui);
      60           9 :         hostapd_free_psk_list(e->psk);
      61           9 :         os_free(e);
      62           9 : }
      63             : 
      64             : 
      65        1682 : static void hostapd_acl_cache_free(struct hostapd_cached_radius_acl *acl_cache)
      66             : {
      67             :         struct hostapd_cached_radius_acl *prev;
      68             : 
      69        3373 :         while (acl_cache) {
      70           9 :                 prev = acl_cache;
      71           9 :                 acl_cache = acl_cache->next;
      72           9 :                 hostapd_acl_cache_free_entry(prev);
      73             :         }
      74        1682 : }
      75             : 
      76             : 
      77          16 : static void copy_psk_list(struct hostapd_sta_wpa_psk_short **psk,
      78             :                           struct hostapd_sta_wpa_psk_short *src)
      79             : {
      80             :         struct hostapd_sta_wpa_psk_short **copy_to;
      81             :         struct hostapd_sta_wpa_psk_short *copy_from;
      82             : 
      83             :         /* Copy PSK linked list */
      84          16 :         copy_to = psk;
      85          16 :         copy_from = src;
      86          34 :         while (copy_from && copy_to) {
      87           2 :                 *copy_to = os_zalloc(sizeof(struct hostapd_sta_wpa_psk_short));
      88           2 :                 if (*copy_to == NULL)
      89           0 :                         break;
      90           2 :                 os_memcpy(*copy_to, copy_from,
      91             :                           sizeof(struct hostapd_sta_wpa_psk_short));
      92           2 :                 copy_from = copy_from->next;
      93           2 :                 copy_to = &((*copy_to)->next);
      94             :         }
      95          16 :         if (copy_to)
      96          16 :                 *copy_to = NULL;
      97          16 : }
      98             : 
      99             : 
     100          25 : static int hostapd_acl_cache_get(struct hostapd_data *hapd, const u8 *addr,
     101             :                                  u32 *session_timeout,
     102             :                                  u32 *acct_interim_interval, int *vlan_id,
     103             :                                  struct hostapd_sta_wpa_psk_short **psk,
     104             :                                  char **identity, char **radius_cui)
     105             : {
     106             :         struct hostapd_cached_radius_acl *entry;
     107             :         struct os_reltime now;
     108             : 
     109          25 :         os_get_reltime(&now);
     110             : 
     111          60 :         for (entry = hapd->acl_cache; entry; entry = entry->next) {
     112          21 :                 if (os_memcmp(entry->addr, addr, ETH_ALEN) != 0)
     113           5 :                         continue;
     114             : 
     115          16 :                 if (os_reltime_expired(&now, &entry->timestamp,
     116             :                                        RADIUS_ACL_TIMEOUT))
     117           0 :                         return -1; /* entry has expired */
     118          16 :                 if (entry->accepted == HOSTAPD_ACL_ACCEPT_TIMEOUT)
     119           0 :                         if (session_timeout)
     120           0 :                                 *session_timeout = entry->session_timeout;
     121          16 :                 if (acct_interim_interval)
     122          16 :                         *acct_interim_interval =
     123          16 :                                 entry->acct_interim_interval;
     124          16 :                 if (vlan_id)
     125          16 :                         *vlan_id = entry->vlan_id;
     126          16 :                 copy_psk_list(psk, entry->psk);
     127          16 :                 if (identity) {
     128          16 :                         if (entry->identity)
     129           7 :                                 *identity = os_strdup(entry->identity);
     130             :                         else
     131           9 :                                 *identity = NULL;
     132             :                 }
     133          16 :                 if (radius_cui) {
     134          16 :                         if (entry->radius_cui)
     135           7 :                                 *radius_cui = os_strdup(entry->radius_cui);
     136             :                         else
     137           9 :                                 *radius_cui = NULL;
     138             :                 }
     139          16 :                 return entry->accepted;
     140             :         }
     141             : 
     142           9 :         return -1;
     143             : }
     144             : #endif /* CONFIG_NO_RADIUS */
     145             : 
     146             : 
     147           9 : static void hostapd_acl_query_free(struct hostapd_acl_query_data *query)
     148             : {
     149           9 :         if (query == NULL)
     150           9 :                 return;
     151           9 :         os_free(query->auth_msg);
     152           9 :         os_free(query);
     153             : }
     154             : 
     155             : 
     156             : #ifndef CONFIG_NO_RADIUS
     157           9 : static int hostapd_radius_acl_query(struct hostapd_data *hapd, const u8 *addr,
     158             :                                     struct hostapd_acl_query_data *query)
     159             : {
     160             :         struct radius_msg *msg;
     161             :         char buf[128];
     162             : 
     163           9 :         query->radius_id = radius_client_get_id(hapd->radius);
     164           9 :         msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST, query->radius_id);
     165           9 :         if (msg == NULL)
     166           0 :                 return -1;
     167             : 
     168           9 :         radius_msg_make_authenticator(msg, addr, ETH_ALEN);
     169             : 
     170           9 :         os_snprintf(buf, sizeof(buf), RADIUS_ADDR_FORMAT, MAC2STR(addr));
     171           9 :         if (!radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME, (u8 *) buf,
     172             :                                  os_strlen(buf))) {
     173           0 :                 wpa_printf(MSG_DEBUG, "Could not add User-Name");
     174           0 :                 goto fail;
     175             :         }
     176             : 
     177          18 :         if (!radius_msg_add_attr_user_password(
     178             :                     msg, (u8 *) buf, os_strlen(buf),
     179           9 :                     hapd->conf->radius->auth_server->shared_secret,
     180           9 :                     hapd->conf->radius->auth_server->shared_secret_len)) {
     181           0 :                 wpa_printf(MSG_DEBUG, "Could not add User-Password");
     182           0 :                 goto fail;
     183             :         }
     184             : 
     185           9 :         if (add_common_radius_attr(hapd, hapd->conf->radius_auth_req_attr,
     186             :                                    NULL, msg) < 0)
     187           0 :                 goto fail;
     188             : 
     189          54 :         os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
     190          54 :                     MAC2STR(addr));
     191           9 :         if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
     192             :                                  (u8 *) buf, os_strlen(buf))) {
     193           0 :                 wpa_printf(MSG_DEBUG, "Could not add Calling-Station-Id");
     194           0 :                 goto fail;
     195             :         }
     196             : 
     197           9 :         os_snprintf(buf, sizeof(buf), "CONNECT 11Mbps 802.11b");
     198           9 :         if (!radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
     199             :                                  (u8 *) buf, os_strlen(buf))) {
     200           0 :                 wpa_printf(MSG_DEBUG, "Could not add Connect-Info");
     201           0 :                 goto fail;
     202             :         }
     203             : 
     204           9 :         if (radius_client_send(hapd->radius, msg, RADIUS_AUTH, addr) < 0)
     205           0 :                 goto fail;
     206           9 :         return 0;
     207             : 
     208             :  fail:
     209           0 :         radius_msg_free(msg);
     210           0 :         return -1;
     211             : }
     212             : #endif /* CONFIG_NO_RADIUS */
     213             : 
     214             : 
     215             : /**
     216             :  * hostapd_allowed_address - Check whether a specified STA can be authenticated
     217             :  * @hapd: hostapd BSS data
     218             :  * @addr: MAC address of the STA
     219             :  * @msg: Authentication message
     220             :  * @len: Length of msg in octets
     221             :  * @session_timeout: Buffer for returning session timeout (from RADIUS)
     222             :  * @acct_interim_interval: Buffer for returning account interval (from RADIUS)
     223             :  * @vlan_id: Buffer for returning VLAN ID
     224             :  * @psk: Linked list buffer for returning WPA PSK
     225             :  * @identity: Buffer for returning identity (from RADIUS)
     226             :  * @radius_cui: Buffer for returning CUI (from RADIUS)
     227             :  * Returns: HOSTAPD_ACL_ACCEPT, HOSTAPD_ACL_REJECT, or HOSTAPD_ACL_PENDING
     228             :  *
     229             :  * The caller is responsible for freeing the returned *identity and *radius_cui
     230             :  * values with os_free().
     231             :  */
     232        3629 : int hostapd_allowed_address(struct hostapd_data *hapd, const u8 *addr,
     233             :                             const u8 *msg, size_t len, u32 *session_timeout,
     234             :                             u32 *acct_interim_interval, int *vlan_id,
     235             :                             struct hostapd_sta_wpa_psk_short **psk,
     236             :                             char **identity, char **radius_cui)
     237             : {
     238        3629 :         if (session_timeout)
     239        3629 :                 *session_timeout = 0;
     240        3629 :         if (acct_interim_interval)
     241        3629 :                 *acct_interim_interval = 0;
     242        3629 :         if (vlan_id)
     243        3629 :                 *vlan_id = 0;
     244        3629 :         if (psk)
     245        3629 :                 *psk = NULL;
     246        3629 :         if (identity)
     247        3629 :                 *identity = NULL;
     248        3629 :         if (radius_cui)
     249        3629 :                 *radius_cui = NULL;
     250             : 
     251        3629 :         if (hostapd_maclist_found(hapd->conf->accept_mac,
     252        3629 :                                   hapd->conf->num_accept_mac, addr, vlan_id))
     253         120 :                 return HOSTAPD_ACL_ACCEPT;
     254             : 
     255        3509 :         if (hostapd_maclist_found(hapd->conf->deny_mac,
     256        3509 :                                   hapd->conf->num_deny_mac, addr, vlan_id))
     257           5 :                 return HOSTAPD_ACL_REJECT;
     258             : 
     259        3504 :         if (hapd->conf->macaddr_acl == ACCEPT_UNLESS_DENIED)
     260        3474 :                 return HOSTAPD_ACL_ACCEPT;
     261          30 :         if (hapd->conf->macaddr_acl == DENY_UNLESS_ACCEPTED)
     262           5 :                 return HOSTAPD_ACL_REJECT;
     263             : 
     264          25 :         if (hapd->conf->macaddr_acl == USE_EXTERNAL_RADIUS_AUTH) {
     265             : #ifdef CONFIG_NO_RADIUS
     266           0 :                 return HOSTAPD_ACL_REJECT;
     267             : #else /* CONFIG_NO_RADIUS */
     268             :                 struct hostapd_acl_query_data *query;
     269             : 
     270             :                 /* Check whether ACL cache has an entry for this station */
     271          25 :                 int res = hostapd_acl_cache_get(hapd, addr, session_timeout,
     272             :                                                 acct_interim_interval,
     273             :                                                 vlan_id, psk,
     274             :                                                 identity, radius_cui);
     275          25 :                 if (res == HOSTAPD_ACL_ACCEPT ||
     276             :                     res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
     277           8 :                         return res;
     278          17 :                 if (res == HOSTAPD_ACL_REJECT)
     279           8 :                         return HOSTAPD_ACL_REJECT;
     280             : 
     281           9 :                 query = hapd->acl_queries;
     282          18 :                 while (query) {
     283           0 :                         if (os_memcmp(query->addr, addr, ETH_ALEN) == 0) {
     284             :                                 /* pending query in RADIUS retransmit queue;
     285             :                                  * do not generate a new one */
     286           0 :                                 if (identity) {
     287           0 :                                         os_free(*identity);
     288           0 :                                         *identity = NULL;
     289             :                                 }
     290           0 :                                 if (radius_cui) {
     291           0 :                                         os_free(*radius_cui);
     292           0 :                                         *radius_cui = NULL;
     293             :                                 }
     294           0 :                                 return HOSTAPD_ACL_PENDING;
     295             :                         }
     296           0 :                         query = query->next;
     297             :                 }
     298             : 
     299           9 :                 if (!hapd->conf->radius->auth_server)
     300           0 :                         return HOSTAPD_ACL_REJECT;
     301             : 
     302             :                 /* No entry in the cache - query external RADIUS server */
     303           9 :                 query = os_zalloc(sizeof(*query));
     304           9 :                 if (query == NULL) {
     305           0 :                         wpa_printf(MSG_ERROR, "malloc for query data failed");
     306           0 :                         return HOSTAPD_ACL_REJECT;
     307             :                 }
     308           9 :                 os_get_reltime(&query->timestamp);
     309           9 :                 os_memcpy(query->addr, addr, ETH_ALEN);
     310           9 :                 if (hostapd_radius_acl_query(hapd, addr, query)) {
     311           0 :                         wpa_printf(MSG_DEBUG, "Failed to send Access-Request "
     312             :                                    "for ACL query.");
     313           0 :                         hostapd_acl_query_free(query);
     314           0 :                         return HOSTAPD_ACL_REJECT;
     315             :                 }
     316             : 
     317           9 :                 query->auth_msg = os_malloc(len);
     318           9 :                 if (query->auth_msg == NULL) {
     319           0 :                         wpa_printf(MSG_ERROR, "Failed to allocate memory for "
     320             :                                    "auth frame.");
     321           0 :                         hostapd_acl_query_free(query);
     322           0 :                         return HOSTAPD_ACL_REJECT;
     323             :                 }
     324           9 :                 os_memcpy(query->auth_msg, msg, len);
     325           9 :                 query->auth_msg_len = len;
     326           9 :                 query->next = hapd->acl_queries;
     327           9 :                 hapd->acl_queries = query;
     328             : 
     329             :                 /* Queued data will be processed in hostapd_acl_recv_radius()
     330             :                  * when RADIUS server replies to the sent Access-Request. */
     331           9 :                 return HOSTAPD_ACL_PENDING;
     332             : #endif /* CONFIG_NO_RADIUS */
     333             :         }
     334             : 
     335           0 :         return HOSTAPD_ACL_REJECT;
     336             : }
     337             : 
     338             : 
     339             : #ifndef CONFIG_NO_RADIUS
     340        1433 : static void hostapd_acl_expire_cache(struct hostapd_data *hapd,
     341             :                                      struct os_reltime *now)
     342             : {
     343             :         struct hostapd_cached_radius_acl *prev, *entry, *tmp;
     344             : 
     345        1433 :         prev = NULL;
     346        1433 :         entry = hapd->acl_cache;
     347             : 
     348        2867 :         while (entry) {
     349           1 :                 if (os_reltime_expired(now, &entry->timestamp,
     350             :                                        RADIUS_ACL_TIMEOUT)) {
     351           0 :                         wpa_printf(MSG_DEBUG, "Cached ACL entry for " MACSTR
     352           0 :                                    " has expired.", MAC2STR(entry->addr));
     353           0 :                         if (prev)
     354           0 :                                 prev->next = entry->next;
     355             :                         else
     356           0 :                                 hapd->acl_cache = entry->next;
     357           0 :                         hostapd_drv_set_radius_acl_expire(hapd, entry->addr);
     358           0 :                         tmp = entry;
     359           0 :                         entry = entry->next;
     360           0 :                         hostapd_acl_cache_free_entry(tmp);
     361           0 :                         continue;
     362             :                 }
     363             : 
     364           1 :                 prev = entry;
     365           1 :                 entry = entry->next;
     366             :         }
     367        1433 : }
     368             : 
     369             : 
     370        1433 : static void hostapd_acl_expire_queries(struct hostapd_data *hapd,
     371             :                                        struct os_reltime *now)
     372             : {
     373             :         struct hostapd_acl_query_data *prev, *entry, *tmp;
     374             : 
     375        1433 :         prev = NULL;
     376        1433 :         entry = hapd->acl_queries;
     377             : 
     378        2866 :         while (entry) {
     379           0 :                 if (os_reltime_expired(now, &entry->timestamp,
     380             :                                        RADIUS_ACL_TIMEOUT)) {
     381           0 :                         wpa_printf(MSG_DEBUG, "ACL query for " MACSTR
     382           0 :                                    " has expired.", MAC2STR(entry->addr));
     383           0 :                         if (prev)
     384           0 :                                 prev->next = entry->next;
     385             :                         else
     386           0 :                                 hapd->acl_queries = entry->next;
     387             : 
     388           0 :                         tmp = entry;
     389           0 :                         entry = entry->next;
     390           0 :                         hostapd_acl_query_free(tmp);
     391           0 :                         continue;
     392             :                 }
     393             : 
     394           0 :                 prev = entry;
     395           0 :                 entry = entry->next;
     396             :         }
     397        1433 : }
     398             : 
     399             : 
     400             : /**
     401             :  * hostapd_acl_expire - ACL cache expiration callback
     402             :  * @hapd: struct hostapd_data *
     403             :  */
     404        1433 : void hostapd_acl_expire(struct hostapd_data *hapd)
     405             : {
     406             :         struct os_reltime now;
     407             : 
     408        1433 :         os_get_reltime(&now);
     409        1433 :         hostapd_acl_expire_cache(hapd, &now);
     410        1433 :         hostapd_acl_expire_queries(hapd, &now);
     411        1433 : }
     412             : 
     413             : 
     414           9 : static void decode_tunnel_passwords(struct hostapd_data *hapd,
     415             :                                     const u8 *shared_secret,
     416             :                                     size_t shared_secret_len,
     417             :                                     struct radius_msg *msg,
     418             :                                     struct radius_msg *req,
     419             :                                     struct hostapd_cached_radius_acl *cache)
     420             : {
     421             :         int passphraselen;
     422             :         char *passphrase, *strpassphrase;
     423             :         size_t i;
     424             :         struct hostapd_sta_wpa_psk_short *psk;
     425             : 
     426             :         /*
     427             :          * Decode all tunnel passwords as PSK and save them into a linked list.
     428             :          */
     429          11 :         for (i = 0; ; i++) {
     430          11 :                 passphrase = radius_msg_get_tunnel_password(
     431             :                         msg, &passphraselen, shared_secret, shared_secret_len,
     432             :                         req, i);
     433             :                 /*
     434             :                  * Passphrase is NULL iff there is no i-th Tunnel-Password
     435             :                  * attribute in msg.
     436             :                  */
     437          11 :                 if (passphrase == NULL)
     438           9 :                         break;
     439             :                 /*
     440             :                  * passphrase does not contain the NULL termination.
     441             :                  * Add it here as pbkdf2_sha1() requires it.
     442             :                  */
     443           2 :                 strpassphrase = os_zalloc(passphraselen + 1);
     444           2 :                 psk = os_zalloc(sizeof(struct hostapd_sta_wpa_psk_short));
     445           2 :                 if (strpassphrase && psk) {
     446           2 :                         os_memcpy(strpassphrase, passphrase, passphraselen);
     447           4 :                         pbkdf2_sha1(strpassphrase,
     448           2 :                                     hapd->conf->ssid.ssid,
     449           2 :                                     hapd->conf->ssid.ssid_len, 4096,
     450           2 :                                     psk->psk, PMK_LEN);
     451           2 :                         psk->next = cache->psk;
     452           2 :                         cache->psk = psk;
     453           2 :                         psk = NULL;
     454             :                 }
     455           2 :                 os_free(strpassphrase);
     456           2 :                 os_free(psk);
     457           2 :                 os_free(passphrase);
     458           2 :         }
     459           9 : }
     460             : 
     461             : 
     462             : /**
     463             :  * hostapd_acl_recv_radius - Process incoming RADIUS Authentication messages
     464             :  * @msg: RADIUS response message
     465             :  * @req: RADIUS request message
     466             :  * @shared_secret: RADIUS shared secret
     467             :  * @shared_secret_len: Length of shared_secret in octets
     468             :  * @data: Context data (struct hostapd_data *)
     469             :  * Returns: RADIUS_RX_PROCESSED if RADIUS message was a reply to ACL query (and
     470             :  * was processed here) or RADIUS_RX_UNKNOWN if not.
     471             :  */
     472             : static RadiusRxResult
     473        3755 : hostapd_acl_recv_radius(struct radius_msg *msg, struct radius_msg *req,
     474             :                         const u8 *shared_secret, size_t shared_secret_len,
     475             :                         void *data)
     476             : {
     477        3755 :         struct hostapd_data *hapd = data;
     478             :         struct hostapd_acl_query_data *query, *prev;
     479             :         struct hostapd_cached_radius_acl *cache;
     480        3755 :         struct radius_hdr *hdr = radius_msg_get_hdr(msg);
     481             : 
     482        3755 :         query = hapd->acl_queries;
     483        3755 :         prev = NULL;
     484        7510 :         while (query) {
     485           9 :                 if (query->radius_id == hdr->identifier)
     486           9 :                         break;
     487           0 :                 prev = query;
     488           0 :                 query = query->next;
     489             :         }
     490        3755 :         if (query == NULL)
     491        3746 :                 return RADIUS_RX_UNKNOWN;
     492             : 
     493           9 :         wpa_printf(MSG_DEBUG, "Found matching Access-Request for RADIUS "
     494           9 :                    "message (id=%d)", query->radius_id);
     495             : 
     496           9 :         if (radius_msg_verify(msg, shared_secret, shared_secret_len, req, 0)) {
     497           0 :                 wpa_printf(MSG_INFO, "Incoming RADIUS packet did not have "
     498             :                            "correct authenticator - dropped\n");
     499           0 :                 return RADIUS_RX_INVALID_AUTHENTICATOR;
     500             :         }
     501             : 
     502           9 :         if (hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
     503           0 :             hdr->code != RADIUS_CODE_ACCESS_REJECT) {
     504           0 :                 wpa_printf(MSG_DEBUG, "Unknown RADIUS message code %d to ACL "
     505           0 :                            "query", hdr->code);
     506           0 :                 return RADIUS_RX_UNKNOWN;
     507             :         }
     508             : 
     509             :         /* Insert Accept/Reject info into ACL cache */
     510           9 :         cache = os_zalloc(sizeof(*cache));
     511           9 :         if (cache == NULL) {
     512           0 :                 wpa_printf(MSG_DEBUG, "Failed to add ACL cache entry");
     513           0 :                 goto done;
     514             :         }
     515           9 :         os_get_reltime(&cache->timestamp);
     516           9 :         os_memcpy(cache->addr, query->addr, sizeof(cache->addr));
     517           9 :         if (hdr->code == RADIUS_CODE_ACCESS_ACCEPT) {
     518             :                 u8 *buf;
     519             :                 size_t len;
     520             : 
     521           9 :                 if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_SESSION_TIMEOUT,
     522             :                                               &cache->session_timeout) == 0)
     523           0 :                         cache->accepted = HOSTAPD_ACL_ACCEPT_TIMEOUT;
     524             :                 else
     525           9 :                         cache->accepted = HOSTAPD_ACL_ACCEPT;
     526             : 
     527           9 :                 if (radius_msg_get_attr_int32(
     528             :                             msg, RADIUS_ATTR_ACCT_INTERIM_INTERVAL,
     529           0 :                             &cache->acct_interim_interval) == 0 &&
     530           0 :                     cache->acct_interim_interval < 60) {
     531           0 :                         wpa_printf(MSG_DEBUG, "Ignored too small "
     532             :                                    "Acct-Interim-Interval %d for STA " MACSTR,
     533             :                                    cache->acct_interim_interval,
     534           0 :                                    MAC2STR(query->addr));
     535           0 :                         cache->acct_interim_interval = 0;
     536             :                 }
     537             : 
     538           9 :                 cache->vlan_id = radius_msg_get_vlanid(msg);
     539             : 
     540           9 :                 decode_tunnel_passwords(hapd, shared_secret, shared_secret_len,
     541             :                                         msg, req, cache);
     542             : 
     543           9 :                 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_USER_NAME,
     544             :                                             &buf, &len, NULL) == 0) {
     545           3 :                         cache->identity = os_zalloc(len + 1);
     546           3 :                         if (cache->identity)
     547           3 :                                 os_memcpy(cache->identity, buf, len);
     548             :                 }
     549           9 :                 if (radius_msg_get_attr_ptr(
     550             :                             msg, RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
     551             :                             &buf, &len, NULL) == 0) {
     552           3 :                         cache->radius_cui = os_zalloc(len + 1);
     553           3 :                         if (cache->radius_cui)
     554           3 :                                 os_memcpy(cache->radius_cui, buf, len);
     555             :                 }
     556             : 
     557          11 :                 if (hapd->conf->wpa_psk_radius == PSK_RADIUS_REQUIRED &&
     558           2 :                     !cache->psk)
     559           0 :                         cache->accepted = HOSTAPD_ACL_REJECT;
     560             : 
     561          10 :                 if (cache->vlan_id &&
     562           1 :                     !hostapd_vlan_id_valid(hapd->conf->vlan, cache->vlan_id)) {
     563           0 :                         hostapd_logger(hapd, query->addr,
     564             :                                        HOSTAPD_MODULE_RADIUS,
     565             :                                        HOSTAPD_LEVEL_INFO,
     566             :                                        "Invalid VLAN ID %d received from RADIUS server",
     567             :                                        cache->vlan_id);
     568           0 :                         cache->vlan_id = 0;
     569             :                 }
     570          12 :                 if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_REQUIRED &&
     571           3 :                     !cache->vlan_id)
     572           2 :                         cache->accepted = HOSTAPD_ACL_REJECT;
     573             :         } else
     574           0 :                 cache->accepted = HOSTAPD_ACL_REJECT;
     575           9 :         cache->next = hapd->acl_cache;
     576           9 :         hapd->acl_cache = cache;
     577             : 
     578             : #ifdef CONFIG_DRIVER_RADIUS_ACL
     579             :         hostapd_drv_set_radius_acl_auth(hapd, query->addr, cache->accepted,
     580             :                                         cache->session_timeout);
     581             : #else /* CONFIG_DRIVER_RADIUS_ACL */
     582             : #ifdef NEED_AP_MLME
     583             :         /* Re-send original authentication frame for 802.11 processing */
     584           9 :         wpa_printf(MSG_DEBUG, "Re-sending authentication frame after "
     585             :                    "successful RADIUS ACL query");
     586           9 :         ieee802_11_mgmt(hapd, query->auth_msg, query->auth_msg_len, NULL);
     587             : #endif /* NEED_AP_MLME */
     588             : #endif /* CONFIG_DRIVER_RADIUS_ACL */
     589             : 
     590             :  done:
     591           9 :         if (prev == NULL)
     592           9 :                 hapd->acl_queries = query->next;
     593             :         else
     594           0 :                 prev->next = query->next;
     595             : 
     596           9 :         hostapd_acl_query_free(query);
     597             : 
     598           9 :         return RADIUS_RX_PROCESSED;
     599             : }
     600             : #endif /* CONFIG_NO_RADIUS */
     601             : 
     602             : 
     603             : /**
     604             :  * hostapd_acl_init: Initialize IEEE 802.11 ACL
     605             :  * @hapd: hostapd BSS data
     606             :  * Returns: 0 on success, -1 on failure
     607             :  */
     608        2051 : int hostapd_acl_init(struct hostapd_data *hapd)
     609             : {
     610             : #ifndef CONFIG_NO_RADIUS
     611        1678 :         if (radius_client_register(hapd->radius, RADIUS_AUTH,
     612             :                                    hostapd_acl_recv_radius, hapd))
     613           0 :                 return -1;
     614             : #endif /* CONFIG_NO_RADIUS */
     615             : 
     616        2051 :         return 0;
     617             : }
     618             : 
     619             : 
     620             : /**
     621             :  * hostapd_acl_deinit - Deinitialize IEEE 802.11 ACL
     622             :  * @hapd: hostapd BSS data
     623             :  */
     624        2055 : void hostapd_acl_deinit(struct hostapd_data *hapd)
     625             : {
     626             :         struct hostapd_acl_query_data *query, *prev;
     627             : 
     628             : #ifndef CONFIG_NO_RADIUS
     629        1682 :         hostapd_acl_cache_free(hapd->acl_cache);
     630             : #endif /* CONFIG_NO_RADIUS */
     631             : 
     632        2055 :         query = hapd->acl_queries;
     633        4110 :         while (query) {
     634           0 :                 prev = query;
     635           0 :                 query = query->next;
     636           0 :                 hostapd_acl_query_free(prev);
     637             :         }
     638        2055 : }
     639             : 
     640             : 
     641        9722 : void hostapd_free_psk_list(struct hostapd_sta_wpa_psk_short *psk)
     642             : {
     643       19448 :         while (psk) {
     644           4 :                 struct hostapd_sta_wpa_psk_short *prev = psk;
     645           4 :                 psk = psk->next;
     646           4 :                 os_free(prev);
     647             :         }
     648        9722 : }

Generated by: LCOV version 1.10