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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
41 #define WIN32_NO_STATUS
50 #include "wine/library.h"
54 struct list entry; /* entry in list of notifications */
55 struct event *event; /* event to set when changing this key */
56 int subtree; /* true if subtree notification */
57 unsigned int filter; /* which events to notify on */
58 obj_handle_t hkey; /* hkey associated with this notification */
59 struct process *process; /* process in which the hkey is valid */
65 struct object obj; /* object header */
66 WCHAR *name; /* key name */
67 WCHAR *class; /* key class */
68 unsigned short namelen; /* length of key name */
69 unsigned short classlen; /* length of class name */
70 struct key *parent; /* parent key */
71 int last_subkey; /* last in use subkey */
72 int nb_subkeys; /* count of allocated subkeys */
73 struct key **subkeys; /* subkeys array */
74 int last_value; /* last in use value */
75 int nb_values; /* count of allocated values in array */
76 struct key_value *values; /* values array */
77 unsigned int flags; /* flags */
78 time_t modif; /* last modification time */
79 struct list notify_list; /* 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 */
90 WCHAR *name; /* value name */
91 unsigned short namelen; /* length of value name */
92 unsigned short type; /* value type */
93 data_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 */
100 #define MAX_NAME_LEN MAX_PATH /* max. length of a key name */
101 #define MAX_VALUE_LEN MAX_PATH /* max. length of a value name */
103 /* the root of the registry tree */
104 static struct key *root_key;
106 static const timeout_t save_period = 30 * -TICKS_PER_SEC; /* delay between periodic saves */
107 static struct timeout_user *save_timeout_user; /* saving timer */
109 static void set_periodic_save_timer(void);
111 /* information about where to save a registry branch */
112 struct save_branch_info
118 #define MAX_SAVE_BRANCH_INFO 3
119 static int save_branch_count;
120 static struct save_branch_info save_branch_info[MAX_SAVE_BRANCH_INFO];
123 /* information about a file being loaded */
124 struct file_load_info
126 const char *filename; /* input file name */
127 FILE *file; /* input file */
128 char *buffer; /* line buffer */
129 int len; /* buffer length */
130 int line; /* current input line */
131 WCHAR *tmp; /* temp buffer to use while parsing input */
132 size_t tmplen; /* length of temp buffer */
136 static void key_dump( struct object *obj, int verbose );
137 static unsigned int key_map_access( struct object *obj, unsigned int access );
138 static int key_close_handle( struct object *obj, struct process *process, obj_handle_t handle );
139 static void key_destroy( struct object *obj );
141 static const struct object_ops key_ops =
143 sizeof(struct key), /* size */
145 no_get_type, /* get_type */
146 no_add_queue, /* add_queue */
147 NULL, /* remove_queue */
149 NULL, /* satisfied */
150 no_signal, /* signal */
151 no_get_fd, /* get_fd */
152 key_map_access, /* map_access */
153 default_get_sd, /* get_sd */
154 default_set_sd, /* set_sd */
155 no_lookup_name, /* lookup_name */
156 no_open_file, /* open_file */
157 key_close_handle, /* close_handle */
158 key_destroy /* destroy */
163 * The registry text file format v2 used by this code is similar to the one
164 * used by REGEDIT import/export functionality, with the following differences:
165 * - strings and key names can contain \x escapes for Unicode
166 * - key names use escapes too in order to support Unicode
167 * - the modification time optionally follows the key name
168 * - REG_EXPAND_SZ and REG_MULTI_SZ are saved as strings instead of hex
171 /* dump the full path of a key */
172 static void dump_path( const struct key *key, const struct key *base, FILE *f )
174 if (key->parent && key->parent != base)
176 dump_path( key->parent, base, f );
177 fprintf( f, "\\\\" );
179 dump_strW( key->name, key->namelen / sizeof(WCHAR), f, "[]" );
182 /* dump a value to a text file */
183 static void dump_value( const struct key_value *value, FILE *f )
191 count = 1 + dump_strW( value->name, value->namelen / sizeof(WCHAR), f, "\"\"" );
192 count += fprintf( f, "\"=" );
194 else count = fprintf( f, "@=" );
201 /* only output properly terminated strings in string format */
202 if (value->len < sizeof(WCHAR)) break;
203 if (value->len % sizeof(WCHAR)) break;
204 if (((WCHAR *)value->data)[value->len / sizeof(WCHAR) - 1]) break;
205 if (value->type != REG_SZ) fprintf( f, "str(%x):", value->type );
207 dump_strW( (WCHAR *)value->data, value->len / sizeof(WCHAR), f, "\"\"" );
208 fprintf( f, "\"\n" );
212 if (value->len != sizeof(dw)) break;
213 memcpy( &dw, value->data, sizeof(dw) );
214 fprintf( f, "dword:%08x\n", dw );
218 if (value->type == REG_BINARY) count += fprintf( f, "hex:" );
219 else count += fprintf( f, "hex(%x):", value->type );
220 for (i = 0; i < value->len; i++)
222 count += fprintf( f, "%02x", *((unsigned char *)value->data + i) );
223 if (i < value->len-1)
228 fprintf( f, "\\\n " );
236 /* save a registry and all its subkeys to a text file */
237 static void save_subkeys( const struct key *key, const struct key *base, FILE *f )
241 if (key->flags & KEY_VOLATILE) return;
242 /* save key if it has either some values or no subkeys */
243 /* keys with no values but subkeys are saved implicitly by saving the subkeys */
244 if ((key->last_value >= 0) || (key->last_subkey == -1))
247 if (key != base) dump_path( key, base, f );
248 fprintf( f, "] %ld\n", (long)key->modif );
249 for (i = 0; i <= key->last_value; i++) dump_value( &key->values[i], f );
251 for (i = 0; i <= key->last_subkey; i++) save_subkeys( key->subkeys[i], base, f );
254 static void dump_operation( const struct key *key, const struct key_value *value, const char *op )
256 fprintf( stderr, "%s key ", op );
257 if (key) dump_path( key, NULL, stderr );
258 else fprintf( stderr, "ERROR" );
261 fprintf( stderr, " value ");
262 dump_value( value, stderr );
264 else fprintf( stderr, "\n" );
267 static void key_dump( struct object *obj, int verbose )
269 struct key *key = (struct key *)obj;
270 assert( obj->ops == &key_ops );
271 fprintf( stderr, "Key flags=%x ", key->flags );
272 dump_path( key, NULL, stderr );
273 fprintf( stderr, "\n" );
276 /* notify waiter and maybe delete the notification */
277 static void do_notification( struct key *key, struct notify *notify, int del )
281 set_event( notify->event );
282 release_object( notify->event );
283 notify->event = NULL;
287 list_remove( ¬ify->entry );
292 static inline struct notify *find_notify( struct key *key, struct process *process, obj_handle_t hkey )
294 struct notify *notify;
296 LIST_FOR_EACH_ENTRY( notify, &key->notify_list, struct notify, entry )
298 if (notify->process == process && notify->hkey == hkey) return notify;
303 static unsigned int key_map_access( struct object *obj, unsigned int access )
305 if (access & GENERIC_READ) access |= KEY_READ;
306 if (access & GENERIC_WRITE) access |= KEY_WRITE;
307 if (access & GENERIC_EXECUTE) access |= KEY_EXECUTE;
308 if (access & GENERIC_ALL) access |= KEY_ALL_ACCESS;
309 return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
312 /* close the notification associated with a handle */
313 static int key_close_handle( struct object *obj, struct process *process, obj_handle_t handle )
315 struct key * key = (struct key *) obj;
316 struct notify *notify = find_notify( key, process, handle );
317 if (notify) do_notification( key, notify, 1 );
318 return 1; /* ok to close */
321 static void key_destroy( struct object *obj )
325 struct key *key = (struct key *)obj;
326 assert( obj->ops == &key_ops );
330 for (i = 0; i <= key->last_value; i++)
332 free( key->values[i].name );
333 free( key->values[i].data );
336 for (i = 0; i <= key->last_subkey; i++)
338 key->subkeys[i]->parent = NULL;
339 release_object( key->subkeys[i] );
341 free( key->subkeys );
342 /* unconditionally notify everything waiting on this key */
343 while ((ptr = list_head( &key->notify_list )))
345 struct notify *notify = LIST_ENTRY( ptr, struct notify, entry );
346 do_notification( key, notify, 1 );
350 /* get the request vararg as registry path */
351 static inline void get_req_path( struct unicode_str *str, int skip_root )
353 static const WCHAR root_name[] = { '\\','R','e','g','i','s','t','r','y','\\' };
355 str->str = get_req_data();
356 str->len = (get_req_data_size() / sizeof(WCHAR)) * sizeof(WCHAR);
358 if (skip_root && str->len >= sizeof(root_name) &&
359 !memicmpW( str->str, root_name, sizeof(root_name)/sizeof(WCHAR) ))
361 str->str += sizeof(root_name)/sizeof(WCHAR);
362 str->len -= sizeof(root_name);
366 /* return the next token in a given path */
367 /* token->str must point inside the path, or be NULL for the first call */
368 static struct unicode_str *get_path_token( const struct unicode_str *path, struct unicode_str *token )
370 data_size_t i = 0, len = path->len / sizeof(WCHAR);
372 if (!token->str) /* first time */
374 /* path cannot start with a backslash */
375 if (len && path->str[0] == '\\')
377 set_error( STATUS_OBJECT_PATH_INVALID );
383 i = token->str - path->str;
384 i += token->len / sizeof(WCHAR);
385 while (i < len && path->str[i] == '\\') i++;
387 token->str = path->str + i;
388 while (i < len && path->str[i] != '\\') i++;
389 token->len = (path->str + i - token->str) * sizeof(WCHAR);
393 /* allocate a key object */
394 static struct key *alloc_key( const struct unicode_str *name, time_t modif )
397 if ((key = alloc_object( &key_ops )))
401 key->namelen = name->len;
404 key->last_subkey = -1;
408 key->last_value = -1;
412 list_init( &key->notify_list );
413 if (name->len && !(key->name = memdup( name->str, name->len )))
415 release_object( key );
422 /* mark a key and all its parents as dirty (modified) */
423 static void make_dirty( struct key *key )
427 if (key->flags & (KEY_DIRTY|KEY_VOLATILE)) return; /* nothing to do */
428 key->flags |= KEY_DIRTY;
433 /* mark a key and all its subkeys as clean (not modified) */
434 static void make_clean( struct key *key )
438 if (key->flags & KEY_VOLATILE) return;
439 if (!(key->flags & KEY_DIRTY)) return;
440 key->flags &= ~KEY_DIRTY;
441 for (i = 0; i <= key->last_subkey; i++) make_clean( key->subkeys[i] );
444 /* go through all the notifications and send them if necessary */
445 static void check_notify( struct key *key, unsigned int change, int not_subtree )
447 struct list *ptr, *next;
449 LIST_FOR_EACH_SAFE( ptr, next, &key->notify_list )
451 struct notify *n = LIST_ENTRY( ptr, struct notify, entry );
452 if ( ( not_subtree || n->subtree ) && ( change & n->filter ) )
453 do_notification( key, n, 0 );
457 /* update key modification time */
458 static void touch_key( struct key *key, unsigned int change )
462 key->modif = time(NULL);
465 /* do notifications */
466 check_notify( key, change, 1 );
467 for ( k = key->parent; k; k = k->parent )
468 check_notify( k, change & ~REG_NOTIFY_CHANGE_LAST_SET, 0 );
471 /* try to grow the array of subkeys; return 1 if OK, 0 on error */
472 static int grow_subkeys( struct key *key )
474 struct key **new_subkeys;
479 nb_subkeys = key->nb_subkeys + (key->nb_subkeys / 2); /* grow by 50% */
480 if (!(new_subkeys = realloc( key->subkeys, nb_subkeys * sizeof(*new_subkeys) )))
482 set_error( STATUS_NO_MEMORY );
488 nb_subkeys = MIN_VALUES;
489 if (!(new_subkeys = mem_alloc( nb_subkeys * sizeof(*new_subkeys) ))) return 0;
491 key->subkeys = new_subkeys;
492 key->nb_subkeys = nb_subkeys;
496 /* allocate a subkey for a given key, and return its index */
497 static struct key *alloc_subkey( struct key *parent, const struct unicode_str *name,
498 int index, time_t modif )
503 if (name->len > MAX_NAME_LEN * sizeof(WCHAR))
505 set_error( STATUS_NAME_TOO_LONG );
508 if (parent->last_subkey + 1 == parent->nb_subkeys)
510 /* need to grow the array */
511 if (!grow_subkeys( parent )) return NULL;
513 if ((key = alloc_key( name, modif )) != NULL)
515 key->parent = parent;
516 for (i = ++parent->last_subkey; i > index; i--)
517 parent->subkeys[i] = parent->subkeys[i-1];
518 parent->subkeys[index] = key;
523 /* free a subkey of a given key */
524 static void free_subkey( struct key *parent, int index )
529 assert( index >= 0 );
530 assert( index <= parent->last_subkey );
532 key = parent->subkeys[index];
533 for (i = index; i < parent->last_subkey; i++) parent->subkeys[i] = parent->subkeys[i + 1];
534 parent->last_subkey--;
535 key->flags |= KEY_DELETED;
537 release_object( key );
539 /* try to shrink the array */
540 nb_subkeys = parent->nb_subkeys;
541 if (nb_subkeys > MIN_SUBKEYS && parent->last_subkey < nb_subkeys / 2)
543 struct key **new_subkeys;
544 nb_subkeys -= nb_subkeys / 3; /* shrink by 33% */
545 if (nb_subkeys < MIN_SUBKEYS) nb_subkeys = MIN_SUBKEYS;
546 if (!(new_subkeys = realloc( parent->subkeys, nb_subkeys * sizeof(*new_subkeys) ))) return;
547 parent->subkeys = new_subkeys;
548 parent->nb_subkeys = nb_subkeys;
552 /* find the named child of a given key and return its index */
553 static struct key *find_subkey( const struct key *key, const struct unicode_str *name, int *index )
555 int i, min, max, res;
559 max = key->last_subkey;
563 len = min( key->subkeys[i]->namelen, name->len );
564 res = memicmpW( key->subkeys[i]->name, name->str, len / sizeof(WCHAR) );
565 if (!res) res = key->subkeys[i]->namelen - name->len;
569 return key->subkeys[i];
571 if (res > 0) max = i - 1;
574 *index = min; /* this is where we should insert it */
579 static struct key *open_key( struct key *key, const struct unicode_str *name )
582 struct unicode_str token;
585 if (!get_path_token( name, &token )) return NULL;
588 if (!(key = find_subkey( key, &token, &index )))
590 set_error( STATUS_OBJECT_NAME_NOT_FOUND );
593 get_path_token( name, &token );
596 if (debug_level > 1) dump_operation( key, NULL, "Open" );
597 if (key) grab_object( key );
601 /* create a subkey */
602 static struct key *create_key( struct key *key, const struct unicode_str *name,
603 const struct unicode_str *class, int flags, time_t modif, int *created )
607 struct unicode_str token;
609 if (key->flags & KEY_DELETED) /* we cannot create a subkey under a deleted key */
611 set_error( STATUS_KEY_DELETED );
614 if (!(flags & KEY_VOLATILE) && (key->flags & KEY_VOLATILE))
616 set_error( STATUS_CHILD_MUST_BE_VOLATILE );
619 if (!modif) modif = time(NULL);
622 if (!get_path_token( name, &token )) return NULL;
627 if (!(subkey = find_subkey( key, &token, &index ))) break;
629 get_path_token( name, &token );
632 /* create the remaining part */
634 if (!token.len) goto done;
636 if (flags & KEY_DIRTY) make_dirty( key );
637 if (!(key = alloc_subkey( key, &token, index, modif ))) return NULL;
642 get_path_token( name, &token );
643 if (!token.len) break;
644 /* we know the index is always 0 in a new key */
645 if (!(key = alloc_subkey( key, &token, 0, modif )))
647 free_subkey( base, index );
653 if (debug_level > 1) dump_operation( key, NULL, "Create" );
654 if (class && class->len)
656 key->classlen = class->len;
658 if (!(key->class = memdup( class->str, key->classlen ))) key->classlen = 0;
664 /* query information about a key or a subkey */
665 static void enum_key( const struct key *key, int index, int info_class,
666 struct enum_key_reply *reply )
669 data_size_t len, namelen, classlen;
670 data_size_t max_subkey = 0, max_class = 0;
671 data_size_t max_value = 0, max_data = 0;
674 if (index != -1) /* -1 means use the specified key directly */
676 if ((index < 0) || (index > key->last_subkey))
678 set_error( STATUS_NO_MORE_ENTRIES );
681 key = key->subkeys[index];
684 namelen = key->namelen;
685 classlen = key->classlen;
689 case KeyBasicInformation:
690 classlen = 0; /* only return the name */
692 case KeyNodeInformation:
693 reply->max_subkey = 0;
694 reply->max_class = 0;
695 reply->max_value = 0;
698 case KeyFullInformation:
699 for (i = 0; i <= key->last_subkey; i++)
701 struct key *subkey = key->subkeys[i];
702 len = subkey->namelen / sizeof(WCHAR);
703 if (len > max_subkey) max_subkey = len;
704 len = subkey->classlen / sizeof(WCHAR);
705 if (len > max_class) max_class = len;
707 for (i = 0; i <= key->last_value; i++)
709 len = key->values[i].namelen / sizeof(WCHAR);
710 if (len > max_value) max_value = len;
711 len = key->values[i].len;
712 if (len > max_data) max_data = len;
714 reply->max_subkey = max_subkey;
715 reply->max_class = max_class;
716 reply->max_value = max_value;
717 reply->max_data = max_data;
718 namelen = 0; /* only return the class */
721 set_error( STATUS_INVALID_PARAMETER );
724 reply->subkeys = key->last_subkey + 1;
725 reply->values = key->last_value + 1;
726 reply->modif = key->modif;
727 reply->total = namelen + classlen;
729 len = min( reply->total, get_reply_max_size() );
730 if (len && (data = set_reply_data_size( len )))
734 reply->namelen = namelen;
735 memcpy( data, key->name, namelen );
736 memcpy( data + namelen, key->class, len - namelen );
740 reply->namelen = len;
741 memcpy( data, key->name, len );
744 if (debug_level > 1) dump_operation( key, NULL, "Enum" );
747 /* delete a key and its values */
748 static int delete_key( struct key *key, int recurse )
753 /* must find parent and index */
756 set_error( STATUS_ACCESS_DENIED );
759 if (!(parent = key->parent) || (key->flags & KEY_DELETED))
761 set_error( STATUS_KEY_DELETED );
765 while (recurse && (key->last_subkey>=0))
766 if (0 > delete_key(key->subkeys[key->last_subkey], 1))
769 for (index = 0; index <= parent->last_subkey; index++)
770 if (parent->subkeys[index] == key) break;
771 assert( index <= parent->last_subkey );
773 /* we can only delete a key that has no subkeys */
774 if (key->last_subkey >= 0)
776 set_error( STATUS_ACCESS_DENIED );
780 if (debug_level > 1) dump_operation( key, NULL, "Delete" );
781 free_subkey( parent, index );
782 touch_key( parent, REG_NOTIFY_CHANGE_NAME );
786 /* try to grow the array of values; return 1 if OK, 0 on error */
787 static int grow_values( struct key *key )
789 struct key_value *new_val;
794 nb_values = key->nb_values + (key->nb_values / 2); /* grow by 50% */
795 if (!(new_val = realloc( key->values, nb_values * sizeof(*new_val) )))
797 set_error( STATUS_NO_MEMORY );
803 nb_values = MIN_VALUES;
804 if (!(new_val = mem_alloc( nb_values * sizeof(*new_val) ))) return 0;
806 key->values = new_val;
807 key->nb_values = nb_values;
811 /* find the named value of a given key and return its index in the array */
812 static struct key_value *find_value( const struct key *key, const struct unicode_str *name, int *index )
814 int i, min, max, res;
818 max = key->last_value;
822 len = min( key->values[i].namelen, name->len );
823 res = memicmpW( key->values[i].name, name->str, len / sizeof(WCHAR) );
824 if (!res) res = key->values[i].namelen - name->len;
828 return &key->values[i];
830 if (res > 0) max = i - 1;
833 *index = min; /* this is where we should insert it */
837 /* insert a new value; the index must have been returned by find_value */
838 static struct key_value *insert_value( struct key *key, const struct unicode_str *name, int index )
840 struct key_value *value;
841 WCHAR *new_name = NULL;
844 if (name->len > MAX_VALUE_LEN * sizeof(WCHAR))
846 set_error( STATUS_NAME_TOO_LONG );
849 if (key->last_value + 1 == key->nb_values)
851 if (!grow_values( key )) return NULL;
853 if (name->len && !(new_name = memdup( name->str, name->len ))) return NULL;
854 for (i = ++key->last_value; i > index; i--) key->values[i] = key->values[i - 1];
855 value = &key->values[index];
856 value->name = new_name;
857 value->namelen = name->len;
863 /* set a key value */
864 static void set_value( struct key *key, const struct unicode_str *name,
865 int type, const void *data, data_size_t len )
867 struct key_value *value;
871 if ((value = find_value( key, name, &index )))
873 /* check if the new value is identical to the existing one */
874 if (value->type == type && value->len == len &&
875 value->data && !memcmp( value->data, data, len ))
877 if (debug_level > 1) dump_operation( key, value, "Skip setting" );
882 if (len && !(ptr = memdup( data, len ))) return;
886 if (!(value = insert_value( key, name, index )))
892 else free( value->data ); /* already existing, free previous data */
897 touch_key( key, REG_NOTIFY_CHANGE_LAST_SET );
898 if (debug_level > 1) dump_operation( key, value, "Set" );
901 /* get a key value */
902 static void get_value( struct key *key, const struct unicode_str *name, int *type, data_size_t *len )
904 struct key_value *value;
907 if ((value = find_value( key, name, &index )))
911 if (value->data) set_reply_data( value->data, min( value->len, get_reply_max_size() ));
912 if (debug_level > 1) dump_operation( key, value, "Get" );
917 set_error( STATUS_OBJECT_NAME_NOT_FOUND );
921 /* enumerate a key value */
922 static void enum_value( struct key *key, int i, int info_class, struct enum_key_value_reply *reply )
924 struct key_value *value;
926 if (i < 0 || i > key->last_value) set_error( STATUS_NO_MORE_ENTRIES );
930 data_size_t namelen, maxlen;
932 value = &key->values[i];
933 reply->type = value->type;
934 namelen = value->namelen;
938 case KeyValueBasicInformation:
939 reply->total = namelen;
941 case KeyValueFullInformation:
942 reply->total = namelen + value->len;
944 case KeyValuePartialInformation:
945 reply->total = value->len;
949 set_error( STATUS_INVALID_PARAMETER );
953 maxlen = min( reply->total, get_reply_max_size() );
954 if (maxlen && ((data = set_reply_data_size( maxlen ))))
956 if (maxlen > namelen)
958 reply->namelen = namelen;
959 memcpy( data, value->name, namelen );
960 memcpy( (char *)data + namelen, value->data, maxlen - namelen );
964 reply->namelen = maxlen;
965 memcpy( data, value->name, maxlen );
968 if (debug_level > 1) dump_operation( key, value, "Enum" );
973 static void delete_value( struct key *key, const struct unicode_str *name )
975 struct key_value *value;
976 int i, index, nb_values;
978 if (!(value = find_value( key, name, &index )))
980 set_error( STATUS_OBJECT_NAME_NOT_FOUND );
983 if (debug_level > 1) dump_operation( key, value, "Delete" );
986 for (i = index; i < key->last_value; i++) key->values[i] = key->values[i + 1];
988 touch_key( key, REG_NOTIFY_CHANGE_LAST_SET );
990 /* try to shrink the array */
991 nb_values = key->nb_values;
992 if (nb_values > MIN_VALUES && key->last_value < nb_values / 2)
994 struct key_value *new_val;
995 nb_values -= nb_values / 3; /* shrink by 33% */
996 if (nb_values < MIN_VALUES) nb_values = MIN_VALUES;
997 if (!(new_val = realloc( key->values, nb_values * sizeof(*new_val) ))) return;
998 key->values = new_val;
999 key->nb_values = nb_values;
1003 /* get the registry key corresponding to an hkey handle */
1004 static inline struct key *get_hkey_obj( obj_handle_t hkey, unsigned int access )
1006 return (struct key *)get_handle_obj( current->process, hkey, access, &key_ops );
1009 /* get the registry key corresponding to a parent key handle */
1010 static inline struct key *get_parent_hkey_obj( obj_handle_t hkey )
1012 if (!hkey) return (struct key *)grab_object( root_key );
1013 return (struct key *)get_handle_obj( current->process, hkey, 0, &key_ops );
1016 /* read a line from the input file */
1017 static int read_next_line( struct file_load_info *info )
1020 int newlen, pos = 0;
1025 if (!fgets( info->buffer + pos, info->len - pos, info->file ))
1026 return (pos != 0); /* EOF */
1027 pos = strlen(info->buffer);
1028 if (info->buffer[pos-1] == '\n')
1030 /* got a full line */
1031 info->buffer[--pos] = 0;
1032 if (pos > 0 && info->buffer[pos-1] == '\r') info->buffer[pos-1] = 0;
1035 if (pos < info->len - 1) return 1; /* EOF but something was read */
1037 /* need to enlarge the buffer */
1038 newlen = info->len + info->len / 2;
1039 if (!(newbuf = realloc( info->buffer, newlen )))
1041 set_error( STATUS_NO_MEMORY );
1044 info->buffer = newbuf;
1049 /* make sure the temp buffer holds enough space */
1050 static int get_file_tmp_space( struct file_load_info *info, size_t size )
1053 if (info->tmplen >= size) return 1;
1054 if (!(tmp = realloc( info->tmp, size )))
1056 set_error( STATUS_NO_MEMORY );
1060 info->tmplen = size;
1064 /* report an error while loading an input file */
1065 static void file_read_error( const char *err, struct file_load_info *info )
1068 fprintf( stderr, "%s:%d: %s '%s'\n", info->filename, info->line, err, info->buffer );
1070 fprintf( stderr, "<fd>:%d: %s '%s'\n", info->line, err, info->buffer );
1073 /* convert a data type tag to a value type */
1074 static int get_data_type( const char *buffer, int *type, int *parse_type )
1076 struct data_type { const char *tag; int len; int type; int parse_type; };
1078 static const struct data_type data_types[] =
1079 { /* actual type */ /* type to assume for parsing */
1080 { "\"", 1, REG_SZ, REG_SZ },
1081 { "str:\"", 5, REG_SZ, REG_SZ },
1082 { "str(2):\"", 8, REG_EXPAND_SZ, REG_SZ },
1083 { "str(7):\"", 8, REG_MULTI_SZ, REG_SZ },
1084 { "hex:", 4, REG_BINARY, REG_BINARY },
1085 { "dword:", 6, REG_DWORD, REG_DWORD },
1086 { "hex(", 4, -1, REG_BINARY },
1090 const struct data_type *ptr;
1093 for (ptr = data_types; ptr->tag; ptr++)
1095 if (strncmp( ptr->tag, buffer, ptr->len )) continue;
1096 *parse_type = ptr->parse_type;
1097 if ((*type = ptr->type) != -1) return ptr->len;
1098 /* "hex(xx):" is special */
1099 *type = (int)strtoul( buffer + 4, &end, 16 );
1100 if ((end <= buffer) || strncmp( end, "):", 2 )) return 0;
1101 return end + 2 - buffer;
1106 /* load and create a key from the input file */
1107 static struct key *load_key( struct key *base, const char *buffer, int flags,
1108 int prefix_len, struct file_load_info *info,
1112 struct unicode_str name;
1116 if (!get_file_tmp_space( info, strlen(buffer) * sizeof(WCHAR) )) return NULL;
1119 if ((res = parse_strW( info->tmp, &len, buffer, ']' )) == -1)
1121 file_read_error( "Malformed key", info );
1124 if (sscanf( buffer + res, " %d", &modif ) != 1) modif = default_modif;
1127 while (prefix_len && *p) { if (*p++ == '\\') prefix_len--; }
1133 file_read_error( "Malformed key", info );
1136 /* empty key name, return base key */
1137 return (struct key *)grab_object( base );
1140 name.len = len - (p - info->tmp + 1) * sizeof(WCHAR);
1141 return create_key( base, &name, NULL, flags, modif, &res );
1144 /* parse a comma-separated list of hex digits */
1145 static int parse_hex( unsigned char *dest, data_size_t *len, const char *buffer )
1147 const char *p = buffer;
1148 data_size_t count = 0;
1151 while (isxdigit(*p))
1153 unsigned int val = strtoul( p, &end, 16 );
1154 if (end == p || val > 0xff) return -1;
1155 if (count++ >= *len) return -1; /* dest buffer overflow */
1158 while (isspace(*p)) p++;
1160 while (isspace(*p)) p++;
1166 /* parse a value name and create the corresponding value */
1167 static struct key_value *parse_value_name( struct key *key, const char *buffer, data_size_t *len,
1168 struct file_load_info *info )
1170 struct key_value *value;
1171 struct unicode_str name;
1174 if (!get_file_tmp_space( info, strlen(buffer) * sizeof(WCHAR) )) return NULL;
1175 name.str = info->tmp;
1176 name.len = info->tmplen;
1177 if (buffer[0] == '@')
1184 int r = parse_strW( info->tmp, &name.len, buffer + 1, '\"' );
1185 if (r == -1) goto error;
1186 *len = r + 1; /* for initial quote */
1187 name.len -= sizeof(WCHAR); /* terminating null */
1189 while (isspace(buffer[*len])) (*len)++;
1190 if (buffer[*len] != '=') goto error;
1192 while (isspace(buffer[*len])) (*len)++;
1193 if (!(value = find_value( key, &name, &index ))) value = insert_value( key, &name, index );
1197 file_read_error( "Malformed value name", info );
1201 /* load a value from the input file */
1202 static int load_value( struct key *key, const char *buffer, struct file_load_info *info )
1206 int res, type, parse_type;
1207 data_size_t maxlen, len;
1208 struct key_value *value;
1210 if (!(value = parse_value_name( key, buffer, &len, info ))) return 0;
1211 if (!(res = get_data_type( buffer + len, &type, &parse_type ))) goto error;
1212 buffer += len + res;
1217 if (!get_file_tmp_space( info, strlen(buffer) * sizeof(WCHAR) )) return 0;
1219 if ((res = parse_strW( info->tmp, &len, buffer, '\"' )) == -1) goto error;
1223 dw = strtoul( buffer, NULL, 16 );
1227 case REG_BINARY: /* hex digits */
1231 maxlen = 1 + strlen(buffer) / 2; /* at least 2 chars for one hex byte */
1232 if (!get_file_tmp_space( info, len + maxlen )) return 0;
1233 if ((res = parse_hex( (unsigned char *)info->tmp + len, &maxlen, buffer )) == -1) goto error;
1236 while (isspace(*buffer)) buffer++;
1237 if (!*buffer) break;
1238 if (*buffer != '\\') goto error;
1239 if (read_next_line( info) != 1) goto error;
1240 buffer = info->buffer;
1241 while (isspace(*buffer)) buffer++;
1247 ptr = NULL; /* keep compiler quiet */
1251 if (!len) newptr = NULL;
1252 else if (!(newptr = memdup( ptr, len ))) return 0;
1254 free( value->data );
1255 value->data = newptr;
1262 file_read_error( "Malformed value", info );
1263 free( value->data );
1266 value->type = REG_NONE;
1271 /* return the length (in path elements) of name that is part of the key name */
1272 /* for instance if key is USER\foo\bar and name is foo\bar\baz, return 2 */
1273 static int get_prefix_len( struct key *key, const char *name, struct file_load_info *info )
1279 if (!get_file_tmp_space( info, strlen(name) * sizeof(WCHAR) )) return 0;
1282 if ((res = parse_strW( info->tmp, &len, name, ']' )) == -1)
1284 file_read_error( "Malformed key", info );
1287 for (p = info->tmp; *p; p++) if (*p == '\\') break;
1288 len = (p - info->tmp) * sizeof(WCHAR);
1289 for (res = 1; key != root_key; res++)
1291 if (len == key->namelen && !memicmpW( info->tmp, key->name, len / sizeof(WCHAR) )) break;
1294 if (key == root_key) res = 0; /* no matching name */
1298 /* load all the keys from the input file */
1299 /* prefix_len is the number of key name prefixes to skip, or -1 for autodetection */
1300 static void load_keys( struct key *key, const char *filename, FILE *f, int prefix_len )
1302 struct key *subkey = NULL;
1303 struct file_load_info info;
1305 int default_modif = time(NULL);
1306 int flags = (key->flags & KEY_VOLATILE) ? KEY_VOLATILE : KEY_DIRTY;
1308 info.filename = filename;
1313 if (!(info.buffer = mem_alloc( info.len ))) return;
1314 if (!(info.tmp = mem_alloc( info.tmplen )))
1316 free( info.buffer );
1320 if ((read_next_line( &info ) != 1) ||
1321 strcmp( info.buffer, "WINE REGISTRY Version 2" ))
1323 set_error( STATUS_NOT_REGISTRY_FILE );
1327 while (read_next_line( &info ) == 1)
1330 while (*p && isspace(*p)) p++;
1333 case '[': /* new key */
1334 if (subkey) release_object( subkey );
1335 if (prefix_len == -1) prefix_len = get_prefix_len( key, p + 1, &info );
1336 if (!(subkey = load_key( key, p + 1, flags, prefix_len, &info, default_modif )))
1337 file_read_error( "Error creating key", &info );
1339 case '@': /* default value */
1340 case '\"': /* value */
1341 if (subkey) load_value( subkey, p, &info );
1342 else file_read_error( "Value without key", &info );
1344 case '#': /* comment */
1345 case ';': /* comment */
1346 case 0: /* empty line */
1349 file_read_error( "Unrecognized input", &info );
1355 if (subkey) release_object( subkey );
1356 free( info.buffer );
1360 /* load a part of the registry from a file */
1361 static void load_registry( struct key *key, obj_handle_t handle )
1366 if (!(file = get_file_obj( current->process, handle, FILE_READ_DATA ))) return;
1367 fd = dup( get_file_unix_fd( file ) );
1368 release_object( file );
1371 FILE *f = fdopen( fd, "r" );
1374 load_keys( key, NULL, f, -1 );
1377 else file_set_error();
1381 /* load one of the initial registry files */
1382 static void load_init_registry_from_file( const char *filename, struct key *key )
1386 if ((f = fopen( filename, "r" )))
1388 load_keys( key, filename, f, 0 );
1390 if (get_error() == STATUS_NOT_REGISTRY_FILE)
1392 fprintf( stderr, "%s is not a valid registry file\n", filename );
1397 assert( save_branch_count < MAX_SAVE_BRANCH_INFO );
1399 if ((save_branch_info[save_branch_count].path = strdup( filename )))
1401 save_branch_info[save_branch_count++].key = (struct key *)grab_object( key );
1402 make_object_static( &key->obj );
1406 static WCHAR *format_user_registry_path( const SID *sid, struct unicode_str *path )
1408 static const WCHAR prefixW[] = {'U','s','e','r','\\','S',0};
1409 static const WCHAR formatW[] = {'-','%','u',0};
1410 WCHAR buffer[7 + 10 + 10 + 10 * SID_MAX_SUB_AUTHORITIES];
1414 strcpyW( p, prefixW );
1415 p += strlenW( prefixW );
1416 p += sprintfW( p, formatW, sid->Revision );
1417 p += sprintfW( p, formatW, MAKELONG( MAKEWORD( sid->IdentifierAuthority.Value[5],
1418 sid->IdentifierAuthority.Value[4] ),
1419 MAKEWORD( sid->IdentifierAuthority.Value[3],
1420 sid->IdentifierAuthority.Value[2] )));
1421 for (i = 0; i < sid->SubAuthorityCount; i++)
1422 p += sprintfW( p, formatW, sid->SubAuthority[i] );
1424 path->len = (p - buffer) * sizeof(WCHAR);
1425 path->str = p = memdup( buffer, path->len );
1429 /* registry initialisation */
1430 void init_registry(void)
1432 static const WCHAR HKLM[] = { 'M','a','c','h','i','n','e' };
1433 static const WCHAR HKU_default[] = { 'U','s','e','r','\\','.','D','e','f','a','u','l','t' };
1434 static const struct unicode_str root_name = { NULL, 0 };
1435 static const struct unicode_str HKLM_name = { HKLM, sizeof(HKLM) };
1436 static const struct unicode_str HKU_name = { HKU_default, sizeof(HKU_default) };
1438 WCHAR *current_user_path;
1439 struct unicode_str current_user_str;
1441 const char *config = wine_get_config_dir();
1446 /* create the root key */
1447 root_key = alloc_key( &root_name, time(NULL) );
1449 make_object_static( &root_key->obj );
1451 if (!(filename = malloc( strlen(config) + 16 ))) fatal_error( "out of memory\n" );
1452 strcpy( filename, config );
1453 p = filename + strlen(filename);
1455 /* load system.reg into Registry\Machine */
1457 if (!(key = create_key( root_key, &HKLM_name, NULL, 0, time(NULL), &dummy )))
1458 fatal_error( "could not create Machine registry key\n" );
1460 strcpy( p, "/system.reg" );
1461 load_init_registry_from_file( filename, key );
1462 release_object( key );
1464 /* load userdef.reg into Registry\User\.Default */
1466 if (!(key = create_key( root_key, &HKU_name, NULL, 0, time(NULL), &dummy )))
1467 fatal_error( "could not create User\\.Default registry key\n" );
1469 strcpy( p, "/userdef.reg" );
1470 load_init_registry_from_file( filename, key );
1471 release_object( key );
1473 /* load user.reg into HKEY_CURRENT_USER */
1475 /* FIXME: match default user in token.c. should get from process token instead */
1476 current_user_path = format_user_registry_path( security_interactive_sid, ¤t_user_str );
1477 if (!current_user_path ||
1478 !(key = create_key( root_key, ¤t_user_str, NULL, 0, time(NULL), &dummy )))
1479 fatal_error( "could not create HKEY_CURRENT_USER registry key\n" );
1480 free( current_user_path );
1481 strcpy( p, "/user.reg" );
1482 load_init_registry_from_file( filename, key );
1483 release_object( key );
1487 /* start the periodic save timer */
1488 set_periodic_save_timer();
1491 /* save a registry branch to a file */
1492 static void save_all_subkeys( struct key *key, FILE *f )
1494 fprintf( f, "WINE REGISTRY Version 2\n" );
1495 fprintf( f, ";; All keys relative to " );
1496 dump_path( key, NULL, f );
1498 save_subkeys( key, key, f );
1501 /* save a registry branch to a file handle */
1502 static void save_registry( struct key *key, obj_handle_t handle )
1507 if (key->flags & KEY_DELETED)
1509 set_error( STATUS_KEY_DELETED );
1512 if (!(file = get_file_obj( current->process, handle, FILE_WRITE_DATA ))) return;
1513 fd = dup( get_file_unix_fd( file ) );
1514 release_object( file );
1517 FILE *f = fdopen( fd, "w" );
1520 save_all_subkeys( key, f );
1521 if (fclose( f )) file_set_error();
1531 /* save a registry branch to a file */
1532 static int save_branch( struct key *key, const char *path )
1535 char *p, *real, *tmp = NULL;
1536 int fd, count = 0, ret = 0, by_symlink;
1539 if (!(key->flags & KEY_DIRTY))
1541 if (debug_level > 1) dump_operation( key, NULL, "Not saving clean" );
1545 /* get the real path */
1547 by_symlink = (!lstat(path, &st) && S_ISLNK (st.st_mode));
1548 if (!(real = malloc( PATH_MAX ))) return 0;
1549 if (!realpath( path, real ))
1556 /* test the file type */
1558 if ((fd = open( path, O_WRONLY )) != -1)
1560 /* if file is not a regular file or has multiple links or is accessed
1561 * via symbolic links, write directly into it; otherwise use a temp file */
1563 (!fstat( fd, &st ) && (!S_ISREG(st.st_mode) || st.st_nlink > 1)))
1571 /* create a temp file in the same directory */
1573 if (!(tmp = malloc( strlen(path) + 20 ))) goto done;
1574 strcpy( tmp, path );
1575 if ((p = strrchr( tmp, '/' ))) p++;
1579 sprintf( p, "reg%lx%04x.tmp", (long) getpid(), count++ );
1580 if ((fd = open( tmp, O_CREAT | O_EXCL | O_WRONLY, 0666 )) != -1) break;
1581 if (errno != EEXIST) goto done;
1585 /* now save to it */
1588 if (!(f = fdopen( fd, "w" )))
1590 if (tmp) unlink( tmp );
1595 if (debug_level > 1)
1597 fprintf( stderr, "%s: ", path );
1598 dump_operation( key, NULL, "saving" );
1601 save_all_subkeys( key, f );
1606 /* if successfully written, rename to final name */
1607 if (ret) ret = !rename( tmp, path );
1608 if (!ret) unlink( tmp );
1614 if (ret) make_clean( key );
1618 /* periodic saving of the registry */
1619 static void periodic_save( void *arg )
1623 save_timeout_user = NULL;
1624 for (i = 0; i < save_branch_count; i++)
1625 save_branch( save_branch_info[i].key, save_branch_info[i].path );
1626 set_periodic_save_timer();
1629 /* start the periodic save timer */
1630 static void set_periodic_save_timer(void)
1632 if (save_timeout_user) remove_timeout_user( save_timeout_user );
1633 save_timeout_user = add_timeout_user( save_period, periodic_save, NULL );
1636 /* save the modified registry branches to disk */
1637 void flush_registry(void)
1641 for (i = 0; i < save_branch_count; i++)
1643 if (!save_branch( save_branch_info[i].key, save_branch_info[i].path ))
1645 fprintf( stderr, "wineserver: could not save registry branch to %s",
1646 save_branch_info[i].path );
1653 /* create a registry key */
1654 DECL_HANDLER(create_key)
1656 struct key *key = NULL, *parent;
1657 struct unicode_str name, class;
1658 unsigned int access = req->access;
1662 if (req->namelen > get_req_data_size())
1664 set_error( STATUS_INVALID_PARAMETER );
1667 class.str = (const WCHAR *)get_req_data() + req->namelen / sizeof(WCHAR);
1668 class.len = ((get_req_data_size() - req->namelen) / sizeof(WCHAR)) * sizeof(WCHAR);
1669 get_req_path( &name, !req->parent );
1670 if (name.str > class.str)
1672 set_error( STATUS_INVALID_PARAMETER );
1675 name.len = (class.str - name.str) * sizeof(WCHAR);
1677 /* NOTE: no access rights are required from the parent handle to create a key */
1678 if ((parent = get_parent_hkey_obj( req->parent )))
1680 int flags = (req->options & REG_OPTION_VOLATILE) ? KEY_VOLATILE : KEY_DIRTY;
1682 if ((key = create_key( parent, &name, &class, flags, req->modif, &reply->created )))
1684 reply->hkey = alloc_handle( current->process, key, access, req->attributes );
1685 release_object( key );
1687 release_object( parent );
1691 /* open a registry key */
1692 DECL_HANDLER(open_key)
1694 struct key *key, *parent;
1695 struct unicode_str name;
1696 unsigned int access = req->access;
1699 /* NOTE: no access rights are required to open the parent key, only the child key */
1700 if ((parent = get_parent_hkey_obj( req->parent )))
1702 get_req_path( &name, !req->parent );
1703 if ((key = open_key( parent, &name )))
1705 reply->hkey = alloc_handle( current->process, key, access, req->attributes );
1706 release_object( key );
1708 release_object( parent );
1712 /* delete a registry key */
1713 DECL_HANDLER(delete_key)
1717 if ((key = get_hkey_obj( req->hkey, DELETE )))
1719 delete_key( key, 0);
1720 release_object( key );
1724 /* flush a registry key */
1725 DECL_HANDLER(flush_key)
1727 struct key *key = get_hkey_obj( req->hkey, 0 );
1730 /* we don't need to do anything here with the current implementation */
1731 release_object( key );
1735 /* enumerate registry subkeys */
1736 DECL_HANDLER(enum_key)
1740 if ((key = get_hkey_obj( req->hkey,
1741 req->index == -1 ? KEY_QUERY_VALUE : KEY_ENUMERATE_SUB_KEYS )))
1743 enum_key( key, req->index, req->info_class, reply );
1744 release_object( key );
1748 /* set a value of a registry key */
1749 DECL_HANDLER(set_key_value)
1752 struct unicode_str name;
1754 if (req->namelen > get_req_data_size())
1756 set_error( STATUS_INVALID_PARAMETER );
1759 name.str = get_req_data();
1760 name.len = (req->namelen / sizeof(WCHAR)) * sizeof(WCHAR);
1762 if ((key = get_hkey_obj( req->hkey, KEY_SET_VALUE )))
1764 data_size_t datalen = get_req_data_size() - req->namelen;
1765 const char *data = (const char *)get_req_data() + req->namelen;
1767 set_value( key, &name, req->type, data, datalen );
1768 release_object( key );
1772 /* retrieve the value of a registry key */
1773 DECL_HANDLER(get_key_value)
1776 struct unicode_str name;
1779 if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE )))
1781 get_req_unicode_str( &name );
1782 get_value( key, &name, &reply->type, &reply->total );
1783 release_object( key );
1787 /* enumerate the value of a registry key */
1788 DECL_HANDLER(enum_key_value)
1792 if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE )))
1794 enum_value( key, req->index, req->info_class, reply );
1795 release_object( key );
1799 /* delete a value of a registry key */
1800 DECL_HANDLER(delete_key_value)
1803 struct unicode_str name;
1805 if ((key = get_hkey_obj( req->hkey, KEY_SET_VALUE )))
1807 get_req_unicode_str( &name );
1808 delete_value( key, &name );
1809 release_object( key );
1813 /* load a registry branch from a file */
1814 DECL_HANDLER(load_registry)
1816 struct key *key, *parent;
1817 struct token *token = thread_get_impersonation_token( current );
1818 struct unicode_str name;
1820 const LUID_AND_ATTRIBUTES privs[] =
1822 { SeBackupPrivilege, 0 },
1823 { SeRestorePrivilege, 0 },
1826 if (!token || !token_check_privileges( token, TRUE, privs,
1827 sizeof(privs)/sizeof(privs[0]), NULL ))
1829 set_error( STATUS_PRIVILEGE_NOT_HELD );
1833 if ((parent = get_parent_hkey_obj( req->hkey )))
1836 get_req_path( &name, !req->hkey );
1837 if ((key = create_key( parent, &name, NULL, KEY_DIRTY, time(NULL), &dummy )))
1839 load_registry( key, req->file );
1840 release_object( key );
1842 release_object( parent );
1846 DECL_HANDLER(unload_registry)
1849 struct token *token = thread_get_impersonation_token( current );
1851 const LUID_AND_ATTRIBUTES privs[] =
1853 { SeBackupPrivilege, 0 },
1854 { SeRestorePrivilege, 0 },
1857 if (!token || !token_check_privileges( token, TRUE, privs,
1858 sizeof(privs)/sizeof(privs[0]), NULL ))
1860 set_error( STATUS_PRIVILEGE_NOT_HELD );
1864 if ((key = get_hkey_obj( req->hkey, 0 )))
1866 delete_key( key, 1 ); /* FIXME */
1867 release_object( key );
1871 /* save a registry branch to a file */
1872 DECL_HANDLER(save_registry)
1876 if (!thread_single_check_privilege( current, &SeBackupPrivilege ))
1878 set_error( STATUS_PRIVILEGE_NOT_HELD );
1882 if ((key = get_hkey_obj( req->hkey, 0 )))
1884 save_registry( key, req->file );
1885 release_object( key );
1889 /* add a registry key change notification */
1890 DECL_HANDLER(set_registry_notification)
1893 struct event *event;
1894 struct notify *notify;
1896 key = get_hkey_obj( req->hkey, KEY_NOTIFY );
1899 event = get_event_obj( current->process, req->event, SYNCHRONIZE );
1902 notify = find_notify( key, current->process, req->hkey );
1906 release_object( notify->event );
1907 grab_object( event );
1908 notify->event = event;
1912 notify = mem_alloc( sizeof(*notify) );
1915 grab_object( event );
1916 notify->event = event;
1917 notify->subtree = req->subtree;
1918 notify->filter = req->filter;
1919 notify->hkey = req->hkey;
1920 notify->process = current->process;
1921 list_add_head( &key->notify_list, ¬ify->entry );
1924 release_object( event );
1926 release_object( key );