aboutsummaryrefslogtreecommitdiffstats
path: root/src/radius
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2009-12-19 16:34:41 +0200
committerJouni Malinen <j@w1.fi>2009-12-19 16:34:41 +0200
commit9e7245bdb414dec167363b9178a37f4745afa595 (patch)
treebcb52c9731b1af430703926c1de98124465afcca /src/radius
parentd94f86d85ef1a846ff91fe3c66b368c1d535352c (diff)
downloadexternal_wpa_supplicant_8_ti-9e7245bdb414dec167363b9178a37f4745afa595.zip
external_wpa_supplicant_8_ti-9e7245bdb414dec167363b9178a37f4745afa595.tar.gz
external_wpa_supplicant_8_ti-9e7245bdb414dec167363b9178a37f4745afa595.tar.bz2
Change radius_msg_free() to free the buffer
Since all callers were freeing the buffer immediately anyway, move this operation into radius_msg_free() to reduce code size.
Diffstat (limited to 'src/radius')
-rw-r--r--src/radius/radius.c41
-rw-r--r--src/radius/radius.h8
-rw-r--r--src/radius/radius_client.c5
-rw-r--r--src/radius/radius_server.c29
4 files changed, 39 insertions, 44 deletions
diff --git a/src/radius/radius.c b/src/radius/radius.c
index 7b69c9b..a00cee5 100644
--- a/src/radius/radius.c
+++ b/src/radius/radius.c
@@ -63,6 +63,15 @@ static int radius_msg_initialize(struct radius_msg *msg, size_t init_len)
}
+/**
+ * radius_msg_new - Create a new RADIUS message
+ * @code: Code for RADIUS header
+ * @identifier: Identifier for RADIUS header
+ * Returns: Context for RADIUS message or %NULL on failure
+ *
+ * The caller is responsible for freeing the returned data with
+ * radius_msg_free().
+ */
struct radius_msg * radius_msg_new(u8 code, u8 identifier)
{
struct radius_msg *msg;
@@ -82,16 +91,18 @@ struct radius_msg * radius_msg_new(u8 code, u8 identifier)
}
+/**
+ * radius_msg_free - Free a RADIUS message
+ * @msg: RADIUS message from radius_msg_new() or radius_msg_parse()
+ */
void radius_msg_free(struct radius_msg *msg)
{
- os_free(msg->buf);
- msg->buf = NULL;
- msg->hdr = NULL;
- msg->buf_size = msg->buf_used = 0;
+ if (msg == NULL)
+ return;
+ os_free(msg->buf);
os_free(msg->attr_pos);
- msg->attr_pos = NULL;
- msg->attr_size = msg->attr_used = 0;
+ os_free(msg);
}
@@ -452,7 +463,16 @@ struct radius_attr_hdr *radius_msg_add_attr(struct radius_msg *msg, u8 type,
}
-struct radius_msg *radius_msg_parse(const u8 *data, size_t len)
+/**
+ * radius_msg_parse - Parse a RADIUS message
+ * @data: RADIUS message to be parsed
+ * @len: Length of data buffer in octets
+ * Returns: Parsed RADIUS message or %NULL on failure
+ *
+ * This parses a RADIUS message and makes a copy of its data. The caller is
+ * responsible for freeing the returned data with radius_msg_free().
+ */
+struct radius_msg * radius_msg_parse(const u8 *data, size_t len)
{
struct radius_msg *msg;
struct radius_hdr *hdr;
@@ -467,13 +487,13 @@ struct radius_msg *radius_msg_parse(const u8 *data, size_t len)
msg_len = ntohs(hdr->length);
if (msg_len < sizeof(*hdr) || msg_len > len) {
- printf("Invalid RADIUS message length\n");
+ wpa_printf(MSG_INFO, "RADIUS: Invalid message length");
return NULL;
}
if (msg_len < len) {
- printf("Ignored %lu extra bytes after RADIUS message\n",
- (unsigned long) len - msg_len);
+ wpa_printf(MSG_DEBUG, "RADIUS: Ignored %lu extra bytes after "
+ "RADIUS message", (unsigned long) len - msg_len);
}
msg = os_zalloc(sizeof(*msg));
@@ -512,7 +532,6 @@ struct radius_msg *radius_msg_parse(const u8 *data, size_t len)
fail:
radius_msg_free(msg);
- os_free(msg);
return NULL;
}
diff --git a/src/radius/radius.h b/src/radius/radius.h
index 9f77a5a..6050b54 100644
--- a/src/radius/radius.h
+++ b/src/radius/radius.h
@@ -230,7 +230,7 @@ struct radius_msg {
/* MAC address ASCII format for non-802.1X use */
#define RADIUS_ADDR_FORMAT "%02x%02x%02x%02x%02x%02x"
-struct radius_msg *radius_msg_new(u8 code, u8 identifier);
+struct radius_msg * radius_msg_new(u8 code, u8 identifier);
void radius_msg_free(struct radius_msg *msg);
void radius_msg_dump(struct radius_msg *msg);
int radius_msg_finish(struct radius_msg *msg, const u8 *secret,
@@ -239,9 +239,9 @@ int radius_msg_finish_srv(struct radius_msg *msg, const u8 *secret,
size_t secret_len, const u8 *req_authenticator);
void radius_msg_finish_acct(struct radius_msg *msg, const u8 *secret,
size_t secret_len);
-struct radius_attr_hdr *radius_msg_add_attr(struct radius_msg *msg, u8 type,
- const u8 *data, size_t data_len);
-struct radius_msg *radius_msg_parse(const u8 *data, size_t len);
+struct radius_attr_hdr * radius_msg_add_attr(struct radius_msg *msg, u8 type,
+ const u8 *data, size_t data_len);
+struct radius_msg * radius_msg_parse(const u8 *data, size_t len);
int radius_msg_add_eap(struct radius_msg *msg, const u8 *data,
size_t data_len);
u8 *radius_msg_get_eap(struct radius_msg *msg, size_t *len);
diff --git a/src/radius/radius_client.c b/src/radius/radius_client.c
index 4cb9c39..0ace8d1 100644
--- a/src/radius/radius_client.c
+++ b/src/radius/radius_client.c
@@ -247,7 +247,6 @@ static int radius_client_init_auth(struct radius_client_data *radius);
static void radius_client_msg_free(struct radius_msg_list *req)
{
radius_msg_free(req->msg);
- os_free(req->msg);
os_free(req);
}
@@ -526,7 +525,6 @@ static void radius_client_list_add(struct radius_client_data *radius,
/* No point in adding entries to retransmit queue since event
* loop has already been terminated. */
radius_msg_free(msg);
- os_free(msg);
return;
}
@@ -534,7 +532,6 @@ static void radius_client_list_add(struct radius_client_data *radius,
if (entry == NULL) {
printf("Failed to add RADIUS packet into retransmit list\n");
radius_msg_free(msg);
- os_free(msg);
return;
}
@@ -802,7 +799,6 @@ static void radius_client_receive(int sock, void *eloop_ctx, void *sock_ctx)
switch (res) {
case RADIUS_RX_PROCESSED:
radius_msg_free(msg);
- os_free(msg);
/* continue */
case RADIUS_RX_QUEUED:
radius_client_msg_free(req);
@@ -830,7 +826,6 @@ static void radius_client_receive(int sock, void *eloop_ctx, void *sock_ctx)
fail:
radius_msg_free(msg);
- os_free(msg);
}
diff --git a/src/radius/radius_server.c b/src/radius/radius_server.c
index 635143f..54bfdac 100644
--- a/src/radius/radius_server.c
+++ b/src/radius/radius_server.c
@@ -359,15 +359,9 @@ static void radius_server_session_free(struct radius_server_data *data,
{
eloop_cancel_timeout(radius_server_session_timeout, data, sess);
eap_server_sm_deinit(sess->eap);
- if (sess->last_msg) {
- radius_msg_free(sess->last_msg);
- os_free(sess->last_msg);
- }
+ radius_msg_free(sess->last_msg);
os_free(sess->last_from_addr);
- if (sess->last_reply) {
- radius_msg_free(sess->last_reply);
- os_free(sess->last_reply);
- }
+ radius_msg_free(sess->last_reply);
os_free(sess);
data->num_sess--;
}
@@ -584,7 +578,6 @@ radius_server_encapsulate_eap(struct radius_server_data *data,
if (radius_msg_copy_attr(msg, request, RADIUS_ATTR_PROXY_STATE) < 0) {
RADIUS_DEBUG("Failed to copy Proxy-State attribute(s)");
radius_msg_free(msg);
- os_free(msg);
return NULL;
}
@@ -629,7 +622,6 @@ static int radius_server_reject(struct radius_server_data *data,
if (radius_msg_copy_attr(msg, request, RADIUS_ATTR_PROXY_STATE) < 0) {
RADIUS_DEBUG("Failed to copy Proxy-State attribute(s)");
radius_msg_free(msg);
- os_free(msg);
return -1;
}
@@ -652,7 +644,6 @@ static int radius_server_reject(struct radius_server_data *data,
}
radius_msg_free(msg);
- os_free(msg);
return ret;
}
@@ -763,10 +754,7 @@ static int radius_server_request(struct radius_server_data *data,
RADIUS_DEBUG("No EAP data from the state machine, but eapFail "
"set");
} else if (eap_sm_method_pending(sess->eap)) {
- if (sess->last_msg) {
- radius_msg_free(sess->last_msg);
- os_free(sess->last_msg);
- }
+ radius_msg_free(sess->last_msg);
sess->last_msg = msg;
sess->last_from_port = from_port;
os_free(sess->last_from_addr);
@@ -813,10 +801,7 @@ static int radius_server_request(struct radius_server_data *data,
if (res < 0) {
perror("sendto[RADIUS SRV]");
}
- if (sess->last_reply) {
- radius_msg_free(sess->last_reply);
- os_free(sess->last_reply);
- }
+ radius_msg_free(sess->last_reply);
sess->last_reply = reply;
sess->last_from_port = from_port;
sess->last_identifier = msg->hdr->identifier;
@@ -944,10 +929,7 @@ static void radius_server_receive_auth(int sock, void *eloop_ctx,
return; /* msg was stored with the session */
fail:
- if (msg) {
- radius_msg_free(msg);
- os_free(msg);
- }
+ radius_msg_free(msg);
os_free(buf);
}
@@ -1515,5 +1497,4 @@ void radius_server_eap_pending_cb(struct radius_server_data *data, void *ctx)
return; /* msg was stored with the session */
radius_msg_free(msg);
- os_free(msg);
}