示例#1
0
/**
 * Add an XML attribute value to the table.
 *
 * If the value exisited in the table, the new value replaces the older one
 * which is then freed.
 *
 * Attributes are kept in the order in which they are inserted.
 *
 * For convenience, the URI may be NULL, in which case the routine behaves
 * as if xattr_table_add_local() had been called.
 *
 * @param xat		the XML attribute table
 * @param uri		the URI namespace of the attribute (copied if non-NULL)
 * @param local		the local name (copied)
 * @param value		the attribute value (copied)
 */
bool
xattr_table_add(xattr_table_t *xat,
	const char *uri, const char *local, const char *value)
{
	struct xattr *xa;

	xattr_table_check(xat);
	g_assert(local != NULL);
	g_assert(value != NULL);

	xa = xattr_alloc(uri, local, value);
	return xattr_table_insert(xat, xa);
}
示例#2
0
/*Not Working Yet*/
static int copyup_xattrs(struct dentry *old_hidden_dentry,
			 struct dentry *new_hidden_dentry)
{
	int err = 0;
	ssize_t list_size = -1;
	char *name_list = NULL;
	char *attr_value = NULL;
	char *name_list_orig = NULL;

	print_entry_location();

	PASSERT(old_hidden_dentry);
	PASSERT(old_hidden_dentry->d_inode);
	PASSERT(old_hidden_dentry->d_inode->i_op);
	PASSERT(new_hidden_dentry);
	PASSERT(new_hidden_dentry->d_inode);
	PASSERT(new_hidden_dentry->d_inode->i_op);

	if (!old_hidden_dentry->d_inode->i_op->getxattr ||
	    !old_hidden_dentry->d_inode->i_op->listxattr ||
	    !new_hidden_dentry->d_inode->i_op->setxattr) {
		err = -ENOTSUPP;
		goto out;
	}

	list_size =
	    old_hidden_dentry->d_inode->i_op->listxattr(old_hidden_dentry, NULL,
							0);
	if (list_size <= 0) {
		err = list_size;
		goto out;
	}

	name_list = xattr_alloc(list_size + 1, XATTR_LIST_MAX);
	if (!name_list || IS_ERR(name_list)) {
		err = PTR_ERR(name_list);
		goto out;
	}
	list_size =
	    old_hidden_dentry->d_inode->i_op->listxattr(old_hidden_dentry,
							name_list, list_size);
	attr_value = xattr_alloc(XATTR_SIZE_MAX, XATTR_SIZE_MAX);
	if (!attr_value || IS_ERR(attr_value)) {
		err = PTR_ERR(name_list);
		goto out;
	}
	name_list_orig = name_list;
	while (*name_list) {
		ssize_t size;
		down(&old_hidden_dentry->d_inode->i_sem);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
		err = security_inode_getxattr(old_hidden_dentry, name_list);
		if (err)
			size = err;
		else
#endif
			size =
			    old_hidden_dentry->d_inode->i_op->
			    getxattr(old_hidden_dentry, name_list, attr_value,
				     XATTR_SIZE_MAX);
		up(&old_hidden_dentry->d_inode->i_sem);
		if (size < 0) {
			err = size;
			goto out;
		}

		if (size > XATTR_SIZE_MAX) {
			err = -E2BIG;
			goto out;
		}

		down(&new_hidden_dentry->d_inode->i_sem);

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
		err =
		    security_inode_setxattr(old_hidden_dentry, name_list,
					    attr_value, size, 0);

		if (!err) {
#endif
			err =
			    new_hidden_dentry->d_inode->i_op->
			    setxattr(new_hidden_dentry, name_list, attr_value,
				     size, 0);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
			if (!err)
				security_inode_post_setxattr(old_hidden_dentry,
							     name_list,
							     attr_value, size,
							     0);
		}
#endif
		up(&new_hidden_dentry->d_inode->i_sem);

		if (err < 0)
			goto out;
		name_list += strlen(name_list) + 1;
	}
      out:
	name_list = name_list_orig;

	if (name_list)
		xattr_free(name_list, list_size + 1);
	if (attr_value)
		xattr_free(attr_value, XATTR_SIZE_MAX);
	/* It is no big deal if this fails, we just roll with the punches. */
	if (err == -ENOTSUPP)
		err = 0;
	return err;
}