static ssize_t _osprd_write(struct file *filp, char __user *usr, size_t size, loff_t *loff) { osprd_info_t *d = file2osprd(filp); if (d == NULL) { return blkdev_write(filp, usr, size, loff); } char *buf = (char*)kmalloc(size, GFP_KERNEL); if (buf == NULL) { return -ENOMEM; } if (copy_from_user(buf, usr, size) != 0) { kfree(buf); return -EFAULT; } //eprintk("WRITE buf: %s\npasswd_hash: %d\n", buf, d->passwd_hash); xor_cipher(buf, size, d->passwd_hash); //eprintk("WRITE buf: %s\npasswd_hash: %d\n", buf, d->passwd_hash); if (copy_to_user(usr, buf, size) != 0) { kfree(buf); return -EFAULT; } kfree(buf); return blkdev_write(filp, usr, size, loff); }
/*-------------------------------------------------------------------------------------------------------------------- -- FUNCTION: process_user -- -- DATE: 2014/09/06 -- -- REVISIONS: (Date and Description) -- -- DESIGNER: Luke Tao, Ian Lee -- -- PROGRAMMER: Luke Tao, Ian Lee -- -- INTERFACE: void * process_user (void * arg) -- -- RETURNS: 0, not important -- -- NOTES: Takes in user input, encrypts commands and sends them. ----------------------------------------------------------------------------------------------------------------------*/ void * process_user (void * arg) { struct client * client = (struct client *) arg; char buffer[BUF_LENGTH]; int quit = FALSE; int password_entered = FALSE; //Initial Suppress Password Echoing struct termios initial_rsettings, new_rsettings; tcgetattr(fileno(stdin), &initial_rsettings); new_rsettings = initial_rsettings; new_rsettings.c_lflag &= ~ECHO; while(!quit) { // First time iteration if(!password_entered) { printf("Enter a password: "******"\nEnter a command: "); strcpy(client->command, get_line(buffer, BUF_LENGTH, stdin)); if(strcmp(client->command, "quit") == 0) { quit = TRUE; } memset(buffer, 0, sizeof(buffer)); sprintf(buffer, "%s %d %s%s%s", client->password, SERVER_MODE, CMD_START, client->command, CMD_END); printf("Sending data: %s\n", buffer); //Encrypt the data send_packet(xor_cipher(buffer, strlen(buffer)), strlen(buffer), get_ip_addr(NETWORK_INT), client->server_host, client->dst_port); //clear buffer memset(client->command, 0, BUF_LENGTH); //sleep to allow for response before prompting for next command usleep(2500000); } return 0; }