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"
47 #include "winnt.h" /* registry definitions */
49 #include "wine/library.h"
53 struct event *event; /* event to set when changing this key */
54 int subtree; /* true if subtree notification */
55 unsigned int filter; /* which events to notify on */
56 obj_handle_t hkey; /* hkey associated with this notification */
57 struct notify *next; /* list of notifications */
58 struct notify *prev; /* list of notifications */
64 struct object obj; /* object header */
65 WCHAR *name; /* key name */
66 WCHAR *class; /* key class */
67 struct key *parent; /* parent key */
68 int last_subkey; /* last in use subkey */
69 int nb_subkeys; /* count of allocated subkeys */
70 struct key **subkeys; /* subkeys array */
71 int last_value; /* last in use value */
72 int nb_values; /* count of allocated values in array */
73 struct key_value *values; /* values array */
74 short flags; /* flags */
75 short level; /* saving level */
76 time_t modif; /* last modification time */
77 struct notify *first_notify; /* list of notifications */
78 struct notify *last_notify; /* list of notifications */
82 #define KEY_VOLATILE 0x0001 /* key is volatile (not saved to disk) */
83 #define KEY_DELETED 0x0002 /* key has been deleted */
84 #define KEY_DIRTY 0x0004 /* key has been modified */
85 #define KEY_ROOT 0x0008 /* key is a root key */
90 WCHAR *name; /* value name */
91 int type; /* value type */
92 size_t len; /* value data length in bytes */
93 void *data; /* pointer to value data */
96 #define MIN_SUBKEYS 8 /* min. number of allocated subkeys per key */
97 #define MIN_VALUES 8 /* min. number of allocated values per key */
100 /* the special root keys */
101 #define HKEY_SPECIAL_ROOT_FIRST ((unsigned int)HKEY_CLASSES_ROOT)
102 #define HKEY_SPECIAL_ROOT_LAST ((unsigned int)HKEY_DYN_DATA)
103 #define NB_SPECIAL_ROOT_KEYS (HKEY_SPECIAL_ROOT_LAST - HKEY_SPECIAL_ROOT_FIRST + 1)
104 #define IS_SPECIAL_ROOT_HKEY(h) (((unsigned int)(h) >= HKEY_SPECIAL_ROOT_FIRST) && \
105 ((unsigned int)(h) <= HKEY_SPECIAL_ROOT_LAST))
107 static struct key *special_root_keys[NB_SPECIAL_ROOT_KEYS];
109 /* the real root key */
110 static struct key *root_key;
112 /* the special root key names */
113 static const char * const special_root_names[NB_SPECIAL_ROOT_KEYS] =
115 "Machine\\Software\\Classes", /* HKEY_CLASSES_ROOT */
116 "User\\", /* we append the user name dynamically */ /* HKEY_CURRENT_USER */
117 "Machine", /* HKEY_LOCAL_MACHINE */
118 "User", /* HKEY_USERS */
119 "PerfData", /* HKEY_PERFORMANCE_DATA */
120 "Machine\\System\\CurrentControlSet\\HardwareProfiles\\Current", /* HKEY_CURRENT_CONFIG */
121 "DynData" /* HKEY_DYN_DATA */
125 /* keys saving level */
126 /* current_level is the level that is put into all newly created or modified keys */
127 /* saving_level is the minimum level that a key needs in order to get saved */
128 static int current_level;
129 static int saving_level;
131 static struct timeval next_save_time; /* absolute time of next periodic save */
132 static int save_period; /* delay between periodic saves (ms) */
133 static struct timeout_user *save_timeout_user; /* saving timer */
135 /* information about where to save a registry branch */
136 struct save_branch_info
142 #define MAX_SAVE_BRANCH_INFO 8
143 static int save_branch_count;
144 static struct save_branch_info save_branch_info[MAX_SAVE_BRANCH_INFO];
147 /* information about a file being loaded */
148 struct file_load_info
150 FILE *file; /* input file */
151 char *buffer; /* line buffer */
152 int len; /* buffer length */
153 int line; /* current input line */
154 char *tmp; /* temp buffer to use while parsing input */
155 int tmplen; /* length of temp buffer */
159 static void key_dump( struct object *obj, int verbose );
160 static void key_destroy( struct object *obj );
162 static const struct object_ops key_ops =
164 sizeof(struct key), /* size */
166 no_add_queue, /* add_queue */
167 NULL, /* remove_queue */
169 NULL, /* satisfied */
170 NULL, /* get_poll_events */
171 NULL, /* poll_event */
172 no_get_fd, /* get_fd */
173 no_flush, /* flush */
174 no_get_file_info, /* get_file_info */
175 NULL, /* queue_async */
176 key_destroy /* destroy */
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
189 static inline char to_hex( char ch )
191 if (isdigit(ch)) return ch - '0';
192 return tolower(ch) - 'a' + 10;
195 /* dump the full path of a key */
196 static void dump_path( const struct key *key, const struct key *base, FILE *f )
198 if (key->parent && key->parent != base)
200 dump_path( key->parent, base, f );
201 fprintf( f, "\\\\" );
203 dump_strW( key->name, strlenW(key->name), f, "[]" );
206 /* dump a value to a text file */
207 static void dump_value( const struct key_value *value, FILE *f )
214 count = 1 + dump_strW( value->name, strlenW(value->name), f, "\"\"" );
215 count += fprintf( f, "\"=" );
217 else count = fprintf( f, "@=" );
224 if (value->type != REG_SZ) fprintf( f, "str(%d):", value->type );
226 if (value->data) dump_strW( (WCHAR *)value->data, value->len / sizeof(WCHAR), f, "\"\"" );
230 if (value->len == sizeof(DWORD))
233 memcpy( &dw, value->data, sizeof(DWORD) );
234 fprintf( f, "dword:%08lx", dw );
237 /* else fall through */
239 if (value->type == REG_BINARY) count += fprintf( f, "hex:" );
240 else count += fprintf( f, "hex(%x):", value->type );
241 for (i = 0; i < value->len; i++)
243 count += fprintf( f, "%02x", *((unsigned char *)value->data + i) );
244 if (i < value->len-1)
249 fprintf( f, "\\\n " );
259 /* save a registry and all its subkeys to a text file */
260 static void save_subkeys( const struct key *key, const struct key *base, FILE *f )
264 if (key->flags & KEY_VOLATILE) return;
265 /* save key if it has the proper level, and has either some values or no subkeys */
266 /* keys with no values but subkeys are saved implicitly by saving the subkeys */
267 if ((key->level >= saving_level) && ((key->last_value >= 0) || (key->last_subkey == -1)))
270 if (key != base) dump_path( key, base, f );
271 fprintf( f, "] %ld\n", key->modif );
272 for (i = 0; i <= key->last_value; i++) dump_value( &key->values[i], f );
274 for (i = 0; i <= key->last_subkey; i++) save_subkeys( key->subkeys[i], base, f );
277 static void dump_operation( const struct key *key, const struct key_value *value, const char *op )
279 fprintf( stderr, "%s key ", op );
280 if (key) dump_path( key, NULL, stderr );
281 else fprintf( stderr, "ERROR" );
284 fprintf( stderr, " value ");
285 dump_value( value, stderr );
287 else fprintf( stderr, "\n" );
290 static void key_dump( struct object *obj, int verbose )
292 struct key *key = (struct key *)obj;
293 assert( obj->ops == &key_ops );
294 fprintf( stderr, "Key flags=%x ", key->flags );
295 dump_path( key, NULL, stderr );
296 fprintf( stderr, "\n" );
299 /* notify waiter and maybe delete the notification */
300 static void do_notification( struct key *key, struct notify *notify, int del )
304 set_event( notify->event );
305 release_object( notify->event );
306 notify->event = NULL;
312 notify->next->prev = notify->prev;
314 key->last_notify = notify->prev;
316 notify->prev->next = notify->next;
318 key->first_notify = notify->next;
322 static struct notify *find_notify( struct key *key, obj_handle_t hkey)
326 for( n=key->first_notify; n; n = n->next)
327 if( n->hkey == hkey )
332 /* close the notification associated with a handle */
333 void registry_close_handle( struct object *obj, obj_handle_t hkey )
335 struct key * key = (struct key *) obj;
336 struct notify *notify;
338 if( obj->ops != &key_ops )
340 notify = find_notify( key, hkey );
343 do_notification( key, notify, 1 );
346 static void key_destroy( struct object *obj )
349 struct key *key = (struct key *)obj;
350 assert( obj->ops == &key_ops );
352 if (key->name) free( key->name );
353 if (key->class) free( key->class );
354 for (i = 0; i <= key->last_value; i++)
356 free( key->values[i].name );
357 if (key->values[i].data) free( key->values[i].data );
359 for (i = 0; i <= key->last_subkey; i++)
361 key->subkeys[i]->parent = NULL;
362 release_object( key->subkeys[i] );
364 /* unconditionally notify everything waiting on this key */
365 while ( key->first_notify )
366 do_notification( key, key->first_notify, 1 );
369 /* duplicate a key path */
370 /* returns a pointer to a static buffer, so only useable once per request */
371 static WCHAR *copy_path( const WCHAR *path, size_t len, int skip_root )
373 static WCHAR buffer[MAX_PATH+1];
374 static const WCHAR root_name[] = { '\\','R','e','g','i','s','t','r','y','\\',0 };
376 if (len > sizeof(buffer)-sizeof(buffer[0]))
378 set_error( STATUS_BUFFER_OVERFLOW );
381 memcpy( buffer, path, len );
382 buffer[len / sizeof(WCHAR)] = 0;
383 if (skip_root && !strncmpiW( buffer, root_name, 10 )) return buffer + 10;
387 /* copy a path from the request buffer */
388 static WCHAR *copy_req_path( size_t len, int skip_root )
390 const WCHAR *name_ptr = get_req_data();
391 if (len > get_req_data_size())
393 fatal_protocol_error( current, "copy_req_path: invalid length %d/%d\n",
394 len, get_req_data_size() );
397 return copy_path( name_ptr, len, skip_root );
400 /* return the next token in a given path */
401 /* returns a pointer to a static buffer, so only useable once per request */
402 static WCHAR *get_path_token( WCHAR *initpath )
409 /* path cannot start with a backslash */
410 if (*initpath == '\\')
412 set_error( STATUS_OBJECT_PATH_INVALID );
417 else while (*path == '\\') path++;
420 while (*path && *path != '\\') path++;
421 if (*path) *path++ = 0;
425 /* duplicate a Unicode string from the request buffer */
426 static WCHAR *req_strdupW( const void *req, const WCHAR *str, size_t len )
429 if ((name = mem_alloc( len + sizeof(WCHAR) )) != NULL)
431 memcpy( name, str, len );
432 name[len / sizeof(WCHAR)] = 0;
437 /* allocate a key object */
438 static struct key *alloc_key( const WCHAR *name, time_t modif )
441 if ((key = (struct key *)alloc_object( &key_ops, -1 )))
445 key->last_subkey = -1;
449 key->last_value = -1;
451 key->level = current_level;
454 key->first_notify = NULL;
455 key->last_notify = NULL;
456 if (!(key->name = strdupW( name )))
458 release_object( key );
465 /* mark a key and all its parents as dirty (modified) */
466 static void make_dirty( struct key *key )
470 if (key->flags & (KEY_DIRTY|KEY_VOLATILE)) return; /* nothing to do */
471 key->flags |= KEY_DIRTY;
476 /* mark a key and all its subkeys as clean (not modified) */
477 static void make_clean( struct key *key )
481 if (key->flags & KEY_VOLATILE) return;
482 if (!(key->flags & KEY_DIRTY)) return;
483 key->flags &= ~KEY_DIRTY;
484 for (i = 0; i <= key->last_subkey; i++) make_clean( key->subkeys[i] );
487 /* go through all the notifications and send them if necessary */
488 void check_notify( struct key *key, unsigned int change, int not_subtree )
490 struct notify *n = key->first_notify;
493 struct notify *next = n->next;
494 if ( ( not_subtree || n->subtree ) && ( change & n->filter ) )
495 do_notification( key, n, 0 );
500 /* update key modification time */
501 static void touch_key( struct key *key, unsigned int change )
505 key->modif = time(NULL);
506 key->level = max( key->level, current_level );
509 /* do notifications */
510 check_notify( key, change, 1 );
511 for ( k = key->parent; k; k = k->parent )
512 check_notify( k, change & ~REG_NOTIFY_CHANGE_LAST_SET, 0 );
515 /* try to grow the array of subkeys; return 1 if OK, 0 on error */
516 static int grow_subkeys( struct key *key )
518 struct key **new_subkeys;
523 nb_subkeys = key->nb_subkeys + (key->nb_subkeys / 2); /* grow by 50% */
524 if (!(new_subkeys = realloc( key->subkeys, nb_subkeys * sizeof(*new_subkeys) )))
526 set_error( STATUS_NO_MEMORY );
532 nb_subkeys = MIN_VALUES;
533 if (!(new_subkeys = mem_alloc( nb_subkeys * sizeof(*new_subkeys) ))) return 0;
535 key->subkeys = new_subkeys;
536 key->nb_subkeys = nb_subkeys;
540 /* allocate a subkey for a given key, and return its index */
541 static struct key *alloc_subkey( struct key *parent, const WCHAR *name, int index, time_t modif )
546 if (parent->last_subkey + 1 == parent->nb_subkeys)
548 /* need to grow the array */
549 if (!grow_subkeys( parent )) return NULL;
551 if ((key = alloc_key( name, modif )) != NULL)
553 key->parent = parent;
554 for (i = ++parent->last_subkey; i > index; i--)
555 parent->subkeys[i] = parent->subkeys[i-1];
556 parent->subkeys[index] = key;
561 /* free a subkey of a given key */
562 static void free_subkey( struct key *parent, int index )
567 assert( index >= 0 );
568 assert( index <= parent->last_subkey );
570 key = parent->subkeys[index];
571 for (i = index; i < parent->last_subkey; i++) parent->subkeys[i] = parent->subkeys[i + 1];
572 parent->last_subkey--;
573 key->flags |= KEY_DELETED;
575 release_object( key );
577 /* try to shrink the array */
578 nb_subkeys = parent->nb_subkeys;
579 if (nb_subkeys > MIN_SUBKEYS && parent->last_subkey < nb_subkeys / 2)
581 struct key **new_subkeys;
582 nb_subkeys -= nb_subkeys / 3; /* shrink by 33% */
583 if (nb_subkeys < MIN_SUBKEYS) nb_subkeys = MIN_SUBKEYS;
584 if (!(new_subkeys = realloc( parent->subkeys, nb_subkeys * sizeof(*new_subkeys) ))) return;
585 parent->subkeys = new_subkeys;
586 parent->nb_subkeys = nb_subkeys;
590 /* find the named child of a given key and return its index */
591 static struct key *find_subkey( const struct key *key, const WCHAR *name, int *index )
593 int i, min, max, res;
596 max = key->last_subkey;
600 if (!(res = strcmpiW( key->subkeys[i]->name, name )))
603 return key->subkeys[i];
605 if (res > 0) max = i - 1;
608 *index = min; /* this is where we should insert it */
613 /* warning: the key name must be writeable (use copy_path) */
614 static struct key *open_key( struct key *key, WCHAR *name )
619 if (!(path = get_path_token( name ))) return NULL;
622 if (!(key = find_subkey( key, path, &index )))
624 set_error( STATUS_OBJECT_NAME_NOT_FOUND );
627 path = get_path_token( NULL );
630 if (debug_level > 1) dump_operation( key, NULL, "Open" );
631 if (key) grab_object( key );
635 /* create a subkey */
636 /* warning: the key name must be writeable (use copy_path) */
637 static struct key *create_key( struct key *key, WCHAR *name, WCHAR *class,
638 int flags, time_t modif, int *created )
644 if (key->flags & KEY_DELETED) /* we cannot create a subkey under a deleted key */
646 set_error( STATUS_KEY_DELETED );
649 if (!(flags & KEY_VOLATILE) && (key->flags & KEY_VOLATILE))
651 set_error( STATUS_CHILD_MUST_BE_VOLATILE );
654 if (!modif) modif = time(NULL);
656 if (!(path = get_path_token( name ))) return NULL;
661 if (!(subkey = find_subkey( key, path, &index ))) break;
663 path = get_path_token( NULL );
666 /* create the remaining part */
668 if (!*path) goto done;
670 touch_key( key, REG_NOTIFY_CHANGE_NAME ); /* FIXME: is this right? */
671 if (flags & KEY_DIRTY) make_dirty( key );
674 key = alloc_subkey( key, path, index, modif );
678 path = get_path_token( NULL );
679 if (!*path) goto done;
680 /* we know the index is always 0 in a new key */
681 key = alloc_subkey( key, path, 0, modif );
683 if (base_idx != -1) free_subkey( base, base_idx );
687 if (debug_level > 1) dump_operation( key, NULL, "Create" );
688 if (class) key->class = strdupW(class);
693 /* query information about a key or a subkey */
694 static void enum_key( const struct key *key, int index, int info_class,
695 struct enum_key_reply *reply )
698 size_t len, namelen, classlen;
699 int max_subkey = 0, max_class = 0;
700 int max_value = 0, max_data = 0;
703 if (index != -1) /* -1 means use the specified key directly */
705 if ((index < 0) || (index > key->last_subkey))
707 set_error( STATUS_NO_MORE_ENTRIES );
710 key = key->subkeys[index];
713 namelen = strlenW(key->name) * sizeof(WCHAR);
714 classlen = key->class ? strlenW(key->class) * sizeof(WCHAR) : 0;
718 case KeyBasicInformation:
719 classlen = 0; /* only return the name */
721 case KeyNodeInformation:
722 reply->max_subkey = 0;
723 reply->max_class = 0;
724 reply->max_value = 0;
727 case KeyFullInformation:
728 for (i = 0; i <= key->last_subkey; i++)
730 struct key *subkey = key->subkeys[i];
731 len = strlenW( subkey->name );
732 if (len > max_subkey) max_subkey = len;
733 if (!subkey->class) continue;
734 len = strlenW( subkey->class );
735 if (len > max_class) max_class = len;
737 for (i = 0; i <= key->last_value; i++)
739 len = strlenW( key->values[i].name );
740 if (len > max_value) max_value = len;
741 len = key->values[i].len;
742 if (len > max_data) max_data = len;
744 reply->max_subkey = max_subkey;
745 reply->max_class = max_class;
746 reply->max_value = max_value;
747 reply->max_data = max_data;
748 namelen = 0; /* only return the class */
751 set_error( STATUS_INVALID_PARAMETER );
754 reply->subkeys = key->last_subkey + 1;
755 reply->values = key->last_value + 1;
756 reply->modif = key->modif;
757 reply->total = namelen + classlen;
759 len = min( reply->total, get_reply_max_size() );
760 if (len && (data = set_reply_data_size( len )))
764 reply->namelen = namelen;
765 memcpy( data, key->name, namelen );
766 memcpy( (char *)data + namelen, key->class, len - namelen );
770 reply->namelen = len;
771 memcpy( data, key->name, len );
774 if (debug_level > 1) dump_operation( key, NULL, "Enum" );
777 /* delete a key and its values */
778 static void delete_key( struct key *key )
783 /* must find parent and index */
784 if (key->flags & KEY_ROOT)
786 set_error( STATUS_ACCESS_DENIED );
789 if (!(parent = key->parent) || (key->flags & KEY_DELETED))
791 set_error( STATUS_KEY_DELETED );
794 for (index = 0; index <= parent->last_subkey; index++)
795 if (parent->subkeys[index] == key) break;
796 assert( index <= parent->last_subkey );
798 /* we can only delete a key that has no subkeys (FIXME) */
799 if ((key->flags & KEY_ROOT) || (key->last_subkey >= 0))
801 set_error( STATUS_ACCESS_DENIED );
804 if (debug_level > 1) dump_operation( key, NULL, "Delete" );
805 free_subkey( parent, index );
806 touch_key( parent, REG_NOTIFY_CHANGE_NAME );
809 /* try to grow the array of values; return 1 if OK, 0 on error */
810 static int grow_values( struct key *key )
812 struct key_value *new_val;
817 nb_values = key->nb_values + (key->nb_values / 2); /* grow by 50% */
818 if (!(new_val = realloc( key->values, nb_values * sizeof(*new_val) )))
820 set_error( STATUS_NO_MEMORY );
826 nb_values = MIN_VALUES;
827 if (!(new_val = mem_alloc( nb_values * sizeof(*new_val) ))) return 0;
829 key->values = new_val;
830 key->nb_values = nb_values;
834 /* find the named value of a given key and return its index in the array */
835 static struct key_value *find_value( const struct key *key, const WCHAR *name, int *index )
837 int i, min, max, res;
840 max = key->last_value;
844 if (!(res = strcmpiW( key->values[i].name, name )))
847 return &key->values[i];
849 if (res > 0) max = i - 1;
852 *index = min; /* this is where we should insert it */
856 /* insert a new value; the index must have been returned by find_value */
857 static struct key_value *insert_value( struct key *key, const WCHAR *name, int index )
859 struct key_value *value;
863 if (key->last_value + 1 == key->nb_values)
865 if (!grow_values( key )) return NULL;
867 if (!(new_name = strdupW(name))) return NULL;
868 for (i = ++key->last_value; i > index; i--) key->values[i] = key->values[i - 1];
869 value = &key->values[index];
870 value->name = new_name;
876 /* set a key value */
877 static void set_value( struct key *key, WCHAR *name, int type, const void *data, size_t len )
879 struct key_value *value;
883 if ((value = find_value( key, name, &index )))
885 /* check if the new value is identical to the existing one */
886 if (value->type == type && value->len == len &&
887 value->data && !memcmp( value->data, data, len ))
889 if (debug_level > 1) dump_operation( key, value, "Skip setting" );
894 if (len && !(ptr = memdup( data, len ))) return;
898 if (!(value = insert_value( key, name, index )))
900 if (ptr) free( ptr );
904 else if (value->data) free( value->data ); /* already existing, free previous data */
909 touch_key( key, REG_NOTIFY_CHANGE_LAST_SET );
910 if (debug_level > 1) dump_operation( key, value, "Set" );
913 /* get a key value */
914 static void get_value( struct key *key, const WCHAR *name, int *type, int *len )
916 struct key_value *value;
919 if ((value = find_value( key, name, &index )))
923 if (value->data) set_reply_data( value->data, min( value->len, get_reply_max_size() ));
924 if (debug_level > 1) dump_operation( key, value, "Get" );
929 set_error( STATUS_OBJECT_NAME_NOT_FOUND );
933 /* enumerate a key value */
934 static void enum_value( struct key *key, int i, int info_class, struct enum_key_value_reply *reply )
936 struct key_value *value;
938 if (i < 0 || i > key->last_value) set_error( STATUS_NO_MORE_ENTRIES );
942 size_t namelen, maxlen;
944 value = &key->values[i];
945 reply->type = value->type;
946 namelen = strlenW( value->name ) * sizeof(WCHAR);
950 case KeyValueBasicInformation:
951 reply->total = namelen;
953 case KeyValueFullInformation:
954 reply->total = namelen + value->len;
956 case KeyValuePartialInformation:
957 reply->total = value->len;
961 set_error( STATUS_INVALID_PARAMETER );
965 maxlen = min( reply->total, get_reply_max_size() );
966 if (maxlen && ((data = set_reply_data_size( maxlen ))))
968 if (maxlen > namelen)
970 reply->namelen = namelen;
971 memcpy( data, value->name, namelen );
972 memcpy( (char *)data + namelen, value->data, maxlen - namelen );
976 reply->namelen = maxlen;
977 memcpy( data, value->name, maxlen );
980 if (debug_level > 1) dump_operation( key, value, "Enum" );
985 static void delete_value( struct key *key, const WCHAR *name )
987 struct key_value *value;
988 int i, index, nb_values;
990 if (!(value = find_value( key, name, &index )))
992 set_error( STATUS_OBJECT_NAME_NOT_FOUND );
995 if (debug_level > 1) dump_operation( key, value, "Delete" );
997 if (value->data) free( value->data );
998 for (i = index; i < key->last_value; i++) key->values[i] = key->values[i + 1];
1000 touch_key( key, REG_NOTIFY_CHANGE_LAST_SET );
1002 /* try to shrink the array */
1003 nb_values = key->nb_values;
1004 if (nb_values > MIN_VALUES && key->last_value < nb_values / 2)
1006 struct key_value *new_val;
1007 nb_values -= nb_values / 3; /* shrink by 33% */
1008 if (nb_values < MIN_VALUES) nb_values = MIN_VALUES;
1009 if (!(new_val = realloc( key->values, nb_values * sizeof(*new_val) ))) return;
1010 key->values = new_val;
1011 key->nb_values = nb_values;
1015 static struct key *create_root_key( obj_handle_t hkey )
1022 p = special_root_names[(unsigned int)hkey - HKEY_SPECIAL_ROOT_FIRST];
1024 while (*p) keyname[i++] = *p++;
1026 if (hkey == (obj_handle_t)HKEY_CURRENT_USER) /* this one is special */
1028 /* get the current user name */
1029 p = wine_get_user_name();
1030 while (*p && i < sizeof(keyname)/sizeof(WCHAR)-1) keyname[i++] = *p++;
1034 if ((key = create_key( root_key, keyname, NULL, 0, time(NULL), &dummy )))
1036 special_root_keys[(unsigned int)hkey - HKEY_SPECIAL_ROOT_FIRST] = key;
1037 key->flags |= KEY_ROOT;
1042 /* get the registry key corresponding to an hkey handle */
1043 static struct key *get_hkey_obj( obj_handle_t hkey, unsigned int access )
1047 if (!hkey) return (struct key *)grab_object( root_key );
1048 if (IS_SPECIAL_ROOT_HKEY(hkey))
1050 if (!(key = special_root_keys[(unsigned int)hkey - HKEY_SPECIAL_ROOT_FIRST]))
1051 key = create_root_key( hkey );
1056 key = (struct key *)get_handle_obj( current->process, hkey, access, &key_ops );
1060 /* read a line from the input file */
1061 static int read_next_line( struct file_load_info *info )
1064 int newlen, pos = 0;
1069 if (!fgets( info->buffer + pos, info->len - pos, info->file ))
1070 return (pos != 0); /* EOF */
1071 pos = strlen(info->buffer);
1072 if (info->buffer[pos-1] == '\n')
1074 /* got a full line */
1075 info->buffer[--pos] = 0;
1076 if (pos > 0 && info->buffer[pos-1] == '\r') info->buffer[pos-1] = 0;
1079 if (pos < info->len - 1) return 1; /* EOF but something was read */
1081 /* need to enlarge the buffer */
1082 newlen = info->len + info->len / 2;
1083 if (!(newbuf = realloc( info->buffer, newlen )))
1085 set_error( STATUS_NO_MEMORY );
1088 info->buffer = newbuf;
1093 /* make sure the temp buffer holds enough space */
1094 static int get_file_tmp_space( struct file_load_info *info, int size )
1097 if (info->tmplen >= size) return 1;
1098 if (!(tmp = realloc( info->tmp, size )))
1100 set_error( STATUS_NO_MEMORY );
1104 info->tmplen = size;
1108 /* report an error while loading an input file */
1109 static void file_read_error( const char *err, struct file_load_info *info )
1111 fprintf( stderr, "Line %d: %s '%s'\n", info->line, err, info->buffer );
1114 /* parse an escaped string back into Unicode */
1115 /* return the number of chars read from the input, or -1 on output overflow */
1116 static int parse_strW( WCHAR *dest, int *len, const char *src, char endchar )
1118 int count = sizeof(WCHAR); /* for terminating null */
1119 const char *p = src;
1120 while (*p && *p != endchar)
1122 if (*p != '\\') *dest = (WCHAR)*p++;
1128 case 'a': *dest = '\a'; p++; break;
1129 case 'b': *dest = '\b'; p++; break;
1130 case 'e': *dest = '\e'; p++; break;
1131 case 'f': *dest = '\f'; p++; break;
1132 case 'n': *dest = '\n'; p++; break;
1133 case 'r': *dest = '\r'; p++; break;
1134 case 't': *dest = '\t'; p++; break;
1135 case 'v': *dest = '\v'; p++; break;
1136 case 'x': /* hex escape */
1138 if (!isxdigit(*p)) *dest = 'x';
1141 *dest = to_hex(*p++);
1142 if (isxdigit(*p)) *dest = (*dest * 16) + to_hex(*p++);
1143 if (isxdigit(*p)) *dest = (*dest * 16) + to_hex(*p++);
1144 if (isxdigit(*p)) *dest = (*dest * 16) + to_hex(*p++);
1154 case '7': /* octal escape */
1156 if (*p >= '0' && *p <= '7') *dest = (*dest * 8) + (*p++ - '0');
1157 if (*p >= '0' && *p <= '7') *dest = (*dest * 8) + (*p++ - '0');
1160 *dest = (WCHAR)*p++;
1164 if ((count += sizeof(WCHAR)) > *len) return -1; /* dest buffer overflow */
1168 if (!*p) return -1; /* delimiter not found */
1173 /* convert a data type tag to a value type */
1174 static int get_data_type( const char *buffer, int *type, int *parse_type )
1176 struct data_type { const char *tag; int len; int type; int parse_type; };
1178 static const struct data_type data_types[] =
1179 { /* actual type */ /* type to assume for parsing */
1180 { "\"", 1, REG_SZ, REG_SZ },
1181 { "str:\"", 5, REG_SZ, REG_SZ },
1182 { "str(2):\"", 8, REG_EXPAND_SZ, REG_SZ },
1183 { "str(7):\"", 8, REG_MULTI_SZ, REG_SZ },
1184 { "hex:", 4, REG_BINARY, REG_BINARY },
1185 { "dword:", 6, REG_DWORD, REG_DWORD },
1186 { "hex(", 4, -1, REG_BINARY },
1190 const struct data_type *ptr;
1193 for (ptr = data_types; ptr->tag; ptr++)
1195 if (memcmp( ptr->tag, buffer, ptr->len )) continue;
1196 *parse_type = ptr->parse_type;
1197 if ((*type = ptr->type) != -1) return ptr->len;
1198 /* "hex(xx):" is special */
1199 *type = (int)strtoul( buffer + 4, &end, 16 );
1200 if ((end <= buffer) || memcmp( end, "):", 2 )) return 0;
1201 return end + 2 - buffer;
1206 /* load and create a key from the input file */
1207 static struct key *load_key( struct key *base, const char *buffer, int flags,
1208 int prefix_len, struct file_load_info *info )
1211 int res, len, modif;
1213 len = strlen(buffer) * sizeof(WCHAR);
1214 if (!get_file_tmp_space( info, len )) return NULL;
1216 if ((res = parse_strW( (WCHAR *)info->tmp, &len, buffer, ']' )) == -1)
1218 file_read_error( "Malformed key", info );
1221 if (sscanf( buffer + res, " %d", &modif ) != 1) modif = time(NULL);
1223 p = (WCHAR *)info->tmp;
1224 while (prefix_len && *p) { if (*p++ == '\\') prefix_len--; }
1230 file_read_error( "Malformed key", info );
1233 /* empty key name, return base key */
1234 return (struct key *)grab_object( base );
1236 if (!(name = copy_path( p, len - ((char *)p - info->tmp), 0 )))
1238 file_read_error( "Key is too long", info );
1241 return create_key( base, name, NULL, flags, modif, &res );
1244 /* parse a comma-separated list of hex digits */
1245 static int parse_hex( unsigned char *dest, int *len, const char *buffer )
1247 const char *p = buffer;
1249 while (isxdigit(*p))
1253 memcpy( buf, p, 2 );
1255 sscanf( buf, "%x", &val );
1256 if (count++ >= *len) return -1; /* dest buffer overflow */
1257 *dest++ = (unsigned char )val;
1265 /* parse a value name and create the corresponding value */
1266 static struct key_value *parse_value_name( struct key *key, const char *buffer, int *len,
1267 struct file_load_info *info )
1269 struct key_value *value;
1272 maxlen = strlen(buffer) * sizeof(WCHAR);
1273 if (!get_file_tmp_space( info, maxlen )) return NULL;
1274 if (buffer[0] == '@')
1276 info->tmp[0] = info->tmp[1] = 0;
1281 if ((*len = parse_strW( (WCHAR *)info->tmp, &maxlen, buffer + 1, '\"' )) == -1) goto error;
1282 (*len)++; /* for initial quote */
1284 while (isspace(buffer[*len])) (*len)++;
1285 if (buffer[*len] != '=') goto error;
1287 while (isspace(buffer[*len])) (*len)++;
1288 if (!(value = find_value( key, (WCHAR *)info->tmp, &index )))
1289 value = insert_value( key, (WCHAR *)info->tmp, index );
1293 file_read_error( "Malformed value name", info );
1297 /* load a value from the input file */
1298 static int load_value( struct key *key, const char *buffer, struct file_load_info *info )
1302 int maxlen, len, res;
1303 int type, parse_type;
1304 struct key_value *value;
1306 if (!(value = parse_value_name( key, buffer, &len, info ))) return 0;
1307 if (!(res = get_data_type( buffer + len, &type, &parse_type ))) goto error;
1308 buffer += len + res;
1313 len = strlen(buffer) * sizeof(WCHAR);
1314 if (!get_file_tmp_space( info, len )) return 0;
1315 if ((res = parse_strW( (WCHAR *)info->tmp, &len, buffer, '\"' )) == -1) goto error;
1319 dw = strtoul( buffer, NULL, 16 );
1323 case REG_BINARY: /* hex digits */
1327 maxlen = 1 + strlen(buffer)/3; /* 3 chars for one hex byte */
1328 if (!get_file_tmp_space( info, len + maxlen )) return 0;
1329 if ((res = parse_hex( info->tmp + len, &maxlen, buffer )) == -1) goto error;
1332 while (isspace(*buffer)) buffer++;
1333 if (!*buffer) break;
1334 if (*buffer != '\\') goto error;
1335 if (read_next_line( info) != 1) goto error;
1336 buffer = info->buffer;
1337 while (isspace(*buffer)) buffer++;
1343 ptr = NULL; /* keep compiler quiet */
1347 if (!len) newptr = NULL;
1348 else if (!(newptr = memdup( ptr, len ))) return 0;
1350 if (value->data) free( value->data );
1351 value->data = newptr;
1354 /* update the key level but not the modification time */
1355 key->level = max( key->level, current_level );
1360 file_read_error( "Malformed value", info );
1364 /* return the length (in path elements) of name that is part of the key name */
1365 /* for instance if key is USER\foo\bar and name is foo\bar\baz, return 2 */
1366 static int get_prefix_len( struct key *key, const char *name, struct file_load_info *info )
1370 int len = strlen(name) * sizeof(WCHAR);
1371 if (!get_file_tmp_space( info, len )) return 0;
1373 if ((res = parse_strW( (WCHAR *)info->tmp, &len, name, ']' )) == -1)
1375 file_read_error( "Malformed key", info );
1378 for (p = (WCHAR *)info->tmp; *p; p++) if (*p == '\\') break;
1380 for (res = 1; key != root_key; res++)
1382 if (!strcmpiW( (WCHAR *)info->tmp, key->name )) break;
1385 if (key == root_key) res = 0; /* no matching name */
1389 /* load all the keys from the input file */
1390 static void load_keys( struct key *key, FILE *f )
1392 struct key *subkey = NULL;
1393 struct file_load_info info;
1395 int flags = (key->flags & KEY_VOLATILE) ? KEY_VOLATILE : KEY_DIRTY;
1396 int prefix_len = -1; /* number of key name prefixes to skip */
1402 if (!(info.buffer = mem_alloc( info.len ))) return;
1403 if (!(info.tmp = mem_alloc( info.tmplen )))
1405 free( info.buffer );
1409 if ((read_next_line( &info ) != 1) ||
1410 strcmp( info.buffer, "WINE REGISTRY Version 2" ))
1412 set_error( STATUS_NOT_REGISTRY_FILE );
1416 while (read_next_line( &info ) == 1)
1419 while (*p && isspace(*p)) p++;
1422 case '[': /* new key */
1423 if (subkey) release_object( subkey );
1424 if (prefix_len == -1) prefix_len = get_prefix_len( key, p + 1, &info );
1425 if (!(subkey = load_key( key, p + 1, flags, prefix_len, &info )))
1426 file_read_error( "Error creating key", &info );
1428 case '@': /* default value */
1429 case '\"': /* value */
1430 if (subkey) load_value( subkey, p, &info );
1431 else file_read_error( "Value without key", &info );
1433 case '#': /* comment */
1434 case ';': /* comment */
1435 case 0: /* empty line */
1438 file_read_error( "Unrecognized input", &info );
1444 if (subkey) release_object( subkey );
1445 free( info.buffer );
1449 /* load a part of the registry from a file */
1450 static void load_registry( struct key *key, obj_handle_t handle )
1455 if (!(obj = get_handle_obj( current->process, handle, GENERIC_READ, NULL ))) return;
1456 fd = dup(obj->ops->get_fd( obj ));
1457 release_object( obj );
1460 FILE *f = fdopen( fd, "r" );
1463 load_keys( key, f );
1466 else file_set_error();
1470 /* registry initialisation */
1471 void init_registry(void)
1473 static const WCHAR root_name[] = { 0 };
1474 static const WCHAR config_name[] =
1475 { 'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e','\\',
1476 'W','i','n','e','\\','W','i','n','e','\\','C','o','n','f','i','g',0 };
1482 /* create the root key */
1483 root_key = alloc_key( root_name, time(NULL) );
1485 root_key->flags |= KEY_ROOT;
1487 /* load the config file */
1488 config = wine_get_config_dir();
1489 if (!(filename = malloc( strlen(config) + 8 ))) fatal_error( "out of memory\n" );
1490 strcpy( filename, config );
1491 strcat( filename, "/config" );
1492 if ((f = fopen( filename, "r" )))
1497 /* create the config key */
1498 if (!(key = create_key( root_key, copy_path( config_name, sizeof(config_name), 0 ),
1499 NULL, 0, time(NULL), &dummy )))
1500 fatal_error( "could not create config key\n" );
1501 key->flags |= KEY_VOLATILE;
1503 load_keys( key, f );
1505 if (get_error() == STATUS_NOT_REGISTRY_FILE)
1506 fatal_error( "%s is not a valid registry file\n", filename );
1508 fatal_error( "loading %s failed with error %x\n", filename, get_error() );
1510 release_object( key );
1515 /* update the level of the parents of a key (only needed for the old format) */
1516 static int update_level( struct key *key )
1519 int max = key->level;
1520 for (i = 0; i <= key->last_subkey; i++)
1522 int sub = update_level( key->subkeys[i] );
1523 if (sub > max) max = sub;
1529 /* save a registry branch to a file */
1530 static void save_all_subkeys( struct key *key, FILE *f )
1532 fprintf( f, "WINE REGISTRY Version 2\n" );
1533 fprintf( f, ";; All keys relative to " );
1534 dump_path( key, NULL, f );
1536 save_subkeys( key, key, f );
1539 /* save a registry branch to a file handle */
1540 static void save_registry( struct key *key, obj_handle_t handle )
1545 if (key->flags & KEY_DELETED)
1547 set_error( STATUS_KEY_DELETED );
1550 if (!(obj = get_handle_obj( current->process, handle, GENERIC_WRITE, NULL ))) return;
1551 fd = dup(obj->ops->get_fd( obj ));
1552 release_object( obj );
1555 FILE *f = fdopen( fd, "w" );
1558 save_all_subkeys( key, f );
1559 if (fclose( f )) file_set_error();
1569 /* register a key branch for being saved on exit */
1570 static void register_branch_for_saving( struct key *key, const char *path, size_t len )
1572 if (save_branch_count >= MAX_SAVE_BRANCH_INFO)
1574 set_error( STATUS_NO_MORE_ENTRIES );
1577 if (!len || !(save_branch_info[save_branch_count].path = memdup( path, len ))) return;
1578 save_branch_info[save_branch_count].path[len - 1] = 0;
1579 save_branch_info[save_branch_count].key = (struct key *)grab_object( key );
1580 save_branch_count++;
1583 /* save a registry branch to a file */
1584 static int save_branch( struct key *key, const char *path )
1586 char *p, *real, *tmp = NULL;
1587 int fd, count = 0, ret = 0;
1590 if (!(key->flags & KEY_DIRTY))
1592 if (debug_level > 1) dump_operation( key, NULL, "Not saving clean" );
1596 /* get the real path */
1598 if (!(real = malloc( PATH_MAX ))) return 0;
1599 if (!realpath( path, real ))
1606 /* test the file type */
1608 if ((fd = open( path, O_WRONLY )) != -1)
1611 /* if file is not a regular file or has multiple links,
1612 write directly into it; otherwise use a temp file */
1613 if (!fstat( fd, &st ) && (!S_ISREG(st.st_mode) || st.st_nlink > 1))
1621 /* create a temp file in the same directory */
1623 if (!(tmp = malloc( strlen(path) + 20 ))) goto done;
1624 strcpy( tmp, path );
1625 if ((p = strrchr( tmp, '/' ))) p++;
1629 sprintf( p, "reg%lx%04x.tmp", (long) getpid(), count++ );
1630 if ((fd = open( tmp, O_CREAT | O_EXCL | O_WRONLY, 0666 )) != -1) break;
1631 if (errno != EEXIST) goto done;
1635 /* now save to it */
1638 if (!(f = fdopen( fd, "w" )))
1640 if (tmp) unlink( tmp );
1645 if (debug_level > 1)
1647 fprintf( stderr, "%s: ", path );
1648 dump_operation( key, NULL, "saving" );
1651 save_all_subkeys( key, f );
1656 /* if successfully written, rename to final name */
1657 if (ret) ret = !rename( tmp, path );
1658 if (!ret) unlink( tmp );
1663 if (real) free( real );
1664 if (ret) make_clean( key );
1668 /* periodic saving of the registry */
1669 static void periodic_save( void *arg )
1672 for (i = 0; i < save_branch_count; i++)
1673 save_branch( save_branch_info[i].key, save_branch_info[i].path );
1674 add_timeout( &next_save_time, save_period );
1675 save_timeout_user = add_timeout_user( &next_save_time, periodic_save, 0 );
1678 /* save the modified registry branches to disk */
1679 void flush_registry(void)
1683 for (i = 0; i < save_branch_count; i++)
1685 if (!save_branch( save_branch_info[i].key, save_branch_info[i].path ))
1687 fprintf( stderr, "wineserver: could not save registry branch to %s",
1688 save_branch_info[i].path );
1694 /* close the top-level keys; used on server exit */
1695 void close_registry(void)
1699 for (i = 0; i < save_branch_count; i++) release_object( save_branch_info[i].key );
1700 release_object( root_key );
1704 /* create a registry key */
1705 DECL_HANDLER(create_key)
1707 struct key *key = NULL, *parent;
1708 unsigned int access = req->access;
1709 WCHAR *name, *class;
1711 if (access & MAXIMUM_ALLOWED) access = KEY_ALL_ACCESS; /* FIXME: needs general solution */
1713 if (!(name = copy_req_path( req->namelen, !req->parent ))) return;
1714 if ((parent = get_hkey_obj( req->parent, 0 /*FIXME*/ )))
1716 int flags = (req->options & REG_OPTION_VOLATILE) ? KEY_VOLATILE : KEY_DIRTY;
1718 if (req->namelen == get_req_data_size()) /* no class specified */
1720 key = create_key( parent, name, NULL, flags, req->modif, &reply->created );
1724 const WCHAR *class_ptr = (WCHAR *)((char *)get_req_data() + req->namelen);
1726 if ((class = req_strdupW( req, class_ptr, get_req_data_size() - req->namelen )))
1728 key = create_key( parent, name, class, flags, req->modif, &reply->created );
1734 reply->hkey = alloc_handle( current->process, key, access, 0 );
1735 release_object( key );
1737 release_object( parent );
1741 /* open a registry key */
1742 DECL_HANDLER(open_key)
1744 struct key *key, *parent;
1745 unsigned int access = req->access;
1747 if (access & MAXIMUM_ALLOWED) access = KEY_ALL_ACCESS; /* FIXME: needs general solution */
1749 if ((parent = get_hkey_obj( req->parent, 0 /*FIXME*/ )))
1751 WCHAR *name = copy_path( get_req_data(), get_req_data_size(), !req->parent );
1752 if (name && (key = open_key( parent, name )))
1754 reply->hkey = alloc_handle( current->process, key, access, 0 );
1755 release_object( key );
1757 release_object( parent );
1761 /* delete a registry key */
1762 DECL_HANDLER(delete_key)
1766 if ((key = get_hkey_obj( req->hkey, 0 /*FIXME*/ )))
1769 release_object( key );
1773 /* enumerate registry subkeys */
1774 DECL_HANDLER(enum_key)
1778 if ((key = get_hkey_obj( req->hkey,
1779 req->index == -1 ? KEY_QUERY_VALUE : KEY_ENUMERATE_SUB_KEYS )))
1781 enum_key( key, req->index, req->info_class, reply );
1782 release_object( key );
1786 /* set a value of a registry key */
1787 DECL_HANDLER(set_key_value)
1792 if (!(name = copy_req_path( req->namelen, 0 ))) return;
1793 if ((key = get_hkey_obj( req->hkey, KEY_SET_VALUE )))
1795 size_t datalen = get_req_data_size() - req->namelen;
1796 const char *data = (char *)get_req_data() + req->namelen;
1798 set_value( key, name, req->type, data, datalen );
1799 release_object( key );
1803 /* retrieve the value of a registry key */
1804 DECL_HANDLER(get_key_value)
1810 if (!(name = copy_path( get_req_data(), get_req_data_size(), 0 ))) return;
1811 if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE )))
1813 get_value( key, name, &reply->type, &reply->total );
1814 release_object( key );
1818 /* enumerate the value of a registry key */
1819 DECL_HANDLER(enum_key_value)
1823 if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE )))
1825 enum_value( key, req->index, req->info_class, reply );
1826 release_object( key );
1830 /* delete a value of a registry key */
1831 DECL_HANDLER(delete_key_value)
1836 if ((key = get_hkey_obj( req->hkey, KEY_SET_VALUE )))
1838 if ((name = req_strdupW( req, get_req_data(), get_req_data_size() )))
1840 delete_value( key, name );
1843 release_object( key );
1847 /* load a registry branch from a file */
1848 DECL_HANDLER(load_registry)
1852 if ((key = get_hkey_obj( req->hkey, KEY_SET_VALUE | KEY_CREATE_SUB_KEY )))
1854 /* FIXME: use subkey name */
1855 load_registry( key, req->file );
1856 release_object( key );
1860 /* save a registry branch to a file */
1861 DECL_HANDLER(save_registry)
1865 if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS )))
1867 save_registry( key, req->file );
1868 release_object( key );
1872 /* set the current and saving level for the registry */
1873 DECL_HANDLER(set_registry_levels)
1875 current_level = req->current;
1876 saving_level = req->saving;
1878 /* set periodic save timer */
1880 if (save_timeout_user)
1882 remove_timeout_user( save_timeout_user );
1883 save_timeout_user = NULL;
1885 if ((save_period = req->period))
1887 if (save_period < 10000) save_period = 10000; /* limit rate */
1888 gettimeofday( &next_save_time, 0 );
1889 add_timeout( &next_save_time, save_period );
1890 save_timeout_user = add_timeout_user( &next_save_time, periodic_save, 0 );
1894 /* save a registry branch at server exit */
1895 DECL_HANDLER(save_registry_atexit)
1899 if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS )))
1901 register_branch_for_saving( key, get_req_data(), get_req_data_size() );
1902 release_object( key );
1906 /* add a registry key change notification */
1907 DECL_HANDLER(set_registry_notification)
1910 struct event *event;
1911 struct notify *notify;
1913 key = get_hkey_obj( req->hkey, KEY_NOTIFY );
1916 event = get_event_obj( current->process, req->event, SYNCHRONIZE );
1919 notify = find_notify( key, req->hkey );
1922 release_object( notify->event );
1923 grab_object( event );
1924 notify->event = event;
1928 notify = (struct notify *) malloc (sizeof *notify);
1931 grab_object( event );
1932 notify->event = event;
1933 notify->subtree = req->subtree;
1934 notify->filter = req->filter;
1935 notify->hkey = req->hkey;
1937 /* add to linked list */
1938 notify->prev = NULL;
1939 notify->next = key->first_notify;
1941 notify->next->prev = notify;
1943 key->last_notify = notify;
1944 key->first_notify = notify;
1947 set_error( STATUS_NO_MEMORY );
1949 release_object( event );
1951 release_object( key );