/* This is take directly from Part 1 * * Change the a specific file privalages * Same as the user change but in this one you change all the privilages for an object * */ void changeFilePriv(int** array, int num_users, int num_files, int num_perm, SYSUSER *tempUser, SYSFILE *tempFile, SYSPERM *tempPerm) { char input_file[25] = ""; char temp_priv[10] = ""; int len,i,j,k; // Promt for the User printf("Which file would you like to change(file change only): "); if (fgets(input_file, MAX_LEN, stdin) != NULL) { clearInputStream(input_file); len = strlen(input_file); if(input_file[len - 1] == '\n') input_file[len - 1] = '\0'; } //Promt for the Privilage to change printf("Which privelages would you like to set(NO, R, W, RW): "); if (fgets(temp_priv, MAX_LEN, stdin) != NULL) { clearInputStream(temp_priv); len = strlen(temp_priv); if(temp_priv[len - 1] == '\n') temp_priv[len - 1] = '\0'; } //Go thought the matrix if the object is matched then change the privalges for (i = 0; i < num_files; i++) if(strcmp(input_file, tempFile[i].label) == 0) for (j=0; j < num_users; j++) for(k=0; k < num_perm; k++) if(strcmp(temp_priv,tempPerm[k].label) == 0){ array[j][i] = tempPerm[k].permission; } }
/* * * Change the a specific labs permissions for all the students in it * Ask for the user, object and the permission and apply all of those. Same as in the other two * */ void changeStudentLabPerm(int** array, int num_users, int num_files, int num_perm, SYSUSER *tempUser, SYSFILE *tempFile, SYSPERM *tempPerm) { char temp_priv[15] = ""; char input_group[25] = ""; int input_lab; char term; int len,i,j,k,x, temp_user_perm; // Select Lab Number printf("Which lab would you like to modify(integer): "); if(scanf("%d%c", &input_lab, &term) != 2 || term != '\n') printf("failure\n"); //Select Object printf("Which group would you like to change: "); //Clearing of Input Buffer if (fgets(input_group, MAX_LEN, stdin) != NULL) { clearInputStream(input_group); len = strlen(input_group); if(input_group[len - 1] == '\n') input_group[len - 1] = '\0'; } //Select Privilege printf("Which privelages would you like to set(NO, R, W, RW): "); //Clearing of Input Buffer if (fgets(temp_priv, MAX_LEN, stdin) != NULL) { clearInputStream(temp_priv); len = strlen(temp_priv); if(temp_priv[len - 1] == '\n') temp_priv[len - 1] = '\0'; } //printf("Lab#:%d, group:%s, privelage:%s\n", input_lab, input_group, temp_priv); //Go thought the matrix matching the Lab number, the file, and the privilage // Then change the permissions and after that call the "checkChangesForInstructor" to make sure that any other lower hierarchical users are changed as well for(i=0; i<num_users; i++){ for(x=0; x< arraySize(tempUser[i].group_num); x++){ if((strcmp(input_group, tempUser[i].group) == 0) && input_lab == tempUser[i].group_num[x]) for (j=0; j < num_files; j++) for(k=0; k < num_perm; k++) if(strcmp(temp_priv,tempPerm[k].label) == 0){ array[i][j] = tempPerm[k].permission; temp_user_perm = tempPerm[k].permission; checkChangesForInstructor(array, tempUser[i].group, num_users, tempUser, input_lab, num_files, tempFile[j].label, tempFile, num_perm, tempPerm, temp_user_perm); } } } }
/* * * Change the a specific user and object privalages * Ask for the user, object and the permission and apply all of those. Same as in the other two * */ void changeUserObjectPriv(int** array, int num_users, int num_files, int num_perm, SYSUSER *tempUser, SYSFILE *tempFile, SYSPERM *tempPerm) { char temp_user[15] = ""; char temp_priv[15] = ""; char input_file[25] = ""; int len,i,j,k; // Select User printf("Which user permission would you like to change(user and file change): "); //Clearing of Input Buffer if (fgets(temp_user, MAX_LEN, stdin) != NULL) { clearInputStream(temp_user); len = strlen(temp_user); if(temp_user[len - 1] == '\n') temp_user[len - 1] = '\0'; } //Select Object printf("Which file would you like to change: "); //Clearing of Input Buffer if (fgets(input_file, MAX_LEN, stdin) != NULL) { clearInputStream(input_file); len = strlen(input_file); if(input_file[len - 1] == '\n') input_file[len - 1] = '\0'; } //Select Privilege printf("Which privelages would you like to set(NO, R, W, RW): "); //Clearing of Input Buffer if (fgets(temp_priv, MAX_LEN, stdin) != NULL) { clearInputStream(temp_priv); len = strlen(temp_priv); if(temp_priv[len - 1] == '\n') temp_priv[len - 1] = '\0'; } //printf("used:%s, file:%s, privelage:%s\n", temp_user, input_file, temp_priv); //Go thought the matrix if the object and the user is matched then change the privilege for (i = 0; i < num_files; i++){ if(strcmp(input_file, tempFile[i].label) == 0){ for (j=0; j < num_users; j++){ if(strcmp(temp_user, tempUser[j].name) == 0){ for(k=0; k < num_perm; k++){ if(strcmp(temp_priv,tempPerm[k].label) == 0){ array[j][i] = tempPerm[k].permission; } } } } } } }
/* * This is Take from the Last Lab * * Print the Capability Ticket for a specific user * Prompt for input for the user and then show capabilities for each file */ void printCapabilityTicket(int** array, int num_users, int num_files, int num_perm, SYSUSER *tempUser, SYSFILE *tempFile, SYSPERM *tempPerm) { int i, j, len, k; char temp_user[25] = ""; // Select User printf("Which user would you like to view: "); //Clearing of Input Buffer if (fgets(temp_user, MAX_LEN, stdin) != NULL) { clearInputStream(temp_user); len = strlen(temp_user); if(temp_user[len - 1] == '\n') temp_user[len - 1] = '\0'; } for(i=0; i<num_users; i++){ if(strcmp(temp_user, tempUser[i].name) == 0){ printf("Capability Ticket for: %s\n\n", tempUser[i].name); for (j=0; j < num_files; j++){ printf("%*s:", 25,tempFile[j].name); for(k=0; k < num_perm; k++){ if(array[i][j] == '\0'){ printf(" "); break; }else if(array[i][j] == tempPerm[k].permission){ printf(" %s ", tempPerm[k].label); } } printf("\n"); } } } }
/* This function prints out an access control list for a particular file. * Every user in the access matrix is listed with their corresponding * access privileges to the file. */ void printAccessControlList(int** array, int num_users, int num_files, int num_perm, SYSUSER *tempUser, SYSFILE *tempFile, SYSPERM *tempPerm){ int i, j, k, len; char temp_file[MAX_LEN] = ""; int sizeOfArray = num_users * num_files; // Select User printf("Which file would you like to view: "); //Clearing of Input Buffer if (fgets(temp_file, MAX_LEN, stdin) != NULL) { clearInputStream(temp_file); len = strlen(temp_file); if(temp_file[len - 1] == '\n') temp_file[len - 1] = '\0'; } /* Look for the file label the user is searching for and when found * print all users in the access matrix along with the corresponding * list of privileges in the file's field. */ for(i=0; i<sizeOfArray; i++){ if(strcmp(temp_file, tempFile[i].label) == 0){ printf("Access Control List for: %s\n\n", tempFile[i].name); for (j=0; j < num_users; j++){ printf("%*s:", 25,tempUser[j].name); for(k=0; k < num_perm; k++){ if(array[j][i] == tempPerm[k].permission){ printf(" %s ", tempPerm[k].label); } } printf("\n"); } } } }
/* * Change the user privilages * Does all the change but does not work with the group array for the TAs * This could be done in further iteration * */ void changeUserRole(int num_users, SYSUSER *tempUser){ char temp_user[15] = ""; char new_group[15] = ""; char term; int i, len, new_lab; // Promt for the User printf("Which user would you like to change: "); if (fgets(temp_user, MAX_LEN, stdin) != NULL) { clearInputStream(temp_user); len = strlen(temp_user); if(temp_user[len - 1] == '\n') temp_user[len - 1] = '\0'; } for(i=0;i<num_users; i++){ if(strcmp(temp_user, tempUser[i].name) == 0){ printf("User: %s is part of group:%s and lab number:%d\n", tempUser[i].name, tempUser[i].group, tempUser[i].group_num[0]); // Promt for Lab change printf("Which lab would you like to assign to this user(integer): "); if(scanf("%d%c", &new_lab, &term) != 2 || term != '\n') printf("failure\n"); // Promt for the group change printf("Which group would you like to assign the user to: "); if (fgets(new_group, MAX_LEN, stdin) != NULL) { clearInputStream(new_group); len = strlen(new_group); if(new_group[len - 1] == '\n') new_group[len - 1] = '\0'; } strcpy(tempUser[i].group, new_group); tempUser[i].group_num[0] = new_lab; } } }
bool transmitFromDriverRequestBuffer() { // Handle redirection if (redirectFunction != NULL) { bool result = redirectFunction(); return result; } // We do exactly as if the data was written by a end-user // requestBuffer must be filled before calling this method Buffer* requestBuffer = getDriverRequestBuffer(); Buffer* responseBuffer = getDriverResponseBuffer(); InputStream* inputStream = getDriverResponseInputStream(); if (inputStream == NULL) { writeError(DRIVER_INPUT_STREAM_NULL); return false; } // The first char is the device header unsigned dataDispacherLength = 0; unsigned char deviceHeader = bufferGetCharAtIndex(requestBuffer, DEVICE_HEADER_INDEX); if (deviceHeader == DISPATCHER_COMMAND_HEADER) { dataDispacherLength = DISPATCHER_COMMAND_AND_INDEX_HEADER_LENGTH; // Reload the real Device Header deviceHeader = bufferGetCharAtIndex(requestBuffer, dataDispacherLength + DEVICE_HEADER_INDEX); } // The second char is the command header unsigned char commandHeader = bufferGetCharAtIndex(requestBuffer, dataDispacherLength + COMMAND_HEADER_INDEX); bool result = handleStreamInstruction( requestBuffer, responseBuffer, // Don't copy to an outputStream, because, we // want to read the content of responseBuffer NULL, // TODO : Check why we don't provide any NotificationOutputStream NULL, // No Input Filter NULL, // No Output Filter NULL); // We need ack result = checkIsAck(inputStream); if (!result) { // The buffer is corrupted, but we would like to avoid further problem clearInputStream(inputStream); return false; } // Device header answer with the same header as the request checkIsChar(inputStream, deviceHeader); if (!result) { // The buffer is corrupted, but we would like to avoid further problem clearInputStream(inputStream); return false; } // Command header answer with the same header as the request checkIsChar(inputStream, commandHeader); if (!result) { // The buffer is corrupted, but we would like to avoid further problem clearInputStream(inputStream); return false; } return result; }
/* * Works for the hierchies of the system * Change the a specific labs permissions for all the students in it * Ask for the user, object and the permission and apply all of those. Same as in the other two * */ void changeStudentLabFilePerm(int** array, int num_users, int num_files, int num_perm, SYSUSER *tempUser, SYSFILE *tempFile, SYSPERM *tempPerm) { char temp_priv[15] = ""; char input_group[25] = ""; char input_file[25] = ""; char temp_user_group[25] = ""; char temp_file_name[25]; int input_lab = 0; char term; int len,i,j,k,x, temp_group_num=0; int temp_user_perm = 0; // Select Lab printf("Which lab would you like to modify(integer)(0 for instructors): "); if(scanf("%d%c", &input_lab, &term) != 2 || term != '\n') printf("failure\n"); //Select Group printf("Which user role would you like to change: "); //Clearing of Input Buffer if (fgets(input_group, MAX_LEN, stdin) != NULL) { clearInputStream(input_group); len = strlen(input_group); if(input_group[len - 1] == '\n') input_group[len - 1] = '\0'; } //Select File printf("Which file would you like to change: "); //Clearing of Input Buffer if (fgets(input_file, MAX_LEN, stdin) != NULL) { clearInputStream(input_file); len = strlen(input_file); if(input_file[len - 1] == '\n') input_file[len - 1] = '\0'; } //Select Privilege printf("Which privelages would you like to set(NO, R, W, RW): "); //Clearing of Input Buffer if (fgets(temp_priv, MAX_LEN, stdin) != NULL) { clearInputStream(temp_priv); len = strlen(temp_priv); if(temp_priv[len - 1] == '\n') temp_priv[len - 1] = '\0'; } printf("Lab#:%d, group:%s, privelage:%s\n", input_lab, input_group, temp_priv); //Go thought the matrix matching the Lab number, the file, privilage and name of the group // Then change the permissions and after that call the "checkChangesForInstructor" to make sure that any other lower hierarchical users are changed as well // in this one the checkChangesForInstructor is called after the loop, using the set temporary_files for (i = 0; i < num_users; i++){ for(x=0; x<= arraySize(tempUser[i].group_num)+1; x++){ if((strcmp(input_group, tempUser[i].group) == 0) && input_lab == tempUser[i].group_num[x]){ for (j=0; j < num_files; j++){ if (strcmp(input_file, tempFile[j].label) == 0){ for(k=0; k < num_perm; k++){ if(strcmp(temp_priv,tempPerm[k].label) == 0){ array[i][j] = tempPerm[k].permission; strcpy(temp_user_group, tempUser[i].group); strcpy(temp_file_name, tempFile[j].label); temp_user_perm = tempPerm[k].permission; temp_group_num = tempUser[i].group_num[x]; } } } } } } } checkChangesForInstructor(array, temp_user_group, num_users, tempUser, temp_group_num, num_files, temp_file_name, tempFile, num_perm, tempPerm, temp_user_perm); }