{
listen_socket_t *sock = listener->data;
+ SSL_shutdown(sock->ssn->ssl);
+
listener->status = RAD_LISTEN_STATUS_EOL;
listener->tls = NULL; /* parent owns this! */
- if (sock->parent) {
- /*
- * Decrement the number of connections.
- */
- if (sock->parent->limit.num_connections > 0) {
- sock->parent->limit.num_connections--;
- }
- if (sock->client->limit.num_connections > 0) {
- sock->client->limit.num_connections--;
- }
- }
-
/*
* Tell the event handler that an FD has disappeared.
*/
- event_new_fd(listener);
+ DEBUG("Client has closed connection");
+ radius_update_listener(listener);
/*
* Do NOT free the listener here. It's in use by
*/
}
-static int tls_socket_write(rad_listen_t *listener, REQUEST *request)
+static int CC_HINT(nonnull) tls_socket_write(rad_listen_t *listener, REQUEST *request)
{
uint8_t *p;
ssize_t rcode;
RADCLIENT *client = sock->client;
if (!sock->packet) {
- sock->packet = rad_alloc(sock, 0);
+ sock->packet = rad_alloc(sock, false);
if (!sock->packet) return 0;
sock->packet->sockfd = listener->fd;
sock->packet->dst_port = sock->my_port;
if (sock->request) {
- (void) talloc_steal(sock->request, sock->packet);
- sock->request->packet = sock->packet;
+ sock->request->packet = talloc_steal(sock->request, sock->packet);
}
}
rad_assert(request->packet == NULL);
rad_assert(sock->packet != NULL);
- request->packet = sock->packet;
+ request->packet = talloc_steal(request, sock->packet);
request->component = "<core>";
request->component = "<tls-connect>";
/*
* Not sure if we should do this on every packet...
*/
- request->reply = rad_alloc(request, 0);
+ request->reply = rad_alloc(request, false);
if (!request->reply) return 0;
rad_assert(sock->ssn == NULL);
- sock->ssn = tls_new_session(listener->tls, sock->request,
+ sock->ssn = tls_new_session(listener->tls, listener->tls, sock->request,
listener->tls->require_client_cert);
if (!sock->ssn) {
- request_free(&sock->request);
+ TALLOC_FREE(sock->request);
sock->packet = NULL;
return 0;
}
(void) talloc_steal(sock, sock->ssn);
SSL_set_ex_data(sock->ssn->ssl, FR_TLS_EX_INDEX_REQUEST, (void *)request);
SSL_set_ex_data(sock->ssn->ssl, FR_TLS_EX_INDEX_CERTS, (void *)&request->packet->vps);
+ SSL_set_ex_data(sock->ssn->ssl, FR_TLS_EX_INDEX_TALLOC, sock->parent);
doing_init = true;
}
sizeof(sock->ssn->dirty_in.data));
if ((rcode < 0) && (errno == ECONNRESET)) {
do_close:
- DEBUG("Closing TLS socket from client");
+ DEBUG("Closing TLS socket from client port %u", sock->other_port);
tls_socket_close(listener);
PTHREAD_MUTEX_UNLOCK(&sock->mutex);
return 0;
return 0;
}
- dump_hex("TUNNELED DATA", sock->ssn->clean_out.data, sock->ssn->clean_out.used);
+ dump_hex("TUNNELED DATA > ", sock->ssn->clean_out.data, sock->ssn->clean_out.used);
/*
* If the packet is a complete RADIUS packet, return it to
packet->vps = NULL;
PTHREAD_MUTEX_UNLOCK(&sock->mutex);
- if (!rad_packet_ok(packet, 0)) {
+ if (!rad_packet_ok(packet, 0, NULL)) {
RDEBUG("Received bad packet: %s", fr_strerror());
DEBUG("Closing TLS socket from client");
PTHREAD_MUTEX_LOCK(&sock->mutex);
if (fr_debug_flag) {
char host_ipaddr[128];
- if ((packet->code > 0) && (packet->code < FR_MAX_PACKET_CODE)) {
+ if (is_radius_code(packet->code)) {
RDEBUG("tls_recv: %s packet from host %s port %d, id=%d, length=%d",
fr_packet_codes[packet->code],
inet_ntop(packet->src_ipaddr.af,
* set.
*/
switch(packet->code) {
- case PW_AUTHENTICATION_REQUEST:
+ case PW_CODE_ACCESS_REQUEST:
if (listener->type != RAD_LISTEN_AUTH) goto bad_packet;
FR_STATS_INC(auth, total_requests);
fun = rad_authenticate;
break;
#ifdef WITH_ACCOUNTING
- case PW_ACCOUNTING_REQUEST:
+ case PW_CODE_ACCOUNTING_REQUEST:
if (listener->type != RAD_LISTEN_ACCT) {
/*
* Allow auth + dual. Disallow
break;
#endif
- case PW_STATUS_SERVER:
- if (!mainconfig.status_server) {
+ case PW_CODE_STATUS_SERVER:
+ if (!main_config.status_server) {
FR_STATS_INC(auth, total_unknown_types);
- WDEBUG("Ignoring Status-Server request due to security configuration");
+ WARN("Ignoring Status-Server request due to security configuration");
rad_free(&sock->packet);
request->packet = NULL;
return 0;
{
listen_socket_t *sock = listener->data;
+ VERIFY_REQUEST(request);
+
rad_assert(request->listener == listener);
rad_assert(listener->send == dual_tls_send);
}
PTHREAD_MUTEX_LOCK(&sock->mutex);
+
/*
* Write the packet to the SSL buffers.
*/
sock->ssn->record_plus(&sock->ssn->clean_in,
request->reply->data, request->reply->data_len);
+ dump_hex("TUNNELED DATA < ", sock->ssn->clean_in.data, sock->ssn->clean_in.used);
+
/*
* Do SSL magic to get encrypted data.
*/
*
* Called with the mutex held.
*/
-static int proxy_tls_read(rad_listen_t *listener)
+static ssize_t proxy_tls_read(rad_listen_t *listener)
{
int rcode;
size_t length;
DEBUG("proxy recv says %s",
ERR_error_string(err, NULL));
}
-
+
goto do_close;
}
}
return 0;
}
- return 1;
+ sock->partial = 0; /* we've now read the packet */
+ return length;
}
int proxy_tls_recv(rad_listen_t *listener)
{
- int rcode;
listen_socket_t *sock = listener->data;
char buffer[256];
RADIUS_PACKET *packet;
uint8_t *data;
+ ssize_t data_len;
if (listener->status != RAD_LISTEN_STATUS_KNOWN) return 0;
DEBUG3("Proxy SSL socket has data to read");
PTHREAD_MUTEX_LOCK(&sock->mutex);
- rcode = proxy_tls_read(listener);
+ data_len = proxy_tls_read(listener);
PTHREAD_MUTEX_UNLOCK(&sock->mutex);
- if (rcode < 0) {
+ if (data_len < 0) {
DEBUG("Closing TLS socket to home server");
PTHREAD_MUTEX_LOCK(&sock->mutex);
tls_socket_close(listener);
return 0;
}
- if (rcode == 0) return 0; /* no data to read */
+ if (data_len == 0) return 0; /* not done yet */
data = sock->data;
- sock->partial = 0; /* we've now read the packet */
- packet = rad_alloc(sock, 0);
+ packet = rad_alloc(sock, false);
packet->sockfd = listener->fd;
packet->src_ipaddr = sock->other_ipaddr;
packet->src_port = sock->other_port;
packet->dst_port = sock->my_port;
packet->code = data[0];
packet->id = data[1];
- packet->data_len = (data[2] << 8) | data[3];
+ packet->data_len = data_len;
packet->data = talloc_array(packet, uint8_t, packet->data_len);
memcpy(packet->data, data, packet->data_len);
memcpy(packet->vector, packet->data + 4, 16);
* FIXME: Client MIB updates?
*/
switch(packet->code) {
- case PW_AUTHENTICATION_ACK:
- case PW_ACCESS_CHALLENGE:
- case PW_AUTHENTICATION_REJECT:
+ case PW_CODE_ACCESS_ACCEPT:
+ case PW_CODE_ACCESS_CHALLENGE:
+ case PW_CODE_ACCESS_REJECT:
break;
#ifdef WITH_ACCOUNTING
- case PW_ACCOUNTING_RESPONSE:
+ case PW_CODE_ACCOUNTING_RESPONSE:
break;
#endif
int rcode;
listen_socket_t *sock = listener->data;
- if (listener->status != RAD_LISTEN_STATUS_KNOWN) return 0;
+ VERIFY_REQUEST(request);
+
+ if ((listener->status != RAD_LISTEN_STATUS_INIT) &&
+ (listener->status != RAD_LISTEN_STATUS_KNOWN)) return 0;
/*
* Normal proxying calls us with the data already