示例#1
0
bool COleDBConnectionProp::ConnectMSOracle(ATL::CDataSource* pDataSource,CSession* pSession)
{
	ASSERT(pDataSource);

	m_strDatabaseName = g_sDBName;
	m_strLoginName = g_sDBUser;
	m_strPassword = g_sDBPassword;
	m_strServerName = g_sDBDNS;


	CComBSTR bstrServer(m_strServerName);
	CComBSTR bstrUser(m_strLoginName);
	CComBSTR bstrPassword(m_strPassword);
	CComBSTR bstrDatabase(m_strDatabaseName);


	if (pSession && pSession->m_spOpenRowset != NULL)
		pSession->m_spOpenRowset.Release();

	
	CDBPropSet	dbinit(DBPROPSET_DBINIT);

	dbinit.AddProperty(DBPROP_AUTH_PASSWORD, bstrPassword);
	dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);
	dbinit.AddProperty(DBPROP_AUTH_USERID, bstrUser);
	dbinit.AddProperty(DBPROP_INIT_DATASOURCE, bstrDatabase);
	dbinit.AddProperty(DBPROP_INIT_LCID, (long)1049);
	dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);

		
	
	if(FAILED(pDataSource->Open(_T("MSDAORA"), &dbinit)))
	{
		CString strMsg = "Cannot connect to data source";
		strMsg += "\nDatabase\t= "	+ m_strDatabaseName;
		strMsg += "\nLogin\t= "		+ m_strLoginName;
		strMsg += "\nPassword\t= "	+ m_strPassword;

		AfxMessageBox(strMsg);
		if(pDataSource)
		{
			pDataSource->Close();
		}
		goto ErrorExit;
	}
	else
	{
		if (pSession && pSession->Open(*pDataSource) != S_OK)
		{
			AfxMessageBox(_T("Couldn't create session on data source"));
			goto ErrorExit;
		}
	}
	return true;

