From 9d4d1aa83356ba570a41b5e5a2e4e4416c129f38 Mon Sep 17 00:00:00 2001 From: "wtc%netscape.com" Date: Wed, 28 Jun 2000 01:13:33 +0000 Subject: [PATCH] Bugzilla bug #42874: allow OpenProcessToken to fail with ERROR_CALL_NOT_IMPLEMENTED (on non-NT systems) or ERROR_ACCESS_DENIED (processes with insufficient access permissions). git-svn-id: svn://10.0.0.236/trunk@73365 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/nsprpub/pr/src/md/windows/ntsec.c | 37 ++++++++++++++--------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/mozilla/nsprpub/pr/src/md/windows/ntsec.c b/mozilla/nsprpub/pr/src/md/windows/ntsec.c index 0cced6a9f39..74c000e3752 100644 --- a/mozilla/nsprpub/pr/src/md/windows/ntsec.c +++ b/mozilla/nsprpub/pr/src/md/windows/ntsec.c @@ -75,26 +75,26 @@ void _PR_NT_InitSids(void) DWORD dwLength; BOOL rv; - /* Create a well-known SID for the Everyone group. */ - if (!AllocateAndInitializeSid(&SIDAuthWorld, 1, - SECURITY_WORLD_RID, - 0, 0, 0, 0, 0, 0, 0, - &_pr_nt_sids.everyone)) { - /* - * On non-NT systems, this function is not implemented, - * and neither are the other security functions. There - * is no point in going further. - */ - PR_ASSERT(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED); - return; - } - /* * Look up and make a copy of the owner and primary group * SIDs in the access token of the calling process. */ rv = OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken); - PR_ASSERT(rv != 0); + if (rv == 0) { + /* + * On non-NT systems, this function is not implemented + * (error code ERROR_CALL_NOT_IMPLEMENTED), and neither are + * the other security functions. There is no point in + * going further. + * + * A process with insufficient access permissions may fail + * with the error code ERROR_ACCESS_DENIED. + */ + PR_LOG(_pr_io_lm, PR_LOG_DEBUG, + ("_PR_NT_InitSids: OpenProcessToken() failed. Error: %d", + GetLastError())); + return; + } rv = GetTokenInformation(hToken, TokenOwner, infoBuffer, sizeof(infoBuffer), &dwLength); @@ -117,6 +117,13 @@ void _PR_NT_InitSids(void) rv = CloseHandle(hToken); PR_ASSERT(rv != 0); + + /* Create a well-known SID for the Everyone group. */ + rv = AllocateAndInitializeSid(&SIDAuthWorld, 1, + SECURITY_WORLD_RID, + 0, 0, 0, 0, 0, 0, 0, + &_pr_nt_sids.everyone); + PR_ASSERT(rv != 0); } /*