BOOL CService::Start () { SC_HANDLE hSCM = NULL; SC_HANDLE hService = NULL; BOOL bResult = FALSE; do { if (!GetServiceName ()) { SetLastError (ERROR_BAD_CONFIGURATION); break; } hSCM = OpenSCManager (_scmHost (GetHost ()), NULL, GENERIC_READ); if (!hSCM) break; hService = OpenService (hSCM, GetServiceName (), SERVICE_START); if (!hService) break; if (!StartService (hService, 0, NULL)) break; bResult = TRUE; } while (FALSE); int nError = bResult ? 0 : GetLastError (); if (hSCM) CloseServiceHandle (hSCM); if (hService) CloseServiceHandle (hService); if (bResult) { return TRUE; } else { SetLastError (nError); return FALSE; } }
void RecommendationsWidget::InitializeProviders () { const auto& lastProv = ShouldRememberProvs () ? XmlSettingsManager::Instance () .Property ("LastUsedRecsProvider", QString ()).toString () : QString (); bool lastFound = false; const auto& roots = Core::Instance ().GetProxy ()->GetPluginsManager ()-> GetAllCastableRoots<Media::IRecommendedArtists*> (); for (auto root : roots) { auto scrob = qobject_cast<Media::IAudioScrobbler*> (root); if (!scrob) continue; Ui_.RecProvider_->addItem (qobject_cast<IInfo*> (root)->GetIcon (), scrob->GetServiceName ()); ProvRoots_ << root; Providers_ << qobject_cast<Media::IRecommendedArtists*> (root); if (scrob->GetServiceName () == lastProv) { const int idx = Providers_.size () - 1; Ui_.RecProvider_->setCurrentIndex (idx); on_RecProvider__activated (idx); lastFound = true; } } if (!lastFound) Ui_.RecProvider_->setCurrentIndex (-1); }
BOOL CService::IsAutoStart () { SC_HANDLE hSCM = NULL; SC_HANDLE hService = NULL; LPQUERY_SERVICE_CONFIG lpqsc = NULL; BOOL bResult = FALSE; do { if (!GetServiceName ()) break; hSCM = OpenSCManager (_scmHost (GetHost ()), NULL, GENERIC_READ); if (!hSCM) break; hService = OpenService (hSCM, GetServiceName (), SERVICE_QUERY_CONFIG); if (!hService) break; DWORD dwBytes = 1024; do { DWORD dwBytesNeeded; lpqsc = (LPQUERY_SERVICE_CONFIG)new BYTE[dwBytes]; if (!lpqsc) break; if (!QueryServiceConfig (hService, lpqsc, dwBytes, &dwBytesNeeded)) { if (GetLastError () == ERROR_INSUFFICIENT_BUFFER) { delete lpqsc; lpqsc = NULL; dwBytes = dwBytesNeeded; continue; } } break; } while (TRUE); if (!lpqsc) break; bResult = (lpqsc->dwStartType == SERVICE_AUTO_START); } while (FALSE); if (hSCM) CloseServiceHandle (hSCM); if (hService) CloseServiceHandle (hService); return bResult; }
int CService::GetStatus () { SC_HANDLE hSCM = NULL; SC_HANDLE hService = NULL; SERVICE_STATUS ss; int nResult; do { if (!GetServiceName () || !GetHost () || !GetPort ()) { nResult = SERVICE_STATUS_BAD_CONFIG; break; } if (m_nWinsock) { nResult = SERVICE_STATUS_BAD_WINSOCK; SetLastError (m_nWinsock); break; } hSCM = OpenSCManager (_scmHost (GetHost ()), NULL, GENERIC_READ); if (!hSCM) { nResult = SERVICE_STATUS_BAD_SCM; break; } hService = OpenService (hSCM, GetServiceName (), SERVICE_INTERROGATE); if (!hService) { DWORD dwError = GetLastError (); switch (dwError) { case ERROR_SERVICE_DOES_NOT_EXIST : nResult = SERVICE_STATUS_NOT_INSTALLED; break; default : nResult = SERVICE_STATUS_CONNECTOR_ERROR; break; } break; } if (!ControlService (hService, SERVICE_CONTROL_INTERROGATE, &ss)) { DWORD dwError = GetLastError (); switch (dwError) { case ERROR_SERVICE_NEVER_STARTED : case ERROR_SERVICE_NOT_ACTIVE : nResult = SERVICE_STATUS_STOPPED; break; case ERROR_SERVICE_CANNOT_ACCEPT_CTRL : nResult = SERVICE_STATUS_BUSY; break; default : nResult = SERVICE_STATUS_QUERY_ERROR; break; } break; } if (ss.dwCurrentState != SERVICE_RUNNING) { nResult = SERVICE_STATUS_BUSY; break; } nResult = _socketConnect (GetHost (), GetPort ()) ? SERVICE_STATUS_OK : SERVICE_STATUS_STARTING; } while (FALSE); if (hSCM) CloseServiceHandle (hSCM); if (hService) CloseServiceHandle (hService); return nResult; }
//--------------------------------------------------------------------------- void __fastcall TForm1::SendData(void) { TBytes ToSend; if((FSocket == NULL) || (ItemIndex != ComboBoxPaired->ItemIndex)) { if(ComboBoxPaired->ItemIndex > -1) { TBluetoothDevice * LDevice = FPairedDevices->Items[ComboBoxPaired->ItemIndex]; DisplayR->Lines->Add(GetServiceName(ServiceGUI)); DisplayR->GoToTextEnd(); FSocket = LDevice->CreateClientSocket(StringToGUID(ServiceGUI), false); if(FSocket != NULL) { ItemIndex = ComboBoxPaired->ItemIndex; FSocket->Connect(); ToSend = TEncoding::UTF8->GetBytes(Edit1->Text); FSocket->SendData(ToSend); DisplayR->Lines->Add("Text Sent"); DisplayR->GoToTextEnd(); } else { ShowMessage("Out of time ~15s~"); } } else { ShowMessage("No paired device selected"); } } else { ToSend = TEncoding::UTF8->GetBytes(Edit1->Text); FSocket->SendData(ToSend); DisplayR->Lines->Add("Text Sent"); DisplayR->GoToTextEnd(); } }
int win_svc_base::Main( int argc, char * argv[] ) { ////////////////////////////////////////////////////////////////////////// /// 命令行参数解析 boost::program_options::options_description opts; opts.add_options() ("help", "options: --install --uninstall") ("install", "") ("uninstall", "") ("auto-start", ""); boost::program_options::store( boost::program_options::parse_command_line(argc, argv, opts) , m_vm ); ////////////////////////////////////////////////////////////////////////// /// 定义SERVICE_TABLE_ENTRY DispatchTable[] 结构 SERVICE_TABLE_ENTRYA DispatchTable[2] = { {(char*)GetServiceName(), (LPSERVICE_MAIN_FUNCTIONA)GetServiceStartFunction()}, {NULL, NULL} }; if ( m_vm.count("help") ) { /// 帮助 std::cout << opts << std::endl; } else if ( m_vm.count("install") ) { bool bAutoStart = (m_vm.count("auto-start") > 0); /// 安装服务 if ( Install(bAutoStart) ) { std::cout << "安装成功!" << std::endl; OnInstall(bAutoStart); } else std::cout << "安装失败!" << std::endl; } else if ( m_vm.count("uninstall") ) { /// 卸载服务 if ( Uninstall() ) std::cout << "卸载成功!" << std::endl; else std::cout << "卸载失败!" << std::endl; } else { /// OS启动该程序 BOOL bSuccessed = ::StartServiceCtrlDispatcherA(DispatchTable); //if (bSuccessed) // LOG << "服务入口函数注册成功!" << std::endl; //else // LOG << "服务入口函数注册失败!" << std::endl; } return 0; }
void GTicketInternalClient::ServiceInfo(strstream & s) { boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); string t; IsConnection()?t=to_simple_string(connected):t=to_simple_string(disconnected); s<<boost::format("%|-8d|%|-12s|%|-20s|%|-12s|%|-22s|%|-10d|%|-10d|%|-11d|%|-10d|")% client_service_group % GetServiceName(client_service_type) % AddrToString(addr)() % (IsConnection()?"Connected":"Error") %t % (sequence_number-1) % (int)out.size() % (int)wait.size() % (int)(last_latency / GSECOND_1); s<<lend; }
void LogServer::OnInnerNetMsg(int nSessionID, Packet* poPacket) { assert(poPacket != NULL); INNER_HEADER oHeader; int* pSessionArray = NULL; if (!poPacket->GetInnerHeader(oHeader, &pSessionArray, true)) { XLog(LEVEL_INFO, "%s: Get inner header fail\n", GetServiceName()); poPacket->Release(__FILE__, __LINE__); return; } if (oHeader.uTarServer != g_poContext->GetServerID() || oHeader.nTarService != GetServiceID()) { XLog(LEVEL_INFO, "%s: Tar server:%d service:%d error\n", GetServiceName(), oHeader.uTarServer, oHeader.nTarService); poPacket->Release(__FILE__, __LINE__); return; } g_poContext->GetPacketHandler()->OnRecvInnerPacket(nSessionID, poPacket, oHeader, pSessionArray); }
void ServiceFrameworkBase::HandleSyncRequest(Kernel::HLERequestContext& context) { u32 header_code = context.CommandBuffer()[0]; auto itr = handlers.find(header_code); const FunctionInfoBase* info = itr == handlers.end() ? nullptr : &itr->second; if (info == nullptr || info->handler_callback == nullptr) { return ReportUnimplementedFunction(context.CommandBuffer(), info); } LOG_TRACE(Service, "{}", MakeFunctionString(info->name, GetServiceName(), context.CommandBuffer())); handler_invoker(this, info->handler_callback, context); }
//-------------------------------------------------------------------------------- BOOL CNTService::InstallService() { AFX_MANAGE_STATE_IF_DLL TCHAR szPath[1024]; if(GetModuleFileName( 0, szPath, 1023 ) == 0 ) return FALSE; BOOL bRet = FALSE; SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if(schSCManager != NULL) { DWORD nServiceType = GetServiceType(); DWORD nStartType = GetStartType(); SC_HANDLE schService = CreateService( schSCManager, GetServiceName(), GetDisplayName(), GetDesiredAccess(), nServiceType, nStartType, GetErrorControl(), szPath, GetLoadOrderGroup(), ((nServiceType == SERVICE_KERNEL_DRIVER || nServiceType == SERVICE_FILE_SYSTEM_DRIVER) && (nStartType == SERVICE_BOOT_START || nStartType == SERVICE_SYSTEM_START)) ? &m_dwTagID : NULL, GetDependencies(), GetUserName(), GetPassword() ); if(schService != NULL) { CloseServiceHandle(schService); bRet = TRUE; } CloseServiceHandle(schSCManager); } if(bRet) // installation succeeded. Now register the message file RegisterApplicationLog(szPath, EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE); return bRet; }
QList<IDataFilter::FilterVariant> Plugin::GetFilterVariants (const QVariant&) const { QList<IDataFilter::FilterVariant> result; for (auto acc : AccountsMgr_->GetAccounts ()) { if (!qobject_cast<ISupportUploads*> (acc->GetQObject ())) continue; const auto accService = acc->GetService (); accService->GetServiceIcon (); result.append ({ acc->GetID (), acc->GetName () + " (" + accService->GetServiceName () + ")", tr ("Upload image to account %1 at %2.") .arg (acc->GetName ()) .arg (accService->GetServiceName ()), accService->GetServiceIcon () }); } return result; }
int32 RunRemoteBlastJobs (Service *service_p, ServiceJobSet *jobs_p, ParameterSet *params_p, PairedService *paired_service_p, ProvidersStateTable *providers_p) { int32 num_successful_runs = -1; json_t *res_p = MakeRemotePairedServiceCall (GetServiceName (service_p), params_p, paired_service_p -> ps_server_uri_s, providers_p); if (res_p) { BlastServiceData *data_p = (BlastServiceData *) service_p -> se_data_p; num_successful_runs = AddRemoteResultsToServiceJobs (res_p, jobs_p, paired_service_p -> ps_name_s, paired_service_p -> ps_server_uri_s, data_p); json_decref (res_p); } /* if (res_p) */ return num_successful_runs; }
void RecommendationsWidget::on_RecProvider__activated (int index) { if (index < 0 || index >= Providers_.size ()) return; auto pending = Providers_.at (index)->RequestRecommended (10); connect (pending->GetQObject (), SIGNAL (ready ()), this, SLOT (handleGotRecs ())); auto scrob = qobject_cast<Media::IAudioScrobbler*> (ProvRoots_.at (index)); XmlSettingsManager::Instance () .setProperty ("LastUsedRecsProvider", scrob->GetServiceName ()); }
BOOL CService::Stop () { SC_HANDLE hSCM = NULL; SC_HANDLE hService = NULL; BOOL bResult = FALSE; do { if (!GetServiceName ()) break; hSCM = OpenSCManager (_scmHost (GetHost ()), NULL, GENERIC_READ); if (!hSCM) break; hService = OpenService (hSCM, GetServiceName (), SERVICE_STOP); if (!hService) break; SERVICE_STATUS status; if (!ControlService (hService, SERVICE_CONTROL_STOP, &status)) break; bResult = TRUE; } while (FALSE); int nError = bResult ? 0 : GetLastError (); if (hSCM) CloseServiceHandle (hSCM); if (hService) CloseServiceHandle (hService); if (bResult) { return TRUE; } else { SetLastError (nError); return FALSE; } }
//-------------------------------------------------------------------------------- BOOL CNTService::StartDispatcher() { AFX_MANAGE_STATE_IF_DLL // Default implementation creates a single threaded service. // Override this method and provide more table entries for // a multithreaded service (one entry for each thread). SERVICE_TABLE_ENTRY dispatchTable[] = { { LPTSTR(GetServiceName()), (LPSERVICE_MAIN_FUNCTION)ServiceMain }, { 0, 0 } }; if(! StartServiceCtrlDispatcher(dispatchTable)) return false; return true; }
bool win_svc_base::Install(bool bAutoStart) { SC_HANDLE schSCMgr, schService; char szPath[MAX_PATH] = {}; if (!::GetModuleFileNameA(NULL, szPath, sizeof(szPath))) return false; /// 打开服务管理数据库 schSCMgr = ::OpenSCManagerA(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (!schSCMgr) { std::cout << "服务管理数据库打开失败!" << std::endl; return false; } schService = ::CreateServiceA( schSCMgr, ///< 服务管理数据库句柄 GetServiceName(), ///< 服务名 GetShowName(), ///< 用于显示服务的标识 SERVICE_ALL_ACCESS, ///< 响应所有的访问请求 SERVICE_WIN32_OWN_PROCESS, ///< 服务类型(独占一个进程) bAutoStart ? SERVICE_AUTO_START : SERVICE_DEMAND_START, ///< 启动类型(手动启动) SERVICE_ERROR_NORMAL, ///< 错误控制类型 szPath, ///< 服务程序路径 NULL, ///< 服务不属于任何组 NULL, ///< 没有tag标识符 NULL, ///< 启动服务所依赖的服务或服务组,这里仅仅是一个空字符串 NULL, ///< LocalSystem 帐号 NULL ); if (!schService) { std::cout << "服务创建失败!" << std::endl; ::CloseServiceHandle(schSCMgr); return false; } ::CloseServiceHandle(schService); ::CloseServiceHandle(schSCMgr); return true; }
//-------------------------------------------------------------------------------- BOOL CNTService::StartupService() { AFX_MANAGE_STATE_IF_DLL BOOL bRet = FALSE; SC_HANDLE schSCManager = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if(schSCManager != NULL) { QUERY_SERVICE_CONFIG serviceConfig; ::QueryServiceConfig(schSCManager, &serviceConfig, sizeof(serviceConfig), NULL); SC_HANDLE schService = ::OpenService(schSCManager, GetServiceName(), SERVICE_ALL_ACCESS); if(schService != NULL) { // try to start the service if(::StartService(schService, 0, 0) ) { Sleep(1000); while(::QueryServiceStatus(schService, &m_ssStatus) ) { if(m_ssStatus.dwCurrentState == SERVICE_START_PENDING ) ::Sleep(1000); else break; } bRet = (m_ssStatus.dwCurrentState == SERVICE_RUNNING); } ::CloseServiceHandle(schService); } ::CloseServiceHandle(schSCManager); } return bRet; }
//-------------------------------------------------------------------------------- BOOL CNTService::RemoveService() { AFX_MANAGE_STATE_IF_DLL BOOL bRet = FALSE; SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if(schSCManager != NULL) { SC_HANDLE schService = OpenService(schSCManager, GetServiceName(), SERVICE_ALL_ACCESS); if(schService != NULL) { // try to stop the service if(ControlService(schService, SERVICE_CONTROL_STOP, &m_ssStatus) ) { Sleep(1000); while(QueryServiceStatus(schService, &m_ssStatus) ) { if(m_ssStatus.dwCurrentState == SERVICE_STOP_PENDING ) ::Sleep(1000); else break; } } // now remove the service bRet = DeleteService(schService) != 0; CloseServiceHandle(schService); } CloseServiceHandle(schSCManager); } if(bRet) DeregisterApplicationLog(); return bRet; }
bool win_svc_base::Uninstall() { SC_HANDLE schSCMgr = ::OpenSCManagerA(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (!schSCMgr) { std::cout << "服务管理数据库打开失败!" << std::endl; return false; } SC_HANDLE schService = ::OpenServiceA(schSCMgr, GetServiceName(), SERVICE_ALL_ACCESS); if (!schService) { std::cout << "服务打开失败!" << std::endl; ::CloseServiceHandle(schSCMgr); return false; } BOOL bDeleted = ::DeleteService(schService); ::CloseServiceHandle(schService); ::CloseServiceHandle(schSCMgr); return (bDeleted ? true : false); }
void RadioManager::InitProviders () { InitProvider (new RadioCustomStreams (this)); auto pm = Core::Instance ().GetProxy ()->GetPluginsManager (); auto pileObjs = pm->GetAllCastableRoots<Media::IAudioPile*> (); for (auto pileObj : pileObjs) { auto pile = qobject_cast<Media::IAudioPile*> (pileObj); auto item = new QStandardItem (tr ("Search in %1") .arg (pile->GetServiceName ())); item->setIcon (pile->GetServiceIcon ()); item->setEditable (false); item->setData (QVariant::fromValue (pileObj), RadioWidgetRole::PileObject); StationsModel_->appendRow (item); } auto providerObjs = pm->GetAllCastableRoots<Media::IRadioStationProvider*> (); for (auto provObj : providerObjs) InitProvider (provObj); }
//-------------------------------------------------------------------------------- BOOL CNTService::EndService() { AFX_MANAGE_STATE_IF_DLL BOOL bRet = FALSE; SC_HANDLE schSCManager = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if(schSCManager != NULL) { SC_HANDLE schService = ::OpenService(schSCManager, GetServiceName(), SERVICE_ALL_ACCESS); if(schService != NULL) { // try to stop the service if(::ControlService(schService, SERVICE_CONTROL_STOP, &m_ssStatus)) { ::Sleep(1000); while(::QueryServiceStatus(schService, &m_ssStatus)) { if(m_ssStatus.dwCurrentState == SERVICE_STOP_PENDING) ::Sleep(1000); else break; } bRet = (m_ssStatus.dwCurrentState == SERVICE_STOPPED); } ::CloseServiceHandle(schService); } ::CloseServiceHandle(schSCManager); } return bRet; }
/// 安装成功回调 void win_svc_base::OnInstall( bool bAutoStart ) { if ( bAutoStart ) { SC_HANDLE schSCMgr = ::OpenSCManagerA(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (!schSCMgr) { std::cout << "服务管理数据库打开失败!" << std::endl; return ; } SC_HANDLE schService = ::OpenServiceA(schSCMgr, GetServiceName(), SERVICE_ALL_ACCESS); if (!schService) { std::cout << "服务打开失败!" << std::endl; ::CloseServiceHandle(schSCMgr); return ; } ::StartServiceA(schService, 0, NULL); ::CloseServiceHandle(schService); ::CloseServiceHandle(schSCMgr); } }
void GTicketInternalClient::PreProcessMessage(int message, GNetTarget & target) { if(target.number==0) return; last_connection_activity = GSERVER->GetClock().Get(); list<GTicketPtr>::iterator pos; pos=find_if(wait.begin(),wait.end(),isTarget(target.number)); if(pos!=wait.end()) { if (target.timestamp > 0) { last_latency = GSERVER->GetClock().Get() - target.timestamp; if (last_latency >= GSECOND_1) { SNetMsgDesc * format; format = msg_base.Get((*pos)->message, ENetCmdInternal); string m; if (format) { m = format->name; } RAPORT("Long Ticket acknowledgment latency: %5lld ms. %s:%s%s", last_latency, GetServiceName(client_service_type), m.c_str(), pos == wait.begin() ? "" : " (not in order)"); } } if(pos!=wait.begin()) { string stable_sequence_identifier = (*pos)->stable_sequence_identifier; wait.erase(pos); list<GTicketPtr>::iterator it; for (it = wait.begin(); it != wait.end(); ) { if ((*it)->OldLoop()) { if (dropped_ticket_callback) { dropped_ticket_callback(**it, ETDR_TooManyRetries); } it = wait.erase(it); } else { it++; } } wait.erase(wait.begin(),find_if(wait.begin(),wait.end(),boost::bind(>icketInternalClient::RollbackTicket,this,_1,target.number,stable_sequence_identifier))); SRAP(WARNING_LOGIC_ROLLBACK); } else { wait.erase(pos); } } else { list<GTicketPtr>::iterator pos; pos=find_if(out.begin(),out.end(),isTarget(target.number)); if(pos!=out.end()) { out.erase(pos); SRAP(WARNING_LOGIC_OUT_ERASE); } } }
void GServerBaseConsole::AnalizeAcceptConsole(epoll_event * ev) { if(ev->events & (EPOLLERR|EPOLLHUP)) { SRAP(ERROR_CONSOLE_ACCEPT_ERROR); RAPORT(GSTR(ERROR_CONSOLE_ACCEPT_ERROR)); return; } unsigned int accept_count=0; SOCKET client_sock=0; struct sockaddr_in client_addr; DWORD addr; while (client_sock != -1 && accept_count<global_serverconfig->net.accept_limit && poll_manager.Free()) { socklen_t sin_size=sizeof(struct sockaddr_in); GSocketConsole * s=reinterpret_cast<GSocketConsole*>(ev->data.ptr); SOCKET fd=s->GetSocket(); client_sock=accept(fd,(struct sockaddr *)&client_addr,&sin_size); if(client_sock==-1) break; memcpy(&addr,&client_addr.sin_addr,4); accept_count++; SRAP(INFO_CONSOLE_ACCEPT_COUNT); GSocketConsole* socket=SocketConsoleAdd(); if(socket) { GPollManager & pm=poll_manager; GMemoryManager & mm=memory_manager; socket->Init(raport_interface,client_sock,GetServiceTypeAssociate(s->GetServiceType()),&mm,&pm); socket->SetTimeConnection(clock.Get()); if(socket->RegisterPoll()) { socket->AllocateOut(); socket->MemoryOut()<<GetServiceName(s->GetServiceType()); socket->MemoryOut()<<lend; socket->Write(); } else { SRAP(ERROR_CONSOLE_REGISTER_POLL); GSTR(ERROR_CONSOLE_REGISTER_POLL); SocketConsoleRemove(socket); } } else { closesocket(client_sock); } } if(client_sock != -1) { if(accept_count==global_serverconfig->net.accept_limit) { SRAP(WARNING_SERVER_ACCEPT_LIMIT_EXCEED); RAPORT(GSTR(WARNING_SERVER_ACCEPT_LIMIT_EXCEED)); } if(!poll_manager.Free()) { SRAP(WARNING_SERVER_POLL_LIMIT_EXCEED); RAPORT(GSTR(WARNING_SERVER_POLL_LIMIT_EXCEED)); } } }
BOOL CService::SetAutoStart (BOOL bAutoStart) { SC_HANDLE hSCM = NULL; SC_HANDLE hService = NULL; LPQUERY_SERVICE_CONFIG lpqsc = NULL; BOOL bResult = FALSE; do { if (!GetServiceName ()) break; hSCM = OpenSCManager (_scmHost (GetHost ()), NULL, GENERIC_READ); if (!hSCM) break; hService = OpenService (hSCM, GetServiceName (), SERVICE_QUERY_CONFIG | SERVICE_CHANGE_CONFIG); if (!hService) break; DWORD dwBytes = 1024; do { DWORD dwBytesNeeded; lpqsc = (LPQUERY_SERVICE_CONFIG)new BYTE[dwBytes]; if (!lpqsc) break; if (!QueryServiceConfig (hService, lpqsc, dwBytes, &dwBytesNeeded)) { if (GetLastError () == ERROR_INSUFFICIENT_BUFFER) { delete lpqsc; lpqsc = NULL; dwBytes = dwBytesNeeded; continue; } } break; } while (TRUE); if (!lpqsc) break; if (bAutoStart) { if (lpqsc->dwStartType == SERVICE_AUTO_START) { bResult = TRUE; break; } } else { if (lpqsc->dwStartType == SERVICE_DEMAND_START) { bResult = TRUE; break; } } if (!ChangeServiceConfig ( hService, SERVICE_NO_CHANGE, bAutoStart ? SERVICE_AUTO_START : SERVICE_DEMAND_START, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) break; bResult = TRUE; } while (FALSE); int nError = bResult ? 0 : GetLastError (); if (hSCM) CloseServiceHandle (hSCM); if (hService) CloseServiceHandle (hService); delete lpqsc; if (bResult) { return TRUE; } else { SetLastError (nError); return FALSE; } }
int main(int ac, _TCHAR** av) { int error; struct _THREAD_PARAM InputThreadParam; HANDLE InputEventHandle; HANDLE InputThreadHandle; SC_HANDLE ManagerHandle; SC_HANDLE ServiceHandle; _TCHAR* DriverPath; _TCHAR* ServiceName; HKEY ServiceKey; void* Cmdline; DWORD CmdlineLength; SERVICE_STATUS ServiceStatus; BOOLEAN isDone; DWORD res; _TCHAR KeyName[1024]; if (ac == 1) { printf("%s: <driver> <avs>\n", av[0]); return -1; } DriverPath = GetFullPath(av[1]); if (DriverPath == NULL) { printf("GetFullPath() == NULL\n"); return -1; } ServiceName = GetServiceName(DriverPath); if (ServiceName == NULL) { printf("GetServiceName() == NULL\n"); return -1; } Cmdline = AvToMultiRegSz(av + 2, &CmdlineLength); if (Cmdline == NULL) { printf("AvToMultiRegSz() == NULL\n"); return -1; } error = -1; InputEventHandle = NULL; InputThreadHandle = NULL; ServiceKey = NULL; ManagerHandle = NULL; ServiceHandle = NULL; ManagerHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (ManagerHandle == NULL) { printf("OpenSCManager() == %u\n", GetLastError()); goto Cleanup; } /* remove the serice if already exist */ ServiceHandle = OpenService(ManagerHandle, ServiceName, SC_MANAGER_ALL_ACCESS); if (ServiceHandle != NULL) { if (DeleteService(ServiceHandle) == FALSE) { printf("DeleteService() == %u\n", GetLastError()); goto Cleanup; } ServiceHandle = NULL; } /* create the service */ ServiceHandle = CreateService(ManagerHandle, ServiceName, ServiceName, SC_MANAGER_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_IGNORE, DriverPath, NULL, NULL, NULL, NULL, NULL); if (ServiceHandle == NULL) { printf("CreateService() == %u\n", GetLastError()); goto Cleanup; } /* set registry */ _tcscpy(KeyName, _T("SYSTEM\\CurrentControlSet\\Services\\")); _tcscat(KeyName, ServiceName); if (RegOpenKey(HKEY_LOCAL_MACHINE, KeyName, &ServiceKey) != ERROR_SUCCESS) { printf("RegOpenKey() == %u\n", GetLastError()); goto Cleanup; } if (RegSetValueEx(ServiceKey, _T("Cmdline"), 0, REG_MULTI_SZ, Cmdline, CmdlineLength) != ERROR_SUCCESS) { printf("RegSetKeyValue() == %u\n", GetLastError()); goto Cleanup; } /* input thread */ InputEventHandle = CreateEvent(NULL, TRUE, FALSE, NULL); if (InputEventHandle == NULL) { printf("CreateEvent() == %u\n", GetLastError()); goto Cleanup; } InputThreadParam.InputEventHandle = InputEventHandle; InputThreadHandle = CreateThread(NULL, 0, InputThreadRoutine, &InputThreadParam, 0, NULL); if (InputThreadHandle == NULL) { printf("CreateThread() == %u\n", GetLastError()); goto Cleanup; } /* start the service */ if (StartService(ServiceHandle, 0, NULL) == FALSE) { printf("StartService() == %u\n", GetLastError()); goto Cleanup; } #if 0 /* VISTA */ { EventHandle = CreateHandle(); if (EventHandle) { printf("CreateEvent() == %u\n", GetLastError()); goto Cleanup; } memset(&ServiceNotify, 0, sizeof(ServiceNotify)); ServiceNotify.dwVersion = SERVICE_NOTIFY_STATUS_CHANGE; ServiceNotify.pfnNotifyCallback = onServiceChange; ServiceNotify.pContext = &EventHandle; NotifyServiceStatusChange(ServiceHandle, SERVICE_NOTIFY_STOPPED, &ServiceNotify); WaitForSingleObject(EventHandle, INFINITE); } #else /* ! VISTA */ { /* wait for the service to be stopped */ isDone = FALSE; while (isDone == FALSE) { res = WaitForSingleObject(InputEventHandle, 1000); if (res == WAIT_OBJECT_0) ControlService(ServiceHandle, SERVICE_CONTROL_STOP, &ServiceStatus); if (QueryServiceStatus(ServiceHandle, &ServiceStatus) == FALSE) { printf("QueryServiceStatus() == %u\n", GetLastError()); ControlService(ServiceHandle, SERVICE_CONTROL_STOP, &ServiceStatus); goto Cleanup; } if (ServiceStatus.dwCurrentState == SERVICE_STOPPED) { if (ServiceStatus.dwWin32ExitCode == ERROR_SERVICE_SPECIFIC_ERROR) error = ServiceStatus.dwServiceSpecificExitCode; else error = ServiceStatus.dwWin32ExitCode; isDone = TRUE; } } } #endif /* VISTA */ /* success */ Cleanup: if (InputThreadHandle != NULL) { TerminateThread(InputThreadHandle, 0); CloseHandle(InputThreadHandle); } if (InputEventHandle != NULL) CloseHandle(InputEventHandle); if (Cmdline != NULL) free(Cmdline); if (ServiceKey != NULL) RegCloseKey(ServiceKey); if (ServiceHandle != NULL) { if (DeleteService(ServiceHandle) == FALSE) printf("DeleteService() == %u\n", GetLastError()); CloseServiceHandle(ServiceHandle); } if (ManagerHandle != NULL) CloseServiceHandle(ManagerHandle); return error; }
char *GetPreviousRemoteBlastServiceJob (const char *local_job_id_s, const uint32 output_format_code, const BlastServiceData *blast_data_p) { char *result_s = NULL; char *job_filename_s = GetLocalJobFilename (local_job_id_s, blast_data_p); if (job_filename_s) { json_error_t e; json_t *remote_p = json_load_file (job_filename_s, 0, &e); if (remote_p) { /* * This json_t should consist of the remote server's uri and the uuid * of the job on that server */ const char *uri_s = GetJSONString (remote_p, JOB_REMOTE_URI_S); if (uri_s) { const char *remote_job_id_s = GetJSONString (remote_p, JOB_REMOTE_UUID_S); if (remote_job_id_s) { /* * Make the call to the remote server for the previous results * using this id */ ParameterSet *param_set_p = AllocateParameterSet ("Blast service parameters", "The parameters used for the Blast service"); ParameterGroup *group_p = NULL; if (param_set_p) { Parameter *param_p = SetUpPreviousJobUUIDParamater (blast_data_p, param_set_p, group_p); if (param_p) { if (SetParameterValue (param_p, remote_job_id_s, true)) { param_p = SetUpOutputFormatParamater (blast_data_p, param_set_p, group_p); if (param_p) { if (SetParameterValue (param_p, &output_format_code, true)) { Service *service_p = blast_data_p -> bsd_base_data.sd_service_p; if (service_p) { const char *service_name_s = GetServiceName (blast_data_p -> bsd_base_data.sd_service_p); if (service_name_s) { json_t *res_p = MakeRemotePairedServiceCall (service_name_s, param_set_p, uri_s, NULL); if (res_p) { int32 num_added = AddRemoteResultsToServiceJobs (res_p, service_p -> se_jobs_p, service_name_s, uri_s, blast_data_p); #if PAIRED_BLAST_SERVICE_DEBUG >= STM_LEVEL_FINE PrintLog (STM_LEVEL_FINE, __FILE__, __LINE__, "Added " INT32_FMT " jobs from remote results"); #endif json_decref (res_p); } /* if (res_p) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "MakeRemotePairedServiceCall to \"%s\" at \"%s\" with param set to \"%s\" returned NULL", service_name_s, uri_s, param_p -> pa_current_value.st_string_value_s); } } /* if (service_name_s) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get Blast service name"); } } /* if (service_p) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to set get Blast service"); } } /* if (SetParameterValue (param_p, &output_format_code, true)) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to set Parameter value for out put format to " UINT32_FMT, output_format_code); } } else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to create Parameter for output format"); } } /* if (SetParameterValue (param_p, remote_job_id_s, true)) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to set Parameter value for previous job ids to \"%s\"", remote_job_id_s); } } /* if (param_p) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to create Parameter for previous job ids"); } FreeParameterSet (param_set_p); } /* if (param_set_p) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to allocate ParamaterSet"); } } /* if (remote_job_id_s) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get \"%s\" from \"%s\"", JOB_REMOTE_UUID_S, job_filename_s); } } /* if (uri_s) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get \"%s\" from \"%s\"", JOB_REMOTE_UUID_S, job_filename_s); } json_decref (remote_p); } /* if (remote_p) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to load remote json data from \"%s\", error at line %d, col %d, \"%s\"", job_filename_s, e.line, e.column, e.text); } FreeCopiedString (job_filename_s); } /* if (job_filename_s) */ else { PrintErrors (STM_LEVEL_WARNING, __FILE__, __LINE__, "Failed to get output filename for \"%s\"", local_job_id_s); } return result_s; }
// WinMain parses the command line and either calls the main App // routine or, under NT, the main service routine. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { if (VNCOS.OS_NOTSUPPORTED==true) { MessageBoxSecure(NULL, "Error OS not supported","Unsupported OS", MB_ICONERROR); return true; } // make vnc last service to stop SetProcessShutdownParameters(0x100,false); // handle dpi on aero /*HMODULE hUser32 = LoadLibrary(_T("user32.dll")); typedef BOOL (*SetProcessDPIAwareFunc)(); SetProcessDPIAwareFunc setDPIAware=NULL; if (hUser32) setDPIAware = (SetProcessDPIAwareFunc)GetProcAddress(hUser32, "SetProcessDPIAware"); if (setDPIAware) setDPIAware(); if (hUser32) FreeLibrary(hUser32);*/ #ifdef IPP InitIpp(); #endif #ifdef CRASHRPT CR_INSTALL_INFO info; memset(&info, 0, sizeof(CR_INSTALL_INFO)); info.cb = sizeof(CR_INSTALL_INFO); info.pszAppName = _T("UVNC"); info.pszAppVersion = _T("1.2.0.9"); info.pszEmailSubject = _T("UVNC server 1.2.0.9 Error Report"); info.pszEmailTo = _T("*****@*****.**"); info.uPriorities[CR_SMAPI] = 1; // Third try send report over Simple MAPI // Install all available exception handlers info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS; // Restart the app on crash info.dwFlags |= CR_INST_APP_RESTART; info.dwFlags |= CR_INST_SEND_QUEUED_REPORTS; info.dwFlags |= CR_INST_AUTO_THREAD_HANDLERS; info.pszRestartCmdLine = _T("/restart"); // Define the Privacy Policy URL // Install crash reporting int nResult = crInstall(&info); if (nResult != 0) { // Something goes wrong. Get error message. TCHAR szErrorMsg[512] = _T(""); crGetLastErrorMsg(szErrorMsg, 512); _tprintf_s(_T("%s\n"), szErrorMsg); return 1; } #endif bool Injected_autoreconnect=false; SPECIAL_SC_EXIT=false; SPECIAL_SC_PROMPT=false; setbuf(stderr, 0); // [v1.0.2-jp1 fix] Load resouce from dll hInstResDLL = NULL; //limit the vnclang.dll searchpath to avoid char szCurrentDir[MAX_PATH]; char szCurrentDir_vnclangdll[MAX_PATH]; if (GetModuleFileName(NULL, szCurrentDir, MAX_PATH)) { char* p = strrchr(szCurrentDir, '\\'); *p = '\0'; } strcpy (szCurrentDir_vnclangdll,szCurrentDir); strcat (szCurrentDir_vnclangdll,"\\"); strcat (szCurrentDir_vnclangdll,"vnclang_server.dll"); hInstResDLL = LoadLibrary(szCurrentDir_vnclangdll); if (hInstResDLL == NULL) { hInstResDLL = hInstance; } // RegisterLinkLabel(hInstResDLL); //Load all messages from ressource file Load_Localization(hInstResDLL) ; char WORKDIR[MAX_PATH]; if (GetModuleFileName(NULL, WORKDIR, MAX_PATH)) { char* p = strrchr(WORKDIR, '\\'); if (p == NULL) return 0; *p = '\0'; } char progname[MAX_PATH]; strncpy(progname, WORKDIR, sizeof progname); progname[MAX_PATH - 1] = 0; //strcat(WORKDIR,"\\"); //strcat(WORKDIR,"WinVNC.log"); vnclog.SetFile(); //vnclog.SetMode(4); //vnclog.SetLevel(10); #ifdef _DEBUG { // Get current flag int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ); // Turn on leak-checking bit tmpFlag |= _CRTDBG_LEAK_CHECK_DF; // Set flag to the new value _CrtSetDbgFlag( tmpFlag ); } #endif // Save the application instance and main thread id hAppInstance = hInstance; mainthreadId = GetCurrentThreadId(); // Initialise the VSocket system VSocketSystem socksys; if (!socksys.Initialised()) { MessageBoxSecure(NULL, sz_ID_FAILED_INIT, szAppName, MB_OK); #ifdef CRASHRPT crUninstall(); #endif return 0; } // look up the current service name in the registry. GetServiceName(progname, service_name); // Make the command-line lowercase and parse it size_t i; for (i = 0; i < strlen(szCmdLine); i++) { szCmdLine[i] = tolower(szCmdLine[i]); } BOOL argfound = FALSE; for (i = 0; i < strlen(szCmdLine); i++) { if (szCmdLine[i] <= ' ') continue; argfound = TRUE; if (strncmp(&szCmdLine[i], winvncSettingshelper, strlen(winvncSettingshelper)) == 0) { Sleep(3000); char mycommand[MAX_PATH]; i+=strlen(winvncSettingshelper); strcpy( mycommand, &(szCmdLine[i+1])); Set_settings_as_admin(mycommand); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncStopserviceHelper, strlen(winvncStopserviceHelper)) == 0) { Sleep(3000); Set_stop_service_as_admin(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncKill, strlen(winvncKill)) == 0) { static HANDLE hShutdownEventTmp; hShutdownEventTmp = OpenEvent(EVENT_ALL_ACCESS, FALSE, "Global\\SessionEventUltra"); SetEvent(hShutdownEventTmp); CloseHandle(hShutdownEventTmp); //adzm 2010-02-10 - Finds the appropriate VNC window for any process. Sends this message to all of them! // do removed, loops forever with cpu 100 HWND hservwnd = NULL; hservwnd = FindWinVNCWindow(false); if (hservwnd!=NULL) { PostMessage(hservwnd, WM_COMMAND, 40002, 0); PostMessage(hservwnd, WM_CLOSE, 0, 0); } #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncopenhomepage, strlen(winvncopenhomepage)) == 0) { Open_homepage(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncopenforum, strlen(winvncopenforum)) == 0) { Open_forum(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncStartserviceHelper, strlen(winvncStartserviceHelper)) == 0) { Sleep(3000); Set_start_service_as_admin(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncInstallServiceHelper, strlen(winvncInstallServiceHelper)) == 0) { //Sleeps are realy needed, else runas fails... Sleep(3000); Set_install_service_as_admin(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncUnInstallServiceHelper, strlen(winvncUnInstallServiceHelper)) == 0) { Sleep(3000); Set_uninstall_service_as_admin(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncSoftwarecadHelper, strlen(winvncSoftwarecadHelper)) == 0) { Sleep(3000); Enable_softwareCAD_elevated(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncdelSoftwarecadHelper, strlen(winvncdelSoftwarecadHelper)) == 0) { Sleep(3000); delete_softwareCAD_elevated(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncRebootSafeHelper, strlen(winvncRebootSafeHelper)) == 0) { Sleep(3000); Reboot_in_safemode_elevated(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncRebootForceHelper, strlen(winvncRebootForceHelper)) == 0) { Sleep(3000); Reboot_with_force_reboot_elevated(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncSecurityEditorHelper, strlen(winvncSecurityEditorHelper)) == 0) { Sleep(3000); winvncSecurityEditorHelper_as_admin(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncSecurityEditor, strlen(winvncSecurityEditor)) == 0) { typedef void (*vncEditSecurityFn) (HWND hwnd, HINSTANCE hInstance); vncEditSecurityFn vncEditSecurity = 0; char szCurrentDirl[MAX_PATH]; if (GetModuleFileName(NULL, szCurrentDirl, MAX_PATH)) { char* p = strrchr(szCurrentDirl, '\\'); *p = '\0'; strcat (szCurrentDirl,"\\authSSP.dll"); } HMODULE hModule = LoadLibrary(szCurrentDirl); if (hModule) { vncEditSecurity = (vncEditSecurityFn) GetProcAddress(hModule, "vncEditSecurity"); HRESULT hr = CoInitialize(NULL); vncEditSecurity(NULL, hAppInstance); CoUninitialize(); FreeLibrary(hModule); } #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncSettings, strlen(winvncSettings)) == 0) { char mycommand[MAX_PATH]; i+=strlen(winvncSettings); strcpy( mycommand, &(szCmdLine[i+1])); Real_settings(mycommand); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], dsmpluginhelper, strlen(dsmpluginhelper)) == 0) { char mycommand[MAX_PATH]; i += strlen(dsmpluginhelper); strcpy(mycommand, &(szCmdLine[i + 1])); Secure_Plugin_elevated(mycommand); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], dsmplugininstance, strlen(dsmplugininstance)) == 0) { char mycommand[MAX_PATH]; i += strlen(dsmplugininstance); strcpy(mycommand, &(szCmdLine[i + 1])); Secure_Plugin(mycommand); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncSoftwarecad, strlen(winvncSoftwarecad)) == 0) { Enable_softwareCAD(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncdelSoftwarecad, strlen(winvncdelSoftwarecad)) == 0) { delete_softwareCAD(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncRebootSafe, strlen(winvncRebootSafe)) == 0) { Reboot_in_safemode(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncRebootForce, strlen(winvncRebootForce)) == 0) { Reboot_with_force_reboot(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncStopservice, strlen(winvncStopservice)) == 0) { Real_stop_service(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncStartservice, strlen(winvncStartservice)) == 0) { Real_start_service(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncInstallService, strlen(winvncInstallService)) == 0) { // rest of command line service name, if provided. char *pServiceName = &szCmdLine[i]; // skip over command switch, find next whitepace while (*pServiceName && !isspace(*(unsigned char*)pServiceName)) ++pServiceName; // skip past whitespace to service name while (*pServiceName && isspace(*(unsigned char*)pServiceName)) ++pServiceName; // strip off any quotes if (*pServiceName && *pServiceName == '\"') ++pServiceName; if (*pServiceName) { // look for trailing quote, if found, terminate the string there. char *pQuote = pServiceName; pQuote = strrchr(pServiceName, '\"'); if (pQuote) *pQuote = 0; } // if a service name is supplied, and it differs except in case from // the default, use the supplied service name instead if (*pServiceName && (_strcmpi(pServiceName, service_name) != 0)) { strncpy(service_name, pServiceName, 256); service_name[255] = 0; } install_service(); Sleep(2000); char command[MAX_PATH + 32]; // 29 January 2008 jdp _snprintf(command, sizeof command, "net start \"%s\"", service_name); WinExec(command,SW_HIDE); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncUnInstallService, strlen(winvncUnInstallService)) == 0) { char command[MAX_PATH + 32]; // 29 January 2008 jdp // rest of command line service name, if provided. char *pServiceName = &szCmdLine[i]; // skip over command switch, find next whitepace while (*pServiceName && !isspace(*(unsigned char*)pServiceName)) ++pServiceName; // skip past whitespace to service name while (*pServiceName && isspace(*(unsigned char*)pServiceName)) ++pServiceName; // strip off any quotes if (*pServiceName && *pServiceName == '\"') ++pServiceName; if (*pServiceName) { // look for trailing quote, if found, terminate the string there. char *pQuote = pServiceName; pQuote = strrchr(pServiceName, '\"'); if (pQuote) *pQuote = 0; } if (*pServiceName && (_strcmpi(pServiceName, service_name) != 0)) { strncpy(service_name, pServiceName, 256); service_name[255] = 0; } _snprintf(command, sizeof command, "net stop \"%s\"", service_name); WinExec(command,SW_HIDE); uninstall_service(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncRunService, strlen(winvncRunService)) == 0) { //Run as service if (!Myinit(hInstance)) return 0; fRunningFromExternalService = true; vncService::RunningFromExternalService(true); int returnvalue = WinVNCAppMain(); #ifdef CRASHRPT crUninstall(); #endif return returnvalue; } if (strncmp(&szCmdLine[i], winvncStartService, strlen(winvncStartService)) == 0) { start_service(szCmdLine); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncRunAsUserApp, strlen(winvncRunAsUserApp)) == 0) { // WinVNC is being run as a user-level program if (!Myinit(hInstance)) return 0; int returnvalue = WinVNCAppMain(); #ifdef CRASHRPT crUninstall(); #endif return returnvalue; } if (strncmp(&szCmdLine[i], winvncSCexit, strlen(winvncSCexit)) == 0) { SPECIAL_SC_EXIT=true; i+=strlen(winvncSCexit); continue; } if (strncmp(&szCmdLine[i], winvncSCprompt, strlen(winvncSCprompt)) == 0) { SPECIAL_SC_PROMPT=true; i+=strlen(winvncSCprompt); continue; } if (strncmp(&szCmdLine[i], winvncmulti, strlen(winvncmulti)) == 0) { multi=true; i+=strlen(winvncmulti); continue; } if (strncmp(&szCmdLine[i], winvnchttp, strlen(winvnchttp)) == 0) { G_HTTP=true; i+=strlen(winvnchttp); continue; } if (strncmp(&szCmdLine[i], winvncStopReconnect, strlen(winvncStopReconnect)) == 0) { i+=strlen(winvncStopReconnect); vncService::PostAddStopConnectClientAll(); continue; } if (strncmp(&szCmdLine[i], winvncAutoReconnect, strlen(winvncAutoReconnect)) == 0) { // Note that this "autoreconnect" param MUST be BEFORE the "connect" one // on the command line ! // wa@2005 -- added support for the AutoReconnectId i+=strlen(winvncAutoReconnect); Injected_autoreconnect=true; int start, end; char* pszId = NULL; start = i; // skip any spaces and grab the parameter while (szCmdLine[start] <= ' ' && szCmdLine[start] != 0) start++; if ( strncmp( &szCmdLine[start], winvncAutoReconnectId, strlen(winvncAutoReconnectId) ) == 0 ) { end = start; while (szCmdLine[end] > ' ') end++; if (end - start > 0) { pszId = new char[end - start + 1]; strncpy(pszId, &(szCmdLine[start]), end - start); pszId[end - start] = 0; pszId = _strupr(pszId); } //multiple spaces between autoreconnect and id i = end; }// end of condition we found the ID: parameter // NOTE: id must be NULL or the ID:???? (pointer will get deleted when message is processed) // We can not contact a runnning service, permissions, so we must store the settings // and process until the vncmenu has been started if (!vncService::PostAddAutoConnectClient( pszId )) { PostAddAutoConnectClient_bool=true; if (pszId==NULL) { PostAddAutoConnectClient_bool_null=true; PostAddAutoConnectClient_bool=false; } else { strcpy(pszId_char,pszId); //memory leak fix delete[] pszId; pszId = NULL; } } if (pszId != NULL) delete[] pszId; pszId = NULL; continue; } if ( strncmp( &szCmdLine[i], winvncReconnectId, strlen(winvncReconnectId) ) == 0 ) { i+=strlen("-"); int start, end; char* pszId = NULL; start = i; end = start; while (szCmdLine[end] > ' ') end++; if (end - start > 0) { pszId = new char[end - start + 1]; if (pszId != 0) { strncpy(pszId, &(szCmdLine[start]), end - start); pszId[end - start] = 0; pszId = _strupr(pszId); } } i = end; if (!vncService::PostAddConnectClient( pszId )) { PostAddConnectClient_bool=true; if (pszId==NULL) { PostAddConnectClient_bool_null=true; PostAddConnectClient_bool=false; } else { strcpy(pszId_char,pszId); //memory leak fix delete[] pszId; pszId = NULL; } } if (pszId != NULL) delete[] pszId; pszId = NULL; continue; } if (strncmp(&szCmdLine[i], winvncConnect, strlen(winvncConnect)) == 0) { if (!Injected_autoreconnect) { vncService::PostAddStopConnectClient(); } // Add a new client to an existing copy of winvnc i+=strlen(winvncConnect); // First, we have to parse the command line to get the filename to use int start, end; start=i; while (szCmdLine[start] <= ' ' && szCmdLine[start] != 0) start++; end = start; while (szCmdLine[end] > ' ') end++; // Was there a hostname (and optionally a port number) given? if (end-start > 0) { char *name = new char[end-start+1]; if (name != 0) { strncpy(name, &(szCmdLine[start]), end-start); name[end-start] = 0; int port = INCOMING_PORT_OFFSET; char *portp = strchr(name, ':'); if (portp) { *portp++ = '\0'; if (*portp == ':') { port = atoi(++portp); // Port number after "::" } else { port = atoi(portp); // Display number after ":" } } vnclog.Print(LL_STATE, VNCLOG("test... %s %d\n"),name,port); strcpy_s(dnsname,name); VCard32 address = VSocket::Resolve(name); delete [] name; if (address != 0) { // Post the IP address to the server // We can not contact a runnning service, permissions, so we must store the settings // and process until the vncmenu has been started vnclog.Print(LL_INTERR, VNCLOG("PostAddNewClient III \n")); if (!vncService::PostAddNewClientInit(address, port)) { PostAddNewClient_bool=true; port_int=port; address_vcard=address; } } else { //ask for host,port PostAddNewClient_bool=true; port_int=0; address_vcard=0; Sleep(2000); //Beep(200,1000); return 0; } } i=end; continue; } else { // Tell the server to show the Add New Client dialog // We can not contact a runnning service, permissions, so we must store the settings // and process until the vncmenu has been started vnclog.Print(LL_INTERR, VNCLOG("PostAddNewClient IIII\n")); if (!vncService::PostAddNewClient(0, 0)) { PostAddNewClient_bool=true; port_int=0; address_vcard=0; } } continue; } //adzm 2009-06-20 if (strncmp(&szCmdLine[i], winvncRepeater, strlen(winvncRepeater)) == 0) { // set the default repeater host i+=strlen(winvncRepeater); // First, we have to parse the command line to get the host to use int start, end; start=i; while (szCmdLine[start] <= ' ' && szCmdLine[start] != 0) start++; end = start; while (szCmdLine[end] > ' ') end++; // Was there a hostname (and optionally a port number) given? if (end-start > 0) { if (g_szRepeaterHost) { delete[] g_szRepeaterHost; g_szRepeaterHost = NULL; } g_szRepeaterHost = new char[end-start+1]; if (g_szRepeaterHost != 0) { strncpy(g_szRepeaterHost, &(szCmdLine[start]), end-start); g_szRepeaterHost[end-start] = 0; // We can not contact a runnning service, permissions, so we must store the settings // and process until the vncmenu has been started vnclog.Print(LL_INTERR, VNCLOG("PostAddNewRepeaterClient I\n")); if (!vncService::PostAddNewRepeaterClient()) { PostAddNewRepeaterClient_bool=true; port_int=0; address_vcard=0; } } i=end; continue; } else { /* // Tell the server to show the Add New Client dialog // We can not contact a runnning service, permissions, so we must store the settings // and process until the vncmenu has been started vnclog.Print(LL_INTERR, VNCLOG("PostAddNewClient IIII\n")); if (!vncService::PostAddNewClient(0, 0)) { PostAddNewClient_bool=true; port_int=0; address_vcard=0; } */ } continue; } // Either the user gave the -help option or there is something odd on the cmd-line! // Show the usage dialog MessageBoxSecure(NULL, winvncUsageText, sz_ID_WINVNC_USAGE, MB_OK | MB_ICONINFORMATION); break; }; // If no arguments were given then just run if (!argfound) { if (!Myinit(hInstance)) { #ifdef CRASHRPT crUninstall(); #endif return 0; } int returnvalue= WinVNCAppMain(); #ifdef CRASHRPT crUninstall(); #endif return returnvalue; } #ifdef CRASHRPT crUninstall(); #endif return 0; }
QString Plugin::GetAlbumArtProviderName () const { return GetServiceName (); }