ErrorExit:
	CloseConnection();
	return false;
}
示例#2
0
bool COleDBConnectionProp::ConnectMSAccess(ATL::CDataSource* pDataSource,CSession* pSession)
{
	ASSERT(pDataSource);

	m_strDatabaseName = g_sDBName;
	m_strLoginName = g_sDBUser;
	m_strPassword = g_sDBPassword;
	m_strServerName = g_sDBDNS;

	CComBSTR bstrServer(m_strServerName);
	CComBSTR bstrUser(m_strLoginName);
	CComBSTR bstrPassword(m_strPassword);
	CComBSTR bstrDatabase(m_strDatabaseName);


	if (pSession && pSession->m_spOpenRowset != NULL)
		pSession->m_spOpenRowset.Release();

	
	
	CLSID clsid = {0xdee35070L,0x506b,0x11cf, 
	              {0xb1,0xaa,0x0,0xaa,0x0,0xb8,0xde,0x95}};

	
	if(FAILED(pDataSource->Open(clsid, m_strDatabaseName, NULL, NULL, DB_MODE_SHARE_EXCLUSIVE)))
	{
		CString strMsg = "Cannot connect to data source";
		strMsg += "\nDatabase\t= "	+ m_strDatabaseName;

		AfxMessageBox(strMsg);
		if(pDataSource)
		{
			pDataSource->Close();
		}
		goto ErrorExit;
	}
	else
	{
		if (pSession && pSession->Open(*pDataSource) != S_OK)
		{
			AfxMessageBox(_T("Couldn't create session on data source"));
			goto ErrorExit;
		}
	}
	return true;

ErrorExit:
	CloseConnection();
	return false;
}
示例#3
0
bool COleDBConnectionProp::ConnectDB2(ATL::CDataSource* pDataSource,CSession* pSession)
{
	ASSERT(pDataSource);

	m_strDatabaseName = g_sDBName;
	m_strLoginName = g_sDBUser;
	m_strPassword = g_sDBPassword;
	m_strServerName = g_sDBDNS;


	CComBSTR bstrServer(m_strServerName);
	CComBSTR bstrUser(m_strLoginName);
	CComBSTR bstrPassword(m_strPassword);
	CComBSTR bstrDatabase(m_strDatabaseName);


	if (pSession && pSession->m_spOpenRowset != NULL)
		pSession->m_spOpenRowset.Release();

	
		
	if(FAILED(pDataSource->Open(_T("IBMDADB2.1"), m_strDatabaseName, m_strLoginName, m_strPassword )))
	{
		CString strMsg = "Cannot connect to data source";
		strMsg += "\nDatabase\t= "	+ m_strDatabaseName;
		strMsg += "\nLogin\t= "		+ m_strLoginName;
		strMsg += "\nPassword\t= "	+ m_strPassword;

		AfxMessageBox(strMsg);
		if(pDataSource)
		{
			pDataSource->Close();
		}
		goto ErrorExit;
	}
	else
	{
		if (pSession && pSession->Open(*pDataSource) != S_OK)
		{
			AfxMessageBox(_T("Couldn't create session on data source"));
			goto ErrorExit;
		}
	}
	return true;

ErrorExit:
	CloseConnection();
	return false;
}
示例#4
0
void Connection::open(const tstring& host, const tstring& login, const tstring& password, const tstring& nmspace)
{
	ASSERT(!isOpen());

	// Format the full connection path.
	tstring path = host + nmspace;

	if (path.compare(0, 2, TXT("\\\\")) != 0)
		path = TXT("\\\\") + path;

	// Create the connection.
	IWbemServicesPtr	services;
	IWbemLocatorPtr		locator(CLSID_WbemLocator);
	WCL::ComStr			bstrPath(path);
	WCL::ComStr			bstrAuth(TXT(""));
	HRESULT				result;

	if (login.empty())
	{
		result = locator->ConnectServer(bstrPath.Get(), nullptr, nullptr, nullptr, 0,
										bstrAuth.Get(), nullptr, AttachTo(services));
	}
	else
	{
		WCL::ComStr	bstrLogin(login);
		WCL::ComStr	bstrPassword(password);

		result = locator->ConnectServer(bstrPath.Get(), bstrLogin.Get(), bstrPassword.Get(), nullptr, 0,
										bstrAuth.Get(), nullptr, AttachTo(services));
	}

	if (FAILED(result))
		throw Exception(result, locator, Core::fmt(TXT("Failed to connect to the WMI provider on '%s'"), host.c_str()).c_str());

	// Enable impersonation on the connection.
    result = ::CoSetProxyBlanket(services.get(), RPC_C_AUTHN_DEFAULT, RPC_C_AUTHZ_DEFAULT, nullptr,
									RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE,
									nullptr, EOAC_NONE);

	if (FAILED(result))
		throw Exception(result, locator, TXT("Failed to enable impersonation on the WMI connection"));

	// Update state.
	m_locator  = locator;
	m_services = services;
}
CString Login( CString sUser, CString sPassword )
{
	HRESULT hr = ::CoInitialize(NULL);
	CString sOut(""); 
	try
	{
		ProcessClientServicesLib::IRpcCallHelperPtr piClientHelper(__uuidof(ProcessClientServicesLib::RpcCallHelper));
		_bstr_t bstrUser(sUser);
		_bstr_t bstrPassword(sPassword);
		CString sUpResult = (LPCTSTR)_bstr_t(piClientHelper->ClientLogin(bstrUser, bstrPassword));
		sOut = sUpResult;
	}
	catch (_com_error e)
	{
		CString strErrorMsg = e.ErrorMessage();
		ZTools::WriteZToolsFormatLog("RPC组件调用异常,%s", strErrorMsg);
		return "";
	}
	catch (COleException* e)
	{
		TCHAR szCause[255];
		CString strFormatted;
		e->GetErrorMessage(szCause, 255);
		ZTools::WriteZToolsFormatLog("PRC组件调用异常,%s", szCause);
		return "";
	}
	catch (CException* e)
	{
		TCHAR szCause[255];
		CString strFormatted;
		e->GetErrorMessage(szCause, 255);
		ZTools::WriteZToolsFormatLog("RPC组件调用异常,%s", szCause);
		return "";
	}
	if (SUCCEEDED(hr))
	{
		::CoUninitialize();
	}

	//return "{\"error\":\"0\",\"userName\":\"admin\",\"password\":\"111\",\"ticket\":\"ticket-proxy=ZzxSJrzPhvKJCElqycem\",\"realName\":\"超管\",\"roles\":\"asdf\"}";
	return sOut;
}
CString Login(CString strUser,CString strPswod,CString strIp,CString strbForce)
{
	HRESULT hr = ::CoInitialize(NULL);
	CString sResult(""); 
	try
	{
		ProcessClientServicesLib::IRpcCallHelperPtr piClientHelper(__uuidof(ProcessClientServicesLib::RpcCallHelper));
		_bstr_t bstrUser(strUser);
		_bstr_t bstrPassword(strPswod);
		_bstr_t bstrIp(strIp);
		_bstr_t bstrForce(strbForce);

		 sResult = (LPCTSTR)_bstr_t(piClientHelper->ERMDoLogin(bstrUser, bstrPassword,bstrIp,bstrForce));
		 if (sResult.Find("ticket-proxy=") == -1)
		 {
			 if (sResult.Compare("-2") == 0)
			 {
				 printf("系统错误,请确认服务器工作正常\n");
			 }
			 else if (sResult.Compare("-6") == 0)
			 {
				 printf("用户不存在\n");
			 }
			 else if (sResult.Compare("-7") == 0)
			 {
				 printf("密码错误\n");
			 }
			 else if (sResult.Compare("-8") == 0)
			 {
				 printf( "用户被锁定\n");
			 }
			 else if (sResult.Compare("-9") == 0)
			 {
				 printf("用户被删除\n");
			 }
			 else if (sResult.Compare("-10") == 0)
			 {
				 printf("用户被禁用\n");
			 }
			 else
			 {
				 printf("登录失败,请确认服务器工作正常\n");
			 }
		 }
		

	}
	catch (_com_error e)
	{
		CString strErrorMsg = e.ErrorMessage();
		ZTools::WriteZToolsFormatLog("RPC组件调用异常,%s", strErrorMsg);
		return "";
	}
	catch (COleException* e)
	{
		TCHAR szCause[255];
		CString strFormatted;
		e->GetErrorMessage(szCause, 255);
		ZTools::WriteZToolsFormatLog("PRC组件调用异常,%s", szCause);
		return "";
	}
	catch (CException* e)
	{
		TCHAR szCause[255];
		CString strFormatted;
		e->GetErrorMessage(szCause, 255);
		ZTools::WriteZToolsFormatLog("RPC组件调用异常,%s", szCause);
		return "";
	}
	if (SUCCEEDED(hr))
	{
		::CoUninitialize();
	}
	return sResult;
}