Ejemplo n.º 1
0
CKeyTransformBCrypt::CKeyTransformBCrypt()
{
	if(m_bEnableBCrypt == FALSE) { m_hLib = NULL; return; }

	// BCrypt.dll is only supported on >= Vista
	if(AU_IsAtLeastWinVistaSystem() == FALSE) { m_hLib = NULL; return; }

	m_hLib = AU_LoadLibrary(BCRYPT_DLLNAME);
	if(m_hLib == NULL) return;

	m_lpBCryptOpenAlgorithmProvider = (LPBCRYPTOPENALGORITHMPROVIDER)
		GetProcAddress(m_hLib, BCFN_OAP);
	m_lpBCryptCloseAlgorithmProvider = (LPBCRYPTCLOSEALGORITHMPROVIDER)
		GetProcAddress(m_hLib, BCFN_CAP);
	m_lpBCryptGetProperty = (LPBCRYPTGETPROPERTY)GetProcAddress(m_hLib, BCFN_GP);
	m_lpBCryptSetProperty = (LPBCRYPTSETPROPERTY)GetProcAddress(m_hLib, BCFN_SP);
	m_lpBCryptGenerateSymmetricKey = (LPBCRYPTGENERATESYMMETRICKEY)
		GetProcAddress(m_hLib, BCFN_GSK);
	m_lpBCryptImportKey = (LPBCRYPTIMPORTKEY)GetProcAddress(m_hLib, BCFN_IK);
	m_lpBCryptDestroyKey = (LPBCRYPTDESTROYKEY)GetProcAddress(m_hLib, BCFN_DK);
	m_lpBCryptEncrypt = (LPBCRYPTENCRYPT)GetProcAddress(m_hLib, BCFN_E);

	if((m_lpBCryptOpenAlgorithmProvider == NULL) || (m_lpBCryptCloseAlgorithmProvider == NULL) ||
		(m_lpBCryptGetProperty == NULL) || (m_lpBCryptSetProperty == NULL) ||
		(m_lpBCryptGenerateSymmetricKey == NULL) || (m_lpBCryptImportKey == NULL) ||
		(m_lpBCryptDestroyKey == NULL) || (m_lpBCryptEncrypt == NULL))
	{
		ASSERT(FALSE);
		this->_FreeLib();
	}
}
Ejemplo n.º 2
0
HANDLE CPwSafeApp::CreateGlobalMutex()
{
	std::basic_string<TCHAR> strName = _T("Global\\");
	strName += MTXNAME_GLOBAL;

	HMODULE hInst = AU_LoadLibrary(_T("AdvApi32.dll"));
	if(hInst == NULL) { ASSERT(FALSE); return NULL; }

	LPINITIALIZESECURITYDESCRIPTOR lpInit = (LPINITIALIZESECURITYDESCRIPTOR)
		::GetProcAddress(hInst, "InitializeSecurityDescriptor");
	LPSETSECURITYDESCRIPTORDACL lpSet = (LPSETSECURITYDESCRIPTORDACL)
		::GetProcAddress(hInst, "SetSecurityDescriptorDacl");
	if((lpInit == NULL) || (lpSet == NULL))
	{
		::FreeLibrary(hInst);
		return NULL;
	}

	SECURITY_DESCRIPTOR sd;
	ZeroMemory(&sd, sizeof(SECURITY_DESCRIPTOR));
	VERIFY(lpInit(&sd, SECURITY_DESCRIPTOR_REVISION));
	VERIFY(lpSet(&sd, TRUE, NULL, FALSE));

	SECURITY_ATTRIBUTES sa;
	ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
	sa.nLength = sizeof(SECURITY_ATTRIBUTES);
	sa.lpSecurityDescriptor = &sd;
	sa.bInheritHandle = FALSE;

	HANDLE hMutex = ::CreateMutex(&sa, FALSE, strName.c_str());

	::FreeLibrary(hInst);
	return hMutex;
}
Ejemplo n.º 3
0
void CPwSafeApp::NotifyAssocChanged()
{
	HINSTANCE hShell32 = AU_LoadLibrary(_T("Shell32.dll"));
	if(hShell32 != NULL)
	{
		LPSHCHANGENOTIFY lpSHChangeNotify = (LPSHCHANGENOTIFY)GetProcAddress(
			hShell32, "SHChangeNotify");

		if(lpSHChangeNotify != NULL)
			lpSHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
		else { ASSERT(FALSE); }

		FreeLibrary(hShell32);
	}
	else { ASSERT(FALSE); }
}
Ejemplo n.º 4
0
BOOL CSessionNotify::Register(HWND hWnd)
{
	ASSERT(m_hWTSAPI == NULL); Unregister();

	m_hWTSAPI = AU_LoadLibrary(_T("Wtsapi32.dll"));
	if(m_hWTSAPI == NULL) return TRUE; // We're running on Win9x/Win2000?

	m_hTarget = hWnd;

	m_lpWTSRegisterSessionNotification = (LPWTSREGISTERSESSIONNOTIFICATION)GetProcAddress(m_hWTSAPI,
		"WTSRegisterSessionNotification");
	m_lpWTSUnRegisterSessionNotification = (LPWTSUNREGISTERSESSIONNOTIFICATION)GetProcAddress(m_hWTSAPI,
		"WTSUnRegisterSessionNotification");

	if(m_lpWTSRegisterSessionNotification != NULL)
		return m_lpWTSRegisterSessionNotification(hWnd, 0); // 0 = NOTIFY_FOR_THIS_SESSION

	return TRUE;
}