BOOL vmsFdmWebInterfaceServer::ProcessRequest(vmsHttpRequest &request, vmsHttpResponse &response) { if (lstrcmpiA (request.get_RequestType (), "GET")) return FALSE; CString strU = AfxGetApp ()->GetProfileString (_T("Network"), _T("Login")), strP = AfxGetApp ()->GetProfileString (_T("Network"), _T("Password")); CString strAuth = strU + ":" + strP; #ifdef UNICODE _bstr_t bstrAuth((LPCWSTR)strAuth); #else _bstr_t bstrAuth((LPCSTR)strAuth); #endif if (strU.IsEmpty () == FALSE && lstrcmpA (request.get_Auth (), (LPCSTR)bstrAuth)) { response.set_ResponseCode ("401 Authorization Required"); return FALSE; } LPCSTR pszRes = request.get_ResourcePath (); if (lstrcmpA (pszRes, "/") == 0) return RequestRootPage (response); if (strncmp (pszRes, "/adddownload.req?", lstrlenA ("/adddownload.req?")) == 0) return RequestCreateNewDownload (pszRes, response); if (strncmp (pszRes, "/compdlds.req", lstrlenA ("/compdlds.req")) == 0) return RequestListOfCompletedDownloads (pszRes, response); response.set_ResponseCode ("404 Not Found"); return FALSE; }
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; }