Commit aa372671 authored by Robert Dubner's avatar Robert Dubner
Browse files

Remove redundant udp_socket code; some formatting changes

parent bff4ee10
This diff is collapsed.
......@@ -114,7 +114,8 @@ typedef struct _ATTRIBUTE_VALUE
static int
radiusov_generalized_callback(Operation *op, SlapReply *rs)
{
Debug(LDAP_DEBUG_TRACE, "=> %s(): rs->sr_type = %d\n", __func__, rs->sr_type);
Debug( LDAP_DEBUG_TRACE,
"=> %s(): rs->sr_type = %d\n", __func__, rs->sr_type);
ATTRIBUTE_VALUE *desired_attribute = op->o_callback->sc_private;
......@@ -143,7 +144,9 @@ radiusov_generalized_callback(Operation *op, SlapReply *rs)
Attribute *a;
int i;
for( a = rs->sr_un.sru_search.r_entry->e_attrs; a != NULL; a = a->a_next )
for( a = rs->sr_un.sru_search.r_entry->e_attrs;
a != NULL;
a = a->a_next )
{
if( desired_attribute->returned_value[0] )
{
......@@ -158,8 +161,10 @@ radiusov_generalized_callback(Operation *op, SlapReply *rs)
ber_name = &a->a_desc[i].ad_cname;
ber_attr = &a->a_nvals[i];
//Debug(LDAP_DEBUG_TRACE, " There is an a_nval[%d] ber_name %s\n", i, ber_name->bv_val);
if( ber_name->bv_len == strlen(desired_attribute->attribute_name)
&& memcmp(ber_name->bv_val, desired_attribute->attribute_name, ber_name->bv_len) == 0 )
if( ber_name->bv_len == strlen(desired_attribute->attribute_name)
&& memcmp( ber_name->bv_val,
desired_attribute->attribute_name,
ber_name->bv_len) == 0 )
{
//Debug(LDAP_DEBUG_TRACE, " Found you, my pretty!\n");
size_t to_be_copied = ber_attr->bv_len;
......@@ -381,13 +386,13 @@ radiusov_get_password_from_uid( RADIUS_INFO *radius_info,
pszUsername);
rc = radiusov_generalized_database_fetch(
radius_info->radius_db,
radius_info->lud_radius_user->lud_dn,
radius_info->lud_radius_user->lud_scope,
achSearchString,
radius_info->lud_radius_user->lud_attrs[0],
password,
password_len);
radius_info->radius_db,
radius_info->lud_radius_user->lud_dn,
radius_info->lud_radius_user->lud_scope,
achSearchString,
radius_info->lud_radius_user->lud_attrs[0],
password,
password_len);
return rc;
}
......@@ -404,7 +409,10 @@ radiusov_test_and_development( RADIUS_INFO *radius_info,
// It has the form <username>,<password>. <password> MAY end with '\n'.
// It MUST have a terminating '\0';
//
Debug(LDAP_DEBUG_TRACE,"=> %s(): The request is %s\n",__func__, pszUsernamePassword_);
Debug( LDAP_DEBUG_TRACE,
"=> %s(): The request is %s\n",
__func__,
pszUsernamePassword_);
int rc = FAIL_SILENTLY;
......@@ -437,7 +445,9 @@ radiusov_test_and_development( RADIUS_INFO *radius_info,
if( strchr(pszUsername,'\\') )
{
Debug(LDAP_DEBUG_ANY,"=> %s(): Backslash is illegal in <uid>\n",__func__);
Debug( LDAP_DEBUG_ANY,
"=> %s(): Backslash is illegal in <uid>\n",
__func__);
return rc;
}
......@@ -492,12 +502,10 @@ radiusov_acceptconn(void *ctx, void *arg)
char response[1024];
char ebuf[128];
//int udp_socket = radius_info->radius_udp_socket;
static const int MAX_MESSAGE_LENGTH = 4096;
uint8_t incoming_request[MAX_MESSAGE_LENGTH + 1]; // Room for a '\0 fencepost
slen = sizeof(client_addr);
recv_len = recvfrom(radius_info->radius_udp_socket,
recv_len = recvfrom(radius_info->udp_socket,
incoming_request,
MAX_MESSAGE_LENGTH,
0,
......@@ -549,7 +557,7 @@ radiusov_acceptconn(void *ctx, void *arg)
// Get the port number of our socket
struct sockaddr_in us;
socklen_t len = sizeof(us);
getsockname(radius_info->radius_udp_socket, (struct sockaddr *)&us, &len);
getsockname(radius_info->udp_socket, (struct sockaddr *)&us, &len);
int our_port = ntohs(us.sin_port);
Debug( LDAP_DEBUG_ARGS,
......@@ -601,7 +609,6 @@ radiusov_acceptconn(void *ctx, void *arg)
case RADIUS_PROTOCOL:
rc = radiusov_protocol( radius_info,
radius_info->radius_udp_socket,
&client_addr,
achSharedSecret,
incoming_request,
......@@ -628,7 +635,7 @@ radiusov_acceptconn(void *ctx, void *arg)
if( *response )
{
nsent = sendto(radius_info->radius_udp_socket,
nsent = sendto(radius_info->udp_socket,
response,
strlen(response),
0,
......@@ -676,13 +683,12 @@ radiusov_create_udp_port( BackendDB *be,
slap_overinst *radiusov = (slap_overinst *)be->bd_info;
RADIUS_INFO *radius_info = radiusov->on_bi.bi_private;
int udp_socket;
struct sockaddr_in server_addr;
char ebuf[128];
/* create a socket */
udp_socket = socket(AF_INET,SOCK_DGRAM,0);
if ( udp_socket == -1 )
radius_info->udp_socket = socket(AF_INET,SOCK_DGRAM,0);
if ( radius_info->udp_socket == -1 )
{
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,
......@@ -695,7 +701,8 @@ radiusov_create_udp_port( BackendDB *be,
// assign IP, PORT
server_addr.sin_family = AF_INET;
//server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
int rc = inet_aton(port_host, (struct in_addr *)&server_addr.sin_addr.s_addr);
int rc = inet_aton( port_host,
(struct in_addr *)&server_addr.sin_addr.s_addr);
if ( rc == 0 )
{
int saved_errno = errno;
......@@ -709,7 +716,7 @@ radiusov_create_udp_port( BackendDB *be,
server_addr.sin_port = htons(port_number);
// Binding newly created socket to given IP and verification
if ( bind( udp_socket,
if ( bind( radius_info->udp_socket,
(const struct sockaddr*)&server_addr,
sizeof(server_addr)) )
{
......@@ -717,7 +724,7 @@ radiusov_create_udp_port( BackendDB *be,
Debug( LDAP_DEBUG_ANY,"radiusov: bind() to port %d failed: %s",
port_number,
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
if (close(udp_socket))
if (close(radius_info->udp_socket))
{
saved_errno = errno;
Debug( LDAP_DEBUG_ANY,"radiusov: problem closing socket: %s",
......@@ -726,10 +733,10 @@ radiusov_create_udp_port( BackendDB *be,
return 1;
}
radius_info->radius_udp_socket = udp_socket;
radius_info->radius_connection = connection_client_setup( udp_socket,
radiusov_acceptconn,
radius_info );
radius_info->radius_connection = connection_client_setup(
radius_info->udp_socket,
radiusov_acceptconn,
radius_info );
return 0;
}
......@@ -1038,16 +1045,16 @@ radiusov_db_close( BackendDB *be,
{
char ebuf[128];
/* close socket if it's still in use */
if (radius_info->radius_udp_socket >= 0)
if (radius_info->udp_socket >= 0)
{
if (close(radius_info->radius_udp_socket))
if (close(radius_info->udp_socket))
{
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,
"problem closing server socket (ignored): %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
}
radius_info->radius_udp_socket = -1;
radius_info->udp_socket = -1;
}
}
return 0;
......@@ -1058,7 +1065,8 @@ static slap_overinst radiusov;
int
radiusov_initialize( void )
{
Debug( LDAP_DEBUG_TRACE, "=> radiusov_initialize(): registering slap_overinst\n");
Debug( LDAP_DEBUG_TRACE,
"=> radiusov_initialize(): registering slap_overinst\n");
int rc;
......
......@@ -61,9 +61,7 @@
typedef struct _STATE_VOLATILES
{
struct _RADIUS_INFO *radius_info;
int udp_socket;
struct sockaddr_in *client_addr;
// struct _search_descriptor *sd;
const char *shared_secret;
struct _RADIUS_PACKET *request;
struct _EAP_MESSAGE *eap_message;
......@@ -124,7 +122,7 @@ typedef struct _RADIUS_INFO
LDAPURLDesc *lud_radius_user; // From slapd.conf. The parsed search URI for RADIUS user password
LDAPURLDesc *lud_simple_test; // From slapd.conf. The parsed search URI for simple testing
int radius_udp_socket;
int udp_socket;
Connection *radius_connection;
BackendDB *radius_db;
TLS_SERVER_CONF *openssl_configuration;
......@@ -138,13 +136,7 @@ typedef enum _search_methods
RADIUS_PROTOCOL, // This is a formal RADIUS protocol implementation
} search_methods;
//typedef struct _search_descriptor
// {
// char *shared_secret;
// } search_descriptor;
int radiusov_protocol( RADIUS_INFO *radius_info,
int udp_socket,
struct sockaddr_in *client_addr,
const char *shared_secret,
uint8_t *incoming_request,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment