Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Registry Functions |
| 3 | * |
| 4 | * Copyright 1996 Marcus Meissner |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 5 | * Copyright 1998 Matthew Becker |
Sylvain St.Germain | e533222 | 1999-04-10 16:46:15 +0000 | [diff] [blame] | 6 | * Copyright 1999 Sylvain St-Germain |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 7 | * |
| 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. |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 11 | * |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 12 | * NOTES |
| 13 | * When changing this file, please re-run the regtest program to ensure |
| 14 | * the conditions are handled properly. |
| 15 | * |
| 16 | * TODO |
| 17 | * Security access |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 18 | * Option handling |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 19 | * Time for RegEnumKey*, RegQueryInfoKey* |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Marcus Meissner | 31b9dab | 1999-10-24 22:08:33 +0000 | [diff] [blame] | 22 | #include "config.h" |
| 23 | |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 24 | #include <stdlib.h> |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 25 | #include <string.h> |
| 26 | #include <unistd.h> |
| 27 | #include <ctype.h> |
Alexandre Julliard | 8664b89 | 1996-04-05 14:58:24 +0000 | [diff] [blame] | 28 | #include <errno.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 29 | #ifdef HAVE_SYS_ERRNO_H |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 30 | #include <sys/errno.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 31 | #endif |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 32 | #include <sys/types.h> |
Patrik Stridvall | 6afc68a | 2000-01-04 00:32:38 +0000 | [diff] [blame] | 33 | #include <fcntl.h> |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 34 | #include <sys/fcntl.h> |
| 35 | #include <sys/stat.h> |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 36 | #include <assert.h> |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 37 | #include <time.h> |
Marcus Meissner | 04c3e1d | 1999-02-19 10:37:02 +0000 | [diff] [blame] | 38 | #include "windef.h" |
| 39 | #include "winbase.h" |
| 40 | #include "wine/winbase16.h" |
| 41 | #include "wine/winestring.h" |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 42 | #include "winerror.h" |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 43 | #include "file.h" |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 44 | #include "heap.h" |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 45 | #include "debugtools.h" |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 46 | #include "xmalloc.h" |
Marcus Meissner | 6b9dd2e | 1999-03-18 17:39:57 +0000 | [diff] [blame] | 47 | #include "options.h" |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 48 | #include "winreg.h" |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 49 | #include "server.h" |
Alexandre Julliard | 705686e | 1999-11-24 19:34:32 +0000 | [diff] [blame] | 50 | #include "services.h" |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 51 | |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 52 | DEFAULT_DEBUG_CHANNEL(reg) |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 53 | |
Juergen Schmied | ebc2b77 | 1998-11-14 18:59:30 +0000 | [diff] [blame] | 54 | static void REGISTRY_Init(void); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 55 | /* FIXME: following defines should be configured global ... */ |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 56 | |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 57 | /* NOTE: do not append a /. linux' mkdir() WILL FAIL if you do that */ |
Sylvain St.Germain | e533222 | 1999-04-10 16:46:15 +0000 | [diff] [blame] | 58 | #define WINE_PREFIX "/.wine" |
Marcus Meissner | adf8a0c | 1999-06-12 08:18:38 +0000 | [diff] [blame] | 59 | #define SAVE_USERS_DEFAULT ETCDIR"/wine.userreg" |
| 60 | #define SAVE_LOCAL_MACHINE_DEFAULT ETCDIR"/wine.systemreg" |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 61 | |
| 62 | /* relative in ~user/.wine/ : */ |
Sylvain St.Germain | e533222 | 1999-04-10 16:46:15 +0000 | [diff] [blame] | 63 | #define SAVE_CURRENT_USER "user.reg" |
| 64 | #define SAVE_LOCAL_USERS_DEFAULT "wine.userreg" |
| 65 | #define SAVE_LOCAL_MACHINE "system.reg" |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 66 | |
Sylvain St.Germain | e533222 | 1999-04-10 16:46:15 +0000 | [diff] [blame] | 67 | #define KEY_REGISTRY "Software\\The WINE team\\WINE\\Registry" |
| 68 | #define VAL_SAVEUPDATED "SaveOnlyUpdatedKeys" |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 69 | |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 70 | |
| 71 | /* what valuetypes do we need to convert? */ |
| 72 | #define UNICONVMASK ((1<<REG_SZ)|(1<<REG_MULTI_SZ)|(1<<REG_EXPAND_SZ)) |
| 73 | |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 74 | |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 75 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 76 | /* |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 77 | * QUESTION |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 78 | * Are these doing the same as HEAP_strdupAtoW and HEAP_strdupWtoA? |
| 79 | * If so, can we remove them? |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 80 | * ANSWER |
| 81 | * No, the memory handling functions are called very often in here, |
| 82 | * just replacing them by HeapAlloc(SystemHeap,...) makes registry |
| 83 | * loading 100 times slower. -MM |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 84 | */ |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 85 | static LPWSTR strdupA2W(LPCSTR src) |
| 86 | { |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 87 | if(src) { |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 88 | LPWSTR dest=xmalloc(2*strlen(src)+2); |
| 89 | lstrcpyAtoW(dest,src); |
| 90 | return dest; |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 91 | } |
| 92 | return NULL; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 95 | LPWSTR strcvtA2W(LPCSTR src, int nchars) |
| 96 | |
| 97 | { |
| 98 | LPWSTR dest = xmalloc (2 * nchars + 2); |
| 99 | |
| 100 | lstrcpynAtoW(dest,src,nchars+1); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 101 | return dest; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 102 | } |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 103 | |
| 104 | |
| 105 | |
| 106 | /****************************************************************************** |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 107 | * REGISTRY_Init [Internal] |
| 108 | * Registry initialisation, allocates some default keys. |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 109 | */ |
Juergen Schmied | ebc2b77 | 1998-11-14 18:59:30 +0000 | [diff] [blame] | 110 | static void REGISTRY_Init(void) { |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 111 | HKEY hkey; |
| 112 | char buf[200]; |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 113 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 114 | TRACE("(void)\n"); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 115 | |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 116 | RegCreateKeyA(HKEY_DYN_DATA,"PerfStats\\StatData",&hkey); |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 117 | RegCloseKey(hkey); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 118 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 119 | /* This was an Open, but since it is called before the real registries |
| 120 | are loaded, it was changed to a Create - MTB 980507*/ |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 121 | RegCreateKeyA(HKEY_LOCAL_MACHINE,"HARDWARE\\DESCRIPTION\\System",&hkey); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 122 | RegSetValueExA(hkey,"Identifier",0,REG_SZ,"SystemType WINE",strlen("SystemType WINE")); |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 123 | RegCloseKey(hkey); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 124 | |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 125 | /* \\SOFTWARE\\Microsoft\\Window NT\\CurrentVersion |
| 126 | * CurrentVersion |
| 127 | * CurrentBuildNumber |
| 128 | * CurrentType |
| 129 | * string RegisteredOwner |
| 130 | * string RegisteredOrganization |
| 131 | * |
| 132 | */ |
| 133 | /* System\\CurrentControlSet\\Services\\SNMP\\Parameters\\RFC1156Agent |
| 134 | * string SysContact |
| 135 | * string SysLocation |
| 136 | * SysServices |
Huw D M Davies | f49cb52 | 1999-11-12 00:58:15 +0000 | [diff] [blame] | 137 | */ |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 138 | if (-1!=gethostname(buf,200)) { |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 139 | RegCreateKeyA(HKEY_LOCAL_MACHINE,"System\\CurrentControlSet\\Control\\ComputerName\\ComputerName",&hkey); |
| 140 | RegSetValueExA(hkey,"ComputerName",0,REG_SZ,buf,strlen(buf)+1); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 141 | RegCloseKey(hkey); |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 142 | } |
| 143 | } |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 144 | |
| 145 | |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 146 | /************************ SAVE Registry Function ****************************/ |
| 147 | |
| 148 | #define REGISTRY_SAVE_VERSION 0x00000001 |
| 149 | |
| 150 | /* Registry saveformat: |
| 151 | * If you change it, increase above number by 1, which will flush |
| 152 | * old registry database files. |
| 153 | * |
| 154 | * Global: |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 155 | * "WINE REGISTRY Version %d" |
| 156 | * subkeys.... |
| 157 | * Subkeys: |
| 158 | * keyname |
| 159 | * valuename=lastmodified,type,data |
| 160 | * ... |
| 161 | * subkeys |
| 162 | * ... |
| 163 | * keyname,valuename,stringdata: |
| 164 | * the usual ascii characters from 0x00-0xff (well, not 0x00) |
| 165 | * and \uXXXX as UNICODE value XXXX with XXXX>0xff |
| 166 | * ( "=\\\t" escaped in \uXXXX form.) |
| 167 | * type,lastmodified: |
| 168 | * int |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 169 | * |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 170 | * FIXME: doesn't save 'class' (what does it mean anyway?), nor flags. |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 171 | * |
| 172 | * [HKEY_CURRENT_USER\\Software\\The WINE team\\WINE\\Registry] |
| 173 | * SaveOnlyUpdatedKeys=yes |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 174 | */ |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 175 | |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 176 | /* Same as RegSaveKey but with Unix pathnames */ |
| 177 | static void save_key( HKEY hkey, const char *filename ) |
| 178 | { |
| 179 | struct save_registry_request *req = get_req_buffer(); |
| 180 | int count = 0; |
| 181 | DWORD ret; |
| 182 | HANDLE handle; |
Alexandre Julliard | 6b34fed | 1999-11-25 22:15:11 +0000 | [diff] [blame] | 183 | char *p; |
| 184 | char *name = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + 20 ); |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 185 | |
Alexandre Julliard | 6b34fed | 1999-11-25 22:15:11 +0000 | [diff] [blame] | 186 | if (!name) return; |
| 187 | strcpy( name, filename ); |
| 188 | if ((p = strrchr( name, '/' ))) p++; |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 189 | else p = name; |
| 190 | |
| 191 | for (;;) |
| 192 | { |
| 193 | sprintf( p, "reg%04x.tmp", count++ ); |
| 194 | handle = FILE_CreateFile( name, GENERIC_WRITE, 0, NULL, |
| 195 | CREATE_NEW, FILE_ATTRIBUTE_NORMAL, -1 ); |
| 196 | if (handle != INVALID_HANDLE_VALUE) break; |
Alexandre Julliard | 6b34fed | 1999-11-25 22:15:11 +0000 | [diff] [blame] | 197 | if ((ret = GetLastError()) != ERROR_FILE_EXISTS) break; |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Alexandre Julliard | 6b34fed | 1999-11-25 22:15:11 +0000 | [diff] [blame] | 200 | if (handle != INVALID_HANDLE_VALUE) |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 201 | { |
Alexandre Julliard | 6b34fed | 1999-11-25 22:15:11 +0000 | [diff] [blame] | 202 | req->hkey = hkey; |
| 203 | req->file = handle; |
| 204 | ret = server_call_noerr( REQ_SAVE_REGISTRY ); |
| 205 | CloseHandle( handle ); |
| 206 | if (ret) unlink( name ); |
| 207 | else if (rename( name, filename ) == -1) |
| 208 | { |
| 209 | ERR( "Failed to move %s to %s: ", name, filename ); |
| 210 | perror( "rename" ); |
| 211 | unlink( name ); |
| 212 | } |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 213 | } |
Alexandre Julliard | 6b34fed | 1999-11-25 22:15:11 +0000 | [diff] [blame] | 214 | HeapFree( GetProcessHeap(), 0, name ); |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 215 | } |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 216 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 217 | |
| 218 | /****************************************************************************** |
Andreas Mohr | d4b13da | 1999-08-07 14:17:10 +0000 | [diff] [blame] | 219 | * SHELL_SaveRegistryBranch [Internal] |
| 220 | * |
| 221 | * Saves main registry branch specified by hkey. |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 222 | */ |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 223 | static void SHELL_SaveRegistryBranch(HKEY hkey) |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 224 | { |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 225 | char *fn, *home; |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 226 | |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 227 | /* Find out what to save to, get from config file */ |
| 228 | BOOL writeToHome = PROFILE_GetWineIniBool("registry","WritetoHomeRegistries",1); |
| 229 | BOOL writeToAlt = PROFILE_GetWineIniBool("registry","WritetoAltRegistries",1); |
| 230 | |
Andreas Mohr | d4b13da | 1999-08-07 14:17:10 +0000 | [diff] [blame] | 231 | /* FIXME: does this check apply to all keys written below ? */ |
Alexandre Julliard | 154c99b | 1999-04-25 12:41:36 +0000 | [diff] [blame] | 232 | if (!(home = getenv( "HOME" ))) |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 233 | ERR("Failed to get homedirectory of UID %ld.\n",(long) getuid()); |
Andreas Mohr | d4b13da | 1999-08-07 14:17:10 +0000 | [diff] [blame] | 234 | |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 235 | /* HKEY_LOCAL_MACHINE contains the HKEY_CLASSES_ROOT branch */ |
| 236 | if (hkey == HKEY_CLASSES_ROOT) hkey = HKEY_LOCAL_MACHINE; |
Andreas Mohr | d4b13da | 1999-08-07 14:17:10 +0000 | [diff] [blame] | 237 | |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 238 | switch (hkey) |
Andreas Mohr | d4b13da | 1999-08-07 14:17:10 +0000 | [diff] [blame] | 239 | { |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 240 | case HKEY_CURRENT_USER: |
| 241 | fn = xmalloc( MAX_PATHNAME_LEN ); |
| 242 | if (writeToAlt && PROFILE_GetWineIniString( "registry", "AltCurrentUserFile", "", |
| 243 | fn, MAX_PATHNAME_LEN - 1)) |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 244 | save_key( HKEY_CURRENT_USER, fn ); |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 245 | free (fn); |
Andreas Mohr | d4b13da | 1999-08-07 14:17:10 +0000 | [diff] [blame] | 246 | |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 247 | if (home && writeToHome) |
| 248 | { |
| 249 | fn=(char*)xmalloc( strlen(home) + strlen(WINE_PREFIX) + |
| 250 | strlen(SAVE_CURRENT_USER) + 2 ); |
| 251 | strcpy(fn,home); |
| 252 | strcat(fn,WINE_PREFIX); |
Alexandre Julliard | 154c99b | 1999-04-25 12:41:36 +0000 | [diff] [blame] | 253 | |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 254 | /* create the directory. don't care about errorcodes. */ |
| 255 | mkdir(fn,0755); /* drwxr-xr-x */ |
| 256 | strcat(fn,"/"SAVE_CURRENT_USER); |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 257 | save_key( HKEY_CURRENT_USER, fn ); |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 258 | free(fn); |
Alexandre Julliard | 154c99b | 1999-04-25 12:41:36 +0000 | [diff] [blame] | 259 | } |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 260 | break; |
| 261 | case HKEY_LOCAL_MACHINE: |
| 262 | /* Try first saving according to the defined location in .winerc */ |
| 263 | fn = xmalloc ( MAX_PATHNAME_LEN); |
| 264 | if (writeToAlt && PROFILE_GetWineIniString( "Registry", "AltLocalMachineFile", "", |
| 265 | fn, MAX_PATHNAME_LEN - 1)) |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 266 | save_key( HKEY_LOCAL_MACHINE, fn ); |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 267 | free (fn); |
Nathan Zorich | bd3771c | 1999-03-14 15:12:48 +0000 | [diff] [blame] | 268 | |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 269 | if (home && writeToHome) |
| 270 | { |
| 271 | fn=(char*)xmalloc( strlen(home) + strlen(WINE_PREFIX) + |
| 272 | strlen(SAVE_LOCAL_MACHINE) + 2); |
| 273 | strcpy(fn,home); |
| 274 | strcat(fn,WINE_PREFIX"/"SAVE_LOCAL_MACHINE); |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 275 | save_key( HKEY_LOCAL_MACHINE, fn ); |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 276 | free(fn); |
Alexandre Julliard | 154c99b | 1999-04-25 12:41:36 +0000 | [diff] [blame] | 277 | } |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 278 | break; |
| 279 | case HKEY_USERS: |
| 280 | fn = xmalloc( MAX_PATHNAME_LEN ); |
| 281 | if (writeToAlt && PROFILE_GetWineIniString( "Registry", "AltUserFile", "", |
| 282 | fn, MAX_PATHNAME_LEN - 1)) |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 283 | save_key( HKEY_USERS, fn ); |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 284 | free (fn); |
Nathan Zorich | bd3771c | 1999-03-14 15:12:48 +0000 | [diff] [blame] | 285 | |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 286 | if (home && writeToHome) |
| 287 | { |
| 288 | fn=(char*)xmalloc( strlen(home) + strlen(WINE_PREFIX) + |
| 289 | strlen(SAVE_LOCAL_USERS_DEFAULT) + 2); |
| 290 | strcpy(fn,home); |
| 291 | strcat(fn,WINE_PREFIX"/"SAVE_LOCAL_USERS_DEFAULT); |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 292 | save_key( HKEY_USERS, fn ); |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 293 | free(fn); |
Alexandre Julliard | 154c99b | 1999-04-25 12:41:36 +0000 | [diff] [blame] | 294 | } |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 295 | break; |
| 296 | default: |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 297 | ERR("unknown/invalid key handle !\n"); |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 298 | break; |
Sylvain St.Germain | e533222 | 1999-04-10 16:46:15 +0000 | [diff] [blame] | 299 | } |
Andreas Mohr | d4b13da | 1999-08-07 14:17:10 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | |
| 303 | /****************************************************************************** |
| 304 | * SHELL_SaveRegistry [Internal] |
| 305 | */ |
| 306 | void SHELL_SaveRegistry( void ) |
| 307 | { |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 308 | struct set_registry_levels_request *req = get_req_buffer(); |
Andreas Mohr | d4b13da | 1999-08-07 14:17:10 +0000 | [diff] [blame] | 309 | char buf[4]; |
| 310 | HKEY hkey; |
| 311 | int all; |
| 312 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 313 | TRACE("(void)\n"); |
Andreas Mohr | d4b13da | 1999-08-07 14:17:10 +0000 | [diff] [blame] | 314 | |
| 315 | all=0; |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 316 | if (RegOpenKeyA(HKEY_CURRENT_USER,KEY_REGISTRY,&hkey)!=ERROR_SUCCESS) |
Andreas Mohr | d4b13da | 1999-08-07 14:17:10 +0000 | [diff] [blame] | 317 | { |
| 318 | strcpy(buf,"yes"); |
| 319 | } |
| 320 | else |
| 321 | { |
| 322 | DWORD len,junk,type; |
| 323 | |
| 324 | len=4; |
| 325 | if ((ERROR_SUCCESS!=RegQueryValueExA( hkey, |
| 326 | VAL_SAVEUPDATED, |
| 327 | &junk, |
| 328 | &type, |
| 329 | buf, |
| 330 | &len)) || (type!=REG_SZ)) |
| 331 | { |
| 332 | strcpy(buf,"yes"); |
| 333 | } |
| 334 | RegCloseKey(hkey); |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 335 | } |
Andreas Mohr | d4b13da | 1999-08-07 14:17:10 +0000 | [diff] [blame] | 336 | |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 337 | if (lstrcmpiA(buf,"yes")) all = 1; |
Andreas Mohr | d4b13da | 1999-08-07 14:17:10 +0000 | [diff] [blame] | 338 | |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 339 | /* set saving level (0 for saving everything, 1 for saving only modified keys) */ |
| 340 | req->current = 1; |
| 341 | req->saving = !all; |
Alexandre Julliard | 705686e | 1999-11-24 19:34:32 +0000 | [diff] [blame] | 342 | req->version = PROFILE_GetWineIniBool( "registry", "UseNewFormat", 0 ) ? 2 : 1; |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 343 | server_call( REQ_SET_REGISTRY_LEVELS ); |
| 344 | |
| 345 | SHELL_SaveRegistryBranch(HKEY_CURRENT_USER); |
| 346 | SHELL_SaveRegistryBranch(HKEY_LOCAL_MACHINE); |
| 347 | SHELL_SaveRegistryBranch(HKEY_USERS); |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Alexandre Julliard | 705686e | 1999-11-24 19:34:32 +0000 | [diff] [blame] | 350 | /* Periodic save callback */ |
| 351 | static void CALLBACK periodic_save( ULONG_PTR dummy ) |
| 352 | { |
| 353 | SHELL_SaveRegistry(); |
| 354 | } |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 355 | |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 356 | /************************ LOAD Registry Function ****************************/ |
| 357 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 358 | |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 359 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 360 | /****************************************************************************** |
| 361 | * _find_or_add_key [Internal] |
| 362 | */ |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 363 | static inline HKEY _find_or_add_key( HKEY hkey, LPWSTR keyname ) |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 364 | { |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 365 | HKEY subkey; |
| 366 | if (RegCreateKeyW( hkey, keyname, &subkey ) != ERROR_SUCCESS) subkey = 0; |
| 367 | if (keyname) free( keyname ); |
| 368 | return subkey; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 371 | /****************************************************************************** |
| 372 | * _find_or_add_value [Internal] |
| 373 | */ |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 374 | static void _find_or_add_value( HKEY hkey, LPWSTR name, DWORD type, LPBYTE data, DWORD len ) |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 375 | { |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 376 | RegSetValueExW( hkey, name, 0, type, data, len ); |
| 377 | if (name) free( name ); |
| 378 | if (data) free( data ); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 382 | /****************************************************************************** |
| 383 | * _wine_read_line [Internal] |
| 384 | * |
| 385 | * reads a line including dynamically enlarging the readbuffer and throwing |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 386 | * away comments |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 387 | */ |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 388 | static int _wine_read_line( FILE *F, char **buf, int *len ) |
| 389 | { |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 390 | char *s,*curread; |
| 391 | int mylen,curoff; |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 392 | |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 393 | curread = *buf; |
| 394 | mylen = *len; |
| 395 | **buf = '\0'; |
| 396 | while (1) { |
| 397 | while (1) { |
| 398 | s=fgets(curread,mylen,F); |
| 399 | if (s==NULL) |
| 400 | return 0; /* EOF */ |
| 401 | if (NULL==(s=strchr(curread,'\n'))) { |
| 402 | /* buffer wasn't large enough */ |
| 403 | curoff = strlen(*buf); |
| 404 | *buf = xrealloc(*buf,*len*2); |
| 405 | curread = *buf + curoff; |
| 406 | mylen = *len; /* we filled up the buffer and |
| 407 | * got new '*len' bytes to fill |
| 408 | */ |
| 409 | *len = *len * 2; |
| 410 | } else { |
| 411 | *s='\0'; |
| 412 | break; |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 413 | } |
| 414 | } |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 415 | /* throw away comments */ |
| 416 | if (**buf=='#' || **buf==';') { |
| 417 | curread = *buf; |
| 418 | mylen = *len; |
| 419 | continue; |
| 420 | } |
| 421 | if (s) /* got end of line */ |
| 422 | break; |
| 423 | } |
| 424 | return 1; |
| 425 | } |
| 426 | |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 427 | |
| 428 | /****************************************************************************** |
| 429 | * _wine_read_USTRING [Internal] |
| 430 | * |
| 431 | * converts a char* into a UNICODE string (up to a special char) |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 432 | * and returns the position exactly after that string |
| 433 | */ |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 434 | static char* _wine_read_USTRING( char *buf, LPWSTR *str ) |
| 435 | { |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 436 | char *s; |
| 437 | LPWSTR ws; |
| 438 | |
| 439 | /* read up to "=" or "\0" or "\n" */ |
| 440 | s = buf; |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 441 | *str = (LPWSTR)xmalloc(2*strlen(buf)+2); |
| 442 | ws = *str; |
| 443 | while (*s && (*s!='\n') && (*s!='=')) { |
| 444 | if (*s!='\\') |
| 445 | *ws++=*((unsigned char*)s++); |
| 446 | else { |
| 447 | s++; |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 448 | if (!*s) { |
| 449 | /* Dangling \ ... may only happen if a registry |
| 450 | * write was short. FIXME: What do to? |
| 451 | */ |
| 452 | break; |
| 453 | } |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 454 | if (*s=='\\') { |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 455 | *ws++='\\'; |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 456 | s++; |
| 457 | continue; |
| 458 | } |
| 459 | if (*s!='u') { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 460 | WARN("Non unicode escape sequence \\%c found in |%s|\n",*s,buf); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 461 | *ws++='\\'; |
| 462 | *ws++=*s++; |
| 463 | } else { |
| 464 | char xbuf[5]; |
| 465 | int wc; |
| 466 | |
| 467 | s++; |
| 468 | memcpy(xbuf,s,4);xbuf[4]='\0'; |
| 469 | if (!sscanf(xbuf,"%x",&wc)) |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 470 | WARN("Strange escape sequence %s found in |%s|\n",xbuf,buf); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 471 | s+=4; |
| 472 | *ws++ =(unsigned short)wc; |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | *ws = 0; |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 477 | return s; |
| 478 | } |
| 479 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 480 | |
| 481 | /****************************************************************************** |
| 482 | * _wine_loadsubkey [Internal] |
| 483 | * |
| 484 | * NOTES |
| 485 | * It seems like this is returning a boolean. Should it? |
| 486 | * |
| 487 | * RETURNS |
| 488 | * Success: 1 |
| 489 | * Failure: 0 |
| 490 | */ |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 491 | static int _wine_loadsubkey( FILE *F, HKEY hkey, int level, char **buf, int *buflen ) |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 492 | { |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 493 | HKEY subkey; |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 494 | int i; |
| 495 | char *s; |
| 496 | LPWSTR name; |
| 497 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 498 | TRACE("(%p,%x,%d,%s,%d)\n", F, hkey, level, debugstr_a(*buf), *buflen); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 499 | |
| 500 | /* Good. We already got a line here ... so parse it */ |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 501 | subkey = 0; |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 502 | while (1) { |
| 503 | i=0;s=*buf; |
| 504 | while (*s=='\t') { |
| 505 | s++; |
| 506 | i++; |
| 507 | } |
| 508 | if (i>level) { |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 509 | if (!subkey) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 510 | WARN("Got a subhierarchy without resp. key?\n"); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 511 | return 0; |
| 512 | } |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 513 | if (!_wine_loadsubkey(F,subkey,level+1,buf,buflen)) |
Eric Pouech | c0bcf26 | 1999-11-04 01:38:11 +0000 | [diff] [blame] | 514 | if (!_wine_read_line(F,buf,buflen)) |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 515 | goto done; |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 516 | continue; |
| 517 | } |
| 518 | |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 519 | /* let the caller handle this line */ |
| 520 | if (i<level || **buf=='\0') |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 521 | goto done; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 522 | |
| 523 | /* it can be: a value or a keyname. Parse the name first */ |
| 524 | s=_wine_read_USTRING(s,&name); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 525 | |
| 526 | /* switch() default: hack to avoid gotos */ |
| 527 | switch (0) { |
| 528 | default: |
| 529 | if (*s=='\0') { |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 530 | if (subkey) RegCloseKey( subkey ); |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 531 | subkey=_find_or_add_key(hkey,name); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 532 | } else { |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 533 | LPBYTE data; |
| 534 | int len,lastmodified,type; |
| 535 | |
| 536 | if (*s!='=') { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 537 | WARN("Unexpected character: %c\n",*s); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 538 | break; |
| 539 | } |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 540 | s++; |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 541 | if (2!=sscanf(s,"%d,%d,",&type,&lastmodified)) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 542 | WARN("Haven't understood possible value in |%s|, skipping.\n",*buf); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 543 | break; |
| 544 | } |
| 545 | /* skip the 2 , */ |
| 546 | s=strchr(s,',');s++; |
Eric Pouech | c0bcf26 | 1999-11-04 01:38:11 +0000 | [diff] [blame] | 547 | s=strchr(s,','); |
| 548 | if (!s++) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 549 | WARN("Haven't understood possible value in |%s|, skipping.\n",*buf); |
Eric Pouech | c0bcf26 | 1999-11-04 01:38:11 +0000 | [diff] [blame] | 550 | break; |
| 551 | } |
Juergen Schmied | f74fa4e | 1999-01-31 09:19:46 +0000 | [diff] [blame] | 552 | if (type == REG_SZ || type == REG_EXPAND_SZ) { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 553 | s=_wine_read_USTRING(s,(LPWSTR*)&data); |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 554 | len = lstrlenW((LPWSTR)data)*2+2; |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 555 | } else { |
| 556 | len=strlen(s)/2; |
| 557 | data = (LPBYTE)xmalloc(len+1); |
| 558 | for (i=0;i<len;i++) { |
| 559 | data[i]=0; |
| 560 | if (*s>='0' && *s<='9') |
| 561 | data[i]=(*s-'0')<<4; |
| 562 | if (*s>='a' && *s<='f') |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 563 | data[i]=(*s-'a'+'\xa')<<4; |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 564 | if (*s>='A' && *s<='F') |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 565 | data[i]=(*s-'A'+'\xa')<<4; |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 566 | s++; |
| 567 | if (*s>='0' && *s<='9') |
| 568 | data[i]|=*s-'0'; |
| 569 | if (*s>='a' && *s<='f') |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 570 | data[i]|=*s-'a'+'\xa'; |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 571 | if (*s>='A' && *s<='F') |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 572 | data[i]|=*s-'A'+'\xa'; |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 573 | s++; |
| 574 | } |
| 575 | } |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 576 | _find_or_add_value(hkey,name,type,data,len); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | /* read the next line */ |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 580 | if (!_wine_read_line(F,buf,buflen)) |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 581 | goto done; |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 582 | } |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 583 | done: |
| 584 | if (subkey) RegCloseKey( subkey ); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 585 | return 1; |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 586 | } |
| 587 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 588 | |
| 589 | /****************************************************************************** |
| 590 | * _wine_loadsubreg [Internal] |
| 591 | */ |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 592 | static int _wine_loadsubreg( FILE *F, HKEY hkey, const char *fn ) |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 593 | { |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 594 | int ver; |
| 595 | char *buf; |
| 596 | int buflen; |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 597 | |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 598 | buf=xmalloc(10);buflen=10; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 599 | if (!_wine_read_line(F,&buf,&buflen)) { |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 600 | free(buf); |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 601 | return 0; |
| 602 | } |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 603 | if (!sscanf(buf,"WINE REGISTRY Version %d",&ver)) { |
| 604 | free(buf); |
| 605 | return 0; |
| 606 | } |
| 607 | if (ver!=REGISTRY_SAVE_VERSION) { |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 608 | if (ver == 2) /* new version */ |
| 609 | { |
| 610 | HANDLE file; |
| 611 | if ((file = FILE_CreateFile( fn, GENERIC_READ, 0, NULL, OPEN_EXISTING, |
| 612 | FILE_ATTRIBUTE_NORMAL, -1 )) != INVALID_HANDLE_VALUE) |
| 613 | { |
| 614 | struct load_registry_request *req = get_req_buffer(); |
| 615 | req->hkey = hkey; |
| 616 | req->file = file; |
| 617 | req->name[0] = 0; |
| 618 | server_call( REQ_LOAD_REGISTRY ); |
| 619 | CloseHandle( file ); |
| 620 | } |
| 621 | free( buf ); |
| 622 | return 1; |
| 623 | } |
| 624 | else |
| 625 | { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 626 | TRACE("Old format (%d) registry found, ignoring it. (buf was %s).\n",ver,buf); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 627 | free(buf); |
| 628 | return 0; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 629 | } |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 630 | } |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 631 | if (!_wine_read_line(F,&buf,&buflen)) { |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 632 | free(buf); |
| 633 | return 0; |
| 634 | } |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 635 | if (!_wine_loadsubkey(F,hkey,0,&buf,&buflen)) { |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 636 | free(buf); |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 637 | return 0; |
| 638 | } |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 639 | free(buf); |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 640 | return 1; |
| 641 | } |
| 642 | |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 643 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 644 | /****************************************************************************** |
| 645 | * _wine_loadreg [Internal] |
| 646 | */ |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 647 | static void _wine_loadreg( HKEY hkey, char *fn ) |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 648 | { |
| 649 | FILE *F; |
| 650 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 651 | TRACE("(%x,%s)\n",hkey,debugstr_a(fn)); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 652 | |
| 653 | F = fopen(fn,"rb"); |
| 654 | if (F==NULL) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 655 | WARN("Couldn't open %s for reading: %s\n",fn,strerror(errno) ); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 656 | return; |
| 657 | } |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 658 | _wine_loadsubreg(F,hkey,fn); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 659 | fclose(F); |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 660 | } |
| 661 | |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 662 | /* NT REGISTRY LOADER */ |
Patrik Stridvall | 6afc68a | 2000-01-04 00:32:38 +0000 | [diff] [blame] | 663 | |
| 664 | #ifdef HAVE_SYS_MMAN_H |
| 665 | # include <sys/mman.h> |
| 666 | #endif |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 667 | |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 668 | #ifndef MAP_FAILED |
| 669 | #define MAP_FAILED ((LPVOID)-1) |
| 670 | #endif |
| 671 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 672 | #define NT_REG_BLOCK_SIZE 0x1000 |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 673 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 674 | #define NT_REG_HEADER_BLOCK_ID 0x66676572 /* regf */ |
| 675 | #define NT_REG_POOL_BLOCK_ID 0x6E696268 /* hbin */ |
| 676 | #define NT_REG_KEY_BLOCK_ID 0x6b6e |
| 677 | #define NT_REG_VALUE_BLOCK_ID 0x6b76 |
| 678 | #define NT_REG_HASH_BLOCK_ID 0x666c |
| 679 | #define NT_REG_NOHASH_BLOCK_ID 0x696c |
| 680 | #define NT_REG_KEY_BLOCK_TYPE 0x20 |
| 681 | #define NT_REG_ROOT_KEY_BLOCK_TYPE 0x2c |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 682 | |
| 683 | typedef struct |
| 684 | { |
| 685 | DWORD id; /* 0x66676572 'regf'*/ |
| 686 | DWORD uk1; /* 0x04 */ |
| 687 | DWORD uk2; /* 0x08 */ |
| 688 | FILETIME DateModified; /* 0x0c */ |
| 689 | DWORD uk3; /* 0x14 */ |
| 690 | DWORD uk4; /* 0x18 */ |
| 691 | DWORD uk5; /* 0x1c */ |
| 692 | DWORD uk6; /* 0x20 */ |
| 693 | DWORD RootKeyBlock; /* 0x24 */ |
| 694 | DWORD BlockSize; /* 0x28 */ |
| 695 | DWORD uk7[116]; |
| 696 | DWORD Checksum; /* at offset 0x1FC */ |
| 697 | } nt_regf; |
| 698 | |
| 699 | typedef struct |
| 700 | { |
| 701 | DWORD blocksize; |
| 702 | BYTE data[1]; |
| 703 | } nt_hbin_sub; |
| 704 | |
| 705 | typedef struct |
| 706 | { |
| 707 | DWORD id; /* 0x6E696268 'hbin' */ |
| 708 | DWORD off_prev; |
| 709 | DWORD off_next; |
| 710 | DWORD uk1; |
| 711 | DWORD uk2; /* 0x10 */ |
| 712 | DWORD uk3; /* 0x14 */ |
| 713 | DWORD uk4; /* 0x18 */ |
| 714 | DWORD size; /* 0x1C */ |
| 715 | nt_hbin_sub hbin_sub; /* 0x20 */ |
| 716 | } nt_hbin; |
| 717 | |
| 718 | /* |
| 719 | * the value_list consists of offsets to the values (vk) |
| 720 | */ |
| 721 | typedef struct |
| 722 | { |
| 723 | WORD SubBlockId; /* 0x00 0x6B6E */ |
| 724 | WORD Type; /* 0x02 for the root-key: 0x2C, otherwise 0x20*/ |
| 725 | FILETIME writetime; /* 0x04 */ |
| 726 | DWORD uk1; /* 0x0C */ |
| 727 | DWORD parent_off; /* 0x10 Offset of Owner/Parent key */ |
| 728 | DWORD nr_subkeys; /* 0x14 number of sub-Keys */ |
| 729 | DWORD uk8; /* 0x18 */ |
| 730 | DWORD lf_off; /* 0x1C Offset of the sub-key lf-Records */ |
| 731 | DWORD uk2; /* 0x20 */ |
| 732 | DWORD nr_values; /* 0x24 number of values */ |
| 733 | DWORD valuelist_off; /* 0x28 Offset of the Value-List */ |
| 734 | DWORD off_sk; /* 0x2c Offset of the sk-Record */ |
| 735 | DWORD off_class; /* 0x30 Offset of the Class-Name */ |
| 736 | DWORD uk3; /* 0x34 */ |
| 737 | DWORD uk4; /* 0x38 */ |
| 738 | DWORD uk5; /* 0x3c */ |
| 739 | DWORD uk6; /* 0x40 */ |
| 740 | DWORD uk7; /* 0x44 */ |
| 741 | WORD name_len; /* 0x48 name-length */ |
| 742 | WORD class_len; /* 0x4a class-name length */ |
| 743 | char name[1]; /* 0x4c key-name */ |
| 744 | } nt_nk; |
| 745 | |
| 746 | typedef struct |
| 747 | { |
| 748 | DWORD off_nk; /* 0x00 */ |
| 749 | DWORD name; /* 0x04 */ |
| 750 | } hash_rec; |
| 751 | |
| 752 | typedef struct |
| 753 | { |
| 754 | WORD id; /* 0x00 0x666c */ |
| 755 | WORD nr_keys; /* 0x06 */ |
| 756 | hash_rec hash_rec[1]; |
| 757 | } nt_lf; |
| 758 | |
| 759 | typedef struct |
| 760 | { |
| 761 | WORD id; /* 0x00 0x696c */ |
| 762 | WORD nr_keys; |
| 763 | DWORD off_nk[1]; |
| 764 | } nt_il; |
| 765 | |
| 766 | typedef struct |
| 767 | { |
| 768 | WORD id; /* 0x00 'vk' */ |
| 769 | WORD nam_len; |
| 770 | DWORD data_len; |
| 771 | DWORD data_off; |
| 772 | DWORD type; |
| 773 | WORD flag; |
| 774 | WORD uk1; |
| 775 | char name[1]; |
| 776 | } nt_vk; |
| 777 | |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 778 | LPSTR _strdupnA( LPCSTR str, int len ) |
| 779 | { |
| 780 | LPSTR ret; |
| 781 | |
| 782 | if (!str) return NULL; |
| 783 | ret = malloc( len + 1 ); |
| 784 | lstrcpynA( ret, str, len ); |
| 785 | ret[len] = 0x00; |
| 786 | return ret; |
| 787 | } |
| 788 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 789 | static int _nt_parse_nk(HKEY hkey, char * base, nt_nk * nk, int level); |
| 790 | static int _nt_parse_vk(HKEY hkey, char * base, nt_vk * vk); |
| 791 | static int _nt_parse_lf(HKEY hkey, char * base, nt_lf * lf, int level); |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 792 | |
| 793 | |
| 794 | /* |
| 795 | * gets a value |
| 796 | * |
| 797 | * vk->flag: |
| 798 | * 0 value is a default value |
| 799 | * 1 the value has a name |
| 800 | * |
| 801 | * vk->data_len |
| 802 | * len of the whole data block |
| 803 | * - reg_sz (unicode) |
| 804 | * bytes including the terminating \0 = 2*(number_of_chars+1) |
| 805 | * - reg_dword, reg_binary: |
| 806 | * if highest bit of data_len is set data_off contains the value |
| 807 | */ |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 808 | static int _nt_parse_vk(HKEY hkey, char * base, nt_vk * vk) |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 809 | { |
| 810 | WCHAR name [256]; |
Juergen Schmied | c35cce2 | 1999-12-20 03:58:44 +0000 | [diff] [blame] | 811 | DWORD ret; |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 812 | BYTE * pdata = (BYTE *)(base+vk->data_off+4); /* start of data */ |
| 813 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 814 | if(vk->id != NT_REG_VALUE_BLOCK_ID) goto error; |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 815 | |
| 816 | lstrcpynAtoW(name, vk->name, vk->nam_len+1); |
| 817 | |
Juergen Schmied | c35cce2 | 1999-12-20 03:58:44 +0000 | [diff] [blame] | 818 | ret = RegSetValueExW( hkey, (vk->flag & 0x00000001) ? name : NULL, 0, vk->type, |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 819 | (vk->data_len & 0x80000000) ? (LPBYTE)&(vk->data_off): pdata, |
Juergen Schmied | c35cce2 | 1999-12-20 03:58:44 +0000 | [diff] [blame] | 820 | (vk->data_len & 0x7fffffff) ); |
| 821 | if (ret) ERR("RegSetValueEx failed (0x%08lx)\n", ret); |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 822 | return TRUE; |
| 823 | error: |
| 824 | ERR_(reg)("vk block invalid\n"); |
| 825 | return FALSE; |
| 826 | } |
| 827 | |
| 828 | /* |
| 829 | * get the subkeys |
| 830 | * |
| 831 | * this structure contains the hash of a keyname and points to all |
| 832 | * subkeys |
| 833 | * |
| 834 | * exception: if the id is 'il' there are no hash values and every |
| 835 | * dword is a offset |
| 836 | */ |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 837 | static int _nt_parse_lf(HKEY hkey, char * base, nt_lf * lf, int level) |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 838 | { |
| 839 | int i; |
| 840 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 841 | if (lf->id == NT_REG_HASH_BLOCK_ID) |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 842 | { |
| 843 | for (i=0; i<lf->nr_keys; i++) |
| 844 | { |
| 845 | if (!_nt_parse_nk(hkey, base, (nt_nk*)(base+lf->hash_rec[i].off_nk+4), level)) goto error; |
| 846 | } |
| 847 | |
| 848 | } |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 849 | else if (lf->id == NT_REG_NOHASH_BLOCK_ID) |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 850 | { |
| 851 | for (i=0; i<lf->nr_keys; i++) |
| 852 | { |
| 853 | if (!_nt_parse_nk(hkey, base, (nt_nk*)(base+((nt_il*)lf)->off_nk[i]+4), level)) goto error; |
| 854 | } |
| 855 | } |
| 856 | return TRUE; |
| 857 | |
| 858 | error: ERR_(reg)("error reading lf block\n"); |
| 859 | return FALSE; |
| 860 | } |
| 861 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 862 | static int _nt_parse_nk(HKEY hkey, char * base, nt_nk * nk, int level) |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 863 | { |
| 864 | char * name; |
| 865 | int i; |
| 866 | DWORD * vl; |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 867 | HKEY subkey = hkey; |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 868 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 869 | if(nk->SubBlockId != NT_REG_KEY_BLOCK_ID) goto error; |
| 870 | if((nk->Type!=NT_REG_ROOT_KEY_BLOCK_TYPE) && |
| 871 | (((nt_nk*)(base+nk->parent_off+4))->SubBlockId != NT_REG_KEY_BLOCK_ID)) goto error; |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 872 | |
| 873 | /* create the new key */ |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 874 | if(level <= 0) |
| 875 | { |
| 876 | name = _strdupnA( nk->name, nk->name_len+1); |
| 877 | if(RegCreateKeyA( hkey, name, &subkey )) { free(name); goto error; } |
| 878 | free(name); |
| 879 | } |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 880 | |
| 881 | /* loop through the subkeys */ |
| 882 | if (nk->nr_subkeys) |
| 883 | { |
| 884 | nt_lf * lf = (nt_lf*)(base+nk->lf_off+4); |
| 885 | if (nk->nr_subkeys != lf->nr_keys) goto error1; |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 886 | if (!_nt_parse_lf(subkey, base, lf, level-1)) goto error1; |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | /* loop trough the value list */ |
| 890 | vl = (DWORD *)(base+nk->valuelist_off+4); |
| 891 | for (i=0; i<nk->nr_values; i++) |
| 892 | { |
| 893 | nt_vk * vk = (nt_vk*)(base+vl[i]+4); |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 894 | if (!_nt_parse_vk(subkey, base, vk)) goto error1; |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | RegCloseKey(subkey); |
| 898 | return TRUE; |
| 899 | |
| 900 | error1: RegCloseKey(subkey); |
| 901 | error: ERR_(reg)("error reading nk block\n"); |
| 902 | return FALSE; |
| 903 | } |
| 904 | |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 905 | /* end nt loader */ |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 906 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 907 | /* windows 95 registry loader */ |
| 908 | |
| 909 | /* SECTION 1: main header |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 910 | * |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 911 | * once at offset 0 |
| 912 | */ |
| 913 | #define W95_REG_CREG_ID 0x47455243 |
| 914 | |
| 915 | typedef struct |
| 916 | { |
| 917 | DWORD id; /* "CREG" = W95_REG_CREG_ID */ |
| 918 | DWORD version; /* ???? 0x00010000 */ |
| 919 | DWORD rgdb_off; /* 0x08 Offset of 1st RGDB-block */ |
| 920 | DWORD uk2; /* 0x0c */ |
| 921 | WORD rgdb_num; /* 0x10 # of RGDB-blocks */ |
| 922 | WORD uk3; |
| 923 | DWORD uk[3]; |
| 924 | /* rgkn */ |
| 925 | } _w95creg; |
| 926 | |
| 927 | /* SECTION 2: Directory information (tree structure) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 928 | * |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 929 | * once on offset 0x20 |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 930 | * |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 931 | * structure: [rgkn][dke]* (repeat till rgkn->size is reached) |
| 932 | */ |
| 933 | #define W95_REG_RGKN_ID 0x4e4b4752 |
| 934 | |
| 935 | typedef struct |
| 936 | { |
| 937 | DWORD id; /*"RGKN" = W95_REG_RGKN_ID */ |
| 938 | DWORD size; /* Size of the RGKN-block */ |
| 939 | DWORD root_off; /* Rel. Offset of the root-record */ |
| 940 | DWORD uk[5]; |
| 941 | } _w95rgkn; |
| 942 | |
| 943 | /* Disk Key Entry Structure |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 944 | * |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 945 | * the 1st entry in a "usual" registry file is a nul-entry with subkeys: the |
| 946 | * hive itself. It looks the same like other keys. Even the ID-number can |
| 947 | * be any value. |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 948 | * |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 949 | * The "hash"-value is a value representing the key's name. Windows will not |
| 950 | * search for the name, but for a matching hash-value. if it finds one, it |
| 951 | * will compare the actual string info, otherwise continue with the next key. |
| 952 | * To calculate the hash initialize a D-Word with 0 and add all ASCII-values |
| 953 | * of the string which are smaller than 0x80 (128) to this D-Word. |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 954 | * |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 955 | * If you want to modify key names, also modify the hash-values, since they |
| 956 | * cannot be found again (although they would be displayed in REGEDIT) |
| 957 | * End of list-pointers are filled with 0xFFFFFFFF |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 958 | * |
| 959 | * Disk keys are layed out flat ... But, sometimes, nrLS and nrHS are both |
| 960 | * 0xFFFF, which means skipping over nextkeyoffset bytes (including this |
| 961 | * structure) and reading another RGDB_section. |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 962 | * |
| 963 | * there is a one to one relationship between dke and dkh |
| 964 | */ |
| 965 | /* key struct, once per key */ |
| 966 | typedef struct |
| 967 | { |
| 968 | DWORD x1; /* Free entry indicator(?) */ |
| 969 | DWORD hash; /* sum of bytes of keyname */ |
| 970 | DWORD x3; /* Root key indicator? usually 0xFFFFFFFF */ |
| 971 | DWORD prevlvl; /* offset of previous key */ |
| 972 | DWORD nextsub; /* offset of child key */ |
| 973 | DWORD next; /* offset of sibling key */ |
| 974 | WORD nrLS; /* id inside the rgdb block */ |
| 975 | WORD nrMS; /* number of the rgdb block */ |
| 976 | } _w95dke; |
| 977 | |
| 978 | /* SECTION 3: key information, values and data |
| 979 | * |
| 980 | * structure: |
| 981 | * section: [blocks]* (repeat creg->rgdb_num times) |
| 982 | * blocks: [rgdb] [subblocks]* (repeat till block size reached ) |
| 983 | * subblocks: [dkh] [dkv]* (repeat dkh->values times ) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 984 | * |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 985 | * An interesting relationship exists in RGDB_section. The value at offset |
| 986 | * 10 equals the value at offset 4 minus the value at offset 8. I have no |
| 987 | * idea at the moment what this means. (Kevin Cozens) |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 988 | */ |
| 989 | |
| 990 | /* block header, once per block */ |
| 991 | #define W95_REG_RGDB_ID 0x42444752 |
| 992 | |
| 993 | typedef struct |
| 994 | { |
| 995 | DWORD id; /* 0x00 'rgdb' = W95_REG_RGDB_ID */ |
| 996 | DWORD size; /* 0x04 */ |
| 997 | DWORD uk1; /* 0x08 */ |
| 998 | DWORD uk2; /* 0x0c */ |
| 999 | DWORD uk3; /* 0x10 */ |
| 1000 | DWORD uk4; /* 0x14 */ |
| 1001 | DWORD uk5; /* 0x18 */ |
| 1002 | DWORD uk6; /* 0x1c */ |
| 1003 | /* dkh */ |
| 1004 | } _w95rgdb; |
| 1005 | |
| 1006 | /* Disk Key Header structure (RGDB part), once per key */ |
| 1007 | typedef struct |
| 1008 | { |
| 1009 | DWORD nextkeyoff; /* 0x00 offset to next dkh*/ |
| 1010 | WORD nrLS; /* 0x04 id inside the rgdb block */ |
| 1011 | WORD nrMS; /* 0x06 number of the rgdb block */ |
| 1012 | DWORD bytesused; /* 0x08 */ |
| 1013 | WORD keynamelen; /* 0x0c len of name */ |
| 1014 | WORD values; /* 0x0e number of values */ |
| 1015 | DWORD xx1; /* 0x10 */ |
| 1016 | char name[1]; /* 0x14 */ |
| 1017 | /* dkv */ /* 0x14 + keynamelen */ |
| 1018 | } _w95dkh; |
| 1019 | |
| 1020 | /* Disk Key Value structure, once per value */ |
| 1021 | typedef struct |
| 1022 | { |
| 1023 | DWORD type; /* 0x00 */ |
| 1024 | DWORD x1; /* 0x04 */ |
| 1025 | WORD valnamelen; /* 0x08 length of name, 0 is default key */ |
| 1026 | WORD valdatalen; /* 0x0A length of data */ |
| 1027 | char name[1]; /* 0x0c */ |
| 1028 | /* raw data */ /* 0x0c + valnamelen */ |
| 1029 | } _w95dkv; |
| 1030 | |
| 1031 | /****************************************************************************** |
| 1032 | * _w95_lookup_dkh [Internal] |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 1033 | * |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1034 | * seeks the dkh belonging to a dke |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 1035 | */ |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1036 | static _w95dkh * _w95_lookup_dkh (_w95creg *creg, int nrLS, int nrMS) |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1037 | { |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1038 | _w95rgdb * rgdb; |
| 1039 | _w95dkh * dkh; |
| 1040 | int i; |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1041 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1042 | rgdb = (_w95rgdb*)((char*)creg+creg->rgdb_off); /* get the beginning of the rgdb datastore */ |
| 1043 | assert (creg->rgdb_num > nrMS); /* check: requested block < last_block) */ |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1044 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1045 | /* find the right block */ |
| 1046 | for(i=0; i<nrMS ;i++) |
| 1047 | { |
| 1048 | assert(rgdb->id == W95_REG_RGDB_ID); /* check the magic */ |
| 1049 | rgdb = (_w95rgdb*) ((char*)rgdb+rgdb->size); /* find next block */ |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1052 | dkh = (_w95dkh*)(rgdb + 1); /* first sub block within the rgdb */ |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1053 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1054 | do |
| 1055 | { |
| 1056 | if(nrLS==dkh->nrLS ) return dkh; |
| 1057 | dkh = (_w95dkh*)((char*)dkh + dkh->nextkeyoff); /* find next subblock */ |
| 1058 | } while ((char *)dkh < ((char*)rgdb+rgdb->size)); |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1059 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1060 | return NULL; |
| 1061 | } |
| 1062 | |
| 1063 | /****************************************************************************** |
| 1064 | * _w95_parse_dkv [Internal] |
| 1065 | */ |
| 1066 | static int _w95_parse_dkv ( |
| 1067 | HKEY hkey, |
| 1068 | _w95dkh * dkh, |
| 1069 | int nrLS, |
| 1070 | int nrMS ) |
| 1071 | { |
| 1072 | _w95dkv * dkv; |
| 1073 | int i; |
| 1074 | DWORD ret; |
| 1075 | char * name; |
| 1076 | |
| 1077 | /* first value block */ |
| 1078 | dkv = (_w95dkv*)((char*)dkh+dkh->keynamelen+0x14); |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1079 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1080 | /* loop trought the values */ |
| 1081 | for (i=0; i< dkh->values; i++) |
| 1082 | { |
| 1083 | name = _strdupnA(dkv->name, dkv->valnamelen+1); |
| 1084 | ret = RegSetValueExA(hkey, name, 0, dkv->type, &(dkv->name[dkv->valnamelen]),dkv->valdatalen); |
| 1085 | if (ret) ERR("RegSetValueEx failed (0x%08lx)\n", ret); |
| 1086 | free (name); |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1087 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1088 | /* next value */ |
| 1089 | dkv = (_w95dkv*)((char*)dkv+dkv->valnamelen+dkv->valdatalen+0x0c); |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1090 | } |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1091 | return TRUE; |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1094 | /****************************************************************************** |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1095 | * _w95_parse_dke [Internal] |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1096 | */ |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1097 | static int _w95_parse_dke( |
| 1098 | HKEY hkey, |
| 1099 | _w95creg * creg, |
| 1100 | _w95rgkn *rgkn, |
| 1101 | _w95dke * dke, |
| 1102 | int level ) |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1103 | { |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1104 | _w95dkh * dkh; |
| 1105 | HKEY hsubkey = hkey; |
| 1106 | char * name; |
| 1107 | int ret = FALSE; |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1108 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1109 | /* get start address of root key block */ |
| 1110 | if (!dke) dke = (_w95dke*)((char*)rgkn + rgkn->root_off); |
| 1111 | |
Juergen Schmied | 0311eb3 | 2000-01-17 22:23:10 +0000 | [diff] [blame] | 1112 | /* special root key */ |
| 1113 | if (dke->nrLS == 0xffff || dke->nrMS==0xffff) /* eg. the root key has no name */ |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1114 | { |
Juergen Schmied | 0311eb3 | 2000-01-17 22:23:10 +0000 | [diff] [blame] | 1115 | /* parse the one subkey*/ |
| 1116 | if (dke->nextsub != 0xffffffff) |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1117 | { |
Juergen Schmied | 0311eb3 | 2000-01-17 22:23:10 +0000 | [diff] [blame] | 1118 | return _w95_parse_dke(hsubkey, creg, rgkn, (_w95dke*)((char*)rgkn+dke->nextsub), level); |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1119 | } |
Juergen Schmied | 0311eb3 | 2000-01-17 22:23:10 +0000 | [diff] [blame] | 1120 | /* has no sibling keys */ |
| 1121 | goto error; |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1122 | } |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1123 | |
Juergen Schmied | 0311eb3 | 2000-01-17 22:23:10 +0000 | [diff] [blame] | 1124 | /* search subblock */ |
| 1125 | if (!(dkh = _w95_lookup_dkh(creg, dke->nrLS, dke->nrMS))) |
| 1126 | { |
| 1127 | fprintf(stderr, "dke pointing to missing dkh !\n"); |
| 1128 | goto error; |
| 1129 | } |
| 1130 | |
| 1131 | if ( level <= 0 ) |
| 1132 | { |
| 1133 | /* walk sibling keys */ |
| 1134 | if (dke->next != 0xffffffff ) |
| 1135 | { |
| 1136 | if (!_w95_parse_dke(hkey, creg, rgkn, (_w95dke*)((char*)rgkn+dke->next), level)) goto error; |
| 1137 | } |
| 1138 | |
| 1139 | /* create subkey and insert values */ |
| 1140 | name = _strdupnA( dkh->name, dkh->keynamelen+1); |
| 1141 | if (RegCreateKeyA(hkey, name, &hsubkey)) { free(name); goto error; } |
| 1142 | free(name); |
| 1143 | if (!_w95_parse_dkv(hsubkey, dkh, dke->nrLS, dke->nrMS)) goto error1; |
| 1144 | } |
| 1145 | |
| 1146 | /* next sub key */ |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1147 | if (dke->nextsub != 0xffffffff) |
| 1148 | { |
Juergen Schmied | 0311eb3 | 2000-01-17 22:23:10 +0000 | [diff] [blame] | 1149 | if (!_w95_parse_dke(hsubkey, creg, rgkn, (_w95dke*)((char*)rgkn+dke->nextsub), level-1)) goto error1; |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1150 | } |
Juergen Schmied | 0311eb3 | 2000-01-17 22:23:10 +0000 | [diff] [blame] | 1151 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1152 | ret = TRUE; |
Juergen Schmied | 0311eb3 | 2000-01-17 22:23:10 +0000 | [diff] [blame] | 1153 | error1: if (hsubkey != hkey) RegCloseKey(hsubkey); |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1154 | error: return ret; |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1155 | } |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1156 | /* end windows 95 loader */ |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1157 | |
| 1158 | /****************************************************************************** |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1159 | * NativeRegLoadKey [Internal] |
| 1160 | * |
| 1161 | * Loads a native registry file (win95/nt) |
| 1162 | * hkey root key |
| 1163 | * fn filename |
| 1164 | * level number of levels to cut away (eg. ".Default" in user.dat) |
| 1165 | * |
| 1166 | * this function intentionally uses unix file functions to make it possible |
| 1167 | * to move it to a seperate registry helper programm |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1168 | */ |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1169 | static int NativeRegLoadKey( HKEY hkey, char* fn, int level ) |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1170 | { |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1171 | int fd = 0; |
| 1172 | struct stat st; |
| 1173 | DOS_FULL_NAME full_name; |
| 1174 | int ret = FALSE; |
| 1175 | void * base; |
| 1176 | |
| 1177 | if (!DOSFS_GetFullName( fn, 0, &full_name )) return FALSE; |
| 1178 | |
| 1179 | /* map the registry into the memory */ |
| 1180 | if ((fd = open(full_name.long_name, O_RDONLY | O_NONBLOCK)) == -1) return FALSE; |
| 1181 | if ((fstat(fd, &st) == -1)) goto error; |
| 1182 | if ((base = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) goto error; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 1183 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1184 | switch (*(LPDWORD)base) |
| 1185 | { |
| 1186 | /* windows 95 'creg' */ |
| 1187 | case W95_REG_CREG_ID: |
| 1188 | { |
| 1189 | _w95creg * creg; |
| 1190 | _w95rgkn * rgkn; |
| 1191 | creg = base; |
| 1192 | TRACE_(reg)("Loading win95 registry '%s' '%s'\n",fn, full_name.long_name); |
| 1193 | |
| 1194 | /* load the header (rgkn) */ |
| 1195 | rgkn = (_w95rgkn*)(creg + 1); |
| 1196 | if (rgkn->id != W95_REG_RGKN_ID) |
| 1197 | { |
| 1198 | ERR("second IFF header not RGKN, but %lx\n", rgkn->id); |
| 1199 | goto error1; |
| 1200 | } |
| 1201 | |
| 1202 | ret = _w95_parse_dke(hkey, creg, rgkn, NULL, level); |
| 1203 | } |
| 1204 | break; |
| 1205 | /* nt 'regf'*/ |
| 1206 | case NT_REG_HEADER_BLOCK_ID: |
| 1207 | { |
| 1208 | nt_regf * regf; |
| 1209 | nt_hbin * hbin; |
| 1210 | nt_hbin_sub * hbin_sub; |
| 1211 | nt_nk* nk; |
| 1212 | |
| 1213 | TRACE_(reg)("Loading nt registry '%s' '%s'\n",fn, full_name.long_name); |
| 1214 | |
| 1215 | /* start block */ |
| 1216 | regf = base; |
| 1217 | |
| 1218 | /* hbin block */ |
| 1219 | hbin = base + 0x1000; |
| 1220 | if (hbin->id != NT_REG_POOL_BLOCK_ID) |
| 1221 | { |
| 1222 | ERR_(reg)( "%s hbin block invalid\n", fn); |
| 1223 | goto error1; |
| 1224 | } |
| 1225 | |
| 1226 | /* hbin_sub block */ |
| 1227 | hbin_sub = (nt_hbin_sub*)&(hbin->hbin_sub); |
| 1228 | if ((hbin_sub->data[0] != 'n') || (hbin_sub->data[1] != 'k')) |
| 1229 | { |
| 1230 | ERR_(reg)( "%s hbin_sub block invalid\n", fn); |
| 1231 | goto error1; |
| 1232 | } |
| 1233 | |
| 1234 | /* nk block */ |
| 1235 | nk = (nt_nk*)&(hbin_sub->data[0]); |
| 1236 | if (nk->Type != NT_REG_ROOT_KEY_BLOCK_TYPE) |
| 1237 | { |
| 1238 | ERR_(reg)( "%s special nk block not found\n", fn); |
| 1239 | goto error1; |
| 1240 | } |
| 1241 | |
| 1242 | ret = _nt_parse_nk (hkey, base+0x1000, nk, level); |
| 1243 | } |
| 1244 | break; |
| 1245 | default: |
| 1246 | { |
| 1247 | ERR("unknown signature in registry file %s.\n",fn); |
| 1248 | goto error1; |
| 1249 | } |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 1250 | } |
Juergen Schmied | 0311eb3 | 2000-01-17 22:23:10 +0000 | [diff] [blame] | 1251 | if(!ret) ERR("error loading registry file %s\n", fn); |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1252 | error1: munmap(base, st.st_size); |
| 1253 | error: close(fd); |
| 1254 | return ret; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1257 | /* WINDOWS 31 REGISTRY LOADER, supplied by Tor Sjøwall, tor@sn.no */ |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1258 | /* |
| 1259 | reghack - windows 3.11 registry data format demo program. |
| 1260 | |
| 1261 | The reg.dat file has 3 parts, a header, a table of 8-byte entries that is |
| 1262 | a combined hash table and tree description, and finally a text table. |
| 1263 | |
| 1264 | The header is obvious from the struct header. The taboff1 and taboff2 |
| 1265 | fields are always 0x20, and their usage is unknown. |
| 1266 | |
| 1267 | The 8-byte entry table has various entry types. |
| 1268 | |
| 1269 | tabent[0] is a root index. The second word has the index of the root of |
| 1270 | the directory. |
| 1271 | tabent[1..hashsize] is a hash table. The first word in the hash entry is |
| 1272 | the index of the key/value that has that hash. Data with the same |
| 1273 | hash value are on a circular list. The other three words in the |
| 1274 | hash entry are always zero. |
| 1275 | tabent[hashsize..tabcnt] is the tree structure. There are two kinds of |
| 1276 | entry: dirent and keyent/valent. They are identified by context. |
| 1277 | tabent[freeidx] is the first free entry. The first word in a free entry |
| 1278 | is the index of the next free entry. The last has 0 as a link. |
| 1279 | The other three words in the free list are probably irrelevant. |
| 1280 | |
| 1281 | Entries in text table are preceeded by a word at offset-2. This word |
| 1282 | has the value (2*index)+1, where index is the referring keyent/valent |
| 1283 | entry in the table. I have no suggestion for the 2* and the +1. |
| 1284 | Following the word, there are N bytes of data, as per the keyent/valent |
| 1285 | entry length. The offset of the keyent/valent entry is from the start |
| 1286 | of the text table to the first data byte. |
| 1287 | |
| 1288 | This information is not available from Microsoft. The data format is |
| 1289 | deduced from the reg.dat file by me. Mistakes may |
| 1290 | have been made. I claim no rights and give no guarantees for this program. |
| 1291 | |
| 1292 | Tor Sjøwall, tor@sn.no |
| 1293 | */ |
| 1294 | |
| 1295 | /* reg.dat header format */ |
| 1296 | struct _w31_header { |
| 1297 | char cookie[8]; /* 'SHCC3.10' */ |
| 1298 | unsigned long taboff1; /* offset of hash table (??) = 0x20 */ |
| 1299 | unsigned long taboff2; /* offset of index table (??) = 0x20 */ |
| 1300 | unsigned long tabcnt; /* number of entries in index table */ |
| 1301 | unsigned long textoff; /* offset of text part */ |
| 1302 | unsigned long textsize; /* byte size of text part */ |
| 1303 | unsigned short hashsize; /* hash size */ |
| 1304 | unsigned short freeidx; /* free index */ |
| 1305 | }; |
| 1306 | |
| 1307 | /* generic format of table entries */ |
| 1308 | struct _w31_tabent { |
| 1309 | unsigned short w0, w1, w2, w3; |
| 1310 | }; |
| 1311 | |
| 1312 | /* directory tabent: */ |
| 1313 | struct _w31_dirent { |
| 1314 | unsigned short sibling_idx; /* table index of sibling dirent */ |
| 1315 | unsigned short child_idx; /* table index of child dirent */ |
| 1316 | unsigned short key_idx; /* table index of key keyent */ |
| 1317 | unsigned short value_idx; /* table index of value valent */ |
| 1318 | }; |
| 1319 | |
| 1320 | /* key tabent: */ |
| 1321 | struct _w31_keyent { |
| 1322 | unsigned short hash_idx; /* hash chain index for string */ |
| 1323 | unsigned short refcnt; /* reference count */ |
| 1324 | unsigned short length; /* length of string */ |
| 1325 | unsigned short string_off; /* offset of string in text table */ |
| 1326 | }; |
| 1327 | |
| 1328 | /* value tabent: */ |
| 1329 | struct _w31_valent { |
| 1330 | unsigned short hash_idx; /* hash chain index for string */ |
| 1331 | unsigned short refcnt; /* reference count */ |
| 1332 | unsigned short length; /* length of string */ |
| 1333 | unsigned short string_off; /* offset of string in text table */ |
| 1334 | }; |
| 1335 | |
| 1336 | /* recursive helper function to display a directory tree */ |
| 1337 | void |
| 1338 | __w31_dumptree( unsigned short idx, |
| 1339 | unsigned char *txt, |
| 1340 | struct _w31_tabent *tab, |
| 1341 | struct _w31_header *head, |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1342 | HKEY hkey, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1343 | time_t lastmodified, |
| 1344 | int level |
| 1345 | ) { |
| 1346 | struct _w31_dirent *dir; |
| 1347 | struct _w31_keyent *key; |
| 1348 | struct _w31_valent *val; |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1349 | HKEY subkey = 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1350 | static char tail[400]; |
| 1351 | |
| 1352 | while (idx!=0) { |
| 1353 | dir=(struct _w31_dirent*)&tab[idx]; |
| 1354 | |
| 1355 | if (dir->key_idx) { |
| 1356 | key = (struct _w31_keyent*)&tab[dir->key_idx]; |
| 1357 | |
| 1358 | memcpy(tail,&txt[key->string_off],key->length); |
| 1359 | tail[key->length]='\0'; |
| 1360 | /* all toplevel entries AND the entries in the |
| 1361 | * toplevel subdirectory belong to \SOFTWARE\Classes |
| 1362 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1363 | if (!level && !lstrcmpA(tail,".classes")) { |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1364 | __w31_dumptree(dir->child_idx,txt,tab,head,hkey,lastmodified,level+1); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1365 | idx=dir->sibling_idx; |
| 1366 | continue; |
| 1367 | } |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 1368 | if (subkey) RegCloseKey( subkey ); |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1369 | if (RegCreateKeyA( hkey, tail, &subkey ) != ERROR_SUCCESS) subkey = 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1370 | /* only add if leaf node or valued node */ |
| 1371 | if (dir->value_idx!=0||dir->child_idx==0) { |
| 1372 | if (dir->value_idx) { |
| 1373 | val=(struct _w31_valent*)&tab[dir->value_idx]; |
| 1374 | memcpy(tail,&txt[val->string_off],val->length); |
| 1375 | tail[val->length]='\0'; |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 1376 | RegSetValueA( subkey, NULL, REG_SZ, tail, 0 ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1377 | } |
| 1378 | } |
| 1379 | } else { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1380 | TRACE("strange: no directory key name, idx=%04x\n", idx); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1381 | } |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1382 | __w31_dumptree(dir->child_idx,txt,tab,head,subkey,lastmodified,level+1); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1383 | idx=dir->sibling_idx; |
| 1384 | } |
Alexandre Julliard | b3d90e4 | 1999-11-24 02:46:27 +0000 | [diff] [blame] | 1385 | if (subkey) RegCloseKey( subkey ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1388 | |
| 1389 | /****************************************************************************** |
| 1390 | * _w31_loadreg [Internal] |
| 1391 | */ |
Juergen Schmied | ebc2b77 | 1998-11-14 18:59:30 +0000 | [diff] [blame] | 1392 | void _w31_loadreg(void) { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1393 | HFILE hf; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1394 | struct _w31_header head; |
| 1395 | struct _w31_tabent *tab; |
| 1396 | unsigned char *txt; |
| 1397 | int len; |
| 1398 | OFSTRUCT ofs; |
| 1399 | BY_HANDLE_FILE_INFORMATION hfinfo; |
| 1400 | time_t lastmodified; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1401 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1402 | TRACE("(void)\n"); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1403 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1404 | hf = OpenFile("reg.dat",&ofs,OF_READ); |
| 1405 | if (hf==HFILE_ERROR) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1406 | return; |
| 1407 | |
| 1408 | /* read & dump header */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1409 | if (sizeof(head)!=_lread(hf,&head,sizeof(head))) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1410 | ERR("reg.dat is too short.\n"); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1411 | _lclose(hf); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1412 | return; |
| 1413 | } |
| 1414 | if (memcmp(head.cookie, "SHCC3.10", sizeof(head.cookie))!=0) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1415 | ERR("reg.dat has bad signature.\n"); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1416 | _lclose(hf); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1417 | return; |
| 1418 | } |
| 1419 | |
| 1420 | len = head.tabcnt * sizeof(struct _w31_tabent); |
| 1421 | /* read and dump index table */ |
| 1422 | tab = xmalloc(len); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1423 | if (len!=_lread(hf,tab,len)) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1424 | ERR("couldn't read %d bytes.\n",len); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1425 | free(tab); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1426 | _lclose(hf); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1427 | return; |
| 1428 | } |
| 1429 | |
| 1430 | /* read text */ |
| 1431 | txt = xmalloc(head.textsize); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1432 | if (-1==_llseek(hf,head.textoff,SEEK_SET)) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1433 | ERR("couldn't seek to textblock.\n"); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1434 | free(tab); |
| 1435 | free(txt); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1436 | _lclose(hf); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1437 | return; |
| 1438 | } |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1439 | if (head.textsize!=_lread(hf,txt,head.textsize)) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1440 | ERR("textblock too short (%d instead of %ld).\n",len,head.textsize); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1441 | free(tab); |
| 1442 | free(txt); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1443 | _lclose(hf); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1444 | return; |
| 1445 | } |
| 1446 | |
| 1447 | if (!GetFileInformationByHandle(hf,&hfinfo)) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1448 | ERR("GetFileInformationByHandle failed?.\n"); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1449 | free(tab); |
| 1450 | free(txt); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1451 | _lclose(hf); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1452 | return; |
| 1453 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1454 | lastmodified = DOSFS_FileTimeToUnixTime(&hfinfo.ftLastWriteTime,NULL); |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1455 | __w31_dumptree(tab[0].w1,txt,tab,&head,HKEY_CLASSES_ROOT,lastmodified,0); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1456 | free(tab); |
| 1457 | free(txt); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1458 | _lclose(hf); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1459 | return; |
| 1460 | } |
| 1461 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1462 | /********************************************************************************** |
| 1463 | * SetLoadLevel [Internal] |
| 1464 | * |
| 1465 | * set level to 0 for loading system files |
| 1466 | * set level to 1 for loading user files |
| 1467 | */ |
| 1468 | static void SetLoadLevel(int level) |
| 1469 | { |
| 1470 | struct set_registry_levels_request *req = get_req_buffer(); |
| 1471 | |
| 1472 | req->current = level; |
| 1473 | req->saving = 0; |
| 1474 | req->version = 1; |
| 1475 | server_call( REQ_SET_REGISTRY_LEVELS ); |
| 1476 | } |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1477 | |
| 1478 | /********************************************************************************** |
| 1479 | * SHELL_LoadRegistry [Internal] |
| 1480 | */ |
Juergen Schmied | 8573cc7 | 2000-01-30 03:03:23 +0000 | [diff] [blame^] | 1481 | #define REG_DONTLOAD -1 |
| 1482 | #define REG_WIN31 0 |
| 1483 | #define REG_WIN95 1 |
| 1484 | #define REG_WINNT 2 |
| 1485 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1486 | void SHELL_LoadRegistry( void ) |
| 1487 | { |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1488 | int save_timeout; |
| 1489 | char *fn, *home; |
| 1490 | HKEY hkey; |
Juergen Schmied | 8573cc7 | 2000-01-30 03:03:23 +0000 | [diff] [blame^] | 1491 | char windir[MAX_PATHNAME_LEN]; |
| 1492 | char path[MAX_PATHNAME_LEN]; |
| 1493 | int systemtype = REG_WIN31; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 1494 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1495 | TRACE("(void)\n"); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1496 | |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 1497 | if (!CLIENT_IsBootThread()) return; /* already loaded */ |
| 1498 | |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1499 | REGISTRY_Init(); |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1500 | SetLoadLevel(0); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 1501 | |
Juergen Schmied | 8573cc7 | 2000-01-30 03:03:23 +0000 | [diff] [blame^] | 1502 | GetWindowsDirectoryA( windir, MAX_PATHNAME_LEN ); |
| 1503 | |
| 1504 | if (PROFILE_GetWineIniBool( "Registry", "LoadWindowsRegistryFiles", 1)) |
| 1505 | { |
| 1506 | /* test %windir%/system32/config/system --> winnt */ |
| 1507 | strcpy(path, windir); |
| 1508 | strncat(path, "\\system32\\config\\system", MAX_PATHNAME_LEN - strlen(path) - 1); |
| 1509 | if(GetFileAttributesA(path) != -1) |
| 1510 | { |
| 1511 | systemtype = REG_WINNT; |
| 1512 | } |
| 1513 | else |
| 1514 | { |
| 1515 | /* test %windir%/system.dat --> win95 */ |
| 1516 | strcpy(path, windir); |
| 1517 | strncat(path, "\\system.dat", MAX_PATHNAME_LEN - strlen(path) - 1); |
| 1518 | if(GetFileAttributesA(path) != -1) |
| 1519 | { |
| 1520 | systemtype = REG_WIN95; |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | if ((systemtype==REG_WINNT) |
| 1525 | && (! PROFILE_GetWineIniString( "Wine", "Profile", "", path, MAX_PATHNAME_LEN))) |
| 1526 | { |
| 1527 | MESSAGE("When you are running with a native NT directory specify\n"); |
| 1528 | MESSAGE("'Profile=<profiledirectory>' or disable loading of Windows\n"); |
| 1529 | MESSAGE("registry (LoadWindowsRegistryFiles=N)\n"); |
| 1530 | systemtype = REG_DONTLOAD; |
| 1531 | } |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 1532 | } |
Juergen Schmied | 8573cc7 | 2000-01-30 03:03:23 +0000 | [diff] [blame^] | 1533 | else |
| 1534 | { |
| 1535 | /* only wine registry */ |
| 1536 | systemtype = REG_DONTLOAD; |
| 1537 | } |
| 1538 | |
| 1539 | switch (systemtype) |
| 1540 | { |
| 1541 | case REG_WIN31: |
| 1542 | _w31_loadreg(); |
| 1543 | break; |
| 1544 | |
| 1545 | case REG_WIN95: |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1546 | /* Load windows 95 entries */ |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1547 | NativeRegLoadKey(HKEY_LOCAL_MACHINE, "C:\\system.1st", 0); |
Juergen Schmied | 8573cc7 | 2000-01-30 03:03:23 +0000 | [diff] [blame^] | 1548 | |
| 1549 | strcpy(path, windir); |
| 1550 | strncat(path, "\\system.dat", MAX_PATHNAME_LEN - strlen(path) - 1); |
| 1551 | NativeRegLoadKey(HKEY_LOCAL_MACHINE, path, 0); |
| 1552 | |
| 1553 | if (PROFILE_GetWineIniString( "Wine", "Profile", "", path, MAX_PATHNAME_LEN)) |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 1554 | { |
Juergen Schmied | 8573cc7 | 2000-01-30 03:03:23 +0000 | [diff] [blame^] | 1555 | /* user specific user.dat */ |
| 1556 | strncat(path, "\\user.dat", MAX_PATHNAME_LEN - strlen(path) - 1); |
| 1557 | if (!NativeRegLoadKey( HKEY_CURRENT_USER, path, 1 )) |
| 1558 | { |
| 1559 | MESSAGE("can't load win95 user-registry %s\n", path); |
| 1560 | MESSAGE("check wine.conf, section [Wine], value 'Profile'\n"); |
| 1561 | } |
| 1562 | /* default user.dat */ |
| 1563 | if (!RegCreateKeyA(HKEY_USERS, ".Default", &hkey)) |
| 1564 | { |
| 1565 | strcpy(path, windir); |
| 1566 | strncat(path, "\\user.dat", MAX_PATHNAME_LEN - strlen(path) - 1); |
| 1567 | NativeRegLoadKey(hkey, path, 1); |
| 1568 | RegCloseKey(hkey); |
| 1569 | } |
| 1570 | } |
| 1571 | else |
| 1572 | { |
| 1573 | /* global user.dat */ |
| 1574 | strcpy(path, windir); |
| 1575 | strncat(path, "\\user.dat", MAX_PATHNAME_LEN - strlen(path) - 1); |
| 1576 | NativeRegLoadKey(HKEY_CURRENT_USER, path, 1); |
| 1577 | } |
| 1578 | break; |
| 1579 | |
| 1580 | case REG_WINNT: |
| 1581 | /* default user.dat */ |
| 1582 | if (PROFILE_GetWineIniString( "Wine", "Profile", "", path, MAX_PATHNAME_LEN)) |
| 1583 | { |
| 1584 | strncat(path, "\\ntuser.dat", MAX_PATHNAME_LEN - strlen(path) - 1); |
| 1585 | if(!NativeRegLoadKey( HKEY_CURRENT_USER, path, 1 )) |
| 1586 | { |
| 1587 | MESSAGE("can't load NT user-registry %s\n", path); |
| 1588 | MESSAGE("check wine.conf, section [Wine], value 'Profile'\n"); |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | /* default user.dat */ |
| 1593 | if (!RegCreateKeyA(HKEY_USERS, ".Default", &hkey)) |
| 1594 | { |
| 1595 | strcpy(path, windir); |
| 1596 | strncat(path, "\\system32\\config\\default", MAX_PATHNAME_LEN - strlen(path) - 1); |
| 1597 | NativeRegLoadKey(hkey, path, 1); |
| 1598 | RegCloseKey(hkey); |
| 1599 | } |
| 1600 | |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 1601 | /* |
| 1602 | * FIXME |
| 1603 | * map HLM\System\ControlSet001 to HLM\System\CurrentControlSet |
| 1604 | */ |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 1605 | |
Juergen Schmied | 8573cc7 | 2000-01-30 03:03:23 +0000 | [diff] [blame^] | 1606 | strcpy(path, windir); |
| 1607 | strncat(path, "\\system32\\config\\system", MAX_PATHNAME_LEN - strlen(path) - 1); |
| 1608 | NativeRegLoadKey(HKEY_LOCAL_MACHINE, path, 0); |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 1609 | |
Juergen Schmied | 8573cc7 | 2000-01-30 03:03:23 +0000 | [diff] [blame^] | 1610 | strcpy(path, windir); |
| 1611 | strncat(path, "\\system32\\config\\software", MAX_PATHNAME_LEN - strlen(path) - 1); |
| 1612 | NativeRegLoadKey(HKEY_LOCAL_MACHINE, path, 0); |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 1613 | |
Juergen Schmied | 8573cc7 | 2000-01-30 03:03:23 +0000 | [diff] [blame^] | 1614 | strcpy(path, windir); |
| 1615 | strncat(path, "\\system32\\config\\sam", MAX_PATHNAME_LEN - strlen(path) - 1); |
| 1616 | NativeRegLoadKey(HKEY_LOCAL_MACHINE, path, 0); |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 1617 | |
Juergen Schmied | 8573cc7 | 2000-01-30 03:03:23 +0000 | [diff] [blame^] | 1618 | strcpy(path, windir); |
| 1619 | strncat(path, "\\system32\\config\\security", MAX_PATHNAME_LEN - strlen(path) - 1); |
| 1620 | NativeRegLoadKey(HKEY_LOCAL_MACHINE, path, 0); |
Juergen Schmied | 9e6b1d1 | 1999-12-11 23:22:52 +0000 | [diff] [blame] | 1621 | |
Juergen Schmied | c35cce2 | 1999-12-20 03:58:44 +0000 | [diff] [blame] | 1622 | /* this key is generated when the nt-core booted successfully */ |
| 1623 | if (!RegCreateKeyA(HKEY_LOCAL_MACHINE,"System\\Clone",&hkey)) |
| 1624 | RegCloseKey(hkey); |
Juergen Schmied | 8573cc7 | 2000-01-30 03:03:23 +0000 | [diff] [blame^] | 1625 | break; |
| 1626 | } /* switch */ |
| 1627 | |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1628 | if (PROFILE_GetWineIniBool ("registry","LoadGlobalRegistryFiles", 1)) |
| 1629 | { |
| 1630 | /* |
| 1631 | * Load the global HKU hive directly from sysconfdir |
| 1632 | */ |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1633 | _wine_loadreg( HKEY_USERS, SAVE_USERS_DEFAULT ); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 1634 | |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1635 | /* |
| 1636 | * Load the global machine defaults directly form sysconfdir |
| 1637 | */ |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1638 | _wine_loadreg( HKEY_LOCAL_MACHINE, SAVE_LOCAL_MACHINE_DEFAULT ); |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1639 | } |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 1640 | |
Juergen Schmied | 271ba29 | 2000-01-15 23:42:50 +0000 | [diff] [blame] | 1641 | SetLoadLevel(1); |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1642 | |
Sylvain St.Germain | e533222 | 1999-04-10 16:46:15 +0000 | [diff] [blame] | 1643 | /* |
| 1644 | * Load the user saved registries |
| 1645 | */ |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1646 | if (!(home = getenv( "HOME" ))) |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1647 | WARN("Failed to get homedirectory of UID %ld.\n",(long) getuid()); |
Marcus Meissner | 31b9dab | 1999-10-24 22:08:33 +0000 | [diff] [blame] | 1648 | else if (PROFILE_GetWineIniBool("registry", "LoadHomeRegistryFiles", 1)) |
Sylvain St.Germain | e533222 | 1999-04-10 16:46:15 +0000 | [diff] [blame] | 1649 | { |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1650 | /* |
| 1651 | * Load user's personal versions of global HKU/.Default keys |
| 1652 | */ |
| 1653 | fn=(char*)xmalloc( strlen(home)+ strlen(WINE_PREFIX) + |
| 1654 | strlen(SAVE_LOCAL_USERS_DEFAULT)+2); |
| 1655 | strcpy(fn, home); |
| 1656 | strcat(fn, WINE_PREFIX"/"SAVE_LOCAL_USERS_DEFAULT); |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1657 | _wine_loadreg( HKEY_USERS, fn ); |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1658 | free(fn); |
Nathan Zorich | bd3771c | 1999-03-14 15:12:48 +0000 | [diff] [blame] | 1659 | |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1660 | fn=(char*)xmalloc( strlen(home) + strlen(WINE_PREFIX) + strlen(SAVE_CURRENT_USER)+2); |
| 1661 | strcpy(fn, home); |
| 1662 | strcat(fn, WINE_PREFIX"/"SAVE_CURRENT_USER); |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1663 | _wine_loadreg( HKEY_CURRENT_USER, fn ); |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1664 | free(fn); |
Nathan Zorich | bd3771c | 1999-03-14 15:12:48 +0000 | [diff] [blame] | 1665 | |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1666 | /* |
| 1667 | * Load HKLM, attempt to get the registry location from the config |
| 1668 | * file first, if exist, load and keep going. |
| 1669 | */ |
| 1670 | fn=(char*)xmalloc( strlen(home)+ strlen(WINE_PREFIX)+ strlen(SAVE_LOCAL_MACHINE)+2); |
| 1671 | strcpy(fn,home); |
| 1672 | strcat(fn,WINE_PREFIX"/"SAVE_LOCAL_MACHINE); |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1673 | _wine_loadreg( HKEY_LOCAL_MACHINE, fn ); |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1674 | free(fn); |
Sylvain St.Germain | e533222 | 1999-04-10 16:46:15 +0000 | [diff] [blame] | 1675 | } |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1676 | |
| 1677 | /* |
| 1678 | * Load HKCU, get the registry location from the config |
| 1679 | * file, if exist, load and keep going. |
| 1680 | */ |
| 1681 | if (PROFILE_GetWineIniBool ( "registry", "LoadAltRegistryFiles", 1)) |
Sylvain St.Germain | e533222 | 1999-04-10 16:46:15 +0000 | [diff] [blame] | 1682 | { |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1683 | fn = xmalloc( MAX_PATHNAME_LEN ); |
| 1684 | if ( PROFILE_GetWineIniString( "registry", "AltCurrentUserFile", "", |
| 1685 | fn, MAX_PATHNAME_LEN - 1)) |
| 1686 | { |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1687 | _wine_loadreg( HKEY_CURRENT_USER, fn ); |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1688 | } |
| 1689 | free (fn); |
| 1690 | /* |
| 1691 | * Load HKU, get the registry location from the config |
| 1692 | * file, if exist, load and keep going. |
| 1693 | */ |
| 1694 | fn = xmalloc ( MAX_PATHNAME_LEN ); |
| 1695 | if ( PROFILE_GetWineIniString ( "registry", "AltUserFile", "", |
| 1696 | fn, MAX_PATHNAME_LEN - 1)) |
| 1697 | { |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1698 | _wine_loadreg( HKEY_USERS, fn ); |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1699 | } |
| 1700 | free (fn); |
| 1701 | /* |
| 1702 | * Load HKLM, get the registry location from the config |
| 1703 | * file, if exist, load and keep going. |
| 1704 | */ |
| 1705 | fn = xmalloc ( MAX_PATHNAME_LEN ); |
| 1706 | if (PROFILE_GetWineIniString ( "registry", "AltLocalMachineFile", "", |
| 1707 | fn, MAX_PATHNAME_LEN - 1)) |
| 1708 | { |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1709 | _wine_loadreg( HKEY_LOCAL_MACHINE, fn ); |
Nathaniel | 7bf36ad | 1999-10-24 19:35:47 +0000 | [diff] [blame] | 1710 | } |
| 1711 | free (fn); |
Alexandre Julliard | 154c99b | 1999-04-25 12:41:36 +0000 | [diff] [blame] | 1712 | } |
Juergen Schmied | 5d0ae2d | 2000-01-09 21:07:01 +0000 | [diff] [blame] | 1713 | |
Sylvain St.Germain | e533222 | 1999-04-10 16:46:15 +0000 | [diff] [blame] | 1714 | /* |
| 1715 | * Make sure the update mode is there |
| 1716 | */ |
| 1717 | if (ERROR_SUCCESS==RegCreateKey16(HKEY_CURRENT_USER,KEY_REGISTRY,&hkey)) |
| 1718 | { |
| 1719 | DWORD junk,type,len; |
| 1720 | char data[5]; |
| 1721 | |
| 1722 | len=4; |
| 1723 | if (( RegQueryValueExA( |
| 1724 | hkey, |
| 1725 | VAL_SAVEUPDATED, |
| 1726 | &junk, |
| 1727 | &type, |
| 1728 | data, |
| 1729 | &len) != ERROR_SUCCESS) || (type != REG_SZ)) |
| 1730 | { |
| 1731 | RegSetValueExA(hkey,VAL_SAVEUPDATED,0,REG_SZ,"yes",4); |
| 1732 | } |
| 1733 | |
| 1734 | RegCloseKey(hkey); |
| 1735 | } |
Alexandre Julliard | 705686e | 1999-11-24 19:34:32 +0000 | [diff] [blame] | 1736 | |
| 1737 | if ((save_timeout = PROFILE_GetWineIniInt( "registry", "PeriodicSave", 0 ))) |
| 1738 | { |
| 1739 | SERVICE_AddTimer( save_timeout * 1000000, periodic_save, 0 ); |
| 1740 | } |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 1743 | |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 1744 | /********************* API FUNCTIONS ***************************************/ |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 1745 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1746 | |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 1747 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1748 | |
| 1749 | /****************************************************************************** |
| 1750 | * RegFlushKey [KERNEL.227] [ADVAPI32.143] |
Andreas Mohr | d4b13da | 1999-08-07 14:17:10 +0000 | [diff] [blame] | 1751 | * Immediately writes key to registry. |
| 1752 | * Only returns after data has been written to disk. |
| 1753 | * |
| 1754 | * FIXME: does it really wait until data is written ? |
| 1755 | * |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1756 | * PARAMS |
| 1757 | * hkey [I] Handle of key to write |
| 1758 | * |
| 1759 | * RETURNS |
| 1760 | * Success: ERROR_SUCCESS |
| 1761 | * Failure: Error code |
| 1762 | */ |
| 1763 | DWORD WINAPI RegFlushKey( HKEY hkey ) |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1764 | { |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1765 | FIXME( "(%x): stub\n", hkey ); |
| 1766 | return ERROR_SUCCESS; |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 1767 | } |
| 1768 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1769 | /****************************************************************************** |
| 1770 | * RegConnectRegistry32W [ADVAPI32.128] |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1771 | * |
| 1772 | * PARAMS |
| 1773 | * lpMachineName [I] Address of name of remote computer |
| 1774 | * hHey [I] Predefined registry handle |
| 1775 | * phkResult [I] Address of buffer for remote registry handle |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1776 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1777 | LONG WINAPI RegConnectRegistryW( LPCWSTR lpMachineName, HKEY hKey, |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1778 | LPHKEY phkResult ) |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1779 | { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1780 | TRACE("(%s,%x,%p): stub\n",debugstr_w(lpMachineName),hKey,phkResult); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1781 | |
| 1782 | if (!lpMachineName || !*lpMachineName) { |
| 1783 | /* Use the local machine name */ |
| 1784 | return RegOpenKey16( hKey, "", phkResult ); |
| 1785 | } |
| 1786 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1787 | FIXME("Cannot connect to %s\n",debugstr_w(lpMachineName)); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1788 | return ERROR_BAD_NETPATH; |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | |
| 1792 | /****************************************************************************** |
| 1793 | * RegConnectRegistry32A [ADVAPI32.127] |
| 1794 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1795 | LONG WINAPI RegConnectRegistryA( LPCSTR machine, HKEY hkey, LPHKEY reskey ) |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1796 | { |
| 1797 | DWORD ret; |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1798 | LPWSTR machineW = strdupA2W(machine); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1799 | ret = RegConnectRegistryW( machineW, hkey, reskey ); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1800 | free(machineW); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1801 | return ret; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1802 | } |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1803 | |
| 1804 | |
| 1805 | /****************************************************************************** |
| 1806 | * RegGetKeySecurity [ADVAPI32.144] |
| 1807 | * Retrieves a copy of security descriptor protecting the registry key |
| 1808 | * |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1809 | * PARAMS |
| 1810 | * hkey [I] Open handle of key to set |
| 1811 | * SecurityInformation [I] Descriptor contents |
| 1812 | * pSecurityDescriptor [O] Address of descriptor for key |
| 1813 | * lpcbSecurityDescriptor [I/O] Address of size of buffer and description |
| 1814 | * |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1815 | * RETURNS |
| 1816 | * Success: ERROR_SUCCESS |
| 1817 | * Failure: Error code |
| 1818 | */ |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1819 | LONG WINAPI RegGetKeySecurity( HKEY hkey, |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1820 | SECURITY_INFORMATION SecurityInformation, |
Juergen Schmied | 1ed51af | 1999-02-12 17:47:07 +0000 | [diff] [blame] | 1821 | PSECURITY_DESCRIPTOR pSecurityDescriptor, |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1822 | LPDWORD lpcbSecurityDescriptor ) |
| 1823 | { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1824 | TRACE("(%x,%ld,%p,%ld)\n",hkey,SecurityInformation,pSecurityDescriptor, |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 1825 | lpcbSecurityDescriptor?*lpcbSecurityDescriptor:0); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1826 | |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 1827 | /* FIXME: Check for valid SecurityInformation values */ |
| 1828 | |
Alexandre Julliard | b24fc08 | 1999-02-25 16:36:07 +0000 | [diff] [blame] | 1829 | if (*lpcbSecurityDescriptor < sizeof(SECURITY_DESCRIPTOR)) |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1830 | return ERROR_INSUFFICIENT_BUFFER; |
| 1831 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1832 | FIXME("(%x,%ld,%p,%ld): stub\n",hkey,SecurityInformation, |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 1833 | pSecurityDescriptor,lpcbSecurityDescriptor?*lpcbSecurityDescriptor:0); |
| 1834 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1835 | return ERROR_SUCCESS; |
| 1836 | } |
| 1837 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1838 | |
| 1839 | /****************************************************************************** |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1840 | * RegNotifyChangeKeyValue [ADVAPI32.???] |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1841 | * |
| 1842 | * PARAMS |
| 1843 | * hkey [I] Handle of key to watch |
| 1844 | * fWatchSubTree [I] Flag for subkey notification |
| 1845 | * fdwNotifyFilter [I] Changes to be reported |
| 1846 | * hEvent [I] Handle of signaled event |
| 1847 | * fAsync [I] Flag for asynchronous reporting |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1848 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1849 | LONG WINAPI RegNotifyChangeKeyValue( HKEY hkey, BOOL fWatchSubTree, |
| 1850 | DWORD fdwNotifyFilter, HANDLE hEvent, |
| 1851 | BOOL fAsync ) |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1852 | { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1853 | FIXME("(%x,%i,%ld,%x,%i): stub\n",hkey,fWatchSubTree,fdwNotifyFilter, |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 1854 | hEvent,fAsync); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1855 | return ERROR_SUCCESS; |
| 1856 | } |
| 1857 | |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1858 | |
| 1859 | /****************************************************************************** |
| 1860 | * RegUnLoadKey32W [ADVAPI32.173] |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1861 | * |
| 1862 | * PARAMS |
| 1863 | * hkey [I] Handle of open key |
| 1864 | * lpSubKey [I] Address of name of subkey to unload |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1865 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1866 | LONG WINAPI RegUnLoadKeyW( HKEY hkey, LPCWSTR lpSubKey ) |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1867 | { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1868 | FIXME("(%x,%s): stub\n",hkey, debugstr_w(lpSubKey)); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1869 | return ERROR_SUCCESS; |
| 1870 | } |
| 1871 | |
| 1872 | |
| 1873 | /****************************************************************************** |
| 1874 | * RegUnLoadKey32A [ADVAPI32.172] |
| 1875 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1876 | LONG WINAPI RegUnLoadKeyA( HKEY hkey, LPCSTR lpSubKey ) |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1877 | { |
| 1878 | LONG ret; |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1879 | LPWSTR lpSubKeyW = strdupA2W(lpSubKey); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1880 | ret = RegUnLoadKeyW( hkey, lpSubKeyW ); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1881 | if(lpSubKeyW) free(lpSubKeyW); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1882 | return ret; |
| 1883 | } |
| 1884 | |
| 1885 | |
| 1886 | /****************************************************************************** |
| 1887 | * RegSetKeySecurity [ADVAPI32.167] |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1888 | * |
| 1889 | * PARAMS |
| 1890 | * hkey [I] Open handle of key to set |
| 1891 | * SecurityInfo [I] Descriptor contents |
| 1892 | * pSecurityDesc [I] Address of descriptor for key |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1893 | */ |
| 1894 | LONG WINAPI RegSetKeySecurity( HKEY hkey, SECURITY_INFORMATION SecurityInfo, |
Juergen Schmied | 1ed51af | 1999-02-12 17:47:07 +0000 | [diff] [blame] | 1895 | PSECURITY_DESCRIPTOR pSecurityDesc ) |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1896 | { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1897 | TRACE("(%x,%ld,%p)\n",hkey,SecurityInfo,pSecurityDesc); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1898 | |
| 1899 | /* It seems to perform this check before the hkey check */ |
| 1900 | if ((SecurityInfo & OWNER_SECURITY_INFORMATION) || |
| 1901 | (SecurityInfo & GROUP_SECURITY_INFORMATION) || |
| 1902 | (SecurityInfo & DACL_SECURITY_INFORMATION) || |
| 1903 | (SecurityInfo & SACL_SECURITY_INFORMATION)) { |
| 1904 | /* Param OK */ |
| 1905 | } else |
| 1906 | return ERROR_INVALID_PARAMETER; |
| 1907 | |
| 1908 | if (!pSecurityDesc) |
| 1909 | return ERROR_INVALID_PARAMETER; |
| 1910 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1911 | FIXME(":(%x,%ld,%p): stub\n",hkey,SecurityInfo,pSecurityDesc); |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 1912 | |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1913 | return ERROR_SUCCESS; |
| 1914 | } |
| 1915 | |
| 1916 | |
| 1917 | /****************************************************************************** |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1918 | * RegRestoreKey32W [ADVAPI32.164] |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1919 | * |
| 1920 | * PARAMS |
| 1921 | * hkey [I] Handle of key where restore begins |
| 1922 | * lpFile [I] Address of filename containing saved tree |
| 1923 | * dwFlags [I] Optional flags |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1924 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1925 | LONG WINAPI RegRestoreKeyW( HKEY hkey, LPCWSTR lpFile, DWORD dwFlags ) |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1926 | { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1927 | TRACE("(%x,%s,%ld)\n",hkey,debugstr_w(lpFile),dwFlags); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1928 | |
| 1929 | /* It seems to do this check before the hkey check */ |
| 1930 | if (!lpFile || !*lpFile) |
| 1931 | return ERROR_INVALID_PARAMETER; |
| 1932 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1933 | FIXME("(%x,%s,%ld): stub\n",hkey,debugstr_w(lpFile),dwFlags); |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 1934 | |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1935 | /* Check for file existence */ |
| 1936 | |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1937 | return ERROR_SUCCESS; |
| 1938 | } |
| 1939 | |
| 1940 | |
| 1941 | /****************************************************************************** |
| 1942 | * RegRestoreKey32A [ADVAPI32.163] |
| 1943 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1944 | LONG WINAPI RegRestoreKeyA( HKEY hkey, LPCSTR lpFile, DWORD dwFlags ) |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1945 | { |
| 1946 | LONG ret; |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1947 | LPWSTR lpFileW = strdupA2W(lpFile); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1948 | ret = RegRestoreKeyW( hkey, lpFileW, dwFlags ); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1949 | if(lpFileW) free(lpFileW); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1950 | return ret; |
| 1951 | } |
| 1952 | |
| 1953 | |
| 1954 | /****************************************************************************** |
| 1955 | * RegReplaceKey32W [ADVAPI32.162] |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1956 | * |
| 1957 | * PARAMS |
| 1958 | * hkey [I] Handle of open key |
| 1959 | * lpSubKey [I] Address of name of subkey |
| 1960 | * lpNewFile [I] Address of filename for file with new data |
| 1961 | * lpOldFile [I] Address of filename for backup file |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1962 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1963 | LONG WINAPI RegReplaceKeyW( HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpNewFile, |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1964 | LPCWSTR lpOldFile ) |
| 1965 | { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 1966 | FIXME("(%x,%s,%s,%s): stub\n", hkey, debugstr_w(lpSubKey), |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 1967 | debugstr_w(lpNewFile),debugstr_w(lpOldFile)); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1968 | return ERROR_SUCCESS; |
| 1969 | } |
| 1970 | |
| 1971 | |
| 1972 | /****************************************************************************** |
| 1973 | * RegReplaceKey32A [ADVAPI32.161] |
| 1974 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1975 | LONG WINAPI RegReplaceKeyA( HKEY hkey, LPCSTR lpSubKey, LPCSTR lpNewFile, |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1976 | LPCSTR lpOldFile ) |
| 1977 | { |
| 1978 | LONG ret; |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1979 | LPWSTR lpSubKeyW = strdupA2W(lpSubKey); |
| 1980 | LPWSTR lpNewFileW = strdupA2W(lpNewFile); |
| 1981 | LPWSTR lpOldFileW = strdupA2W(lpOldFile); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1982 | ret = RegReplaceKeyW( hkey, lpSubKeyW, lpNewFileW, lpOldFileW ); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1983 | free(lpOldFileW); |
| 1984 | free(lpNewFileW); |
| 1985 | free(lpSubKeyW); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1986 | return ret; |
| 1987 | } |
| 1988 | |
Alexandre Julliard | 2fab2ef | 1999-11-23 19:41:34 +0000 | [diff] [blame] | 1989 | |
| 1990 | |
| 1991 | |
| 1992 | |
| 1993 | |
| 1994 | /* 16-bit functions */ |
| 1995 | |
| 1996 | /* 0 and 1 are valid rootkeys in win16 shell.dll and are used by |
| 1997 | * some programs. Do not remove those cases. -MM |
| 1998 | */ |
| 1999 | static inline void fix_win16_hkey( HKEY *hkey ) |
| 2000 | { |
| 2001 | if (*hkey == 0 || *hkey == 1) *hkey = HKEY_CLASSES_ROOT; |
| 2002 | } |
| 2003 | |
| 2004 | /****************************************************************************** |
| 2005 | * RegEnumKey16 [KERNEL.216] [SHELL.7] |
| 2006 | */ |
| 2007 | DWORD WINAPI RegEnumKey16( HKEY hkey, DWORD index, LPSTR name, DWORD name_len ) |
| 2008 | { |
| 2009 | fix_win16_hkey( &hkey ); |
| 2010 | return RegEnumKeyA( hkey, index, name, name_len ); |
| 2011 | } |
| 2012 | |
| 2013 | /****************************************************************************** |
| 2014 | * RegOpenKey16 [KERNEL.217] [SHELL.1] |
| 2015 | */ |
| 2016 | DWORD WINAPI RegOpenKey16( HKEY hkey, LPCSTR name, LPHKEY retkey ) |
| 2017 | { |
| 2018 | fix_win16_hkey( &hkey ); |
| 2019 | return RegOpenKeyA( hkey, name, retkey ); |
| 2020 | } |
| 2021 | |
| 2022 | /****************************************************************************** |
| 2023 | * RegCreateKey16 [KERNEL.218] [SHELL.2] |
| 2024 | */ |
| 2025 | DWORD WINAPI RegCreateKey16( HKEY hkey, LPCSTR name, LPHKEY retkey ) |
| 2026 | { |
| 2027 | fix_win16_hkey( &hkey ); |
| 2028 | return RegCreateKeyA( hkey, name, retkey ); |
| 2029 | } |
| 2030 | |
| 2031 | /****************************************************************************** |
| 2032 | * RegDeleteKey16 [KERNEL.219] [SHELL.4] |
| 2033 | */ |
| 2034 | DWORD WINAPI RegDeleteKey16( HKEY hkey, LPCSTR name ) |
| 2035 | { |
| 2036 | fix_win16_hkey( &hkey ); |
| 2037 | return RegDeleteKeyA( hkey, name ); |
| 2038 | } |
| 2039 | |
| 2040 | /****************************************************************************** |
| 2041 | * RegCloseKey16 [KERNEL.220] [SHELL.3] |
| 2042 | */ |
| 2043 | DWORD WINAPI RegCloseKey16( HKEY hkey ) |
| 2044 | { |
| 2045 | fix_win16_hkey( &hkey ); |
| 2046 | return RegCloseKey( hkey ); |
| 2047 | } |
| 2048 | |
| 2049 | /****************************************************************************** |
| 2050 | * RegSetValue16 [KERNEL.221] [SHELL.5] |
| 2051 | */ |
| 2052 | DWORD WINAPI RegSetValue16( HKEY hkey, LPCSTR name, DWORD type, LPCSTR data, DWORD count ) |
| 2053 | { |
| 2054 | fix_win16_hkey( &hkey ); |
| 2055 | return RegSetValueA( hkey, name, type, data, count ); |
| 2056 | } |
| 2057 | |
| 2058 | /****************************************************************************** |
| 2059 | * RegDeleteValue16 [KERNEL.222] |
| 2060 | */ |
| 2061 | DWORD WINAPI RegDeleteValue16( HKEY hkey, LPSTR name ) |
| 2062 | { |
| 2063 | fix_win16_hkey( &hkey ); |
| 2064 | return RegDeleteValueA( hkey, name ); |
| 2065 | } |
| 2066 | |
| 2067 | /****************************************************************************** |
| 2068 | * RegEnumValue16 [KERNEL.223] |
| 2069 | */ |
| 2070 | DWORD WINAPI RegEnumValue16( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count, |
| 2071 | LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count ) |
| 2072 | { |
| 2073 | fix_win16_hkey( &hkey ); |
| 2074 | return RegEnumValueA( hkey, index, value, val_count, reserved, type, data, count ); |
| 2075 | } |
| 2076 | |
| 2077 | /****************************************************************************** |
| 2078 | * RegQueryValue16 [KERNEL.224] [SHELL.6] |
| 2079 | * |
| 2080 | * NOTES |
| 2081 | * Is this HACK still applicable? |
| 2082 | * |
| 2083 | * HACK |
| 2084 | * The 16bit RegQueryValue doesn't handle selectorblocks anyway, so we just |
| 2085 | * mask out the high 16 bit. This (not so much incidently) hopefully fixes |
| 2086 | * Aldus FH4) |
| 2087 | */ |
| 2088 | DWORD WINAPI RegQueryValue16( HKEY hkey, LPCSTR name, LPSTR data, LPDWORD count ) |
| 2089 | { |
| 2090 | fix_win16_hkey( &hkey ); |
| 2091 | if (count) *count &= 0xffff; |
| 2092 | return RegQueryValueA( hkey, name, data, count ); |
| 2093 | } |
| 2094 | |
| 2095 | /****************************************************************************** |
| 2096 | * RegQueryValueEx16 [KERNEL.225] |
| 2097 | */ |
| 2098 | DWORD WINAPI RegQueryValueEx16( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD type, |
| 2099 | LPBYTE data, LPDWORD count ) |
| 2100 | { |
| 2101 | fix_win16_hkey( &hkey ); |
| 2102 | return RegQueryValueExA( hkey, name, reserved, type, data, count ); |
| 2103 | } |
| 2104 | |
| 2105 | /****************************************************************************** |
| 2106 | * RegSetValueEx16 [KERNEL.226] |
| 2107 | */ |
| 2108 | DWORD WINAPI RegSetValueEx16( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type, |
| 2109 | CONST BYTE *data, DWORD count ) |
| 2110 | { |
| 2111 | fix_win16_hkey( &hkey ); |
| 2112 | return RegSetValueExA( hkey, name, reserved, type, data, count ); |
| 2113 | } |