Example #1
0
DWORD
Sm::Terminate()
{
	BidxScopeAutoSNI0( SNIAPI_TAG _T("\n") );

	DWORD dwError = ERROR_SUCCESS;

	if( !rgProvInfo[SM_PROV].fInitialized )
	{
		BidTraceU1( SNI_BID_TRACE_ON, RETURN_TAG _T("%d{WINERR}\n"), dwError);
		return dwError;
	}

	rgProvInfo[SM_PROV].fInitialized = FALSE; 

#ifdef SNI_BASED_CLIENT
	Sm_Shiloh::Terminate();

	// The contract is there should be no open call pending when performing termination,
	// thus there is no protection when check gdwfInstapidll.

	if ( gpInstapiStruct )
	{
		Assert ( gpInstapiStruct->hInstapidll );
		FreeLibrary (gpInstapiStruct->hInstapidll );
		delete gpInstapiStruct;
		gpInstapiStruct = NULL;
		
	}
#endif
	
	BidTraceU1( SNI_BID_TRACE_ON, RETURN_TAG _T("%d{WINERR}\n"), dwError);
	return dwError;
}
Example #2
0
HANDLE DynamicQueue::DeQueue()
{
	BidxScopeAutoSNI0( SNIAPI_TAG _T("\n") );
	
	HANDLE Key;

	Assert(m_pHead);

	Key = m_pHead->Key;

	QueueItem *tmp;
	tmp= m_pHead;
	
	m_pHead=m_pHead->pNext;

	if(!m_pHead)
	{
		m_ppTail=&m_pHead;
	}
	
	tmp->pNext = m_pFree;
	m_pFree = tmp;

	BidTraceU1( SNI_BID_TRACE_ON, RETURN_TAG _T("Key: %p\n"), Key);
	
	return Key;
}
Example #3
0
HANDLE DynamicQueue::Peek()
{
	BidxScopeAutoSNI0( SNIAPI_TAG _T("\n") );
	
	HANDLE Key;

	Assert(m_pHead);

	Key = m_pHead->Key;

	BidTraceU1( SNI_BID_TRACE_ON, RETURN_TAG _T("Key: %p\n"), Key);
	
	return Key;
}
Example #4
0
DWORD Sm_Shiloh::Terminate()
{
	BidxScopeAutoSNI0( SNIAPI_TAG _T( "\n") );
	
	if( hNetlib )
		FreeLibrary( hNetlib );
	hNetlib = NULL;

	if( DllCritSec )
	{
		DeleteCriticalSection( &DllCritSec );
	}

	Assert( NULL == DllCritSec ); 

	BidTraceU1( SNI_BID_TRACE_ON, RETURN_TAG _T("%d{WINERR}\n"), ERROR_SUCCESS);
		
	return ERROR_SUCCESS;
}
Example #5
0
DWORD Sm::LoadInstapiIfNeeded()
{
	DWORD dwError = ERROR_SUCCESS;	
	INSTAPILIBSTRUCT* pInstapiStruct = NULL;
	
	BidxScopeAutoSNI0( SNIAPI_TAG _T("\n") );

	//	Check to see if instapdll is already loaded
	//
	if (InterlockedCompareExchangePointer (
		reinterpret_cast<volatile PVOID*>(&gpInstapiStruct),
		NULL, NULL))
	{
		goto ErrorExit;
	}

	pInstapiStruct = NewNoX(gpmo) INSTAPILIBSTRUCT;

	if ( NULL == pInstapiStruct )
	{
		dwError = ERROR_OUTOFMEMORY;
		goto ErrorExit;
	}
	
	pInstapiStruct -> hInstapidll = NULL;
	
	
	//	Temparorily load the DLL.

	//1. Read registry value SharedCode under HKLM\Software\Microsoft\Microsoft SQL Server\90\Shared, 
	const char szSharedPathLocation[]="Software\\Microsoft\\Microsoft SQL Server\\90";
	HKEY  hKey;

	dwError = static_cast<DWORD> (RegOpenKeyEx( HKEY_LOCAL_MACHINE,// handle to open key
								 szSharedPathLocation,	// subkey name
								 0,					// reserved
								 KEY_QUERY_VALUE,	// security access mask
								 &hKey ));				// handle to open key

	if( ERROR_SUCCESS != dwError )
	{
		
		BidTrace1(ERROR_TAG _T("Cannot retrieve the shared path. %d{WINERR}\n"), dwError);
		goto ErrorExit;
	}

	char szSharedPath[MAX_PATH+1];
	DWORD cszSharedPath = MAX_PATH;
	DWORD dwSharedPathRegType; 
	dwError =  static_cast<DWORD> ( RegQueryValueEx(	hKey,					// handle to key
							   "SharedCode",			// value name
							   0,						// reserved
							   &dwSharedPathRegType,	// value type
							   (LPBYTE)szSharedPath,	// value data
							   &cszSharedPath ));			// size of value data

	RegCloseKey( hKey );							   

	if( ERROR_SUCCESS != dwError )
	{
		BidTrace1(ERROR_TAG _T("Cannot retrieve the shared path. %d{WINERR}\n"), dwError);
		goto ErrorExit;
	}

	if(REG_SZ != dwSharedPathRegType)
	{
		// RegValue is corrupted. In this case, we error out.
		dwError = ERROR_INVALID_DATA;
		goto ErrorExit;
	}

	__analysis_assume(cszSharedPath<=MAX_PATH); //The current header we use does not annotate RegQueryValueEx correctly, adding this to suppress Prefast 26015, we could remove it when the tools set is updated to Vista SDK.
	// Ensure NULL-termination.  
	szSharedPath[cszSharedPath] = '\0';

	//2. Load instapi.dll from the location where SharedCode points to

	const char szInstapidllname[] ="instapi.dll";
	char szInstapipath[MAX_PATH+sizeof(szInstapidllname)+1];
	if(FAILED(StringCchPrintf_lA( szInstapipath,
				CCH_ANSI_STRING(szInstapipath),
				"%s%s", GetDefaultLocale(),szSharedPath,szInstapidllname)))
	{
			dwError = ERROR_INVALID_PARAMETER;
			goto ErrorExit;
	}
	
	szInstapipath[sizeof(szInstapipath)-1] = '\0';
	
	if( NULL == (pInstapiStruct->hInstapidll = LoadLibrary( szInstapipath)) )
	{
		dwError = GetLastError();
		BidTrace1(ERROR_TAG _T("Failed to load instapi.dll. %d{WINERR}\n"), dwError );
		goto ErrorExit;
	}


	const char * szGetSvcInstanceIDFromName = "GetSvcInstanceIDFromName";	
	
	if( !(pInstapiStruct->pfnGetSvcInstanceIDFromName
		=  (PFNGetSvcInstanceIDFromName)GetProcAddress( pInstapiStruct->hInstapidll, 
												szGetSvcInstanceIDFromName)) 
	  )
	{
		dwError = GetLastError();
		BidTrace1(ERROR_TAG _T("Failed to load function GetSvcInstanceIDFromName. %d{WINERR}\n"), dwError );
		goto ErrorExit;
	}


	const char * szGetSQLInstanceRegStringByID = "GetSQLInstanceRegStringByID";	
	
	if( !(pInstapiStruct->pfnGetSQLInstanceRegStringByID
		=  (PFNGetSQLInstanceRegStringByID)GetProcAddress( pInstapiStruct->hInstapidll, 
												szGetSQLInstanceRegStringByID)) 
	  )
	{
		dwError = GetLastError();
		BidTrace1(ERROR_TAG _T("Failed to load function GetSQLInstanceRegStringByID. %d{WINERR}\n"), dwError );
		goto ErrorExit;
	}


	Assert (ERROR_SUCCESS == dwError );

	//	Now try to set global gpInstapiStruct
	if ( InterlockedCompareExchangePointer (
		reinterpret_cast<volatile PVOID*>(&gpInstapiStruct),
		reinterpret_cast<PVOID>(pInstapiStruct) ,NULL))
	{		
		goto ErrorExit;
	}

	BidTraceU1( SNI_BID_TRACE_ON, RETURN_TAG _T("Loaded instapi.dll. %d{WINERR}\n"), dwError );	
	return dwError;
	
ErrorExit:

	if ( pInstapiStruct )
	{
		if ( pInstapiStruct -> hInstapidll )	
			FreeLibrary( pInstapiStruct -> hInstapidll );
		
		delete pInstapiStruct;			
	}

	if ( ERROR_SUCCESS != dwError )
		SNI_SET_LAST_ERROR( SM_PROV, SNIE_36, dwError );
	
	BidTraceU1( SNI_BID_TRACE_ON, RETURN_TAG _T("%d{WINERR}\n"), dwError );	
	return dwError;
}	
Example #6
0
void Sm_Shiloh::Release()
{
	BidxScopeAutoSNI0( SNIAPI_TAG _T( "\n") );

	delete this;
}