2 * Server-side registry management
4 * Copyright (C) 1999 Alexandre Julliard
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.
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.
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
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * - behavior with deleted keys
23 * - values larger than request buffer
28 #include "wine/port.h"
50 #include "wine/library.h"
54 struct event *event; /* event to set when changing this key */
55 int subtree; /* true if subtree notification */
56 unsigned int filter; /* which events to notify on */
57 obj_handle_t hkey; /* hkey associated with this notification */
58 struct notify *next; /* list of notifications */
59 struct notify *prev; /* list of notifications */
65 struct object obj; /* object header */
66 WCHAR *name; /* key name */
67 WCHAR *class; /* key class */
68 struct key *parent; /* parent key */
69 int last_subkey; /* last in use subkey */
70 int nb_subkeys; /* count of allocated subkeys */
71 struct key **subkeys; /* subkeys array */
72 int last_value; /* last in use value */
73 int nb_values; /* count of allocated values in array */
74 struct key_value *values; /* values array */
75 short flags; /* flags */
76 short level; /* saving level */
77 time_t modif; /* last modification time */
78 struct notify *first_notify; /* list of notifications */
79 struct notify *last_notify; /* list of notifications */
83 #define KEY_VOLATILE 0x0001 /* key is volatile (not saved to disk) */
84 #define KEY_DELETED 0x0002 /* key has been deleted */
85 #define KEY_DIRTY 0x0004 /* key has been modified */
86 #define KEY_ROOT 0x0008 /* key is a root key */
91 WCHAR *name; /* value name */
92 int type; /* value type */
93 size_t len; /* value data length in bytes */
94 void *data; /* pointer to value data */
97 #define MIN_SUBKEYS 8 /* min. number of allocated subkeys per key */
98 #define MIN_VALUES 8 /* min. number of allocated values per key */
101 /* the special root keys */
102 #define HKEY_SPECIAL_ROOT_FIRST ((unsigned int)HKEY_CLASSES_ROOT)
103 #define HKEY_SPECIAL_ROOT_LAST ((unsigned int)HKEY_DYN_DATA)
104 #define NB_SPECIAL_ROOT_KEYS (HKEY_SPECIAL_ROOT_LAST - HKEY_SPECIAL_ROOT_FIRST + 1)
105 #define IS_SPECIAL_ROOT_HKEY(h) (((unsigned int)(h) >= HKEY_SPECIAL_ROOT_FIRST) && \
106 ((unsigned int)(h) <= HKEY_SPECIAL_ROOT_LAST))
108 static struct key *special_root_keys[NB_SPECIAL_ROOT_KEYS];
110 /* the real root key */
111 static struct key *root_key;
113 /* the special root key names */
114 static const char * const special_root_names[NB_SPECIAL_ROOT_KEYS] =
116 "Machine\\Software\\Classes", /* HKEY_CLASSES_ROOT */
117 "User\\", /* we append the user name dynamically */ /* HKEY_CURRENT_USER */
118 "Machine", /* HKEY_LOCAL_MACHINE */
119 "User", /* HKEY_USERS */
120 "PerfData", /* HKEY_PERFORMANCE_DATA */
121 "Machine\\System\\CurrentControlSet\\HardwareProfiles\\Current", /* HKEY_CURRENT_CONFIG */
122 "DynData" /* HKEY_DYN_DATA */
126 /* keys saving level */
127 /* current_level is the level that is put into all newly created or modified keys */
128 /* saving_level is the minimum level that a key needs in order to get saved */
129 static int current_level;
130 static int saving_level;
132 static struct timeval next_save_time; /* absolute time of next periodic save */
133 static int save_period; /* delay between periodic saves (ms) */
134 static struct timeout_user *save_timeout_user; /* saving timer */
136 /* information about where to save a registry branch */
137 struct save_branch_info
143 #define MAX_SAVE_BRANCH_INFO 8
144 static int save_branch_count;
145 static struct save_branch_info save_branch_info[MAX_SAVE_BRANCH_INFO];
148 /* information about a file being loaded */
149 struct file_load_info
151 FILE *file; /* input file */
152 char *buffer; /* line buffer */
153 int len; /* buffer length */
154 int line; /* current input line */
155 char *tmp; /* temp buffer to use while parsing input */
156 int tmplen; /* length of temp buffer */
160 static void key_dump( struct object *obj, int verbose );
161 static void key_destroy( struct object *obj );
163 static const struct object_ops key_ops =
165 sizeof(struct key), /* size */
167 no_add_queue, /* add_queue */
168 NULL, /* remove_queue */
170 NULL, /* satisfied */
171 no_get_fd, /* get_fd */
172 key_destroy /* destroy */
177 * The registry text file format v2 used by this code is similar to the one
178 * used by REGEDIT import/export functionality, with the following differences:
179 * - strings and key names can contain \x escapes for Unicode
180 * - key names use escapes too in order to support Unicode
181 * - the modification time optionally follows the key name
182 * - REG_EXPAND_SZ and REG_MULTI_SZ are saved as strings instead of hex
185 static inline char to_hex( char ch )
187 if (isdigit(ch)) return ch - '0';
188 return tolower(ch) - 'a' + 10;
191 /* dump the full path of a key */
192 static void dump_path( const struct key *key, const struct key *base, FILE *f )
194 if (key->parent && key->parent != base)
196 dump_path( key->parent, base, f );
197 fprintf( f, "\\\\" );
199 dump_strW( key->name, strlenW(key->name), f, "[]" );
202 /* dump a value to a text file */
203 static void dump_value( const struct key_value *value, FILE *f )
210 count = 1 + dump_strW( value->name, strlenW(value->name), f, "\"\"" );
211 count += fprintf( f, "\"=" );
213 else count = fprintf( f, "@=" );
220 if (value->type != REG_SZ) fprintf( f, "str(%d):", value->type );
222 if (value->data) dump_strW( (WCHAR *)value->data, value->len / sizeof(WCHAR), f, "\"\"" );
226 if (value->len == sizeof(DWORD))
229 memcpy( &dw, value->data, sizeof(DWORD) );
230 fprintf( f, "dword:%08lx", dw );
233 /* else fall through */
235 if (value->type == REG_BINARY) count += fprintf( f, "hex:" );
236 else count += fprintf( f, "hex(%x):", value->type );
237 for (i = 0; i < value->len; i++)
239 count += fprintf( f, "%02x", *((unsigned char *)value->data + i) );
240 if (i < value->len-1)
245 fprintf( f, "\\\n " );
255 /* save a registry and all its subkeys to a text file */
256 static void save_subkeys( const struct key *key, const struct key *base, FILE *f )
260 if (key->flags & KEY_VOLATILE) return;
261 /* save key if it has the proper level, and has either some values or no subkeys */
262 /* keys with no values but subkeys are saved implicitly by saving the subkeys */
263 if ((key->level >= saving_level) && ((key->last_value >= 0) || (key->last_subkey == -1)))
266 if (key != base) dump_path( key, base, f );
267 fprintf( f, "] %ld\n", key->modif );
268 for (i = 0; i <= key->last_value; i++) dump_value( &key->values[i], f );
270 for (i = 0; i <= key->last_subkey; i++) save_subkeys( key->subkeys[i], base, f );
273 static void dump_operation( const struct key *key, const struct key_value *value, const char *op )
275 fprintf( stderr, "%s key ", op );
276 if (key) dump_path( key, NULL, stderr );
277 else fprintf( stderr, "ERROR" );
280 fprintf( stderr, " value ");
281 dump_value( value, stderr );
283 else fprintf( stderr, "\n" );
286 static void key_dump( struct object *obj, int verbose )
288 struct key *key = (struct key *)obj;
289 assert( obj->ops == &key_ops );
290 fprintf( stderr, "Key flags=%x ", key->flags );
291 dump_path( key, NULL, stderr );
292 fprintf( stderr, "\n" );
295 /* notify waiter and maybe delete the notification */
296 static void do_notification( struct key *key, struct notify *notify, int del )
300 set_event( notify->event );
301 release_object( notify->event );
302 notify->event = NULL;
308 notify->next->prev = notify->prev;
310 key->last_notify = notify->prev;
312 notify->prev->next = notify->next;
314 key->first_notify = notify->next;
318 static struct notify *find_notify( struct key *key, obj_handle_t hkey)
322 for( n=key->first_notify; n; n = n->next)
323 if( n->hkey == hkey )
328 /* close the notification associated with a handle */
329 void registry_close_handle( struct object *obj, obj_handle_t hkey )
331 struct key * key = (struct key *) obj;
332 struct notify *notify;
334 if( obj->ops != &key_ops )
336 notify = find_notify( key, hkey );
339 do_notification( key, notify, 1 );
342 static void key_destroy( struct object *obj )
345 struct key *key = (struct key *)obj;
346 assert( obj->ops == &key_ops );
348 if (key->name) free( key->name );
349 if (key->class) free( key->class );
350 for (i = 0; i <= key->last_value; i++)
352 free( key->values[i].name );
353 if (key->values[i].data) free( key->values[i].data );
355 for (i = 0; i <= key->last_subkey; i++)
357 key->subkeys[i]->parent = NULL;
358 release_object( key->subkeys[i] );
360 /* unconditionally notify everything waiting on this key */
361 while ( key->first_notify )
362 do_notification( key, key->first_notify, 1 );
365 /* duplicate a key path */
366 /* returns a pointer to a static buffer, so only useable once per request */
367 static WCHAR *copy_path( const WCHAR *path, size_t len, int skip_root )
369 static WCHAR buffer[MAX_PATH+1];
370 static const WCHAR root_name[] = { '\\','R','e','g','i','s','t','r','y','\\',0 };
372 if (len > sizeof(buffer)-sizeof(buffer[0]))
374 set_error( STATUS_BUFFER_OVERFLOW );
377 memcpy( buffer, path, len );
378 buffer[len / sizeof(WCHAR)] = 0;
379 if (skip_root && !strncmpiW( buffer, root_name, 10 )) return buffer + 10;
383 /* copy a path from the request buffer */
384 static WCHAR *copy_req_path( size_t len, int skip_root )
386 const WCHAR *name_ptr = get_req_data();
387 if (len > get_req_data_size())
389 fatal_protocol_error( current, "copy_req_path: invalid length %d/%d\n",
390 len, get_req_data_size() );
393 return copy_path( name_ptr, len, skip_root );
396 /* return the next token in a given path */
397 /* returns a pointer to a static buffer, so only useable once per request */
398 static WCHAR *get_path_token( WCHAR *initpath )
405 /* path cannot start with a backslash */
406 if (*initpath == '\\')
408 set_error( STATUS_OBJECT_PATH_INVALID );
413 else while (*path == '\\') path++;
416 while (*path && *path != '\\') path++;
417 if (*path) *path++ = 0;
421 /* duplicate a Unicode string from the request buffer */
422 static WCHAR *req_strdupW( const void *req, const WCHAR *str, size_t len )
425 if ((name = mem_alloc( len + sizeof(WCHAR) )) != NULL)
427 memcpy( name, str, len );
428 name[len / sizeof(WCHAR)] = 0;
433 /* allocate a key object */
434 static struct key *alloc_key( const WCHAR *name, time_t modif )
437 if ((key = (struct key *)alloc_object( &key_ops, -1 )))
441 key->last_subkey = -1;
445 key->last_value = -1;
447 key->level = current_level;
450 key->first_notify = NULL;
451 key->last_notify = NULL;
452 if (!(key->name = strdupW( name )))
454 release_object( key );
461 /* mark a key and all its parents as dirty (modified) */
462 static void make_dirty( struct key *key )
466 if (key->flags & (KEY_DIRTY|KEY_VOLATILE)) return; /* nothing to do */
467 key->flags |= KEY_DIRTY;
472 /* mark a key and all its subkeys as clean (not modified) */
473 static void make_clean( struct key *key )
477 if (key->flags & KEY_VOLATILE) return;
478 if (!(key->flags & KEY_DIRTY)) return;
479 key->flags &= ~KEY_DIRTY;
480 for (i = 0; i <= key->last_subkey; i++) make_clean( key->subkeys[i] );
483 /* go through all the notifications and send them if necessary */
484 void check_notify( struct key *key, unsigned int change, int not_subtree )
486 struct notify *n = key->first_notify;
489 struct notify *next = n->next;
490 if ( ( not_subtree || n->subtree ) && ( change & n->filter ) )
491 do_notification( key, n, 0 );
496 /* update key modification time */
497 static void touch_key( struct key *key, unsigned int change )
501 key->modif = time(NULL);
502 key->level = max( key->level, current_level );
505 /* do notifications */
506 check_notify( key, change, 1 );
507 for ( k = key->parent; k; k = k->parent )
508 check_notify( k, change & ~REG_NOTIFY_CHANGE_LAST_SET, 0 );
511 /* try to grow the array of subkeys; return 1 if OK, 0 on error */
512 static int grow_subkeys( struct key *key )
514 struct key **new_subkeys;
519 nb_subkeys = key->nb_subkeys + (key->nb_subkeys / 2); /* grow by 50% */
520 if (!(new_subkeys = realloc( key->subkeys, nb_subkeys * sizeof(*new_subkeys) )))
522 set_error( STATUS_NO_MEMORY );
528 nb_subkeys = MIN_VALUES;
529 if (!(new_subkeys = mem_alloc( nb_subkeys * sizeof(*new_subkeys) ))) return 0;
531 key->subkeys = new_subkeys;
532 key->nb_subkeys = nb_subkeys;
536 /* allocate a subkey for a given key, and return its index */
537 static struct key *alloc_subkey( struct key *parent, const WCHAR *name, int index, time_t modif )
542 if (parent->last_subkey + 1 == parent->nb_subkeys)
544 /* need to grow the array */
545 if (!grow_subkeys( parent )) return NULL;
547 if ((key = alloc_key( name, modif )) != NULL)
549 key->parent = parent;
550 for (i = ++parent->last_subkey; i > index; i--)
551 parent->subkeys[i] = parent->subkeys[i-1];
552 parent->subkeys[index] = key;
557 /* free a subkey of a given key */
558 static void free_subkey( struct key *parent, int index )
563 assert( index >= 0 );
564 assert( index <= parent->last_subkey );
566 key = parent->subkeys[index];
567 for (i = index; i < parent->last_subkey; i++) parent->subkeys[i] = parent->subkeys[i + 1];
568 parent->last_subkey--;
569 key->flags |= KEY_DELETED;
571 release_object( key );
573 /* try to shrink the array */
574 nb_subkeys = parent->nb_subkeys;
575 if (nb_subkeys > MIN_SUBKEYS && parent->last_subkey < nb_subkeys / 2)
577 struct key **new_subkeys;
578 nb_subkeys -= nb_subkeys / 3; /* shrink by 33% */
579 if (nb_subkeys < MIN_SUBKEYS) nb_subkeys = MIN_SUBKEYS;
580 if (!(new_subkeys = realloc( parent->subkeys, nb_subkeys * sizeof(*new_subkeys) ))) return;
581 parent->subkeys = new_subkeys;
582 parent->nb_subkeys = nb_subkeys;
586 /* find the named child of a given key and return its index */
587 static struct key *find_subkey( const struct key *key, const WCHAR *name, int *index )
589 int i, min, max, res;
592 max = key->last_subkey;
596 if (!(res = strcmpiW( key->subkeys[i]->name, name )))
599 return key->subkeys[i];
601 if (res > 0) max = i - 1;
604 *index = min; /* this is where we should insert it */
609 /* warning: the key name must be writeable (use copy_path) */
610 static struct key *open_key( struct key *key, WCHAR *name )
615 if (!(path = get_path_token( name ))) return NULL;
618 if (!(key = find_subkey( key, path, &index )))
620 set_error( STATUS_OBJECT_NAME_NOT_FOUND );
623 path = get_path_token( NULL );
626 if (debug_level > 1) dump_operation( key, NULL, "Open" );
627 if (key) grab_object( key );
631 /* create a subkey */
632 /* warning: the key name must be writeable (use copy_path) */
633 static struct key *create_key( struct key *key, WCHAR *name, WCHAR *class,
634 int flags, time_t modif, int *created )
640 if (key->flags & KEY_DELETED) /* we cannot create a subkey under a deleted key */
642 set_error( STATUS_KEY_DELETED );
645 if (!(flags & KEY_VOLATILE) && (key->flags & KEY_VOLATILE))
647 set_error( STATUS_CHILD_MUST_BE_VOLATILE );
650 if (!modif) modif = time(NULL);
652 if (!(path = get_path_token( name ))) return NULL;
657 if (!(subkey = find_subkey( key, path, &index ))) break;
659 path = get_path_token( NULL );
662 /* create the remaining part */
664 if (!*path) goto done;
666 touch_key( key, REG_NOTIFY_CHANGE_NAME ); /* FIXME: is this right? */
667 if (flags & KEY_DIRTY) make_dirty( key );
670 key = alloc_subkey( key, path, index, modif );
674 path = get_path_token( NULL );
675 if (!*path) goto done;
676 /* we know the index is always 0 in a new key */
677 key = alloc_subkey( key, path, 0, modif );
679 if (base_idx != -1) free_subkey( base, base_idx );
683 if (debug_level > 1) dump_operation( key, NULL, "Create" );
684 if (class) key->class = strdupW(class);
689 /* query information about a key or a subkey */
690 static void enum_key( const struct key *key, int index, int info_class,
691 struct enum_key_reply *reply )
694 size_t len, namelen, classlen;
695 int max_subkey = 0, max_class = 0;
696 int max_value = 0, max_data = 0;
699 if (index != -1) /* -1 means use the specified key directly */
701 if ((index < 0) || (index > key->last_subkey))
703 set_error( STATUS_NO_MORE_ENTRIES );
706 key = key->subkeys[index];
709 namelen = strlenW(key->name) * sizeof(WCHAR);
710 classlen = key->class ? strlenW(key->class) * sizeof(WCHAR) : 0;
714 case KeyBasicInformation:
715 classlen = 0; /* only return the name */
717 case KeyNodeInformation:
718 reply->max_subkey = 0;
719 reply->max_class = 0;
720 reply->max_value = 0;
723 case KeyFullInformation:
724 for (i = 0; i <= key->last_subkey; i++)
726 struct key *subkey = key->subkeys[i];
727 len = strlenW( subkey->name );
728 if (len > max_subkey) max_subkey = len;
729 if (!subkey->class) continue;
730 len = strlenW( subkey->class );
731 if (len > max_class) max_class = len;
733 for (i = 0; i <= key->last_value; i++)
735 len = strlenW( key->values[i].name );
736 if (len > max_value) max_value = len;
737 len = key->values[i].len;
738 if (len > max_data) max_data = len;
740 reply->max_subkey = max_subkey;
741 reply->max_class = max_class;
742 reply->max_value = max_value;
743 reply->max_data = max_data;
744 namelen = 0; /* only return the class */
747 set_error( STATUS_INVALID_PARAMETER );
750 reply->subkeys = key->last_subkey + 1;
751 reply->values = key->last_value + 1;
752 reply->modif = key->modif;
753 reply->total = namelen + classlen;
755 len = min( reply->total, get_reply_max_size() );
756 if (len && (data = set_reply_data_size( len )))
760 reply->namelen = namelen;
761 memcpy( data, key->name, namelen );
762 memcpy( (char *)data + namelen, key->class, len - namelen );
766 reply->namelen = len;
767 memcpy( data, key->name, len );
770 if (debug_level > 1) dump_operation( key, NULL, "Enum" );
773 /* delete a key and its values */
774 static void delete_key( struct key *key )
779 /* must find parent and index */
780 if (key->flags & KEY_ROOT)
782 set_error( STATUS_ACCESS_DENIED );
785 if (!(parent = key->parent) || (key->flags & KEY_DELETED))
787 set_error( STATUS_KEY_DELETED );
790 for (index = 0; index <= parent->last_subkey; index++)
791 if (parent->subkeys[index] == key) break;
792 assert( index <= parent->last_subkey );
794 /* we can only delete a key that has no subkeys (FIXME) */
795 if ((key->flags & KEY_ROOT) || (key->last_subkey >= 0))
797 set_error( STATUS_ACCESS_DENIED );
800 if (debug_level > 1) dump_operation( key, NULL, "Delete" );
801 free_subkey( parent, index );
802 touch_key( parent, REG_NOTIFY_CHANGE_NAME );
805 /* try to grow the array of values; return 1 if OK, 0 on error */
806 static int grow_values( struct key *key )
808 struct key_value *new_val;
813 nb_values = key->nb_values + (key->nb_values / 2); /* grow by 50% */
814 if (!(new_val = realloc( key->values, nb_values * sizeof(*new_val) )))
816 set_error( STATUS_NO_MEMORY );
822 nb_values = MIN_VALUES;
823 if (!(new_val = mem_alloc( nb_values * sizeof(*new_val) ))) return 0;
825 key->values = new_val;
826 key->nb_values = nb_values;
830 /* find the named value of a given key and return its index in the array */
831 static struct key_value *find_value( const struct key *key, const WCHAR *name, int *index )
833 int i, min, max, res;
836 max = key->last_value;
840 if (!(res = strcmpiW( key->values[i].name, name )))
843 return &key->values[i];
845 if (res > 0) max = i - 1;
848 *index = min; /* this is where we should insert it */
852 /* insert a new value; the index must have been returned by find_value */
853 static struct key_value *insert_value( struct key *key, const WCHAR *name, int index )
855 struct key_value *value;
859 if (key->last_value + 1 == key->nb_values)
861 if (!grow_values( key )) return NULL;
863 if (!(new_name = strdupW(name))) return NULL;
864 for (i = ++key->last_value; i > index; i--) key->values[i] = key->values[i - 1];
865 value = &key->values[index];
866 value->name = new_name;
872 /* set a key value */
873 static void set_value( struct key *key, WCHAR *name, int type, const void *data, size_t len )
875 struct key_value *value;
879 if ((value = find_value( key, name, &index )))
881 /* check if the new value is identical to the existing one */
882 if (value->type == type && value->len == len &&
883 value->data && !memcmp( value->data, data, len ))
885 if (debug_level > 1) dump_operation( key, value, "Skip setting" );
890 if (len && !(ptr = memdup( data, len ))) return;
894 if (!(value = insert_value( key, name, index )))
896 if (ptr) free( ptr );
900 else if (value->data) free( value->data ); /* already existing, free previous data */
905 touch_key( key, REG_NOTIFY_CHANGE_LAST_SET );
906 if (debug_level > 1) dump_operation( key, value, "Set" );
909 /* get a key value */
910 static void get_value( struct key *key, const WCHAR *name, int *type, int *len )
912 struct key_value *value;
915 if ((value = find_value( key, name, &index )))
919 if (value->data) set_reply_data( value->data, min( value->len, get_reply_max_size() ));
920 if (debug_level > 1) dump_operation( key, value, "Get" );
925 set_error( STATUS_OBJECT_NAME_NOT_FOUND );
929 /* enumerate a key value */
930 static void enum_value( struct key *key, int i, int info_class, struct enum_key_value_reply *reply )
932 struct key_value *value;
934 if (i < 0 || i > key->last_value) set_error( STATUS_NO_MORE_ENTRIES );
938 size_t namelen, maxlen;
940 value = &key->values[i];
941 reply->type = value->type;
942 namelen = strlenW( value->name ) * sizeof(WCHAR);
946 case KeyValueBasicInformation:
947 reply->total = namelen;
949 case KeyValueFullInformation:
950 reply->total = namelen + value->len;
952 case KeyValuePartialInformation:
953 reply->total = value->len;
957 set_error( STATUS_INVALID_PARAMETER );
961 maxlen = min( reply->total, get_reply_max_size() );
962 if (maxlen && ((data = set_reply_data_size( maxlen ))))
964 if (maxlen > namelen)
966 reply->namelen = namelen;
967 memcpy( data, value->name, namelen );
968 memcpy( (char *)data + namelen, value->data, maxlen - namelen );
972 reply->namelen = maxlen;
973 memcpy( data, value->name, maxlen );
976 if (debug_level > 1) dump_operation( key, value, "Enum" );
981 static void delete_value( struct key *key, const WCHAR *name )
983 struct key_value *value;
984 int i, index, nb_values;
986 if (!(value = find_value( key, name, &index )))
988 set_error( STATUS_OBJECT_NAME_NOT_FOUND );
991 if (debug_level > 1) dump_operation( key, value, "Delete" );
993 if (value->data) free( value->data );
994 for (i = index; i < key->last_value; i++) key->values[i] = key->values[i + 1];
996 touch_key( key, REG_NOTIFY_CHANGE_LAST_SET );
998 /* try to shrink the array */
999 nb_values = key->nb_values;
1000 if (nb_values > MIN_VALUES && key->last_value < nb_values / 2)
1002 struct key_value *new_val;
1003 nb_values -= nb_values / 3; /* shrink by 33% */
1004 if (nb_values < MIN_VALUES) nb_values = MIN_VALUES;
1005 if (!(new_val = realloc( key->values, nb_values * sizeof(*new_val) ))) return;
1006 key->values = new_val;
1007 key->nb_values = nb_values;
1011 static struct key *create_root_key( obj_handle_t hkey )
1018 p = special_root_names[(unsigned int)hkey - HKEY_SPECIAL_ROOT_FIRST];
1020 while (*p) keyname[i++] = *p++;
1022 if (hkey == (obj_handle_t)HKEY_CURRENT_USER) /* this one is special */
1024 /* get the current user name */
1025 p = wine_get_user_name();
1026 while (*p && i < sizeof(keyname)/sizeof(WCHAR)-1) keyname[i++] = *p++;
1030 if ((key = create_key( root_key, keyname, NULL, 0, time(NULL), &dummy )))
1032 special_root_keys[(unsigned int)hkey - HKEY_SPECIAL_ROOT_FIRST] = key;
1033 key->flags |= KEY_ROOT;
1038 /* get the registry key corresponding to an hkey handle */
1039 static struct key *get_hkey_obj( obj_handle_t hkey, unsigned int access )
1043 if (!hkey) return (struct key *)grab_object( root_key );
1044 if (IS_SPECIAL_ROOT_HKEY(hkey))
1046 if (!(key = special_root_keys[(unsigned int)hkey - HKEY_SPECIAL_ROOT_FIRST]))
1047 key = create_root_key( hkey );
1052 key = (struct key *)get_handle_obj( current->process, hkey, access, &key_ops );
1056 /* read a line from the input file */
1057 static int read_next_line( struct file_load_info *info )
1060 int newlen, pos = 0;
1065 if (!fgets( info->buffer + pos, info->len - pos, info->file ))
1066 return (pos != 0); /* EOF */
1067 pos = strlen(info->buffer);
1068 if (info->buffer[pos-1] == '\n')
1070 /* got a full line */
1071 info->buffer[--pos] = 0;
1072 if (pos > 0 && info->buffer[pos-1] == '\r') info->buffer[pos-1] = 0;
1075 if (pos < info->len - 1) return 1; /* EOF but something was read */
1077 /* need to enlarge the buffer */
1078 newlen = info->len + info->len / 2;
1079 if (!(newbuf = realloc( info->buffer, newlen )))
1081 set_error( STATUS_NO_MEMORY );
1084 info->buffer = newbuf;
1089 /* make sure the temp buffer holds enough space */
1090 static int get_file_tmp_space( struct file_load_info *info, int size )
1093 if (info->tmplen >= size) return 1;
1094 if (!(tmp = realloc( info->tmp, size )))
1096 set_error( STATUS_NO_MEMORY );
1100 info->tmplen = size;
1104 /* report an error while loading an input file */
1105 static void file_read_error( const char *err, struct file_load_info *info )
1107 fprintf( stderr, "Line %d: %s '%s'\n", info->line, err, info->buffer );
1110 /* parse an escaped string back into Unicode */
1111 /* return the number of chars read from the input, or -1 on output overflow */
1112 static int parse_strW( WCHAR *dest, int *len, const char *src, char endchar )
1114 int count = sizeof(WCHAR); /* for terminating null */
1115 const char *p = src;
1116 while (*p && *p != endchar)
1118 if (*p != '\\') *dest = (WCHAR)*p++;
1124 case 'a': *dest = '\a'; p++; break;
1125 case 'b': *dest = '\b'; p++; break;
1126 case 'e': *dest = '\e'; p++; break;
1127 case 'f': *dest = '\f'; p++; break;
1128 case 'n': *dest = '\n'; p++; break;
1129 case 'r': *dest = '\r'; p++; break;
1130 case 't': *dest = '\t'; p++; break;
1131 case 'v': *dest = '\v'; p++; break;
1132 case 'x': /* hex escape */
1134 if (!isxdigit(*p)) *dest = 'x';
1137 *dest = to_hex(*p++);
1138 if (isxdigit(*p)) *dest = (*dest * 16) + to_hex(*p++);
1139 if (isxdigit(*p)) *dest = (*dest * 16) + to_hex(*p++);
1140 if (isxdigit(*p)) *dest = (*dest * 16) + to_hex(*p++);
1150 case '7': /* octal escape */
1152 if (*p >= '0' && *p <= '7') *dest = (*dest * 8) + (*p++ - '0');
1153 if (*p >= '0' && *p <= '7') *dest = (*dest * 8) + (*p++ - '0');
1156 *dest = (WCHAR)*p++;
1160 if ((count += sizeof(WCHAR)) > *len) return -1; /* dest buffer overflow */
1164 if (!*p) return -1; /* delimiter not found */
1169 /* convert a data type tag to a value type */
1170 static int get_data_type( const char *buffer, int *type, int *parse_type )
1172 struct data_type { const char *tag; int len; int type; int parse_type; };
1174 static const struct data_type data_types[] =
1175 { /* actual type */ /* type to assume for parsing */
1176 { "\"", 1, REG_SZ, REG_SZ },
1177 { "str:\"", 5, REG_SZ, REG_SZ },
1178 { "str(2):\"", 8, REG_EXPAND_SZ, REG_SZ },
1179 { "str(7):\"", 8, REG_MULTI_SZ, REG_SZ },
1180 { "hex:", 4, REG_BINARY, REG_BINARY },
1181 { "dword:", 6, REG_DWORD, REG_DWORD },
1182 { "hex(", 4, -1, REG_BINARY },
1186 const struct data_type *ptr;
1189 for (ptr = data_types; ptr->tag; ptr++)
1191 if (memcmp( ptr->tag, buffer, ptr->len )) continue;
1192 *parse_type = ptr->parse_type;
1193 if ((*type = ptr->type) != -1) return ptr->len;
1194 /* "hex(xx):" is special */
1195 *type = (int)strtoul( buffer + 4, &end, 16 );
1196 if ((end <= buffer) || memcmp( end, "):", 2 )) return 0;
1197 return end + 2 - buffer;
1202 /* load and create a key from the input file */
1203 static struct key *load_key( struct key *base, const char *buffer, int flags,
1204 int prefix_len, struct file_load_info *info )
1207 int res, len, modif;
1209 len = strlen(buffer) * sizeof(WCHAR);
1210 if (!get_file_tmp_space( info, len )) return NULL;
1212 if ((res = parse_strW( (WCHAR *)info->tmp, &len, buffer, ']' )) == -1)
1214 file_read_error( "Malformed key", info );
1217 if (sscanf( buffer + res, " %d", &modif ) != 1) modif = time(NULL);
1219 p = (WCHAR *)info->tmp;
1220 while (prefix_len && *p) { if (*p++ == '\\') prefix_len--; }
1226 file_read_error( "Malformed key", info );
1229 /* empty key name, return base key */
1230 return (struct key *)grab_object( base );
1232 if (!(name = copy_path( p, len - ((char *)p - info->tmp), 0 )))
1234 file_read_error( "Key is too long", info );
1237 return create_key( base, name, NULL, flags, modif, &res );
1240 /* parse a comma-separated list of hex digits */
1241 static int parse_hex( unsigned char *dest, int *len, const char *buffer )
1243 const char *p = buffer;
1245 while (isxdigit(*p))
1249 memcpy( buf, p, 2 );
1251 sscanf( buf, "%x", &val );
1252 if (count++ >= *len) return -1; /* dest buffer overflow */
1253 *dest++ = (unsigned char )val;
1261 /* parse a value name and create the corresponding value */
1262 static struct key_value *parse_value_name( struct key *key, const char *buffer, int *len,
1263 struct file_load_info *info )
1265 struct key_value *value;
1268 maxlen = strlen(buffer) * sizeof(WCHAR);
1269 if (!get_file_tmp_space( info, maxlen )) return NULL;
1270 if (buffer[0] == '@')
1272 info->tmp[0] = info->tmp[1] = 0;
1277 if ((*len = parse_strW( (WCHAR *)info->tmp, &maxlen, buffer + 1, '\"' )) == -1) goto error;
1278 (*len)++; /* for initial quote */
1280 while (isspace(buffer[*len])) (*len)++;
1281 if (buffer[*len] != '=') goto error;
1283 while (isspace(buffer[*len])) (*len)++;
1284 if (!(value = find_value( key, (WCHAR *)info->tmp, &index )))
1285 value = insert_value( key, (WCHAR *)info->tmp, index );
1289 file_read_error( "Malformed value name", info );
1293 /* load a value from the input file */
1294 static int load_value( struct key *key, const char *buffer, struct file_load_info *info )
1298 int maxlen, len, res;
1299 int type, parse_type;
1300 struct key_value *value;
1302 if (!(value = parse_value_name( key, buffer, &len, info ))) return 0;
1303 if (!(res = get_data_type( buffer + len, &type, &parse_type ))) goto error;
1304 buffer += len + res;
1309 len = strlen(buffer) * sizeof(WCHAR);
1310 if (!get_file_tmp_space( info, len )) return 0;
1311 if ((res = parse_strW( (WCHAR *)info->tmp, &len, buffer, '\"' )) == -1) goto error;
1315 dw = strtoul( buffer, NULL, 16 );
1319 case REG_BINARY: /* hex digits */
1323 maxlen = 1 + strlen(buffer)/3; /* 3 chars for one hex byte */
1324 if (!get_file_tmp_space( info, len + maxlen )) return 0;
1325 if ((res = parse_hex( info->tmp + len, &maxlen, buffer )) == -1) goto error;
1328 while (isspace(*buffer)) buffer++;
1329 if (!*buffer) break;
1330 if (*buffer != '\\') goto error;
1331 if (read_next_line( info) != 1) goto error;
1332 buffer = info->buffer;
1333 while (isspace(*buffer)) buffer++;
1339 ptr = NULL; /* keep compiler quiet */
1343 if (!len) newptr = NULL;
1344 else if (!(newptr = memdup( ptr, len ))) return 0;
1346 if (value->data) free( value->data );
1347 value->data = newptr;
1350 /* update the key level but not the modification time */
1351 key->level = max( key->level, current_level );
1356 file_read_error( "Malformed value", info );
1360 /* return the length (in path elements) of name that is part of the key name */
1361 /* for instance if key is USER\foo\bar and name is foo\bar\baz, return 2 */
1362 static int get_prefix_len( struct key *key, const char *name, struct file_load_info *info )
1366 int len = strlen(name) * sizeof(WCHAR);
1367 if (!get_file_tmp_space( info, len )) return 0;
1369 if ((res = parse_strW( (WCHAR *)info->tmp, &len, name, ']' )) == -1)
1371 file_read_error( "Malformed key", info );
1374 for (p = (WCHAR *)info->tmp; *p; p++) if (*p == '\\') break;
1376 for (res = 1; key != root_key; res++)
1378 if (!strcmpiW( (WCHAR *)info->tmp, key->name )) break;
1381 if (key == root_key) res = 0; /* no matching name */
1385 /* load all the keys from the input file */
1386 static void load_keys( struct key *key, FILE *f )
1388 struct key *subkey = NULL;
1389 struct file_load_info info;
1391 int flags = (key->flags & KEY_VOLATILE) ? KEY_VOLATILE : KEY_DIRTY;
1392 int prefix_len = -1; /* number of key name prefixes to skip */
1398 if (!(info.buffer = mem_alloc( info.len ))) return;
1399 if (!(info.tmp = mem_alloc( info.tmplen )))
1401 free( info.buffer );
1405 if ((read_next_line( &info ) != 1) ||
1406 strcmp( info.buffer, "WINE REGISTRY Version 2" ))
1408 set_error( STATUS_NOT_REGISTRY_FILE );
1412 while (read_next_line( &info ) == 1)
1415 while (*p && isspace(*p)) p++;
1418 case '[': /* new key */
1419 if (subkey) release_object( subkey );
1420 if (prefix_len == -1) prefix_len = get_prefix_len( key, p + 1, &info );
1421 if (!(subkey = load_key( key, p + 1, flags, prefix_len, &info )))
1422 file_read_error( "Error creating key", &info );
1424 case '@': /* default value */
1425 case '\"': /* value */
1426 if (subkey) load_value( subkey, p, &info );
1427 else file_read_error( "Value without key", &info );
1429 case '#': /* comment */
1430 case ';': /* comment */
1431 case 0: /* empty line */
1434 file_read_error( "Unrecognized input", &info );
1440 if (subkey) release_object( subkey );
1441 free( info.buffer );
1445 /* load a part of the registry from a file */
1446 static void load_registry( struct key *key, obj_handle_t handle )
1451 if (!(file = get_file_obj( current->process, handle, GENERIC_READ ))) return;
1452 fd = dup( get_file_unix_fd( file ) );
1453 release_object( file );
1456 FILE *f = fdopen( fd, "r" );
1459 load_keys( key, f );
1462 else file_set_error();
1466 /* registry initialisation */
1467 void init_registry(void)
1469 static const WCHAR root_name[] = { 0 };
1470 static const WCHAR config_name[] =
1471 { 'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e','\\',
1472 'W','i','n','e','\\','W','i','n','e','\\','C','o','n','f','i','g',0 };
1478 /* create the root key */
1479 root_key = alloc_key( root_name, time(NULL) );
1481 root_key->flags |= KEY_ROOT;
1483 /* load the config file */
1484 config = wine_get_config_dir();
1485 if (!(filename = malloc( strlen(config) + 8 ))) fatal_error( "out of memory\n" );
1486 strcpy( filename, config );
1487 strcat( filename, "/config" );
1488 if ((f = fopen( filename, "r" )))
1493 /* create the config key */
1494 if (!(key = create_key( root_key, copy_path( config_name, sizeof(config_name), 0 ),
1495 NULL, 0, time(NULL), &dummy )))
1496 fatal_error( "could not create config key\n" );
1497 key->flags |= KEY_VOLATILE;
1499 load_keys( key, f );
1501 if (get_error() == STATUS_NOT_REGISTRY_FILE)
1502 fatal_error( "%s is not a valid registry file\n", filename );
1504 fatal_error( "loading %s failed with error %x\n", filename, get_error() );
1506 release_object( key );
1511 /* update the level of the parents of a key (only needed for the old format) */
1512 static int update_level( struct key *key )
1515 int max = key->level;
1516 for (i = 0; i <= key->last_subkey; i++)
1518 int sub = update_level( key->subkeys[i] );
1519 if (sub > max) max = sub;
1525 /* save a registry branch to a file */
1526 static void save_all_subkeys( struct key *key, FILE *f )
1528 fprintf( f, "WINE REGISTRY Version 2\n" );
1529 fprintf( f, ";; All keys relative to " );
1530 dump_path( key, NULL, f );
1532 save_subkeys( key, key, f );
1535 /* save a registry branch to a file handle */
1536 static void save_registry( struct key *key, obj_handle_t handle )
1541 if (key->flags & KEY_DELETED)
1543 set_error( STATUS_KEY_DELETED );
1546 if (!(file = get_file_obj( current->process, handle, GENERIC_WRITE ))) return;
1547 fd = dup( get_file_unix_fd( file ) );
1548 release_object( file );
1551 FILE *f = fdopen( fd, "w" );
1554 save_all_subkeys( key, f );
1555 if (fclose( f )) file_set_error();
1565 /* register a key branch for being saved on exit */
1566 static void register_branch_for_saving( struct key *key, const char *path, size_t len )
1568 if (save_branch_count >= MAX_SAVE_BRANCH_INFO)
1570 set_error( STATUS_NO_MORE_ENTRIES );
1573 if (!len || !(save_branch_info[save_branch_count].path = memdup( path, len ))) return;
1574 save_branch_info[save_branch_count].path[len - 1] = 0;
1575 save_branch_info[save_branch_count].key = (struct key *)grab_object( key );
1576 save_branch_count++;
1579 /* save a registry branch to a file */
1580 static int save_branch( struct key *key, const char *path )
1583 char *p, *real, *tmp = NULL;
1584 int fd, count = 0, ret = 0, by_symlink;
1587 if (!(key->flags & KEY_DIRTY))
1589 if (debug_level > 1) dump_operation( key, NULL, "Not saving clean" );
1593 /* get the real path */
1595 by_symlink = (!lstat(path, &st) && S_ISLNK (st.st_mode));
1596 if (!(real = malloc( PATH_MAX ))) return 0;
1597 if (!realpath( path, real ))
1604 /* test the file type */
1606 if ((fd = open( path, O_WRONLY )) != -1)
1608 /* if file is not a regular file or has multiple links or is accessed
1609 * via symbolic links, write directly into it; otherwise use a temp file */
1611 (!fstat( fd, &st ) && (!S_ISREG(st.st_mode) || st.st_nlink > 1)))
1619 /* create a temp file in the same directory */
1621 if (!(tmp = malloc( strlen(path) + 20 ))) goto done;
1622 strcpy( tmp, path );
1623 if ((p = strrchr( tmp, '/' ))) p++;
1627 sprintf( p, "reg%lx%04x.tmp", (long) getpid(), count++ );
1628 if ((fd = open( tmp, O_CREAT | O_EXCL | O_WRONLY, 0666 )) != -1) break;
1629 if (errno != EEXIST) goto done;
1633 /* now save to it */
1636 if (!(f = fdopen( fd, "w" )))
1638 if (tmp) unlink( tmp );
1643 if (debug_level > 1)
1645 fprintf( stderr, "%s: ", path );
1646 dump_operation( key, NULL, "saving" );
1649 save_all_subkeys( key, f );
1654 /* if successfully written, rename to final name */
1655 if (ret) ret = !rename( tmp, path );
1656 if (!ret) unlink( tmp );
1661 if (real) free( real );
1662 if (ret) make_clean( key );
1666 /* periodic saving of the registry */
1667 static void periodic_save( void *arg )
1670 for (i = 0; i < save_branch_count; i++)
1671 save_branch( save_branch_info[i].key, save_branch_info[i].path );
1672 add_timeout( &next_save_time, save_period );
1673 save_timeout_user = add_timeout_user( &next_save_time, periodic_save, 0 );
1676 /* save the modified registry branches to disk */
1677 void flush_registry(void)
1681 for (i = 0; i < save_branch_count; i++)
1683 if (!save_branch( save_branch_info[i].key, save_branch_info[i].path ))
1685 fprintf( stderr, "wineserver: could not save registry branch to %s",
1686 save_branch_info[i].path );
1692 /* close the top-level keys; used on server exit */
1693 void close_registry(void)
1697 for (i = 0; i < save_branch_count; i++) release_object( save_branch_info[i].key );
1698 release_object( root_key );
1702 /* create a registry key */
1703 DECL_HANDLER(create_key)
1705 struct key *key = NULL, *parent;
1706 unsigned int access = req->access;
1707 WCHAR *name, *class;
1709 if (access & MAXIMUM_ALLOWED) access = KEY_ALL_ACCESS; /* FIXME: needs general solution */
1711 if (!(name = copy_req_path( req->namelen, !req->parent ))) return;
1712 if ((parent = get_hkey_obj( req->parent, 0 /*FIXME*/ )))
1714 int flags = (req->options & REG_OPTION_VOLATILE) ? KEY_VOLATILE : KEY_DIRTY;
1716 if (req->namelen == get_req_data_size()) /* no class specified */
1718 key = create_key( parent, name, NULL, flags, req->modif, &reply->created );
1722 const WCHAR *class_ptr = (WCHAR *)((char *)get_req_data() + req->namelen);
1724 if ((class = req_strdupW( req, class_ptr, get_req_data_size() - req->namelen )))
1726 key = create_key( parent, name, class, flags, req->modif, &reply->created );
1732 reply->hkey = alloc_handle( current->process, key, access, 0 );
1733 release_object( key );
1735 release_object( parent );
1739 /* open a registry key */
1740 DECL_HANDLER(open_key)
1742 struct key *key, *parent;
1743 unsigned int access = req->access;
1745 if (access & MAXIMUM_ALLOWED) access = KEY_ALL_ACCESS; /* FIXME: needs general solution */
1747 if ((parent = get_hkey_obj( req->parent, 0 /*FIXME*/ )))
1749 WCHAR *name = copy_path( get_req_data(), get_req_data_size(), !req->parent );
1750 if (name && (key = open_key( parent, name )))
1752 reply->hkey = alloc_handle( current->process, key, access, 0 );
1753 release_object( key );
1755 release_object( parent );
1759 /* delete a registry key */
1760 DECL_HANDLER(delete_key)
1764 if ((key = get_hkey_obj( req->hkey, 0 /*FIXME*/ )))
1767 release_object( key );
1771 /* enumerate registry subkeys */
1772 DECL_HANDLER(enum_key)
1776 if ((key = get_hkey_obj( req->hkey,
1777 req->index == -1 ? KEY_QUERY_VALUE : KEY_ENUMERATE_SUB_KEYS )))
1779 enum_key( key, req->index, req->info_class, reply );
1780 release_object( key );
1784 /* set a value of a registry key */
1785 DECL_HANDLER(set_key_value)
1790 if (!(name = copy_req_path( req->namelen, 0 ))) return;
1791 if ((key = get_hkey_obj( req->hkey, KEY_SET_VALUE )))
1793 size_t datalen = get_req_data_size() - req->namelen;
1794 const char *data = (char *)get_req_data() + req->namelen;
1796 set_value( key, name, req->type, data, datalen );
1797 release_object( key );
1801 /* retrieve the value of a registry key */
1802 DECL_HANDLER(get_key_value)
1808 if (!(name = copy_path( get_req_data(), get_req_data_size(), 0 ))) return;
1809 if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE )))
1811 get_value( key, name, &reply->type, &reply->total );
1812 release_object( key );
1816 /* enumerate the value of a registry key */
1817 DECL_HANDLER(enum_key_value)
1821 if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE )))
1823 enum_value( key, req->index, req->info_class, reply );
1824 release_object( key );
1828 /* delete a value of a registry key */
1829 DECL_HANDLER(delete_key_value)
1834 if ((key = get_hkey_obj( req->hkey, KEY_SET_VALUE )))
1836 if ((name = req_strdupW( req, get_req_data(), get_req_data_size() )))
1838 delete_value( key, name );
1841 release_object( key );
1845 /* load a registry branch from a file */
1846 DECL_HANDLER(load_registry)
1850 if ((key = get_hkey_obj( req->hkey, KEY_SET_VALUE | KEY_CREATE_SUB_KEY )))
1852 /* FIXME: use subkey name */
1853 load_registry( key, req->file );
1854 release_object( key );
1858 /* save a registry branch to a file */
1859 DECL_HANDLER(save_registry)
1863 if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS )))
1865 save_registry( key, req->file );
1866 release_object( key );
1870 /* set the current and saving level for the registry */
1871 DECL_HANDLER(set_registry_levels)
1873 current_level = req->current;
1874 saving_level = req->saving;
1876 /* set periodic save timer */
1878 if (save_timeout_user)
1880 remove_timeout_user( save_timeout_user );
1881 save_timeout_user = NULL;
1883 if ((save_period = req->period))
1885 if (save_period < 10000) save_period = 10000; /* limit rate */
1886 gettimeofday( &next_save_time, 0 );
1887 add_timeout( &next_save_time, save_period );
1888 save_timeout_user = add_timeout_user( &next_save_time, periodic_save, 0 );
1892 /* save a registry branch at server exit */
1893 DECL_HANDLER(save_registry_atexit)
1897 if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS )))
1899 register_branch_for_saving( key, get_req_data(), get_req_data_size() );
1900 release_object( key );
1904 /* add a registry key change notification */
1905 DECL_HANDLER(set_registry_notification)
1908 struct event *event;
1909 struct notify *notify;
1911 key = get_hkey_obj( req->hkey, KEY_NOTIFY );
1914 event = get_event_obj( current->process, req->event, SYNCHRONIZE );
1917 notify = find_notify( key, req->hkey );
1920 release_object( notify->event );
1921 grab_object( event );
1922 notify->event = event;
1926 notify = (struct notify *) malloc (sizeof *notify);
1929 grab_object( event );
1930 notify->event = event;
1931 notify->subtree = req->subtree;
1932 notify->filter = req->filter;
1933 notify->hkey = req->hkey;
1935 /* add to linked list */
1936 notify->prev = NULL;
1937 notify->next = key->first_notify;
1939 notify->next->prev = notify;
1941 key->last_notify = notify;
1942 key->first_notify = notify;
1945 set_error( STATUS_NO_MEMORY );
1947 release_object( event );
1949 release_object( key );