Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Server-side registry management |
| 3 | * |
| 4 | * Copyright (C) 1999 Alexandre Julliard |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | /* To do: |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 22 | * - symbolic links |
| 23 | */ |
| 24 | |
Alexandre Julliard | 5769d1d | 2002-04-26 19:05:15 +0000 | [diff] [blame] | 25 | #include "config.h" |
| 26 | #include "wine/port.h" |
| 27 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 28 | #include <assert.h> |
Alexandre Julliard | 7e495e1 | 2000-07-25 21:01:59 +0000 | [diff] [blame] | 29 | #include <ctype.h> |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 30 | #include <errno.h> |
| 31 | #include <fcntl.h> |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 32 | #include <limits.h> |
| 33 | #include <stdio.h> |
Alexandre Julliard | 62986a0 | 2003-09-07 05:08:14 +0000 | [diff] [blame] | 34 | #include <stdarg.h> |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 35 | #include <string.h> |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 36 | #include <stdlib.h> |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 37 | #include <sys/stat.h> |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 38 | #include <unistd.h> |
Alexandre Julliard | 863637b | 2003-01-30 00:26:44 +0000 | [diff] [blame] | 39 | |
Ge van Geldorp | 1a1583a | 2005-11-28 17:32:54 +0100 | [diff] [blame] | 40 | #include "ntstatus.h" |
| 41 | #define WIN32_NO_STATUS |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 42 | #include "object.h" |
Alexandre Julliard | 863637b | 2003-01-30 00:26:44 +0000 | [diff] [blame] | 43 | #include "file.h" |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 44 | #include "handle.h" |
| 45 | #include "request.h" |
Alexandre Julliard | bbc03d5 | 2010-05-04 20:26:53 +0200 | [diff] [blame] | 46 | #include "process.h" |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 47 | #include "unicode.h" |
Robert Shearman | b3957e3 | 2005-05-05 16:57:55 +0000 | [diff] [blame] | 48 | #include "security.h" |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 49 | |
Patrik Stridvall | 9c1de6d | 2002-09-12 22:07:02 +0000 | [diff] [blame] | 50 | #include "winternl.h" |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 51 | #include "wine/library.h" |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 52 | |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 53 | struct notify |
| 54 | { |
Alexandre Julliard | 68abbc8 | 2005-02-24 19:43:53 +0000 | [diff] [blame] | 55 | struct list entry; /* entry in list of notifications */ |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 56 | struct event *event; /* event to set when changing this key */ |
| 57 | int subtree; /* true if subtree notification */ |
| 58 | unsigned int filter; /* which events to notify on */ |
| 59 | obj_handle_t hkey; /* hkey associated with this notification */ |
Alexandre Julliard | 9b3b7ca | 2005-06-09 20:36:08 +0000 | [diff] [blame] | 60 | struct process *process; /* process in which the hkey is valid */ |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 63 | /* a registry key */ |
| 64 | struct key |
| 65 | { |
| 66 | struct object obj; /* object header */ |
| 67 | WCHAR *name; /* key name */ |
| 68 | WCHAR *class; /* key class */ |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 69 | unsigned short namelen; /* length of key name */ |
| 70 | unsigned short classlen; /* length of class name */ |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 71 | struct key *parent; /* parent key */ |
| 72 | int last_subkey; /* last in use subkey */ |
| 73 | int nb_subkeys; /* count of allocated subkeys */ |
| 74 | struct key **subkeys; /* subkeys array */ |
| 75 | int last_value; /* last in use value */ |
| 76 | int nb_values; /* count of allocated values in array */ |
| 77 | struct key_value *values; /* values array */ |
Alexandre Julliard | dcab706 | 2005-03-14 11:00:43 +0000 | [diff] [blame] | 78 | unsigned int flags; /* flags */ |
Alexandre Julliard | 3343c40 | 2008-12-06 17:29:01 +0100 | [diff] [blame] | 79 | timeout_t modif; /* last modification time */ |
Alexandre Julliard | 68abbc8 | 2005-02-24 19:43:53 +0000 | [diff] [blame] | 80 | struct list notify_list; /* list of notifications */ |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | /* key flags */ |
| 84 | #define KEY_VOLATILE 0x0001 /* key is volatile (not saved to disk) */ |
| 85 | #define KEY_DELETED 0x0002 /* key has been deleted */ |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 86 | #define KEY_DIRTY 0x0004 /* key has been modified */ |
Alexandre Julliard | b139b93 | 2010-02-15 21:04:26 +0100 | [diff] [blame] | 87 | #define KEY_SYMLINK 0x0008 /* key is a symbolic link */ |
Alexandre Julliard | ac08b03 | 2010-03-02 12:03:17 +0100 | [diff] [blame] | 88 | #define KEY_WOW64 0x0010 /* key contains a Wow6432Node subkey */ |
Alexandre Julliard | 178cd20 | 2010-03-04 20:47:35 +0100 | [diff] [blame] | 89 | #define KEY_WOWSHARE 0x0020 /* key is a Wow64 shared key (used for Software\Classes) */ |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 90 | |
| 91 | /* a key value */ |
| 92 | struct key_value |
| 93 | { |
| 94 | WCHAR *name; /* value name */ |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 95 | unsigned short namelen; /* length of value name */ |
| 96 | unsigned short type; /* value type */ |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 97 | data_size_t len; /* value data length in bytes */ |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 98 | void *data; /* pointer to value data */ |
| 99 | }; |
| 100 | |
| 101 | #define MIN_SUBKEYS 8 /* min. number of allocated subkeys per key */ |
| 102 | #define MIN_VALUES 8 /* min. number of allocated values per key */ |
| 103 | |
Alexandre Julliard | 935cc79 | 2010-04-02 11:48:14 +0200 | [diff] [blame] | 104 | #define MAX_NAME_LEN 255 /* max. length of a key name */ |
| 105 | #define MAX_VALUE_LEN 16383 /* max. length of a value name */ |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 106 | |
Alexandre Julliard | 7e9757c | 2004-05-06 23:42:04 +0000 | [diff] [blame] | 107 | /* the root of the registry tree */ |
Alexandre Julliard | 6c8d917 | 2000-08-26 04:40:07 +0000 | [diff] [blame] | 108 | static struct key *root_key; |
| 109 | |
Alexandre Julliard | 3343c40 | 2008-12-06 17:29:01 +0100 | [diff] [blame] | 110 | static const timeout_t ticks_1601_to_1970 = (timeout_t)86400 * (369 * 365 + 89) * TICKS_PER_SEC; |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 111 | static const timeout_t save_period = 30 * -TICKS_PER_SEC; /* delay between periodic saves */ |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 112 | static struct timeout_user *save_timeout_user; /* saving timer */ |
Alexandre Julliard | 58791c9 | 2010-05-04 20:26:04 +0200 | [diff] [blame] | 113 | static enum prefix_type { PREFIX_UNKNOWN, PREFIX_32BIT, PREFIX_64BIT } prefix_type; |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 114 | |
Alexandre Julliard | b139b93 | 2010-02-15 21:04:26 +0100 | [diff] [blame] | 115 | static const WCHAR root_name[] = { '\\','R','e','g','i','s','t','r','y','\\' }; |
Alexandre Julliard | ac08b03 | 2010-03-02 12:03:17 +0100 | [diff] [blame] | 116 | static const WCHAR wow6432node[] = {'W','o','w','6','4','3','2','N','o','d','e'}; |
Alexandre Julliard | b139b93 | 2010-02-15 21:04:26 +0100 | [diff] [blame] | 117 | static const WCHAR symlink_value[] = {'S','y','m','b','o','l','i','c','L','i','n','k','V','a','l','u','e'}; |
| 118 | static const struct unicode_str symlink_str = { symlink_value, sizeof(symlink_value) }; |
| 119 | |
Alexandre Julliard | dcab706 | 2005-03-14 11:00:43 +0000 | [diff] [blame] | 120 | static void set_periodic_save_timer(void); |
Alexandre Julliard | b139b93 | 2010-02-15 21:04:26 +0100 | [diff] [blame] | 121 | static struct key_value *find_value( const struct key *key, const struct unicode_str *name, int *index ); |
Alexandre Julliard | dcab706 | 2005-03-14 11:00:43 +0000 | [diff] [blame] | 122 | |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 123 | /* information about where to save a registry branch */ |
| 124 | struct save_branch_info |
| 125 | { |
| 126 | struct key *key; |
Alexandre Julliard | 161160f | 2008-04-17 12:41:34 +0200 | [diff] [blame] | 127 | const char *path; |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
Alexandre Julliard | c07ce05 | 2004-05-07 04:13:21 +0000 | [diff] [blame] | 130 | #define MAX_SAVE_BRANCH_INFO 3 |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 131 | static int save_branch_count; |
| 132 | static struct save_branch_info save_branch_info[MAX_SAVE_BRANCH_INFO]; |
| 133 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 134 | |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 135 | /* information about a file being loaded */ |
| 136 | struct file_load_info |
| 137 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 138 | const char *filename; /* input file name */ |
| 139 | FILE *file; /* input file */ |
| 140 | char *buffer; /* line buffer */ |
| 141 | int len; /* buffer length */ |
| 142 | int line; /* current input line */ |
| 143 | WCHAR *tmp; /* temp buffer to use while parsing input */ |
| 144 | size_t tmplen; /* length of temp buffer */ |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 148 | static void key_dump( struct object *obj, int verbose ); |
Alexandre Julliard | 32a9396 | 2005-12-12 15:02:26 +0100 | [diff] [blame] | 149 | static unsigned int key_map_access( struct object *obj, unsigned int access ); |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 150 | static int key_close_handle( struct object *obj, struct process *process, obj_handle_t handle ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 151 | static void key_destroy( struct object *obj ); |
| 152 | |
| 153 | static const struct object_ops key_ops = |
| 154 | { |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 155 | sizeof(struct key), /* size */ |
| 156 | key_dump, /* dump */ |
Alexandre Julliard | 8382eb0 | 2007-12-05 18:16:42 +0100 | [diff] [blame] | 157 | no_get_type, /* get_type */ |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 158 | no_add_queue, /* add_queue */ |
| 159 | NULL, /* remove_queue */ |
| 160 | NULL, /* signaled */ |
| 161 | NULL, /* satisfied */ |
Mike McCormack | f92fff6 | 2005-04-24 17:35:52 +0000 | [diff] [blame] | 162 | no_signal, /* signal */ |
Alexandre Julliard | 1ab243b | 2000-12-19 02:12:45 +0000 | [diff] [blame] | 163 | no_get_fd, /* get_fd */ |
Alexandre Julliard | 32a9396 | 2005-12-12 15:02:26 +0100 | [diff] [blame] | 164 | key_map_access, /* map_access */ |
Rob Shearman | c1707d8 | 2007-10-03 13:10:37 +0100 | [diff] [blame] | 165 | default_get_sd, /* get_sd */ |
| 166 | default_set_sd, /* set_sd */ |
Vitaliy Margolen | baffcb9 | 2005-11-22 14:55:42 +0000 | [diff] [blame] | 167 | no_lookup_name, /* lookup_name */ |
Alexandre Julliard | 7e71c1d | 2007-03-22 11:44:29 +0100 | [diff] [blame] | 168 | no_open_file, /* open_file */ |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 169 | key_close_handle, /* close_handle */ |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 170 | key_destroy /* destroy */ |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 171 | }; |
| 172 | |
| 173 | |
Alexandre Julliard | ac08b03 | 2010-03-02 12:03:17 +0100 | [diff] [blame] | 174 | static inline int is_wow6432node( const WCHAR *name, unsigned int len ) |
| 175 | { |
| 176 | return (len == sizeof(wow6432node) && |
| 177 | !memicmpW( name, wow6432node, sizeof(wow6432node)/sizeof(WCHAR) )); |
| 178 | } |
| 179 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 180 | /* |
| 181 | * The registry text file format v2 used by this code is similar to the one |
| 182 | * used by REGEDIT import/export functionality, with the following differences: |
| 183 | * - strings and key names can contain \x escapes for Unicode |
| 184 | * - key names use escapes too in order to support Unicode |
| 185 | * - the modification time optionally follows the key name |
| 186 | * - REG_EXPAND_SZ and REG_MULTI_SZ are saved as strings instead of hex |
| 187 | */ |
| 188 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 189 | /* dump the full path of a key */ |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 190 | static void dump_path( const struct key *key, const struct key *base, FILE *f ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 191 | { |
Alexandre Julliard | 6c8d917 | 2000-08-26 04:40:07 +0000 | [diff] [blame] | 192 | if (key->parent && key->parent != base) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 193 | { |
Juergen Schmied | 5d0ae2d | 2000-01-09 21:07:01 +0000 | [diff] [blame] | 194 | dump_path( key->parent, base, f ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 195 | fprintf( f, "\\\\" ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 196 | } |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 197 | dump_strW( key->name, key->namelen / sizeof(WCHAR), f, "[]" ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /* dump a value to a text file */ |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 201 | static void dump_value( const struct key_value *value, FILE *f ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 202 | { |
Alexandre Julliard | b647ded | 2008-01-07 21:06:49 +0100 | [diff] [blame] | 203 | unsigned int i, dw; |
Hans Leidekker | 719a789 | 2004-09-22 02:46:38 +0000 | [diff] [blame] | 204 | int count; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 205 | |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 206 | if (value->namelen) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 207 | { |
| 208 | fputc( '\"', f ); |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 209 | count = 1 + dump_strW( value->name, value->namelen / sizeof(WCHAR), f, "\"\"" ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 210 | count += fprintf( f, "\"=" ); |
| 211 | } |
| 212 | else count = fprintf( f, "@=" ); |
| 213 | |
| 214 | switch(value->type) |
| 215 | { |
| 216 | case REG_SZ: |
| 217 | case REG_EXPAND_SZ: |
| 218 | case REG_MULTI_SZ: |
Alexandre Julliard | b647ded | 2008-01-07 21:06:49 +0100 | [diff] [blame] | 219 | /* only output properly terminated strings in string format */ |
| 220 | if (value->len < sizeof(WCHAR)) break; |
| 221 | if (value->len % sizeof(WCHAR)) break; |
| 222 | if (((WCHAR *)value->data)[value->len / sizeof(WCHAR) - 1]) break; |
| 223 | if (value->type != REG_SZ) fprintf( f, "str(%x):", value->type ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 224 | fputc( '\"', f ); |
Marcus Meissner | 368d935 | 2008-01-09 22:56:06 +0100 | [diff] [blame] | 225 | dump_strW( (WCHAR *)value->data, value->len / sizeof(WCHAR), f, "\"\"" ); |
Alexandre Julliard | b647ded | 2008-01-07 21:06:49 +0100 | [diff] [blame] | 226 | fprintf( f, "\"\n" ); |
| 227 | return; |
| 228 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 229 | case REG_DWORD: |
Alexandre Julliard | b647ded | 2008-01-07 21:06:49 +0100 | [diff] [blame] | 230 | if (value->len != sizeof(dw)) break; |
| 231 | memcpy( &dw, value->data, sizeof(dw) ); |
| 232 | fprintf( f, "dword:%08x\n", dw ); |
| 233 | return; |
| 234 | } |
| 235 | |
| 236 | if (value->type == REG_BINARY) count += fprintf( f, "hex:" ); |
| 237 | else count += fprintf( f, "hex(%x):", value->type ); |
| 238 | for (i = 0; i < value->len; i++) |
| 239 | { |
| 240 | count += fprintf( f, "%02x", *((unsigned char *)value->data + i) ); |
| 241 | if (i < value->len-1) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 242 | { |
Alexandre Julliard | b647ded | 2008-01-07 21:06:49 +0100 | [diff] [blame] | 243 | fputc( ',', f ); |
| 244 | if (++count > 76) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 245 | { |
Alexandre Julliard | b647ded | 2008-01-07 21:06:49 +0100 | [diff] [blame] | 246 | fprintf( f, "\\\n " ); |
| 247 | count = 2; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 248 | } |
| 249 | } |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 250 | } |
| 251 | fputc( '\n', f ); |
| 252 | } |
| 253 | |
| 254 | /* save a registry and all its subkeys to a text file */ |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 255 | static void save_subkeys( const struct key *key, const struct key *base, FILE *f ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 256 | { |
| 257 | int i; |
| 258 | |
| 259 | if (key->flags & KEY_VOLATILE) return; |
Alexandre Julliard | 2a37867 | 2010-02-16 12:26:15 +0100 | [diff] [blame] | 260 | /* save key if it has either some values or no subkeys, or needs special options */ |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 261 | /* keys with no values but subkeys are saved implicitly by saving the subkeys */ |
Alexandre Julliard | b5d4289 | 2010-02-16 12:26:44 +0100 | [diff] [blame] | 262 | if ((key->last_value >= 0) || (key->last_subkey == -1) || key->class || (key->flags & KEY_SYMLINK)) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 263 | { |
| 264 | fprintf( f, "\n[" ); |
Alexandre Julliard | 6c8d917 | 2000-08-26 04:40:07 +0000 | [diff] [blame] | 265 | if (key != base) dump_path( key, base, f ); |
Alexandre Julliard | 3343c40 | 2008-12-06 17:29:01 +0100 | [diff] [blame] | 266 | fprintf( f, "] %u\n", (unsigned int)((key->modif - ticks_1601_to_1970) / TICKS_PER_SEC) ); |
Alexandre Julliard | 2a37867 | 2010-02-16 12:26:15 +0100 | [diff] [blame] | 267 | if (key->class) |
| 268 | { |
| 269 | fprintf( f, "#class=\"" ); |
| 270 | dump_strW( key->class, key->classlen / sizeof(WCHAR), f, "\"\"" ); |
| 271 | fprintf( f, "\"\n" ); |
| 272 | } |
Alexandre Julliard | b5d4289 | 2010-02-16 12:26:44 +0100 | [diff] [blame] | 273 | if (key->flags & KEY_SYMLINK) fputs( "#link\n", f ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 274 | for (i = 0; i <= key->last_value; i++) dump_value( &key->values[i], f ); |
| 275 | } |
Juergen Schmied | 5d0ae2d | 2000-01-09 21:07:01 +0000 | [diff] [blame] | 276 | for (i = 0; i <= key->last_subkey; i++) save_subkeys( key->subkeys[i], base, f ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 279 | static void dump_operation( const struct key *key, const struct key_value *value, const char *op ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 280 | { |
| 281 | fprintf( stderr, "%s key ", op ); |
Juergen Schmied | 5d0ae2d | 2000-01-09 21:07:01 +0000 | [diff] [blame] | 282 | if (key) dump_path( key, NULL, stderr ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 283 | else fprintf( stderr, "ERROR" ); |
| 284 | if (value) |
| 285 | { |
| 286 | fprintf( stderr, " value "); |
| 287 | dump_value( value, stderr ); |
| 288 | } |
| 289 | else fprintf( stderr, "\n" ); |
| 290 | } |
| 291 | |
| 292 | static void key_dump( struct object *obj, int verbose ) |
| 293 | { |
| 294 | struct key *key = (struct key *)obj; |
| 295 | assert( obj->ops == &key_ops ); |
| 296 | fprintf( stderr, "Key flags=%x ", key->flags ); |
Juergen Schmied | 5d0ae2d | 2000-01-09 21:07:01 +0000 | [diff] [blame] | 297 | dump_path( key, NULL, stderr ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 298 | fprintf( stderr, "\n" ); |
| 299 | } |
| 300 | |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 301 | /* notify waiter and maybe delete the notification */ |
| 302 | static void do_notification( struct key *key, struct notify *notify, int del ) |
| 303 | { |
Robert Shearman | 3795709 | 2005-06-10 19:54:46 +0000 | [diff] [blame] | 304 | if (notify->event) |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 305 | { |
| 306 | set_event( notify->event ); |
| 307 | release_object( notify->event ); |
| 308 | notify->event = NULL; |
| 309 | } |
Alexandre Julliard | 68abbc8 | 2005-02-24 19:43:53 +0000 | [diff] [blame] | 310 | if (del) |
| 311 | { |
| 312 | list_remove( ¬ify->entry ); |
| 313 | free( notify ); |
| 314 | } |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Alexandre Julliard | 9b3b7ca | 2005-06-09 20:36:08 +0000 | [diff] [blame] | 317 | static inline struct notify *find_notify( struct key *key, struct process *process, obj_handle_t hkey ) |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 318 | { |
Alexandre Julliard | 68abbc8 | 2005-02-24 19:43:53 +0000 | [diff] [blame] | 319 | struct notify *notify; |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 320 | |
Alexandre Julliard | 68abbc8 | 2005-02-24 19:43:53 +0000 | [diff] [blame] | 321 | LIST_FOR_EACH_ENTRY( notify, &key->notify_list, struct notify, entry ) |
| 322 | { |
Alexandre Julliard | 9b3b7ca | 2005-06-09 20:36:08 +0000 | [diff] [blame] | 323 | if (notify->process == process && notify->hkey == hkey) return notify; |
Alexandre Julliard | 68abbc8 | 2005-02-24 19:43:53 +0000 | [diff] [blame] | 324 | } |
| 325 | return NULL; |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Alexandre Julliard | 32a9396 | 2005-12-12 15:02:26 +0100 | [diff] [blame] | 328 | static unsigned int key_map_access( struct object *obj, unsigned int access ) |
| 329 | { |
| 330 | if (access & GENERIC_READ) access |= KEY_READ; |
| 331 | if (access & GENERIC_WRITE) access |= KEY_WRITE; |
| 332 | if (access & GENERIC_EXECUTE) access |= KEY_EXECUTE; |
| 333 | if (access & GENERIC_ALL) access |= KEY_ALL_ACCESS; |
| 334 | return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL); |
| 335 | } |
| 336 | |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 337 | /* close the notification associated with a handle */ |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 338 | static int key_close_handle( struct object *obj, struct process *process, obj_handle_t handle ) |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 339 | { |
| 340 | struct key * key = (struct key *) obj; |
Alexandre Julliard | 9b3b7ca | 2005-06-09 20:36:08 +0000 | [diff] [blame] | 341 | struct notify *notify = find_notify( key, process, handle ); |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 342 | if (notify) do_notification( key, notify, 1 ); |
| 343 | return 1; /* ok to close */ |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 346 | static void key_destroy( struct object *obj ) |
| 347 | { |
| 348 | int i; |
Alexandre Julliard | 68abbc8 | 2005-02-24 19:43:53 +0000 | [diff] [blame] | 349 | struct list *ptr; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 350 | struct key *key = (struct key *)obj; |
| 351 | assert( obj->ops == &key_ops ); |
| 352 | |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 353 | free( key->name ); |
| 354 | free( key->class ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 355 | for (i = 0; i <= key->last_value; i++) |
| 356 | { |
Lionel Debroux | e122f81 | 2007-10-20 09:37:43 +0200 | [diff] [blame] | 357 | free( key->values[i].name ); |
| 358 | free( key->values[i].data ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 359 | } |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 360 | free( key->values ); |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 361 | for (i = 0; i <= key->last_subkey; i++) |
| 362 | { |
| 363 | key->subkeys[i]->parent = NULL; |
| 364 | release_object( key->subkeys[i] ); |
| 365 | } |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 366 | free( key->subkeys ); |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 367 | /* unconditionally notify everything waiting on this key */ |
Alexandre Julliard | 68abbc8 | 2005-02-24 19:43:53 +0000 | [diff] [blame] | 368 | while ((ptr = list_head( &key->notify_list ))) |
| 369 | { |
| 370 | struct notify *notify = LIST_ENTRY( ptr, struct notify, entry ); |
| 371 | do_notification( key, notify, 1 ); |
| 372 | } |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 375 | /* get the request vararg as registry path */ |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 376 | static inline void get_req_path( struct unicode_str *str, int skip_root ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 377 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 378 | str->str = get_req_data(); |
| 379 | str->len = (get_req_data_size() / sizeof(WCHAR)) * sizeof(WCHAR); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 380 | |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 381 | if (skip_root && str->len >= sizeof(root_name) && |
| 382 | !memicmpW( str->str, root_name, sizeof(root_name)/sizeof(WCHAR) )) |
Alexandre Julliard | bcf393a | 2000-10-01 01:44:50 +0000 | [diff] [blame] | 383 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 384 | str->str += sizeof(root_name)/sizeof(WCHAR); |
| 385 | str->len -= sizeof(root_name); |
Alexandre Julliard | bcf393a | 2000-10-01 01:44:50 +0000 | [diff] [blame] | 386 | } |
Alexandre Julliard | bcf393a | 2000-10-01 01:44:50 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 389 | /* return the next token in a given path */ |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 390 | /* token->str must point inside the path, or be NULL for the first call */ |
| 391 | static struct unicode_str *get_path_token( const struct unicode_str *path, struct unicode_str *token ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 392 | { |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 393 | data_size_t i = 0, len = path->len / sizeof(WCHAR); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 394 | |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 395 | if (!token->str) /* first time */ |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 396 | { |
Alexandre Julliard | bcf393a | 2000-10-01 01:44:50 +0000 | [diff] [blame] | 397 | /* path cannot start with a backslash */ |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 398 | if (len && path->str[0] == '\\') |
Alexandre Julliard | bcf393a | 2000-10-01 01:44:50 +0000 | [diff] [blame] | 399 | { |
| 400 | set_error( STATUS_OBJECT_PATH_INVALID ); |
| 401 | return NULL; |
| 402 | } |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 403 | } |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 404 | else |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 405 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 406 | i = token->str - path->str; |
| 407 | i += token->len / sizeof(WCHAR); |
| 408 | while (i < len && path->str[i] == '\\') i++; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 409 | } |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 410 | token->str = path->str + i; |
| 411 | while (i < len && path->str[i] != '\\') i++; |
| 412 | token->len = (path->str + i - token->str) * sizeof(WCHAR); |
| 413 | return token; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | /* allocate a key object */ |
Alexandre Julliard | 3343c40 | 2008-12-06 17:29:01 +0100 | [diff] [blame] | 417 | static struct key *alloc_key( const struct unicode_str *name, timeout_t modif ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 418 | { |
| 419 | struct key *key; |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 420 | if ((key = alloc_object( &key_ops ))) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 421 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 422 | key->name = NULL; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 423 | key->class = NULL; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 424 | key->namelen = name->len; |
| 425 | key->classlen = 0; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 426 | key->flags = 0; |
| 427 | key->last_subkey = -1; |
| 428 | key->nb_subkeys = 0; |
| 429 | key->subkeys = NULL; |
| 430 | key->nb_values = 0; |
| 431 | key->last_value = -1; |
| 432 | key->values = NULL; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 433 | key->modif = modif; |
| 434 | key->parent = NULL; |
Alexandre Julliard | 68abbc8 | 2005-02-24 19:43:53 +0000 | [diff] [blame] | 435 | list_init( &key->notify_list ); |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 436 | if (name->len && !(key->name = memdup( name->str, name->len ))) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 437 | { |
| 438 | release_object( key ); |
| 439 | key = NULL; |
| 440 | } |
| 441 | } |
| 442 | return key; |
| 443 | } |
| 444 | |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 445 | /* mark a key and all its parents as dirty (modified) */ |
| 446 | static void make_dirty( struct key *key ) |
| 447 | { |
| 448 | while (key) |
| 449 | { |
| 450 | if (key->flags & (KEY_DIRTY|KEY_VOLATILE)) return; /* nothing to do */ |
| 451 | key->flags |= KEY_DIRTY; |
| 452 | key = key->parent; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | /* mark a key and all its subkeys as clean (not modified) */ |
| 457 | static void make_clean( struct key *key ) |
| 458 | { |
| 459 | int i; |
| 460 | |
| 461 | if (key->flags & KEY_VOLATILE) return; |
| 462 | if (!(key->flags & KEY_DIRTY)) return; |
| 463 | key->flags &= ~KEY_DIRTY; |
| 464 | for (i = 0; i <= key->last_subkey; i++) make_clean( key->subkeys[i] ); |
| 465 | } |
| 466 | |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 467 | /* go through all the notifications and send them if necessary */ |
Robert Shearman | c516571 | 2005-05-25 18:41:09 +0000 | [diff] [blame] | 468 | static void check_notify( struct key *key, unsigned int change, int not_subtree ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 469 | { |
Alexandre Julliard | 68abbc8 | 2005-02-24 19:43:53 +0000 | [diff] [blame] | 470 | struct list *ptr, *next; |
| 471 | |
| 472 | LIST_FOR_EACH_SAFE( ptr, next, &key->notify_list ) |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 473 | { |
Alexandre Julliard | 68abbc8 | 2005-02-24 19:43:53 +0000 | [diff] [blame] | 474 | struct notify *n = LIST_ENTRY( ptr, struct notify, entry ); |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 475 | if ( ( not_subtree || n->subtree ) && ( change & n->filter ) ) |
| 476 | do_notification( key, n, 0 ); |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | |
| 480 | /* update key modification time */ |
| 481 | static void touch_key( struct key *key, unsigned int change ) |
| 482 | { |
| 483 | struct key *k; |
| 484 | |
Alexandre Julliard | 3343c40 | 2008-12-06 17:29:01 +0100 | [diff] [blame] | 485 | key->modif = current_time; |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 486 | make_dirty( key ); |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 487 | |
| 488 | /* do notifications */ |
| 489 | check_notify( key, change, 1 ); |
| 490 | for ( k = key->parent; k; k = k->parent ) |
| 491 | check_notify( k, change & ~REG_NOTIFY_CHANGE_LAST_SET, 0 ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /* try to grow the array of subkeys; return 1 if OK, 0 on error */ |
| 495 | static int grow_subkeys( struct key *key ) |
| 496 | { |
| 497 | struct key **new_subkeys; |
| 498 | int nb_subkeys; |
| 499 | |
| 500 | if (key->nb_subkeys) |
| 501 | { |
| 502 | nb_subkeys = key->nb_subkeys + (key->nb_subkeys / 2); /* grow by 50% */ |
| 503 | if (!(new_subkeys = realloc( key->subkeys, nb_subkeys * sizeof(*new_subkeys) ))) |
| 504 | { |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 505 | set_error( STATUS_NO_MEMORY ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 506 | return 0; |
| 507 | } |
| 508 | } |
| 509 | else |
| 510 | { |
| 511 | nb_subkeys = MIN_VALUES; |
| 512 | if (!(new_subkeys = mem_alloc( nb_subkeys * sizeof(*new_subkeys) ))) return 0; |
| 513 | } |
| 514 | key->subkeys = new_subkeys; |
| 515 | key->nb_subkeys = nb_subkeys; |
| 516 | return 1; |
| 517 | } |
| 518 | |
| 519 | /* allocate a subkey for a given key, and return its index */ |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 520 | static struct key *alloc_subkey( struct key *parent, const struct unicode_str *name, |
Alexandre Julliard | 3343c40 | 2008-12-06 17:29:01 +0100 | [diff] [blame] | 521 | int index, timeout_t modif ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 522 | { |
| 523 | struct key *key; |
| 524 | int i; |
| 525 | |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 526 | if (name->len > MAX_NAME_LEN * sizeof(WCHAR)) |
| 527 | { |
| 528 | set_error( STATUS_NAME_TOO_LONG ); |
| 529 | return NULL; |
| 530 | } |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 531 | if (parent->last_subkey + 1 == parent->nb_subkeys) |
| 532 | { |
| 533 | /* need to grow the array */ |
| 534 | if (!grow_subkeys( parent )) return NULL; |
| 535 | } |
| 536 | if ((key = alloc_key( name, modif )) != NULL) |
| 537 | { |
| 538 | key->parent = parent; |
| 539 | for (i = ++parent->last_subkey; i > index; i--) |
| 540 | parent->subkeys[i] = parent->subkeys[i-1]; |
| 541 | parent->subkeys[index] = key; |
Alexandre Julliard | 0ea2806 | 2010-04-01 14:09:12 +0200 | [diff] [blame] | 542 | if (is_wow6432node( key->name, key->namelen ) && !is_wow6432node( parent->name, parent->namelen )) |
| 543 | parent->flags |= KEY_WOW64; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 544 | } |
| 545 | return key; |
| 546 | } |
| 547 | |
| 548 | /* free a subkey of a given key */ |
| 549 | static void free_subkey( struct key *parent, int index ) |
| 550 | { |
| 551 | struct key *key; |
| 552 | int i, nb_subkeys; |
| 553 | |
| 554 | assert( index >= 0 ); |
| 555 | assert( index <= parent->last_subkey ); |
| 556 | |
| 557 | key = parent->subkeys[index]; |
| 558 | for (i = index; i < parent->last_subkey; i++) parent->subkeys[i] = parent->subkeys[i + 1]; |
| 559 | parent->last_subkey--; |
| 560 | key->flags |= KEY_DELETED; |
| 561 | key->parent = NULL; |
Alexandre Julliard | ac08b03 | 2010-03-02 12:03:17 +0100 | [diff] [blame] | 562 | if (is_wow6432node( key->name, key->namelen )) parent->flags &= ~KEY_WOW64; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 563 | release_object( key ); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 564 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 565 | /* try to shrink the array */ |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 566 | nb_subkeys = parent->nb_subkeys; |
| 567 | if (nb_subkeys > MIN_SUBKEYS && parent->last_subkey < nb_subkeys / 2) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 568 | { |
| 569 | struct key **new_subkeys; |
| 570 | nb_subkeys -= nb_subkeys / 3; /* shrink by 33% */ |
| 571 | if (nb_subkeys < MIN_SUBKEYS) nb_subkeys = MIN_SUBKEYS; |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 572 | if (!(new_subkeys = realloc( parent->subkeys, nb_subkeys * sizeof(*new_subkeys) ))) return; |
| 573 | parent->subkeys = new_subkeys; |
| 574 | parent->nb_subkeys = nb_subkeys; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 575 | } |
| 576 | } |
| 577 | |
| 578 | /* find the named child of a given key and return its index */ |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 579 | static struct key *find_subkey( const struct key *key, const struct unicode_str *name, int *index ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 580 | { |
| 581 | int i, min, max, res; |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 582 | data_size_t len; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 583 | |
| 584 | min = 0; |
| 585 | max = key->last_subkey; |
| 586 | while (min <= max) |
| 587 | { |
| 588 | i = (min + max) / 2; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 589 | len = min( key->subkeys[i]->namelen, name->len ); |
| 590 | res = memicmpW( key->subkeys[i]->name, name->str, len / sizeof(WCHAR) ); |
| 591 | if (!res) res = key->subkeys[i]->namelen - name->len; |
| 592 | if (!res) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 593 | { |
| 594 | *index = i; |
| 595 | return key->subkeys[i]; |
| 596 | } |
| 597 | if (res > 0) max = i - 1; |
| 598 | else min = i + 1; |
| 599 | } |
| 600 | *index = min; /* this is where we should insert it */ |
| 601 | return NULL; |
| 602 | } |
| 603 | |
Alexandre Julliard | ac08b03 | 2010-03-02 12:03:17 +0100 | [diff] [blame] | 604 | /* return the wow64 variant of the key, or the key itself if none */ |
| 605 | static struct key *find_wow64_subkey( struct key *key, const struct unicode_str *name ) |
| 606 | { |
| 607 | static const struct unicode_str wow6432node_str = { wow6432node, sizeof(wow6432node) }; |
| 608 | int index; |
| 609 | |
| 610 | if (!(key->flags & KEY_WOW64)) return key; |
| 611 | if (!is_wow6432node( name->str, name->len )) |
| 612 | { |
| 613 | key = find_subkey( key, &wow6432node_str, &index ); |
| 614 | assert( key ); /* if KEY_WOW64 is set we must find it */ |
| 615 | } |
| 616 | return key; |
| 617 | } |
| 618 | |
| 619 | |
Alexandre Julliard | b139b93 | 2010-02-15 21:04:26 +0100 | [diff] [blame] | 620 | /* follow a symlink and return the resolved key */ |
| 621 | static struct key *follow_symlink( struct key *key, int iteration ) |
| 622 | { |
| 623 | struct unicode_str path, token; |
| 624 | struct key_value *value; |
| 625 | int index; |
| 626 | |
| 627 | if (iteration > 16) return NULL; |
| 628 | if (!(key->flags & KEY_SYMLINK)) return key; |
| 629 | if (!(value = find_value( key, &symlink_str, &index ))) return NULL; |
| 630 | |
| 631 | path.str = value->data; |
| 632 | path.len = (value->len / sizeof(WCHAR)) * sizeof(WCHAR); |
| 633 | if (path.len <= sizeof(root_name)) return NULL; |
| 634 | if (memicmpW( path.str, root_name, sizeof(root_name)/sizeof(WCHAR) )) return NULL; |
| 635 | path.str += sizeof(root_name) / sizeof(WCHAR); |
| 636 | path.len -= sizeof(root_name); |
| 637 | |
| 638 | key = root_key; |
| 639 | token.str = NULL; |
| 640 | if (!get_path_token( &path, &token )) return NULL; |
| 641 | while (token.len) |
| 642 | { |
| 643 | if (!(key = find_subkey( key, &token, &index ))) break; |
| 644 | if (!(key = follow_symlink( key, iteration + 1 ))) break; |
| 645 | get_path_token( &path, &token ); |
| 646 | } |
| 647 | return key; |
| 648 | } |
| 649 | |
Alexandre Julliard | 606cc06 | 2010-03-04 20:46:42 +0100 | [diff] [blame] | 650 | /* open a key until we find an element that doesn't exist */ |
| 651 | /* helper for open_key and create_key */ |
| 652 | static struct key *open_key_prefix( struct key *key, const struct unicode_str *name, |
| 653 | unsigned int access, struct unicode_str *token, int *index ) |
| 654 | { |
| 655 | token->str = NULL; |
| 656 | if (!get_path_token( name, token )) return NULL; |
| 657 | if (access & KEY_WOW64_32KEY) key = find_wow64_subkey( key, token ); |
| 658 | while (token->len) |
| 659 | { |
| 660 | struct key *subkey; |
Alexandre Julliard | 178cd20 | 2010-03-04 20:47:35 +0100 | [diff] [blame] | 661 | if (!(subkey = find_subkey( key, token, index ))) |
| 662 | { |
| 663 | if ((key->flags & KEY_WOWSHARE) && !(access & KEY_WOW64_64KEY)) |
| 664 | { |
| 665 | /* try in the 64-bit parent */ |
| 666 | key = key->parent; |
| 667 | subkey = find_subkey( key, token, index ); |
| 668 | } |
| 669 | } |
| 670 | if (!subkey) break; |
Alexandre Julliard | 606cc06 | 2010-03-04 20:46:42 +0100 | [diff] [blame] | 671 | key = subkey; |
| 672 | get_path_token( name, token ); |
| 673 | if (!token->len) break; |
| 674 | if (!(access & KEY_WOW64_64KEY)) key = find_wow64_subkey( key, token ); |
| 675 | if (!(key = follow_symlink( key, 0 ))) |
| 676 | { |
| 677 | set_error( STATUS_OBJECT_NAME_NOT_FOUND ); |
| 678 | return NULL; |
| 679 | } |
| 680 | } |
| 681 | return key; |
| 682 | } |
| 683 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 684 | /* open a subkey */ |
Alexandre Julliard | ac08b03 | 2010-03-02 12:03:17 +0100 | [diff] [blame] | 685 | static struct key *open_key( struct key *key, const struct unicode_str *name, unsigned int access, |
| 686 | unsigned int attributes ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 687 | { |
| 688 | int index; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 689 | struct unicode_str token; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 690 | |
Alexandre Julliard | 606cc06 | 2010-03-04 20:46:42 +0100 | [diff] [blame] | 691 | if (!(key = open_key_prefix( key, name, access, &token, &index ))) return NULL; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 692 | |
Alexandre Julliard | 606cc06 | 2010-03-04 20:46:42 +0100 | [diff] [blame] | 693 | if (token.len) |
| 694 | { |
| 695 | set_error( STATUS_OBJECT_NAME_NOT_FOUND ); |
| 696 | return NULL; |
| 697 | } |
Alexandre Julliard | ac08b03 | 2010-03-02 12:03:17 +0100 | [diff] [blame] | 698 | if (!(access & KEY_WOW64_64KEY)) key = find_wow64_subkey( key, &token ); |
Alexandre Julliard | b139b93 | 2010-02-15 21:04:26 +0100 | [diff] [blame] | 699 | if (!(attributes & OBJ_OPENLINK) && !(key = follow_symlink( key, 0 ))) |
| 700 | { |
| 701 | set_error( STATUS_OBJECT_NAME_NOT_FOUND ); |
| 702 | return NULL; |
| 703 | } |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 704 | if (debug_level > 1) dump_operation( key, NULL, "Open" ); |
Alexandre Julliard | b139b93 | 2010-02-15 21:04:26 +0100 | [diff] [blame] | 705 | grab_object( key ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 706 | return key; |
| 707 | } |
| 708 | |
| 709 | /* create a subkey */ |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 710 | static struct key *create_key( struct key *key, const struct unicode_str *name, |
Alexandre Julliard | 22de1f4 | 2010-03-01 14:13:46 +0100 | [diff] [blame] | 711 | const struct unicode_str *class, unsigned int options, |
Alexandre Julliard | ac08b03 | 2010-03-02 12:03:17 +0100 | [diff] [blame] | 712 | unsigned int access, unsigned int attributes, int *created ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 713 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 714 | int index; |
Alexandre Julliard | 8eca1da | 2010-03-01 14:14:50 +0100 | [diff] [blame] | 715 | struct unicode_str token, next; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 716 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 717 | *created = 0; |
Alexandre Julliard | 606cc06 | 2010-03-04 20:46:42 +0100 | [diff] [blame] | 718 | if (!(key = open_key_prefix( key, name, access, &token, &index ))) return NULL; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 719 | |
Alexandre Julliard | 8eca1da | 2010-03-01 14:14:50 +0100 | [diff] [blame] | 720 | if (!token.len) /* the key already exists */ |
Alexandre Julliard | b139b93 | 2010-02-15 21:04:26 +0100 | [diff] [blame] | 721 | { |
Alexandre Julliard | ac08b03 | 2010-03-02 12:03:17 +0100 | [diff] [blame] | 722 | if (!(access & KEY_WOW64_64KEY)) key = find_wow64_subkey( key, &token ); |
Alexandre Julliard | b139b93 | 2010-02-15 21:04:26 +0100 | [diff] [blame] | 723 | if (options & REG_OPTION_CREATE_LINK) |
| 724 | { |
| 725 | set_error( STATUS_OBJECT_NAME_COLLISION ); |
| 726 | return NULL; |
| 727 | } |
| 728 | if (!(attributes & OBJ_OPENLINK) && !(key = follow_symlink( key, 0 ))) |
| 729 | { |
| 730 | set_error( STATUS_OBJECT_NAME_NOT_FOUND ); |
| 731 | return NULL; |
| 732 | } |
Alexandre Julliard | 8eca1da | 2010-03-01 14:14:50 +0100 | [diff] [blame] | 733 | if (debug_level > 1) dump_operation( key, NULL, "Open" ); |
| 734 | grab_object( key ); |
| 735 | return key; |
Alexandre Julliard | b139b93 | 2010-02-15 21:04:26 +0100 | [diff] [blame] | 736 | } |
Alexandre Julliard | 8eca1da | 2010-03-01 14:14:50 +0100 | [diff] [blame] | 737 | |
| 738 | /* token must be the last path component at this point */ |
| 739 | next = token; |
| 740 | get_path_token( name, &next ); |
| 741 | if (next.len) |
| 742 | { |
| 743 | set_error( STATUS_OBJECT_NAME_NOT_FOUND ); |
| 744 | return NULL; |
| 745 | } |
| 746 | |
Alexandre Julliard | 22de1f4 | 2010-03-01 14:13:46 +0100 | [diff] [blame] | 747 | if ((key->flags & KEY_VOLATILE) && !(options & REG_OPTION_VOLATILE)) |
Alexandre Julliard | 72ba00f | 2009-11-20 11:39:55 +0100 | [diff] [blame] | 748 | { |
| 749 | set_error( STATUS_CHILD_MUST_BE_VOLATILE ); |
| 750 | return NULL; |
| 751 | } |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 752 | *created = 1; |
Alexandre Julliard | 22de1f4 | 2010-03-01 14:13:46 +0100 | [diff] [blame] | 753 | make_dirty( key ); |
| 754 | if (!(key = alloc_subkey( key, &token, index, current_time ))) return NULL; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 755 | |
Alexandre Julliard | 8eca1da | 2010-03-01 14:14:50 +0100 | [diff] [blame] | 756 | if (options & REG_OPTION_CREATE_LINK) key->flags |= KEY_SYMLINK; |
| 757 | if (options & REG_OPTION_VOLATILE) key->flags |= KEY_VOLATILE; |
| 758 | else key->flags |= KEY_DIRTY; |
| 759 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 760 | if (debug_level > 1) dump_operation( key, NULL, "Create" ); |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 761 | if (class && class->len) |
| 762 | { |
| 763 | key->classlen = class->len; |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 764 | free(key->class); |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 765 | if (!(key->class = memdup( class->str, key->classlen ))) key->classlen = 0; |
| 766 | } |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 767 | grab_object( key ); |
| 768 | return key; |
| 769 | } |
| 770 | |
Alexandre Julliard | 22de1f4 | 2010-03-01 14:13:46 +0100 | [diff] [blame] | 771 | /* recursively create a subkey (for internal use only) */ |
| 772 | static struct key *create_key_recursive( struct key *key, const struct unicode_str *name, timeout_t modif ) |
| 773 | { |
| 774 | struct key *base; |
| 775 | int index; |
| 776 | struct unicode_str token; |
| 777 | |
| 778 | token.str = NULL; |
| 779 | if (!get_path_token( name, &token )) return NULL; |
| 780 | while (token.len) |
| 781 | { |
| 782 | struct key *subkey; |
| 783 | if (!(subkey = find_subkey( key, &token, &index ))) break; |
| 784 | key = subkey; |
| 785 | if (!(key = follow_symlink( key, 0 ))) |
| 786 | { |
| 787 | set_error( STATUS_OBJECT_NAME_NOT_FOUND ); |
| 788 | return NULL; |
| 789 | } |
| 790 | get_path_token( name, &token ); |
| 791 | } |
| 792 | |
| 793 | if (token.len) |
| 794 | { |
| 795 | if (!(key = alloc_subkey( key, &token, index, modif ))) return NULL; |
| 796 | base = key; |
| 797 | for (;;) |
| 798 | { |
| 799 | get_path_token( name, &token ); |
| 800 | if (!token.len) break; |
| 801 | /* we know the index is always 0 in a new key */ |
| 802 | if (!(key = alloc_subkey( key, &token, 0, modif ))) |
| 803 | { |
| 804 | free_subkey( base, index ); |
| 805 | return NULL; |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | grab_object( key ); |
| 811 | return key; |
| 812 | } |
| 813 | |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 814 | /* query information about a key or a subkey */ |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 815 | static void enum_key( const struct key *key, int index, int info_class, |
| 816 | struct enum_key_reply *reply ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 817 | { |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 818 | int i; |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 819 | data_size_t len, namelen, classlen; |
Michael Stefaniuc | a624977 | 2006-07-25 10:30:04 +0200 | [diff] [blame] | 820 | data_size_t max_subkey = 0, max_class = 0; |
| 821 | data_size_t max_value = 0, max_data = 0; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 822 | char *data; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 823 | |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 824 | if (index != -1) /* -1 means use the specified key directly */ |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 825 | { |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 826 | if ((index < 0) || (index > key->last_subkey)) |
| 827 | { |
| 828 | set_error( STATUS_NO_MORE_ENTRIES ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 829 | return; |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 830 | } |
| 831 | key = key->subkeys[index]; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 832 | } |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 833 | |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 834 | namelen = key->namelen; |
| 835 | classlen = key->classlen; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 836 | |
| 837 | switch(info_class) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 838 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 839 | case KeyBasicInformation: |
| 840 | classlen = 0; /* only return the name */ |
| 841 | /* fall through */ |
| 842 | case KeyNodeInformation: |
| 843 | reply->max_subkey = 0; |
| 844 | reply->max_class = 0; |
| 845 | reply->max_value = 0; |
| 846 | reply->max_data = 0; |
| 847 | break; |
| 848 | case KeyFullInformation: |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 849 | for (i = 0; i <= key->last_subkey; i++) |
| 850 | { |
| 851 | struct key *subkey = key->subkeys[i]; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 852 | len = subkey->namelen / sizeof(WCHAR); |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 853 | if (len > max_subkey) max_subkey = len; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 854 | len = subkey->classlen / sizeof(WCHAR); |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 855 | if (len > max_class) max_class = len; |
| 856 | } |
| 857 | for (i = 0; i <= key->last_value; i++) |
| 858 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 859 | len = key->values[i].namelen / sizeof(WCHAR); |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 860 | if (len > max_value) max_value = len; |
| 861 | len = key->values[i].len; |
| 862 | if (len > max_data) max_data = len; |
| 863 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 864 | reply->max_subkey = max_subkey; |
| 865 | reply->max_class = max_class; |
| 866 | reply->max_value = max_value; |
| 867 | reply->max_data = max_data; |
| 868 | namelen = 0; /* only return the class */ |
| 869 | break; |
| 870 | default: |
| 871 | set_error( STATUS_INVALID_PARAMETER ); |
| 872 | return; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 873 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 874 | reply->subkeys = key->last_subkey + 1; |
| 875 | reply->values = key->last_value + 1; |
| 876 | reply->modif = key->modif; |
| 877 | reply->total = namelen + classlen; |
| 878 | |
| 879 | len = min( reply->total, get_reply_max_size() ); |
| 880 | if (len && (data = set_reply_data_size( len ))) |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 881 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 882 | if (len > namelen) |
| 883 | { |
| 884 | reply->namelen = namelen; |
| 885 | memcpy( data, key->name, namelen ); |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 886 | memcpy( data + namelen, key->class, len - namelen ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 887 | } |
| 888 | else |
| 889 | { |
| 890 | reply->namelen = len; |
| 891 | memcpy( data, key->name, len ); |
| 892 | } |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 893 | } |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 894 | if (debug_level > 1) dump_operation( key, NULL, "Enum" ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | /* delete a key and its values */ |
Mike McCormack | 5ac945c | 2003-08-19 03:08:17 +0000 | [diff] [blame] | 898 | static int delete_key( struct key *key, int recurse ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 899 | { |
| 900 | int index; |
Alexandre Julliard | 6ebc627 | 2010-04-02 12:43:31 +0200 | [diff] [blame] | 901 | struct key *parent = key->parent; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 902 | |
Alexandre Julliard | bcf393a | 2000-10-01 01:44:50 +0000 | [diff] [blame] | 903 | /* must find parent and index */ |
Alexandre Julliard | 7e9757c | 2004-05-06 23:42:04 +0000 | [diff] [blame] | 904 | if (key == root_key) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 905 | { |
Alexandre Julliard | bcf393a | 2000-10-01 01:44:50 +0000 | [diff] [blame] | 906 | set_error( STATUS_ACCESS_DENIED ); |
Mike McCormack | 5ac945c | 2003-08-19 03:08:17 +0000 | [diff] [blame] | 907 | return -1; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 908 | } |
Alexandre Julliard | 6ebc627 | 2010-04-02 12:43:31 +0200 | [diff] [blame] | 909 | assert( parent ); |
Mike McCormack | 5ac945c | 2003-08-19 03:08:17 +0000 | [diff] [blame] | 910 | |
| 911 | while (recurse && (key->last_subkey>=0)) |
Robert Shearman | 3795709 | 2005-06-10 19:54:46 +0000 | [diff] [blame] | 912 | if (0 > delete_key(key->subkeys[key->last_subkey], 1)) |
Mike McCormack | 5ac945c | 2003-08-19 03:08:17 +0000 | [diff] [blame] | 913 | return -1; |
| 914 | |
Alexandre Julliard | bcf393a | 2000-10-01 01:44:50 +0000 | [diff] [blame] | 915 | for (index = 0; index <= parent->last_subkey; index++) |
| 916 | if (parent->subkeys[index] == key) break; |
| 917 | assert( index <= parent->last_subkey ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 918 | |
Alexandre Julliard | 7e9757c | 2004-05-06 23:42:04 +0000 | [diff] [blame] | 919 | /* we can only delete a key that has no subkeys */ |
| 920 | if (key->last_subkey >= 0) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 921 | { |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 922 | set_error( STATUS_ACCESS_DENIED ); |
Mike McCormack | 5ac945c | 2003-08-19 03:08:17 +0000 | [diff] [blame] | 923 | return -1; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 924 | } |
Mike McCormack | 5ac945c | 2003-08-19 03:08:17 +0000 | [diff] [blame] | 925 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 926 | if (debug_level > 1) dump_operation( key, NULL, "Delete" ); |
| 927 | free_subkey( parent, index ); |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 928 | touch_key( parent, REG_NOTIFY_CHANGE_NAME ); |
Mike McCormack | 5ac945c | 2003-08-19 03:08:17 +0000 | [diff] [blame] | 929 | return 0; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | /* try to grow the array of values; return 1 if OK, 0 on error */ |
| 933 | static int grow_values( struct key *key ) |
| 934 | { |
| 935 | struct key_value *new_val; |
| 936 | int nb_values; |
| 937 | |
| 938 | if (key->nb_values) |
| 939 | { |
| 940 | nb_values = key->nb_values + (key->nb_values / 2); /* grow by 50% */ |
| 941 | if (!(new_val = realloc( key->values, nb_values * sizeof(*new_val) ))) |
| 942 | { |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 943 | set_error( STATUS_NO_MEMORY ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 944 | return 0; |
| 945 | } |
| 946 | } |
| 947 | else |
| 948 | { |
| 949 | nb_values = MIN_VALUES; |
| 950 | if (!(new_val = mem_alloc( nb_values * sizeof(*new_val) ))) return 0; |
| 951 | } |
| 952 | key->values = new_val; |
| 953 | key->nb_values = nb_values; |
| 954 | return 1; |
| 955 | } |
| 956 | |
| 957 | /* find the named value of a given key and return its index in the array */ |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 958 | static struct key_value *find_value( const struct key *key, const struct unicode_str *name, int *index ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 959 | { |
| 960 | int i, min, max, res; |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 961 | data_size_t len; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 962 | |
| 963 | min = 0; |
| 964 | max = key->last_value; |
| 965 | while (min <= max) |
| 966 | { |
| 967 | i = (min + max) / 2; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 968 | len = min( key->values[i].namelen, name->len ); |
| 969 | res = memicmpW( key->values[i].name, name->str, len / sizeof(WCHAR) ); |
| 970 | if (!res) res = key->values[i].namelen - name->len; |
| 971 | if (!res) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 972 | { |
| 973 | *index = i; |
| 974 | return &key->values[i]; |
| 975 | } |
| 976 | if (res > 0) max = i - 1; |
| 977 | else min = i + 1; |
| 978 | } |
| 979 | *index = min; /* this is where we should insert it */ |
| 980 | return NULL; |
| 981 | } |
| 982 | |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 983 | /* insert a new value; the index must have been returned by find_value */ |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 984 | static struct key_value *insert_value( struct key *key, const struct unicode_str *name, int index ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 985 | { |
| 986 | struct key_value *value; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 987 | WCHAR *new_name = NULL; |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 988 | int i; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 989 | |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 990 | if (name->len > MAX_VALUE_LEN * sizeof(WCHAR)) |
| 991 | { |
| 992 | set_error( STATUS_NAME_TOO_LONG ); |
| 993 | return NULL; |
| 994 | } |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 995 | if (key->last_value + 1 == key->nb_values) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 996 | { |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 997 | if (!grow_values( key )) return NULL; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 998 | } |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 999 | if (name->len && !(new_name = memdup( name->str, name->len ))) return NULL; |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 1000 | for (i = ++key->last_value; i > index; i--) key->values[i] = key->values[i - 1]; |
| 1001 | value = &key->values[index]; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1002 | value->name = new_name; |
| 1003 | value->namelen = name->len; |
| 1004 | value->len = 0; |
| 1005 | value->data = NULL; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1006 | return value; |
| 1007 | } |
| 1008 | |
| 1009 | /* set a key value */ |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1010 | static void set_value( struct key *key, const struct unicode_str *name, |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1011 | int type, const void *data, data_size_t len ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1012 | { |
| 1013 | struct key_value *value; |
| 1014 | void *ptr = NULL; |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 1015 | int index; |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1016 | |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 1017 | if ((value = find_value( key, name, &index ))) |
| 1018 | { |
| 1019 | /* check if the new value is identical to the existing one */ |
| 1020 | if (value->type == type && value->len == len && |
| 1021 | value->data && !memcmp( value->data, data, len )) |
| 1022 | { |
| 1023 | if (debug_level > 1) dump_operation( key, value, "Skip setting" ); |
| 1024 | return; |
| 1025 | } |
| 1026 | } |
| 1027 | |
Alexandre Julliard | b139b93 | 2010-02-15 21:04:26 +0100 | [diff] [blame] | 1028 | if (key->flags & KEY_SYMLINK) |
| 1029 | { |
| 1030 | if (type != REG_LINK || name->len != symlink_str.len || |
| 1031 | memicmpW( name->str, symlink_str.str, name->len / sizeof(WCHAR) )) |
| 1032 | { |
| 1033 | set_error( STATUS_ACCESS_DENIED ); |
| 1034 | return; |
| 1035 | } |
| 1036 | } |
| 1037 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1038 | if (len && !(ptr = memdup( data, len ))) return; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1039 | |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 1040 | if (!value) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1041 | { |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 1042 | if (!(value = insert_value( key, name, index ))) |
| 1043 | { |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 1044 | free( ptr ); |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 1045 | return; |
| 1046 | } |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1047 | } |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 1048 | else free( value->data ); /* already existing, free previous data */ |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 1049 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1050 | value->type = type; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1051 | value->len = len; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1052 | value->data = ptr; |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 1053 | touch_key( key, REG_NOTIFY_CHANGE_LAST_SET ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1054 | if (debug_level > 1) dump_operation( key, value, "Set" ); |
| 1055 | } |
| 1056 | |
| 1057 | /* get a key value */ |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1058 | static void get_value( struct key *key, const struct unicode_str *name, int *type, data_size_t *len ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1059 | { |
| 1060 | struct key_value *value; |
| 1061 | int index; |
| 1062 | |
| 1063 | if ((value = find_value( key, name, &index ))) |
| 1064 | { |
| 1065 | *type = value->type; |
| 1066 | *len = value->len; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1067 | if (value->data) set_reply_data( value->data, min( value->len, get_reply_max_size() )); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1068 | if (debug_level > 1) dump_operation( key, value, "Get" ); |
| 1069 | } |
| 1070 | else |
| 1071 | { |
| 1072 | *type = -1; |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 1073 | set_error( STATUS_OBJECT_NAME_NOT_FOUND ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | /* enumerate a key value */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1078 | static void enum_value( struct key *key, int i, int info_class, struct enum_key_value_reply *reply ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1079 | { |
| 1080 | struct key_value *value; |
| 1081 | |
Alexandre Julliard | ef88637 | 2000-04-04 19:33:27 +0000 | [diff] [blame] | 1082 | if (i < 0 || i > key->last_value) set_error( STATUS_NO_MORE_ENTRIES ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1083 | else |
| 1084 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1085 | void *data; |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1086 | data_size_t namelen, maxlen; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1087 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1088 | value = &key->values[i]; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1089 | reply->type = value->type; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1090 | namelen = value->namelen; |
Alexandre Julliard | 0b6a79c | 2000-12-15 20:57:00 +0000 | [diff] [blame] | 1091 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1092 | switch(info_class) |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1093 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1094 | case KeyValueBasicInformation: |
| 1095 | reply->total = namelen; |
| 1096 | break; |
| 1097 | case KeyValueFullInformation: |
| 1098 | reply->total = namelen + value->len; |
| 1099 | break; |
| 1100 | case KeyValuePartialInformation: |
| 1101 | reply->total = value->len; |
| 1102 | namelen = 0; |
| 1103 | break; |
| 1104 | default: |
| 1105 | set_error( STATUS_INVALID_PARAMETER ); |
| 1106 | return; |
| 1107 | } |
Alexandre Julliard | 0b6a79c | 2000-12-15 20:57:00 +0000 | [diff] [blame] | 1108 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1109 | maxlen = min( reply->total, get_reply_max_size() ); |
| 1110 | if (maxlen && ((data = set_reply_data_size( maxlen )))) |
| 1111 | { |
| 1112 | if (maxlen > namelen) |
Alexandre Julliard | 0b6a79c | 2000-12-15 20:57:00 +0000 | [diff] [blame] | 1113 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1114 | reply->namelen = namelen; |
| 1115 | memcpy( data, value->name, namelen ); |
| 1116 | memcpy( (char *)data + namelen, value->data, maxlen - namelen ); |
Alexandre Julliard | 0b6a79c | 2000-12-15 20:57:00 +0000 | [diff] [blame] | 1117 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1118 | else |
Alexandre Julliard | 0b6a79c | 2000-12-15 20:57:00 +0000 | [diff] [blame] | 1119 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1120 | reply->namelen = maxlen; |
| 1121 | memcpy( data, value->name, maxlen ); |
Alexandre Julliard | 0b6a79c | 2000-12-15 20:57:00 +0000 | [diff] [blame] | 1122 | } |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1123 | } |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1124 | if (debug_level > 1) dump_operation( key, value, "Enum" ); |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | /* delete a value */ |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1129 | static void delete_value( struct key *key, const struct unicode_str *name ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1130 | { |
| 1131 | struct key_value *value; |
| 1132 | int i, index, nb_values; |
| 1133 | |
| 1134 | if (!(value = find_value( key, name, &index ))) |
| 1135 | { |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 1136 | set_error( STATUS_OBJECT_NAME_NOT_FOUND ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1137 | return; |
| 1138 | } |
| 1139 | if (debug_level > 1) dump_operation( key, value, "Delete" ); |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 1140 | free( value->name ); |
| 1141 | free( value->data ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1142 | for (i = index; i < key->last_value; i++) key->values[i] = key->values[i + 1]; |
| 1143 | key->last_value--; |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 1144 | touch_key( key, REG_NOTIFY_CHANGE_LAST_SET ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1145 | |
| 1146 | /* try to shrink the array */ |
| 1147 | nb_values = key->nb_values; |
| 1148 | if (nb_values > MIN_VALUES && key->last_value < nb_values / 2) |
| 1149 | { |
| 1150 | struct key_value *new_val; |
| 1151 | nb_values -= nb_values / 3; /* shrink by 33% */ |
| 1152 | if (nb_values < MIN_VALUES) nb_values = MIN_VALUES; |
| 1153 | if (!(new_val = realloc( key->values, nb_values * sizeof(*new_val) ))) return; |
| 1154 | key->values = new_val; |
| 1155 | key->nb_values = nb_values; |
| 1156 | } |
Alexandre Julliard | 6c8d917 | 2000-08-26 04:40:07 +0000 | [diff] [blame] | 1157 | } |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1158 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1159 | /* get the registry key corresponding to an hkey handle */ |
Alexandre Julliard | 6ebc627 | 2010-04-02 12:43:31 +0200 | [diff] [blame] | 1160 | static struct key *get_hkey_obj( obj_handle_t hkey, unsigned int access ) |
Alexandre Julliard | dd77d1a | 2006-07-10 11:53:23 +0200 | [diff] [blame] | 1161 | { |
Alexandre Julliard | 6ebc627 | 2010-04-02 12:43:31 +0200 | [diff] [blame] | 1162 | struct key *key = (struct key *)get_handle_obj( current->process, hkey, access, &key_ops ); |
| 1163 | |
| 1164 | if (key && key->flags & KEY_DELETED) |
| 1165 | { |
| 1166 | set_error( STATUS_KEY_DELETED ); |
| 1167 | release_object( key ); |
| 1168 | key = NULL; |
| 1169 | } |
| 1170 | return key; |
Alexandre Julliard | dd77d1a | 2006-07-10 11:53:23 +0200 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | /* get the registry key corresponding to a parent key handle */ |
| 1174 | static inline struct key *get_parent_hkey_obj( obj_handle_t hkey ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1175 | { |
Alexandre Julliard | 6c8d917 | 2000-08-26 04:40:07 +0000 | [diff] [blame] | 1176 | if (!hkey) return (struct key *)grab_object( root_key ); |
Alexandre Julliard | 6ebc627 | 2010-04-02 12:43:31 +0200 | [diff] [blame] | 1177 | return get_hkey_obj( hkey, 0 ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1178 | } |
| 1179 | |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1180 | /* read a line from the input file */ |
| 1181 | static int read_next_line( struct file_load_info *info ) |
| 1182 | { |
| 1183 | char *newbuf; |
| 1184 | int newlen, pos = 0; |
| 1185 | |
| 1186 | info->line++; |
| 1187 | for (;;) |
| 1188 | { |
| 1189 | if (!fgets( info->buffer + pos, info->len - pos, info->file )) |
| 1190 | return (pos != 0); /* EOF */ |
| 1191 | pos = strlen(info->buffer); |
| 1192 | if (info->buffer[pos-1] == '\n') |
| 1193 | { |
| 1194 | /* got a full line */ |
| 1195 | info->buffer[--pos] = 0; |
| 1196 | if (pos > 0 && info->buffer[pos-1] == '\r') info->buffer[pos-1] = 0; |
| 1197 | return 1; |
| 1198 | } |
| 1199 | if (pos < info->len - 1) return 1; /* EOF but something was read */ |
| 1200 | |
| 1201 | /* need to enlarge the buffer */ |
| 1202 | newlen = info->len + info->len / 2; |
| 1203 | if (!(newbuf = realloc( info->buffer, newlen ))) |
| 1204 | { |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 1205 | set_error( STATUS_NO_MEMORY ); |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1206 | return -1; |
| 1207 | } |
| 1208 | info->buffer = newbuf; |
| 1209 | info->len = newlen; |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | /* make sure the temp buffer holds enough space */ |
Alexandre Julliard | b0e091a | 2005-08-09 10:36:45 +0000 | [diff] [blame] | 1214 | static int get_file_tmp_space( struct file_load_info *info, size_t size ) |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1215 | { |
Alexandre Julliard | b0e091a | 2005-08-09 10:36:45 +0000 | [diff] [blame] | 1216 | WCHAR *tmp; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1217 | if (info->tmplen >= size) return 1; |
| 1218 | if (!(tmp = realloc( info->tmp, size ))) |
| 1219 | { |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 1220 | set_error( STATUS_NO_MEMORY ); |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1221 | return 0; |
| 1222 | } |
| 1223 | info->tmp = tmp; |
| 1224 | info->tmplen = size; |
| 1225 | return 1; |
| 1226 | } |
| 1227 | |
| 1228 | /* report an error while loading an input file */ |
| 1229 | static void file_read_error( const char *err, struct file_load_info *info ) |
| 1230 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1231 | if (info->filename) |
| 1232 | fprintf( stderr, "%s:%d: %s '%s'\n", info->filename, info->line, err, info->buffer ); |
| 1233 | else |
| 1234 | fprintf( stderr, "<fd>:%d: %s '%s'\n", info->line, err, info->buffer ); |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1237 | /* convert a data type tag to a value type */ |
| 1238 | static int get_data_type( const char *buffer, int *type, int *parse_type ) |
| 1239 | { |
| 1240 | struct data_type { const char *tag; int len; int type; int parse_type; }; |
| 1241 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1242 | static const struct data_type data_types[] = |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1243 | { /* actual type */ /* type to assume for parsing */ |
| 1244 | { "\"", 1, REG_SZ, REG_SZ }, |
| 1245 | { "str:\"", 5, REG_SZ, REG_SZ }, |
| 1246 | { "str(2):\"", 8, REG_EXPAND_SZ, REG_SZ }, |
| 1247 | { "str(7):\"", 8, REG_MULTI_SZ, REG_SZ }, |
| 1248 | { "hex:", 4, REG_BINARY, REG_BINARY }, |
| 1249 | { "dword:", 6, REG_DWORD, REG_DWORD }, |
| 1250 | { "hex(", 4, -1, REG_BINARY }, |
Joerg Mayer | 959d73e | 2000-10-22 23:56:32 +0000 | [diff] [blame] | 1251 | { NULL, 0, 0, 0 } |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1252 | }; |
| 1253 | |
| 1254 | const struct data_type *ptr; |
| 1255 | char *end; |
| 1256 | |
| 1257 | for (ptr = data_types; ptr->tag; ptr++) |
| 1258 | { |
Alexandre Julliard | fb9955d | 2008-01-07 21:06:01 +0100 | [diff] [blame] | 1259 | if (strncmp( ptr->tag, buffer, ptr->len )) continue; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1260 | *parse_type = ptr->parse_type; |
| 1261 | if ((*type = ptr->type) != -1) return ptr->len; |
| 1262 | /* "hex(xx):" is special */ |
| 1263 | *type = (int)strtoul( buffer + 4, &end, 16 ); |
Alexandre Julliard | fb9955d | 2008-01-07 21:06:01 +0100 | [diff] [blame] | 1264 | if ((end <= buffer) || strncmp( end, "):", 2 )) return 0; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1265 | return end + 2 - buffer; |
| 1266 | } |
| 1267 | return 0; |
| 1268 | } |
| 1269 | |
| 1270 | /* load and create a key from the input file */ |
Alexandre Julliard | 22de1f4 | 2010-03-01 14:13:46 +0100 | [diff] [blame] | 1271 | static struct key *load_key( struct key *base, const char *buffer, |
Alexandre Julliard | 3343c40 | 2008-12-06 17:29:01 +0100 | [diff] [blame] | 1272 | int prefix_len, struct file_load_info *info ) |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1273 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1274 | WCHAR *p; |
| 1275 | struct unicode_str name; |
Alexandre Julliard | 3343c40 | 2008-12-06 17:29:01 +0100 | [diff] [blame] | 1276 | int res; |
| 1277 | unsigned int mod; |
| 1278 | timeout_t modif = current_time; |
Alexandre Julliard | 1271739 | 2008-01-07 20:17:24 +0100 | [diff] [blame] | 1279 | data_size_t len; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1280 | |
Alexandre Julliard | 1271739 | 2008-01-07 20:17:24 +0100 | [diff] [blame] | 1281 | if (!get_file_tmp_space( info, strlen(buffer) * sizeof(WCHAR) )) return NULL; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1282 | |
Alexandre Julliard | 1271739 | 2008-01-07 20:17:24 +0100 | [diff] [blame] | 1283 | len = info->tmplen; |
Alexandre Julliard | b0e091a | 2005-08-09 10:36:45 +0000 | [diff] [blame] | 1284 | if ((res = parse_strW( info->tmp, &len, buffer, ']' )) == -1) |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1285 | { |
| 1286 | file_read_error( "Malformed key", info ); |
| 1287 | return NULL; |
| 1288 | } |
Alexandre Julliard | 3343c40 | 2008-12-06 17:29:01 +0100 | [diff] [blame] | 1289 | if (sscanf( buffer + res, " %u", &mod ) == 1) |
| 1290 | modif = (timeout_t)mod * TICKS_PER_SEC + ticks_1601_to_1970; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1291 | |
Alexandre Julliard | b0e091a | 2005-08-09 10:36:45 +0000 | [diff] [blame] | 1292 | p = info->tmp; |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1293 | while (prefix_len && *p) { if (*p++ == '\\') prefix_len--; } |
| 1294 | |
| 1295 | if (!*p) |
| 1296 | { |
| 1297 | if (prefix_len > 1) |
| 1298 | { |
| 1299 | file_read_error( "Malformed key", info ); |
| 1300 | return NULL; |
| 1301 | } |
| 1302 | /* empty key name, return base key */ |
| 1303 | return (struct key *)grab_object( base ); |
| 1304 | } |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1305 | name.str = p; |
| 1306 | name.len = len - (p - info->tmp + 1) * sizeof(WCHAR); |
Alexandre Julliard | 22de1f4 | 2010-03-01 14:13:46 +0100 | [diff] [blame] | 1307 | return create_key_recursive( base, &name, modif ); |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1308 | } |
| 1309 | |
Alexandre Julliard | 58791c9 | 2010-05-04 20:26:04 +0200 | [diff] [blame] | 1310 | /* load a global option from the input file */ |
| 1311 | static int load_global_option( const char *buffer, struct file_load_info *info ) |
| 1312 | { |
| 1313 | const char *p; |
| 1314 | |
| 1315 | if (!strncmp( buffer, "#arch=", 6 )) |
| 1316 | { |
| 1317 | enum prefix_type type; |
| 1318 | p = buffer + 6; |
| 1319 | if (!strcmp( p, "win32" )) type = PREFIX_32BIT; |
| 1320 | else if (!strcmp( p, "win64" )) type = PREFIX_64BIT; |
| 1321 | else |
| 1322 | { |
| 1323 | file_read_error( "Unknown architecture", info ); |
| 1324 | set_error( STATUS_NOT_REGISTRY_FILE ); |
| 1325 | return 0; |
| 1326 | } |
| 1327 | if (prefix_type == PREFIX_UNKNOWN) prefix_type = type; |
| 1328 | else if (type != prefix_type) |
| 1329 | { |
| 1330 | file_read_error( "Mismatched architecture", info ); |
| 1331 | set_error( STATUS_NOT_REGISTRY_FILE ); |
| 1332 | return 0; |
| 1333 | } |
| 1334 | } |
| 1335 | /* ignore unknown options */ |
| 1336 | return 1; |
| 1337 | } |
| 1338 | |
Alexandre Julliard | 2a37867 | 2010-02-16 12:26:15 +0100 | [diff] [blame] | 1339 | /* load a key option from the input file */ |
| 1340 | static int load_key_option( struct key *key, const char *buffer, struct file_load_info *info ) |
| 1341 | { |
| 1342 | const char *p; |
| 1343 | data_size_t len; |
| 1344 | |
| 1345 | if (!strncmp( buffer, "#class=", 7 )) |
| 1346 | { |
| 1347 | p = buffer + 7; |
| 1348 | if (*p++ != '"') return 0; |
| 1349 | if (!get_file_tmp_space( info, strlen(p) * sizeof(WCHAR) )) return 0; |
| 1350 | len = info->tmplen; |
| 1351 | if (parse_strW( info->tmp, &len, p, '\"' ) == -1) return 0; |
| 1352 | free( key->class ); |
| 1353 | if (!(key->class = memdup( info->tmp, len ))) len = 0; |
| 1354 | key->classlen = len; |
| 1355 | } |
Alexandre Julliard | b5d4289 | 2010-02-16 12:26:44 +0100 | [diff] [blame] | 1356 | if (!strncmp( buffer, "#link", 5 )) key->flags |= KEY_SYMLINK; |
Alexandre Julliard | 2a37867 | 2010-02-16 12:26:15 +0100 | [diff] [blame] | 1357 | /* ignore unknown options */ |
| 1358 | return 1; |
| 1359 | } |
| 1360 | |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1361 | /* parse a comma-separated list of hex digits */ |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1362 | static int parse_hex( unsigned char *dest, data_size_t *len, const char *buffer ) |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1363 | { |
| 1364 | const char *p = buffer; |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1365 | data_size_t count = 0; |
Alexandre Julliard | fb9955d | 2008-01-07 21:06:01 +0100 | [diff] [blame] | 1366 | char *end; |
| 1367 | |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1368 | while (isxdigit(*p)) |
| 1369 | { |
Alexandre Julliard | fb9955d | 2008-01-07 21:06:01 +0100 | [diff] [blame] | 1370 | unsigned int val = strtoul( p, &end, 16 ); |
| 1371 | if (end == p || val > 0xff) return -1; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1372 | if (count++ >= *len) return -1; /* dest buffer overflow */ |
Alexandre Julliard | fb9955d | 2008-01-07 21:06:01 +0100 | [diff] [blame] | 1373 | *dest++ = val; |
| 1374 | p = end; |
| 1375 | while (isspace(*p)) p++; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1376 | if (*p == ',') p++; |
Alexandre Julliard | fb9955d | 2008-01-07 21:06:01 +0100 | [diff] [blame] | 1377 | while (isspace(*p)) p++; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1378 | } |
| 1379 | *len = count; |
| 1380 | return p - buffer; |
| 1381 | } |
| 1382 | |
| 1383 | /* parse a value name and create the corresponding value */ |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1384 | static struct key_value *parse_value_name( struct key *key, const char *buffer, data_size_t *len, |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1385 | struct file_load_info *info ) |
| 1386 | { |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 1387 | struct key_value *value; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1388 | struct unicode_str name; |
| 1389 | int index; |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 1390 | |
Alexandre Julliard | 1271739 | 2008-01-07 20:17:24 +0100 | [diff] [blame] | 1391 | if (!get_file_tmp_space( info, strlen(buffer) * sizeof(WCHAR) )) return NULL; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1392 | name.str = info->tmp; |
Alexandre Julliard | 1271739 | 2008-01-07 20:17:24 +0100 | [diff] [blame] | 1393 | name.len = info->tmplen; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1394 | if (buffer[0] == '@') |
| 1395 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1396 | name.len = 0; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1397 | *len = 1; |
| 1398 | } |
| 1399 | else |
| 1400 | { |
Alexandre Julliard | 1271739 | 2008-01-07 20:17:24 +0100 | [diff] [blame] | 1401 | int r = parse_strW( info->tmp, &name.len, buffer + 1, '\"' ); |
Mike McCormack | 14278b4 | 2006-04-07 15:06:15 +0900 | [diff] [blame] | 1402 | if (r == -1) goto error; |
| 1403 | *len = r + 1; /* for initial quote */ |
Alexandre Julliard | 1271739 | 2008-01-07 20:17:24 +0100 | [diff] [blame] | 1404 | name.len -= sizeof(WCHAR); /* terminating null */ |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1405 | } |
Alexandre Julliard | 6c8d917 | 2000-08-26 04:40:07 +0000 | [diff] [blame] | 1406 | while (isspace(buffer[*len])) (*len)++; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1407 | if (buffer[*len] != '=') goto error; |
| 1408 | (*len)++; |
Alexandre Julliard | 6c8d917 | 2000-08-26 04:40:07 +0000 | [diff] [blame] | 1409 | while (isspace(buffer[*len])) (*len)++; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1410 | if (!(value = find_value( key, &name, &index ))) value = insert_value( key, &name, index ); |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 1411 | return value; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1412 | |
| 1413 | error: |
| 1414 | file_read_error( "Malformed value name", info ); |
| 1415 | return NULL; |
| 1416 | } |
| 1417 | |
| 1418 | /* load a value from the input file */ |
| 1419 | static int load_value( struct key *key, const char *buffer, struct file_load_info *info ) |
| 1420 | { |
| 1421 | DWORD dw; |
| 1422 | void *ptr, *newptr; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1423 | int res, type, parse_type; |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1424 | data_size_t maxlen, len; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1425 | struct key_value *value; |
| 1426 | |
| 1427 | if (!(value = parse_value_name( key, buffer, &len, info ))) return 0; |
| 1428 | if (!(res = get_data_type( buffer + len, &type, &parse_type ))) goto error; |
| 1429 | buffer += len + res; |
| 1430 | |
| 1431 | switch(parse_type) |
| 1432 | { |
| 1433 | case REG_SZ: |
Alexandre Julliard | 1271739 | 2008-01-07 20:17:24 +0100 | [diff] [blame] | 1434 | if (!get_file_tmp_space( info, strlen(buffer) * sizeof(WCHAR) )) return 0; |
| 1435 | len = info->tmplen; |
Alexandre Julliard | b0e091a | 2005-08-09 10:36:45 +0000 | [diff] [blame] | 1436 | if ((res = parse_strW( info->tmp, &len, buffer, '\"' )) == -1) goto error; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1437 | ptr = info->tmp; |
| 1438 | break; |
| 1439 | case REG_DWORD: |
| 1440 | dw = strtoul( buffer, NULL, 16 ); |
| 1441 | ptr = &dw; |
| 1442 | len = sizeof(dw); |
| 1443 | break; |
| 1444 | case REG_BINARY: /* hex digits */ |
| 1445 | len = 0; |
| 1446 | for (;;) |
| 1447 | { |
Alexandre Julliard | fb9955d | 2008-01-07 21:06:01 +0100 | [diff] [blame] | 1448 | maxlen = 1 + strlen(buffer) / 2; /* at least 2 chars for one hex byte */ |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1449 | if (!get_file_tmp_space( info, len + maxlen )) return 0; |
Alexandre Julliard | b0e091a | 2005-08-09 10:36:45 +0000 | [diff] [blame] | 1450 | if ((res = parse_hex( (unsigned char *)info->tmp + len, &maxlen, buffer )) == -1) goto error; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1451 | len += maxlen; |
| 1452 | buffer += res; |
| 1453 | while (isspace(*buffer)) buffer++; |
| 1454 | if (!*buffer) break; |
| 1455 | if (*buffer != '\\') goto error; |
| 1456 | if (read_next_line( info) != 1) goto error; |
| 1457 | buffer = info->buffer; |
| 1458 | while (isspace(*buffer)) buffer++; |
| 1459 | } |
| 1460 | ptr = info->tmp; |
| 1461 | break; |
| 1462 | default: |
| 1463 | assert(0); |
| 1464 | ptr = NULL; /* keep compiler quiet */ |
| 1465 | break; |
| 1466 | } |
| 1467 | |
| 1468 | if (!len) newptr = NULL; |
| 1469 | else if (!(newptr = memdup( ptr, len ))) return 0; |
| 1470 | |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 1471 | free( value->data ); |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1472 | value->data = newptr; |
| 1473 | value->len = len; |
| 1474 | value->type = type; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1475 | return 1; |
| 1476 | |
| 1477 | error: |
| 1478 | file_read_error( "Malformed value", info ); |
Alexandre Julliard | fb9955d | 2008-01-07 21:06:01 +0100 | [diff] [blame] | 1479 | free( value->data ); |
| 1480 | value->data = NULL; |
| 1481 | value->len = 0; |
| 1482 | value->type = REG_NONE; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1483 | return 0; |
| 1484 | } |
| 1485 | |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1486 | /* return the length (in path elements) of name that is part of the key name */ |
| 1487 | /* for instance if key is USER\foo\bar and name is foo\bar\baz, return 2 */ |
| 1488 | static int get_prefix_len( struct key *key, const char *name, struct file_load_info *info ) |
| 1489 | { |
| 1490 | WCHAR *p; |
| 1491 | int res; |
Alexandre Julliard | 1271739 | 2008-01-07 20:17:24 +0100 | [diff] [blame] | 1492 | data_size_t len; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1493 | |
Alexandre Julliard | 1271739 | 2008-01-07 20:17:24 +0100 | [diff] [blame] | 1494 | if (!get_file_tmp_space( info, strlen(name) * sizeof(WCHAR) )) return 0; |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1495 | |
Alexandre Julliard | 1271739 | 2008-01-07 20:17:24 +0100 | [diff] [blame] | 1496 | len = info->tmplen; |
Alexandre Julliard | b0e091a | 2005-08-09 10:36:45 +0000 | [diff] [blame] | 1497 | if ((res = parse_strW( info->tmp, &len, name, ']' )) == -1) |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1498 | { |
| 1499 | file_read_error( "Malformed key", info ); |
Patrik Stridvall | 17d1e9e | 2000-05-23 23:38:32 +0000 | [diff] [blame] | 1500 | return 0; |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1501 | } |
Alexandre Julliard | b0e091a | 2005-08-09 10:36:45 +0000 | [diff] [blame] | 1502 | for (p = info->tmp; *p; p++) if (*p == '\\') break; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1503 | len = (p - info->tmp) * sizeof(WCHAR); |
Alexandre Julliard | 6c8d917 | 2000-08-26 04:40:07 +0000 | [diff] [blame] | 1504 | for (res = 1; key != root_key; res++) |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1505 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1506 | if (len == key->namelen && !memicmpW( info->tmp, key->name, len / sizeof(WCHAR) )) break; |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1507 | key = key->parent; |
| 1508 | } |
Alexandre Julliard | 6c8d917 | 2000-08-26 04:40:07 +0000 | [diff] [blame] | 1509 | if (key == root_key) res = 0; /* no matching name */ |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1510 | return res; |
| 1511 | } |
| 1512 | |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1513 | /* load all the keys from the input file */ |
Alexandre Julliard | 58447bc | 2004-04-30 18:35:13 +0000 | [diff] [blame] | 1514 | /* prefix_len is the number of key name prefixes to skip, or -1 for autodetection */ |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1515 | static void load_keys( struct key *key, const char *filename, FILE *f, int prefix_len ) |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1516 | { |
| 1517 | struct key *subkey = NULL; |
| 1518 | struct file_load_info info; |
| 1519 | char *p; |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1520 | |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1521 | info.filename = filename; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1522 | info.file = f; |
| 1523 | info.len = 4; |
| 1524 | info.tmplen = 4; |
| 1525 | info.line = 0; |
| 1526 | if (!(info.buffer = mem_alloc( info.len ))) return; |
| 1527 | if (!(info.tmp = mem_alloc( info.tmplen ))) |
| 1528 | { |
| 1529 | free( info.buffer ); |
| 1530 | return; |
| 1531 | } |
| 1532 | |
| 1533 | if ((read_next_line( &info ) != 1) || |
| 1534 | strcmp( info.buffer, "WINE REGISTRY Version 2" )) |
| 1535 | { |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 1536 | set_error( STATUS_NOT_REGISTRY_FILE ); |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1537 | goto done; |
| 1538 | } |
| 1539 | |
| 1540 | while (read_next_line( &info ) == 1) |
| 1541 | { |
Alexandre Julliard | 566a52a | 2001-03-05 19:34:17 +0000 | [diff] [blame] | 1542 | p = info.buffer; |
| 1543 | while (*p && isspace(*p)) p++; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1544 | switch(*p) |
| 1545 | { |
| 1546 | case '[': /* new key */ |
| 1547 | if (subkey) release_object( subkey ); |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1548 | if (prefix_len == -1) prefix_len = get_prefix_len( key, p + 1, &info ); |
Alexandre Julliard | 22de1f4 | 2010-03-01 14:13:46 +0100 | [diff] [blame] | 1549 | if (!(subkey = load_key( key, p + 1, prefix_len, &info ))) |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1550 | file_read_error( "Error creating key", &info ); |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1551 | break; |
| 1552 | case '@': /* default value */ |
| 1553 | case '\"': /* value */ |
| 1554 | if (subkey) load_value( subkey, p, &info ); |
| 1555 | else file_read_error( "Value without key", &info ); |
| 1556 | break; |
Alexandre Julliard | 2a37867 | 2010-02-16 12:26:15 +0100 | [diff] [blame] | 1557 | case '#': /* option */ |
| 1558 | if (subkey) load_key_option( subkey, p, &info ); |
Alexandre Julliard | 58791c9 | 2010-05-04 20:26:04 +0200 | [diff] [blame] | 1559 | else if (!load_global_option( p, &info )) goto done; |
Alexandre Julliard | 2a37867 | 2010-02-16 12:26:15 +0100 | [diff] [blame] | 1560 | break; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1561 | case ';': /* comment */ |
| 1562 | case 0: /* empty line */ |
| 1563 | break; |
| 1564 | default: |
| 1565 | file_read_error( "Unrecognized input", &info ); |
| 1566 | break; |
| 1567 | } |
| 1568 | } |
| 1569 | |
| 1570 | done: |
| 1571 | if (subkey) release_object( subkey ); |
| 1572 | free( info.buffer ); |
| 1573 | free( info.tmp ); |
| 1574 | } |
| 1575 | |
| 1576 | /* load a part of the registry from a file */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 1577 | static void load_registry( struct key *key, obj_handle_t handle ) |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1578 | { |
Alexandre Julliard | cf27a7f | 2003-02-14 20:27:09 +0000 | [diff] [blame] | 1579 | struct file *file; |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1580 | int fd; |
| 1581 | |
Alexandre Julliard | a510a7e | 2005-12-12 16:46:17 +0100 | [diff] [blame] | 1582 | if (!(file = get_file_obj( current->process, handle, FILE_READ_DATA ))) return; |
Alexandre Julliard | cf27a7f | 2003-02-14 20:27:09 +0000 | [diff] [blame] | 1583 | fd = dup( get_file_unix_fd( file ) ); |
| 1584 | release_object( file ); |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1585 | if (fd != -1) |
| 1586 | { |
| 1587 | FILE *f = fdopen( fd, "r" ); |
| 1588 | if (f) |
| 1589 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1590 | load_keys( key, NULL, f, -1 ); |
Alexandre Julliard | 53f3a83 | 1999-11-24 04:19:43 +0000 | [diff] [blame] | 1591 | fclose( f ); |
| 1592 | } |
| 1593 | else file_set_error(); |
| 1594 | } |
| 1595 | } |
| 1596 | |
Alexandre Julliard | c07ce05 | 2004-05-07 04:13:21 +0000 | [diff] [blame] | 1597 | /* load one of the initial registry files */ |
Alexandre Julliard | 58791c9 | 2010-05-04 20:26:04 +0200 | [diff] [blame] | 1598 | static int load_init_registry_from_file( const char *filename, struct key *key ) |
Alexandre Julliard | c07ce05 | 2004-05-07 04:13:21 +0000 | [diff] [blame] | 1599 | { |
| 1600 | FILE *f; |
| 1601 | |
Alexandre Julliard | 5b23efc | 2004-05-14 00:45:11 +0000 | [diff] [blame] | 1602 | if ((f = fopen( filename, "r" ))) |
| 1603 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1604 | load_keys( key, filename, f, 0 ); |
Alexandre Julliard | 5b23efc | 2004-05-14 00:45:11 +0000 | [diff] [blame] | 1605 | fclose( f ); |
| 1606 | if (get_error() == STATUS_NOT_REGISTRY_FILE) |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1607 | { |
| 1608 | fprintf( stderr, "%s is not a valid registry file\n", filename ); |
Alexandre Julliard | 58791c9 | 2010-05-04 20:26:04 +0200 | [diff] [blame] | 1609 | return 1; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1610 | } |
Alexandre Julliard | 5b23efc | 2004-05-14 00:45:11 +0000 | [diff] [blame] | 1611 | } |
Alexandre Julliard | c07ce05 | 2004-05-07 04:13:21 +0000 | [diff] [blame] | 1612 | |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1613 | assert( save_branch_count < MAX_SAVE_BRANCH_INFO ); |
Alexandre Julliard | c07ce05 | 2004-05-07 04:13:21 +0000 | [diff] [blame] | 1614 | |
Alexandre Julliard | 161160f | 2008-04-17 12:41:34 +0200 | [diff] [blame] | 1615 | save_branch_info[save_branch_count].path = filename; |
| 1616 | save_branch_info[save_branch_count++].key = (struct key *)grab_object( key ); |
| 1617 | make_object_static( &key->obj ); |
Alexandre Julliard | 58791c9 | 2010-05-04 20:26:04 +0200 | [diff] [blame] | 1618 | return (f != NULL); |
Alexandre Julliard | c07ce05 | 2004-05-07 04:13:21 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1621 | static WCHAR *format_user_registry_path( const SID *sid, struct unicode_str *path ) |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 1622 | { |
| 1623 | static const WCHAR prefixW[] = {'U','s','e','r','\\','S',0}; |
| 1624 | static const WCHAR formatW[] = {'-','%','u',0}; |
| 1625 | WCHAR buffer[7 + 10 + 10 + 10 * SID_MAX_SUB_AUTHORITIES]; |
| 1626 | WCHAR *p = buffer; |
| 1627 | unsigned int i; |
| 1628 | |
| 1629 | strcpyW( p, prefixW ); |
| 1630 | p += strlenW( prefixW ); |
| 1631 | p += sprintfW( p, formatW, sid->Revision ); |
| 1632 | p += sprintfW( p, formatW, MAKELONG( MAKEWORD( sid->IdentifierAuthority.Value[5], |
| 1633 | sid->IdentifierAuthority.Value[4] ), |
| 1634 | MAKEWORD( sid->IdentifierAuthority.Value[3], |
| 1635 | sid->IdentifierAuthority.Value[2] ))); |
| 1636 | for (i = 0; i < sid->SubAuthorityCount; i++) |
| 1637 | p += sprintfW( p, formatW, sid->SubAuthority[i] ); |
| 1638 | |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1639 | path->len = (p - buffer) * sizeof(WCHAR); |
| 1640 | path->str = p = memdup( buffer, path->len ); |
| 1641 | return p; |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 1642 | } |
| 1643 | |
Alexandre Julliard | ac69fcb | 2010-05-04 18:23:29 +0200 | [diff] [blame] | 1644 | /* get the cpu architectures that can be supported in the current prefix */ |
| 1645 | unsigned int get_prefix_cpu_mask(void) |
| 1646 | { |
| 1647 | /* Allowed server/client/prefix combinations: |
| 1648 | * |
| 1649 | * prefix |
| 1650 | * 32 64 |
| 1651 | * server +------+------+ client |
| 1652 | * | ok | fail | 32 |
| 1653 | * 32 +------+------+--- |
| 1654 | * | fail | fail | 64 |
| 1655 | * ---+------+------+--- |
| 1656 | * | ok | ok | 32 |
| 1657 | * 64 +------+------+--- |
| 1658 | * | fail | ok | 64 |
| 1659 | * ---+------+------+--- |
| 1660 | */ |
| 1661 | switch (prefix_type) |
| 1662 | { |
| 1663 | case PREFIX_64BIT: |
| 1664 | /* 64-bit prefix requires 64-bit server */ |
| 1665 | return sizeof(void *) > sizeof(int) ? ~0 : 0; |
| 1666 | case PREFIX_32BIT: |
| 1667 | default: |
| 1668 | return ~CPU_64BIT_MASK; /* only 32-bit cpus supported on 32-bit prefix */ |
| 1669 | } |
| 1670 | } |
| 1671 | |
Alexandre Julliard | 27f0f80 | 2005-04-20 12:57:53 +0000 | [diff] [blame] | 1672 | /* registry initialisation */ |
| 1673 | void init_registry(void) |
| 1674 | { |
Alexandre Julliard | c07ce05 | 2004-05-07 04:13:21 +0000 | [diff] [blame] | 1675 | static const WCHAR HKLM[] = { 'M','a','c','h','i','n','e' }; |
| 1676 | static const WCHAR HKU_default[] = { 'U','s','e','r','\\','.','D','e','f','a','u','l','t' }; |
Alexandre Julliard | 178cd20 | 2010-03-04 20:47:35 +0100 | [diff] [blame] | 1677 | static const WCHAR classes[] = {'S','o','f','t','w','a','r','e','\\', |
| 1678 | 'C','l','a','s','s','e','s','\\', |
| 1679 | 'W','o','w','6','4','3','2','N','o','d','e'}; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1680 | static const struct unicode_str root_name = { NULL, 0 }; |
| 1681 | static const struct unicode_str HKLM_name = { HKLM, sizeof(HKLM) }; |
| 1682 | static const struct unicode_str HKU_name = { HKU_default, sizeof(HKU_default) }; |
Alexandre Julliard | 178cd20 | 2010-03-04 20:47:35 +0100 | [diff] [blame] | 1683 | static const struct unicode_str classes_name = { classes, sizeof(classes) }; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1684 | |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 1685 | WCHAR *current_user_path; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1686 | struct unicode_str current_user_str; |
Alexandre Julliard | 178cd20 | 2010-03-04 20:47:35 +0100 | [diff] [blame] | 1687 | struct key *key, *hklm, *hkcu; |
Alexandre Julliard | c07ce05 | 2004-05-07 04:13:21 +0000 | [diff] [blame] | 1688 | |
Alexandre Julliard | 161160f | 2008-04-17 12:41:34 +0200 | [diff] [blame] | 1689 | /* switch to the config dir */ |
| 1690 | |
| 1691 | if (fchdir( config_dir_fd ) == -1) fatal_perror( "chdir to config dir" ); |
| 1692 | |
Alexandre Julliard | 27f0f80 | 2005-04-20 12:57:53 +0000 | [diff] [blame] | 1693 | /* create the root key */ |
Alexandre Julliard | 3343c40 | 2008-12-06 17:29:01 +0100 | [diff] [blame] | 1694 | root_key = alloc_key( &root_name, current_time ); |
Alexandre Julliard | 27f0f80 | 2005-04-20 12:57:53 +0000 | [diff] [blame] | 1695 | assert( root_key ); |
Alexandre Julliard | b00fb17 | 2006-03-22 20:32:04 +0100 | [diff] [blame] | 1696 | make_object_static( &root_key->obj ); |
Alexandre Julliard | 27f0f80 | 2005-04-20 12:57:53 +0000 | [diff] [blame] | 1697 | |
Alexandre Julliard | c07ce05 | 2004-05-07 04:13:21 +0000 | [diff] [blame] | 1698 | /* load system.reg into Registry\Machine */ |
| 1699 | |
Alexandre Julliard | 178cd20 | 2010-03-04 20:47:35 +0100 | [diff] [blame] | 1700 | if (!(hklm = create_key_recursive( root_key, &HKLM_name, current_time ))) |
Alexandre Julliard | c07ce05 | 2004-05-07 04:13:21 +0000 | [diff] [blame] | 1701 | fatal_error( "could not create Machine registry key\n" ); |
| 1702 | |
Alexandre Julliard | 58791c9 | 2010-05-04 20:26:04 +0200 | [diff] [blame] | 1703 | if (!load_init_registry_from_file( "system.reg", hklm )) |
| 1704 | prefix_type = sizeof(void *) > sizeof(int) ? PREFIX_64BIT : PREFIX_32BIT; |
| 1705 | else if (prefix_type == PREFIX_UNKNOWN) |
| 1706 | prefix_type = PREFIX_32BIT; |
Alexandre Julliard | c07ce05 | 2004-05-07 04:13:21 +0000 | [diff] [blame] | 1707 | |
| 1708 | /* load userdef.reg into Registry\User\.Default */ |
| 1709 | |
Alexandre Julliard | 22de1f4 | 2010-03-01 14:13:46 +0100 | [diff] [blame] | 1710 | if (!(key = create_key_recursive( root_key, &HKU_name, current_time ))) |
Alexandre Julliard | c07ce05 | 2004-05-07 04:13:21 +0000 | [diff] [blame] | 1711 | fatal_error( "could not create User\\.Default registry key\n" ); |
| 1712 | |
Alexandre Julliard | 161160f | 2008-04-17 12:41:34 +0200 | [diff] [blame] | 1713 | load_init_registry_from_file( "userdef.reg", key ); |
Alexandre Julliard | c07ce05 | 2004-05-07 04:13:21 +0000 | [diff] [blame] | 1714 | release_object( key ); |
| 1715 | |
Alexandre Julliard | 6aa0cc5 | 2005-07-11 20:44:59 +0000 | [diff] [blame] | 1716 | /* load user.reg into HKEY_CURRENT_USER */ |
| 1717 | |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 1718 | /* FIXME: match default user in token.c. should get from process token instead */ |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1719 | current_user_path = format_user_registry_path( security_interactive_sid, ¤t_user_str ); |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 1720 | if (!current_user_path || |
Alexandre Julliard | 178cd20 | 2010-03-04 20:47:35 +0100 | [diff] [blame] | 1721 | !(hkcu = create_key_recursive( root_key, ¤t_user_str, current_time ))) |
Alexandre Julliard | 6aa0cc5 | 2005-07-11 20:44:59 +0000 | [diff] [blame] | 1722 | fatal_error( "could not create HKEY_CURRENT_USER registry key\n" ); |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 1723 | free( current_user_path ); |
Alexandre Julliard | 178cd20 | 2010-03-04 20:47:35 +0100 | [diff] [blame] | 1724 | load_init_registry_from_file( "user.reg", hkcu ); |
| 1725 | |
| 1726 | /* set the shared flag on Software\Classes\Wow6432Node */ |
Alexandre Julliard | 58791c9 | 2010-05-04 20:26:04 +0200 | [diff] [blame] | 1727 | if (prefix_type == PREFIX_64BIT) |
Alexandre Julliard | 178cd20 | 2010-03-04 20:47:35 +0100 | [diff] [blame] | 1728 | { |
| 1729 | if ((key = create_key_recursive( hklm, &classes_name, current_time ))) |
| 1730 | { |
| 1731 | key->flags |= KEY_WOWSHARE; |
| 1732 | release_object( key ); |
| 1733 | } |
| 1734 | /* FIXME: handle HKCU too */ |
| 1735 | } |
| 1736 | |
| 1737 | release_object( hklm ); |
| 1738 | release_object( hkcu ); |
Alexandre Julliard | 6aa0cc5 | 2005-07-11 20:44:59 +0000 | [diff] [blame] | 1739 | |
Alexandre Julliard | 6aa0cc5 | 2005-07-11 20:44:59 +0000 | [diff] [blame] | 1740 | /* start the periodic save timer */ |
| 1741 | set_periodic_save_timer(); |
Alexandre Julliard | 161160f | 2008-04-17 12:41:34 +0200 | [diff] [blame] | 1742 | |
| 1743 | /* go back to the server dir */ |
| 1744 | if (fchdir( server_dir_fd ) == -1) fatal_perror( "chdir to server dir" ); |
Alexandre Julliard | 6c8d917 | 2000-08-26 04:40:07 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1747 | /* save a registry branch to a file */ |
| 1748 | static void save_all_subkeys( struct key *key, FILE *f ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1749 | { |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1750 | fprintf( f, "WINE REGISTRY Version 2\n" ); |
| 1751 | fprintf( f, ";; All keys relative to " ); |
| 1752 | dump_path( key, NULL, f ); |
| 1753 | fprintf( f, "\n" ); |
Alexandre Julliard | 58791c9 | 2010-05-04 20:26:04 +0200 | [diff] [blame] | 1754 | switch (prefix_type) |
| 1755 | { |
| 1756 | case PREFIX_32BIT: |
| 1757 | fprintf( f, "\n#arch=win32\n" ); |
| 1758 | break; |
| 1759 | case PREFIX_64BIT: |
| 1760 | fprintf( f, "\n#arch=win64\n" ); |
| 1761 | break; |
| 1762 | default: |
| 1763 | break; |
| 1764 | } |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1765 | save_subkeys( key, key, f ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | /* save a registry branch to a file handle */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 1769 | static void save_registry( struct key *key, obj_handle_t handle ) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1770 | { |
Alexandre Julliard | cf27a7f | 2003-02-14 20:27:09 +0000 | [diff] [blame] | 1771 | struct file *file; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1772 | int fd; |
| 1773 | |
Alexandre Julliard | a510a7e | 2005-12-12 16:46:17 +0100 | [diff] [blame] | 1774 | if (!(file = get_file_obj( current->process, handle, FILE_WRITE_DATA ))) return; |
Alexandre Julliard | cf27a7f | 2003-02-14 20:27:09 +0000 | [diff] [blame] | 1775 | fd = dup( get_file_unix_fd( file ) ); |
| 1776 | release_object( file ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1777 | if (fd != -1) |
| 1778 | { |
| 1779 | FILE *f = fdopen( fd, "w" ); |
| 1780 | if (f) |
| 1781 | { |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1782 | save_all_subkeys( key, f ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1783 | if (fclose( f )) file_set_error(); |
| 1784 | } |
| 1785 | else |
| 1786 | { |
| 1787 | file_set_error(); |
| 1788 | close( fd ); |
| 1789 | } |
| 1790 | } |
| 1791 | } |
| 1792 | |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 1793 | /* save a registry branch to a file */ |
| 1794 | static int save_branch( struct key *key, const char *path ) |
| 1795 | { |
Bill Medland | 309566d | 2002-12-18 05:03:51 +0000 | [diff] [blame] | 1796 | struct stat st; |
Alexandre Julliard | 161160f | 2008-04-17 12:41:34 +0200 | [diff] [blame] | 1797 | char *p, *tmp = NULL; |
| 1798 | int fd, count = 0, ret = 0; |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 1799 | FILE *f; |
| 1800 | |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 1801 | if (!(key->flags & KEY_DIRTY)) |
| 1802 | { |
| 1803 | if (debug_level > 1) dump_operation( key, NULL, "Not saving clean" ); |
| 1804 | return 1; |
| 1805 | } |
| 1806 | |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 1807 | /* test the file type */ |
| 1808 | |
| 1809 | if ((fd = open( path, O_WRONLY )) != -1) |
| 1810 | { |
Bill Medland | 309566d | 2002-12-18 05:03:51 +0000 | [diff] [blame] | 1811 | /* if file is not a regular file or has multiple links or is accessed |
| 1812 | * via symbolic links, write directly into it; otherwise use a temp file */ |
Alexandre Julliard | 161160f | 2008-04-17 12:41:34 +0200 | [diff] [blame] | 1813 | if (!lstat( path, &st ) && (!S_ISREG(st.st_mode) || st.st_nlink > 1)) |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 1814 | { |
| 1815 | ftruncate( fd, 0 ); |
| 1816 | goto save; |
| 1817 | } |
| 1818 | close( fd ); |
| 1819 | } |
| 1820 | |
| 1821 | /* create a temp file in the same directory */ |
| 1822 | |
| 1823 | if (!(tmp = malloc( strlen(path) + 20 ))) goto done; |
| 1824 | strcpy( tmp, path ); |
| 1825 | if ((p = strrchr( tmp, '/' ))) p++; |
| 1826 | else p = tmp; |
| 1827 | for (;;) |
| 1828 | { |
Patrik Stridvall | e29dbc5 | 2000-04-24 18:04:24 +0000 | [diff] [blame] | 1829 | sprintf( p, "reg%lx%04x.tmp", (long) getpid(), count++ ); |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 1830 | if ((fd = open( tmp, O_CREAT | O_EXCL | O_WRONLY, 0666 )) != -1) break; |
| 1831 | if (errno != EEXIST) goto done; |
| 1832 | close( fd ); |
| 1833 | } |
| 1834 | |
| 1835 | /* now save to it */ |
| 1836 | |
| 1837 | save: |
| 1838 | if (!(f = fdopen( fd, "w" ))) |
| 1839 | { |
| 1840 | if (tmp) unlink( tmp ); |
| 1841 | close( fd ); |
| 1842 | goto done; |
| 1843 | } |
| 1844 | |
| 1845 | if (debug_level > 1) |
| 1846 | { |
| 1847 | fprintf( stderr, "%s: ", path ); |
| 1848 | dump_operation( key, NULL, "saving" ); |
| 1849 | } |
| 1850 | |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 1851 | save_all_subkeys( key, f ); |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 1852 | ret = !fclose(f); |
| 1853 | |
| 1854 | if (tmp) |
| 1855 | { |
| 1856 | /* if successfully written, rename to final name */ |
| 1857 | if (ret) ret = !rename( tmp, path ); |
| 1858 | if (!ret) unlink( tmp ); |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | done: |
Peter Berg Larsen | 514f432 | 2005-03-10 11:18:31 +0000 | [diff] [blame] | 1862 | free( tmp ); |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 1863 | if (ret) make_clean( key ); |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 1864 | return ret; |
| 1865 | } |
| 1866 | |
| 1867 | /* periodic saving of the registry */ |
| 1868 | static void periodic_save( void *arg ) |
| 1869 | { |
| 1870 | int i; |
Alexandre Julliard | dcab706 | 2005-03-14 11:00:43 +0000 | [diff] [blame] | 1871 | |
Alexandre Julliard | 161160f | 2008-04-17 12:41:34 +0200 | [diff] [blame] | 1872 | if (fchdir( config_dir_fd ) == -1) return; |
Alexandre Julliard | dcab706 | 2005-03-14 11:00:43 +0000 | [diff] [blame] | 1873 | save_timeout_user = NULL; |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 1874 | for (i = 0; i < save_branch_count; i++) |
| 1875 | save_branch( save_branch_info[i].key, save_branch_info[i].path ); |
Alexandre Julliard | 161160f | 2008-04-17 12:41:34 +0200 | [diff] [blame] | 1876 | if (fchdir( server_dir_fd ) == -1) fatal_perror( "chdir to server dir" ); |
Alexandre Julliard | dcab706 | 2005-03-14 11:00:43 +0000 | [diff] [blame] | 1877 | set_periodic_save_timer(); |
| 1878 | } |
| 1879 | |
| 1880 | /* start the periodic save timer */ |
| 1881 | static void set_periodic_save_timer(void) |
| 1882 | { |
Alexandre Julliard | dcab706 | 2005-03-14 11:00:43 +0000 | [diff] [blame] | 1883 | if (save_timeout_user) remove_timeout_user( save_timeout_user ); |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 1884 | save_timeout_user = add_timeout_user( save_period, periodic_save, NULL ); |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 1885 | } |
| 1886 | |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 1887 | /* save the modified registry branches to disk */ |
| 1888 | void flush_registry(void) |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 1889 | { |
| 1890 | int i; |
| 1891 | |
Alexandre Julliard | 161160f | 2008-04-17 12:41:34 +0200 | [diff] [blame] | 1892 | if (fchdir( config_dir_fd ) == -1) return; |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 1893 | for (i = 0; i < save_branch_count; i++) |
| 1894 | { |
| 1895 | if (!save_branch( save_branch_info[i].key, save_branch_info[i].path )) |
| 1896 | { |
| 1897 | fprintf( stderr, "wineserver: could not save registry branch to %s", |
| 1898 | save_branch_info[i].path ); |
| 1899 | perror( " " ); |
| 1900 | } |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 1901 | } |
Alexandre Julliard | 161160f | 2008-04-17 12:41:34 +0200 | [diff] [blame] | 1902 | if (fchdir( server_dir_fd ) == -1) fatal_perror( "chdir to server dir" ); |
Alexandre Julliard | 88e4261 | 2002-06-20 23:18:56 +0000 | [diff] [blame] | 1903 | } |
| 1904 | |
Alexandre Julliard | bbc03d5 | 2010-05-04 20:26:53 +0200 | [diff] [blame] | 1905 | /* determine if the thread is wow64 (32-bit client running on 64-bit prefix) */ |
| 1906 | static int is_wow64_thread( struct thread *thread ) |
| 1907 | { |
| 1908 | return (prefix_type == PREFIX_64BIT && !(CPU_FLAG(thread->process->cpu) & CPU_64BIT_MASK)); |
| 1909 | } |
| 1910 | |
Alexandre Julliard | c970904 | 2000-04-16 17:21:13 +0000 | [diff] [blame] | 1911 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1912 | /* create a registry key */ |
| 1913 | DECL_HANDLER(create_key) |
| 1914 | { |
Alexandre Julliard | bcf393a | 2000-10-01 01:44:50 +0000 | [diff] [blame] | 1915 | struct key *key = NULL, *parent; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1916 | struct unicode_str name, class; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1917 | unsigned int access = req->access; |
| 1918 | |
Alexandre Julliard | ac08b03 | 2010-03-02 12:03:17 +0100 | [diff] [blame] | 1919 | if (!is_wow64_thread( current )) access = (access & ~KEY_WOW64_32KEY) | KEY_WOW64_64KEY; |
| 1920 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1921 | reply->hkey = 0; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1922 | |
| 1923 | if (req->namelen > get_req_data_size()) |
| 1924 | { |
| 1925 | set_error( STATUS_INVALID_PARAMETER ); |
| 1926 | return; |
| 1927 | } |
| 1928 | class.str = (const WCHAR *)get_req_data() + req->namelen / sizeof(WCHAR); |
| 1929 | class.len = ((get_req_data_size() - req->namelen) / sizeof(WCHAR)) * sizeof(WCHAR); |
| 1930 | get_req_path( &name, !req->parent ); |
| 1931 | if (name.str > class.str) |
| 1932 | { |
| 1933 | set_error( STATUS_INVALID_PARAMETER ); |
| 1934 | return; |
| 1935 | } |
| 1936 | name.len = (class.str - name.str) * sizeof(WCHAR); |
| 1937 | |
Robert Shearman | 8cb3f92 | 2005-06-16 20:34:34 +0000 | [diff] [blame] | 1938 | /* NOTE: no access rights are required from the parent handle to create a key */ |
Alexandre Julliard | dd77d1a | 2006-07-10 11:53:23 +0200 | [diff] [blame] | 1939 | if ((parent = get_parent_hkey_obj( req->parent ))) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1940 | { |
Alexandre Julliard | ac08b03 | 2010-03-02 12:03:17 +0100 | [diff] [blame] | 1941 | if ((key = create_key( parent, &name, &class, req->options, access, |
| 1942 | req->attributes, &reply->created ))) |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 1943 | { |
Alexandre Julliard | 03b040c | 2005-12-09 14:52:04 +0100 | [diff] [blame] | 1944 | reply->hkey = alloc_handle( current->process, key, access, req->attributes ); |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 1945 | release_object( key ); |
| 1946 | } |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1947 | release_object( parent ); |
| 1948 | } |
| 1949 | } |
| 1950 | |
| 1951 | /* open a registry key */ |
| 1952 | DECL_HANDLER(open_key) |
| 1953 | { |
| 1954 | struct key *key, *parent; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1955 | struct unicode_str name; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1956 | unsigned int access = req->access; |
| 1957 | |
Alexandre Julliard | ac08b03 | 2010-03-02 12:03:17 +0100 | [diff] [blame] | 1958 | if (!is_wow64_thread( current )) access = (access & ~KEY_WOW64_32KEY) | KEY_WOW64_64KEY; |
| 1959 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1960 | reply->hkey = 0; |
Robert Shearman | b3957e3 | 2005-05-05 16:57:55 +0000 | [diff] [blame] | 1961 | /* NOTE: no access rights are required to open the parent key, only the child key */ |
Alexandre Julliard | dd77d1a | 2006-07-10 11:53:23 +0200 | [diff] [blame] | 1962 | if ((parent = get_parent_hkey_obj( req->parent ))) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1963 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 1964 | get_req_path( &name, !req->parent ); |
Alexandre Julliard | ac08b03 | 2010-03-02 12:03:17 +0100 | [diff] [blame] | 1965 | if ((key = open_key( parent, &name, access, req->attributes ))) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1966 | { |
Alexandre Julliard | 03b040c | 2005-12-09 14:52:04 +0100 | [diff] [blame] | 1967 | reply->hkey = alloc_handle( current->process, key, access, req->attributes ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1968 | release_object( key ); |
| 1969 | } |
| 1970 | release_object( parent ); |
| 1971 | } |
| 1972 | } |
| 1973 | |
| 1974 | /* delete a registry key */ |
| 1975 | DECL_HANDLER(delete_key) |
| 1976 | { |
| 1977 | struct key *key; |
| 1978 | |
Robert Shearman | b3957e3 | 2005-05-05 16:57:55 +0000 | [diff] [blame] | 1979 | if ((key = get_hkey_obj( req->hkey, DELETE ))) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1980 | { |
Mike McCormack | 5ac945c | 2003-08-19 03:08:17 +0000 | [diff] [blame] | 1981 | delete_key( key, 0); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1982 | release_object( key ); |
| 1983 | } |
| 1984 | } |
| 1985 | |
Mike Hearn | 43cb03b | 2004-01-03 00:38:30 +0000 | [diff] [blame] | 1986 | /* flush a registry key */ |
| 1987 | DECL_HANDLER(flush_key) |
| 1988 | { |
| 1989 | struct key *key = get_hkey_obj( req->hkey, 0 ); |
| 1990 | if (key) |
| 1991 | { |
| 1992 | /* we don't need to do anything here with the current implementation */ |
| 1993 | release_object( key ); |
| 1994 | } |
| 1995 | } |
| 1996 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 1997 | /* enumerate registry subkeys */ |
| 1998 | DECL_HANDLER(enum_key) |
| 1999 | { |
| 2000 | struct key *key; |
| 2001 | |
Alexandre Julliard | 454355e | 2000-10-02 03:46:58 +0000 | [diff] [blame] | 2002 | if ((key = get_hkey_obj( req->hkey, |
| 2003 | req->index == -1 ? KEY_QUERY_VALUE : KEY_ENUMERATE_SUB_KEYS ))) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2004 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2005 | enum_key( key, req->index, req->info_class, reply ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2006 | release_object( key ); |
| 2007 | } |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | /* set a value of a registry key */ |
| 2011 | DECL_HANDLER(set_key_value) |
| 2012 | { |
| 2013 | struct key *key; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 2014 | struct unicode_str name; |
Alexandre Julliard | a01004d | 2000-05-14 22:57:57 +0000 | [diff] [blame] | 2015 | |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 2016 | if (req->namelen > get_req_data_size()) |
| 2017 | { |
| 2018 | set_error( STATUS_INVALID_PARAMETER ); |
| 2019 | return; |
| 2020 | } |
| 2021 | name.str = get_req_data(); |
| 2022 | name.len = (req->namelen / sizeof(WCHAR)) * sizeof(WCHAR); |
| 2023 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2024 | if ((key = get_hkey_obj( req->hkey, KEY_SET_VALUE ))) |
| 2025 | { |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 2026 | data_size_t datalen = get_req_data_size() - req->namelen; |
Eric Pouech | 0a25896 | 2004-11-30 21:38:57 +0000 | [diff] [blame] | 2027 | const char *data = (const char *)get_req_data() + req->namelen; |
Alexandre Julliard | bcf393a | 2000-10-01 01:44:50 +0000 | [diff] [blame] | 2028 | |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 2029 | set_value( key, &name, req->type, data, datalen ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2030 | release_object( key ); |
| 2031 | } |
| 2032 | } |
| 2033 | |
| 2034 | /* retrieve the value of a registry key */ |
| 2035 | DECL_HANDLER(get_key_value) |
| 2036 | { |
| 2037 | struct key *key; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 2038 | struct unicode_str name; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2039 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2040 | reply->total = 0; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2041 | if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE ))) |
| 2042 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 2043 | get_req_unicode_str( &name ); |
| 2044 | get_value( key, &name, &reply->type, &reply->total ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2045 | release_object( key ); |
| 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | /* enumerate the value of a registry key */ |
| 2050 | DECL_HANDLER(enum_key_value) |
| 2051 | { |
| 2052 | struct key *key; |
| 2053 | |
| 2054 | if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE ))) |
| 2055 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 2056 | enum_value( key, req->index, req->info_class, reply ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2057 | release_object( key ); |
| 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | /* delete a value of a registry key */ |
| 2062 | DECL_HANDLER(delete_key_value) |
| 2063 | { |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2064 | struct key *key; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 2065 | struct unicode_str name; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2066 | |
| 2067 | if ((key = get_hkey_obj( req->hkey, KEY_SET_VALUE ))) |
| 2068 | { |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 2069 | get_req_unicode_str( &name ); |
| 2070 | delete_value( key, &name ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2071 | release_object( key ); |
| 2072 | } |
| 2073 | } |
| 2074 | |
| 2075 | /* load a registry branch from a file */ |
| 2076 | DECL_HANDLER(load_registry) |
| 2077 | { |
James Hawkins | 580ded6 | 2005-03-29 11:38:58 +0000 | [diff] [blame] | 2078 | struct key *key, *parent; |
Robert Shearman | b3957e3 | 2005-05-05 16:57:55 +0000 | [diff] [blame] | 2079 | struct token *token = thread_get_impersonation_token( current ); |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 2080 | struct unicode_str name; |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2081 | |
Robert Shearman | b3957e3 | 2005-05-05 16:57:55 +0000 | [diff] [blame] | 2082 | const LUID_AND_ATTRIBUTES privs[] = |
| 2083 | { |
| 2084 | { SeBackupPrivilege, 0 }, |
| 2085 | { SeRestorePrivilege, 0 }, |
| 2086 | }; |
| 2087 | |
| 2088 | if (!token || !token_check_privileges( token, TRUE, privs, |
| 2089 | sizeof(privs)/sizeof(privs[0]), NULL )) |
| 2090 | { |
| 2091 | set_error( STATUS_PRIVILEGE_NOT_HELD ); |
| 2092 | return; |
| 2093 | } |
| 2094 | |
Alexandre Julliard | dd77d1a | 2006-07-10 11:53:23 +0200 | [diff] [blame] | 2095 | if ((parent = get_parent_hkey_obj( req->hkey ))) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2096 | { |
James Hawkins | 580ded6 | 2005-03-29 11:38:58 +0000 | [diff] [blame] | 2097 | int dummy; |
Alexandre Julliard | 7f9e281 | 2005-11-22 12:05:36 +0000 | [diff] [blame] | 2098 | get_req_path( &name, !req->hkey ); |
Alexandre Julliard | ac08b03 | 2010-03-02 12:03:17 +0100 | [diff] [blame] | 2099 | if ((key = create_key( parent, &name, NULL, 0, KEY_WOW64_64KEY, 0, &dummy ))) |
James Hawkins | 580ded6 | 2005-03-29 11:38:58 +0000 | [diff] [blame] | 2100 | { |
| 2101 | load_registry( key, req->file ); |
| 2102 | release_object( key ); |
| 2103 | } |
| 2104 | release_object( parent ); |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2105 | } |
| 2106 | } |
| 2107 | |
Mike McCormack | 5ac945c | 2003-08-19 03:08:17 +0000 | [diff] [blame] | 2108 | DECL_HANDLER(unload_registry) |
| 2109 | { |
| 2110 | struct key *key; |
Robert Shearman | b3957e3 | 2005-05-05 16:57:55 +0000 | [diff] [blame] | 2111 | struct token *token = thread_get_impersonation_token( current ); |
| 2112 | |
| 2113 | const LUID_AND_ATTRIBUTES privs[] = |
| 2114 | { |
| 2115 | { SeBackupPrivilege, 0 }, |
| 2116 | { SeRestorePrivilege, 0 }, |
| 2117 | }; |
| 2118 | |
| 2119 | if (!token || !token_check_privileges( token, TRUE, privs, |
| 2120 | sizeof(privs)/sizeof(privs[0]), NULL )) |
| 2121 | { |
| 2122 | set_error( STATUS_PRIVILEGE_NOT_HELD ); |
| 2123 | return; |
| 2124 | } |
Mike McCormack | 5ac945c | 2003-08-19 03:08:17 +0000 | [diff] [blame] | 2125 | |
| 2126 | if ((key = get_hkey_obj( req->hkey, 0 ))) |
| 2127 | { |
| 2128 | delete_key( key, 1 ); /* FIXME */ |
| 2129 | release_object( key ); |
| 2130 | } |
| 2131 | } |
| 2132 | |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2133 | /* save a registry branch to a file */ |
| 2134 | DECL_HANDLER(save_registry) |
| 2135 | { |
| 2136 | struct key *key; |
| 2137 | |
Robert Shearman | b3957e3 | 2005-05-05 16:57:55 +0000 | [diff] [blame] | 2138 | if (!thread_single_check_privilege( current, &SeBackupPrivilege )) |
| 2139 | { |
| 2140 | set_error( STATUS_PRIVILEGE_NOT_HELD ); |
| 2141 | return; |
| 2142 | } |
| 2143 | |
| 2144 | if ((key = get_hkey_obj( req->hkey, 0 ))) |
Alexandre Julliard | d7e85d6 | 1999-11-23 19:39:11 +0000 | [diff] [blame] | 2145 | { |
| 2146 | save_registry( key, req->file ); |
| 2147 | release_object( key ); |
| 2148 | } |
| 2149 | } |
| 2150 | |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 2151 | /* add a registry key change notification */ |
| 2152 | DECL_HANDLER(set_registry_notification) |
| 2153 | { |
| 2154 | struct key *key; |
| 2155 | struct event *event; |
| 2156 | struct notify *notify; |
| 2157 | |
| 2158 | key = get_hkey_obj( req->hkey, KEY_NOTIFY ); |
Robert Shearman | 3795709 | 2005-06-10 19:54:46 +0000 | [diff] [blame] | 2159 | if (key) |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 2160 | { |
| 2161 | event = get_event_obj( current->process, req->event, SYNCHRONIZE ); |
Robert Shearman | 3795709 | 2005-06-10 19:54:46 +0000 | [diff] [blame] | 2162 | if (event) |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 2163 | { |
Alexandre Julliard | 9b3b7ca | 2005-06-09 20:36:08 +0000 | [diff] [blame] | 2164 | notify = find_notify( key, current->process, req->hkey ); |
Robert Shearman | 3795709 | 2005-06-10 19:54:46 +0000 | [diff] [blame] | 2165 | if (notify) |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 2166 | { |
Mike McCormack | 5fb6e0e | 2006-05-14 17:11:54 +0900 | [diff] [blame] | 2167 | if (notify->event) |
| 2168 | release_object( notify->event ); |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 2169 | grab_object( event ); |
| 2170 | notify->event = event; |
| 2171 | } |
| 2172 | else |
| 2173 | { |
Alexandre Julliard | 68abbc8 | 2005-02-24 19:43:53 +0000 | [diff] [blame] | 2174 | notify = mem_alloc( sizeof(*notify) ); |
Robert Shearman | 3795709 | 2005-06-10 19:54:46 +0000 | [diff] [blame] | 2175 | if (notify) |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 2176 | { |
| 2177 | grab_object( event ); |
| 2178 | notify->event = event; |
| 2179 | notify->subtree = req->subtree; |
| 2180 | notify->filter = req->filter; |
| 2181 | notify->hkey = req->hkey; |
Alexandre Julliard | 9b3b7ca | 2005-06-09 20:36:08 +0000 | [diff] [blame] | 2182 | notify->process = current->process; |
Alexandre Julliard | 68abbc8 | 2005-02-24 19:43:53 +0000 | [diff] [blame] | 2183 | list_add_head( &key->notify_list, ¬ify->entry ); |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 2184 | } |
Mike McCormack | 11f4b44 | 2002-11-25 02:47:32 +0000 | [diff] [blame] | 2185 | } |
| 2186 | release_object( event ); |
| 2187 | } |
| 2188 | release_object( key ); |
| 2189 | } |
| 2190 | } |