blob: 8837a26257b3d9bc11e33e839fa0666ed8a4db0b [file] [log] [blame]
developer2a209692023-08-14 20:23:42 +08001--- a/hostapd/Makefile
2+++ b/hostapd/Makefile
3@@ -63,6 +63,10 @@ endif
4 OBJS += main.o
5 OBJS += config_file.o
6
7+ifdef CONFIG_RADIUS_SERVER
8+OBJS += radius.o
9+endif
10+
11 OBJS += ../src/ap/hostapd.o
12 OBJS += ../src/ap/wpa_auth_glue.o
13 OBJS += ../src/ap/drv_callbacks.o
14--- a/hostapd/main.c
15+++ b/hostapd/main.c
developerdfb50982023-09-11 13:34:36 +080016@@ -40,6 +40,7 @@ struct hapd_global {
17
18 static struct hapd_global global;
developer2a209692023-08-14 20:23:42 +080019
20+extern int radius_main(int argc, char **argv);
21
22 #ifndef CONFIG_NO_HOSTAPD_LOGGER
23 static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module,
developere35b8e42023-10-16 11:04:00 +080024@@ -771,6 +772,11 @@ int main(int argc, char *argv[])
developer2a209692023-08-14 20:23:42 +080025 if (os_program_init())
26 return -1;
27
28+#ifdef RADIUS_SERVER
29+ if (strstr(argv[0], "radius"))
30+ return radius_main(argc, argv);
31+#endif
32+
33 os_memset(&interfaces, 0, sizeof(interfaces));
34 interfaces.reload_config = hostapd_reload_config;
35 interfaces.config_read_cb = hostapd_config_read;
36--- a/src/radius/radius_server.c
37+++ b/src/radius/radius_server.c
38@@ -63,6 +63,12 @@ struct radius_server_counters {
39 u32 unknown_acct_types;
40 };
41
42+struct radius_accept_attr {
43+ u8 type;
44+ u16 len;
45+ void *data;
46+};
47+
48 /**
49 * struct radius_session - Internal RADIUS server data for a session
50 */
51@@ -90,7 +96,7 @@ struct radius_session {
52 unsigned int macacl:1;
53 unsigned int t_c_filtering:1;
54
55- struct hostapd_radius_attr *accept_attr;
56+ struct radius_accept_attr *accept_attr;
57
58 u32 t_c_timestamp; /* Last read T&C timestamp from user DB */
59 };
60@@ -394,6 +400,7 @@ static void radius_server_session_free(s
61 radius_msg_free(sess->last_reply);
62 os_free(sess->username);
63 os_free(sess->nas_ip);
64+ os_free(sess->accept_attr);
65 os_free(sess);
66 data->num_sess--;
67 }
68@@ -554,6 +561,36 @@ radius_server_erp_find_key(struct radius
69 }
70 #endif /* CONFIG_ERP */
71
72+static struct radius_accept_attr *
73+radius_server_copy_attr(const struct hostapd_radius_attr *data)
74+{
75+ const struct hostapd_radius_attr *attr;
76+ struct radius_accept_attr *attr_new;
77+ size_t data_size = 0;
78+ void *data_buf;
79+ int n_attr = 1;
80+
81+ for (attr = data; attr; attr = attr->next) {
82+ n_attr++;
83+ data_size += wpabuf_len(attr->val);
84+ }
85+
86+ attr_new = os_zalloc(n_attr * sizeof(*attr) + data_size);
87+ if (!attr_new)
88+ return NULL;
89+
90+ data_buf = &attr_new[n_attr];
91+ for (n_attr = 0, attr = data; attr; attr = attr->next) {
92+ struct radius_accept_attr *cur = &attr_new[n_attr++];
93+
94+ cur->type = attr->type;
95+ cur->len = wpabuf_len(attr->val);
96+ cur->data = memcpy(data_buf, wpabuf_head(attr->val), cur->len);
97+ data_buf += cur->len;
98+ }
99+
100+ return attr_new;
101+}
102
103 static struct radius_session *
104 radius_server_get_new_session(struct radius_server_data *data,
105@@ -607,7 +644,7 @@ radius_server_get_new_session(struct rad
106 eap_user_free(tmp);
107 return NULL;
108 }
109- sess->accept_attr = tmp->accept_attr;
110+ sess->accept_attr = radius_server_copy_attr(tmp->accept_attr);
111 sess->macacl = tmp->macacl;
112 eap_user_free(tmp);
113
114@@ -1118,11 +1155,10 @@ radius_server_encapsulate_eap(struct rad
115 }
116
117 if (code == RADIUS_CODE_ACCESS_ACCEPT) {
118- struct hostapd_radius_attr *attr;
119- for (attr = sess->accept_attr; attr; attr = attr->next) {
120- if (!radius_msg_add_attr(msg, attr->type,
121- wpabuf_head(attr->val),
122- wpabuf_len(attr->val))) {
123+ struct radius_accept_attr *attr;
124+ for (attr = sess->accept_attr; attr->data; attr++) {
125+ if (!radius_msg_add_attr(msg, attr->type, attr->data,
126+ attr->len)) {
127 wpa_printf(MSG_ERROR, "Could not add RADIUS attribute");
128 radius_msg_free(msg);
129 return NULL;
130@@ -1211,11 +1247,10 @@ radius_server_macacl(struct radius_serve
131 }
132
133 if (code == RADIUS_CODE_ACCESS_ACCEPT) {
134- struct hostapd_radius_attr *attr;
135- for (attr = sess->accept_attr; attr; attr = attr->next) {
136- if (!radius_msg_add_attr(msg, attr->type,
137- wpabuf_head(attr->val),
138- wpabuf_len(attr->val))) {
139+ struct radius_accept_attr *attr;
140+ for (attr = sess->accept_attr; attr->data; attr++) {
141+ if (!radius_msg_add_attr(msg, attr->type, attr->data,
142+ attr->len)) {
143 wpa_printf(MSG_ERROR, "Could not add RADIUS attribute");
144 radius_msg_free(msg);
145 return NULL;
146@@ -2512,7 +2547,7 @@ static int radius_server_get_eap_user(vo
147 ret = data->get_eap_user(data->conf_ctx, identity, identity_len,
148 phase2, user);
149 if (ret == 0 && user) {
150- sess->accept_attr = user->accept_attr;
151+ sess->accept_attr = radius_server_copy_attr(user->accept_attr);
152 sess->remediation = user->remediation;
153 sess->macacl = user->macacl;
154 sess->t_c_timestamp = user->t_c_timestamp;