From 67d6d366161c04ec32f2b429a2441016dfd91f2a Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 17 Feb 2022 08:37:10 +0000 Subject: win32: fake file ownership on FAT filesystems busybox-w32 tries to display the ownership of files by comparing the security identifier (SID) of the current user with that of the file on disk. For filesystems that don't support SIDs this resulted in files being listed as owned by root. It appears that filesystems without support for file ownership return a null SID. In such cases pretend the file belongs to the current user. GitHub issue #241. --- win32/mingw.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index 06da37040..f34ea1102 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -488,9 +488,14 @@ static uid_t file_owner(HANDLE fh) uid_t uid = 0; DWORD *ptr; unsigned char prefix[] = { - 0x01, 0x05, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x05, - 0x15, 0x00, 0x00, 0x00 + 0x01, 0x05, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x05, + 0x15, 0x00, 0x00, 0x00 + }; + unsigned char nullsid[] = { + 0x01, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00 }; /* get SID of current user */ @@ -520,8 +525,9 @@ static uid_t file_owner(HANDLE fh) if (EqualSid(pSidOwner, user->User.Sid)) { uid = DEFAULT_UID; - } - else if (memcmp(pSidOwner, prefix, sizeof(prefix)) == 0) { + } else if (memcmp(pSidOwner, nullsid, sizeof(nullsid)) == 0) { + uid = DEFAULT_UID; + } else if (memcmp(pSidOwner, prefix, sizeof(prefix)) == 0) { /* for local or domain users use the RID as uid */ ptr = (DWORD *)pSidOwner; if (ptr[6] >= 500 && ptr[6] < DEFAULT_UID) -- cgit v1.2.3-55-g6feb