Beispiel #1
0
int  connector_hub_add_connector (void * hub,void * connector,void * attr)
{
	struct tcloud_connector_hub * conn_hub;

	struct List_head * head, *currlib;
	Record_List * record_elem;
	Record_List * conn_list;
	

	conn_hub = (struct tcloud_connector_hub *)hub;

	record_elem = Dalloc(sizeof(Record_List),hub);
	if(record_elem==NULL)
		return -ENOMEM;
	INIT_LIST_HEAD(&(record_elem->list));
	record_elem->record=connector;

	conn_list=(Record_List *)conn_hub->connector_list;

	head = &(conn_list->list);
	List_add_tail(&(record_elem->list),head);

	struct tcloud_connector * new_conn = connector;
	int new_fd;
	new_fd=new_conn->conn_ops->getfd(new_conn);

	if(new_fd<=0)
		return -EINVAL;

	FD_SET(new_fd,&conn_hub->readfds);
	if(conn_hub->nfds<new_fd+1)
		conn_hub->nfds=new_fd+1;
	return 0;
}
Beispiel #2
0
int list_queue_put(void * list_queue,void * record)
{
	LIST_QUEUE * queue;
	Record_List * slot;
	queue=(LIST_QUEUE *)list_queue;
	
	slot=Calloc0(sizeof(Record_List));
	if(slot==NULL)
		return -EINVAL;
	INIT_LIST_HEAD(&slot->list);
	slot->record=record;
	List_add_tail(&slot->list,&queue->queue_list.list);
	queue->record_num++;
	return queue->record_num;
}
Beispiel #3
0
int _dispatch_rule_add(void * list,void * rule)
{
	int ret;
	Record_List * recordhead;
	Record_List * newrecord;
    	POLICY_LIST * rule_list=(POLICY_LIST *)list;

   	recordhead = &(rule_list->head);
	if(recordhead==NULL)
		return -ENOMEM;

	ret=Galloc0(&newrecord,sizeof(Record_List));
	if(newrecord==NULL)
		return -ENOMEM;
	INIT_LIST_HEAD(&(newrecord->list));
	newrecord->record=rule;
	List_add_tail(&(newrecord->list),recordhead);
	rule_list->policy_num++;
	return 1;
}
Beispiel #4
0
int hashlist_add_elem(void * hashlist,void * elem)
{
	Record_List * new_record;
	UUID_LIST * uuid_list= (UUID_LIST *)hashlist;
	int hindex;
	new_record=Calloc(sizeof(Record_List));
	if(new_record==NULL)
		return -ENOMEM;
	INIT_LIST_HEAD(&(new_record->list));
	new_record->record=elem;

	if(uuid_list->hash_num==256)
		hindex=get_hash_subindex(elem);
	else if(uuid_list->hash_num==1024)
		hindex=get_hash_index(elem);
	else
		return -EINVAL;
	
	List_add_tail(&new_record->list,&uuid_list->hash_table[hindex].list);
	return 0;
}
/* This function returns a linked list of all the users and passwords from the
   auth file read in by the auth thread */
List_t *readInUsersFromFile(char *filename)
{
    // Define variables for storing and parsing values
    char line[80];
    char parsed[80];
    List_t *userPassList;
    userPassFile *userPassNode;
    FILE *file;

    // Malloc list
    userPassList = (List_t *) malloc( sizeof( List_t ) );

    // Init the list to store user and pass in
    if (List_init( userPassList ))
    {
        // Open filename given
        file = fopen (filename, "r");

        // Check if file is null
        if (file != NULL)
        {
            // Loop through each line of the file
            while (fgets(line, 80, file) != NULL)
            {
                //Read in a line
                sscanf (line, "%s", parsed);

                // Allocate memory for userPassNode
                userPassNode = (userPassFile *) malloc( sizeof( userPassFile ) );
                if (userPassNode != NULL)
                {
                    // Add username and password to the struct and then into the linked list
                    strncpy( userPassNode->usernamePassword, parsed, CHAR_MAX - 1 );
                    userPassNode->usernamePassword[CHAR_MAX] = '\0'; /* Make sure that it is null-terminated. */

                    // Add userpass struct to a list
                    if (List_add_tail( userPassList, (void *)userPassNode ) == 0)
                    {
                        printf ("Error in inserting the process into the list.\n");
                    }
                }
                else
                {
                    printf("Unable to allocate memory for struct\n");
                }
            }
            fclose(file);  /* close the file prior to exiting the routine */
        }
        else
        {
            printf("Could not open file, exiting... %s\n", filename);
            exit(0);
        }
    }
    else
    {
        printf("Could not initialize list\n");
    }

    //Return a linked list with all values
    return userPassList;
}
/* This function returns a linked list of the serviceFile struct with all of the
   information from the service file in it */
List_t *readInServiceFile(char *filename)
{
    /* Read in file from argument supplied
       Loop through each line
       Store Ticket Secret Value, Service name, secret, and a list of the comma seperated users into a struct
       Add each struct to a linked list so you have a list of services, their secret, and their users
       Return the linked list */

    // Define variables for parseing and storing values
    char line[80];
    char parsed[80];
    char service[80];
    char secret[80];
    char userList[80];
    List_t *returnList;
    serviceFile *serviceNode;
    FILE *file;

    // Malloc list
    returnList = (List_t *) malloc( sizeof( List_t ) );

    if (List_init( returnList ))
    {
        // Open filename given
        file = fopen (filename, "r");

        if (file != NULL)
        {

            while (fgets(line, 80, file) != NULL)
            {
                //Read in a line
                sscanf (line, "%s", parsed);

                //Get parts of service file
                sscanf( parsed, "%[^:]:%[^:]:%s", service, secret, userList);

                // Add it to the userpass struct
                serviceNode = (serviceFile *) malloc( sizeof( serviceFile ) );
                if (serviceNode != NULL)
                {
                    strncpy( serviceNode->secretValue, ticketGrantingSecret, TICKET_SECRET_MAX - 1 );
                    serviceNode->secretValue[TICKET_SECRET_MAX] = '\0'; /* Make sure that it is null-terminated. */

                    strncpy( serviceNode->service, service, CHAR_MAX - 1 );
                    serviceNode->service[CHAR_MAX] = '\0'; /* Make sure that it is null-terminated. */

                    strncpy( serviceNode->secret, secret, CHAR_MAX - 1 );
                    serviceNode->secret[CHAR_MAX] = '\0'; /* Make sure that it is null-terminated. */

                    strncpy( serviceNode->userList, userList, CHAR_MAX - 1 );
                    serviceNode->userList[CHAR_MAX] = '\0'; /* Make sure that it is null-terminated. */

                    // Add userpass struct to a list
                    if (List_add_tail( returnList, (void *)serviceNode ) == 0)
                    {
                        printf ("Error in inserting the process into the list.\n");
                    }
                }
                else
                {
                    printf("Unable to allocate memory for struct\n");
                }

            }
            fclose(file);  /* close the file prior to exiting the routine */
        }
        else
        {
            printf("Could not open file, exiting... %s\n", filename);
            exit(0);
        }
    }
    else
    {
        printf("Could not initialize list\n");
    }


    // End file reading

    //Return a linked list with all values for ticket granting thread
    return returnList;
}