Kaydet (Commit) 5f55b7d0 authored tarafından Armin Le Grand's avatar Armin Le Grand

profilesafe: extended to three modes

Saving configuration is now extended to three
basic modes, from just saving registrymodifiications
to adding user-defined config stuff to saving all
information in the user profile, additionally
configuration information for Extensions is saved.
Added configuration entries for this and tested
saving/restoring.

Change-Id: I79b09c37617803bf656826f76a7e3db79cda49ac
Reviewed-on: https://gerrit.libreoffice.org/29770Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarArmin Le Grand <Armin.Le.Grand@cib.de>
üst 83cc9a3f
......@@ -818,42 +818,6 @@ OUString Desktop::CreateErrorMsgString(
return MakeStartupErrorMessage( aMsg );
}
// helper method to test if SecureUserConfig is active, detect the num copies
// and extract the User's config directory URL
bool testSecureUserConfigActive(sal_uInt16& rnSecureUserConfigNumCopies, OUString& raUserConfigDir)
{
// read configuration from soffice.ini
if(comphelper::BackupFileHelper::getSecureUserConfig(rnSecureUserConfigNumCopies))
{
// try to asccess user layer configuration file
OUString conf("${CONFIGURATION_LAYERS}");
rtl::Bootstrap::expandMacros(conf);
const OUString aTokenUser("user:");
sal_Int32 nStart(conf.indexOf(aTokenUser));
if (-1 != nStart)
{
nStart += aTokenUser.getLength();
sal_Int32 nEnd(conf.indexOf(' ', nStart));
if (-1 == nEnd)
{
nEnd = conf.getLength();
}
raUserConfigDir = conf.copy(nStart, nEnd - nStart);
raUserConfigDir.startsWith("!", &raUserConfigDir);
}
if (!raUserConfigDir.isEmpty())
{
return true;
}
}
return false;
}
void Desktop::HandleBootstrapErrors(
BootstrapError aBootstrapError, OUString const & aErrorMessage )
{
......@@ -987,43 +951,37 @@ void Desktop::HandleBootstrapErrors(
}
else if ( aBootstrapError == BE_OFFICECONFIG_BROKEN )
{
// test if SecureUserConfig is active
sal_uInt16 nSecureUserConfigNumCopies(0);
OUString aUserConfigDir;
bool bFireOriginalError(true);
comphelper::BackupFileHelper aBackupFileHelper;
if (testSecureUserConfigActive(nSecureUserConfigNumCopies, aUserConfigDir))
// crerate BackupFileHelper and check if active and if pop is possible
if (aBackupFileHelper.isPopPossible())
{
comphelper::BackupFileHelper aBackupFileHelper(aUserConfigDir, nSecureUserConfigNumCopies);
// for linux (and probably others?) we need to instantiate XDesktop2
// to be able to open a *.ui-file based dialog, so do this here locally.
// does no harm on win, so better always do this (in error case only anyways)
Reference< XComponentContext > xLocalContext = ::comphelper::getProcessComponentContext();
Reference< XDesktop2 > xDesktop = css::frame::Desktop::create(xLocalContext);
ScopedVclPtrInstance< MessageDialog > aQueryShouldRestore(
Application::GetDefDialogParent(),
"QueryTryToRestoreConfigurationDialog",
"desktop/ui/querytrytorestoreconfigurationdialog.ui");
if (aBackupFileHelper.isPopPossible())
if (aQueryShouldRestore.get())
{
// for linux (and probably others?) we need to instantiate XDesktop2
// to be able to open a *.ui-file based dialog, so do this here locally.
// does no harm on win, so better always do this (in error case only anyways)
Reference< XComponentContext > xLocalContext = ::comphelper::getProcessComponentContext();
Reference< XDesktop2 > xDesktop = css::frame::Desktop::create(xLocalContext);
ScopedVclPtrInstance< MessageDialog > aQueryShouldRestore(
Application::GetDefDialogParent(),
"QueryTryToRestoreConfigurationDialog",
"desktop/ui/querytrytorestoreconfigurationdialog.ui");
if (aQueryShouldRestore.get())
if (!aErrorMessage.isEmpty())
{
if (!aErrorMessage.isEmpty())
{
OUString aPrimaryText(aQueryShouldRestore->get_primary_text());
OUString aPrimaryText(aQueryShouldRestore->get_primary_text());
aPrimaryText += "\n(\"" + aErrorMessage + "\")";
aQueryShouldRestore->set_primary_text(aPrimaryText);
}
aPrimaryText += "\n(\"" + aErrorMessage + "\")";
aQueryShouldRestore->set_primary_text(aPrimaryText);
}
if (RET_YES == aQueryShouldRestore->Execute())
{
aBackupFileHelper.tryPop();
bFireOriginalError = false;
}
if (RET_YES == aQueryShouldRestore->Execute())
{
aBackupFileHelper.tryPop();
bFireOriginalError = false;
}
}
}
......@@ -1863,16 +1821,9 @@ int Desktop::doShutdown()
// Test if SecureUserConfig is active. If yes and we are at this point, regular shutdown
// is in progress and the currently used configuration was working. Try to secure this
// working configuration for later eventually necessary restores
sal_uInt16 nSecureUserConfigNumCopies(0);
OUString aUserConfigDir;
comphelper::BackupFileHelper aBackupFileHelper;
if (testSecureUserConfigActive(nSecureUserConfigNumCopies, aUserConfigDir))
{
// try to push registrymodifications.xcu
comphelper::BackupFileHelper aBackupFileHelper(aUserConfigDir, nSecureUserConfigNumCopies);
aBackupFileHelper.tryPush();
}
aBackupFileHelper.tryPush();
}
// The acceptors in the AcceptorMap must be released (in DeregisterServices)
......
......@@ -16,6 +16,7 @@
#include <rtl/ustring.hxx>
#include <osl/file.hxx>
#include <memory>
#include <set>
namespace comphelper
{
......@@ -59,11 +60,20 @@ namespace comphelper
{
private:
// internal data
const OUString& mrBaseURL;
sal_uInt16 mnNumBackups;
OUString maBase;
OUString maName;
OUString maExt;
OUString maInitialBaseURL;
OUString maUserConfigBaseURL;
OUString maRegModName;
OUString maExt;
std::set< OUString > maDirs;
std::set< std::pair< OUString, OUString > > maFiles;
sal_uInt16 mnNumBackups;
sal_uInt16 mnMode;
bool mbActive;
bool mbExtensions;
bool mbCompress;
// internal flag if _exit() was called already - a hint to evtl.
// not create copies of potentially not well-defined data. This
......@@ -78,51 +88,26 @@ namespace comphelper
static sal_uInt16 mnMaxAllowedBackups;
public:
/** Constructor to handle Backups of the given file
*
* @param rxContext
* ComponentContext to use internally; needs to be handed
* over due to usages after DeInit() and thus no access
* anymore using comphelper::getProcessComponentContext()
* @param rBaseURL
* URL to an existing file that needs to be backed up
*
* @param nNumBackups
* Specifies the maximum number of backups to allow for
* the file. This value gets truncated to [1..max] where
* max currently is 10 and defined in the implementation.
* It is used in tryPush() and tryPop() calls to cleanup/
* reduce the number of existing backups
/** Constructor to handle Backups of the given file, will internally
* detect configuration values and URL to initial registrymodifications
* and thus the User configuration directory
*/
BackupFileHelper(
const OUString& rBaseURL,
sal_uInt16 nNumBackups = 5);
BackupFileHelper();
// allow to set static global flag when app had to call _exit()
static void setExitWasCalled();
static bool getExitWasCalled();
// static helper to read config values - these are derived from
// soffice.ini due to cui not being available in all cases. The
// boolean SecureUserConfig is returned.
// Default for SecureUserConfig is false
// Default for SecureUserConfigNumCopies is 0 (zero)
static bool getSecureUserConfig(sal_uInt16& rnSecureUserConfigNumCopies);
/** tries to create a new backup, if there is none yet, or if the
* last differs from the base file. It will then put a new verion
* on the 'stack' of copies and evtl. delete the oldest backup.
* Also may cleanup older backups when NumBackups given in the
* constructor has changed.
*
* @param bCompress
* Defines if the new backup will be compressed when
* added. Default is true
*
* @return bool
* returns true if a new backup was actually created
*/
bool tryPush(bool bCompress = true);
bool tryPush();
/** finds out if a restore is possible
*
......@@ -143,15 +128,27 @@ namespace comphelper
private:
// internal helper methods
bool splitBaseURL();
const rtl::OUString getPackDirName() const;
const rtl::OUString getPackFileName(const rtl::OUString& rFileName) const;
bool tryPush_basefile(bool bCompress);
bool tryPush_extensionInfo(bool bCompress);
bool isPopPossible_basefile();
bool isPopPossible_extensionInfo();
bool tryPop_basefile();
bool tryPop_extensionInfo();
const rtl::OUString getPackURL() const;
// file push helpers
bool tryPush_Files(const std::set< OUString >& rDirs, const std::set< std::pair< OUString, OUString > >& rFiles, const OUString& rSourceURL, const OUString& rTargetURL);
bool tryPush_file(const OUString& rSourceURL, const OUString& rTargetURL, const OUString& rName, const OUString& rExt);
// file pop possibilities helper
bool isPopPossible_files(const std::set< OUString >& rDirs, const std::set< std::pair< OUString, OUString > >& rFiles, const OUString& rSourceURL, const OUString& rTargetURL);
static bool isPopPossible_file(const OUString& rSourceURL, const OUString& rTargetURL, const OUString& rName, const OUString& rExt);
// file pop helpers
bool tryPop_files(const std::set< OUString >& rDirs, const std::set< std::pair< OUString, OUString > >& rFiles, const OUString& rSourceURL, const OUString& rTargetURL);
bool tryPop_file(const OUString& rSourceURL, const OUString& rTargetURL, const OUString& rName, const OUString& rExt);
// ExtensionInfo helpers
bool tryPush_extensionInfo(const OUString& rTargetURL);
static bool isPopPossible_extensionInfo(const OUString& rTargetURL);
bool tryPop_extensionInfo(const OUString& rTargetURL);
// FileDirInfo helpers
void fillDirFileInfo();
};
}
......
......@@ -104,7 +104,16 @@ $(call gb_CustomTarget_get_workdir,instsetoo_native/setup)/$(call gb_Helper_get_
) > $@
# for release-builds (building installers) adjust values in openoffice.lst.in
# Added 'SecureUserConfig' flags to enable and safe three registrymodifications.xcu versions
# Added 'SecureUserConfig' flags to enable and safe user config files
# SecureUserConfig : boolean - switches securing on/off - default false
# SecureUserConfigCompress : boolean - defines if backup data will be compressed - default true
# SecureUserConfigNumCopies : integer - defines how many compressed copies of saved content will be kept - default 2
# SecureUserConfigMode: integer - defines what to secure, default is 0
# 0 : only registrymodifications.xcu
# 1 : a selected amount of user-defined configs
# 2 : everything in the user config directory
# SecureUserConfigExtensions: boolean - defines to also safe the extension configuration (which extensions
# are installed, which are activated) - default is true
$(call gb_CustomTarget_get_workdir,instsetoo_native/setup)/$(call gb_Helper_get_rcfile,soffice) :
$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),ECH,1)
( \
......@@ -120,7 +129,10 @@ $(call gb_CustomTarget_get_workdir,instsetoo_native/setup)/$(call gb_Helper_get_
&& echo 'ProgressTextColor=255,255,255' \
&& echo 'URE_BOOTSTRAP=$${ORIGIN}/$(call gb_Helper_get_rcfile,fundamental)' \
&& echo 'SecureUserConfig=true' \
&& echo 'SecureUserConfigNumCopies=3' \
&& echo 'SecureUserConfigCompress=true' \
&& echo 'SecureUserConfigNumCopies=2' \
&& echo 'SecureUserConfigMode=0' \
&& echo 'SecureUserConfigExtensions=true' \
) > $@
$(call gb_CustomTarget_get_workdir,instsetoo_native/setup)/$(call gb_Helper_get_rcfile,uno) :
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment