Having all security models implemented in one monolithic function is cumbersome. Especially when the need arises to fix something in the shared code, as it forces to change all the paths at the same time.
This doesn't fix any bug, it is just preparatory cleanup. Signed-off-by: Greg Kurz <[email protected]> --- hw/9pfs/9p-local.c | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index f9abd4229b17..d424d8994779 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -1187,26 +1187,52 @@ static int local_rename(FsContext *ctx, const char *oldpath, return err; } -static int local_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) +static int local_chown_passthrough(FsContext *fs_ctx, V9fsPath *fs_path, + FsCred *credp) { char *buffer; int ret = -1; char *path = fs_path->data; + buffer = rpath(fs_ctx, path); + ret = lchown(buffer, credp->fc_uid, credp->fc_gid); + g_free(buffer); + return ret; +} + +static int local_chown_mapped(FsContext *fs_ctx, V9fsPath *fs_path, + FsCred *credp) +{ + char *buffer; + int ret = -1; + char *path = fs_path->data; + + buffer = rpath(fs_ctx, path); + ret = local_set_xattr(buffer, credp); + g_free(buffer); + return ret; +} + +static int local_chown_mapped_file(FsContext *fs_ctx, V9fsPath *fs_path, + FsCred *credp) +{ + char *path = fs_path->data; + + return local_set_mapped_file_attr(fs_ctx, path, credp); +} + +static int local_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) +{ if ((credp->fc_uid == -1 && credp->fc_gid == -1) || (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) || (fs_ctx->export_flags & V9FS_SM_NONE)) { - buffer = rpath(fs_ctx, path); - ret = lchown(buffer, credp->fc_uid, credp->fc_gid); - g_free(buffer); + return local_chown_passthrough(fs_ctx, fs_path, credp); } else if (fs_ctx->export_flags & V9FS_SM_MAPPED) { - buffer = rpath(fs_ctx, path); - ret = local_set_xattr(buffer, credp); - g_free(buffer); + return local_chown_mapped(fs_ctx, fs_path, credp); } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { - return local_set_mapped_file_attr(fs_ctx, path, credp); + return local_chown_mapped_file(fs_ctx, fs_path, credp); } - return ret; + g_assert_not_reached(); } static int local_utimensat(FsContext *s, V9fsPath *fs_path,
