14#define WIN32_LEAN_AND_MEAN
18#include <com/sun/star/uno/RuntimeException.hpp>
19#include <com/sun/star/uno/XInterface.hpp>
20#include <rtl/ustring.hxx>
23#include <osl/file.hxx>
28#define MAX_KEY_LENGTH 255
116void dumpWindowsRegistryKey(HKEY hKey, OUString
const & aKeyName, TempFile &aFileHandle)
121 hKey, o3tl::toW(aKeyName.getStr()), 0,
127 DWORD nLongestValueNameLen, nLongestValueLen;
129 RegQueryInfoKeyW(hCurKey,
nullptr,
nullptr,
nullptr, &nSubKeys,
nullptr,
nullptr, &nValues, &nLongestValueNameLen, &nLongestValueLen,
nullptr,
nullptr);
133 for(DWORD
i = 0;
i < nSubKeys;
i++)
136 buffKeyName[0] =
'\0';
138 OUString aSubkeyName;
140 RegEnumKeyExW(hCurKey,
i, buffKeyName, &buffSize,
nullptr,
nullptr,
nullptr,
nullptr);
143 if(aKeyName.isEmpty())
144 aSubkeyName = aKeyName + o3tl::toU(buffKeyName);
146 aSubkeyName = aKeyName +
"\\" + o3tl::toU(buffKeyName);
149 dumpWindowsRegistryKey(hKey, aSubkeyName, aFileHandle);
155 auto pValueName = std::unique_ptr<wchar_t[]>(
156 new wchar_t[nLongestValueNameLen + 1]);
157 auto pValue = std::unique_ptr<wchar_t[]>(
158 new wchar_t[nLongestValueLen/
sizeof(
wchar_t) + 1]);
161 bool bExternal =
false;
165 OUString aExternalBackend;
167 for(DWORD
i = 0;
i < nValues; ++
i)
169 DWORD nValueNameLen = nLongestValueNameLen + 1;
170 DWORD nValueLen = nLongestValueLen + 1;
172 RegEnumValueW(hCurKey,
i, pValueName.get(), &nValueNameLen,
nullptr,
nullptr,
reinterpret_cast<LPBYTE
>(pValue.get()), &nValueLen);
174 if (!wcscmp(pValueName.get(), L
"Value"))
175 aValue = o3tl::toU(pValue.get());
176 else if (!wcscmp(pValueName.get(), L
"Type"))
177 aType = o3tl::toU(pValue.get());
178 else if (!wcscmp(pValueName.get(), L
"Final"))
180 if (*
reinterpret_cast<DWORD*
>(pValue.get()) == 1)
183 else if (!wcscmp(pValueName.get(), L
"Nil"))
185 if (*
reinterpret_cast<DWORD*
>(pValue.get()) == 1)
188 else if (!wcscmp(pValueName.get(), L
"External"))
190 if (*
reinterpret_cast<DWORD*
>(pValue.get()) == 1)
193 else if (!wcscmp(pValueName.get(), L
"ExternalBackend"))
194 aExternalBackend = o3tl::toU(pValue.get());
203 if (!aExternalBackend.isEmpty())
204 aValue = aExternalBackend +
" " + aValue;
207 sal_Int32 aLastSeparator = aKeyName.lastIndexOf(
'\\');
208 OUString aPathAndNodes = aKeyName.copy(0, aLastSeparator);
209 OUString aProp = aKeyName.copy(aLastSeparator + 1);
210 bool bHasNode =
false;
211 sal_Int32 nCloseNode = 0;
213 aFileHandle.writeString(
"<item oor:path=\"");
214 for(sal_Int32
nIndex = 0;;)
216 OUString aNextPathPart = aPathAndNodes.getToken(0,
'\\',
nIndex);
218 if(!aNextPathPart.isEmpty())
220 if((aNextPathPart.lastIndexOf(
"/#") != -1) || bHasNode)
224 aFileHandle.writeString(
"\"><node oor:name=\"");
225 sal_Int32 nCommandSeparator = aNextPathPart.lastIndexOf(
'#');
226 if(nCommandSeparator != -1)
228 OUString aNodeOp = aNextPathPart.copy(nCommandSeparator + 1);
230 aFileHandle.writeString(
"\" oor:op=\"");
241 aFileHandle, Concat2View(
"/" + aNextPathPart));
246 aFileHandle.writeString(
"\">");
251 aFileHandle.writeString(
"<prop oor:name=\"");
253 aFileHandle.writeString(
"\"");
256 aFileHandle.writeString(
" oor:type=\"");
258 aFileHandle.writeString(
"\"");
261 aFileHandle.writeString(
" oor:finalized=\"true\"");
262 aFileHandle.writeString(
"><value");
263 if (aValue.isEmpty() && bNil)
265 aFileHandle.writeString(
" xsi:nil=\"true\"/");
269 aFileHandle.writeString(
" oor:external=\"");
271 aFileHandle.writeString(
"\"/");
275 aFileHandle.writeString(
">");
277 aFileHandle.writeString(
"</value");
279 aFileHandle.writeString(
"></prop>");
280 for(; nCloseNode > 0; nCloseNode--)
281 aFileHandle.writeString(
"</node>");
282 aFileHandle.writeString(
"</item>\n");
284 RegCloseKey(hCurKey);
293 if(RegOpenKeyExW(hDomain, L
"SOFTWARE\\Policies\\LibreOffice", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
297 (
"Windows registry settings do not exist in HKLM\\SOFTWARE\\Policies\\LibreOffice"));
302 switch (osl::FileBase::createTempFile(
nullptr, &aFileHandle.
handle, pFileURL)) {
303 case osl::FileBase::E_None:
305 case osl::FileBase::E_ACCES:
308 (
"cannot create temp Windows registry dump (E_ACCES)"));
311 throw css::uno::RuntimeException(
312 "cannot create temporary file");
314 aFileHandle.
url = *pFileURL;
316 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<oor:items"
317 " xmlns:oor=\"http://openoffice.org/2001/registry\""
318 " xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""
319 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n");
320 dumpWindowsRegistryKey(hKey,
"", aFileHandle);
322 oslFileError e = aFileHandle.closeWithoutUnlink();
323 if (e != osl_File_E_None)
324 SAL_WARN(
"configmgr",
"osl_closeFile failed with " << +e);
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
void writeValueContent(TempFile &handle, std::u16string_view value)
bool dumpWindowsRegistry(OUString *pFileURL, WinRegType eType)
void writeAttributeValue(TempFile &handle, std::u16string_view value)
void writeString(std::string_view text)