BOOL Sm::IsShilohClustered(LPSTR szInstance) { BidxScopeAutoSNI1( SNIAPI_TAG _T("szInstance: \"%hs\"\n"), szInstance ); char szRegLocation[MAX_PATH+128] = ""; szRegLocation[ sizeof(szRegLocation) -1] = 0; // If its MSSQLSERVER (default instance), append another MSSQLServer to the path if(!_stricmp_l("MSSQLSERVER", szInstance, GetDefaultLocale()) ) { if(FAILED(StringCchPrintf_lA( szRegLocation, CCH_ANSI_STRING(szRegLocation), "SOFTWARE\\Microsoft\\MSSQLServer\\Cluster", GetDefaultLocale()))) { goto ErrorExit; } } // Else, its a named instance else { if(FAILED(StringCchPrintf_lA( szRegLocation, CCH_ANSI_STRING(szRegLocation), "SOFTWARE\\Microsoft\\Microsoft SQL Server\\%s\\Cluster", GetDefaultLocale(), szInstance))) { goto ErrorExit; } } HKEY hKey; LONG lReturn = RegOpenKeyEx( HKEY_LOCAL_MACHINE, // handle to open key szRegLocation, // subkey name 0, // reserved KEY_QUERY_VALUE, // security access mask &hKey ); // handle to open key if( ERROR_SUCCESS != lReturn ) { goto ErrorExit; } RegCloseKey( hKey ); BidTraceU1( SNI_BID_TRACE_ON, RETURN_TAG _T("%d{BOOL}\n"), TRUE); return TRUE; ErrorExit: BidTraceU1( SNI_BID_TRACE_ON, RETURN_TAG _T("%d{BOOL}\n"), FALSE); return FALSE; }
void SetPkgName(LPTSTR szPkgName) { Assert ( NULL != szPkgName ); if(!_tcsnicmp_l((_TCHAR *) _T("NTLM"), szPkgName, 5 , GetDefaultLocale()) ) // Use 5 to allow null-terminator m_PkgId = NTLM; else if(!_tcsnicmp_l((_TCHAR *) _T("Kerberos"), szPkgName, 9 , GetDefaultLocale())) // Use 9 to allow null-terminator. m_PkgId = KERBEROS; else // BASIC and NEGOTIATE packages are only reported by // Http auth provider and are set // through SetSecPkgId(), so we don't provide a mapping // from string. The SNI Auth provider always resolves the // NEGOTIATE package to the underlying NTLM/KERBEROS // auth scheme. // m_PkgId = INVALID; }
static String HHVM_STATIC_METHOD(Locale, getDefault) { return GetDefaultLocale(); }
DWORD Sm::OpenNpBasedYukon( __in SNI_CONSUMER_INFO * pConsumerInfo, __out SNI_Conn ** ppConn, __in ProtElem * pProtElem, __out SNI_Provider ** ppProv, BOOL fSync ) { BidxScopeAutoSNI5( SNIAPI_TAG _T( "pConsumerInfo: %p{SNI_CONSUMER_INFO*}, ppConn: %p{SNI_Conn**}, pProtElem: %p{ProtElem*}, ppProv: %p{SNI_Provider**}, fSync: %d{BOOL}\n"), pConsumerInfo, ppConn, pProtElem, ppProv, fSync); DWORD dwError = ERROR_SUCCESS; SNI_Conn * pConn = NULL; // Locals used for Shared-Memory mapping into Named-Pipes // ProtElem protElemSmOverNp; DWORD dwLength = sizeof(protElemSmOverNp.Np.Pipe) / sizeof(protElemSmOverNp.Np.Pipe[0]); LPSTR szInstance = NULL; Assert( NULL == *ppConn ); dwError = Sm::CreateSNIConn( pConsumerInfo, &pConn, pProtElem, fSync ); if( ERROR_SUCCESS != dwError ) { goto ErrorExit; } // Parse out the instance // szInstance = StrChrA_SYS(pProtElem->Sm.Alias,(int) strlen(pProtElem->Sm.Alias), '\\'); if( szInstance ) (szInstance) += 1; else szInstance = "MSSQLSERVER"; protElemSmOverNp.SetProviderNum(NP_PROV); protElemSmOverNp.m_ProviderToReport = SM_PROV; dwError = protElemSmOverNp.Init( pProtElem->m_szServerName, pProtElem->m_szOriginalServerName ); if( ERROR_SUCCESS != dwError ) { goto ErrorExit; } protElemSmOverNp.Np.Pipe[dwLength - 1] = '\0'; if( FAILED ( StringCchPrintf_lA( protElemSmOverNp.Np.Pipe, dwLength, "%s%s", GetDefaultLocale(), "\\\\.\\pipe\\SQLLocal\\", szInstance ) ) ) { dwError = ERROR_BUFFER_OVERFLOW; goto ErrorExit; } if( ERROR_SUCCESS != (dwError = Np::Open(pConn, &protElemSmOverNp, ppProv)) ) goto ErrorExit; pConn->m_ConnInfo.TransportProvider = pProtElem->GetProviderNum(); *ppConn = pConn; pConn = NULL; BidTraceU3( SNI_BID_TRACE_ON, RETURN_TAG _T("*ppConn: %p{SNI_Conn*}, *ppProv: %p{SNI_Provider*}, %d{WINERR}\n"), *ppConn, *ppProv, dwError); return ERROR_SUCCESS; ErrorExit: if( NULL != pConn ) { pConn->Release( REF_Active ); pConn = NULL; } BidTraceU1( SNI_BID_TRACE_ON, RETURN_TAG _T("%d{WINERR}\n"), dwError); return dwError; }
DWORD Sm::IsYukonByInstanceString(__in_opt LPSTR szInstance, __out BOOL * pfIsYukon, __out_opt BOOL * pfNew, __out BOOL * pfVersionRetrieved) { BidxScopeAutoSNI4( SNIAPI_TAG _T("szInstance: \"%hs\", pfIsYukon: %p{BOOL*}, pfNew: %p{BOOL*}, pfVersionRetrieved: %p{BOOL*}\n"), szInstance, pfIsYukon, pfNew, pfVersionRetrieved ); DWORD dwError = ERROR_SUCCESS; Assert ( szInstance && szInstance[0] ); Assert ( pfIsYukon != NULL ); Assert ( pfNew != NULL ); if ( szInstance == NULL || szInstance[0] == '\0' || pfIsYukon == NULL || pfNew == NULL || pfVersionRetrieved == NULL ) { dwError = ERROR_INVALID_PARAMETER; goto Exit; } *pfVersionRetrieved = FALSE; *pfNew = FALSE; if ( !gpInstapiStruct ) { *pfIsYukon = FALSE; goto Exit; } WCHAR wszVersion[MAX_VERSION_LENGTH+1]; DWORD cwszVersion = MAX_VERSION_LENGTH; WCHAR wszInstance[MAX_INSTANCENAME_LENGTH+1]; int cRet = MultiByteToWideChar(CP_ACP, 0, szInstance, static_cast<int>(strlen(szInstance))+1, wszInstance, MAX_INSTANCENAME_LENGTH ); if( cRet == 0 ) { dwError = GetLastError(); goto Exit; } wszInstance[MAX_INSTANCENAME_LENGTH] = L'\0'; // For obtain instance ID specifying SQL Server service to make sure we // don't get version for AS or RS. // INST_ID instID; if( !gpInstapiStruct->pfnGetSvcInstanceIDFromName( wszInstance, //instance name SVC_SQL, &instID ) ) { // If we cannot get the version, it is not yukon *pfIsYukon = FALSE; goto Exit; } if( !gpInstapiStruct->pfnGetSQLInstanceRegStringByID( &instID, L"MSSQLSERVER\\CurrentVersion", //RegPath L"CurrentVersion", //ValueName wszVersion, //String &cwszVersion) ) { // If we cannot get the version, it is not yukon *pfIsYukon = FALSE; goto Exit; } wszVersion[MAX_VERSION_LENGTH]=L'\0'; char szVersion[MAX_VERSION_LENGTH+1]; cRet = WideCharToMultiByte( CP_ACP, 0, wszVersion, -1, szVersion, MAX_VERSION_LENGTH, NULL, NULL ); if( cRet == 0 ) { dwError = GetLastError(); goto Exit; } szVersion[MAX_VERSION_LENGTH]='\0'; //4. We got Yukon Version number now! *pfIsYukon = FALSE; LPSTR szTmp = strchr(szVersion, '.'); if( szTmp ) { //szTmp = strtok(szVersion, "."); *szTmp = 0; int iMajorVer = _atoi_l(szVersion, GetDefaultLocale()); if( 9 == iMajorVer ) { *pfIsYukon = TRUE; szTmp = szTmp + 1; szTmp = strchr(szTmp, '.'); if( szTmp ) { szTmp = szTmp + 1; if( 579 <= _atoi_l(szTmp, GetDefaultLocale()) ) *pfNew = TRUE; } } else if( 9 < iMajorVer ) { *pfIsYukon = TRUE; *pfNew = TRUE; } *pfVersionRetrieved = TRUE; } Exit: BidTraceU1( SNI_BID_TRACE_ON, RETURN_TAG _T("%d{WINERR}\n"), dwError); if ( ERROR_SUCCESS != dwError ) SNI_SET_LAST_ERROR( SM_PROV, SNIE_36 , dwError ); return dwError; }
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; }
{ while(*pwStr && (*pwStr==L' ' || *pwStr==L'\t')) pwStr++; if(!*pwStr) //end of string return true; return false; } // LocalHost checking // inline bool IsLocalHost( const WCHAR *wszServer) { OACR_WARNING_PUSH OACR_WARNING_DISABLE(SYSTEM_LOCALE_MISUSE , " INTERNATIONALIZATION BASELINE AT KATMAI RTM. FUTURE ANALYSIS INTENDED. ") if( wcscmp(L".",wszServer) && _wcsicmp_l(L"(local)",wszServer, GetDefaultLocale()) && _wcsicmp_l(L"localhost",wszServer, GetDefaultLocale()) && CSTR_EQUAL != CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE|NORM_IGNOREWIDTH, gwszComputerName, -1, wszServer, -1)) OACR_WARNING_POP { return false; } return true; } // NOTE: The caller assumes ownership of the dynamically allocated copy DWORD CopyConnectionString(__in LPCWSTR wszConnect, __out LPWSTR* pwszCopyConnect);