static void VNCServiceAction(int action) { STARTUPINFO si; PROCESS_INFORMATION pi; char cmdLine[BUFSIZ] = "cmd.exe /c "; memset(&si, 0, sizeof(si)); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; si.cb = sizeof(si); memset(&pi, 0, sizeof(pi)); switch(action) { case DEF_VNC_SERVER_INSTALL: { sprintf(cmdLine, "%s \"%s\" %s", cmdLine, VNCServerPath, "-install"); break; } case DEF_VNC_SERVER_UNINSTALL: { sprintf(cmdLine, "%s \"%s\" %s", cmdLine, VNCServerPath, "-uninstall"); break; } case DEF_VNC_SERVER_START: { sprintf(cmdLine, "%s \"%s\" %s", cmdLine, VNCServerPath, "-startservice"); break; } case DEF_VNC_SERVER_STOP: { sprintf(cmdLine, "%s \"%s\" %s", cmdLine, VNCServerPath, "-stopservice"); break; } } app_os_CreateProcess(cmdLine); app_os_WaitForSingleObject(pi.hProcess, INFINITE); switch(action) { case DEF_VNC_SERVER_START: while(IsSvcRun(DEF_VNC_SERVICE_NAME) != 1) { app_os_sleep(100); } break; case DEF_VNC_SERVER_STOP: while(IsSvcStop(DEF_VNC_SERVICE_NAME) != 1) { app_os_sleep(100); } break; } app_os_CloseHandle(pi.hProcess); app_os_CloseHandle(pi.hThread); }
void SAMANAGER_API SAManager_Uninitialize() { struct samanager_topic_entry *iter_topic = NULL; struct samanager_topic_entry *tmp_topic = NULL; if(g_statethreadctx.isThreadRunning == true) { g_statethreadctx.isThreadRunning = false; app_os_thread_join(g_statethreadctx.threadHandler); g_statethreadctx.threadHandler = NULL; } if(g_statethreadctx.msgqueue) { queue_uninit(g_statethreadctx.msgqueue); free(g_statethreadctx.msgqueue); g_statethreadctx.msgqueue = NULL; } /*Release Handler Loader*/ if(g_SALoader) { //#ifdef WIN32 keepalive_uninitialize(); //#endif if(g_SALoader->Loader_ConcurrentReleaseAllHandler_API) g_SALoader->Loader_ConcurrentReleaseAllHandler_API(&g_handlerList); if(g_SALoader->Loader_Uninitialize_API) g_SALoader->Loader_Uninitialize_API(); dl_CleanupSALoaderLib(g_SALoader); free(g_SALoader); g_SALoader = NULL; } if(g_SAGeneral) { dl_CleanupSAGeneralLib(g_SAGeneral); free(g_SAGeneral); g_SAGeneral = NULL; app_os_sleep(500); } iter_topic = samanager_Topic_FirstTopic(); while(iter_topic != NULL) { tmp_topic = iter_topic->next; samanager_Topic_RemoveTopic(iter_topic->name); iter_topic = tmp_topic; } }
idigi_callback_status_t app_os_handler(idigi_os_request_t const request, void const * const request_data, size_t const request_length, void * response_data, size_t * const response_length) { idigi_callback_status_t status; UNUSED_ARGUMENT(request_length); UNUSED_ARGUMENT(response_length); switch (request) { case idigi_os_malloc: { size_t const * const bytes = request_data; status = app_os_malloc(*bytes, response_data); } break; case idigi_os_free: app_os_free(request_data); status = idigi_callback_continue; break; case idigi_os_system_up_time: status = app_os_get_system_time(response_data); break; case idigi_os_sleep: { unsigned int const * const seconds = request_data; status = app_os_sleep(*seconds); } break; default: APP_DEBUG("app_os_handler: unrecognized request [%d]\n", request); status = idigi_callback_unrecognized; break; } return status; }
static CAGENT_PTHREAD_ENTRY(StateQueueThread, args) { struct state_ctx *pstateContex = (struct state_ctx *)args; int interval = 100; struct statemessage *msg = NULL; while(pstateContex->isThreadRunning) { app_os_sleep(interval); msg = queue_get(pstateContex->msgqueue); if(!msg) continue; if(g_SALoader) { if(g_SALoader->Loader_SetAgentStatus_API) g_SALoader->Loader_SetAgentStatus_API(&g_handlerList, msg->conf, msg->status); } statemsg_free(msg); msg = NULL; } app_os_thread_exit(0); return 0; }
static CAGENT_PTHREAD_ENTRY(CreateASZThreadStart, args) { char ** aszParams = (char **)args; char * pIsDefSetting = aszParams[0]; char * pASZPercentStr = aszParams[1]; unsigned int ASZPercent = atoi(pASZPercentStr); create_asz_status_t createASZStatus = create_asz_success; char cmdLine[BUFSIZ] = {0}; if(app_os_is_file_exist(AcroCmdExePath)) { if(!AcrStartService()) { createASZStatus = create_asz_service_fail; goto done; } { char aszVolumeName[4096] = {0}; int i=0; for (i = 0; i < 10; i++) { memset(aszVolumeName, 0, sizeof(aszVolumeName)); GetVolume(aszVolumeName); if(strlen(aszVolumeName)) { break; } app_os_sleep(10000); } if (strlen(aszVolumeName) == 0) { createASZStatus = create_asz_get_voluem_fail; goto done; } if (IsHaveASZ) { createASZStatus = create_asz_exist; WriteASZExistRecord(TRUE); goto done; } #ifdef _is_linux { FILE *fd = NULL; char buf[BUFSIZ] = {0}; fd = popen("swapon -s", "r"); while (fgets(buf, sizeof(buf), fd)) { if (strstr(buf, "partition"))// delete swap partition { char *tp = aszVolumeName; while (*tp++ != '\0'); while (*--tp != ','); *tp = '\0'; break; } } pclose(fd); } if (!_stricmp(pIsDefSetting, "TRUE")) { sprintf(cmdLine, "acrocmd create asz --disk=%s --volume=%s --reboot", AcrDiskName, aszVolumeName); } else { LONGLONG ASZSize = 0; LONGLONG MinSize = 0, MaxSize = 0; app_os_GetMinAndMaxSpaceMB(&MinSize, &MaxSize); ASZSize = MaxSize * ASZPercent / 100; if (ASZSize <= MinSize) ASZSize = MinSize; sprintf(cmdLine, "acrocmd create asz --disk=%s --volume=%s --asz_size=%d --reboot", AcrDiskName, aszVolumeName, ASZSize); } #else if(!_stricmp(pIsDefSetting, "TRUE")) { sprintf(cmdLine, "cmd.exe /c acrocmd.exe create asz --disk=%s --volume=%s --reboot", AcrDiskName, aszVolumeName); } else { LONGLONG ASZSize = 0; LONGLONG MinSize = 0, MaxSize = 0; app_os_GetMinAndMaxSpaceMB(&MinSize, &MaxSize); ASZSize = MaxSize * ASZPercent / 100; if (ASZSize <= MinSize) ASZSize = MinSize; sprintf(cmdLine, "cmd.exe /c acrocmd.exe create asz --disk=%s --volume=%s --asz_size=%d --reboot", AcrDiskName, aszVolumeName, ASZSize); } #endif /* _is_linux */ if(!app_os_CreateProcess(cmdLine)) { RecoveryLog(g_loghandle, Normal, "%s()[%d]###Create asz process failed!\n",__FUNCTION__, __LINE__); createASZStatus = create_asz_other_error; goto done; } else { WriteASZExistRecord(TRUE); #ifdef _is_linux createASZStatus = create_asz_success; #else { char modulePath[MAX_PATH] = {0}; char acrCloseCmdPath[MAX_PATH] = {0}; app_os_get_module_path(modulePath); sprintf(acrCloseCmdPath, "%s%s", modulePath, DEF_CLOSE_ACROCMD_NAME); memset(cmdLine, 0, sizeof(cmdLine)); sprintf(cmdLine, "%s", acrCloseCmdPath); if(!app_os_CreateProcess(cmdLine)) { RecoveryLog(g_loghandle, Normal, "%s()[%d]###Create asz close process failed!\n",__FUNCTION__, __LINE__ ); createASZStatus = create_asz_other_error; goto done; } else { createASZStatus = create_asz_success; } } #endif /* _is_linux */ } } } else { createASZStatus = create_asz_no_install; } done: { char createASZMsg[BUFSIZ] = {0}; switch(createASZStatus) { case create_asz_service_fail: { sprintf(createASZMsg, "%s", "create_asz_service_fail"); SendReplyMsg_Rcvy(createASZMsg, asz_srvFail, rcvy_create_asz_rep); break; } case create_asz_get_voluem_fail: { sprintf(createASZMsg, "%s", "create_asz_get_voluem_fail"); SendReplyMsg_Rcvy(createASZMsg, asz_volumeFail, rcvy_create_asz_rep); break; } case create_asz_exist: { sprintf(createASZMsg, "%s", "create_asz_exist"); SendReplyMsg_Rcvy(createASZMsg, asz_exist, rcvy_create_asz_rep); break; } case create_asz_no_install: { sprintf(createASZMsg, "%s", "create_asz_no_install"); SendReplyMsg_Rcvy(createASZMsg, asz_noAcronis, rcvy_create_asz_rep); break; } case create_asz_success: { sprintf(createASZMsg, "%s", "create_asz_success"); SendReplyMsg_Rcvy(createASZMsg, oprt_success, rcvy_create_asz_rep); break; } case create_asz_other_error: { sprintf(createASZMsg, "%s", "create_asz_other_error"); SendReplyMsg_Rcvy(createASZMsg, oprt_fail, rcvy_create_asz_rep); break; } } } GetRcvyCurStatus(); if(createASZStatus == create_asz_success) { memset(cmdLine, 0, sizeof(cmdLine)); #ifndef _is_linux sprintf(cmdLine, "%s", "cmd.exe /c shutdown -r -f -t 0"); #else sprintf(cmdLine, "%s", "reboot"); #endif /* _is_linux */ if(!app_os_CreateProcess(cmdLine)) { RecoveryLog(g_loghandle, Normal, "%s()[%d]###Create shut down process failed!\n",__FUNCTION__, __LINE__ ); } } return 0; }
static CAGENT_PTHREAD_ENTRY(SampleHandlerThreadStart, args) { char *cPayload = NULL; MSG_CLASSIFY_T *myEvent = NULL; handler_context_t *pHandlerContex = (handler_context_t *)args; while (g_PluginInfo.agentInfo->status == 0) { if(!pHandlerContex->isThreadRunning) return 0; app_os_sleep(1000); } /*Send notify*/ { myEvent = DEV_CreateEventNotify("message", "test message for event notify!!"); cPayload = DEV_PrintUnformatted(myEvent); DEV_ReleaseDevice(myEvent); if(g_sendeventcbf) g_sendeventcbf( &g_PluginInfo, Severity_Informational, cPayload, strlen(cPayload), NULL, NULL); free(cPayload); } /* Update InfoSpec test*/ if(!g_Capability) g_Capability = CreateCapability(); { cPayload = IoT_PrintCapability(g_Capability); if(g_sendcapabilitycbf) g_sendcapabilitycbf(&g_PluginInfo, cPayload, strlen(cPayload), NULL, NULL); free(cPayload); } TestCustMsg(); while(pHandlerContex->isThreadRunning) { app_os_sleep(5000); if(m_bAutoReprot) { /* Send AutoReport test*/ if(g_Capability) { cPayload = IoT_PrintData(g_Capability); if(g_sendreportcbf) g_sendreportcbf(&g_PluginInfo, cPayload, strlen(cPayload), NULL, NULL); free(cPayload); } } /*update timer for status check*/ time(&g_monitortime); } return 0; }
//----------------------------------------------------------------------------- // Local functions define: //----------------------------------------------------------------------------- static CAGENT_PTHREAD_ENTRY(ProtectActionThreadStart, args) { handler_context_t *pProtectHandlerContext = (handler_context_t *)args; char cmdLine[BUFSIZ] = {0}; char sadminOuputPath[MAX_PATH] = {0}; char sysDir[MAX_PATH] = {0}; CAGENT_HANDLE sadminPrcHandle = NULL; SendReplyMsg_Prtt("ProtectActionStart", prtt_start, prtt_protect_rep); #ifdef _WIN32 app_os_GetSystemDirectory(sysDir, sizeof(sysDir)); strcat(sadminOuputPath, sysDir); strcat(sadminOuputPath, DEF_SADMIN_OUTPUT_FILE_NAME); strcat(cmdLine, "cmd.exe /c sadmin.exe so "); #else sprintf(sadminOuputPath, "/tmp%s", DEF_SADMIN_OUTPUT_FILE_NAME); sprintf(cmdLine, "sadmin so "); #endif /* _WIN32 */ if(strlen(EncodePassWord)) { strcat(cmdLine, " -z "); strcat(cmdLine, EncodePassWord); } strcat(cmdLine, " > "); strcat(cmdLine, sadminOuputPath); SendReplyMsg_Prtt("ProtectActionSolidifyStart", prtt_soStart, prtt_protect_rep); pProtectHandlerContext->sadminOutputCheckEnable = TRUE; sadminPrcHandle = app_os_CreateProcessWithCmdLineEx(cmdLine); if(!sadminPrcHandle) { ProtectLog(g_loghandle, Warning, " %s> Create sadimin so process failed!", strPluginName); pProtectHandlerContext->sadminOutputCheckEnable = FALSE; SendReplyMsg_Prtt("ProtectActionSolidifyFail", prtt_soStartFail, prtt_protect_rep); } else { int prcExitCode = 0; // wait process and get exit code prcExitCode = GetResultFromProcess(sadminPrcHandle); app_os_sleep(DEF_SADMIN_OUTPUT_CHECK_INTERVAL_MS); pProtectHandlerContext->sadminOutputCheckEnable = FALSE; if(app_os_is_file_exist(sadminOuputPath)) { app_os_file_remove(sadminOuputPath); } app_os_sleep(DEF_SADMIN_OUTPUT_CHECK_INTERVAL_MS); if(prcExitCode != 0 ) { #ifdef _WIN32 {//lockdown CLI CAGENT_HANDLE sadminLockdownPrcHandle = NULL; memset(cmdLine, 0, sizeof(cmdLine)); sprintf_s(cmdLine, sizeof(cmdLine), "%s", "cmd.exe /c sadmin.exe lockdown"); sadminLockdownPrcHandle = app_os_CreateProcessWithCmdLineEx(cmdLine); if(sadminLockdownPrcHandle) { DWORD prcExitCode = 0; app_os_WaitForSingleObject(sadminLockdownPrcHandle, INFINITE); app_os_GetExitCodeProcess(sadminLockdownPrcHandle, &prcExitCode); app_os_CloseHandle(sadminLockdownPrcHandle); app_os_sleep(DEF_SADMIN_OUTPUT_CHECK_INTERVAL_MS); if(prcExitCode == 0) { } } } {//recover CLI CAGENT_HANDLE sadminRecoverPrcHandle = NULL; memset(cmdLine, 0, sizeof(cmdLine)); sprintf_s(cmdLine, sizeof(cmdLine), "%s", "cmd.exe /c sadmin.exe recover -f"); sadminRecoverPrcHandle = app_os_CreateProcessWithCmdLineEx(cmdLine); if(sadminRecoverPrcHandle) { DWORD prcExitCode = 0; app_os_WaitForSingleObject(sadminRecoverPrcHandle, INFINITE); app_os_GetExitCodeProcess(sadminRecoverPrcHandle, &prcExitCode); app_os_CloseHandle(sadminRecoverPrcHandle); } } #endif /* _WIN32 */ SendReplyMsg_Prtt("ProtectActionSolidifyFail, Sadmin abnormal exit!", prtt_soFail, prtt_protect_rep); } else { SendReplyMsg_Prtt("ProtectActionSolidifyEnd", prtt_soEnd, prtt_protect_rep); #ifdef _WIN32 {//Report McAfee Solidifier log CAGENT_THREAD_HANDLE sysLogHandle = app_os_RegisterEventSource(NULL, "McAfee Solidifier"); if(sysLogHandle) { const char * pStr[1]; pStr[0] = "Mcafee Solidify"; app_os_ReportEvent(sysLogHandle, 91, pStr); app_os_DeregisterEventSource(sysLogHandle); sysLogHandle = NULL; } } {//setvalue "SOFTWARE\\McAfee" char regName[] = "SOFTWARE\\McAfee"; char valueName[] = "LastWarningMsg"; app_os_set_regLocalMachine_value(regName, valueName, "", 0); } {//sadmin.exe add updaters process char mcAfeeAddUpdaterPath[MAX_PATH] = {0}; char moudlePath[MAX_PATH]={0}; CAGENT_HANDLE mcafeeAddUpdaterPrcHandle = NULL; app_os_get_module_path(moudlePath); sprintf_s(mcAfeeAddUpdaterPath, sizeof(mcAfeeAddUpdaterPath), "%s%s", moudlePath, "McAfeeAddUpdater.bat"); memset(cmdLine, 0, sizeof(cmdLine)); sprintf_s(cmdLine, sizeof(cmdLine), "cmd.exe /c \"%s\" ", mcAfeeAddUpdaterPath); if(strlen(EncodePassWord)) { strcat(cmdLine, EncodePassWord); } mcafeeAddUpdaterPrcHandle = app_os_CreateProcessWithCmdLineEx(cmdLine); if(!mcafeeAddUpdaterPrcHandle) { ProtectLog(g_loghandle, Warning, " %s> Create sadimin.exe add updaters process failed!", strPluginName); SendReplyMsg_Prtt("ProtectActionAddUpdaterFail", \ prtt_addUpdtWLFail, prtt_protect_rep); } else { SendReplyMsg_Prtt("ProtectActionAddUpdaterSuccess",\ prtt_addUpdtWLOK, prtt_protect_rep); app_os_WaitForSingleObject(mcafeeAddUpdaterPrcHandle, INFINITE); app_os_CloseHandle(mcafeeAddUpdaterPrcHandle); } } #else {//sadmin.exe add updaters process char mcAfeeAddUpdaterPath[MAX_PATH] = {0}; char moudlePath[MAX_PATH]={0}; int result = -1; app_os_get_module_path(moudlePath); sprintf_s(mcAfeeAddUpdaterPath, sizeof(mcAfeeAddUpdaterPath), "%s%s", moudlePath, "McAfeeAddUpdater.sh"); memset(cmdLine, 0, sizeof(cmdLine)); sprintf_s(cmdLine, sizeof(cmdLine), "%s", mcAfeeAddUpdaterPath); result = system(cmdLine); if(result < 0) { ProtectLog(g_loghandle, Warning, " %s> Create sadimin.exe add updaters process failed! %s", strPluginName, strerror(errno)); SendReplyMsg_Prtt("ProtectActionAddUpdaterFail", prtt_addUpdtWLFail, prtt_protect_rep); } else { if(WIFEXITED(result)) { SendReplyMsg_Prtt("ProtectActionAddUpdaterSuccess", prtt_addUpdtWLOK, prtt_protect_rep); } else if(WIFSIGNALED(result)) { ProtectLog(g_loghandle, Warning, " %s> Create sadimin.exe add updaters process failed! abnormal termination,signal number =%d", strPluginName, WTERMSIG(result)); SendReplyMsg_Prtt("ProtectActionAddUpdaterFail", prtt_addUpdtWLFail, prtt_protect_rep); } else if(WIFSTOPPED(result)) { ProtectLog(g_loghandle, Warning, " %s> Create sadimin.exe add updaters process failed! process stopped, signal number =%d", strPluginName, WSTOPSIG(result)); SendReplyMsg_Prtt("ProtectActionAddUpdaterFail", prtt_addUpdtWLFail, prtt_protect_rep); } } } #endif /* _WIN32 */ {//sadmin.exe enable process CAGENT_HANDLE sadminEnablePrcHandle = NULL; memset(cmdLine, 0, sizeof(cmdLine)); #ifdef _WIN32 strcat(cmdLine, "cmd.exe /c sadmin.exe enable "); #else sprintf(cmdLine, "sadmin enable "); #endif /* _WIN32 */ if(strlen(EncodePassWord)) { strcat(cmdLine, " -z "); strcat(cmdLine, EncodePassWord); } sadminEnablePrcHandle = app_os_CreateProcessWithCmdLineEx(cmdLine); if(!sadminEnablePrcHandle) { ProtectLog(g_loghandle, Warning, " %s> Create sadimin enable process failed!", strPluginName); SendReplyFailMsg_Prtt("ProtectActionEnableFail", prtt_protect_rep); } else { // wait process and get exit code if (0 == GetResultFromProcess(sadminEnablePrcHandle)) SendReplySuccessMsg_Prtt("ProtectActionEnableSuccess",prtt_protect_rep); else SendReplyFailMsg_Prtt("ProtectActionEnableFail", prtt_protect_rep); } } } } SendReplyMsg_Prtt("ProtectActionEnd", prtt_end, prtt_protect_rep); pProtectHandlerContext->isProtectActionRunning = FALSE; GetProtectionCurStatus(); return 0; }
static CAGENT_PTHREAD_ENTRY(FtpDLInfoGetThreadStart, pThreadParam) { PFTPDLCONTEXT pFtpDLContext = (PFTPDLCONTEXT)pThreadParam; app_os_sleep(100); if(pFtpDLContext && pFtpDLContext->hCurl) { CURL *curl = pFtpDLContext->hCurl; CURLcode res; double dlCountLen = 0; unsigned long dwPersent = 0; double dlCurSize = 0, dlSpeed = 0; while(pFtpDLContext->dlInfoGetThreadRunning) { if(dlCountLen <= 0) { res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &dlCountLen); if(res == CURLE_OK) { pFtpDLContext->dlFileLenB = (unsigned int)dlCountLen; } else { char * tmpStr = NULL; pFtpDLContext->dlStatus = FTP_DSC_ERROR; tmpStr = (char *)curl_easy_strerror(res); if(tmpStr && strlen(tmpStr)) { memset(pFtpDLContext->dlLastError, 0, sizeof(pFtpDLContext->dlLastError)); strcpy(pFtpDLContext->dlLastError, tmpStr); } break; } } else { pFtpDLContext->dlStatus = FTP_DSC_DOWNLOADING; res = curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &dlCurSize); if(res == CURLE_OK) { pFtpDLContext->dlCurSizeKB = (unsigned int)(dlCurSize/1024); dwPersent = (DWORD)((dlCurSize*100)/dlCountLen); pFtpDLContext->dlPersent = dwPersent; } else { char * tmpStr = NULL; pFtpDLContext->dlStatus = FTP_DSC_ERROR; tmpStr = (char *)curl_easy_strerror(res); if(tmpStr && strlen(tmpStr)) { memset(pFtpDLContext->dlLastError, 0, sizeof(pFtpDLContext->dlLastError)); strcpy(pFtpDLContext->dlLastError, tmpStr); } break; } res = curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &dlSpeed); if(res == CURLE_OK) { pFtpDLContext->dlSpeedKBS = (float)dlSpeed/1024; } else { char * tmpStr = NULL; pFtpDLContext->dlStatus = FTP_DSC_ERROR; tmpStr = (char *)curl_easy_strerror(res); if(tmpStr && strlen(tmpStr)) { memset(pFtpDLContext->dlLastError, 0, sizeof(pFtpDLContext->dlLastError)); strcpy(pFtpDLContext->dlLastError, tmpStr); } break; } } if(dwPersent == 100 ) { pFtpDLContext->dlStatus = FTP_DSC_FINISHED; break; } app_os_sleep(100); } } app_os_thread_exit(0); return 0; }