[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-4.1' - 2 commits - configmgr/Library_configmgr.mk configmgr/source scp2/source
Janos Farago
farago.janos at andrews.hu
Thu Oct 17 04:53:45 PDT 2013
configmgr/Library_configmgr.mk | 5
configmgr/source/components.cxx | 23 +++
configmgr/source/winreg.cxx | 235 ++++++++++++++++++++++++++++++++++++++
configmgr/source/winreg.hxx | 22 +++
configmgr/source/writemodfile.cxx | 5
configmgr/source/writemodfile.hxx | 4
scp2/source/ooo/common_brand.scp | 4
7 files changed, 291 insertions(+), 7 deletions(-)
New commits:
commit 2f0208dc68670023b0afeffd3a4b84a2ea1426bd
Author: Janos Farago <farago.janos at andrews.hu>
Date: Sun Sep 29 15:03:53 2013 +0200
winreg backend: add support for oor:op in config nodes
Change-Id: I9cc4472b37d24e426a67661806805c11b521dfb1
Reviewed-on: https://gerrit.libreoffice.org/6074
Reviewed-by: Andras Timar <andras.timar at collabora.com>
Tested-by: Andras Timar <andras.timar at collabora.com>
diff --git a/configmgr/source/winreg.cxx b/configmgr/source/winreg.cxx
index b68b9d2..2969598 100644
--- a/configmgr/source/winreg.cxx
+++ b/configmgr/source/winreg.cxx
@@ -36,18 +36,39 @@ namespace configmgr {
namespace {
// This is not a generic registry reader. We assume the following structure:
-// Last element of Key becomes prop, first part is the path.
+// Last element of Key becomes prop, first part is the path and optionally nodes,
+// when the node has oor:op attribute.
// Values can be the following: Value (string) and Final (dword, optional)
+//
// For example the following registry setting:
// [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\LibreOffice\org.openoffice.UserProfile\Data\o]
// "Value"="Example Corp."
// "Final"=dword:00000001
// becomes the following in configuration:
+// <!-- set the Company name -->
// <item oor:path="/org.openoffice.UserProfile/Data">
// <prop oor:name="o" oor:finalized="true">
// <value>Example Corp.</value>
// </prop>
// </item>
+//
+// Another example:
+// [HKEY_LOCAL_MACHINE\Policies\LibreOffice\org.openoffice.Office.OptionsDialog\OptionsDialogGroups\ProductName/#fuse\Pages\AboutConfig/#fuse\Hide]
+// "Value"="true"
+// becomes the following in configuration:
+// <!-- Hide Tools - Options - LibreOffice - Expert Config panel -->
+// <item oor:path="/org.openoffice.Office.OptionsDialog/OptionsDialogGroups">
+// <node oor:name="ProductName" oor:op="fuse">
+// <node oor:name="Pages">
+// <node oor:name="AboutConfig" oor:op="fuse">
+// <prop oor:name="Hide">
+// <value>true</value>
+// </prop>
+// </node>
+// </node>
+// </node>
+// </item>
+
void dumpWindowsRegistryKey(HKEY hKey, OUString aKeyName, oslFileHandle aFileHandle)
{
HKEY hCurKey;
@@ -107,19 +128,59 @@ void dumpWindowsRegistryKey(HKEY hKey, OUString aKeyName, oslFileHandle aFileHan
bFinal = true;
}
sal_Int32 aLastSeparator = aKeyName.lastIndexOf('\\');
- OUString aPath = aKeyName.replaceAll("\\","/").copy(0, aLastSeparator);
+ OUString aPathAndNodes = aKeyName.copy(0, aLastSeparator);
OUString aProp = aKeyName.copy(aLastSeparator + 1);
+ bool bHasNode = false;
+ sal_Int32 nCloseNode = 0;
+
+ writeData(aFileHandle, "<item oor:path=\"");
+ for(sal_Int32 nIndex = 0;; ++nIndex)
+ {
+ OUString aNextPathPart = aPathAndNodes.getToken(nIndex, '\\');
+
+ if(!aNextPathPart.isEmpty())
+ {
+ if((aNextPathPart.lastIndexOf("/#") != -1) || bHasNode)
+ {
+ bHasNode = true;
+ nCloseNode++;
+ writeData(aFileHandle, "\"><node oor:name=\"");
+ sal_Int32 nCommandSeparator = aNextPathPart.lastIndexOf('#');
+ if(nCommandSeparator != -1)
+ {
+ OUString aNodeOp = aNextPathPart.copy(nCommandSeparator + 1);
+ writeAttributeValue(aFileHandle, aNextPathPart.copy(0, nCommandSeparator - 1));
+ writeData(aFileHandle, "\" oor:op=\"");
+ writeAttributeValue(aFileHandle, aNodeOp);
+ }
+ else
+ {
+ writeAttributeValue(aFileHandle, aNextPathPart);
+ }
+ }
+ else
+ {
+ writeAttributeValue(aFileHandle, "/" + aNextPathPart);
+ }
+ }
+ else
+ {
+ writeData(aFileHandle, "\">");
+ break;
+ }
+ }
- writeData(aFileHandle, "<item oor:path=\"/");
- writeAttributeValue(aFileHandle, aPath);
- writeData(aFileHandle, "\"><prop oor:name=\"");
+ writeData(aFileHandle, "<prop oor:name=\"");
writeAttributeValue(aFileHandle, aProp);
writeData(aFileHandle, "\"");
if(bFinal)
writeData(aFileHandle, " oor:finalized=\"true\"");
writeData(aFileHandle, "><value>");
writeValueContent(aFileHandle, aValue);
- writeData(aFileHandle, "</value></prop></item>\n");
+ writeData(aFileHandle, "</value></prop>");
+ for(; nCloseNode > 0; nCloseNode--)
+ writeData(aFileHandle, "</node>");
+ writeData(aFileHandle, "</item>\n");
delete[] pValueName;
delete[] pValue;
}
commit b8d87040689d0db56867465aabddaab3932abdc0
Author: Janos Farago <farago.janos at andrews.hu>
Date: Tue Sep 3 09:42:44 2013 +0200
Windows registry configuration backend
The goal is to manage LibreOffice configuration centrally
in the enterprise. In Windows Server environment using
Group Policies is a common solution for configuration
management. Therefore it is required that LibreOffice can
read configuration data from Windows registry, too.
Windows registry is another configuration layer on the
top of normal xml based configuration.
For example the following registry setting:
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\LibreOffice\org.openoffice.UserProfile\Data\o]
"Value"="Example Corp."
"Final"=dword:00000001
becomes the following in configuration:
<item oor:path="/org.openoffice.UserProfile/Data">
<prop oor:name="o" oor:finalized="true">
<value>Example Corp.</value>
</prop>
</item>
Signed-off-by: Stephan Bergmann <sbergman at redhat.com>
Conflicts:
scp2/source/ooo/common_brand.scp
Change-Id: I2cdd83fc93922bf2806417bfd1b83f85cc926d4c
diff --git a/configmgr/Library_configmgr.mk b/configmgr/Library_configmgr.mk
index 791782d..2243350 100644
--- a/configmgr/Library_configmgr.mk
+++ b/configmgr/Library_configmgr.mk
@@ -36,6 +36,7 @@ $(eval $(call gb_Library_add_exception_objects,configmgr, \
configmgr/source/type \
configmgr/source/update \
configmgr/source/valueparser \
+ $(if $(filter $(OS),WNT), configmgr/source/winreg ) \
configmgr/source/writemodfile \
configmgr/source/xcdparser \
configmgr/source/xcsparser \
@@ -54,8 +55,8 @@ $(eval $(call gb_Library_use_libraries,configmgr, \
sal \
salhelper \
xmlreader \
- i18nlangtag \
- $(gb_UWINAPI) \
+ i18nlangtag \
+ $(gb_UWINAPI) \
))
$(eval $(call gb_Library_set_componentfile,configmgr,configmgr/source/configmgr))
diff --git a/configmgr/source/components.cxx b/configmgr/source/components.cxx
index fa1302a..6dc34a9 100644
--- a/configmgr/source/components.cxx
+++ b/configmgr/source/components.cxx
@@ -65,6 +65,9 @@
#include "xcdparser.hxx"
#include "xcuparser.hxx"
#include "xcsparser.hxx"
+#ifdef WNT
+#include "winreg.hxx"
+#endif
namespace configmgr {
@@ -552,7 +555,25 @@ Components::Components(
}
modificationFileUrl_ = url;
parseModificationLayer(url);
- } else {
+ }
+#ifdef WNT
+ else if ( type == "winreg" )
+ {
+ if (!url.isEmpty()) {
+ SAL_WARN(
+ "configmgr",
+ "winreg URL is not empty, URL handling is not implemented for winreg");
+ }
+ OUString aTempFileURL;
+ if ( dumpWindowsRegistry(&aTempFileURL) )
+ {
+ parseFileLeniently(&parseXcuFile, aTempFileURL, layer, data_, 0, 0, 0);
+ layer++;
+ osl::File::remove(aTempFileURL);
+ }
+ }
+#endif
+ else {
throw css::uno::RuntimeException(
(OUString("CONFIGURATION_LAYERS: unknown layer type \"") +
type +
diff --git a/configmgr/source/winreg.cxx b/configmgr/source/winreg.cxx
new file mode 100644
index 0000000..b68b9d2
--- /dev/null
+++ b/configmgr/source/winreg.cxx
@@ -0,0 +1,174 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <cwchar>
+#ifdef _MSC_VER
+#pragma warning(push, 1) /* disable warnings within system headers */
+#endif
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <msiquery.h>
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
+#include "com/sun/star/uno/Any.hxx"
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/RuntimeException.hpp"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "com/sun/star/uno/XInterface.hpp"
+#include "rtl/ustring.hxx"
+#include "osl/file.h"
+#include "osl/file.hxx"
+#include "winreg.hxx"
+#include "writemodfile.hxx"
+
+#define MAX_KEY_LENGTH 255
+
+namespace configmgr {
+
+namespace {
+// This is not a generic registry reader. We assume the following structure:
+// Last element of Key becomes prop, first part is the path.
+// Values can be the following: Value (string) and Final (dword, optional)
+// For example the following registry setting:
+// [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\LibreOffice\org.openoffice.UserProfile\Data\o]
+// "Value"="Example Corp."
+// "Final"=dword:00000001
+// becomes the following in configuration:
+// <item oor:path="/org.openoffice.UserProfile/Data">
+// <prop oor:name="o" oor:finalized="true">
+// <value>Example Corp.</value>
+// </prop>
+// </item>
+void dumpWindowsRegistryKey(HKEY hKey, OUString aKeyName, oslFileHandle aFileHandle)
+{
+ HKEY hCurKey;
+
+ if(RegOpenKeyExW(hKey, aKeyName.getStr(), 0, KEY_READ, &hCurKey) == ERROR_SUCCESS)
+ {
+ DWORD nSubKeys = 0;
+ DWORD nValues = 0;
+ DWORD nLongestValueNameLen, nLongestValueLen;
+ // Query the number of subkeys
+ RegQueryInfoKeyW(hCurKey, NULL, NULL, NULL, &nSubKeys, NULL, NULL, &nValues, &nLongestValueNameLen, &nLongestValueLen, NULL, NULL);
+ if(nSubKeys)
+ {
+ //Look for subkeys in this key
+ for(DWORD i = 0; i < nSubKeys; i++)
+ {
+ wchar_t buffKeyName[MAX_KEY_LENGTH];
+ buffKeyName[0] = '\0';
+ DWORD buffSize=MAX_KEY_LENGTH;
+ OUString aSubkeyName;
+ //Get subkey name
+ RegEnumKeyExW(hCurKey, i, buffKeyName, &buffSize, NULL, NULL, NULL, NULL);
+
+ //Make up full key name
+ if(aKeyName.isEmpty())
+ aSubkeyName = aKeyName + OUString(buffKeyName);
+ else
+ aSubkeyName = aKeyName + "\\" + OUString(buffKeyName);
+
+ //Recursion, until no more subkeys are found
+ dumpWindowsRegistryKey(hKey, aSubkeyName, aFileHandle);
+ }
+ }
+ else if(nValues)
+ {
+ // No more subkeys, we are at a leaf
+ wchar_t* pValueName = new wchar_t[nLongestValueNameLen + 1];
+ wchar_t* pValue = new wchar_t[nLongestValueLen + 1];
+
+ if(pValueName && pValue)
+ {
+ bool bFinal = false;
+ OUString aValue;
+
+ for(DWORD i = 0; i < nValues; ++i)
+ {
+ DWORD nValueNameLen = nLongestValueNameLen + 1;
+ DWORD nValueLen = nLongestValueLen + 1;
+
+ RegEnumValueW(hCurKey, i, pValueName, &nValueNameLen, NULL, NULL, (LPBYTE)pValue, &nValueLen);
+ const wchar_t wsValue[] = L"Value";
+ const wchar_t wsFinal[] = L"Final";
+
+ if(!wcscmp(pValueName, wsValue))
+ aValue = OUString(pValue);
+ if(!wcscmp(pValueName, wsFinal) && *(DWORD*)pValue == 1)
+ bFinal = true;
+ }
+ sal_Int32 aLastSeparator = aKeyName.lastIndexOf('\\');
+ OUString aPath = aKeyName.replaceAll("\\","/").copy(0, aLastSeparator);
+ OUString aProp = aKeyName.copy(aLastSeparator + 1);
+
+ writeData(aFileHandle, "<item oor:path=\"/");
+ writeAttributeValue(aFileHandle, aPath);
+ writeData(aFileHandle, "\"><prop oor:name=\"");
+ writeAttributeValue(aFileHandle, aProp);
+ writeData(aFileHandle, "\"");
+ if(bFinal)
+ writeData(aFileHandle, " oor:finalized=\"true\"");
+ writeData(aFileHandle, "><value>");
+ writeValueContent(aFileHandle, aValue);
+ writeData(aFileHandle, "</value></prop></item>\n");
+ delete[] pValueName;
+ delete[] pValue;
+ }
+ }
+ RegCloseKey(hCurKey);
+ }
+}
+}
+
+bool dumpWindowsRegistry(OUString* pFileURL)
+{
+ HKEY hKey;
+ if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Policies\\LibreOffice", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
+ {
+ SAL_INFO(
+ "configmgr",
+ ("Windows registry settings do not exist in HKLM\\SOFTWARE\\Policies\\LibreOffice"));
+ return false;
+ }
+
+ oslFileHandle aFileHandle;
+ switch (osl::FileBase::createTempFile(0, &aFileHandle, pFileURL)) {
+ case osl::FileBase::E_None:
+ break;
+ case osl::FileBase::E_ACCES:
+ SAL_INFO(
+ "configmgr",
+ ("cannot create temp Windows registry dump (E_ACCES)"));
+ return false;
+ default:
+ throw css::uno::RuntimeException(
+ "cannot create temporary file",
+ css::uno::Reference< css::uno::XInterface >());
+ }
+ writeData(
+ aFileHandle,
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<oor:items"
+ " xmlns:oor=\"http://openoffice.org/2001/registry\""
+ " xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n");
+ dumpWindowsRegistryKey(hKey, "", aFileHandle);
+ writeData(aFileHandle, "</oor:items>");
+ oslFileError e = osl_closeFile(aFileHandle);
+ if (e != osl_File_E_None)
+ SAL_WARN("configmgr", "osl_closeFile failed with " << +e);
+ RegCloseKey(hKey);
+ return true;
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/configmgr/source/winreg.hxx b/configmgr/source/winreg.hxx
new file mode 100644
index 0000000..0209772
--- /dev/null
+++ b/configmgr/source/winreg.hxx
@@ -0,0 +1,22 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_CONFIGMGR_SOURCE_WINREG_HXX
+#define INCLUDED_CONFIGMGR_SOURCE_WINREG_HXX
+
+namespace configmgr {
+
+bool dumpWindowsRegistry(OUString* pFileURL);
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/configmgr/source/writemodfile.cxx b/configmgr/source/writemodfile.cxx
index daae55c..49c107e 100644
--- a/configmgr/source/writemodfile.cxx
+++ b/configmgr/source/writemodfile.cxx
@@ -21,7 +21,6 @@
#include <cassert>
-#include "boost/noncopyable.hpp"
#include "com/sun/star/uno/Any.hxx"
#include "com/sun/star/uno/Reference.hxx"
#include "com/sun/star/uno/RuntimeException.hpp"
@@ -102,6 +101,8 @@ TempFile::~TempFile() {
}
}
+}
+
void writeData(oslFileHandle handle, char const * begin, sal_Int32 length) {
assert(length >= 0);
sal_uInt64 n;
@@ -514,8 +515,6 @@ void writeModifications(
}
}
-}
-
void writeModFile(
Components & components, OUString const & url, Data const & data)
{
diff --git a/configmgr/source/writemodfile.hxx b/configmgr/source/writemodfile.hxx
index e8c81b2..727ab9f 100644
--- a/configmgr/source/writemodfile.hxx
+++ b/configmgr/source/writemodfile.hxx
@@ -22,12 +22,14 @@
#include "sal/config.h"
-
namespace configmgr {
class Components;
struct Data;
+void writeData(oslFileHandle handle, OString const & text);
+void writeAttributeValue(oslFileHandle handle, OUString const & value);
+void writeValueContent(oslFileHandle handle, OUString const & value);
void writeModFile(
Components & components, OUString const & url, Data const & data);
diff --git a/scp2/source/ooo/common_brand.scp b/scp2/source/ooo/common_brand.scp
index a6b8f12..abeddb8 100644
--- a/scp2/source/ooo/common_brand.scp
+++ b/scp2/source/ooo/common_brand.scp
@@ -1236,7 +1236,11 @@ ProfileItem gid_Brand_Profileitem_Fundamental_Configuration_Layers
ModuleID = gid_Module_Root_Brand;
Section = "Bootstrap";
Key = "CONFIGURATION_LAYERS";
+#if defined WNT
+ Value = "xcsxcu:${BRAND_BASE_DIR}/share/registry res:${BRAND_BASE_DIR}/share/registry winreg: bundledext:${${BRAND_BASE_DIR}/program/" PROFILENAME(uno) ":BUNDLED_EXTENSIONS_USER}/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/configmgr.ini sharedext:${${BRAND_BASE_DIR}/program/" PROFILENAME(uno) ":SHARED_EXTENSIONS_USER}/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/configmgr.ini userext:${${BRAND_BASE_DIR}/program/" PROFILENAME(uno) ":UNO_USER_PACKAGES_CACHE}/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/configmgr.ini user:${$BRAND_BASE_DIR/program/" PROFILENAME(bootstrap) ":UserInstallation}/user/registrymodifications.xcu";
+#else
Value = "xcsxcu:${BRAND_BASE_DIR}/share/registry res:${BRAND_BASE_DIR}/share/registry bundledext:${${BRAND_BASE_DIR}/program/" PROFILENAME(uno) ":BUNDLED_EXTENSIONS_USER}/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/configmgr.ini sharedext:${${BRAND_BASE_DIR}/program/" PROFILENAME(uno) ":SHARED_EXTENSIONS_USER}/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/configmgr.ini userext:${${BRAND_BASE_DIR}/program/" PROFILENAME(uno) ":UNO_USER_PACKAGES_CACHE}/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/configmgr.ini user:${$BRAND_BASE_DIR/program/" PROFILENAME(bootstrap) ":UserInstallation}/user/registrymodifications.xcu";
+#endif
End
#if !defined MACOSX
More information about the Libreoffice-commits
mailing list