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"
51 #include "wine/library.h"
55 struct list entry
; /* entry in list of notifications */
56 struct event
*event
; /* event to set when changing this key */
57 int subtree
; /* true if subtree notification */
58 unsigned int filter
; /* which events to notify on */
59 obj_handle_t hkey
; /* hkey associated with this notification */
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 unsigned int flags
; /* flags */
76 time_t modif
; /* last modification time */
77 struct list notify_list
; /* list of notifications */
81 #define KEY_VOLATILE 0x0001 /* key is volatile (not saved to disk) */
82 #define KEY_DELETED 0x0002 /* key has been deleted */
83 #define KEY_DIRTY 0x0004 /* key has been modified */
88 WCHAR
*name
; /* value name */
89 int type
; /* value type */
90 size_t len
; /* value data length in bytes */
91 void *data
; /* pointer to value data */
94 #define MIN_SUBKEYS 8 /* min. number of allocated subkeys per key */
95 #define MIN_VALUES 8 /* min. number of allocated values per key */
98 /* the root of the registry tree */
99 static struct key
*root_key
;
101 static const int save_period
= 30000; /* delay between periodic saves (in ms) */
102 static struct timeout_user
*save_timeout_user
; /* saving timer */
104 static void set_periodic_save_timer(void);
106 /* information about where to save a registry branch */
107 struct save_branch_info
113 #define MAX_SAVE_BRANCH_INFO 3
114 static int save_branch_count
;
115 static struct save_branch_info save_branch_info
[MAX_SAVE_BRANCH_INFO
];
118 /* information about a file being loaded */
119 struct file_load_info
121 FILE *file
; /* input file */
122 char *buffer
; /* line buffer */
123 int len
; /* buffer length */
124 int line
; /* current input line */
125 char *tmp
; /* temp buffer to use while parsing input */
126 int tmplen
; /* length of temp buffer */
130 static void key_dump( struct object
*obj
, int verbose
);
131 static void key_destroy( struct object
*obj
);
133 static const struct object_ops key_ops
=
135 sizeof(struct key
), /* size */
137 no_add_queue
, /* add_queue */
138 NULL
, /* remove_queue */
140 NULL
, /* satisfied */
141 no_get_fd
, /* get_fd */
142 key_destroy
/* destroy */
147 * The registry text file format v2 used by this code is similar to the one
148 * used by REGEDIT import/export functionality, with the following differences:
149 * - strings and key names can contain \x escapes for Unicode
150 * - key names use escapes too in order to support Unicode
151 * - the modification time optionally follows the key name
152 * - REG_EXPAND_SZ and REG_MULTI_SZ are saved as strings instead of hex
155 static inline char to_hex( char ch
)
157 if (isdigit(ch
)) return ch
- '0';
158 return tolower(ch
) - 'a' + 10;
161 /* dump the full path of a key */
162 static void dump_path( const struct key
*key
, const struct key
*base
, FILE *f
)
164 if (key
->parent
&& key
->parent
!= base
)
166 dump_path( key
->parent
, base
, f
);
167 fprintf( f
, "\\\\" );
169 dump_strW( key
->name
, strlenW(key
->name
), f
, "[]" );
172 /* dump a value to a text file */
173 static void dump_value( const struct key_value
*value
, FILE *f
)
181 count
= 1 + dump_strW( value
->name
, strlenW(value
->name
), f
, "\"\"" );
182 count
+= fprintf( f
, "\"=" );
184 else count
= fprintf( f
, "@=" );
191 if (value
->type
!= REG_SZ
) fprintf( f
, "str(%d):", value
->type
);
193 if (value
->data
) dump_strW( (WCHAR
*)value
->data
, value
->len
/ sizeof(WCHAR
), f
, "\"\"" );
197 if (value
->len
== sizeof(DWORD
))
200 memcpy( &dw
, value
->data
, sizeof(DWORD
) );
201 fprintf( f
, "dword:%08lx", dw
);
204 /* else fall through */
206 if (value
->type
== REG_BINARY
) count
+= fprintf( f
, "hex:" );
207 else count
+= fprintf( f
, "hex(%x):", value
->type
);
208 for (i
= 0; i
< value
->len
; i
++)
210 count
+= fprintf( f
, "%02x", *((unsigned char *)value
->data
+ i
) );
211 if (i
< value
->len
-1)
216 fprintf( f
, "\\\n " );
226 /* save a registry and all its subkeys to a text file */
227 static void save_subkeys( const struct key
*key
, const struct key
*base
, FILE *f
)
231 if (key
->flags
& KEY_VOLATILE
) return;
232 /* save key if it has either some values or no subkeys */
233 /* keys with no values but subkeys are saved implicitly by saving the subkeys */
234 if ((key
->last_value
>= 0) || (key
->last_subkey
== -1))
237 if (key
!= base
) dump_path( key
, base
, f
);
238 fprintf( f
, "] %ld\n", (long)key
->modif
);
239 for (i
= 0; i
<= key
->last_value
; i
++) dump_value( &key
->values
[i
], f
);
241 for (i
= 0; i
<= key
->last_subkey
; i
++) save_subkeys( key
->subkeys
[i
], base
, f
);
244 static void dump_operation( const struct key
*key
, const struct key_value
*value
, const char *op
)
246 fprintf( stderr
, "%s key ", op
);
247 if (key
) dump_path( key
, NULL
, stderr
);
248 else fprintf( stderr
, "ERROR" );
251 fprintf( stderr
, " value ");
252 dump_value( value
, stderr
);
254 else fprintf( stderr
, "\n" );
257 static void key_dump( struct object
*obj
, int verbose
)
259 struct key
*key
= (struct key
*)obj
;
260 assert( obj
->ops
== &key_ops
);
261 fprintf( stderr
, "Key flags=%x ", key
->flags
);
262 dump_path( key
, NULL
, stderr
);
263 fprintf( stderr
, "\n" );
266 /* notify waiter and maybe delete the notification */
267 static void do_notification( struct key
*key
, struct notify
*notify
, int del
)
271 set_event( notify
->event
);
272 release_object( notify
->event
);
273 notify
->event
= NULL
;
277 list_remove( ¬ify
->entry
);
282 static struct notify
*find_notify( struct key
*key
, obj_handle_t hkey
)
284 struct notify
*notify
;
286 LIST_FOR_EACH_ENTRY( notify
, &key
->notify_list
, struct notify
, entry
)
288 if (notify
->hkey
== hkey
) return notify
;
293 /* close the notification associated with a handle */
294 void registry_close_handle( struct object
*obj
, obj_handle_t hkey
)
296 struct key
* key
= (struct key
*) obj
;
297 struct notify
*notify
;
299 if( obj
->ops
!= &key_ops
)
301 notify
= find_notify( key
, hkey
);
304 do_notification( key
, notify
, 1 );
307 static void key_destroy( struct object
*obj
)
311 struct key
*key
= (struct key
*)obj
;
312 assert( obj
->ops
== &key_ops
);
314 if (key
->name
) free( key
->name
);
315 if (key
->class) free( key
->class );
316 for (i
= 0; i
<= key
->last_value
; i
++)
318 free( key
->values
[i
].name
);
319 if (key
->values
[i
].data
) free( key
->values
[i
].data
);
321 for (i
= 0; i
<= key
->last_subkey
; i
++)
323 key
->subkeys
[i
]->parent
= NULL
;
324 release_object( key
->subkeys
[i
] );
326 /* unconditionally notify everything waiting on this key */
327 while ((ptr
= list_head( &key
->notify_list
)))
329 struct notify
*notify
= LIST_ENTRY( ptr
, struct notify
, entry
);
330 do_notification( key
, notify
, 1 );
334 /* duplicate a key path */
335 /* returns a pointer to a static buffer, so only useable once per request */
336 static WCHAR
*copy_path( const WCHAR
*path
, size_t len
, int skip_root
)
338 static WCHAR buffer
[MAX_PATH
+1];
339 static const WCHAR root_name
[] = { '\\','R','e','g','i','s','t','r','y','\\',0 };
341 if (len
> sizeof(buffer
)-sizeof(buffer
[0]))
343 set_error( STATUS_BUFFER_OVERFLOW
);
346 memcpy( buffer
, path
, len
);
347 buffer
[len
/ sizeof(WCHAR
)] = 0;
348 if (skip_root
&& !strncmpiW( buffer
, root_name
, 10 )) return buffer
+ 10;
352 /* copy a path from the request buffer */
353 static WCHAR
*copy_req_path( size_t len
, int skip_root
)
355 const WCHAR
*name_ptr
= get_req_data();
356 if (len
> get_req_data_size())
358 fatal_protocol_error( current
, "copy_req_path: invalid length %d/%d\n",
359 len
, get_req_data_size() );
362 return copy_path( name_ptr
, len
, skip_root
);
365 /* return the next token in a given path */
366 /* returns a pointer to a static buffer, so only useable once per request */
367 static WCHAR
*get_path_token( WCHAR
*initpath
)
374 /* path cannot start with a backslash */
375 if (*initpath
== '\\')
377 set_error( STATUS_OBJECT_PATH_INVALID
);
382 else while (*path
== '\\') path
++;
385 while (*path
&& *path
!= '\\') path
++;
386 if (*path
) *path
++ = 0;
390 /* duplicate a Unicode string from the request buffer */
391 static WCHAR
*req_strdupW( const void *req
, const WCHAR
*str
, size_t len
)
394 if ((name
= mem_alloc( len
+ sizeof(WCHAR
) )) != NULL
)
396 memcpy( name
, str
, len
);
397 name
[len
/ sizeof(WCHAR
)] = 0;
402 /* allocate a key object */
403 static struct key
*alloc_key( const WCHAR
*name
, time_t modif
)
406 if ((key
= alloc_object( &key_ops
)))
410 key
->last_subkey
= -1;
414 key
->last_value
= -1;
418 list_init( &key
->notify_list
);
419 if (!(key
->name
= strdupW( name
)))
421 release_object( key
);
428 /* mark a key and all its parents as dirty (modified) */
429 static void make_dirty( struct key
*key
)
433 if (key
->flags
& (KEY_DIRTY
|KEY_VOLATILE
)) return; /* nothing to do */
434 key
->flags
|= KEY_DIRTY
;
439 /* mark a key and all its subkeys as clean (not modified) */
440 static void make_clean( struct key
*key
)
444 if (key
->flags
& KEY_VOLATILE
) return;
445 if (!(key
->flags
& KEY_DIRTY
)) return;
446 key
->flags
&= ~KEY_DIRTY
;
447 for (i
= 0; i
<= key
->last_subkey
; i
++) make_clean( key
->subkeys
[i
] );
450 /* go through all the notifications and send them if necessary */
451 void check_notify( struct key
*key
, unsigned int change
, int not_subtree
)
453 struct list
*ptr
, *next
;
455 LIST_FOR_EACH_SAFE( ptr
, next
, &key
->notify_list
)
457 struct notify
*n
= LIST_ENTRY( ptr
, struct notify
, entry
);
458 if ( ( not_subtree
|| n
->subtree
) && ( change
& n
->filter
) )
459 do_notification( key
, n
, 0 );
463 /* update key modification time */
464 static void touch_key( struct key
*key
, unsigned int change
)
468 key
->modif
= time(NULL
);
471 /* do notifications */
472 check_notify( key
, change
, 1 );
473 for ( k
= key
->parent
; k
; k
= k
->parent
)
474 check_notify( k
, change
& ~REG_NOTIFY_CHANGE_LAST_SET
, 0 );
477 /* try to grow the array of subkeys; return 1 if OK, 0 on error */
478 static int grow_subkeys( struct key
*key
)
480 struct key
**new_subkeys
;
485 nb_subkeys
= key
->nb_subkeys
+ (key
->nb_subkeys
/ 2); /* grow by 50% */
486 if (!(new_subkeys
= realloc( key
->subkeys
, nb_subkeys
* sizeof(*new_subkeys
) )))
488 set_error( STATUS_NO_MEMORY
);
494 nb_subkeys
= MIN_VALUES
;
495 if (!(new_subkeys
= mem_alloc( nb_subkeys
* sizeof(*new_subkeys
) ))) return 0;
497 key
->subkeys
= new_subkeys
;
498 key
->nb_subkeys
= nb_subkeys
;
502 /* allocate a subkey for a given key, and return its index */
503 static struct key
*alloc_subkey( struct key
*parent
, const WCHAR
*name
, int index
, time_t modif
)
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 WCHAR
*name
, int *index
)
555 int i
, min
, max
, res
;
558 max
= key
->last_subkey
;
562 if (!(res
= strcmpiW( key
->subkeys
[i
]->name
, name
)))
565 return key
->subkeys
[i
];
567 if (res
> 0) max
= i
- 1;
570 *index
= min
; /* this is where we should insert it */
575 /* warning: the key name must be writeable (use copy_path) */
576 static struct key
*open_key( struct key
*key
, WCHAR
*name
)
581 if (!(path
= get_path_token( name
))) return NULL
;
584 if (!(key
= find_subkey( key
, path
, &index
)))
586 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
589 path
= get_path_token( NULL
);
592 if (debug_level
> 1) dump_operation( key
, NULL
, "Open" );
593 if (key
) grab_object( key
);
597 /* create a subkey */
598 /* warning: the key name must be writeable (use copy_path) */
599 static struct key
*create_key( struct key
*key
, WCHAR
*name
, WCHAR
*class,
600 int flags
, time_t modif
, int *created
)
606 if (key
->flags
& KEY_DELETED
) /* we cannot create a subkey under a deleted key */
608 set_error( STATUS_KEY_DELETED
);
611 if (!(flags
& KEY_VOLATILE
) && (key
->flags
& KEY_VOLATILE
))
613 set_error( STATUS_CHILD_MUST_BE_VOLATILE
);
616 if (!modif
) modif
= time(NULL
);
618 if (!(path
= get_path_token( name
))) return NULL
;
623 if (!(subkey
= find_subkey( key
, path
, &index
))) break;
625 path
= get_path_token( NULL
);
628 /* create the remaining part */
630 if (!*path
) goto done
;
632 if (flags
& KEY_DIRTY
) make_dirty( key
);
635 key
= alloc_subkey( key
, path
, index
, modif
);
639 path
= get_path_token( NULL
);
640 if (!*path
) goto done
;
641 /* we know the index is always 0 in a new key */
642 key
= alloc_subkey( key
, path
, 0, modif
);
644 if (base_idx
!= -1) free_subkey( base
, base_idx
);
648 if (debug_level
> 1) dump_operation( key
, NULL
, "Create" );
649 if (class) key
->class = strdupW(class);
654 /* query information about a key or a subkey */
655 static void enum_key( const struct key
*key
, int index
, int info_class
,
656 struct enum_key_reply
*reply
)
659 size_t len
, namelen
, classlen
;
660 int max_subkey
= 0, max_class
= 0;
661 int max_value
= 0, max_data
= 0;
664 if (index
!= -1) /* -1 means use the specified key directly */
666 if ((index
< 0) || (index
> key
->last_subkey
))
668 set_error( STATUS_NO_MORE_ENTRIES
);
671 key
= key
->subkeys
[index
];
674 namelen
= strlenW(key
->name
) * sizeof(WCHAR
);
675 classlen
= key
->class ? strlenW(key
->class) * sizeof(WCHAR
) : 0;
679 case KeyBasicInformation
:
680 classlen
= 0; /* only return the name */
682 case KeyNodeInformation
:
683 reply
->max_subkey
= 0;
684 reply
->max_class
= 0;
685 reply
->max_value
= 0;
688 case KeyFullInformation
:
689 for (i
= 0; i
<= key
->last_subkey
; i
++)
691 struct key
*subkey
= key
->subkeys
[i
];
692 len
= strlenW( subkey
->name
);
693 if (len
> max_subkey
) max_subkey
= len
;
694 if (!subkey
->class) continue;
695 len
= strlenW( subkey
->class );
696 if (len
> max_class
) max_class
= len
;
698 for (i
= 0; i
<= key
->last_value
; i
++)
700 len
= strlenW( key
->values
[i
].name
);
701 if (len
> max_value
) max_value
= len
;
702 len
= key
->values
[i
].len
;
703 if (len
> max_data
) max_data
= len
;
705 reply
->max_subkey
= max_subkey
;
706 reply
->max_class
= max_class
;
707 reply
->max_value
= max_value
;
708 reply
->max_data
= max_data
;
709 namelen
= 0; /* only return the class */
712 set_error( STATUS_INVALID_PARAMETER
);
715 reply
->subkeys
= key
->last_subkey
+ 1;
716 reply
->values
= key
->last_value
+ 1;
717 reply
->modif
= key
->modif
;
718 reply
->total
= namelen
+ classlen
;
720 len
= min( reply
->total
, get_reply_max_size() );
721 if (len
&& (data
= set_reply_data_size( len
)))
725 reply
->namelen
= namelen
;
726 memcpy( data
, key
->name
, namelen
);
727 memcpy( (char *)data
+ namelen
, key
->class, len
- namelen
);
731 reply
->namelen
= len
;
732 memcpy( data
, key
->name
, len
);
735 if (debug_level
> 1) dump_operation( key
, NULL
, "Enum" );
738 /* delete a key and its values */
739 static int delete_key( struct key
*key
, int recurse
)
744 /* must find parent and index */
747 set_error( STATUS_ACCESS_DENIED
);
750 if (!(parent
= key
->parent
) || (key
->flags
& KEY_DELETED
))
752 set_error( STATUS_KEY_DELETED
);
756 while (recurse
&& (key
->last_subkey
>=0))
757 if(0>delete_key(key
->subkeys
[key
->last_subkey
], 1))
760 for (index
= 0; index
<= parent
->last_subkey
; index
++)
761 if (parent
->subkeys
[index
] == key
) break;
762 assert( index
<= parent
->last_subkey
);
764 /* we can only delete a key that has no subkeys */
765 if (key
->last_subkey
>= 0)
767 set_error( STATUS_ACCESS_DENIED
);
771 if (debug_level
> 1) dump_operation( key
, NULL
, "Delete" );
772 free_subkey( parent
, index
);
773 touch_key( parent
, REG_NOTIFY_CHANGE_NAME
);
777 /* try to grow the array of values; return 1 if OK, 0 on error */
778 static int grow_values( struct key
*key
)
780 struct key_value
*new_val
;
785 nb_values
= key
->nb_values
+ (key
->nb_values
/ 2); /* grow by 50% */
786 if (!(new_val
= realloc( key
->values
, nb_values
* sizeof(*new_val
) )))
788 set_error( STATUS_NO_MEMORY
);
794 nb_values
= MIN_VALUES
;
795 if (!(new_val
= mem_alloc( nb_values
* sizeof(*new_val
) ))) return 0;
797 key
->values
= new_val
;
798 key
->nb_values
= nb_values
;
802 /* find the named value of a given key and return its index in the array */
803 static struct key_value
*find_value( const struct key
*key
, const WCHAR
*name
, int *index
)
805 int i
, min
, max
, res
;
808 max
= key
->last_value
;
812 if (!(res
= strcmpiW( key
->values
[i
].name
, name
)))
815 return &key
->values
[i
];
817 if (res
> 0) max
= i
- 1;
820 *index
= min
; /* this is where we should insert it */
824 /* insert a new value; the index must have been returned by find_value */
825 static struct key_value
*insert_value( struct key
*key
, const WCHAR
*name
, int index
)
827 struct key_value
*value
;
831 if (key
->last_value
+ 1 == key
->nb_values
)
833 if (!grow_values( key
)) return NULL
;
835 if (!(new_name
= strdupW(name
))) return NULL
;
836 for (i
= ++key
->last_value
; i
> index
; i
--) key
->values
[i
] = key
->values
[i
- 1];
837 value
= &key
->values
[index
];
838 value
->name
= new_name
;
844 /* set a key value */
845 static void set_value( struct key
*key
, WCHAR
*name
, int type
, const void *data
, size_t len
)
847 struct key_value
*value
;
851 if ((value
= find_value( key
, name
, &index
)))
853 /* check if the new value is identical to the existing one */
854 if (value
->type
== type
&& value
->len
== len
&&
855 value
->data
&& !memcmp( value
->data
, data
, len
))
857 if (debug_level
> 1) dump_operation( key
, value
, "Skip setting" );
862 if (len
&& !(ptr
= memdup( data
, len
))) return;
866 if (!(value
= insert_value( key
, name
, index
)))
868 if (ptr
) free( ptr
);
872 else if (value
->data
) free( value
->data
); /* already existing, free previous data */
877 touch_key( key
, REG_NOTIFY_CHANGE_LAST_SET
);
878 if (debug_level
> 1) dump_operation( key
, value
, "Set" );
881 /* get a key value */
882 static void get_value( struct key
*key
, const WCHAR
*name
, int *type
, int *len
)
884 struct key_value
*value
;
887 if ((value
= find_value( key
, name
, &index
)))
891 if (value
->data
) set_reply_data( value
->data
, min( value
->len
, get_reply_max_size() ));
892 if (debug_level
> 1) dump_operation( key
, value
, "Get" );
897 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
901 /* enumerate a key value */
902 static void enum_value( struct key
*key
, int i
, int info_class
, struct enum_key_value_reply
*reply
)
904 struct key_value
*value
;
906 if (i
< 0 || i
> key
->last_value
) set_error( STATUS_NO_MORE_ENTRIES
);
910 size_t namelen
, maxlen
;
912 value
= &key
->values
[i
];
913 reply
->type
= value
->type
;
914 namelen
= strlenW( value
->name
) * sizeof(WCHAR
);
918 case KeyValueBasicInformation
:
919 reply
->total
= namelen
;
921 case KeyValueFullInformation
:
922 reply
->total
= namelen
+ value
->len
;
924 case KeyValuePartialInformation
:
925 reply
->total
= value
->len
;
929 set_error( STATUS_INVALID_PARAMETER
);
933 maxlen
= min( reply
->total
, get_reply_max_size() );
934 if (maxlen
&& ((data
= set_reply_data_size( maxlen
))))
936 if (maxlen
> namelen
)
938 reply
->namelen
= namelen
;
939 memcpy( data
, value
->name
, namelen
);
940 memcpy( (char *)data
+ namelen
, value
->data
, maxlen
- namelen
);
944 reply
->namelen
= maxlen
;
945 memcpy( data
, value
->name
, maxlen
);
948 if (debug_level
> 1) dump_operation( key
, value
, "Enum" );
953 static void delete_value( struct key
*key
, const WCHAR
*name
)
955 struct key_value
*value
;
956 int i
, index
, nb_values
;
958 if (!(value
= find_value( key
, name
, &index
)))
960 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
963 if (debug_level
> 1) dump_operation( key
, value
, "Delete" );
965 if (value
->data
) free( value
->data
);
966 for (i
= index
; i
< key
->last_value
; i
++) key
->values
[i
] = key
->values
[i
+ 1];
968 touch_key( key
, REG_NOTIFY_CHANGE_LAST_SET
);
970 /* try to shrink the array */
971 nb_values
= key
->nb_values
;
972 if (nb_values
> MIN_VALUES
&& key
->last_value
< nb_values
/ 2)
974 struct key_value
*new_val
;
975 nb_values
-= nb_values
/ 3; /* shrink by 33% */
976 if (nb_values
< MIN_VALUES
) nb_values
= MIN_VALUES
;
977 if (!(new_val
= realloc( key
->values
, nb_values
* sizeof(*new_val
) ))) return;
978 key
->values
= new_val
;
979 key
->nb_values
= nb_values
;
983 /* get the registry key corresponding to an hkey handle */
984 static struct key
*get_hkey_obj( obj_handle_t hkey
, unsigned int access
)
986 if (!hkey
) return (struct key
*)grab_object( root_key
);
987 return (struct key
*)get_handle_obj( current
->process
, hkey
, access
, &key_ops
);
990 /* read a line from the input file */
991 static int read_next_line( struct file_load_info
*info
)
999 if (!fgets( info
->buffer
+ pos
, info
->len
- pos
, info
->file
))
1000 return (pos
!= 0); /* EOF */
1001 pos
= strlen(info
->buffer
);
1002 if (info
->buffer
[pos
-1] == '\n')
1004 /* got a full line */
1005 info
->buffer
[--pos
] = 0;
1006 if (pos
> 0 && info
->buffer
[pos
-1] == '\r') info
->buffer
[pos
-1] = 0;
1009 if (pos
< info
->len
- 1) return 1; /* EOF but something was read */
1011 /* need to enlarge the buffer */
1012 newlen
= info
->len
+ info
->len
/ 2;
1013 if (!(newbuf
= realloc( info
->buffer
, newlen
)))
1015 set_error( STATUS_NO_MEMORY
);
1018 info
->buffer
= newbuf
;
1023 /* make sure the temp buffer holds enough space */
1024 static int get_file_tmp_space( struct file_load_info
*info
, int size
)
1027 if (info
->tmplen
>= size
) return 1;
1028 if (!(tmp
= realloc( info
->tmp
, size
)))
1030 set_error( STATUS_NO_MEMORY
);
1034 info
->tmplen
= size
;
1038 /* report an error while loading an input file */
1039 static void file_read_error( const char *err
, struct file_load_info
*info
)
1041 fprintf( stderr
, "Line %d: %s '%s'\n", info
->line
, err
, info
->buffer
);
1044 /* parse an escaped string back into Unicode */
1045 /* return the number of chars read from the input, or -1 on output overflow */
1046 static int parse_strW( WCHAR
*dest
, int *len
, const char *src
, char endchar
)
1048 int count
= sizeof(WCHAR
); /* for terminating null */
1049 const char *p
= src
;
1050 while (*p
&& *p
!= endchar
)
1052 if (*p
!= '\\') *dest
= (WCHAR
)*p
++;
1058 case 'a': *dest
= '\a'; p
++; break;
1059 case 'b': *dest
= '\b'; p
++; break;
1060 case 'e': *dest
= '\e'; p
++; break;
1061 case 'f': *dest
= '\f'; p
++; break;
1062 case 'n': *dest
= '\n'; p
++; break;
1063 case 'r': *dest
= '\r'; p
++; break;
1064 case 't': *dest
= '\t'; p
++; break;
1065 case 'v': *dest
= '\v'; p
++; break;
1066 case 'x': /* hex escape */
1068 if (!isxdigit(*p
)) *dest
= 'x';
1071 *dest
= to_hex(*p
++);
1072 if (isxdigit(*p
)) *dest
= (*dest
* 16) + to_hex(*p
++);
1073 if (isxdigit(*p
)) *dest
= (*dest
* 16) + to_hex(*p
++);
1074 if (isxdigit(*p
)) *dest
= (*dest
* 16) + to_hex(*p
++);
1084 case '7': /* octal escape */
1086 if (*p
>= '0' && *p
<= '7') *dest
= (*dest
* 8) + (*p
++ - '0');
1087 if (*p
>= '0' && *p
<= '7') *dest
= (*dest
* 8) + (*p
++ - '0');
1090 *dest
= (WCHAR
)*p
++;
1094 if ((count
+= sizeof(WCHAR
)) > *len
) return -1; /* dest buffer overflow */
1098 if (!*p
) return -1; /* delimiter not found */
1103 /* convert a data type tag to a value type */
1104 static int get_data_type( const char *buffer
, int *type
, int *parse_type
)
1106 struct data_type
{ const char *tag
; int len
; int type
; int parse_type
; };
1108 static const struct data_type data_types
[] =
1109 { /* actual type */ /* type to assume for parsing */
1110 { "\"", 1, REG_SZ
, REG_SZ
},
1111 { "str:\"", 5, REG_SZ
, REG_SZ
},
1112 { "str(2):\"", 8, REG_EXPAND_SZ
, REG_SZ
},
1113 { "str(7):\"", 8, REG_MULTI_SZ
, REG_SZ
},
1114 { "hex:", 4, REG_BINARY
, REG_BINARY
},
1115 { "dword:", 6, REG_DWORD
, REG_DWORD
},
1116 { "hex(", 4, -1, REG_BINARY
},
1120 const struct data_type
*ptr
;
1123 for (ptr
= data_types
; ptr
->tag
; ptr
++)
1125 if (memcmp( ptr
->tag
, buffer
, ptr
->len
)) continue;
1126 *parse_type
= ptr
->parse_type
;
1127 if ((*type
= ptr
->type
) != -1) return ptr
->len
;
1128 /* "hex(xx):" is special */
1129 *type
= (int)strtoul( buffer
+ 4, &end
, 16 );
1130 if ((end
<= buffer
) || memcmp( end
, "):", 2 )) return 0;
1131 return end
+ 2 - buffer
;
1136 /* load and create a key from the input file */
1137 static struct key
*load_key( struct key
*base
, const char *buffer
, int flags
,
1138 int prefix_len
, struct file_load_info
*info
,
1142 int res
, len
, modif
;
1144 len
= strlen(buffer
) * sizeof(WCHAR
);
1145 if (!get_file_tmp_space( info
, len
)) return NULL
;
1147 if ((res
= parse_strW( (WCHAR
*)info
->tmp
, &len
, buffer
, ']' )) == -1)
1149 file_read_error( "Malformed key", info
);
1152 if (sscanf( buffer
+ res
, " %d", &modif
) != 1) modif
= default_modif
;
1154 p
= (WCHAR
*)info
->tmp
;
1155 while (prefix_len
&& *p
) { if (*p
++ == '\\') prefix_len
--; }
1161 file_read_error( "Malformed key", info
);
1164 /* empty key name, return base key */
1165 return (struct key
*)grab_object( base
);
1167 if (!(name
= copy_path( p
, len
- ((char *)p
- info
->tmp
), 0 )))
1169 file_read_error( "Key is too long", info
);
1172 return create_key( base
, name
, NULL
, flags
, modif
, &res
);
1175 /* parse a comma-separated list of hex digits */
1176 static int parse_hex( unsigned char *dest
, int *len
, const char *buffer
)
1178 const char *p
= buffer
;
1180 while (isxdigit(*p
))
1184 memcpy( buf
, p
, 2 );
1186 sscanf( buf
, "%x", &val
);
1187 if (count
++ >= *len
) return -1; /* dest buffer overflow */
1188 *dest
++ = (unsigned char )val
;
1196 /* parse a value name and create the corresponding value */
1197 static struct key_value
*parse_value_name( struct key
*key
, const char *buffer
, int *len
,
1198 struct file_load_info
*info
)
1200 struct key_value
*value
;
1203 maxlen
= strlen(buffer
) * sizeof(WCHAR
);
1204 if (!get_file_tmp_space( info
, maxlen
)) return NULL
;
1205 if (buffer
[0] == '@')
1207 info
->tmp
[0] = info
->tmp
[1] = 0;
1212 if ((*len
= parse_strW( (WCHAR
*)info
->tmp
, &maxlen
, buffer
+ 1, '\"' )) == -1) goto error
;
1213 (*len
)++; /* for initial quote */
1215 while (isspace(buffer
[*len
])) (*len
)++;
1216 if (buffer
[*len
] != '=') goto error
;
1218 while (isspace(buffer
[*len
])) (*len
)++;
1219 if (!(value
= find_value( key
, (WCHAR
*)info
->tmp
, &index
)))
1220 value
= insert_value( key
, (WCHAR
*)info
->tmp
, index
);
1224 file_read_error( "Malformed value name", info
);
1228 /* load a value from the input file */
1229 static int load_value( struct key
*key
, const char *buffer
, struct file_load_info
*info
)
1233 int maxlen
, len
, res
;
1234 int type
, parse_type
;
1235 struct key_value
*value
;
1237 if (!(value
= parse_value_name( key
, buffer
, &len
, info
))) return 0;
1238 if (!(res
= get_data_type( buffer
+ len
, &type
, &parse_type
))) goto error
;
1239 buffer
+= len
+ res
;
1244 len
= strlen(buffer
) * sizeof(WCHAR
);
1245 if (!get_file_tmp_space( info
, len
)) return 0;
1246 if ((res
= parse_strW( (WCHAR
*)info
->tmp
, &len
, buffer
, '\"' )) == -1) goto error
;
1250 dw
= strtoul( buffer
, NULL
, 16 );
1254 case REG_BINARY
: /* hex digits */
1258 maxlen
= 1 + strlen(buffer
)/3; /* 3 chars for one hex byte */
1259 if (!get_file_tmp_space( info
, len
+ maxlen
)) return 0;
1260 if ((res
= parse_hex( info
->tmp
+ len
, &maxlen
, buffer
)) == -1) goto error
;
1263 while (isspace(*buffer
)) buffer
++;
1264 if (!*buffer
) break;
1265 if (*buffer
!= '\\') goto error
;
1266 if (read_next_line( info
) != 1) goto error
;
1267 buffer
= info
->buffer
;
1268 while (isspace(*buffer
)) buffer
++;
1274 ptr
= NULL
; /* keep compiler quiet */
1278 if (!len
) newptr
= NULL
;
1279 else if (!(newptr
= memdup( ptr
, len
))) return 0;
1281 if (value
->data
) free( value
->data
);
1282 value
->data
= newptr
;
1289 file_read_error( "Malformed value", info
);
1293 /* return the length (in path elements) of name that is part of the key name */
1294 /* for instance if key is USER\foo\bar and name is foo\bar\baz, return 2 */
1295 static int get_prefix_len( struct key
*key
, const char *name
, struct file_load_info
*info
)
1299 int len
= strlen(name
) * sizeof(WCHAR
);
1300 if (!get_file_tmp_space( info
, len
)) return 0;
1302 if ((res
= parse_strW( (WCHAR
*)info
->tmp
, &len
, name
, ']' )) == -1)
1304 file_read_error( "Malformed key", info
);
1307 for (p
= (WCHAR
*)info
->tmp
; *p
; p
++) if (*p
== '\\') break;
1309 for (res
= 1; key
!= root_key
; res
++)
1311 if (!strcmpiW( (WCHAR
*)info
->tmp
, key
->name
)) break;
1314 if (key
== root_key
) res
= 0; /* no matching name */
1318 /* load all the keys from the input file */
1319 /* prefix_len is the number of key name prefixes to skip, or -1 for autodetection */
1320 static void load_keys( struct key
*key
, FILE *f
, int prefix_len
)
1322 struct key
*subkey
= NULL
;
1323 struct file_load_info info
;
1325 int default_modif
= time(NULL
);
1326 int flags
= (key
->flags
& KEY_VOLATILE
) ? KEY_VOLATILE
: KEY_DIRTY
;
1332 if (!(info
.buffer
= mem_alloc( info
.len
))) return;
1333 if (!(info
.tmp
= mem_alloc( info
.tmplen
)))
1335 free( info
.buffer
);
1339 if ((read_next_line( &info
) != 1) ||
1340 strcmp( info
.buffer
, "WINE REGISTRY Version 2" ))
1342 set_error( STATUS_NOT_REGISTRY_FILE
);
1346 while (read_next_line( &info
) == 1)
1349 while (*p
&& isspace(*p
)) p
++;
1352 case '[': /* new key */
1353 if (subkey
) release_object( subkey
);
1354 if (prefix_len
== -1) prefix_len
= get_prefix_len( key
, p
+ 1, &info
);
1355 if (!(subkey
= load_key( key
, p
+ 1, flags
, prefix_len
, &info
, default_modif
)))
1356 file_read_error( "Error creating key", &info
);
1358 case '@': /* default value */
1359 case '\"': /* value */
1360 if (subkey
) load_value( subkey
, p
, &info
);
1361 else file_read_error( "Value without key", &info
);
1363 case '#': /* comment */
1364 case ';': /* comment */
1365 case 0: /* empty line */
1368 file_read_error( "Unrecognized input", &info
);
1374 if (subkey
) release_object( subkey
);
1375 free( info
.buffer
);
1379 /* load a part of the registry from a file */
1380 static void load_registry( struct key
*key
, obj_handle_t handle
)
1385 if (!(file
= get_file_obj( current
->process
, handle
, GENERIC_READ
))) return;
1386 fd
= dup( get_file_unix_fd( file
) );
1387 release_object( file
);
1390 FILE *f
= fdopen( fd
, "r" );
1393 load_keys( key
, f
, -1 );
1396 else file_set_error();
1400 /* load one of the initial registry files */
1401 static void load_init_registry_from_file( const char *filename
, struct key
*key
)
1405 if ((f
= fopen( filename
, "r" )))
1407 load_keys( key
, f
, 0 );
1409 if (get_error() == STATUS_NOT_REGISTRY_FILE
)
1410 fatal_error( "%s is not a valid registry file\n", filename
);
1412 fatal_error( "loading %s failed with error %x\n", filename
, get_error() );
1415 if (!(key
->flags
& KEY_VOLATILE
))
1417 assert( save_branch_count
< MAX_SAVE_BRANCH_INFO
);
1419 if ((save_branch_info
[save_branch_count
].path
= strdup( filename
)))
1420 save_branch_info
[save_branch_count
++].key
= (struct key
*)grab_object( key
);
1424 /* load the user registry files */
1425 static void load_user_registries( struct key
*key_current_user
)
1427 const char *config
= wine_get_config_dir();
1430 /* load user.reg into HKEY_CURRENT_USER */
1432 if (!(filename
= mem_alloc( strlen(config
) + sizeof("/user.reg") ))) return;
1433 strcpy( filename
, config
);
1434 strcat( filename
, "/user.reg" );
1435 load_init_registry_from_file( filename
, key_current_user
);
1438 /* start the periodic save timer */
1439 set_periodic_save_timer();
1442 /* registry initialisation */
1443 void init_registry(void)
1445 static const WCHAR root_name
[] = { 0 };
1446 static const WCHAR HKLM
[] = { 'M','a','c','h','i','n','e' };
1447 static const WCHAR HKU_default
[] = { 'U','s','e','r','\\','.','D','e','f','a','u','l','t' };
1448 static const WCHAR config_name
[] =
1449 { 'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e','\\',
1450 'W','i','n','e','\\','W','i','n','e','\\','C','o','n','f','i','g',0 };
1452 const char *config
= wine_get_config_dir();
1457 /* create the root key */
1458 root_key
= alloc_key( root_name
, time(NULL
) );
1461 /* load the config file */
1462 if (!(filename
= malloc( strlen(config
) + 16 ))) fatal_error( "out of memory\n" );
1463 strcpy( filename
, config
);
1464 p
= filename
+ strlen(filename
);
1466 /* load system.reg into Registry\Machine */
1468 if (!(key
= create_key( root_key
, copy_path( HKLM
, sizeof(HKLM
), 0 ),
1469 NULL
, 0, time(NULL
), &dummy
)))
1470 fatal_error( "could not create Machine registry key\n" );
1472 strcpy( p
, "/system.reg" );
1473 load_init_registry_from_file( filename
, key
);
1474 release_object( key
);
1476 /* load userdef.reg into Registry\User\.Default */
1478 if (!(key
= create_key( root_key
, copy_path( HKU_default
, sizeof(HKU_default
), 0 ),
1479 NULL
, 0, time(NULL
), &dummy
)))
1480 fatal_error( "could not create User\\.Default registry key\n" );
1482 strcpy( p
, "/userdef.reg" );
1483 load_init_registry_from_file( filename
, key
);
1484 release_object( key
);
1486 /* load config into Registry\Machine\Software\Wine\Wine\Config */
1488 if (!(key
= create_key( root_key
, copy_path( config_name
, sizeof(config_name
), 0 ),
1489 NULL
, 0, time(NULL
), &dummy
)))
1490 fatal_error( "could not create Config registry key\n" );
1492 key
->flags
|= KEY_VOLATILE
;
1493 strcpy( p
, "/config" );
1494 load_init_registry_from_file( filename
, key
);
1495 release_object( key
);
1500 /* save a registry branch to a file */
1501 static void save_all_subkeys( struct key
*key
, FILE *f
)
1503 fprintf( f
, "WINE REGISTRY Version 2\n" );
1504 fprintf( f
, ";; All keys relative to " );
1505 dump_path( key
, NULL
, f
);
1507 save_subkeys( key
, key
, f
);
1510 /* save a registry branch to a file handle */
1511 static void save_registry( struct key
*key
, obj_handle_t handle
)
1516 if (key
->flags
& KEY_DELETED
)
1518 set_error( STATUS_KEY_DELETED
);
1521 if (!(file
= get_file_obj( current
->process
, handle
, GENERIC_WRITE
))) return;
1522 fd
= dup( get_file_unix_fd( file
) );
1523 release_object( file
);
1526 FILE *f
= fdopen( fd
, "w" );
1529 save_all_subkeys( key
, f
);
1530 if (fclose( f
)) file_set_error();
1540 /* save a registry branch to a file */
1541 static int save_branch( struct key
*key
, const char *path
)
1544 char *p
, *real
, *tmp
= NULL
;
1545 int fd
, count
= 0, ret
= 0, by_symlink
;
1548 if (!(key
->flags
& KEY_DIRTY
))
1550 if (debug_level
> 1) dump_operation( key
, NULL
, "Not saving clean" );
1554 /* get the real path */
1556 by_symlink
= (!lstat(path
, &st
) && S_ISLNK (st
.st_mode
));
1557 if (!(real
= malloc( PATH_MAX
))) return 0;
1558 if (!realpath( path
, real
))
1565 /* test the file type */
1567 if ((fd
= open( path
, O_WRONLY
)) != -1)
1569 /* if file is not a regular file or has multiple links or is accessed
1570 * via symbolic links, write directly into it; otherwise use a temp file */
1572 (!fstat( fd
, &st
) && (!S_ISREG(st
.st_mode
) || st
.st_nlink
> 1)))
1580 /* create a temp file in the same directory */
1582 if (!(tmp
= malloc( strlen(path
) + 20 ))) goto done
;
1583 strcpy( tmp
, path
);
1584 if ((p
= strrchr( tmp
, '/' ))) p
++;
1588 sprintf( p
, "reg%lx%04x.tmp", (long) getpid(), count
++ );
1589 if ((fd
= open( tmp
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666 )) != -1) break;
1590 if (errno
!= EEXIST
) goto done
;
1594 /* now save to it */
1597 if (!(f
= fdopen( fd
, "w" )))
1599 if (tmp
) unlink( tmp
);
1604 if (debug_level
> 1)
1606 fprintf( stderr
, "%s: ", path
);
1607 dump_operation( key
, NULL
, "saving" );
1610 save_all_subkeys( key
, f
);
1615 /* if successfully written, rename to final name */
1616 if (ret
) ret
= !rename( tmp
, path
);
1617 if (!ret
) unlink( tmp
);
1623 if (ret
) make_clean( key
);
1627 /* periodic saving of the registry */
1628 static void periodic_save( void *arg
)
1632 save_timeout_user
= NULL
;
1633 for (i
= 0; i
< save_branch_count
; i
++)
1634 save_branch( save_branch_info
[i
].key
, save_branch_info
[i
].path
);
1635 set_periodic_save_timer();
1638 /* start the periodic save timer */
1639 static void set_periodic_save_timer(void)
1641 struct timeval next
;
1643 gettimeofday( &next
, 0 );
1644 add_timeout( &next
, save_period
);
1645 if (save_timeout_user
) remove_timeout_user( save_timeout_user
);
1646 save_timeout_user
= add_timeout_user( &next
, periodic_save
, 0 );
1649 /* save the modified registry branches to disk */
1650 void flush_registry(void)
1654 for (i
= 0; i
< save_branch_count
; i
++)
1656 if (!save_branch( save_branch_info
[i
].key
, save_branch_info
[i
].path
))
1658 fprintf( stderr
, "wineserver: could not save registry branch to %s",
1659 save_branch_info
[i
].path
);
1665 /* close the top-level keys; used on server exit */
1666 void close_registry(void)
1670 if (save_timeout_user
) remove_timeout_user( save_timeout_user
);
1671 save_timeout_user
= NULL
;
1672 for (i
= 0; i
< save_branch_count
; i
++) release_object( save_branch_info
[i
].key
);
1673 release_object( root_key
);
1677 /* create a registry key */
1678 DECL_HANDLER(create_key
)
1680 struct key
*key
= NULL
, *parent
;
1681 unsigned int access
= req
->access
;
1682 WCHAR
*name
, *class;
1684 if (access
& MAXIMUM_ALLOWED
) access
= KEY_ALL_ACCESS
; /* FIXME: needs general solution */
1686 if (!(name
= copy_req_path( req
->namelen
, !req
->parent
))) return;
1687 if ((parent
= get_hkey_obj( req
->parent
, 0 /*FIXME*/ )))
1689 int flags
= (req
->options
& REG_OPTION_VOLATILE
) ? KEY_VOLATILE
: KEY_DIRTY
;
1691 if (req
->namelen
== get_req_data_size()) /* no class specified */
1693 key
= create_key( parent
, name
, NULL
, flags
, req
->modif
, &reply
->created
);
1697 const WCHAR
*class_ptr
= (const WCHAR
*)((const char *)get_req_data() + req
->namelen
);
1699 if ((class = req_strdupW( req
, class_ptr
, get_req_data_size() - req
->namelen
)))
1701 key
= create_key( parent
, name
, class, flags
, req
->modif
, &reply
->created
);
1707 reply
->hkey
= alloc_handle( current
->process
, key
, access
, 0 );
1708 release_object( key
);
1710 release_object( parent
);
1714 /* open a registry key */
1715 DECL_HANDLER(open_key
)
1717 struct key
*key
, *parent
;
1718 unsigned int access
= req
->access
;
1720 if (access
& MAXIMUM_ALLOWED
) access
= KEY_ALL_ACCESS
; /* FIXME: needs general solution */
1722 if ((parent
= get_hkey_obj( req
->parent
, 0 /*FIXME*/ )))
1724 WCHAR
*name
= copy_path( get_req_data(), get_req_data_size(), !req
->parent
);
1725 if (name
&& (key
= open_key( parent
, name
)))
1727 reply
->hkey
= alloc_handle( current
->process
, key
, access
, 0 );
1728 release_object( key
);
1730 release_object( parent
);
1734 /* delete a registry key */
1735 DECL_HANDLER(delete_key
)
1739 if ((key
= get_hkey_obj( req
->hkey
, 0 /*FIXME*/ )))
1741 delete_key( key
, 0);
1742 release_object( key
);
1746 /* flush a registry key */
1747 DECL_HANDLER(flush_key
)
1749 struct key
*key
= get_hkey_obj( req
->hkey
, 0 );
1752 /* we don't need to do anything here with the current implementation */
1753 release_object( key
);
1757 /* enumerate registry subkeys */
1758 DECL_HANDLER(enum_key
)
1762 if ((key
= get_hkey_obj( req
->hkey
,
1763 req
->index
== -1 ? KEY_QUERY_VALUE
: KEY_ENUMERATE_SUB_KEYS
)))
1765 enum_key( key
, req
->index
, req
->info_class
, reply
);
1766 release_object( key
);
1770 /* set a value of a registry key */
1771 DECL_HANDLER(set_key_value
)
1776 if (!(name
= copy_req_path( req
->namelen
, 0 ))) return;
1777 if ((key
= get_hkey_obj( req
->hkey
, KEY_SET_VALUE
)))
1779 size_t datalen
= get_req_data_size() - req
->namelen
;
1780 const char *data
= (const char *)get_req_data() + req
->namelen
;
1782 set_value( key
, name
, req
->type
, data
, datalen
);
1783 release_object( key
);
1787 /* retrieve the value of a registry key */
1788 DECL_HANDLER(get_key_value
)
1794 if (!(name
= copy_path( get_req_data(), get_req_data_size(), 0 ))) return;
1795 if ((key
= get_hkey_obj( req
->hkey
, KEY_QUERY_VALUE
)))
1797 get_value( key
, name
, &reply
->type
, &reply
->total
);
1798 release_object( key
);
1802 /* enumerate the value of a registry key */
1803 DECL_HANDLER(enum_key_value
)
1807 if ((key
= get_hkey_obj( req
->hkey
, KEY_QUERY_VALUE
)))
1809 enum_value( key
, req
->index
, req
->info_class
, reply
);
1810 release_object( key
);
1814 /* delete a value of a registry key */
1815 DECL_HANDLER(delete_key_value
)
1820 if ((key
= get_hkey_obj( req
->hkey
, KEY_SET_VALUE
)))
1822 if ((name
= req_strdupW( req
, get_req_data(), get_req_data_size() )))
1824 delete_value( key
, name
);
1827 release_object( key
);
1831 /* load a registry branch from a file */
1832 DECL_HANDLER(load_registry
)
1834 struct key
*key
, *parent
;
1836 if ((parent
= get_hkey_obj( req
->hkey
, KEY_SET_VALUE
| KEY_CREATE_SUB_KEY
)))
1839 WCHAR
*name
= copy_path( get_req_data(), get_req_data_size(), !req
->hkey
);
1840 if (name
&& (key
= create_key( parent
, name
, NULL
, KEY_DIRTY
, time(NULL
), &dummy
)))
1842 load_registry( key
, req
->file
);
1843 release_object( key
);
1845 release_object( parent
);
1849 DECL_HANDLER(unload_registry
)
1853 if ((key
= get_hkey_obj( req
->hkey
, 0 )))
1855 delete_key( key
, 1 ); /* FIXME */
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 /* load the user registry files */
1873 DECL_HANDLER(load_user_registries
)
1877 if ((key
= get_hkey_obj( req
->hkey
, KEY_SET_VALUE
| KEY_CREATE_SUB_KEY
)))
1879 load_user_registries( key
);
1880 release_object( key
);
1884 /* add a registry key change notification */
1885 DECL_HANDLER(set_registry_notification
)
1888 struct event
*event
;
1889 struct notify
*notify
;
1891 key
= get_hkey_obj( req
->hkey
, KEY_NOTIFY
);
1894 event
= get_event_obj( current
->process
, req
->event
, SYNCHRONIZE
);
1897 notify
= find_notify( key
, req
->hkey
);
1900 release_object( notify
->event
);
1901 grab_object( event
);
1902 notify
->event
= event
;
1906 notify
= mem_alloc( sizeof(*notify
) );
1909 grab_object( event
);
1910 notify
->event
= event
;
1911 notify
->subtree
= req
->subtree
;
1912 notify
->filter
= req
->filter
;
1913 notify
->hkey
= req
->hkey
;
1914 list_add_head( &key
->notify_list
, ¬ify
->entry
);
1917 release_object( event
);
1919 release_object( key
);