View Single Post

Old 09-27-2008, 02:49 PM   #8 (permalink)
ZoiD
Senior Member
Gold Member
Moderator

Advocate
 
Join Date: Sep 2005
Location: 0xC0DEDBAD
Posts: 161
ZoiD has a spectacular aura about
Send a message via ICQ to ZoiD Send a message via AIM to ZoiD Send a message via MSN to ZoiD
Default

Dyndrilliac you have to close hToken even if return value is 'true' since the handle was opened inside that function.

Not being snide ;p My code shared same issue.
Code:
BOOL EnableDebugPrivledges( void )
{
	HANDLE	hToken;
	LUID	Luid;
	TOKEN_PRIVILEGES tpToken;
	BOOL bRet = FALSE;

	// enable the SeDebugPrivilege
	if( 0 != OpenProcessToken( GetCurrentProcess( ) ,TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ) && 
		0 != LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &Luid ) )
	{
		tpToken.PrivilegeCount			= 1;
		tpToken.Privileges[ 0 ].Luid		= Luid;
		tpToken.Privileges[ 0 ].Attributes	= SE_PRIVILEGE_ENABLED;
		bRet = 0 != AdjustTokenPrivileges( hToken, FALSE, &tpToken, NULL, NULL, NULL );

		CloseHandle( hToken );
	}

	return bRet;
}
In my ver, If LookupPrivilegeValue fails it will just jmp over and not close the handle.
__________________
Quote:
Destiny; A tyrant’s authority for crime and fool’s excuse for failure.
Quote:
...man had been created with a hole in his heart, a hole that no power, riches, or knowledge could fill. And in his infinite greed, man dreamed of expanding his dominion over the entire earth.
ZoiD 15 0FF11|\|3   Reply With Quote