mirror of
https://github.com/winfsp/winfsp.git
synced 2025-07-26 12:32:54 -05:00
dll: fuse: use -ouid=-1,gid=-1 to specify user/group who mounted file system
This commit is contained in:
@@ -485,6 +485,28 @@ FSP_FUSE_API struct fuse *fsp_fuse_new(struct fsp_fuse_env *env,
|
|||||||
if (opt_data.help)
|
if (opt_data.help)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if ((opt_data.set_uid && -1 == opt_data.uid) ||
|
||||||
|
(opt_data.set_gid && -1 == opt_data.gid))
|
||||||
|
{
|
||||||
|
HANDLE Token;
|
||||||
|
|
||||||
|
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &Token))
|
||||||
|
{
|
||||||
|
fsp_fuse_get_token_uidgid(Token, TokenUser,
|
||||||
|
opt_data.set_uid && -1 == opt_data.uid ? &opt_data.uid : 0,
|
||||||
|
opt_data.set_gid && -1 == opt_data.gid ? &opt_data.gid : 0);
|
||||||
|
|
||||||
|
CloseHandle(Token);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((opt_data.set_uid && -1 == opt_data.uid) ||
|
||||||
|
(opt_data.set_gid && -1 == opt_data.gid))
|
||||||
|
{
|
||||||
|
ErrorMessage = L": unknown user/group.";
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!opt_data.set_FileInfoTimeout && opt_data.set_attr_timeout)
|
if (!opt_data.set_FileInfoTimeout && opt_data.set_attr_timeout)
|
||||||
opt_data.VolumeParams.FileInfoTimeout = opt_data.set_attr_timeout * 1000;
|
opt_data.VolumeParams.FileInfoTimeout = opt_data.set_attr_timeout * 1000;
|
||||||
opt_data.VolumeParams.CaseSensitiveSearch = !opt_data.CaseInsensitiveSearch;
|
opt_data.VolumeParams.CaseSensitiveSearch = !opt_data.CaseInsensitiveSearch;
|
||||||
|
@@ -116,19 +116,6 @@ NTSTATUS fsp_fuse_op_enter(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
PWSTR FileName = 0, Suffix;
|
PWSTR FileName = 0, Suffix;
|
||||||
WCHAR Root[2] = L"\\";
|
WCHAR Root[2] = L"\\";
|
||||||
HANDLE Token = 0;
|
HANDLE Token = 0;
|
||||||
union
|
|
||||||
{
|
|
||||||
TOKEN_USER V;
|
|
||||||
UINT8 B[128];
|
|
||||||
} UserInfoBuf;
|
|
||||||
PTOKEN_USER UserInfo = &UserInfoBuf.V;
|
|
||||||
union
|
|
||||||
{
|
|
||||||
TOKEN_PRIMARY_GROUP V;
|
|
||||||
UINT8 B[128];
|
|
||||||
} GroupInfoBuf;
|
|
||||||
PTOKEN_PRIMARY_GROUP GroupInfo = &GroupInfoBuf.V;
|
|
||||||
DWORD Size;
|
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
|
|
||||||
if (FspFsctlTransactCreateKind == Request->Kind)
|
if (FspFsctlTransactCreateKind == Request->Kind)
|
||||||
@@ -157,55 +144,7 @@ NTSTATUS fsp_fuse_op_enter(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
|
|
||||||
if (0 != Token)
|
if (0 != Token)
|
||||||
{
|
{
|
||||||
if (!GetTokenInformation(Token, TokenUser, UserInfo, sizeof UserInfoBuf, &Size))
|
Result = fsp_fuse_get_token_uidgid(Token, TokenUser, &Uid, &Gid);
|
||||||
{
|
|
||||||
if (ERROR_INSUFFICIENT_BUFFER != GetLastError())
|
|
||||||
{
|
|
||||||
Result = FspNtStatusFromWin32(GetLastError());
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
UserInfo = MemAlloc(Size);
|
|
||||||
if (0 == UserInfo)
|
|
||||||
{
|
|
||||||
Result = STATUS_INSUFFICIENT_RESOURCES;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!GetTokenInformation(Token, TokenUser, UserInfo, Size, &Size))
|
|
||||||
{
|
|
||||||
Result = FspNtStatusFromWin32(GetLastError());
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!GetTokenInformation(Token, TokenPrimaryGroup, GroupInfo, sizeof GroupInfoBuf, &Size))
|
|
||||||
{
|
|
||||||
if (ERROR_INSUFFICIENT_BUFFER != GetLastError())
|
|
||||||
{
|
|
||||||
Result = FspNtStatusFromWin32(GetLastError());
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
GroupInfo = MemAlloc(Size);
|
|
||||||
if (0 == UserInfo)
|
|
||||||
{
|
|
||||||
Result = STATUS_INSUFFICIENT_RESOURCES;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!GetTokenInformation(Token, TokenPrimaryGroup, GroupInfo, Size, &Size))
|
|
||||||
{
|
|
||||||
Result = FspNtStatusFromWin32(GetLastError());
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Result = FspPosixMapSidToUid(UserInfo->User.Sid, &Uid);
|
|
||||||
if (!NT_SUCCESS(Result))
|
|
||||||
goto exit;
|
|
||||||
|
|
||||||
Result = FspPosixMapSidToUid(GroupInfo->PrimaryGroup, &Gid);
|
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
@@ -230,12 +169,6 @@ NTSTATUS fsp_fuse_op_enter(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
Result = STATUS_SUCCESS;
|
Result = STATUS_SUCCESS;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (UserInfo != &UserInfoBuf.V)
|
|
||||||
MemFree(UserInfo);
|
|
||||||
|
|
||||||
if (GroupInfo != &GroupInfoBuf.V)
|
|
||||||
MemFree(GroupInfo);
|
|
||||||
|
|
||||||
if (!NT_SUCCESS(Result) && 0 != PosixPath)
|
if (!NT_SUCCESS(Result) && 0 != PosixPath)
|
||||||
FspPosixDeletePath(PosixPath);
|
FspPosixDeletePath(PosixPath);
|
||||||
|
|
||||||
@@ -2062,3 +1995,140 @@ FSP_FILE_SYSTEM_INTERFACE fsp_fuse_intf =
|
|||||||
fsp_fuse_intf_SetReparsePoint,
|
fsp_fuse_intf_SetReparsePoint,
|
||||||
fsp_fuse_intf_DeleteReparsePoint,
|
fsp_fuse_intf_DeleteReparsePoint,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Utility
|
||||||
|
*/
|
||||||
|
NTSTATUS fsp_fuse_get_token_uidgid(
|
||||||
|
HANDLE Token,
|
||||||
|
TOKEN_INFORMATION_CLASS UserOrOwnerClass, /* TokenUser|TokenOwner */
|
||||||
|
PUINT32 PUid, PUINT32 PGid)
|
||||||
|
{
|
||||||
|
UINT32 Uid, Gid;
|
||||||
|
union
|
||||||
|
{
|
||||||
|
TOKEN_USER V;
|
||||||
|
UINT8 B[128];
|
||||||
|
} UserInfoBuf;
|
||||||
|
PTOKEN_USER UserInfo = &UserInfoBuf.V;
|
||||||
|
union
|
||||||
|
{
|
||||||
|
TOKEN_OWNER V;
|
||||||
|
UINT8 B[128];
|
||||||
|
} OwnerInfoBuf;
|
||||||
|
PTOKEN_OWNER OwnerInfo = &OwnerInfoBuf.V;
|
||||||
|
union
|
||||||
|
{
|
||||||
|
TOKEN_PRIMARY_GROUP V;
|
||||||
|
UINT8 B[128];
|
||||||
|
} GroupInfoBuf;
|
||||||
|
PTOKEN_PRIMARY_GROUP GroupInfo = &GroupInfoBuf.V;
|
||||||
|
DWORD Size;
|
||||||
|
NTSTATUS Result;
|
||||||
|
|
||||||
|
if (0 != PUid && TokenUser == UserOrOwnerClass)
|
||||||
|
{
|
||||||
|
if (!GetTokenInformation(Token, TokenUser, UserInfo, sizeof UserInfoBuf, &Size))
|
||||||
|
{
|
||||||
|
if (ERROR_INSUFFICIENT_BUFFER != GetLastError())
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
UserInfo = MemAlloc(Size);
|
||||||
|
if (0 == UserInfo)
|
||||||
|
{
|
||||||
|
Result = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GetTokenInformation(Token, TokenUser, UserInfo, Size, &Size))
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Result = FspPosixMapSidToUid(UserInfo->User.Sid, &Uid);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
else if (0 != PUid && TokenOwner == UserOrOwnerClass)
|
||||||
|
{
|
||||||
|
if (!GetTokenInformation(Token, TokenOwner, OwnerInfo, sizeof OwnerInfoBuf, &Size))
|
||||||
|
{
|
||||||
|
if (ERROR_INSUFFICIENT_BUFFER != GetLastError())
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
OwnerInfo = MemAlloc(Size);
|
||||||
|
if (0 == OwnerInfo)
|
||||||
|
{
|
||||||
|
Result = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GetTokenInformation(Token, TokenOwner, OwnerInfo, Size, &Size))
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Result = FspPosixMapSidToUid(OwnerInfo->Owner, &Uid);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != PGid)
|
||||||
|
{
|
||||||
|
if (!GetTokenInformation(Token, TokenPrimaryGroup, GroupInfo, sizeof GroupInfoBuf, &Size))
|
||||||
|
{
|
||||||
|
if (ERROR_INSUFFICIENT_BUFFER != GetLastError())
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
GroupInfo = MemAlloc(Size);
|
||||||
|
if (0 == GroupInfo)
|
||||||
|
{
|
||||||
|
Result = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GetTokenInformation(Token, TokenPrimaryGroup, GroupInfo, Size, &Size))
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Result = FspPosixMapSidToUid(GroupInfo->PrimaryGroup, &Gid);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != PUid)
|
||||||
|
*PUid = Uid;
|
||||||
|
|
||||||
|
if (0 != PGid)
|
||||||
|
*PGid = Gid;
|
||||||
|
|
||||||
|
Result = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if (UserInfo != &UserInfoBuf.V)
|
||||||
|
MemFree(UserInfo);
|
||||||
|
|
||||||
|
if (OwnerInfo != &OwnerInfoBuf.V)
|
||||||
|
MemFree(OwnerInfo);
|
||||||
|
|
||||||
|
if (GroupInfo != &GroupInfoBuf.V)
|
||||||
|
MemFree(GroupInfo);
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
@@ -78,6 +78,11 @@ NTSTATUS fsp_fuse_op_leave(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
|
|
||||||
extern FSP_FILE_SYSTEM_INTERFACE fsp_fuse_intf;
|
extern FSP_FILE_SYSTEM_INTERFACE fsp_fuse_intf;
|
||||||
|
|
||||||
|
NTSTATUS fsp_fuse_get_token_uidgid(
|
||||||
|
HANDLE Token,
|
||||||
|
TOKEN_INFORMATION_CLASS UserOrOwnerClass, /* TokenUser|TokenOwner */
|
||||||
|
PUINT32 PUid, PUINT32 PGid);
|
||||||
|
|
||||||
/* NFS reparse points */
|
/* NFS reparse points */
|
||||||
|
|
||||||
#define NFS_SPECFILE_FIFO 0x000000004F464946
|
#define NFS_SPECFILE_FIFO 0x000000004F464946
|
||||||
|
Reference in New Issue
Block a user