Skip to content

Commit 194121a

Browse files
author
Paul Gofman
committed
server: Handle owner rights (S-1-3-4) SID in ACE.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49334 CW-Bug-Id: #23154
1 parent 6b88b8c commit 194121a

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

dlls/advapi32/tests/security.c

+65
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,9 @@ static void test_lookupPrivilegeValue(void)
786786
}
787787
}
788788

789+
static TOKEN_OWNER *get_alloc_token_owner( HANDLE token );
790+
static TOKEN_PRIMARY_GROUP *get_alloc_token_primary_group( HANDLE token );
791+
789792
static void test_FileSecurity(void)
790793
{
791794
char wintmpdir [MAX_PATH];
@@ -800,6 +803,16 @@ static void test_FileSecurity(void)
800803
const SECURITY_INFORMATION request = OWNER_SECURITY_INFORMATION
801804
| GROUP_SECURITY_INFORMATION
802805
| DACL_SECURITY_INFORMATION;
806+
TOKEN_OWNER *owner;
807+
PSID owner_sid;
808+
BOOL defaulted, present;
809+
TOKEN_PRIMARY_GROUP *group;
810+
SECURITY_ATTRIBUTES sa;
811+
PACL dacl;
812+
ACL_SIZE_INFORMATION acl_size;
813+
ACCESS_ALLOWED_ACE *ace;
814+
static SID owner_rights_sid = { SID_REVISION, 1, { SECURITY_CREATOR_SID_AUTHORITY }, { SECURITY_CREATOR_OWNER_RIGHTS_RID } };
815+
const WCHAR sd_onwer_rights_str[] = L"D:(A;;FA;;;S-1-3-4)";
803816

804817
if (!pSetFileSecurityA) {
805818
win_skip ("SetFileSecurity is not available\n");
@@ -902,6 +915,58 @@ static void test_FileSecurity(void)
902915
ok (GetLastError() == ERROR_FILE_NOT_FOUND,
903916
"last error ERROR_FILE_NOT_FOUND expected, got %ld\n", GetLastError());
904917

918+
sa.nLength = sizeof(sa);
919+
sa.bInheritHandle = FALSE;
920+
rc = ConvertStringSecurityDescriptorToSecurityDescriptorW(sd_onwer_rights_str, SDDL_REVISION_1, &sa.lpSecurityDescriptor, NULL);
921+
ok(rc, "got error %lu.\n", GetLastError());
922+
923+
DeleteFileA(file);
924+
fh = CreateFileA(file, GENERIC_READ, 0, &sa, CREATE_ALWAYS, 0, NULL);
925+
ok (fh != INVALID_HANDLE_VALUE, "error %lu\n", GetLastError());
926+
LocalFree(sa.lpSecurityDescriptor);
927+
928+
rc = GetFileSecurityA (file, OWNER_SECURITY_INFORMATION, NULL, 0, &retSize);
929+
ok (!rc && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %ld, error %lu.\n", rc, GetLastError());
930+
sd = HeapAlloc (GetProcessHeap (), 0, sdSize);
931+
rc = GetFileSecurityA (file, OWNER_SECURITY_INFORMATION, sd, retSize, &retSize);
932+
ok(rc, "got error %lu.\n", GetLastError());
933+
rc = GetSecurityDescriptorOwner(sd, &owner_sid, &defaulted);
934+
ok(rc, "got error %lu.\n", GetLastError());
935+
ok(!defaulted, "got %d.\n", defaulted);
936+
owner = get_alloc_token_owner(GetCurrentProcessToken());
937+
todo_wine ok(EqualSid(owner_sid, owner->Owner), "Owner SIDs are not equal %s != %s\n", debugstr_sid(owner_sid), debugstr_sid(owner->Owner));
938+
HeapFree (GetProcessHeap (), 0, owner);
939+
HeapFree (GetProcessHeap (), 0, sd);
940+
941+
group = get_alloc_token_primary_group(GetCurrentProcessToken());
942+
test_group_equal(fh, group->PrimaryGroup, __LINE__);
943+
HeapFree (GetProcessHeap (), 0, group);
944+
945+
CloseHandle(fh);
946+
947+
fh = CreateFileA(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
948+
ok (fh != INVALID_HANDLE_VALUE, "error %lu\n", GetLastError());
949+
if (fh != INVALID_HANDLE_VALUE)
950+
{
951+
rc = GetFileSecurityA (file, DACL_SECURITY_INFORMATION, NULL, 0, &retSize);
952+
ok (!rc && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %ld, error %lu.\n", rc, GetLastError());
953+
sd = HeapAlloc (GetProcessHeap (), 0, sdSize);
954+
rc = GetFileSecurityA (file, DACL_SECURITY_INFORMATION, sd, retSize, &retSize);
955+
ok(rc, "got error %lu.\n", GetLastError());
956+
rc = GetSecurityDescriptorDacl(sd, &present, &dacl, &defaulted);
957+
ok(rc, "got error %lu.\n", GetLastError());
958+
ok(present, "got %d.\n", present);
959+
ok(!defaulted, "got %d.\n", defaulted);
960+
rc = GetAclInformation(dacl, &acl_size, sizeof(acl_size), AclSizeInformation);
961+
ok(rc, "got error %lu.\n", GetLastError());
962+
ok(acl_size.AceCount == 1, "got %lu.\n", acl_size.AceCount);
963+
rc = GetAce(dacl, 0, (VOID **)&ace);
964+
ok(rc, "got error %lu.\n", GetLastError());
965+
ok(EqualSid(&ace->SidStart, &owner_rights_sid), "Owner SIDs are not equal %s != %s\n", debugstr_sid(&ace->SidStart), debugstr_sid(&owner_rights_sid));
966+
CloseHandle(fh);
967+
HeapFree (GetProcessHeap (), 0, sd);
968+
}
969+
905970
cleanup:
906971
/* Remove temporary file and directory */
907972
DeleteFileA(file);

server/file.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ mode_t sd_to_mode( const struct security_descriptor *sd, const struct sid *owner
620620
{
621621
bits_to_set &= ~((mode << 6) | (mode << 3)); /* user + group */
622622
}
623-
else if (equal_sid( sid, owner ))
623+
else if (equal_sid( sid, owner ) || equal_sid( sid, &owner_rights_sid ))
624624
{
625625
bits_to_set &= ~(mode << 6); /* user only */
626626
}
@@ -639,7 +639,7 @@ mode_t sd_to_mode( const struct security_descriptor *sd, const struct sid *owner
639639
new_mode |= mode & bits_to_set;
640640
bits_to_set &= ~mode;
641641
}
642-
else if (equal_sid( sid, owner ))
642+
else if (equal_sid( sid, owner ) || equal_sid( sid, &owner_rights_sid ))
643643
{
644644
mode = (mode << 6); /* user only */
645645
new_mode |= mode & bits_to_set;

server/security.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern const struct luid SeManageVolumePrivilege;
4444
extern const struct luid SeImpersonatePrivilege;
4545
extern const struct luid SeCreateGlobalPrivilege;
4646

47+
extern const struct sid owner_rights_sid;
4748
extern const struct sid world_sid;
4849
extern struct sid local_user_sid;
4950
extern const struct sid local_system_sid;

server/token.c

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct sid_attrs
7474
unsigned int attrs;
7575
};
7676

77+
const struct sid owner_rights_sid = { SID_REVISION, 1, SECURITY_CREATOR_SID_AUTHORITY, { SECURITY_CREATOR_OWNER_RIGHTS_RID } };
7778
const struct sid world_sid = { SID_REVISION, 1, SECURITY_WORLD_SID_AUTHORITY, { SECURITY_WORLD_RID } };
7879
const struct sid local_system_sid = { SID_REVISION, 1, SECURITY_NT_AUTHORITY, { SECURITY_LOCAL_SYSTEM_RID } };
7980
const struct sid high_label_sid = { SID_REVISION, 1, SECURITY_MANDATORY_LABEL_AUTHORITY, { SECURITY_MANDATORY_HIGH_RID } };

0 commit comments

Comments
 (0)