Update ntdll.spec against current Microsoft build.
[wine/wine-kai.git] / misc / registry.c
blobdac35a6a45f235f4f31af9d64d8d11d6a206c698
1 /*
2 * Registry Functions
4 * Copyright 1996 Marcus Meissner
5 * Copyright 1998 Matthew Becker
6 * Copyright 1999 Sylvain St-Germain
8 * December 21, 1997 - Kevin Cozens
9 * Fixed bugs in the _w95_loadreg() function. Added extra information
10 * regarding the format of the Windows '95 registry files.
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * TODO
27 * Security access
28 * Option handling
29 * Time for RegEnumKey*, RegQueryInfoKey*
32 #include "config.h"
33 #include "wine/port.h"
35 #include <stdlib.h>
36 #include <string.h>
37 #include <stdarg.h>
38 #include <stdio.h>
39 #ifdef HAVE_UNISTD_H
40 # include <unistd.h>
41 #endif
42 #include <errno.h>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <fcntl.h>
46 #ifdef HAVE_SYS_IOCTL_H
47 #include <sys/ioctl.h>
48 #endif
49 #ifdef HAVE_LINUX_HDREG_H
50 # include <linux/hdreg.h>
51 #endif
53 #define NONAMELESSUNION
54 #define NONAMELESSSTRUCT
55 #include "ntstatus.h"
56 #include "windef.h"
57 #include "winbase.h"
58 #include "winerror.h"
59 #include "winioctl.h"
60 #include "ntddscsi.h"
62 #include "wine/library.h"
63 #include "wine/server.h"
64 #include "wine/unicode.h"
66 #include "wine/debug.h"
68 WINE_DEFAULT_DEBUG_CHANNEL(reg);
70 #define SAVE_GLOBAL_REGBRANCH_USER_DEFAULT "/wine.userreg"
71 #define SAVE_GLOBAL_REGBRANCH_LOCAL_MACHINE "/wine.systemreg"
73 #define MAX_PATHNAME_LEN 1024
75 #define IS_OPTION_FALSE(ch) \
76 ((ch) == 'n' || (ch) == 'N' || (ch) == 'f' || (ch) == 'F' || (ch) == '0')
80 /******************************************************************************
81 * _allocate_default_keys [Internal]
82 * Registry initialisation, allocates some default keys.
84 static void _allocate_default_keys(void)
86 static const WCHAR StatDataW[] = {'D','y','n','D','a','t','a','\\',
87 'P','e','r','f','S','t','a','t','s','\\',
88 'S','t','a','t','D','a','t','a',0};
89 static const WCHAR ConfigManagerW[] = {'D','y','n','D','a','t','a','\\',
90 'C','o','n','f','i','g',' ','M','a','n','a','g','e','r','\\',
91 'E','n','u','m',0};
92 static const WCHAR Clone[] = {'M','a','c','h','i','n','e','\\',
93 'S','y','s','t','e','m','\\',
94 'C','l','o','n','e',0};
95 HKEY hkey;
96 OBJECT_ATTRIBUTES attr;
97 UNICODE_STRING nameW;
99 TRACE("(void)\n");
101 attr.Length = sizeof(attr);
102 attr.RootDirectory = 0;
103 attr.ObjectName = &nameW;
104 attr.Attributes = 0;
105 attr.SecurityDescriptor = NULL;
106 attr.SecurityQualityOfService = NULL;
108 RtlInitUnicodeString( &nameW, StatDataW );
109 if (!NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) NtClose( hkey );
111 RtlInitUnicodeString( &nameW, ConfigManagerW );
112 if (!NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) NtClose( hkey );
114 /* this key is generated when the nt-core booted successfully */
115 RtlInitUnicodeString( &nameW, Clone );
116 if (!NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) NtClose( hkey );
121 /* load the registry file in wine format [Internal] */
122 static void load_wine_registry(HKEY hkey,LPCSTR fn)
124 WCHAR *buffer;
125 HANDLE file;
126 DWORD len;
127 UNICODE_STRING name;
128 OBJECT_ATTRIBUTES attr;
129 IO_STATUS_BLOCK io;
131 len = MultiByteToWideChar( CP_UNIXCP, 0, fn, -1, NULL, 0 );
132 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return;
133 MultiByteToWideChar( CP_UNIXCP, 0, fn, -1, buffer, len );
134 RtlInitUnicodeString( &name, buffer );
136 attr.Length = sizeof(attr);
137 attr.RootDirectory = 0;
138 attr.Attributes = 0;
139 attr.ObjectName = &name;
140 attr.SecurityDescriptor = NULL;
141 attr.SecurityQualityOfService = NULL;
143 if (!NtOpenFile( &file, GENERIC_READ, &attr, &io, FILE_SHARE_READ | FILE_SHARE_WRITE,
144 FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT ))
146 SERVER_START_REQ( load_registry )
148 req->hkey = hkey;
149 req->file = file;
150 wine_server_call( req );
152 SERVER_END_REQ;
153 CloseHandle( file );
155 HeapFree( GetProcessHeap(), 0, buffer );
159 /******************************************************************
160 * init_cdrom_registry
162 * Initializes registry to contain scsi info about the cdrom in NT.
163 * All devices (even not real scsi ones) have this info in NT.
164 * TODO: for now it only works for non scsi devices
165 * NOTE: programs usually read these registry entries after sending the
166 * IOCTL_SCSI_GET_ADDRESS ioctl to the cdrom
168 static void init_cdrom_registry( HANDLE handle )
170 OBJECT_ATTRIBUTES attr;
171 UNICODE_STRING nameW;
172 WCHAR dataW[50];
173 DWORD lenW;
174 char buffer[40];
175 DWORD value;
176 const char *data;
177 HKEY scsiKey;
178 HKEY portKey;
179 HKEY busKey;
180 HKEY targetKey;
181 DWORD disp;
182 IO_STATUS_BLOCK io;
183 SCSI_ADDRESS scsi_addr;
185 if (NtDeviceIoControlFile( handle, 0, NULL, NULL, &io, IOCTL_SCSI_GET_ADDRESS,
186 NULL, 0, &scsi_addr, sizeof(scsi_addr) ))
187 return;
189 attr.Length = sizeof(attr);
190 attr.RootDirectory = 0;
191 attr.ObjectName = &nameW;
192 attr.Attributes = 0;
193 attr.SecurityDescriptor = NULL;
194 attr.SecurityQualityOfService = NULL;
196 /* Ensure there is Scsi key */
197 if (!RtlCreateUnicodeStringFromAsciiz( &nameW, "Machine\\HARDWARE\\DEVICEMAP\\Scsi" ) ||
198 NtCreateKey( &scsiKey, KEY_ALL_ACCESS, &attr, 0,
199 NULL, REG_OPTION_VOLATILE, &disp ))
201 ERR("Cannot create DEVICEMAP\\Scsi registry key\n" );
202 return;
204 RtlFreeUnicodeString( &nameW );
206 snprintf(buffer,sizeof(buffer),"Scsi Port %d",scsi_addr.PortNumber);
207 attr.RootDirectory = scsiKey;
208 if (!RtlCreateUnicodeStringFromAsciiz( &nameW, buffer ) ||
209 NtCreateKey( &portKey, KEY_ALL_ACCESS, &attr, 0,
210 NULL, REG_OPTION_VOLATILE, &disp ))
212 ERR("Cannot create DEVICEMAP\\Scsi Port registry key\n" );
213 return;
215 RtlFreeUnicodeString( &nameW );
217 RtlCreateUnicodeStringFromAsciiz( &nameW, "Driver" );
218 data = "atapi";
219 RtlMultiByteToUnicodeN( dataW, 50, &lenW, data, strlen(data));
220 NtSetValueKey( portKey, &nameW, 0, REG_SZ, (BYTE*)dataW, lenW );
221 RtlFreeUnicodeString( &nameW );
222 value = 10;
223 RtlCreateUnicodeStringFromAsciiz( &nameW, "FirstBusTimeScanInMs" );
224 NtSetValueKey( portKey,&nameW, 0, REG_DWORD, (BYTE *)&value, sizeof(DWORD));
225 RtlFreeUnicodeString( &nameW );
226 value = 0;
227 #ifdef HDIO_GET_DMA
229 int fd, dma;
230 if (!wine_server_handle_to_fd( handle, 0, &fd, NULL ))
232 if (ioctl(fd,HDIO_GET_DMA, &dma) != -1) value = dma;
233 wine_server_release_fd( handle, fd );
236 #endif
237 RtlCreateUnicodeStringFromAsciiz( &nameW, "DMAEnabled" );
238 NtSetValueKey( portKey,&nameW, 0, REG_DWORD, (BYTE *)&value, sizeof(DWORD));
239 RtlFreeUnicodeString( &nameW );
241 snprintf(buffer,40,"Scsi Bus %d", scsi_addr.PathId);
242 attr.RootDirectory = portKey;
243 if (!RtlCreateUnicodeStringFromAsciiz( &nameW, buffer ) ||
244 NtCreateKey( &busKey, KEY_ALL_ACCESS, &attr, 0,
245 NULL, REG_OPTION_VOLATILE, &disp ))
247 ERR("Cannot create DEVICEMAP\\Scsi Port\\Scsi Bus registry key\n" );
248 return;
250 RtlFreeUnicodeString( &nameW );
252 attr.RootDirectory = busKey;
253 if (!RtlCreateUnicodeStringFromAsciiz( &nameW, "Initiator Id 255" ) ||
254 NtCreateKey( &targetKey, KEY_ALL_ACCESS, &attr, 0,
255 NULL, REG_OPTION_VOLATILE, &disp ))
257 ERR("Cannot create DEVICEMAP\\Scsi Port\\Scsi Bus\\Initiator Id 255 registry key\n" );
258 return;
260 RtlFreeUnicodeString( &nameW );
261 NtClose( targetKey );
263 snprintf(buffer,40,"Target Id %d", scsi_addr.TargetId);
264 attr.RootDirectory = busKey;
265 if (!RtlCreateUnicodeStringFromAsciiz( &nameW, buffer ) ||
266 NtCreateKey( &targetKey, KEY_ALL_ACCESS, &attr, 0,
267 NULL, REG_OPTION_VOLATILE, &disp ))
269 ERR("Cannot create DEVICEMAP\\Scsi Port\\Scsi Bus 0\\Target Id registry key\n" );
270 return;
272 RtlFreeUnicodeString( &nameW );
274 RtlCreateUnicodeStringFromAsciiz( &nameW, "Type" );
275 data = "CdRomPeripheral";
276 RtlMultiByteToUnicodeN( dataW, 50, &lenW, data, strlen(data));
277 NtSetValueKey( targetKey, &nameW, 0, REG_SZ, (BYTE*)dataW, lenW );
278 RtlFreeUnicodeString( &nameW );
279 /* FIXME - maybe read the real identifier?? */
280 RtlCreateUnicodeStringFromAsciiz( &nameW, "Identifier" );
281 data = "Wine CDROM";
282 RtlMultiByteToUnicodeN( dataW, 50, &lenW, data, strlen(data));
283 NtSetValueKey( targetKey, &nameW, 0, REG_SZ, (BYTE*)dataW, lenW );
284 RtlFreeUnicodeString( &nameW );
285 /* FIXME - we always use Cdrom0 - do not know about the nt behaviour */
286 RtlCreateUnicodeStringFromAsciiz( &nameW, "DeviceName" );
287 data = "Cdrom0";
288 RtlMultiByteToUnicodeN( dataW, 50, &lenW, data, strlen(data));
289 NtSetValueKey( targetKey, &nameW, 0, REG_SZ, (BYTE*)dataW, lenW );
290 RtlFreeUnicodeString( &nameW );
292 NtClose( targetKey );
293 NtClose( busKey );
294 NtClose( portKey );
295 NtClose( scsiKey );
299 /* create the hardware registry branch */
300 static void create_hardware_branch(void)
302 int i;
303 HANDLE handle;
304 char drive[] = "\\\\.\\A:";
306 /* create entries for cdroms */
307 for (i = 0; i < 26; i++)
309 drive[4] = 'A' + i;
310 handle = CreateFileA( drive, 0, 0, NULL, OPEN_EXISTING, 0, 0 );
311 if (handle == INVALID_HANDLE_VALUE) continue;
312 init_cdrom_registry( handle );
313 CloseHandle( handle );
318 /* convert the drive type entries from the old format to the new one */
319 static void convert_drive_types(void)
321 static const WCHAR TypeW[] = {'T','y','p','e',0};
322 static const WCHAR drive_types_keyW[] = {'M','a','c','h','i','n','e','\\',
323 'S','o','f','t','w','a','r','e','\\',
324 'W','i','n','e','\\',
325 'D','r','i','v','e','s',0 };
326 WCHAR driveW[] = {'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e','\\',
327 'W','i','n','e','\\','W','i','n','e','\\',
328 'C','o','n','f','i','g','\\','D','r','i','v','e',' ','A',0};
329 char tmp[32*sizeof(WCHAR) + sizeof(KEY_VALUE_PARTIAL_INFORMATION)];
330 OBJECT_ATTRIBUTES attr;
331 UNICODE_STRING nameW;
332 DWORD dummy;
333 ULONG disp;
334 HKEY hkey_old, hkey_new;
335 int i;
337 attr.Length = sizeof(attr);
338 attr.RootDirectory = 0;
339 attr.ObjectName = &nameW;
340 attr.Attributes = 0;
341 attr.SecurityDescriptor = NULL;
342 attr.SecurityQualityOfService = NULL;
343 RtlInitUnicodeString( &nameW, drive_types_keyW );
345 if (NtCreateKey( &hkey_new, KEY_ALL_ACCESS, &attr, 0, NULL, 0, &disp )) return;
346 if (disp != REG_CREATED_NEW_KEY)
348 NtClose( hkey_new );
349 return;
352 for (i = 0; i < 26; i++)
354 RtlInitUnicodeString( &nameW, driveW );
355 nameW.Buffer[(nameW.Length / sizeof(WCHAR)) - 1] = 'A' + i;
356 if (NtOpenKey( &hkey_old, KEY_ALL_ACCESS, &attr ) != STATUS_SUCCESS) continue;
357 RtlInitUnicodeString( &nameW, TypeW );
358 if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy ))
360 WCHAR valueW[] = {'A',':',0};
361 WCHAR *type = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
363 valueW[0] = 'A' + i;
364 RtlInitUnicodeString( &nameW, valueW );
365 NtSetValueKey( hkey_new, &nameW, 0, REG_SZ, type, (strlenW(type) + 1) * sizeof(WCHAR) );
366 MESSAGE( "Converted drive type to new entry HKLM\\Software\\Wine\\Drives \"%c:\" = %s\n",
367 'A' + i, debugstr_w(type) );
369 NtClose( hkey_old );
371 NtClose( hkey_new );
375 /* convert the environment variable entries from the old format to the new one */
376 static void convert_environment( HKEY hkey_current_user )
378 static const WCHAR wineW[] = {'M','a','c','h','i','n','e','\\',
379 'S','o','f','t','w','a','r','e','\\',
380 'W','i','n','e','\\','W','i','n','e','\\',
381 'C','o','n','f','i','g','\\','W','i','n','e',0};
382 static const WCHAR windowsW[] = {'w','i','n','d','o','w','s',0};
383 static const WCHAR systemW[] = {'s','y','s','t','e','m',0};
384 static const WCHAR windirW[] = {'w','i','n','d','i','r',0};
385 static const WCHAR systemrootW[] = {'S','y','s','t','e','m','r','o','o','t',0};
386 static const WCHAR winsysdirW[] = {'w','i','n','s','y','s','d','i','r',0};
387 static const WCHAR envW[] = {'E','n','v','i','r','o','n','m','e','n','t',0};
388 static const WCHAR tempW[] = {'T','E','M','P',0};
389 static const WCHAR tmpW[] = {'T','M','P',0};
390 static const WCHAR pathW[] = {'P','A','T','H',0};
391 static const WCHAR profileW[] = {'p','r','o','f','i','l','e',0};
392 static const WCHAR userprofileW[] = {'U','S','E','R','P','R','O','F','I','L','E',0};
394 char buffer[1024*sizeof(WCHAR) + sizeof(KEY_VALUE_PARTIAL_INFORMATION)];
395 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
396 OBJECT_ATTRIBUTES attr;
397 UNICODE_STRING nameW;
398 DWORD dummy;
399 ULONG disp;
400 HKEY hkey_old, hkey_env;
402 attr.Length = sizeof(attr);
403 attr.RootDirectory = 0;
404 attr.ObjectName = &nameW;
405 attr.Attributes = 0;
406 attr.SecurityDescriptor = NULL;
407 attr.SecurityQualityOfService = NULL;
408 RtlInitUnicodeString( &nameW, wineW );
410 if (NtOpenKey( &hkey_old, KEY_ALL_ACCESS, &attr ) != STATUS_SUCCESS) return;
412 attr.RootDirectory = hkey_current_user;
413 RtlInitUnicodeString( &nameW, envW );
414 if (NtCreateKey( &hkey_env, KEY_ALL_ACCESS, &attr, 0, NULL, 0, &disp ))
416 NtClose( hkey_old );
417 return;
420 /* Test for existence of TEMP */
421 RtlInitUnicodeString( &nameW, tempW );
422 if (NtQueryValueKey(hkey_env, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
424 /* convert TEMP */
425 RtlInitUnicodeString( &nameW, tempW );
426 if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
428 NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
429 RtlInitUnicodeString( &nameW, tmpW );
430 NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
431 MESSAGE( "Converted temp dir to new entry HKCU\\Environment \"TEMP\" = %s\n",
432 debugstr_w( (WCHAR*)info->Data ) );
436 /* Test for existence of PATH */
437 RtlInitUnicodeString( &nameW, pathW );
438 if (NtQueryValueKey(hkey_env, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
440 /* convert PATH */
441 RtlInitUnicodeString( &nameW, pathW );
442 if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
444 NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
445 MESSAGE( "Converted path dir to new entry HKCU\\Environment \"PATH\" = %s\n",
446 debugstr_w( (WCHAR*)info->Data ) );
450 /* Test for existence of USERPROFILE */
451 RtlInitUnicodeString( &nameW, userprofileW );
452 if (NtQueryValueKey(hkey_env, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
454 /* convert USERPROFILE */
455 RtlInitUnicodeString( &nameW, profileW );
456 if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
458 RtlInitUnicodeString( &nameW, userprofileW );
459 NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
460 MESSAGE( "Converted profile dir to new entry HKCU\\Environment \"USERPROFILE\" = %s\n",
461 debugstr_w( (WCHAR*)info->Data ) );
465 /* Test for existence of windir */
466 RtlInitUnicodeString( &nameW, windirW );
467 if (NtQueryValueKey(hkey_env, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
469 /* convert windir */
470 RtlInitUnicodeString( &nameW, windowsW );
471 if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
473 RtlInitUnicodeString( &nameW, windirW );
474 NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
475 RtlInitUnicodeString( &nameW, systemrootW );
476 NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
477 MESSAGE( "Converted windows dir to new entry HKCU\\Environment \"windir\" = %s\n",
478 debugstr_w( (WCHAR*)info->Data ) );
482 /* Test for existence of winsysdir */
483 RtlInitUnicodeString( &nameW, winsysdirW );
484 if (NtQueryValueKey(hkey_env, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
486 /* convert winsysdir */
487 RtlInitUnicodeString( &nameW, systemW );
488 if (!NtQueryValueKey( hkey_old, &nameW, KeyValuePartialInformation, buffer, sizeof(buffer), &dummy ))
490 RtlInitUnicodeString( &nameW, winsysdirW );
491 NtSetValueKey( hkey_env, &nameW, 0, info->Type, info->Data, info->DataLength );
492 MESSAGE( "Converted system dir to new entry HKCU\\Environment \"winsysdir\" = %s\n",
493 debugstr_w( (WCHAR*)info->Data ) );
496 NtClose( hkey_old );
497 NtClose( hkey_env );
501 /* load all registry (native and global and home) */
502 void SHELL_LoadRegistry( void )
504 HKEY hkey_local_machine, hkey_users, hkey_users_default, hkey_current_user, hkey_config;
505 OBJECT_ATTRIBUTES attr;
506 UNICODE_STRING nameW;
507 DWORD count;
508 ULONG dispos;
509 BOOL res;
510 int all, period;
511 char tmp[1024];
513 static const WCHAR MachineW[] = {'M','a','c','h','i','n','e',0};
514 static const WCHAR UserW[] = {'U','s','e','r',0};
515 static const WCHAR DefaultW[] = {'.','D','e','f','a','u','l','t',0};
516 static const WCHAR RegistryW[] = {'M','a','c','h','i','n','e','\\',
517 'S','o','f','t','w','a','r','e','\\',
518 'W','i','n','e','\\',
519 'W','i','n','e','\\',
520 'C','o','n','f','i','g','\\',
521 'R','e','g','i','s','t','r','y',0};
522 static const WCHAR load_global_reg_filesW[] = {'L','o','a','d','G','l','o','b','a','l','R','e','g','i','s','t','r','y','F','i','l','e','s',0};
523 static const WCHAR SaveOnlyUpdatedKeysW[] = {'S','a','v','e','O','n','l','y','U','p','d','a','t','e','d','K','e','y','s',0};
524 static const WCHAR PeriodicSaveW[] = {'P','e','r','i','o','d','i','c','S','a','v','e',0};
525 static const WCHAR GlobalRegistryDirW[] = {'G','l','o','b','a','l','R','e','g','i','s','t','r','y','D','i','r',0};
527 TRACE("(void)\n");
529 attr.Length = sizeof(attr);
530 attr.RootDirectory = 0;
531 attr.ObjectName = &nameW;
532 attr.Attributes = 0;
533 attr.SecurityDescriptor = NULL;
534 attr.SecurityQualityOfService = NULL;
536 RtlInitUnicodeString( &nameW, UserW );
537 NtCreateKey( &hkey_users, KEY_ALL_ACCESS, &attr, 0, NULL, 0, &dispos );
538 if (dispos == REG_OPENED_EXISTING_KEY)
540 /* someone else already loaded the registry */
541 NtClose( hkey_users );
542 return;
545 RtlInitUnicodeString( &nameW, MachineW );
546 NtCreateKey( &hkey_local_machine, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL );
548 attr.RootDirectory = hkey_users;
549 RtlInitUnicodeString( &nameW, DefaultW );
550 if (NtCreateKey( &hkey_users_default, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ))
552 ERR("Cannot create HKEY_USERS/.Default\n" );
553 ExitProcess(1);
555 RtlOpenCurrentUser( KEY_ALL_ACCESS, &hkey_current_user );
557 _allocate_default_keys();
559 attr.RootDirectory = 0;
560 RtlInitUnicodeString( &nameW, RegistryW );
561 if (NtOpenKey( &hkey_config, KEY_ALL_ACCESS, &attr )) hkey_config = 0;
563 /* load global registry if required */
565 res = TRUE;
566 RtlInitUnicodeString( &nameW, load_global_reg_filesW );
567 if (!NtQueryValueKey( hkey_config, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
569 WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
570 res = !IS_OPTION_FALSE(str[0]);
572 if (res)
574 /* load global registry files (stored in /etc/wine) */
575 char *p, configfile[MAX_PATHNAME_LEN];
577 /* Override ETCDIR? */
578 configfile[0] = 0;
579 RtlInitUnicodeString( &nameW, GlobalRegistryDirW );
580 if (!NtQueryValueKey( hkey_config, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
582 WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
583 RtlUnicodeToMultiByteN( configfile, sizeof(configfile), NULL,
584 str, (strlenW(str) + 1) * sizeof(WCHAR));
586 if (configfile[0] != '/') strcpy(configfile, ETCDIR);
588 TRACE("GlobalRegistryDir is '%s'.\n", configfile);
590 /* Load the global HKU hive directly from sysconfdir */
591 p = configfile + strlen(configfile);
592 strcpy(p, SAVE_GLOBAL_REGBRANCH_USER_DEFAULT);
593 load_wine_registry( hkey_users, configfile );
595 /* Load the global machine defaults directly from sysconfdir */
596 strcpy(p, SAVE_GLOBAL_REGBRANCH_LOCAL_MACHINE);
597 load_wine_registry( hkey_local_machine, configfile );
600 /* setup registry saving */
602 all = FALSE;
603 RtlInitUnicodeString( &nameW, SaveOnlyUpdatedKeysW );
604 if (!NtQueryValueKey( hkey_config, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
606 WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
607 all = IS_OPTION_FALSE(str[0]);
610 period = 0;
611 RtlInitUnicodeString( &nameW, PeriodicSaveW );
612 if (!NtQueryValueKey( hkey_config, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
614 WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
615 period = (int)strtolW(str, NULL, 10);
618 /* load home registry and set saving level (0 for saving everything,
619 * 1 for saving only modified keys) */
621 SERVER_START_REQ( load_user_registries )
623 req->hkey = hkey_current_user;
624 req->saving = !all;
625 req->period = period * 1000;
626 wine_server_call( req );
628 SERVER_END_REQ;
630 /* create hardware registry branch */
632 create_hardware_branch();
634 /* convert keys from config file to new registry format */
636 convert_drive_types();
637 convert_environment( hkey_current_user );
639 NtClose(hkey_users_default);
640 NtClose(hkey_current_user);
641 NtClose(hkey_users);
642 NtClose(hkey_local_machine);
643 NtClose(hkey_config);