mirror of https://github.com/BOINC/boinc.git
118 lines
2.6 KiB
C++
118 lines
2.6 KiB
C++
|
/*++
|
||
|
|
||
|
DCOM Permission Configuration Sample
|
||
|
Copyright (c) 1996, Microsoft Corporation. All rights reserved.
|
||
|
|
||
|
Module Name:
|
||
|
|
||
|
utils.cpp
|
||
|
|
||
|
Abstract:
|
||
|
|
||
|
Miscellaneous utility functions
|
||
|
|
||
|
Author:
|
||
|
|
||
|
Michael Nelson
|
||
|
|
||
|
Environment:
|
||
|
|
||
|
Windows NT
|
||
|
|
||
|
--*/
|
||
|
|
||
|
#include "stdafx.h"
|
||
|
#include "ntsecapi.h"
|
||
|
#include "dcomperm.h"
|
||
|
|
||
|
DWORD
|
||
|
GetCurrentUserSID (
|
||
|
PSID *Sid
|
||
|
)
|
||
|
{
|
||
|
TOKEN_USER *tokenUser = NULL;
|
||
|
HANDLE tokenHandle = NULL;
|
||
|
DWORD tokenSize = 0;
|
||
|
DWORD sidLength = 0;
|
||
|
|
||
|
if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &tokenHandle))
|
||
|
{
|
||
|
GetTokenInformation (tokenHandle,
|
||
|
TokenUser,
|
||
|
tokenUser,
|
||
|
0,
|
||
|
&tokenSize);
|
||
|
|
||
|
tokenUser = (TOKEN_USER *) malloc (tokenSize);
|
||
|
|
||
|
if (GetTokenInformation (tokenHandle,
|
||
|
TokenUser,
|
||
|
tokenUser,
|
||
|
tokenSize,
|
||
|
&tokenSize))
|
||
|
{
|
||
|
sidLength = GetLengthSid (tokenUser->User.Sid);
|
||
|
*Sid = (PSID) malloc (sidLength);
|
||
|
|
||
|
memcpy (*Sid, tokenUser->User.Sid, sidLength);
|
||
|
CloseHandle (tokenHandle);
|
||
|
} else
|
||
|
{
|
||
|
free (tokenUser);
|
||
|
return GetLastError();
|
||
|
}
|
||
|
} else
|
||
|
{
|
||
|
free (tokenUser);
|
||
|
return GetLastError();
|
||
|
}
|
||
|
|
||
|
free (tokenUser);
|
||
|
return ERROR_SUCCESS;
|
||
|
}
|
||
|
|
||
|
DWORD
|
||
|
GetPrincipalSID (
|
||
|
LPTSTR Principal,
|
||
|
PSID *Sid
|
||
|
)
|
||
|
{
|
||
|
DWORD sidSize = 0;
|
||
|
TCHAR refDomain [256];
|
||
|
DWORD refDomainSize = 0;
|
||
|
DWORD returnValue = 0;
|
||
|
SID_NAME_USE snu;
|
||
|
|
||
|
sidSize = 0;
|
||
|
refDomainSize = 255;
|
||
|
|
||
|
LookupAccountName (NULL,
|
||
|
Principal,
|
||
|
*Sid,
|
||
|
&sidSize,
|
||
|
refDomain,
|
||
|
&refDomainSize,
|
||
|
&snu);
|
||
|
|
||
|
returnValue = GetLastError();
|
||
|
if (returnValue != ERROR_INSUFFICIENT_BUFFER)
|
||
|
return returnValue;
|
||
|
|
||
|
*Sid = (PSID) malloc (sidSize);
|
||
|
refDomainSize = 255;
|
||
|
|
||
|
if (!LookupAccountName (NULL,
|
||
|
Principal,
|
||
|
*Sid,
|
||
|
&sidSize,
|
||
|
refDomain,
|
||
|
&refDomainSize,
|
||
|
&snu))
|
||
|
{
|
||
|
return GetLastError();
|
||
|
}
|
||
|
|
||
|
return ERROR_SUCCESS;
|
||
|
}
|
||
|
|