bool DotNetRegistrar::RegisterItem() { CStdString sFileName; CStdString sParams; CreateRegisterCommandString(sFileName, sParams); if(_taccess(GetNameOfErrorLogFile().c_str(), 00) == 0) _tremove(GetNameOfErrorLogFile().c_str()); CFilePath exePath( GetDotNetRegistrationFileName() ); //this was retrieved in CreateRegisterCommandString, but we want one without enclosing quotes CStdStringA sCommand ; sCommand.Format("\"%s\" %s", CStdStringA(exePath.GetFileName()), CStdStringA( sParams ) ); //Batch file will contain just the executable name, not path. Working directory is assumed //by ExecuteAndWait to be the execution directory. CStdString sBatchFile = GetExecutionPath() + _T("\\Register.bat"); _tremove( sBatchFile.c_str()); CreateTextFile( sBatchFile, sCommand ); ASSERT( CGeneral::FileExists( sBatchFile )); ExecuteAndWait(sBatchFile, _T("")); _tremove( sBatchFile.c_str()); if (ErrorOccurred()) { std::vector<CStdString> Errors = GetErrorsFromFile(); std::vector<CStdString>::iterator it; for(it = Errors.begin(); it != Errors.end(); ++it) { ReportEvent(EVENTLOG_ERROR_TYPE, 0, *it); } return false; } return true; }
void ActivationContextLoader::LoadDll() { // Get a handle to the DLL module. CPath dllPath; dllPath.Combine(GetModulePath(), WS_ACTIVATIONCONTEXTLOADER_DLL); m_hinstLib = LoadLibrary(dllPath); // If the handle is valid, try to get the function address. if (m_hinstLib != NULL) { m_funcLAC = (LAC) GetProcAddress(m_hinstLib, WS_ACLOADFUNC); m_funcULAC = (ULAC) GetProcAddress(m_hinstLib, WS_ACUNLOADFUNC); m_funcIAAFM = (IAAFM) GetProcAddress(m_hinstLib, WS_ACALREADYACTIVEFUNC); } else { CStdStringA msg; msg.Format("LoadLibrary on '%s'failed. Error code: %d.", WS_ACTIVATIONCONTEXTLOADER_DLL_A, GetLastError()); throw std::exception(msg); } }
DocFileField::DocFileField(const WrdCharacterProperties& props, WordParserInfo& wpi) : RTFfield(wpi.GetFileContext()) { the_RTFFieldInst = new RTFfldinst(m_pContext); CStdStringA sFont = wpi.m_FontTable.getFontFamilyName(props.getFontIndexForSymbol()).getFaceName().c_str(); if ((int)sFont.find(" ") > 0) { sFont = "\"" + sFont + "\""; } CStdStringA sInst; if (1 & props.getFontSize()) sInst.Format("SYMBOL %d \\f %s \\s %.1f", props.getSymbolCharacter() & 0xFF, sFont.c_str(), ((double)props.getFontSize())/2); else sInst.Format("SYMBOL %d \\f %s \\s %d", props.getSymbolCharacter() & 0xFF, sFont.c_str(), props.getFontSize()/2); the_RTFFieldInst->AddObject(new DocFilePCData(m_pContext, sInst)); CreateResult(); // the_RTFFieldResult->AddObject( new DocFileChrfmt(props , wpi, false) );//TODO - need a double check }
void ActivationContextLoader::UnloadDll() { if(m_hinstLib) { if (FALSE == FreeLibrary(m_hinstLib)) { CStdStringA msg; msg.Format("FreeLibrary on '%s'failed. Error code: %d.", WS_ACTIVATIONCONTEXTLOADER_DLL_A, GetLastError()); throw std::exception(msg); } } }
void CRTFTablePostProcessor::DebugDumpStructureToFile(int iSuffix, LPCSTR szContext) { if (m_prtfFile->GetModality() == 0) return; CStdStringA csFileName; csFileName.Format("c:\\BHTableDump%d%c.txt",iSuffix, m_prtfFile->GetModality() == 1 ? 'O' : 'M'); if(FILE *fp = fopen(csFileName, "w")) { fprintf( fp, "%s - Starting at %d\n", szContext, m_iStart); m_pParentCollection->Dump(fp, true); fclose(fp); } }
void ActivationContextLoader::UnloadAC() { if (m_funcULAC && m_cookie != 0) { DWORD dwRet = (m_funcULAC)(m_cookie); if (ERROR_SUCCESS != dwRet) { CStdStringA msg; msg.Format("Unloading Activation Context failed. Error code: %d", dwRet); throw std::exception(msg); } } }
void ActivationContextLoader::LoadAC() { if (m_funcLAC) { DWORD dwRet = (m_funcLAC)(m_sManifest, &m_cookie); if (ERROR_SUCCESS != dwRet) { CStdStringA msg; msg.Format("Loading Activation Context with manifest '%s' failed. Error code: %d", m_sManifest.c_str(), dwRet); throw std::exception(msg); } } }
CStdString CTestUtils::CopyTestFileToTempFile(const CStdString& sSource) { if(_taccess(sSource, 0) != 0) { CStdStringA sError; sError.Format("CTestUtils::CopyTestFileToTempFile - source file (%s) doesn't exist.", sSource.c_str()); throw std::exception(sError.c_str()); } TCHAR szTempPath[ MAX_PATH ] = {0}; ::GetTempPath( MAX_PATH, szTempPath ); TCHAR szTempFileName[MAX_PATH] = {0}; ::GetTempFileName( szTempPath, _T( "wst" ), 0, szTempFileName ); if (!CopyFile(sSource.c_str(), szTempFileName, false)) { CStdStringA sError; sError.Format("CTestUtils::CopyTestFileToTempFile copy file failed - source file (%s) destination file (%s)", sSource.c_str(), szTempFileName); throw std::exception(sError.c_str()); } return CStdString(szTempFileName); }
bool DotNetRegistrar::UnregisterItem() { CStdString sFileName; CStdString sParams; CreateUnregisterCommandString(sFileName, sParams); CFilePath exePath( GetDotNetRegistrationFileName() ); //this was retrieved in CreateRegisterCommandString, but we want one without enclosing quotes CStdStringA sCommand ; sCommand.Format("\"%s\" %s", CStdStringA(exePath.GetFileName()), CStdStringA( sParams ) ); CStdString sBatchFile = GetExecutionPath() + _T("\\Register.bat"); _tremove( sBatchFile.c_str()); CreateTextFile( sBatchFile, sCommand ); ASSERT( CGeneral::FileExists( sBatchFile )); bool res = true; try { CStdString cmdLine = sBatchFile; STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); si.wShowWindow = SW_HIDE; ZeroMemory(&pi, sizeof(pi)); if ( !CreateProcess( NULL, cmdLine.GetBuffer(MAX_PATH), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) ) { cmdLine.ReleaseBuffer(); res = false; } cmdLine.ReleaseBuffer(); if ( res ) { // Wait around for 15 seconds WaitForSingleObject(pi.hProcess, 15000); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } } catch(...) { _tremove( sBatchFile.c_str()); throw; } _tremove( sBatchFile.c_str()); return res; }
BOOL CServer::ProcessCommand(CAdminSocket *pAdminSocket, int nID, unsigned char *pData, int nDataLength) { switch (nID) { case 2: if (!nDataLength) { unsigned char buffer[2]; buffer[0] = m_nServerState / 256; buffer[1] = m_nServerState % 256; pAdminSocket->SendCommand(1, 2, buffer, 2); } else if (nDataLength == 2) { ToggleActive(*pData * 256 + pData[1]); unsigned char buffer[2]; buffer[0] = m_nServerState / 256; buffer[1] = m_nServerState % 256; pAdminSocket->SendCommand(1, 2, buffer, 2); } else pAdminSocket->SendCommand(1, 1, "\001Protocol error: Unexpected data length", strlen("\001Protocol error: Unexpected data length") + 1); break; case 3: if (!nDataLength) { pAdminSocket->SendCommand(1, 1, "\001Protocol error: Unexpected data length", strlen("\001Protocol error: Unexpected data length") + 1); } else if (*pData == USERCONTROL_GETLIST) { int len = 4; std::map<int, t_connectiondata>::iterator iter; for (iter = m_UsersList.begin(); iter != m_UsersList.end(); ++iter) { const t_connectiondata& data = iter->second; auto ip = ConvToNetwork(data.ip); auto user = ConvToNetwork(data.user); len += 4 + ip.size() + 2 + 4 + user.size() + 2 + 1; if (data.transferMode) { auto physicalFile = ConvToNetwork(data.physicalFile); auto logicalFile = ConvToNetwork(data.logicalFile); len += 2 + physicalFile.size() + 2 + logicalFile.size(); if (data.currentOffset != 0) len += 8; if (data.totalSize != -1) len += 8; } } unsigned char *buffer = new unsigned char[len]; buffer[0] = USERCONTROL_GETLIST; buffer[1] = ((m_UsersList.size() / 256) / 256) & 0xff; buffer[2] = (m_UsersList.size() / 256) & 0xff; buffer[3] = m_UsersList.size() % 256; unsigned char *p = buffer + 4; for (iter = m_UsersList.begin(); iter != m_UsersList.end(); ++iter) { const t_connectiondata& data = iter->second; auto ip = ConvToNetwork(data.ip); auto user = ConvToNetwork(data.user); memcpy(p, &data.userid, 4); p += 4; *p++ = (ip.size() / 256) & 0xff; *p++ = ip.size() % 256; memcpy(p, ip.c_str(), ip.size()); p += ip.size(); memcpy(p, &data.port, 4); p += 4; *p++ = (user.size() / 256) & 0xff; *p++ = user.size() % 256; memcpy(p, user.c_str(), user.size()); p += user.size(); *p = data.transferMode; if (data.transferMode) { // Bit 5 and 6 indicate presence of currentOffset and totalSize. if (data.currentOffset != 0) { *p |= 0x20; } if (data.totalSize != -1) { *p |= 0x40; } p++; auto physicalFile = ConvToNetwork(data.physicalFile); *p++ = (physicalFile.size() / 256) & 0xff; *p++ = physicalFile.size() % 256; memcpy(p, physicalFile.c_str(), physicalFile.size()); p += physicalFile.size(); auto logicalFile = ConvToNetwork(data.logicalFile); *p++ = (logicalFile.size() / 256) & 0xff; *p++ = logicalFile.size() % 256; memcpy(p, logicalFile.c_str(), logicalFile.size()); p += logicalFile.size(); if (data.currentOffset != 0) { memcpy(p, &data.currentOffset, 8); p += 8; } if (data.totalSize != -1) { memcpy(p, &data.totalSize, 8); p += 8; } } else { p++; } } m_pAdminInterface->SendCommand(1, 3, buffer, len); delete [] buffer; } else if (*pData == USERCONTROL_KICK || *pData == USERCONTROL_BAN) { if (nDataLength != 5) pAdminSocket->SendCommand(1, 1, "\001Protocol error: Unexpected data length", strlen("\001Protocol error: Unexpected data length")+1); else { int nUserID; memcpy(&nUserID, pData+1, 4); std::map<int, t_connectiondata>::iterator iter = m_UsersList.find(nUserID); if (iter!=m_UsersList.end()) { if (*pData == USERCONTROL_BAN) { // Get the list of IP filter rules. CStdString ips = m_pOptions->GetOption(OPTION_IPFILTER_DISALLOWED); if (ips != _T("")) ips += _T(" "); int pos = ips.Find(' '); while (pos != -1) { CStdString blockedIP = ips.Left(pos); ips = ips.Mid(pos + 1); pos = ips.Find(' '); if (MatchesFilter(blockedIP, iter->second.ip)) break; } if (pos == -1) { ips = m_pOptions->GetOption(OPTION_IPFILTER_DISALLOWED); if (ips != _T("")) ips += _T(" "); ips += iter->second.ip; m_pOptions->SetOption(OPTION_IPFILTER_DISALLOWED, ips); } } t_controlmessage *msg = new t_controlmessage; msg->command = USERCONTROL_KICK; msg->socketid = nUserID; iter->second.pThread->PostThreadMessage(WM_FILEZILLA_THREADMSG, FTM_CONTROL, (LPARAM)msg); char buffer[2]; buffer[0] = *pData; buffer[1] = 0; pAdminSocket->SendCommand(1, 3, &buffer, 2); } else { char buffer[2]; buffer[0] = USERCONTROL_KICK; buffer[1] = 1; pAdminSocket->SendCommand(1, 3, &buffer, 2); } } } else pAdminSocket->SendCommand(1, 1, "\001Protocol error: Invalid data", strlen("\001Protocol error: Invalid data")+1); break; case 5: if (!nDataLength) { unsigned char *pBuffer = NULL; DWORD nBufferLength = 0; if (m_pOptions && m_pOptions->GetAsCommand(&pBuffer, &nBufferLength)) { pAdminSocket->SendCommand(1, 5, pBuffer, nBufferLength); delete [] pBuffer; } } else if (m_pOptions) { if (nDataLength < 2) pAdminSocket->SendCommand(1, 1, "\001Protocol error: Unexpected data length", strlen("\001Protocol error: Unexpected data length")+1); else { CStdString const listenPorts = m_pOptions->GetOption(OPTION_SERVERPORT); CStdString const listenPortsSsl = m_pOptions->GetOption(OPTION_TLSPORTS); bool const enableSsl = m_pOptions->GetOptionVal(OPTION_ENABLETLS) != 0; CStdString const ipBindings = m_pOptions->GetOption(OPTION_IPBINDINGS); int const nAdminListenPort = (int)m_pOptions->GetOptionVal(OPTION_ADMINPORT); CStdString const adminIpBindings = m_pOptions->GetOption(OPTION_ADMINIPBINDINGS); CStdString peerIP; UINT port = 0; bool bLocal = false; if (!pAdminSocket->GetPeerName(peerIP, port)) return FALSE; else bLocal = IsLocalhost(peerIP); if (!m_pOptions->ParseOptionsCommand(pData, nDataLength, bLocal)) { pAdminSocket->SendCommand(1, 1, "\001Protocol error: Invalid data, could not import settings.", strlen("\001Protocol error: Invalid data, could not import settings.")+1); char buffer = 1; pAdminSocket->SendCommand(1, 5, &buffer, 1); break; } char buffer = 0; pAdminSocket->SendCommand(1, 5, &buffer, 1); unsigned int threadnum = (int)m_pOptions->GetOptionVal(OPTION_THREADNUM); if (m_nServerState & STATE_ONLINE) { if (threadnum > m_ThreadArray.size()) { while (threadnum > m_ThreadArray.size()) { int index = GetNextThreadNotificationID(); CServerThread *pThread = new CServerThread(WM_FILEZILLA_SERVERMSG + index); m_ThreadNotificationIDs[index] = pThread; if (pThread->Create(THREAD_PRIORITY_NORMAL, CREATE_SUSPENDED)) { pThread->ResumeThread(); m_ThreadArray.push_back(pThread); } } CStdString str; str.Format(_T("Number of threads increased to %d."), threadnum); ShowStatus(str, 0); } else if (threadnum < m_ThreadArray.size()) { CStdString str; str.Format(_T("Decreasing number of threads to %d."), threadnum); ShowStatus(str, 0); unsigned int i = 0; std::vector<CServerThread *> newList; for (auto iter = m_ThreadArray.begin(); iter != m_ThreadArray.end(); iter++, i++) { if (i >= threadnum) { (*iter)->PostThreadMessage(WM_FILEZILLA_THREADMSG, FTM_GOOFFLINE, 2); m_ClosedThreads.push_back(*iter); } else newList.push_back(*iter); } m_ThreadArray.swap(newList); } } if (listenPorts != m_pOptions->GetOption(OPTION_SERVERPORT) || enableSsl != (m_pOptions->GetOptionVal(OPTION_ENABLETLS) != 0) || (m_pOptions->GetOptionVal(OPTION_ENABLETLS) && listenPortsSsl != m_pOptions->GetOption(OPTION_TLSPORTS)) || ipBindings != m_pOptions->GetOption(OPTION_IPBINDINGS)) { if (!m_ListenSocketList.empty()) { ShowStatus(_T("Closing all listening sockets"), 0); for (std::list<CListenSocket*>::iterator listIter = m_ListenSocketList.begin(); listIter != m_ListenSocketList.end(); ++listIter) { (*listIter)->Close(); delete *listIter; } m_ListenSocketList.clear(); if (!CreateListenSocket()) { ShowStatus(_T("Failed to create a listen socket on any of the specified ports. Server is not online!"), 1); m_nServerState &= ~STATE_ONLINE; } else { ShowStatus(_T("Listen socket port changed"), 0); if (!(m_nServerState & STATE_MASK_GOOFFLINE)) m_nServerState |= STATE_ONLINE; } SendState(); } } if (nAdminListenPort != m_pOptions->GetOptionVal(OPTION_ADMINPORT) || adminIpBindings != m_pOptions->GetOption(OPTION_ADMINIPBINDINGS)) { CreateAdminListenSocket(); } VerifyTlsSettings(pAdminSocket); VerifyPassiveModeSettings(pAdminSocket); } } break; case 6: if (!nDataLength) { unsigned char *pBuffer = NULL; DWORD nBufferLength = 0; CPermissions permissions = CPermissions(std::function<void()>()); permissions.GetAsCommand(&pBuffer, &nBufferLength); pAdminSocket->SendCommand(1, 6, pBuffer, nBufferLength); delete [] pBuffer; } else { if (nDataLength < 2) pAdminSocket->SendCommand(1, 1, "\001Protocol error: Unexpected data length", strlen("\001Protocol error: Unexpected data length")+1); else { CPermissions permissions = CPermissions(std::function<void()>()); if (!permissions.ParseUsersCommand(pData, nDataLength)) { pAdminSocket->SendCommand(1, 1, "\001Protocol error: Invalid data, could not import account settings.", strlen("\001Protocol error: Invalid data, could not import account settings.")+1); char buffer = 1; pAdminSocket->SendCommand(1, 6, &buffer, 1); break; } char buffer = 0; pAdminSocket->SendCommand(1, 6, &buffer, 1); } } break; case 8: pAdminSocket->SendCommand(1, 8, NULL, 0); break; default: { CStdStringA str; str.Format("\001Protocol error: Unknown command (%d).", nID); pAdminSocket->SendCommand(1, 1, str.c_str(), str.GetLength()); } break; } return TRUE; }