return !is_superuser(ff, ctxt);
}
+static int check_iflags_access(struct fuse2fs *ff, ext2_ino_t ino,
+ const struct ext2_inode *inode, int mask)
+{
+ ext2_filsys fs = ff->fs;
+
+ /* no writing to read-only or broken fs */
+ if ((mask & W_OK) && !fs_writeable(fs))
+ return -EROFS;
+
+ dbg_printf(ff, "access ino=%d mask=e%s%s%s iflags=0x%x\n",
+ ino,
+ (mask & R_OK ? "r" : ""),
+ (mask & W_OK ? "w" : ""),
+ (mask & X_OK ? "x" : ""),
+ inode->i_flags);
+
+ /* is immutable? */
+ if ((mask & W_OK) &&
+ (inode->i_flags & EXT2_IMMUTABLE_FL))
+ return -EPERM;
+
+ return 0;
+}
+
static int check_inum_access(struct fuse2fs *ff, ext2_ino_t ino, int mask)
{
struct fuse_context *ctxt = fuse_get_context();
struct ext2_inode inode;
mode_t perms;
errcode_t err;
+ int ret;
/* no writing to read-only or broken fs */
if ((mask & W_OK) && !fs_writeable(fs))
if (mask == 0)
return 0;
- /* is immutable? */
- if ((mask & W_OK) &&
- (inode.i_flags & EXT2_IMMUTABLE_FL))
- return -EPERM;
+ ret = check_iflags_access(ff, ino, &inode, mask);
+ if (ret)
+ return ret;
/* If kernel is responsible for mode and acl checks, we're done. */
if (ff->kernel)
goto out;
}
+ ret = check_inum_access(ff, ino, W_OK);
+ if (ret)
+ goto out;
+
ret = unlink_file_by_name(ff, path);
if (ret)
goto out;
}
dbg_printf(ff, "%s: rmdir path=%s ino=%d\n", __func__, path, child);
+ ret = check_inum_access(ff, child, W_OK);
+ if (ret)
+ goto out;
+
rds.parent = 0;
rds.empty = 1;
goto out;
}
+ /* the kernel checks parent permissions before emptiness */
+ if (rds.parent == 0) {
+ ret = translate_error(fs, child, EXT2_ET_FILESYSTEM_CORRUPTED);
+ goto out;
+ }
+
+ ret = check_inum_access(ff, rds.parent, W_OK);
+ if (ret)
+ goto out;
+
if (rds.empty == 0) {
ret = -ENOTEMPTY;
goto out;
goto out;
}
+ ret = check_inum_access(ff, from_ino, W_OK);
+ if (ret)
+ goto out;
+
+ if (to_ino) {
+ ret = check_inum_access(ff, to_ino, W_OK);
+ if (ret)
+ goto out;
+ }
+
temp_to = strdup(to);
if (!temp_to) {
ret = -ENOMEM;
if (ret)
goto out2;
-
err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, src, &ino);
if (err || ino == 0) {
ret = translate_error(fs, 0, err);
goto out2;
}
+ ret = check_iflags_access(ff, ino, EXT2_INODE(&inode), W_OK);
+ if (ret)
+ goto out2;
+
inode.i_links_count++;
ret = update_ctime(fs, ino, &inode);
if (ret)
goto out;
}
+ ret = check_iflags_access(ff, ino, EXT2_INODE(&inode), W_OK);
+ if (ret)
+ goto out;
+
if (want_check_owner(ff, ctxt) && ctxt->uid != inode_uid(inode)) {
ret = -EPERM;
goto out;
goto out;
}
+ ret = check_iflags_access(ff, ino, EXT2_INODE(&inode), W_OK);
+ if (ret)
+ goto out;
+
/* FUSE seems to feed us ~0 to mean "don't change" */
if (owner != (uid_t) ~0) {
/* Only root gets to change UID. */