LibreOffice Module onlineupdate (master) 1
Functions | Variables
workmonitor.cxx File Reference
#include <shlobj.h>
#include <shlwapi.h>
#include <wtsapi32.h>
#include <userenv.h>
#include <shellapi.h>
#include <cstddef>
#include "workmonitor.hxx"
#include "serviceinstall.hxx"
#include "servicebase.hxx"
#include "registrycertificates.hxx"
#include "uachelper.h"
#include "updatehelper.h"
#include "errors.h"
#include "windowsHelper.hxx"
Include dependency graph for workmonitor.cxx:

Go to the source code of this file.

Functions

wchar_t * MakeCommandLine (int argc, wchar_t **argv)
 
BOOL WriteStatusFailure (LPCWSTR updateDirPath, int errorCode)
 
BOOL PathGetSiblingFilePath (LPWSTR destinationBuffer, LPCWSTR siblingFilePath, LPCWSTR newFileName)
 
static BOOL IsStatusApplying (LPCWSTR updateDirPath, BOOL &isApplying)
 
static bool IsUpdateBeingStaged (int argc, LPWSTR *argv)
 Determines whether we're staging an update. More...
 
static bool IsDigits (WCHAR *str)
 Determines whether the param only contains digits. More...
 
static bool IsOldCommandline (int argc, LPWSTR *argv)
 Determines whether the command line contains just the directory to apply the update to (old command line) or if it contains the installation directory and the directory to apply the update to. More...
 
static BOOL GetInstallationDir (int argcTmp, LPWSTR *argvTmp, WCHAR aResultDir[MAX_PATH+1])
 Gets the installation directory from the arguments passed to updater.exe. More...
 
BOOL StartUpdateProcess (int argc, LPWSTR *argv, LPCWSTR installDir, BOOL &processStarted)
 Runs an update process as the service using the SYSTEM account. More...
 
BOOL ProcessSoftwareUpdateCommand (DWORD argc, LPWSTR *argv)
 Processes a software update command. More...
 
BOOL GetSecureUpdaterPath (WCHAR serviceUpdaterPath[MAX_PATH+1])
 Obtains the updater path alongside a subdir of the service binary. More...
 
BOOL DeleteSecureUpdater (WCHAR serviceUpdaterPath[MAX_PATH+1])
 Deletes the passed in updater path and the associated updater.ini file. More...
 
BOOL ExecuteServiceCommand (int argc, LPWSTR *argv)
 Executes a service command. More...
 

Variables

static const int TIME_TO_WAIT_ON_UPDATER = 15 * 60 * 1000
 

Function Documentation

◆ DeleteSecureUpdater()

BOOL DeleteSecureUpdater ( WCHAR  serviceUpdaterPath[MAX_PATH+1])

Deletes the passed in updater path and the associated updater.ini file.

Parameters
serviceUpdaterPathThe path to delete.
Returns
TRUE if a file was deleted.

Definition at line 639 of file workmonitor.cxx.

References FALSE, LOG_WARN, MAX_PATH, PathGetSiblingFilePath(), and result.

Referenced by ExecuteServiceCommand().

◆ ExecuteServiceCommand()

BOOL ExecuteServiceCommand ( int  argc,
LPWSTR *  argv 
)

Executes a service command.

Parameters
argcThe number of arguments in argv
argvThe service command line arguments, argv[0] and argv[1] and automatically included by Windows. argv[2] is the service command.
Returns
FALSE if there was an error executing the service command.

Definition at line 679 of file workmonitor.cxx.

References DeleteSecureUpdater(), FALSE, GetSecureUpdaterPath(), hr, LOG, LOG_WARN, MAX_PATH, PathGetSiblingFilePath(), ProcessSoftwareUpdateCommand(), result, SERVICE_COULD_NOT_COPY_UPDATER, TRUE, and WriteStatusFailure().

Referenced by SvcMain().

◆ GetInstallationDir()

static BOOL GetInstallationDir ( int  argcTmp,
LPWSTR *  argvTmp,
WCHAR  aResultDir[MAX_PATH+1] 
)
static

Gets the installation directory from the arguments passed to updater.exe.

Parameters
argcTmpThe argc value normally sent to updater.exe
argvTmpThe argv value normally sent to updater.exe
aResultDirBuffer to hold the installation directory.

Definition at line 144 of file workmonitor.cxx.

References FALSE, index, IsOldCommandline(), IsUpdateBeingStaged(), MAX_PATH, and TRUE.

