void *prompt_passphrase(stegdisk_t *sctx) { void *hash = steg_malloc(KEY_BYTES); if(get_key_hash(hash)) { steg_free(hash); return NULL; } return hash; }
/** * main_enc_dec * @f: pointer to struct which contains information about input,temporary and output files * @user_args: pointer to struct user_args_t which contains arguments given by user in user-space * * Initiates basic validation checks to be performed before starting encryption/decryption. Gets the required file handles. Post encryption * or decryption, renames and unlinks the file as required. * * Returns 0 on success;non-zero otherwise */ int main_enc_dec(struct file_struct *f, struct user_args_t *user_args) { int err, tmp_err; char *key_hash; struct dentry *lower_old_dentry; struct dentry *lower_new_dentry; struct dentry *lower_old_dir_dentry; struct dentry *lower_new_dir_dentry; struct dentry *trap = NULL; err = validate_in_out_file(f); f->filp_in = f->filp_out = f->filp_temp = NULL; if (err) { printk(KERN_ALERT"error in validate in out"); goto ERR; } key_hash = get_key_hash(user_args->enc_key); if (IS_ERR(key_hash)) { err = PTR_ERR(key_hash); goto ERR; } err = get_file_handle(&(f->filp_in), f->in_file->name, O_RDONLY, 0); if (err) goto ERR_KEY; if (!(f->filp_in->f_op->read)) { printk(KERN_ALERT"read operation not supported\n"); err = -EPERM; goto ERR_IN; } printk(KERN_ALERT"read file permission\n"); if (f->create_out_file == 'y') { printk(KERN_ALERT"file with default permission\n"); err = get_file_handle(&(f->filp_temp), "/tmp/my_temp_file", O_WRONLY|O_CREAT|O_TRUNC, 0666-current_umask()); } else { printk(KERN_ALERT"creating file with outfile mode\n"); err = get_file_handle(&(f->filp_temp), "/tmp/my_temp_file", O_WRONLY|O_CREAT|O_TRUNC, f->out_file_mode); } if (err) goto ERR_IN; printk(KERN_ALERT"file permission for temp file=\n"); printk(KERN_ALERT"\n"); if (user_args->flags == 1) err = encrypt(f, &key_hash[0], user_args); else err = decrypt(f, &key_hash[0], user_args); if (err) { tmp_err = err; err = vfs_unlink(d_inode(f->filp_temp->f_path.dentry->d_parent), f->filp_temp->f_path.dentry, NULL); if (err) printk(KERN_ALERT"Error in unlink\n"); err = tmp_err; goto ERR_IN; } printk(KERN_ALERT"enc/dec done so now doing a rename\n"); if (f->create_out_file == 'y') err = get_file_handle(&(f->filp_out), f->out_file->name, O_WRONLY|O_CREAT|O_TRUNC, 0666-current_umask()); else err = get_file_handle(&(f->filp_out), f->out_file->name, O_WRONLY, 0); if (err) goto ERR_OUT; if (!(f->filp_out->f_op->write)) { printk(KERN_ALERT"write operation not supported\n"); err = -EPERM; goto ERR; } lower_old_dentry = f->filp_temp->f_path.dentry; lower_old_dir_dentry = dget_parent(lower_old_dentry); lower_new_dentry = f->filp_out->f_path.dentry; lower_new_dir_dentry = dget_parent(lower_new_dentry); trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry); err = vfs_rename(d_inode(lower_old_dir_dentry), lower_old_dentry, d_inode(lower_new_dir_dentry), lower_new_dentry, NULL, 0); if (err) { printk(KERN_ALERT"error in rename\n"); tmp_err = err; err = vfs_unlink(d_inode(f->filp_temp->f_path.dentry->d_parent), f->filp_temp->f_path.dentry, NULL); if (err) printk(KERN_ALERT"Error in unlink\n"); if (f->create_out_file == 'y') { err = vfs_unlink(d_inode(f->filp_temp->f_path.dentry->d_parent), f->filp_temp->f_path.dentry, NULL); if (err) printk(KERN_ALERT"Error in unlink\n"); } err = tmp_err; } printk(KERN_ALERT"rename done!\n"); unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry); if (f->filp_temp) filp_close(f->filp_temp, NULL); ERR_OUT: if (f->filp_out) filp_close(f->filp_out, NULL); ERR_IN: if (f->filp_in) filp_close(f->filp_in, NULL); ERR_KEY: kfree(key_hash); ERR: return err; }