Commit aff89d15 authored by 's avatar
Browse files

Fixed few VOd bugs.

Removed optimisation flag from Makefile. Will be restored
when VOd is sufficiently stable.


git-svn-id: file:///home/svn/mapi/trunk@524 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent d835908c
......@@ -3,7 +3,7 @@ INCLUDE= -I.
CWARNINGS=-Wall -Wsign-compare -Wpointer-arith -Wnested-externs\
-Wmissing-declarations -Wcast-align -Wchar-subscripts
CFEATURES=-D_GNU_SOURCE -D_THREAD_SAFE
COPTIMIZATIONS=-O2
#COPTIMIZATIONS=-O2
CDEBUG=-g
CFLAGS=$(CDEBUG) $(CWARNINGS) $(CFEATURES) $(COPTIMIZATIONS)
......
......@@ -124,7 +124,7 @@ int main(int argc, char **argv)
perror("accept");
return(-1);
}
// Thread the hand the query waiting.
if(pthread_create((void*)child, NULL, request_handler, (void *)connected_socket) != 0)
{
......@@ -155,9 +155,15 @@ void *request_handler(void *args)
int mapid_socket = (int)args;
int CA_socket;
// # of received bytes.
int bytes_recvd = 0;
// Initialisations.
pthread_detach(pthread_self());
/*
* CA socket init
*/
if((he = gethostbyname(ca_addr))== NULL)
{
perror("gethostbyname");
......@@ -168,48 +174,58 @@ void *request_handler(void *args)
remote_addr.sin_addr = *((struct in_addr *)he->h_addr);
memset(remote_addr.sin_zero, '\0', 8);
// Get request.
if(recv(mapid_socket, req, sizeof(auth_msg_t), 0) == -1)
while(42)
{
perror("recv");
goto term;
}
// Get request.
bytes_recvd = recv(mapid_socket, req, sizeof(auth_msg_t), 0);
if(bytes_recvd == -1)
{
perror("recv");
goto term;
}
else if(bytes_recvd == 0)
{
// Orderly shutdown. Terminate.
goto term;
}
else
fprintf(stderr, "Got %d bytes.\n", bytes_recvd);
switch(req->opcode)
{
case 0x05:
req->opcode = 0x02;
// TODO -- find the policy and copy it in the packet
send_policy(mapid_socket, req);
send(mapid_socket, req, sizeof(auth_msg_t), 0);
break;
case 0x16:
sconnection = connect_to_CA(&CA_socket, &ssl_context, &remote_addr);
if(!sconnection)
{
switch(req->opcode)
{
case 0x05:
req->opcode = 0x02;
// TODO -- find the policy and copy it in the packet
send_policy(mapid_socket, req);
send(mapid_socket, req, sizeof(auth_msg_t), 0);
break;
}
if(authenticate_user(sconnection, req) == -1)
{
fprintf(stderr, "request_handler: Error in authenticate_user()\n");
case 0x16:
sconnection = connect_to_CA(&CA_socket, &ssl_context, &remote_addr);
if(!sconnection)
{
break;
}
if(authenticate_user(sconnection, req) == -1)
{
fprintf(stderr, "request_handler: Error in authenticate_user()\n");
break;
}
// Respond to mapid.
// The message opcode has already been set.
send(mapid_socket, req, sizeof(auth_msg_t), 0);
break;
}
case 0x1C:
if(send_nic_list(mapid_socket, req) == -1)
fprintf(stderr, "request_handler: Error in send_nic_list()\n");
// Respond to mapid.
// The message opcode has already been set.
send(mapid_socket, req, sizeof(auth_msg_t), 0);
break;
case 0x1C:
if(send_nic_list(mapid_socket, req) == -1)
fprintf(stderr, "request_handler: Error in send_nic_list()\n");
break;
default:
fprintf(stderr,"request_handler: Invalid opcode 0x%x received.\n", req->opcode);
goto term;
break;
default:
fprintf(stderr,"request_handler: Invalid request (code: 0x%x) received.\n", req->opcode);
goto term;
}
}
......@@ -352,7 +368,8 @@ void build_nics(conf_parameter_t *VO_list)
*/
int build_policies()
{
flist_node_t *node = NULL, *tmp = NULL;
flist_node_t *node = NULL;
char *tmp = NULL;
vo_info_t *vo = NULL;
conf_category_entry_t *entry = NULL;
conf_parameter_t *function = NULL;
......@@ -384,17 +401,14 @@ int build_policies()
while(function)
{
if((tmp = malloc(sizeof(flist_node_t))) == NULL)
return(-1);
memset(tmp, 0, sizeof(flist_node_t));
if((tmp->data = malloc(strlen(function->name) + strlen(function->value) + 2)) == NULL)
if((tmp = malloc(strlen(function->name) + strlen(function->value) + 2)) == NULL)
return(-1);
memset(tmp, 0, strlen(function->name) + strlen(function->value) + 2);
snprintf(tmp->data, strlen(function->name) + strlen(function->value) + 2, "%s:%s", function->name, function->value);
snprintf(tmp, strlen(function->name) + strlen(function->value) + 2, "%s:%s", function->name, function->value);
// Concept: Insert all functions in a list.
// Then run the reorder function on it.
ptr = (char *)tmp->data + strlen(function->name) + 1;
ptr = tmp + strlen(function->name) + 1;
while(*ptr)
{
if(*ptr == ':')
......@@ -404,16 +418,16 @@ int build_policies()
flist_append(vo->policy, 0, tmp);
fprintf(stderr, "Added function %s to list.\n", (char*)tmp->data);
fprintf(stderr, "Added function %s to list.\n", tmp);
function = function->next;
}
}
if(reorder(vo->policy) == -1)
/*if(reorder(vo->policy) == -1)
{
fprintf(stderr, "build_policies(): Function list for VO %s is not reordered.\n", vo->vo_name);
}
}*/
node = node->next;
}
......@@ -673,8 +687,6 @@ int send_policy(int mapid_socket, auth_msg_t *request)
return(-1);
}
fprintf(stderr, "VO: %s\n", vo_name);
while(tmp_node)
{
vo = tmp_node->data;
......@@ -705,7 +717,7 @@ int send_policy(int mapid_socket, auth_msg_t *request)
tmp_node = tmp_node->next;
}
fprintf(stderr, "VO: %s\nString: %s\n", vo_name, policy);
fprintf(stderr, "VO: %s\tString: %s\n", vo_name, policy);
// TODO: Send policy to mapid.
return(0);
}
......
Markdown is supported
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