Referenced by ProcessSoftwareUpdateCommand().

◆ GetSecureUpdaterPath()

BOOL GetSecureUpdaterPath ( WCHAR  serviceUpdaterPath[MAX_PATH+1])

Obtains the updater path alongside a subdir of the service binary.

The purpose of this function is to return a path that is likely high integrity and therefore more safe to execute code from.

Parameters
serviceUpdaterPathOut parameter for the path where the updater should be copied to.
Returns
TRUE if a file path was obtained.

Definition at line 597 of file workmonitor.cxx.

References FALSE, LOG_WARN, MAX_PATH, PathAppendSafe(), and TRUE.

Referenced by ExecuteServiceCommand().

◆ IsDigits()

static bool IsDigits ( WCHAR *  str)
static

Determines whether the param only contains digits.

Parameters
strThe string to check
booleanTrue if the param only contains digits

Definition at line 107 of file workmonitor.cxx.

References FALSE, and TRUE.

Referenced by IsOldCommandline().

◆ IsOldCommandline()

static bool IsOldCommandline ( int  argc,
LPWSTR *  argv 
)
static

Determines whether the command line contains just the directory to apply the update to (old command line) or if it contains the installation directory and the directory to apply the update to.

Parameters
argcThe argc value normally sent to updater.exe
argvThe argv value normally sent to updater.exe
booleanTrue if the command line contains just the directory to apply the update to

Definition at line 130 of file workmonitor.cxx.

References IsDigits().

Referenced by GetInstallationDir(), and StartUpdateProcess().

◆ IsStatusApplying()

static BOOL IsStatusApplying ( LPCWSTR  updateDirPath,
BOOL isApplying 
)
static

Definition at line 46 of file workmonitor.cxx.

References FALSE, AutoHandle::get(), LOG, LOG_WARN, MAX_PATH, PathAppendSafe(), and TRUE.

Referenced by StartUpdateProcess().

◆ IsUpdateBeingStaged()

static bool IsUpdateBeingStaged ( int  argc,
LPWSTR *  argv 
)
static

Determines whether we're staging an update.

Parameters
argcThe argc value normally sent to updater.exe
argvThe argv value normally sent to updater.exe
Returns
boolean True if we're staging an update

Definition at line 93 of file workmonitor.cxx.

Referenced by GetInstallationDir(), ProcessSoftwareUpdateCommand(), and StartUpdateProcess().

◆ MakeCommandLine()

wchar_t * MakeCommandLine ( int  argc,
wchar_t **  argv 
)

Referenced by NS_main(), and StartUpdateProcess().

◆ PathGetSiblingFilePath()

BOOL PathGetSiblingFilePath ( LPWSTR  destinationBuffer,
LPCWSTR  siblingFilePath,
LPCWSTR  newFileName 
)

◆ ProcessSoftwareUpdateCommand()

BOOL ProcessSoftwareUpdateCommand ( DWORD  argc,
LPWSTR *  argv 
)

◆ StartUpdateProcess()

BOOL StartUpdateProcess ( int  argc,
LPWSTR *  argv,
LPCWSTR  installDir,
BOOL processStarted 
)

Runs an update process as the service using the SYSTEM account.

Parameters
argcThe number of arguments in argv
argvThe arguments normally passed to updater.exe argv[0] must be the path to updater.exe
processStartedSet to TRUE if the process was started.
Returns
TRUE if the update process was run had a return code of 0.

Definition at line 188 of file workmonitor.cxx.

References FALSE, index, IsOldCommandline(), IsStatusApplying(), IsUpdateBeingStaged(), LaunchWinPostProcess(), LOG, LOG_WARN, MakeCommandLine(), MAX_PATH, PathGetSiblingFilePath(), SERVICE_STILL_APPLYING_ON_FAILURE, SERVICE_STILL_APPLYING_ON_SUCCESS, TIME_TO_WAIT_ON_UPDATER, and WriteStatusFailure().

Referenced by ProcessSoftwareUpdateCommand().

◆ WriteStatusFailure()

BOOL WriteStatusFailure ( LPCWSTR  updateDirPath,
int  errorCode 
)

Variable Documentation

◆ TIME_TO_WAIT_ON_UPDATER

const int TIME_TO_WAIT_ON_UPDATER = 15 * 60 * 1000
static

Definition at line 30 of file workmonitor.cxx.

Referenced by StartUpdateProcess().