本文整理匯總了C++中EqualSid函數的典型用法代碼示例。如果您正苦於以下問題:C++ EqualSid函數的具體用法?C++ EqualSid怎麽用?C++ EqualSid使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了EqualSid函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: QueueHashLookup
VOID * QueueHashLookup(Queue *pQueue, PSID Sid, BOOL EnterCritSec) {
VOID * pValue;
QueueNode *pNextNode;
ASSERT(pQueue != NULL);
if (pQueue->lpCriticalSection != NULL && EnterCritSec) EnterCriticalSection(pQueue->lpCriticalSection);
#ifdef DEBUG2
DbgMsgRecord(TEXT("-> QueueHashLookup\n"));
#endif
pValue = NULL;
for (QueueNode *pNode = pQueue->pFirst; pNode != NULL; pNode = pNextNode) {
pNextNode = pNode->pNext;
if (EqualSid(((QueueHashNode *)(pNode->pData))->pKey, Sid) == TRUE) {
pValue = ((QueueHashNode *)(pNode->pData))->pValue;
break;
}
}
#ifdef DEBUG2
DbgMsgRecord(TEXT("<- QueueHashLookup\n"));
#endif
if (pQueue->lpCriticalSection != NULL && EnterCritSec) LeaveCriticalSection(pQueue->lpCriticalSection);
return pValue;
}
示例2: is_root
int
is_root( void )
{
int root = 0;
#if 1
PSID psid = my_user_Sid();
if( ! psid ) {
dprintf( D_ALWAYS,
"ERROR in is_root(): my_user_Sid() returned NULL\n" );
return 0;
}
root = EqualSid(psid, const_cast<SID*>(&sids.LocalSystem));
free (psid);
#else
char* user = my_username( 0 );
if( ! user ) {
dprintf( D_ALWAYS,
"ERROR in is_root(): my_username() returned NULL\n" );
return 0;
}
if( !strcasecmp(user, "SYSTEM") ) {
root = 1;
}
free( user );
#endif
return root;
}
示例3: IsNTAdmin
/***********************************************************************
* IsNTAdmin (ADVPACK.@)
*
* Checks if the user has admin privileges.
*
* PARAMS
* reserved [I] Reserved. Must be 0.
* pReserved [I] Reserved. Must be NULL.
*
* RETURNS
* TRUE if user has admin rights, FALSE otherwise.
*/
BOOL WINAPI IsNTAdmin(DWORD reserved, LPDWORD pReserved)
{
SID_IDENTIFIER_AUTHORITY SidAuthority = {SECURITY_NT_AUTHORITY};
PTOKEN_GROUPS pTokenGroups;
BOOL bSidFound = FALSE;
DWORD dwSize, i;
HANDLE hToken;
PSID pSid;
TRACE("(%d, %p)\n", reserved, pReserved);
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
return FALSE;
if (!GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize))
{
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
CloseHandle(hToken);
return FALSE;
}
}
pTokenGroups = HeapAlloc(GetProcessHeap(), 0, dwSize);
if (!pTokenGroups)
{
CloseHandle(hToken);
return FALSE;
}
if (!GetTokenInformation(hToken, TokenGroups, pTokenGroups, dwSize, &dwSize))
{
HeapFree(GetProcessHeap(), 0, pTokenGroups);
CloseHandle(hToken);
return FALSE;
}
CloseHandle(hToken);
if (!AllocateAndInitializeSid(&SidAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &pSid))
{
HeapFree(GetProcessHeap(), 0, pTokenGroups);
return FALSE;
}
for (i = 0; i < pTokenGroups->GroupCount; i++)
{
if (EqualSid(pSid, pTokenGroups->Groups[i].Sid))
{
bSidFound = TRUE;
break;
}
}
HeapFree(GetProcessHeap(), 0, pTokenGroups);
FreeSid(pSid);
return bSidFound;
}
示例4: iwin32_uid_compare
static int
iwin32_uid_compare (user_id_t a, user_id_t b)
{
assert (a.value != NULL);
assert (b.value != NULL);
return EqualSid (a.value, b.value);
}
示例5: iwin32_gid_compare
static int
iwin32_gid_compare (group_id_t a, group_id_t b)
{
assert (a.value != NULL);
assert (b.value != NULL);
return EqualSid (a.value, b.value);
}
示例6: JUserIsAdmin
JBoolean
JUserIsAdmin()
{
HANDLE tokenHandle;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &tokenHandle))
{
return kJFalse;
}
DWORD returnLength;
GetTokenInformation(tokenHandle, TokenGroups, NULL, 0, &returnLength);
if (returnLength > 65535)
{
CloseHandle(tokenHandle);
return kJFalse;
}
TOKEN_GROUPS* groupList = (TOKEN_GROUPS*) malloc(returnLength);
if (groupList == NULL)
{
CloseHandle(tokenHandle);
return kJFalse;
}
if (!GetTokenInformation(tokenHandle, TokenGroups,
groupList, returnLength, &returnLength))
{
CloseHandle(tokenHandle);
free(groupList);
return kJFalse;
}
CloseHandle(tokenHandle);
SID_IDENTIFIER_AUTHORITY siaNtAuth = SECURITY_NT_AUTHORITY;
PSID adminSid;
if (!AllocateAndInitializeSid(&siaNtAuth, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
&adminSid))
{
free(groupList);
return kJFalse;
}
JBoolean found = kJFalse;
for (DWORD i = 0; i < groupList->GroupCount; i++)
{
if (EqualSid(adminSid, groupList->Groups[i].Sid))
{
found = kJTrue;
break;
}
}
FreeSid(adminSid);
free(groupList);
return found;
}
示例7: return
BOOL uac::Am_I_In_Admin_Group(BOOL bCheckAdminMode /*= FALSE*/)
{
BOOL fAdmin;
HANDLE hThread;
TOKEN_GROUPS *ptg = NULL;
DWORD cbTokenGroups;
DWORD dwGroup;
PSID psidAdmin;
SID_IDENTIFIER_AUTHORITY SystemSidAuthority = SECURITY_NT_AUTHORITY;
if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &hThread))
{
if (GetLastError() == ERROR_NO_TOKEN)
{
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY,
&hThread))
return (FALSE);
}
else
return (FALSE);
}
if (GetTokenInformation(hThread, TokenGroups, NULL, 0, &cbTokenGroups))
return (FALSE);
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
return (FALSE);
if (!(ptg = (TOKEN_GROUPS*)_alloca(cbTokenGroups)))
return (FALSE);
if (!GetTokenInformation(hThread, TokenGroups, ptg, cbTokenGroups,
&cbTokenGroups))
return (FALSE);
if (!AllocateAndInitializeSid(&SystemSidAuthority, 2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0, &psidAdmin))
return (FALSE);
fAdmin = FALSE;
for (dwGroup = 0; dwGroup < ptg->GroupCount; dwGroup++)
{
if (EqualSid(ptg->Groups[dwGroup].Sid, psidAdmin))
{
if (bCheckAdminMode)
{
if ((ptg->Groups[dwGroup].Attributes) & SE_GROUP_ENABLED)
{
fAdmin = TRUE;
}
}
else
{
fAdmin = TRUE;
}
break;
}
}
FreeSid(psidAdmin);
return (fAdmin);
}
示例8: open
/*-----------------------------------------------------------------------------
Kill any Dr. Watson windows that are open (we already killed the browser process)
-----------------------------------------------------------------------------*/
void CurlBlastDlg::KillProcs(void)
{
#ifndef _DEBUG
WTS_PROCESS_INFO * proc = NULL;
DWORD count = 0;
if( WTSEnumerateProcesses(WTS_CURRENT_SERVER_HANDLE, 0, 1, &proc, &count) )
{
for( DWORD i = 0; i < count; i++ )
{
bool terminate = false;
// check for Dr. Watson
if( !lstrcmpi(PathFindFileName(proc[i].pProcessName), _T("dwwin.exe")) )
{
if( !bDrWatson )
{
log.LogEvent(event_KilledDrWatson);
bDrWatson = true;
}
terminate = true;
}
else if(lstrcmpi(PathFindFileName(proc[i].pProcessName), _T("iexplore.exe")))
{
if (worker) {
EnterCriticalSection( &(worker->cs) );
// make sure it's not the browser we launched
if( proc[i].ProcessId != worker->browserPID
&& worker->userSID && proc[i].pUserSid
&& IsValidSid(worker->userSID) && IsValidSid(proc[i].pUserSid) )
{
// see if the SID matches
if( EqualSid(proc[i].pUserSid, worker->userSID ) )
terminate = true;
}
LeaveCriticalSection( &(worker->cs) );
}
}
if( terminate )
{
HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, proc[i].ProcessId);
if( hProc )
{
TerminateProcess(hProc, 0);
CloseHandle(hProc);
}
}
}
WTSFreeMemory(proc);
}
#endif
}
示例9: APR_DECLARE
APR_DECLARE(apr_status_t) apr_uid_compare(apr_uid_t left, apr_uid_t right)
{
if (!left || !right)
return APR_EINVAL;
#ifndef _WIN32_WCE
if (!IsValidSid(left) || !IsValidSid(right))
return APR_EINVAL;
if (!EqualSid(left, right))
return APR_EMISMATCH;
#endif
return APR_SUCCESS;
}
示例10: IsLocalSid
BOOL IsLocalSid( PSID ps )
{
static PSID pComparisonSid = NULL;
if ( pComparisonSid == NULL )
{
// build "BUILTIN\LOCAL" SID for comparison: S-1-2-0
SID_IDENTIFIER_AUTHORITY sia = SECURITY_LOCAL_SID_AUTHORITY;
AllocateAndInitializeSid( &sia, 1, 0, 0, 0, 0, 0, 0, 0, 0, &pComparisonSid );
}
return EqualSid( ps, pComparisonSid );
}
示例11: GetNameFromSIDCache
const wchar_t* GetNameFromSIDCache(PSID Sid)
{
LPCWSTR Result=nullptr;
for(SIDCacheItem** i=SIDCache.First();i;i=SIDCache.Next(i))
{
if (EqualSid((*i)->Sid,Sid))
{
Result=(*i)->strUserName;
break;
}
}
return Result;
}
示例12: IsInteractiveSid
BOOL IsInteractiveSid( PSID ps )
{
static PSID pComparisonSid = NULL;
if ( pComparisonSid == NULL )
{
// build "BUILTIN\LOCAL" SID for comparison: S-1-5-4
SID_IDENTIFIER_AUTHORITY sia = SECURITY_NT_AUTHORITY; // "-5-"
AllocateAndInitializeSid( &sia, 1, 4, 0, 0, 0, 0, 0, 0, 0, &pComparisonSid );
}
return EqualSid( ps, pComparisonSid );
}
示例13: tr
QString DiagnosticsDialog::getUserRights() const
{
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup = NULL;
HANDLE hToken = NULL;
DWORD dwIndex, dwLength = 0;
PTOKEN_GROUPS pGroup = NULL;
QString rights = tr( "User" );
if ( !OpenThreadToken( GetCurrentThread(), TOKEN_QUERY, TRUE, &hToken ) )
{
if ( GetLastError() != ERROR_NO_TOKEN )
return tr( "Unknown - error %1" ).arg( GetLastError() );
if ( !OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &hToken ) )
return tr( "Unknown - error %1" ).arg( GetLastError() );
}
if ( !GetTokenInformation( hToken, TokenGroups, NULL, dwLength, &dwLength ) )
{
if( GetLastError() != ERROR_INSUFFICIENT_BUFFER )
return tr( "Unknown - error %1" ).arg( GetLastError() );
}
pGroup = (PTOKEN_GROUPS)GlobalAlloc( GPTR, dwLength );
if ( !GetTokenInformation( hToken, TokenGroups, pGroup, dwLength, &dwLength ) )
{
if ( pGroup )
GlobalFree( pGroup );
return tr( "Unknown - error %1" ).arg( GetLastError() );;
}
if( AllocateAndInitializeSid( &NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0, &AdministratorsGroup ) )
{
for ( dwIndex = 0; dwIndex < pGroup->GroupCount; dwIndex++ )
{
if ( EqualSid( AdministratorsGroup, pGroup->Groups[dwIndex].Sid ) )
{
rights = tr( "Administrator" );
break;
}
}
}
if ( AdministratorsGroup )
FreeSid( AdministratorsGroup );
if ( pGroup )
GlobalFree( pGroup );
return rights;
}
示例14: CachedGetUserFromSid
VOID
WINAPI
CachedGetUserFromSid(
PSID pSid,
LPWSTR pUserName,
PULONG pcwcUserName)
{
PLIST_ENTRY pCur;
PSIDTOUSERNAME pEntry;
ULONG cbSid, cwcUserName;
cwcUserName = *pcwcUserName;
/* Walk through the list */
for(pCur = SidToUserNameHead.Flink;
pCur != &SidToUserNameHead;
pCur = pCur->Flink)
{
pEntry = CONTAINING_RECORD(pCur, SIDTOUSERNAME, List);
if (EqualSid((PSID)&pEntry->Data, pSid))
{
wcsncpy(pUserName, pEntry->pszName, cwcUserName);
*pcwcUserName = cwcUserName;
return;
}
}
/* We didn't find the SID in the list, get the name conventional */
SidToUserName(pSid, pUserName, cwcUserName);
/* Allocate a new entry */
*pcwcUserName = wcslen(pUserName);
cwcUserName = *pcwcUserName + 1;
cbSid = GetLengthSid(pSid);
pEntry = HeapAlloc(GetProcessHeap(), 0, sizeof(SIDTOUSERNAME) + cbSid + cwcUserName * sizeof(WCHAR));
/* Copy the Sid and name to our entry */
CopySid(cbSid, (PSID)&pEntry->Data, pSid);
pEntry->pszName = (LPWSTR)(pEntry->Data + cbSid);
wcsncpy(pEntry->pszName, pUserName, cwcUserName);
/* Insert the new entry */
pEntry->List.Flink = &SidToUserNameHead;
pEntry->List.Blink = SidToUserNameHead.Blink;
SidToUserNameHead.Blink->Flink = &pEntry->List;
SidToUserNameHead.Blink = &pEntry->List;
return;
}
示例15: isAccessUserOnly
/*
* Returns JNI_TRUE if the specified owner is the only SID will access
* to the file.
*/
static jboolean isAccessUserOnly(JNIEnv* env, SID* owner, ACL* acl) {
ACL_SIZE_INFORMATION acl_size_info;
DWORD i;
/*
* If there's no DACL then there's no access to the file
*/
if (acl == NULL) {
return JNI_TRUE;
}
/*
* Get the ACE count
*/
if (!GetAclInformation(acl, (void *) &acl_size_info, sizeof(acl_size_info),
AclSizeInformation)) {
JNU_ThrowIOExceptionWithLastError(env, "GetAclInformation failed");
return JNI_FALSE;
}
/*
* Iterate over the ACEs. For each "allow" type check that the SID
* matches the owner, and check that the access is read only.
*/
for (i = 0; i < acl_size_info.AceCount; i++) {
void* ace;
ACCESS_ALLOWED_ACE *access;
SID* sid;
if (!GetAce(acl, i, &ace)) {
JNU_ThrowIOExceptionWithLastError(env, "GetAce failed");
return -1;
}
if (((ACCESS_ALLOWED_ACE *)ace)->Header.AceType != ACCESS_ALLOWED_ACE_TYPE) {
continue;
}
access = (ACCESS_ALLOWED_ACE *)ace;
sid = (SID *) &access->SidStart;
if (!EqualSid(owner, sid)) {
/*
* If the ACE allows any access then the file is not secure.
*/
if (access->Mask & ANY_ACCESS) {
return JNI_FALSE;
}
}
}
return JNI_TRUE;
}