/* Create a new file record */
REFID newFile(ProvObjectPtr p_prov, const char* filename, const char* type)
{
    RecordPtr p_record = ((ProvPtr)p_prov)->p_record;
    IDREF id = newEntity(p_record);
    unsigned char* p_hash;
    if (type == NULL)
	addAttribute(p_record, id, "prov", "xsd:QName", "type", "ni:file");
    else
	addAttribute(p_record, id, "prov", "xsd:QName", "type", type);
    //addAttribute(p_record, id, "ni", "xsd:string", "path", filename);
    p_hash = get_md5_hash(filename);
    if (p_hash != NULL){
	addAttribute(p_record, id, "ni", NULL, "md5sum", p_hash);
        free(p_hash);
    }
    assert(id);
    return((REFID)id);
}
Example #2
0
/*
 * file: file pointer passed from user space, points to inode and inturn contains device info
 * cmd: is the ioctl command that was called from the user space
 * arg: are the arguments passed from the user space
 */
static long wrapfs_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long args)
{
	long err = -ENOTTY;
	struct file *lower_file;

#ifdef WRAPFS_CRYPTO
	char key[KEYLEN];
	struct wrapfs_key_info *kargs=NULL;
#endif

#ifdef EXTRA_CREDIT
	if(wrapfs_get_debug(file->f_dentry->d_sb) & DEBUG_FILE)
		DEBUG_MESG("Enter");
#endif

#ifdef WRAPFS_CRYPTO
	err = verify_and_copy_args(&kargs, (struct wrapfs_key_info*)args);
	if(err) {
		printk("wrapfs_unlocked_ioctl: invalid arguments\n");
		goto out;
	}

	if(cmd == WRAPFS_IO_SETKEY) {
		// printk("wrapfs_unlocked_ioctl: WRAPFS_IO_SETKEY command passed\n");
		if(kargs->key_len==strlen(RESET_KEY) 
			&& memcmp(kargs->key, RESET_KEY, kargs->key_len)==0) {
			WRAPFS_SB(file->f_dentry->d_sb)->has_key = FALSE;
			printk("wrapfs_unlocked_ioctl: key is reset\n");
		}
		/* Only set the key if mmap option is enabled
		 * we cannot perform encryption if different pages aren't available
		 * at different layers, this is achived by enabling
		 * the address_space ops.
		 */
		else if(WRAPFS_SB(file->f_dentry->d_sb)->mount_options.mmap == FALSE) {
			printk("wrapfs_unlocked_ioctl: Cannot set the key if mmap option is disabled\n");
		}
		else {
			WRAPFS_SB(file->f_dentry->d_sb)->has_key = TRUE;
			memset(key, '0', sizeof(key));
			err = get_md5_hash(key, kargs->key, kargs->key_len);
			if(err)
				goto out;
			memcpy(WRAPFS_SB(file->f_dentry->d_sb)->key, key, sizeof(key));
			printk("wrapfs_unlocked_ioctl: key is set\n");
		}
		
	}
#endif

	lower_file = wrapfs_lower_file(file);

	/* XXX: use vfs_ioctl if/when VFS exports it */
	if (!lower_file || !lower_file->f_op)
		goto out;
	if (lower_file->f_op->unlocked_ioctl)
		err = lower_file->f_op->unlocked_ioctl(lower_file, cmd, args);

out:

#ifdef EXTRA_CREDIT
	if(wrapfs_get_debug(file->f_dentry->d_sb) & DEBUG_FILE)
		DEBUG_RETURN("Exit", (int)err);
#endif

	return err;
}