/* Store the deviceid and macs concatenated in the .dat file (compressed) */ BOOL CDeviceid::writeDeviceid() { CString csContent; CByteArray *pCb = NULL; CLog *pLogger = getOcsLogger(); pLogger->log( LOG_PRIORITY_DEBUG, _T( "DID_CHECK => writing DeviceID <%s> and MACs <%s> in file <%s\\%s>"), m_csDeviceid, m_csMacConcat, getDataFolder(), DEVICEID_DAT_FILE); // Set Device ID into first line and MAC adresses into second line csContent.Format( _T( "%s\n%s"), m_csDeviceid, m_csMacConcat); // Compress buffer if ((pCb = CZip::deflate( GetAnsiFromUnicode( csContent))) == NULL) { // Unable to compress pLogger->log( LOG_PRIORITY_WARNING, _T( "DID_CHECK => could not write file <%s\\%s>"), getDataFolder(), DEVICEID_DAT_FILE); return FALSE; } // Write buffer csContent.Format( _T( "%s\\%s"), getDataFolder(), DEVICEID_DAT_FILE); if (!WriteByteArrayToFile( pCb, csContent)) { // Unable to write file pLogger->log( LOG_PRIORITY_WARNING, _T( "DID_CHECK => could not write file <%s\\%s>"), getDataFolder(), DEVICEID_DAT_FILE); delete pCb; return FALSE; } // All successful delete pCb; return TRUE; }
/***** * * Deviceid checkings and renewal if needed * ****/ void CDeviceid::checkDeviceid() { CString csDeviceID, csFileDeviceID, csActualMac, csFileMac, csFileHostname; TCHAR lpHostname[MAX_COMPUTERNAME_LENGTH + 1]; CLog *pLogger = getOcsLogger(); BOOL bMacChanged = FALSE; DWORD size = sizeof( lpHostname ); GetComputerName( lpHostname, &size); m_csHostName = lpHostname; // Load deviceid from .dat file if (!loadDeviceid( csDeviceID, csFileMac)) pLogger->log( LOG_PRIORITY_WARNING, _T( "DID_CHECK => Failed to read file <%s>"), DEVICEID_DAT_FILE); else pLogger->log( LOG_PRIORITY_DEBUG, _T( "DID_CHECK => Read DeviceID <%s> and MACs <%s> in file <%s>"), csDeviceID, csFileMac, DEVICEID_DAT_FILE); // Get list of MC Addresses csActualMac = getMacs(); csFileHostname = csDeviceID.Left( csDeviceID.GetLength()-20); csFileDeviceID = csDeviceID; // Compare reference to actual. There is changes if // - Hostname has changed // - There is only one MAC, and it has changed // - There is 2 or more MACs, and at least 2 has changed has changed bMacChanged = CompareMacs( csFileMac, csActualMac); if (bMacChanged && (m_csHostName != csFileHostname)) { // Both MAC and hostname changes csDeviceID.Empty(); pLogger->log( LOG_PRIORITY_NOTICE, _T( "DID_CHECK => MAC Address changed new:<%s> old:<%s>, Hostname changed new:<%s> old:<%s>"), csActualMac, csFileMac, m_csHostName, csFileHostname ); } else if (bMacChanged || (m_csHostName != csFileHostname)) { m_csOldDeviceid = csDeviceID; csDeviceID.Empty(); if (bMacChanged) pLogger->log( LOG_PRIORITY_NOTICE, _T( "DID_CHECK => MAC Address changed new:<%s> old:<%s>"), csActualMac, csFileMac); else pLogger->log(LOG_PRIORITY_NOTICE, _T( "DID_CHECK => Hostname changed new:<%s> old:<%s>"), m_csHostName, csFileHostname); } if (csDeviceID.IsEmpty()) { // This is the first time we inventory the device => generate a new device unique ID pLogger->log( LOG_PRIORITY_NOTICE, _T( "DID_CHECK => Generating new unique ID for device <%s>"), m_csHostName); m_csDeviceid = generate( m_csHostName); } else m_csDeviceid = csDeviceID; // Write file if something changes, even if DeviceID not regenerated (case of minor changes on MAC addresses) if (( csFileMac != csActualMac) || (m_csHostName != csFileHostname)) writeDeviceid(); }
COptDownloadPackage::COptDownloadPackage(CCapDownload * pC) { pM = pC; m_pLogger = getOcsLogger(); };
BOOL CComProvider::load(LPCTSTR lpstrProvider) { CLog *pLogger = getOcsLogger(); try { CFileVersion fileVer; unload(); pLogger->log( LOG_PRIORITY_DEBUG, _T( "COM PROVIDER => Loading Communication Provider <%s>"), lpstrProvider); if ((m_hComProvider = LoadLibrary( lpstrProvider)) == NULL) { pLogger->log( LOG_PRIORITY_WARNING, _T( "COM PROVIDER => Unable to load library <%s>, %s"), lpstrProvider, LookupError( GetLastError())); return FALSE; } if ((m_pNewServerConfig = (NEW_SERVER_CONFIG_OBJECT)GetProcAddress( m_hComProvider, "newServerConfig")) == NULL) { pLogger->log( LOG_PRIORITY_WARNING, _T( "COM PROVIDER => No newServerConfig hook for Communication Provider <%s>, %s"), lpstrProvider, LookupError( GetLastError())); FreeLibrary( m_hComProvider); return FALSE; } if ((m_pDeleteServerConfig = (DELETE_SERVER_CONFIG_OBJECT)GetProcAddress( m_hComProvider, "deleteServerConfig")) == NULL) { pLogger->log( LOG_PRIORITY_WARNING, _T( "COM PROVIDER => No deleteServerConfig hook for Communication Provider <%s>, %s"), lpstrProvider, LookupError( GetLastError())); FreeLibrary( m_hComProvider); return FALSE; } if ((m_pNewServerConnexion = (NEW_SERVER_OBJECT)GetProcAddress( m_hComProvider, "newServerConnexion")) == NULL) { pLogger->log( LOG_PRIORITY_WARNING, _T( "COM PROVIDER => No newServerConnexion hook for Communication Provider <%s>, %s"), lpstrProvider, LookupError( GetLastError())); FreeLibrary( m_hComProvider); return FALSE; } if ((m_pDeleteServerConnexion = (DELETE_SERVER_OBJECT)GetProcAddress( m_hComProvider, "deleteServerConnexion")) == NULL) { pLogger->log( LOG_PRIORITY_WARNING, _T( "COM PROVIDER => No deleteServerConnexion hook for Communication Provider <%s>, %s"), lpstrProvider, LookupError( GetLastError())); FreeLibrary( m_hComProvider); return FALSE; } // Open application file to get version from file if (fileVer.Open( lpstrProvider)) { m_csName = fileVer.GetFileDescription(); m_csVersion = fileVer.GetFixedFileVersion(); fileVer.Close(); } else { m_csName = _T( "N/A"); m_csVersion = _T( "N/A"); } return TRUE; } catch (CException *pEx) { pLogger->log( LOG_PRIORITY_WARNING, _T( "COM PROVIDER => Error while loading provider DLL <%s>, %s"), lpstrProvider, LookupError( pEx)); pEx->Delete(); return FALSE; } }
CPlugins::CPlugins() { m_pLogger = getOcsLogger(); Load(); }
// http://www.gnu.org/ or Licence.txt //==================================================================================== // OCSPlugin_Example.cpp : Defines the entry point for the DLL application. // #include "stdafx.h" #include "OCSPlugin_Example.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif CLog* m_pLogger = getOcsLogger(); OCSINVENTORY_API_EXPORTED int OCS_CALL_START_EXPORTED(){ m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "SAMPLE DLL PLUGIN => Start hook executed to initialize plugin")); return PLUGIN_OK; } OCSINVENTORY_API_EXPORTED int OCS_CALL_PROLOGWRITE_EXPORTED(CPrologRequest* pPrologReq){ m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "SAMPLE DLL PLUGIN => PrologWrite hook executed before sending prolog to server")); return PLUGIN_OK; } OCSINVENTORY_API_EXPORTED int OCS_CALL_PROLOGRESP_EXPORTED(CPrologResponse* pPrologResp){ m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "SAMPLE DLL PLUGIN => PrologResp hook executed to parse prolog response from server")); return PLUGIN_OK; }
UINT CPackage::executePostCmd( UINT uCommandTimeOut) { CLog *pLog = getOcsLogger(); CExecCommand cmProcess; CString csBuffer; HANDLE hToken; TOKEN_PRIVILEGES tkp; // check if there is post command to execute if (m_csPostCmd.IsEmpty()) { pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => No post execution command provided for package <%s>"), m_csID); return TRUE; } // Check if post command is REBOOT if (m_csPostCmd == OCS_DOWNLOAD_POST_CMD_REBOOT) { pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => Executing post execution command <%s> for package <%s>"), m_csPostCmd, m_csID); // Request ability to restart computer if (!OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Unable to request Reboot privilege for package <%s>: %s"), m_csID, LookupError( GetLastError())); return FALSE; } if (!LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid)) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Unable to request Reboot privilege for package <%s>: %s"), m_csID, LookupError( GetLastError())); return FALSE; } tkp.PrivilegeCount = 1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if (!AdjustTokenPrivileges( hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0)) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Unable to request Reboot privilege for package <%s>: %s"), m_csID, LookupError( GetLastError())); return FALSE; } // Initiate a planned restart to perform application installation. if (!InitiateSystemShutdownEx( NULL, _T( "OCS Inventory NG must REBOOT your system after package setup"), uCommandTimeOut, TRUE, TRUE, SHTDN_REASON_MAJOR_APPLICATION | SHTDN_REASON_MINOR_INSTALLATION | SHTDN_REASON_FLAG_PLANNED)) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Unable to initiate System Reboot after package <%s> execution: %s"), m_csID, LookupError( GetLastError())); return FALSE; } return TRUE; } // Check if post command is SHUTDOWN if (m_csPostCmd == OCS_DOWNLOAD_POST_CMD_SHUTDOWN) { pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => Executing post execution command <%s> for package <%s>"), m_csPostCmd, m_csID); // Request ability to shutdown computer if (!OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Unable to request Shutdown privilege for package <%s>: %s"), m_csID, LookupError( GetLastError())); return FALSE; } if (!LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid)) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Unable to request Shutdown privilege for package <%s>: %s"), m_csID, LookupError( GetLastError())); return FALSE; } tkp.PrivilegeCount = 1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if (!AdjustTokenPrivileges( hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0)) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Unable to request Shutdown privilege for package <%s>: %s"), m_csID, LookupError( GetLastError())); return FALSE; } // Initiate a planned shutdown to perform application installation. if (!InitiateSystemShutdownEx( NULL, _T( "OCS Inventory NG must SHUTDOWN your system after package setup"), uCommandTimeOut, TRUE, FALSE, SHTDN_REASON_MAJOR_APPLICATION | SHTDN_REASON_MINOR_INSTALLATION | SHTDN_REASON_FLAG_PLANNED)) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Unable to initiate System Shutdown after package <%s> execution: %s"), m_csID, LookupError( GetLastError())); return FALSE; } return TRUE; } // Execute default post command pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => Executing post execution command <%s> for package <%s>"), m_csPostCmd, m_csID); // Set command time out in milliseconds cmProcess.setTimeout( uCommandTimeOut * 60 * 1000); // Execute command and wait only for main process to terminate switch (cmProcess.execWait( m_csPostCmd, m_csPath)) { case EXEC_ERROR_START_COMMAND: pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Failed to execute post execution command <%s> for package <%s> (%s)"), m_csPostCmd, m_csID, cmProcess.getOutput()); setDone( ERR_EXECUTE); return FALSE; case EXEC_ERROR_WAIT_COMMAND: pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Failed to get post execution command <%s> result code for package <%s> (%s)"), m_csPostCmd, m_csID, cmProcess.getOutput()); csBuffer = ERR_EXECUTE_NO_EXIT_CODE; return FALSE; case EXEC_ERROR_TIMEOUT_COMMAND: pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Post execution command <%s> execution reached timeout (%s)"), m_csPostCmd, cmProcess.getOutput()); csBuffer = ERR_EXECUTE_TIMEOUT; return FALSE; default: pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => Package <%s> post execution command successfully executed. Command exit code is <%d>"), m_csID, cmProcess.getExitValue()); if (cmProcess.getExitValue() != 0) // Command result code is not a success csBuffer.Format( _T( "%s%d"), ERR_EXIT_CODE, cmProcess.getExitValue()); else csBuffer = CODE_SUCCESS; break; } return TRUE; }
UINT CPackage::execute( UINT uCommandTimeOut) { CLog *pLog = getOcsLogger(); CExecCommand cmProcess; CString csBuffer; UINT uTry; // Check signature before executing package if (!checkSignature()) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Failed verifying signature for Package <%s>"), m_csID); setDone( ERR_BAD_DIGEST); return FALSE; } // Check if package not crashing all time if (!getExecTry( &uTry)) // Assuming first execution try uTry = 0; uTry++; if (uTry > MAX_ERROR_COUNT) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Max try count (%u) reached while executing Package <%s>"), uTry, m_csID); setDone( ERR_EXECUTE_TOO_MANY_TRY); return FALSE; } else setExecTry( uTry); if (m_csAction == OCS_DOWNLOAD_ACTION_LAUNCH) { // We need to wait for all threads/processes started // First, extrac build.zip to tmp folder if (!directoryCreate( m_csPath) || !unZip()) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Failed to unzip package <%s> to folder <%s>"), m_csID, m_csPath); setDone( ERR_UNZIP); return FALSE; } pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => Launching command <%s> for package <%s> on <%s>"), m_csCommand, m_csID, CTime::GetCurrentTime().Format( _T( "%#c"))); if (m_csCommand.IsEmpty()) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => No command provided for <%s> action of package <%s>"), OCS_DOWNLOAD_ACTION_LAUNCH, m_csID); setDone( ERR_BAD_PARAM); return FALSE; } // Set command time out in milliseconds cmProcess.setTimeout( uCommandTimeOut * 60 * 1000); // Execute command and wait for all childs to terminate switch (cmProcess.execWaitForAllChilds( m_csCommand, m_csPath)) { case EXEC_ERROR_START_COMMAND: pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Failed to launch command <%s> for package <%s> (%s)"), m_csCommand, m_csID, cmProcess.getOutput()); setDone( ERR_EXECUTE); return FALSE; case EXEC_ERROR_WAIT_COMMAND: pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Failed to get command <%s> result code for package <%s> (%s)"), m_csCommand, m_csID, cmProcess.getOutput()); csBuffer = ERR_EXECUTE_NO_EXIT_CODE; break; case EXEC_ERROR_TIMEOUT_COMMAND: pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Command <%s> execution reached timeout on <%s> (%s)"), m_csCommand, CTime::GetCurrentTime().Format( _T( "%#c")), cmProcess.getOutput()); csBuffer = ERR_EXECUTE_TIMEOUT; break; default: isExecSuccessful( cmProcess.getExitValue(), csBuffer); pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => Package <%s> successfully launched. Command exit code is <%d>. Package return code is <%s>"), m_csID, cmProcess.getExitValue(), csBuffer); break; } setDone( csBuffer); return TRUE; } if (m_csAction == OCS_DOWNLOAD_ACTION_EXECUTE) { // We only need to wait for cmmand result // First, extrac build.zip to tmp folder if (!directoryCreate( m_csPath) || !unZip()) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Failed to unzip package <%s> to folder <%s>"), m_csID, m_csPath); setDone( ERR_UNZIP); return FALSE; } pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => Executing command <%s> for package <%s> on <%s>"), m_csCommand, m_csID, CTime::GetCurrentTime().Format( _T( "%#c"))); if (m_csCommand.IsEmpty()) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => No command provided for <%s> action of package <%s>"), OCS_DOWNLOAD_ACTION_EXECUTE, m_csID); setDone( ERR_BAD_PARAM); return FALSE; } // Set command time out in milliseconds cmProcess.setTimeout( uCommandTimeOut * 60 * 1000); // Execute command and wait only for main process to terminate switch (cmProcess.execWait( m_csCommand, m_csPath)) { case EXEC_ERROR_START_COMMAND: pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Failed to execute command <%s> for package <%s> (%s)"), m_csCommand, m_csID, cmProcess.getOutput()); setDone( ERR_EXECUTE); return FALSE; case EXEC_ERROR_WAIT_COMMAND: pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Failed to get command <%s> result code for package <%s> (%s)"), m_csCommand, m_csID, cmProcess.getOutput()); csBuffer = ERR_EXECUTE_NO_EXIT_CODE; break; case EXEC_ERROR_TIMEOUT_COMMAND: pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Command <%s> execution reached timeout on <%s> (%s)"), m_csCommand, CTime::GetCurrentTime().Format( _T( "%#c")), cmProcess.getOutput()); csBuffer = ERR_EXECUTE_TIMEOUT; break; default: isExecSuccessful( cmProcess.getExitValue(), csBuffer); pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => Package <%s> successfully executed. Command exit code is <%d>. Package return code is <%s>"), m_csID, cmProcess.getExitValue(), csBuffer); } setDone( csBuffer, GetUnicodeFromAnsi( cmProcess.getOutput())); return TRUE; } if (m_csAction == OCS_DOWNLOAD_ACTION_STORE) { // We just want to unzip data to specified folder pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => Unzipping data to folder <%s> for package <%s> on <%s>"), m_csPath, m_csID, CTime::GetCurrentTime().Format( _T( "%#c"))); if (m_csPath.IsEmpty()) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => No path provided for <%s> action of package <%s>"), OCS_DOWNLOAD_ACTION_STORE, m_csID); setDone( ERR_BAD_PARAM); return FALSE; } if (!directoryCreate( m_csPath) || !unZip()) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Failed to unzip package <%s> to folder <%s>"), m_csID, m_csPath); setDone( ERR_UNZIP); return FALSE; } pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => Package <%s> successfully stored to folder <%s>"), m_csID, m_csPath); setDone( CODE_SUCCESS); return TRUE; } // Unknown action pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Unknown action <%s> for package <%s>"), m_csAction, m_csID); setDone( ERR_BAD_PARAM); return FALSE; }
BOOL CPackage::build() { CString csFile, csZipFile; CFileStatus cfStatus; __int64 i64BuildSize = 0; UINT uIndex; CLog *pLog = getOcsLogger(); CFile fileZip, fileFrag; if (m_uFrags == 0) { pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => No fragment files for package <%s>, nothing to build"), m_csID); return TRUE; } // Ensure all fragment are available pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => Verifying fragment files of package <%s>"), m_csID); for (uIndex=1; uIndex<=m_uFrags; uIndex++) { csFile.Format( _T( "%s\\%s\\%s-%u"), getDownloadFolder(), m_csID, m_csID, uIndex); if (!CFile::GetStatus( csFile, cfStatus)) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Fragment file <%s> is missing or unreadable"), csFile); setDone( ERR_BUILD); return FALSE; } i64BuildSize += cfStatus.m_size; } pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => Checking free disk space for package <%s>"), m_csID); GetCurrentDirectory( 4*_MAX_PATH, csFile.GetBuffer( 4*_MAX_PATH)); csFile.ReleaseBuffer(); if (GetDiskFree( csFile) < (3*i64BuildSize)) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Free disk space missing for package <%s> (required at least %I64d bytes)"), m_csID, 3*i64BuildSize); setDone( ERR_OUT_OF_SPACE); return FALSE; } // Concatenate each fragment file into build.zip pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => Building ZIP for package <%s>"), m_csID); csZipFile.Format( _T( "%s\\%s\\%s"), getDownloadFolder(), m_csID, OCS_DOWNLOAD_BUILD); try { if (!fileZip.Open( csZipFile, CFile::modeCreate|CFile::modeWrite|CFile::shareDenyWrite)) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Cannot create Zip <%s> from fragment files"), csZipFile); setDone( ERR_BUILD); return FALSE; } for (uIndex=1; uIndex<=m_uFrags; uIndex++) { // Read data in frag file and write it in zip file csFile.Format( _T( "%s\\%s\\%s-%u"), getDownloadFolder(), m_csID, m_csID, uIndex); if (!fileFrag.Open( csFile, CFile::modeRead|CFile::shareDenyNone)) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Cannot read Fragment file <%s>"), csFile); setDone( ERR_BUILD); return FALSE; } UINT uLength; BYTE pBuffer[1024]; BOOL bContinue = TRUE; while (bContinue) { uLength = fileFrag.Read( pBuffer, 1024); fileZip.Write( pBuffer, uLength); // Stop if read less than 1024 bytes if (uLength < 1024) bContinue = FALSE; } fileFrag.Close(); } fileZip.Close(); } catch (CException *pEx) { pEx->Delete(); fileZip.Abort(); fileFrag.Abort(); DeleteFile( csZipFile); pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Cannot read Fragment file <%s>"), csFile); setDone( ERR_BUILD); return FALSE; } // Verify signature pLog->log( LOG_PRIORITY_DEBUG, _T( "PACKAGE => Verifying ZIP signature for package <%s>"), m_csID); if (!checkSignature()) { pLog->log( LOG_PRIORITY_WARNING, _T( "PACKAGE => Failed verifying signature for Package <%s>"), m_csID); setDone( ERR_BAD_DIGEST); return FALSE; } // Delete frag files, no more needed deleteFragement(); return TRUE; }
BOOL COcsNotifyUserApp::InitInstance() { HANDLE hMutexOneInstance = NULL; try { // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); if (!CWinApp::InitInstance()) return FALSE; // terminates the application // Logger CTime cStartTime; // Start time of the inventory check cStartTime = CTime::GetCurrentTime(); m_pLogger = getOcsLogger(); m_pLogger->setApplication( AfxGetAppName()); /***** * * Parse command line * ****/ if (!parseCommandLine()) return FALSE; m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "==============================================================================")); m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "Starting OCS Inventory NG User Notification Tool on %s."), cStartTime.Format( _T( "%#c"))); /***** * * Checks wether another instance of ocsinventory.exe is * already running. * ****/ hMutexOneInstance = ::CreateMutex( NULL, TRUE, _T("OCSNOTIFYUSER-088FA840-B10D-11D3-BC36-006067709674")); if ( GetLastError() == ERROR_ALREADY_EXISTS ) { m_nExitCode = OCS_NOTIFY_APP_ALREADY_RUNNING_ERROR; m_pLogger->log( LOG_PRIORITY_DEBUG, _T("Notification Tool => already running")); return FALSE; // terminates the application } /***** * * Gets Download version * ****/ CString csMessage = getVersion(); if (csMessage == _T( "")) { m_pLogger->log( LOG_PRIORITY_DEBUG, _T("Notification Tool => Failed to retrieve Notification Tool version from file. Version 0.0.0.1 assumed")); csMessage=_T( "0.0.0.1"); } m_pLogger->log( LOG_PRIORITY_DEBUG, _T("Notification Tool => Running OCS Inventory NG Notification Tool Version %s"), csMessage); m_pLogger->log( LOG_PRIORITY_DEBUG, _T("Notification Tool => Using OCS Inventory NG FrameWork Version %s"), getFrameworkVersion()); /***** * * Main initinstance block * ****/ AfxEnableControlContainer(); switch (m_uNotifcation) { case NOTIFY_TYPE_PREINSTALL: // Display preinstallation dialogbox if (!displayPreinstallDialogBox()) m_pLogger->log( LOG_PRIORITY_DEBUG, _T("Notification Tool => failed to display preinstall DialogBox")); break; case NOTIFY_TYPE_POSTINSTALL: // Display postinstallation dialogbox if (!displayPostinstallDialogBox()) m_pLogger->log( LOG_PRIORITY_DEBUG, _T("Notification Tool => failed to display postinstall DialogBox")); break; case NOTIFY_TYPE_MSGBOX: // Display standard messagebox if (!displayMessageBox()) m_pLogger->log( LOG_PRIORITY_DEBUG, _T("Notification Tool => failed to display standard MessageBox!")); break; case NOTIFY_TYPE_ASKTAG: // Display standard messagebox if (!askTagDialogBox()) m_pLogger->log( LOG_PRIORITY_DEBUG, _T("Notification Tool => failed to display AskTag DialogBox!")); break; default: m_pLogger->log( LOG_PRIORITY_DEBUG, _T("Notification Tool => wrong notification type!")); break; } } catch( CException *pEx) { m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "Notification Tool => %s"), LookupError( pEx)); pEx->Delete(); } /***** * * Releasing mutex and terminate * ****/ if (hMutexOneInstance != NULL) { ::ReleaseMutex( hMutexOneInstance); } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }