/* 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; }
void sleep_init() { List_init(&sleepq,taskSleepNodes,MAX_TASK); }
void PatternList_init(PatternList *patternList) { assert(patternList != NULL); List_init(patternList); }
void FileFragmentList_init(FileFragmentList *fileFragmentList) { assert(fileFragmentList != NULL); List_init(fileFragmentList); }
void EntryList_init(EntryList *entryList) { assert(entryList != NULL); List_init(entryList); }
void FragmentList_init(FragmentList *fragmentList) { assert(fragmentList != NULL); List_init(fragmentList); }