]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
RADIUS: Share a single function for generating session IDs
authorJouni Malinen <j@w1.fi>
Sat, 6 Feb 2016 14:27:52 +0000 (16:27 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 6 Feb 2016 15:19:35 +0000 (17:19 +0200)
There is no need to maintain three copies of this functionality even if
it is currently implemented as a single function call.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/ap/accounting.c
src/eapol_auth/eapol_auth_sm.c
src/radius/radius.c
src/radius/radius.h

index 22684a68cae82e79194aeea5d362716af23fcffc..f3ce1215cc265f1ad528c4c359331ab96d45adca 100644 (file)
@@ -379,13 +379,8 @@ void accounting_sta_stop(struct hostapd_data *hapd, struct sta_info *sta)
 
 int accounting_sta_get_id(struct hostapd_data *hapd, struct sta_info *sta)
 {
-       /*
-        * Acct-Session-Id should be globally and temporarily unique.
-        * A high quality random number is required therefore.
-        * This could be be improved by switching to a GUID.
-        */
-       return os_get_random((u8 *) &sta->acct_session_id,
-                            sizeof(sta->acct_session_id));
+       return radius_gen_session_id((u8 *) &sta->acct_session_id,
+                                    sizeof(sta->acct_session_id));
 }
 
 
@@ -454,13 +449,8 @@ static void accounting_report_state(struct hostapd_data *hapd, int on)
  */
 int accounting_init(struct hostapd_data *hapd)
 {
-       /*
-        * Acct-Session-Id should be globally and temporarily unique.
-        * A high quality random number is required therefore.
-        * This could be be improved by switching to a GUID.
-        */
-       if (os_get_random((u8 *) &hapd->acct_session_id,
-                         sizeof(hapd->acct_session_id)) < 0)
+       if (radius_gen_session_id((u8 *) &hapd->acct_session_id,
+                                 sizeof(hapd->acct_session_id)) < 0)
                return -1;
 
        if (radius_client_register(hapd->radius, RADIUS_ACCT,
index 62db368e7a29478075243d8b7dadc6ccf2bc5b7f..ff673bb2e785865f5756a68e00a7f00b51a7715d 100644 (file)
@@ -866,16 +866,13 @@ eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
                sm->radius_cui = wpabuf_alloc_copy(radius_cui,
                                                   os_strlen(radius_cui));
 
-       /*
-        * Acct-Multi-Session-Id should be globally and temporarily unique.
-        * A high quality random number is required therefore.
-        * This could be be improved by switching to a GUID.
-        */
-       if (os_get_random((u8 *) &sm->acct_multi_session_id,
-                         sizeof(sm->acct_multi_session_id)) < 0) {
+#ifndef CONFIG_NO_RADIUS
+       if (radius_gen_session_id((u8 *) &sm->acct_multi_session_id,
+                                 sizeof(sm->acct_multi_session_id)) < 0) {
                eapol_auth_free(sm);
                return NULL;
        }
+#endif /* CONFIG_NO_RADIUS */
 
        return sm;
 }
index d48a4b54c2aedcc4b8223fa8ecf66aaf65ad2e25..77f998074e0682a6ca47bff36acc9bc11c363daf 100644 (file)
@@ -1656,3 +1656,14 @@ u8 radius_msg_find_unlisted_attr(struct radius_msg *msg, u8 *attrs)
 
        return 0;
 }
+
+
+int radius_gen_session_id(u8 *id, size_t len)
+{
+       /*
+        * Acct-Session-Id and Acct-Multi-Session-Id should be globally and
+        * temporarily unique. A high quality random number is required
+        * therefore. This could be be improved by switching to a GUID.
+        */
+       return os_get_random(id, len);
+}
index 9218c94d4a46d84006e25ac78f4000b09f8736d2..313fc650f4c64d6a93ba7b006521ddd771421070 100644 (file)
@@ -319,4 +319,6 @@ int radius_copy_class(struct radius_class_data *dst,
 
 u8 radius_msg_find_unlisted_attr(struct radius_msg *msg, u8 *attrs);
 
+int radius_gen_session_id(u8 *id, size_t len);
+
 #endif /* RADIUS_H */