Skip to content

Commit

Permalink
fixes #667 win_sec_attributes fails on Windows x64
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack R. Dunaway committed Apr 25, 2016
1 parent aae3975 commit 8422f52
Showing 1 changed file with 29 additions and 37 deletions.
66 changes: 29 additions & 37 deletions tests/win_sec_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,26 @@ int main ()
PACL pACL;
DWORD ret2;
int ret3;
void * void_ret_value = NULL;
size_t void_ret_size = sizeof(void_ret_value);
void *void_ret_value = NULL;
size_t void_ret_size = sizeof (void_ret_value);
HANDLE pipeHandle = NULL;
PSID pSidOwner = NULL;
PSECURITY_DESCRIPTOR pSD = NULL;

BOOL equal = FALSE;
BOOL bret = FALSE;
ACL* dacl = NULL;
PACL dacl = NULL;
PACE_HEADER ace = NULL;
PACCESS_ALLOWED_ACE allowed_ace = NULL;
PSID the_sid = NULL;
SECURITY_DESCRIPTOR* sd = NULL;
PSECURITY_DESCRIPTOR sd = NULL;

sc = test_socket (AF_SP, NN_PAIR);
test_connect (sc, SOCKET_ADDRESS);

sb = test_socket (AF_SP, NN_PAIR);

memset (&sec, 0, sizeof(sec));
sec.lpSecurityDescriptor = (PSECURITY_DESCRIPTOR)malloc (SECURITY_DESCRIPTOR_MIN_LENGTH);
memset (&sec, 0, sizeof (sec));
sec.lpSecurityDescriptor = malloc (SECURITY_DESCRIPTOR_MIN_LENGTH);
ret = InitializeSecurityDescriptor (sec.lpSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION);
nn_assert (ret);

Expand All @@ -90,10 +89,10 @@ int main ()
ret = SetSecurityDescriptorDacl (sec.lpSecurityDescriptor, TRUE, pACL, FALSE);
nn_assert (ret);

sec.nLength = sizeof(sec);
sec.nLength = sizeof (sec);
sec.bInheritHandle = TRUE;

ret3 = nn_setsockopt (sb, NN_IPC, NN_IPC_SEC_ATTR, (void*)&sec, sizeof(sec));
ret3 = nn_setsockopt (sb, NN_IPC, NN_IPC_SEC_ATTR, &sec, sizeof (sec));
nn_assert (ret3 == 0);
test_bind (sb, SOCKET_ADDRESS);

Expand All @@ -102,44 +101,37 @@ int main ()
test_send (sc, "0123456789012345678901234567890123456789");
test_recv (sb, "0123456789012345678901234567890123456789");

ret3 = nn_getsockopt(sb, NN_IPC, NN_IPC_SEC_ATTR, &void_ret_value, &void_ret_size);
nn_assert(ret3 == 0);
nn_assert(void_ret_value == &sec);

ret3 = nn_getsockopt (sb, NN_IPC, NN_IPC_SEC_ATTR, &void_ret_value, &void_ret_size);
nn_assert (ret3 == 0);
nn_assert (void_ret_value == &sec);

// verify that the pipe has the same security descriptor that we set by comparing the ace of the kernel object
// to the one we created it with
pipeHandle = CreateFileA(
"\\\\.\\\\pipe\\" PIPE_NAME,
READ_CONTROL,
0,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL
);

nn_assert(pipeHandle != INVALID_HANDLE_VALUE);
/* Verify that the pipe has the same security descriptor that we set by
comparing the ace of the kernel object to the one we created it with. */
pipeHandle = CreateFileA ("\\\\.\\\\pipe\\" PIPE_NAME, READ_CONTROL, 0, NULL,
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);

nn_assert (pipeHandle != INVALID_HANDLE_VALUE);

ret2 = GetSecurityInfo(pipeHandle, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, &dacl, NULL, &sd);
ret2 = GetSecurityInfo (pipeHandle, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION,
NULL, NULL, &dacl, NULL, &sd);

nn_assert(ret2 == ERROR_SUCCESS);
nn_assert(1 == dacl->AceCount);
nn_assert (ret2 == ERROR_SUCCESS);
nn_assert (1 == dacl->AceCount);

bret = GetAce(dacl, 0, &ace);
bret = GetAce (dacl, 0, &ace);

nn_assert(bret == TRUE);
nn_assert(ace->AceType == ACCESS_ALLOWED_ACE_TYPE);
nn_assert (bret == TRUE);
nn_assert (ace->AceType == ACCESS_ALLOWED_ACE_TYPE);

allowed_ace = (PACCESS_ALLOWED_ACE)ace;
the_sid = (PSID)&(allowed_ace->SidStart);
allowed_ace = (PACCESS_ALLOWED_ACE) ace;
the_sid = (PSID) &(allowed_ace->SidStart);

nn_assert(IsValidSid(the_sid));
nn_assert (IsValidSid (the_sid));

equal = EqualSid((PSID)&(allowed_ace->SidStart), &SIDAuthUsers);
nn_assert(equal);
LocalFree(dacl);
equal = EqualSid ((PSID) &(allowed_ace->SidStart), &SIDAuthUsers);
nn_assert (equal);
LocalFree (sd);

test_close (sc);
test_close (sb);
Expand Down

0 comments on commit 8422f52

Please sign in to comment.