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
54 struct list entry
; /* entry in list of notifications */
55 struct event
**events
; /* events to set when changing this key */
56 unsigned int event_count
; /* number of events */
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 */
60 struct process
*process
; /* process in which the hkey is valid */
63 static const WCHAR key_name
[] = {'K','e','y'};
65 struct type_descr key_type
=
67 { key_name
, sizeof(key_name
) }, /* name */
68 KEY_ALL_ACCESS
| SYNCHRONIZE
, /* valid_access */
70 STANDARD_RIGHTS_READ
| KEY_NOTIFY
| KEY_ENUMERATE_SUB_KEYS
| KEY_QUERY_VALUE
,
71 STANDARD_RIGHTS_WRITE
| KEY_CREATE_SUB_KEY
| KEY_SET_VALUE
,
72 STANDARD_RIGHTS_EXECUTE
| KEY_CREATE_LINK
| KEY_NOTIFY
| KEY_ENUMERATE_SUB_KEYS
| KEY_QUERY_VALUE
,
80 struct object obj
; /* object header */
81 WCHAR
*name
; /* key name */
82 WCHAR
*class; /* key class */
83 unsigned short namelen
; /* length of key name */
84 unsigned short classlen
; /* length of class name */
85 struct key
*parent
; /* parent key */
86 int last_subkey
; /* last in use subkey */
87 int nb_subkeys
; /* count of allocated subkeys */
88 struct key
**subkeys
; /* subkeys array */
89 int last_value
; /* last in use value */
90 int nb_values
; /* count of allocated values in array */
91 struct key_value
*values
; /* values array */
92 unsigned int flags
; /* flags */
93 timeout_t modif
; /* last modification time */
94 struct list notify_list
; /* list of notifications */
98 #define KEY_VOLATILE 0x0001 /* key is volatile (not saved to disk) */
99 #define KEY_DELETED 0x0002 /* key has been deleted */
100 #define KEY_DIRTY 0x0004 /* key has been modified */
101 #define KEY_SYMLINK 0x0008 /* key is a symbolic link */
102 #define KEY_WOW64 0x0010 /* key contains a Wow6432Node subkey */
103 #define KEY_WOWSHARE 0x0020 /* key is a Wow64 shared key (used for Software\Classes) */
108 WCHAR
*name
; /* value name */
109 unsigned short namelen
; /* length of value name */
110 unsigned int type
; /* value type */
111 data_size_t len
; /* value data length in bytes */
112 void *data
; /* pointer to value data */
115 #define MIN_SUBKEYS 8 /* min. number of allocated subkeys per key */
116 #define MIN_VALUES 8 /* min. number of allocated values per key */
118 #define MAX_NAME_LEN 256 /* max. length of a key name */
119 #define MAX_VALUE_LEN 16383 /* max. length of a value name */
121 /* the root of the registry tree */
122 static struct key
*root_key
;
124 static const timeout_t ticks_1601_to_1970
= (timeout_t
)86400 * (369 * 365 + 89) * TICKS_PER_SEC
;
125 static const timeout_t save_period
= 30 * -TICKS_PER_SEC
; /* delay between periodic saves */
126 static struct timeout_user
*save_timeout_user
; /* saving timer */
127 static enum prefix_type
{ PREFIX_UNKNOWN
, PREFIX_32BIT
, PREFIX_64BIT
} prefix_type
;
129 static const WCHAR root_name
[] = { '\\','R','e','g','i','s','t','r','y','\\' };
130 static const WCHAR wow6432node
[] = {'W','o','w','6','4','3','2','N','o','d','e'};
131 static const WCHAR symlink_value
[] = {'S','y','m','b','o','l','i','c','L','i','n','k','V','a','l','u','e'};
132 static const struct unicode_str symlink_str
= { symlink_value
, sizeof(symlink_value
) };
134 static void set_periodic_save_timer(void);
135 static struct key_value
*find_value( const struct key
*key
, const struct unicode_str
*name
, int *index
);
137 /* information about where to save a registry branch */
138 struct save_branch_info
144 #define MAX_SAVE_BRANCH_INFO 3
145 static int save_branch_count
;
146 static struct save_branch_info save_branch_info
[MAX_SAVE_BRANCH_INFO
];
148 unsigned int supported_machines_count
= 0;
149 unsigned short supported_machines
[8];
150 unsigned short native_machine
= 0;
152 /* information about a file being loaded */
153 struct file_load_info
155 const char *filename
; /* input file name */
156 FILE *file
; /* input file */
157 char *buffer
; /* line buffer */
158 int len
; /* buffer length */
159 int line
; /* current input line */
160 WCHAR
*tmp
; /* temp buffer to use while parsing input */
161 size_t tmplen
; /* length of temp buffer */
165 static void key_dump( struct object
*obj
, int verbose
);
166 static unsigned int key_map_access( struct object
*obj
, unsigned int access
);
167 static struct security_descriptor
*key_get_sd( struct object
*obj
);
168 static WCHAR
*key_get_full_name( struct object
*obj
, data_size_t
*len
);
169 static int key_close_handle( struct object
*obj
, struct process
*process
, obj_handle_t handle
);
170 static void key_destroy( struct object
*obj
);
172 static const struct object_ops key_ops
=
174 sizeof(struct key
), /* size */
175 &key_type
, /* type */
177 no_add_queue
, /* add_queue */
178 NULL
, /* remove_queue */
180 NULL
, /* satisfied */
181 no_signal
, /* signal */
182 no_get_fd
, /* get_fd */
183 key_map_access
, /* map_access */
184 key_get_sd
, /* get_sd */
185 default_set_sd
, /* set_sd */
186 key_get_full_name
, /* get_full_name */
187 no_lookup_name
, /* lookup_name */
188 no_link_name
, /* link_name */
189 NULL
, /* unlink_name */
190 no_open_file
, /* open_file */
191 no_kernel_obj_list
, /* get_kernel_obj_list */
192 key_close_handle
, /* close_handle */
193 key_destroy
/* destroy */
197 static inline int is_wow6432node( const WCHAR
*name
, unsigned int len
)
199 return (len
== sizeof(wow6432node
) && !memicmp_strW( name
, wow6432node
, sizeof( wow6432node
)));
203 * The registry text file format v2 used by this code is similar to the one
204 * used by REGEDIT import/export functionality, with the following differences:
205 * - strings and key names can contain \x escapes for Unicode
206 * - key names use escapes too in order to support Unicode
207 * - the modification time optionally follows the key name
208 * - REG_EXPAND_SZ and REG_MULTI_SZ are saved as strings instead of hex
211 /* dump the full path of a key */
212 static void dump_path( const struct key
*key
, const struct key
*base
, FILE *f
)
214 if (key
->parent
&& key
->parent
!= base
)
216 dump_path( key
->parent
, base
, f
);
217 fprintf( f
, "\\\\" );
219 dump_strW( key
->name
, key
->namelen
, f
, "[]" );
222 /* dump a value to a text file */
223 static void dump_value( const struct key_value
*value
, FILE *f
)
231 count
= 1 + dump_strW( value
->name
, value
->namelen
, f
, "\"\"" );
232 count
+= fprintf( f
, "\"=" );
234 else count
= fprintf( f
, "@=" );
241 /* only output properly terminated strings in string format */
242 if (value
->len
< sizeof(WCHAR
)) break;
243 if (value
->len
% sizeof(WCHAR
)) break;
244 if (((WCHAR
*)value
->data
)[value
->len
/ sizeof(WCHAR
) - 1]) break;
245 if (value
->type
!= REG_SZ
) fprintf( f
, "str(%x):", value
->type
);
247 dump_strW( (WCHAR
*)value
->data
, value
->len
, f
, "\"\"" );
248 fprintf( f
, "\"\n" );
252 if (value
->len
!= sizeof(dw
)) break;
253 memcpy( &dw
, value
->data
, sizeof(dw
) );
254 fprintf( f
, "dword:%08x\n", dw
);
258 if (value
->type
== REG_BINARY
) count
+= fprintf( f
, "hex:" );
259 else count
+= fprintf( f
, "hex(%x):", value
->type
);
260 for (i
= 0; i
< value
->len
; i
++)
262 count
+= fprintf( f
, "%02x", *((unsigned char *)value
->data
+ i
) );
263 if (i
< value
->len
-1)
268 fprintf( f
, "\\\n " );
276 /* save a registry and all its subkeys to a text file */
277 static void save_subkeys( const struct key
*key
, const struct key
*base
, FILE *f
)
281 if (key
->flags
& KEY_VOLATILE
) return;
282 /* save key if it has either some values or no subkeys, or needs special options */
283 /* keys with no values but subkeys are saved implicitly by saving the subkeys */
284 if ((key
->last_value
>= 0) || (key
->last_subkey
== -1) || key
->class || (key
->flags
& KEY_SYMLINK
))
287 if (key
!= base
) dump_path( key
, base
, f
);
288 fprintf( f
, "] %u\n", (unsigned int)((key
->modif
- ticks_1601_to_1970
) / TICKS_PER_SEC
) );
289 fprintf( f
, "#time=%x%08x\n", (unsigned int)(key
->modif
>> 32), (unsigned int)key
->modif
);
292 fprintf( f
, "#class=\"" );
293 dump_strW( key
->class, key
->classlen
, f
, "\"\"" );
294 fprintf( f
, "\"\n" );
296 if (key
->flags
& KEY_SYMLINK
) fputs( "#link\n", f
);
297 for (i
= 0; i
<= key
->last_value
; i
++) dump_value( &key
->values
[i
], f
);
299 for (i
= 0; i
<= key
->last_subkey
; i
++) save_subkeys( key
->subkeys
[i
], base
, f
);
302 static void dump_operation( const struct key
*key
, const struct key_value
*value
, const char *op
)
304 fprintf( stderr
, "%s key ", op
);
305 if (key
) dump_path( key
, NULL
, stderr
);
306 else fprintf( stderr
, "ERROR" );
309 fprintf( stderr
, " value ");
310 dump_value( value
, stderr
);
312 else fprintf( stderr
, "\n" );
315 static void key_dump( struct object
*obj
, int verbose
)
317 struct key
*key
= (struct key
*)obj
;
318 assert( obj
->ops
== &key_ops
);
319 fprintf( stderr
, "Key flags=%x ", key
->flags
);
320 dump_path( key
, NULL
, stderr
);
321 fprintf( stderr
, "\n" );
324 /* notify waiter and maybe delete the notification */
325 static void do_notification( struct key
*key
, struct notify
*notify
, int del
)
329 for (i
= 0; i
< notify
->event_count
; ++i
)
331 set_event( notify
->events
[i
] );
332 release_object( notify
->events
[i
] );
334 free( notify
->events
);
335 notify
->events
= NULL
;
336 notify
->event_count
= 0;
340 list_remove( ¬ify
->entry
);
345 static inline struct notify
*find_notify( struct key
*key
, struct process
*process
, obj_handle_t hkey
)
347 struct notify
*notify
;
349 LIST_FOR_EACH_ENTRY( notify
, &key
->notify_list
, struct notify
, entry
)
351 if (notify
->process
== process
&& notify
->hkey
== hkey
) return notify
;
356 static unsigned int key_map_access( struct object
*obj
, unsigned int access
)
358 access
= default_map_access( obj
, access
);
359 /* filter the WOW64 masks, as they aren't real access bits */
360 return access
& ~(KEY_WOW64_64KEY
| KEY_WOW64_32KEY
);
363 static struct security_descriptor
*key_get_sd( struct object
*obj
)
365 static struct security_descriptor
*key_default_sd
;
367 if (obj
->sd
) return obj
->sd
;
371 size_t users_sid_len
= security_sid_len( security_builtin_users_sid
);
372 size_t admins_sid_len
= security_sid_len( security_builtin_admins_sid
);
373 size_t dacl_len
= sizeof(ACL
) + 2 * offsetof( ACCESS_ALLOWED_ACE
, SidStart
)
374 + users_sid_len
+ admins_sid_len
;
375 ACCESS_ALLOWED_ACE
*aaa
;
378 key_default_sd
= mem_alloc( sizeof(*key_default_sd
) + 2 * admins_sid_len
+ dacl_len
);
379 key_default_sd
->control
= SE_DACL_PRESENT
;
380 key_default_sd
->owner_len
= admins_sid_len
;
381 key_default_sd
->group_len
= admins_sid_len
;
382 key_default_sd
->sacl_len
= 0;
383 key_default_sd
->dacl_len
= dacl_len
;
384 memcpy( key_default_sd
+ 1, security_builtin_admins_sid
, admins_sid_len
);
385 memcpy( (char *)(key_default_sd
+ 1) + admins_sid_len
, security_builtin_admins_sid
, admins_sid_len
);
387 dacl
= (ACL
*)((char *)(key_default_sd
+ 1) + 2 * admins_sid_len
);
388 dacl
->AclRevision
= ACL_REVISION
;
390 dacl
->AclSize
= dacl_len
;
393 aaa
= (ACCESS_ALLOWED_ACE
*)(dacl
+ 1);
394 aaa
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
395 aaa
->Header
.AceFlags
= INHERIT_ONLY_ACE
| CONTAINER_INHERIT_ACE
;
396 aaa
->Header
.AceSize
= offsetof( ACCESS_ALLOWED_ACE
, SidStart
) + users_sid_len
;
397 aaa
->Mask
= GENERIC_READ
;
398 memcpy( &aaa
->SidStart
, security_builtin_users_sid
, users_sid_len
);
399 aaa
= (ACCESS_ALLOWED_ACE
*)((char *)aaa
+ aaa
->Header
.AceSize
);
400 aaa
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
401 aaa
->Header
.AceFlags
= 0;
402 aaa
->Header
.AceSize
= offsetof( ACCESS_ALLOWED_ACE
, SidStart
) + admins_sid_len
;
403 aaa
->Mask
= KEY_ALL_ACCESS
;
404 memcpy( &aaa
->SidStart
, security_builtin_admins_sid
, admins_sid_len
);
406 return key_default_sd
;
409 static WCHAR
*key_get_full_name( struct object
*obj
, data_size_t
*ret_len
)
411 static const WCHAR backslash
= '\\';
412 struct key
*key
= (struct key
*) obj
;
413 data_size_t len
= sizeof(root_name
) - sizeof(WCHAR
);
416 if (key
->flags
& KEY_DELETED
)
418 set_error( STATUS_KEY_DELETED
);
422 for (key
= (struct key
*)obj
; key
!= root_key
; key
= key
->parent
) len
+= key
->namelen
+ sizeof(WCHAR
);
423 if (!(ret
= malloc( len
))) return NULL
;
426 key
= (struct key
*)obj
;
427 for (key
= (struct key
*)obj
; key
!= root_key
; key
= key
->parent
)
429 memcpy( ret
+ len
- key
->namelen
, key
->name
, key
->namelen
);
430 len
-= key
->namelen
+ sizeof(WCHAR
);
431 memcpy( ret
+ len
, &backslash
, sizeof(WCHAR
) );
433 memcpy( ret
, root_name
, sizeof(root_name
) - sizeof(WCHAR
) );
437 /* close the notification associated with a handle */
438 static int key_close_handle( struct object
*obj
, struct process
*process
, obj_handle_t handle
)
440 struct key
* key
= (struct key
*) obj
;
441 struct notify
*notify
= find_notify( key
, process
, handle
);
442 if (notify
) do_notification( key
, notify
, 1 );
443 return 1; /* ok to close */
446 static void key_destroy( struct object
*obj
)
450 struct key
*key
= (struct key
*)obj
;
451 assert( obj
->ops
== &key_ops
);
455 for (i
= 0; i
<= key
->last_value
; i
++)
457 free( key
->values
[i
].name
);
458 free( key
->values
[i
].data
);
461 for (i
= 0; i
<= key
->last_subkey
; i
++)
463 key
->subkeys
[i
]->parent
= NULL
;
464 release_object( key
->subkeys
[i
] );
466 free( key
->subkeys
);
467 /* unconditionally notify everything waiting on this key */
468 while ((ptr
= list_head( &key
->notify_list
)))
470 struct notify
*notify
= LIST_ENTRY( ptr
, struct notify
, entry
);
471 do_notification( key
, notify
, 1 );
475 /* get the request vararg as registry path */
476 static inline void get_req_path( struct unicode_str
*str
, int skip_root
)
478 str
->str
= get_req_data();
479 str
->len
= (get_req_data_size() / sizeof(WCHAR
)) * sizeof(WCHAR
);
481 if (skip_root
&& str
->len
>= sizeof(root_name
) && !memicmp_strW( str
->str
, root_name
, sizeof(root_name
) ))
483 str
->str
+= ARRAY_SIZE( root_name
);
484 str
->len
-= sizeof(root_name
);
488 /* return the next token in a given path */
489 /* token->str must point inside the path, or be NULL for the first call */
490 static struct unicode_str
*get_path_token( const struct unicode_str
*path
, struct unicode_str
*token
)
492 data_size_t i
= 0, len
= path
->len
/ sizeof(WCHAR
);
494 if (!token
->str
) /* first time */
496 /* path cannot start with a backslash */
497 if (len
&& path
->str
[0] == '\\')
499 set_error( STATUS_OBJECT_PATH_INVALID
);
505 i
= token
->str
- path
->str
;
506 i
+= token
->len
/ sizeof(WCHAR
);
507 while (i
< len
&& path
->str
[i
] == '\\') i
++;
509 token
->str
= path
->str
+ i
;
510 while (i
< len
&& path
->str
[i
] != '\\') i
++;
511 token
->len
= (path
->str
+ i
- token
->str
) * sizeof(WCHAR
);
515 /* allocate a key object */
516 static struct key
*alloc_key( const struct unicode_str
*name
, timeout_t modif
)
519 if ((key
= alloc_object( &key_ops
)))
523 key
->namelen
= name
->len
;
526 key
->last_subkey
= -1;
530 key
->last_value
= -1;
534 list_init( &key
->notify_list
);
535 if (name
->len
&& !(key
->name
= memdup( name
->str
, name
->len
)))
537 release_object( key
);
544 /* mark a key and all its parents as dirty (modified) */
545 static void make_dirty( struct key
*key
)
549 if (key
->flags
& (KEY_DIRTY
|KEY_VOLATILE
)) return; /* nothing to do */
550 key
->flags
|= KEY_DIRTY
;
555 /* mark a key and all its subkeys as clean (not modified) */
556 static void make_clean( struct key
*key
)
560 if (key
->flags
& KEY_VOLATILE
) return;
561 if (!(key
->flags
& KEY_DIRTY
)) return;
562 key
->flags
&= ~KEY_DIRTY
;
563 for (i
= 0; i
<= key
->last_subkey
; i
++) make_clean( key
->subkeys
[i
] );
566 /* go through all the notifications and send them if necessary */
567 static void check_notify( struct key
*key
, unsigned int change
, int not_subtree
)
569 struct list
*ptr
, *next
;
571 LIST_FOR_EACH_SAFE( ptr
, next
, &key
->notify_list
)
573 struct notify
*n
= LIST_ENTRY( ptr
, struct notify
, entry
);
574 if ( ( not_subtree
|| n
->subtree
) && ( change
& n
->filter
) )
575 do_notification( key
, n
, 0 );
579 /* update key modification time */
580 static void touch_key( struct key
*key
, unsigned int change
)
584 key
->modif
= current_time
;
587 /* do notifications */
588 check_notify( key
, change
, 1 );
589 for ( k
= key
->parent
; k
; k
= k
->parent
)
590 check_notify( k
, change
, 0 );
593 /* try to grow the array of subkeys; return 1 if OK, 0 on error */
594 static int grow_subkeys( struct key
*key
)
596 struct key
**new_subkeys
;
601 nb_subkeys
= key
->nb_subkeys
+ (key
->nb_subkeys
/ 2); /* grow by 50% */
602 if (!(new_subkeys
= realloc( key
->subkeys
, nb_subkeys
* sizeof(*new_subkeys
) )))
604 set_error( STATUS_NO_MEMORY
);
610 nb_subkeys
= MIN_SUBKEYS
;
611 if (!(new_subkeys
= mem_alloc( nb_subkeys
* sizeof(*new_subkeys
) ))) return 0;
613 key
->subkeys
= new_subkeys
;
614 key
->nb_subkeys
= nb_subkeys
;
618 /* allocate a subkey for a given key, and return its index */
619 static struct key
*alloc_subkey( struct key
*parent
, const struct unicode_str
*name
,
620 int index
, timeout_t modif
)
625 if (name
->len
> MAX_NAME_LEN
* sizeof(WCHAR
))
627 set_error( STATUS_INVALID_PARAMETER
);
630 if (parent
->last_subkey
+ 1 == parent
->nb_subkeys
)
632 /* need to grow the array */
633 if (!grow_subkeys( parent
)) return NULL
;
635 if ((key
= alloc_key( name
, modif
)) != NULL
)
637 key
->parent
= parent
;
638 for (i
= ++parent
->last_subkey
; i
> index
; i
--)
639 parent
->subkeys
[i
] = parent
->subkeys
[i
-1];
640 parent
->subkeys
[index
] = key
;
641 if (is_wow6432node( key
->name
, key
->namelen
) && !is_wow6432node( parent
->name
, parent
->namelen
))
642 parent
->flags
|= KEY_WOW64
;
647 /* free a subkey of a given key */
648 static void free_subkey( struct key
*parent
, int index
)
653 assert( index
>= 0 );
654 assert( index
<= parent
->last_subkey
);
656 key
= parent
->subkeys
[index
];
657 for (i
= index
; i
< parent
->last_subkey
; i
++) parent
->subkeys
[i
] = parent
->subkeys
[i
+ 1];
658 parent
->last_subkey
--;
659 key
->flags
|= KEY_DELETED
;
661 if (is_wow6432node( key
->name
, key
->namelen
)) parent
->flags
&= ~KEY_WOW64
;
662 release_object( key
);
664 /* try to shrink the array */
665 nb_subkeys
= parent
->nb_subkeys
;
666 if (nb_subkeys
> MIN_SUBKEYS
&& parent
->last_subkey
< nb_subkeys
/ 2)
668 struct key
**new_subkeys
;
669 nb_subkeys
-= nb_subkeys
/ 3; /* shrink by 33% */
670 if (nb_subkeys
< MIN_SUBKEYS
) nb_subkeys
= MIN_SUBKEYS
;
671 if (!(new_subkeys
= realloc( parent
->subkeys
, nb_subkeys
* sizeof(*new_subkeys
) ))) return;
672 parent
->subkeys
= new_subkeys
;
673 parent
->nb_subkeys
= nb_subkeys
;
677 /* find the named child of a given key and return its index */
678 static struct key
*find_subkey( const struct key
*key
, const struct unicode_str
*name
, int *index
)
680 int i
, min
, max
, res
;
684 max
= key
->last_subkey
;
688 len
= min( key
->subkeys
[i
]->namelen
, name
->len
);
689 res
= memicmp_strW( key
->subkeys
[i
]->name
, name
->str
, len
);
690 if (!res
) res
= key
->subkeys
[i
]->namelen
- name
->len
;
694 return key
->subkeys
[i
];
696 if (res
> 0) max
= i
- 1;
699 *index
= min
; /* this is where we should insert it */
703 /* return the wow64 variant of the key, or the key itself if none */
704 static struct key
*find_wow64_subkey( struct key
*key
, const struct unicode_str
*name
)
706 static const struct unicode_str wow6432node_str
= { wow6432node
, sizeof(wow6432node
) };
709 if (!(key
->flags
& KEY_WOW64
)) return key
;
710 if (!is_wow6432node( name
->str
, name
->len
))
712 key
= find_subkey( key
, &wow6432node_str
, &index
);
713 assert( key
); /* if KEY_WOW64 is set we must find it */
719 /* follow a symlink and return the resolved key */
720 static struct key
*follow_symlink( struct key
*key
, int iteration
)
722 struct unicode_str path
, token
;
723 struct key_value
*value
;
726 if (iteration
> 16) return NULL
;
727 if (!(key
->flags
& KEY_SYMLINK
)) return key
;
728 if (!(value
= find_value( key
, &symlink_str
, &index
))) return NULL
;
730 path
.str
= value
->data
;
731 path
.len
= (value
->len
/ sizeof(WCHAR
)) * sizeof(WCHAR
);
732 if (path
.len
<= sizeof(root_name
)) return NULL
;
733 if (memicmp_strW( path
.str
, root_name
, sizeof(root_name
) )) return NULL
;
734 path
.str
+= ARRAY_SIZE( root_name
);
735 path
.len
-= sizeof(root_name
);
739 if (!get_path_token( &path
, &token
)) return NULL
;
742 if (!(key
= find_subkey( key
, &token
, &index
))) break;
743 if (!(key
= follow_symlink( key
, iteration
+ 1 ))) break;
744 get_path_token( &path
, &token
);
749 /* open a key until we find an element that doesn't exist */
750 /* helper for open_key and create_key */
751 static struct key
*open_key_prefix( struct key
*key
, const struct unicode_str
*name
,
752 unsigned int access
, struct unicode_str
*token
, int *index
)
755 if (!get_path_token( name
, token
)) return NULL
;
756 if (access
& KEY_WOW64_32KEY
) key
= find_wow64_subkey( key
, token
);
760 if (!(subkey
= find_subkey( key
, token
, index
)))
762 if ((key
->flags
& KEY_WOWSHARE
) && !(access
& KEY_WOW64_64KEY
))
764 /* try in the 64-bit parent */
766 subkey
= find_subkey( key
, token
, index
);
771 get_path_token( name
, token
);
772 if (!token
->len
) break;
773 if (!(access
& KEY_WOW64_64KEY
)) key
= find_wow64_subkey( key
, token
);
774 if (!(key
= follow_symlink( key
, 0 )))
776 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
784 static struct key
*open_key( struct key
*key
, const struct unicode_str
*name
, unsigned int access
,
785 unsigned int attributes
)
788 struct unicode_str token
;
790 if (!(key
= open_key_prefix( key
, name
, access
, &token
, &index
))) return NULL
;
794 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
797 if (!(access
& KEY_WOW64_64KEY
)) key
= find_wow64_subkey( key
, &token
);
798 if (!(attributes
& OBJ_OPENLINK
) && !(key
= follow_symlink( key
, 0 )))
800 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
803 if (debug_level
> 1) dump_operation( key
, NULL
, "Open" );
808 /* create a subkey */
809 static struct key
*create_key( struct key
*key
, const struct unicode_str
*name
,
810 const struct unicode_str
*class, unsigned int options
,
811 unsigned int access
, unsigned int attributes
,
812 const struct security_descriptor
*sd
, int *created
)
815 struct unicode_str token
, next
;
818 if (!(key
= open_key_prefix( key
, name
, access
, &token
, &index
))) return NULL
;
820 if (!token
.len
) /* the key already exists */
822 if (!(access
& KEY_WOW64_64KEY
)) key
= find_wow64_subkey( key
, &token
);
823 if (options
& REG_OPTION_CREATE_LINK
)
825 set_error( STATUS_OBJECT_NAME_COLLISION
);
828 if (!(attributes
& OBJ_OPENLINK
) && !(key
= follow_symlink( key
, 0 )))
830 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
833 if (debug_level
> 1) dump_operation( key
, NULL
, "Open" );
838 /* token must be the last path component at this point */
840 get_path_token( name
, &next
);
843 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
847 if ((key
->flags
& KEY_VOLATILE
) && !(options
& REG_OPTION_VOLATILE
))
849 set_error( STATUS_CHILD_MUST_BE_VOLATILE
);
854 if (!(key
= alloc_subkey( key
, &token
, index
, current_time
))) return NULL
;
856 if (options
& REG_OPTION_CREATE_LINK
) key
->flags
|= KEY_SYMLINK
;
857 if (options
& REG_OPTION_VOLATILE
) key
->flags
|= KEY_VOLATILE
;
858 else key
->flags
|= KEY_DIRTY
;
860 if (sd
) default_set_sd( &key
->obj
, sd
, OWNER_SECURITY_INFORMATION
| GROUP_SECURITY_INFORMATION
|
861 DACL_SECURITY_INFORMATION
| SACL_SECURITY_INFORMATION
);
863 if (debug_level
> 1) dump_operation( key
, NULL
, "Create" );
864 if (class && class->len
)
866 key
->classlen
= class->len
;
868 if (!(key
->class = memdup( class->str
, key
->classlen
))) key
->classlen
= 0;
870 touch_key( key
->parent
, REG_NOTIFY_CHANGE_NAME
);
875 /* recursively create a subkey (for internal use only) */
876 static struct key
*create_key_recursive( struct key
*key
, const struct unicode_str
*name
, timeout_t modif
)
880 struct unicode_str token
;
883 if (!get_path_token( name
, &token
)) return NULL
;
887 if (!(subkey
= find_subkey( key
, &token
, &index
))) break;
889 if (!(key
= follow_symlink( key
, 0 )))
891 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
894 get_path_token( name
, &token
);
899 if (!(key
= alloc_subkey( key
, &token
, index
, modif
))) return NULL
;
903 get_path_token( name
, &token
);
904 if (!token
.len
) break;
905 /* we know the index is always 0 in a new key */
906 if (!(key
= alloc_subkey( key
, &token
, 0, modif
)))
908 free_subkey( base
, index
);
918 /* query information about a key or a subkey */
919 static void enum_key( struct key
*key
, int index
, int info_class
, struct enum_key_reply
*reply
)
922 data_size_t len
, namelen
, classlen
;
923 data_size_t max_subkey
= 0, max_class
= 0;
924 data_size_t max_value
= 0, max_data
= 0;
925 WCHAR
*fullname
= NULL
;
928 if (index
!= -1) /* -1 means use the specified key directly */
930 if ((index
< 0) || (index
> key
->last_subkey
))
932 set_error( STATUS_NO_MORE_ENTRIES
);
935 key
= key
->subkeys
[index
];
938 namelen
= key
->namelen
;
939 classlen
= key
->classlen
;
943 case KeyNameInformation
:
944 if (!(fullname
= key
->obj
.ops
->get_full_name( &key
->obj
, &namelen
))) return;
946 case KeyBasicInformation
:
947 classlen
= 0; /* only return the name */
949 case KeyNodeInformation
:
950 reply
->max_subkey
= 0;
951 reply
->max_class
= 0;
952 reply
->max_value
= 0;
955 case KeyFullInformation
:
956 case KeyCachedInformation
:
957 for (i
= 0; i
<= key
->last_subkey
; i
++)
959 if (key
->subkeys
[i
]->namelen
> max_subkey
) max_subkey
= key
->subkeys
[i
]->namelen
;
960 if (key
->subkeys
[i
]->classlen
> max_class
) max_class
= key
->subkeys
[i
]->classlen
;
962 for (i
= 0; i
<= key
->last_value
; i
++)
964 if (key
->values
[i
].namelen
> max_value
) max_value
= key
->values
[i
].namelen
;
965 if (key
->values
[i
].len
> max_data
) max_data
= key
->values
[i
].len
;
967 reply
->max_subkey
= max_subkey
;
968 reply
->max_class
= max_class
;
969 reply
->max_value
= max_value
;
970 reply
->max_data
= max_data
;
971 reply
->namelen
= namelen
;
972 if (info_class
== KeyCachedInformation
)
973 classlen
= 0; /* don't return any data, only its size */
974 namelen
= 0; /* don't return name */
977 set_error( STATUS_INVALID_PARAMETER
);
980 reply
->subkeys
= key
->last_subkey
+ 1;
981 reply
->values
= key
->last_value
+ 1;
982 reply
->modif
= key
->modif
;
983 reply
->total
= namelen
+ classlen
;
985 len
= min( reply
->total
, get_reply_max_size() );
986 if (len
&& (data
= set_reply_data_size( len
)))
990 reply
->namelen
= namelen
;
991 memcpy( data
, key
->name
, namelen
);
992 memcpy( data
+ namelen
, key
->class, len
- namelen
);
994 else if (info_class
== KeyNameInformation
)
996 reply
->namelen
= namelen
;
997 memcpy( data
, fullname
, len
);
1001 reply
->namelen
= len
;
1002 memcpy( data
, key
->name
, len
);
1006 if (debug_level
> 1) dump_operation( key
, NULL
, "Enum" );
1009 /* delete a key and its values */
1010 static int delete_key( struct key
*key
, int recurse
)
1013 struct key
*parent
= key
->parent
;
1015 /* must find parent and index */
1016 if (key
== root_key
)
1018 set_error( STATUS_ACCESS_DENIED
);
1023 while (recurse
&& (key
->last_subkey
>=0))
1024 if (0 > delete_key(key
->subkeys
[key
->last_subkey
], 1))
1027 for (index
= 0; index
<= parent
->last_subkey
; index
++)
1028 if (parent
->subkeys
[index
] == key
) break;
1029 assert( index
<= parent
->last_subkey
);
1031 /* we can only delete a key that has no subkeys */
1032 if (key
->last_subkey
>= 0)
1034 set_error( STATUS_ACCESS_DENIED
);
1038 if (debug_level
> 1) dump_operation( key
, NULL
, "Delete" );
1039 free_subkey( parent
, index
);
1040 touch_key( parent
, REG_NOTIFY_CHANGE_NAME
);
1044 /* try to grow the array of values; return 1 if OK, 0 on error */
1045 static int grow_values( struct key
*key
)
1047 struct key_value
*new_val
;
1052 nb_values
= key
->nb_values
+ (key
->nb_values
/ 2); /* grow by 50% */
1053 if (!(new_val
= realloc( key
->values
, nb_values
* sizeof(*new_val
) )))
1055 set_error( STATUS_NO_MEMORY
);
1061 nb_values
= MIN_VALUES
;
1062 if (!(new_val
= mem_alloc( nb_values
* sizeof(*new_val
) ))) return 0;
1064 key
->values
= new_val
;
1065 key
->nb_values
= nb_values
;
1069 /* find the named value of a given key and return its index in the array */
1070 static struct key_value
*find_value( const struct key
*key
, const struct unicode_str
*name
, int *index
)
1072 int i
, min
, max
, res
;
1076 max
= key
->last_value
;
1079 i
= (min
+ max
) / 2;
1080 len
= min( key
->values
[i
].namelen
, name
->len
);
1081 res
= memicmp_strW( key
->values
[i
].name
, name
->str
, len
);
1082 if (!res
) res
= key
->values
[i
].namelen
- name
->len
;
1086 return &key
->values
[i
];
1088 if (res
> 0) max
= i
- 1;
1091 *index
= min
; /* this is where we should insert it */
1095 /* insert a new value; the index must have been returned by find_value */
1096 static struct key_value
*insert_value( struct key
*key
, const struct unicode_str
*name
, int index
)
1098 struct key_value
*value
;
1099 WCHAR
*new_name
= NULL
;
1102 if (name
->len
> MAX_VALUE_LEN
* sizeof(WCHAR
))
1104 set_error( STATUS_NAME_TOO_LONG
);
1107 if (key
->last_value
+ 1 == key
->nb_values
)
1109 if (!grow_values( key
)) return NULL
;
1111 if (name
->len
&& !(new_name
= memdup( name
->str
, name
->len
))) return NULL
;
1112 for (i
= ++key
->last_value
; i
> index
; i
--) key
->values
[i
] = key
->values
[i
- 1];
1113 value
= &key
->values
[index
];
1114 value
->name
= new_name
;
1115 value
->namelen
= name
->len
;
1121 /* set a key value */
1122 static void set_value( struct key
*key
, const struct unicode_str
*name
,
1123 int type
, const void *data
, data_size_t len
)
1125 struct key_value
*value
;
1129 if ((value
= find_value( key
, name
, &index
)))
1131 /* check if the new value is identical to the existing one */
1132 if (value
->type
== type
&& value
->len
== len
&&
1133 value
->data
&& !memcmp( value
->data
, data
, len
))
1135 if (debug_level
> 1) dump_operation( key
, value
, "Skip setting" );
1140 if (key
->flags
& KEY_SYMLINK
)
1142 if (type
!= REG_LINK
|| name
->len
!= symlink_str
.len
||
1143 memicmp_strW( name
->str
, symlink_str
.str
, name
->len
))
1145 set_error( STATUS_ACCESS_DENIED
);
1150 if (len
&& !(ptr
= memdup( data
, len
))) return;
1154 if (!(value
= insert_value( key
, name
, index
)))
1160 else free( value
->data
); /* already existing, free previous data */
1165 touch_key( key
, REG_NOTIFY_CHANGE_LAST_SET
);
1166 if (debug_level
> 1) dump_operation( key
, value
, "Set" );
1169 /* get a key value */
1170 static void get_value( struct key
*key
, const struct unicode_str
*name
, int *type
, data_size_t
*len
)
1172 struct key_value
*value
;
1175 if ((value
= find_value( key
, name
, &index
)))
1177 *type
= value
->type
;
1179 if (value
->data
) set_reply_data( value
->data
, min( value
->len
, get_reply_max_size() ));
1180 if (debug_level
> 1) dump_operation( key
, value
, "Get" );
1185 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
1189 /* enumerate a key value */
1190 static void enum_value( struct key
*key
, int i
, int info_class
, struct enum_key_value_reply
*reply
)
1192 struct key_value
*value
;
1194 if (i
< 0 || i
> key
->last_value
) set_error( STATUS_NO_MORE_ENTRIES
);
1198 data_size_t namelen
, maxlen
;
1200 value
= &key
->values
[i
];
1201 reply
->type
= value
->type
;
1202 namelen
= value
->namelen
;
1206 case KeyValueBasicInformation
:
1207 reply
->total
= namelen
;
1209 case KeyValueFullInformation
:
1210 reply
->total
= namelen
+ value
->len
;
1212 case KeyValuePartialInformation
:
1213 reply
->total
= value
->len
;
1217 set_error( STATUS_INVALID_PARAMETER
);
1221 maxlen
= min( reply
->total
, get_reply_max_size() );
1222 if (maxlen
&& ((data
= set_reply_data_size( maxlen
))))
1224 if (maxlen
> namelen
)
1226 reply
->namelen
= namelen
;
1227 memcpy( data
, value
->name
, namelen
);
1228 memcpy( (char *)data
+ namelen
, value
->data
, maxlen
- namelen
);
1232 reply
->namelen
= maxlen
;
1233 memcpy( data
, value
->name
, maxlen
);
1236 if (debug_level
> 1) dump_operation( key
, value
, "Enum" );
1240 /* delete a value */
1241 static void delete_value( struct key
*key
, const struct unicode_str
*name
)
1243 struct key_value
*value
;
1244 int i
, index
, nb_values
;
1246 if (!(value
= find_value( key
, name
, &index
)))
1248 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
1251 if (debug_level
> 1) dump_operation( key
, value
, "Delete" );
1252 free( value
->name
);
1253 free( value
->data
);
1254 for (i
= index
; i
< key
->last_value
; i
++) key
->values
[i
] = key
->values
[i
+ 1];
1256 touch_key( key
, REG_NOTIFY_CHANGE_LAST_SET
);
1258 /* try to shrink the array */
1259 nb_values
= key
->nb_values
;
1260 if (nb_values
> MIN_VALUES
&& key
->last_value
< nb_values
/ 2)
1262 struct key_value
*new_val
;
1263 nb_values
-= nb_values
/ 3; /* shrink by 33% */
1264 if (nb_values
< MIN_VALUES
) nb_values
= MIN_VALUES
;
1265 if (!(new_val
= realloc( key
->values
, nb_values
* sizeof(*new_val
) ))) return;
1266 key
->values
= new_val
;
1267 key
->nb_values
= nb_values
;
1271 /* get the registry key corresponding to an hkey handle */
1272 static struct key
*get_hkey_obj( obj_handle_t hkey
, unsigned int access
)
1274 struct key
*key
= (struct key
*)get_handle_obj( current
->process
, hkey
, access
, &key_ops
);
1276 if (key
&& key
->flags
& KEY_DELETED
)
1278 set_error( STATUS_KEY_DELETED
);
1279 release_object( key
);
1285 /* get the registry key corresponding to a parent key handle */
1286 static inline struct key
*get_parent_hkey_obj( obj_handle_t hkey
)
1288 if (!hkey
) return (struct key
*)grab_object( root_key
);
1289 return get_hkey_obj( hkey
, 0 );
1292 /* read a line from the input file */
1293 static int read_next_line( struct file_load_info
*info
)
1296 int newlen
, pos
= 0;
1301 if (!fgets( info
->buffer
+ pos
, info
->len
- pos
, info
->file
))
1302 return (pos
!= 0); /* EOF */
1303 pos
= strlen(info
->buffer
);
1304 if (info
->buffer
[pos
-1] == '\n')
1306 /* got a full line */
1307 info
->buffer
[--pos
] = 0;
1308 if (pos
> 0 && info
->buffer
[pos
-1] == '\r') info
->buffer
[pos
-1] = 0;
1311 if (pos
< info
->len
- 1) return 1; /* EOF but something was read */
1313 /* need to enlarge the buffer */
1314 newlen
= info
->len
+ info
->len
/ 2;
1315 if (!(newbuf
= realloc( info
->buffer
, newlen
)))
1317 set_error( STATUS_NO_MEMORY
);
1320 info
->buffer
= newbuf
;
1325 /* make sure the temp buffer holds enough space */
1326 static int get_file_tmp_space( struct file_load_info
*info
, size_t size
)
1329 if (info
->tmplen
>= size
) return 1;
1330 if (!(tmp
= realloc( info
->tmp
, size
)))
1332 set_error( STATUS_NO_MEMORY
);
1336 info
->tmplen
= size
;
1340 /* report an error while loading an input file */
1341 static void file_read_error( const char *err
, struct file_load_info
*info
)
1344 fprintf( stderr
, "%s:%d: %s '%s'\n", info
->filename
, info
->line
, err
, info
->buffer
);
1346 fprintf( stderr
, "<fd>:%d: %s '%s'\n", info
->line
, err
, info
->buffer
);
1349 /* convert a data type tag to a value type */
1350 static int get_data_type( const char *buffer
, int *type
, int *parse_type
)
1352 struct data_type
{ const char *tag
; int len
; int type
; int parse_type
; };
1354 static const struct data_type data_types
[] =
1355 { /* actual type */ /* type to assume for parsing */
1356 { "\"", 1, REG_SZ
, REG_SZ
},
1357 { "str:\"", 5, REG_SZ
, REG_SZ
},
1358 { "str(2):\"", 8, REG_EXPAND_SZ
, REG_SZ
},
1359 { "str(7):\"", 8, REG_MULTI_SZ
, REG_SZ
},
1360 { "hex:", 4, REG_BINARY
, REG_BINARY
},
1361 { "dword:", 6, REG_DWORD
, REG_DWORD
},
1362 { "hex(", 4, -1, REG_BINARY
},
1366 const struct data_type
*ptr
;
1369 for (ptr
= data_types
; ptr
->tag
; ptr
++)
1371 if (strncmp( ptr
->tag
, buffer
, ptr
->len
)) continue;
1372 *parse_type
= ptr
->parse_type
;
1373 if ((*type
= ptr
->type
) != -1) return ptr
->len
;
1374 /* "hex(xx):" is special */
1375 *type
= (int)strtoul( buffer
+ 4, &end
, 16 );
1376 if ((end
<= buffer
) || strncmp( end
, "):", 2 )) return 0;
1377 return end
+ 2 - buffer
;
1382 /* load and create a key from the input file */
1383 static struct key
*load_key( struct key
*base
, const char *buffer
, int prefix_len
,
1384 struct file_load_info
*info
, timeout_t
*modif
)
1387 struct unicode_str name
;
1392 if (!get_file_tmp_space( info
, strlen(buffer
) * sizeof(WCHAR
) )) return NULL
;
1395 if ((res
= parse_strW( info
->tmp
, &len
, buffer
, ']' )) == -1)
1397 file_read_error( "Malformed key", info
);
1400 if (sscanf( buffer
+ res
, " %u", &mod
) == 1)
1401 *modif
= (timeout_t
)mod
* TICKS_PER_SEC
+ ticks_1601_to_1970
;
1403 *modif
= current_time
;
1406 while (prefix_len
&& *p
) { if (*p
++ == '\\') prefix_len
--; }
1412 file_read_error( "Malformed key", info
);
1415 /* empty key name, return base key */
1416 return (struct key
*)grab_object( base
);
1419 name
.len
= len
- (p
- info
->tmp
+ 1) * sizeof(WCHAR
);
1420 return create_key_recursive( base
, &name
, 0 );
1423 /* update the modification time of a key (and its parents) after it has been loaded from a file */
1424 static void update_key_time( struct key
*key
, timeout_t modif
)
1426 while (key
&& !key
->modif
)
1433 /* load a global option from the input file */
1434 static int load_global_option( const char *buffer
, struct file_load_info
*info
)
1438 if (!strncmp( buffer
, "#arch=", 6 ))
1440 enum prefix_type type
;
1442 if (!strcmp( p
, "win32" )) type
= PREFIX_32BIT
;
1443 else if (!strcmp( p
, "win64" )) type
= PREFIX_64BIT
;
1446 file_read_error( "Unknown architecture", info
);
1447 set_error( STATUS_NOT_REGISTRY_FILE
);
1450 if (prefix_type
== PREFIX_UNKNOWN
) prefix_type
= type
;
1451 else if (type
!= prefix_type
)
1453 file_read_error( "Mismatched architecture", info
);
1454 set_error( STATUS_NOT_REGISTRY_FILE
);
1458 /* ignore unknown options */
1462 /* load a key option from the input file */
1463 static int load_key_option( struct key
*key
, const char *buffer
, struct file_load_info
*info
)
1468 if (!strncmp( buffer
, "#time=", 6 ))
1470 timeout_t modif
= 0;
1471 for (p
= buffer
+ 6; *p
; p
++)
1473 if (*p
>= '0' && *p
<= '9') modif
= (modif
<< 4) | (*p
- '0');
1474 else if (*p
>= 'A' && *p
<= 'F') modif
= (modif
<< 4) | (*p
- 'A' + 10);
1475 else if (*p
>= 'a' && *p
<= 'f') modif
= (modif
<< 4) | (*p
- 'a' + 10);
1478 update_key_time( key
, modif
);
1480 if (!strncmp( buffer
, "#class=", 7 ))
1483 if (*p
++ != '"') return 0;
1484 if (!get_file_tmp_space( info
, strlen(p
) * sizeof(WCHAR
) )) return 0;
1486 if (parse_strW( info
->tmp
, &len
, p
, '\"' ) == -1) return 0;
1488 if (!(key
->class = memdup( info
->tmp
, len
))) len
= 0;
1489 key
->classlen
= len
;
1491 if (!strncmp( buffer
, "#link", 5 )) key
->flags
|= KEY_SYMLINK
;
1492 /* ignore unknown options */
1496 /* parse a comma-separated list of hex digits */
1497 static int parse_hex( unsigned char *dest
, data_size_t
*len
, const char *buffer
)
1499 const char *p
= buffer
;
1500 data_size_t count
= 0;
1503 while (isxdigit(*p
))
1505 unsigned int val
= strtoul( p
, &end
, 16 );
1506 if (end
== p
|| val
> 0xff) return -1;
1507 if (count
++ >= *len
) return -1; /* dest buffer overflow */
1510 while (isspace(*p
)) p
++;
1512 while (isspace(*p
)) p
++;
1518 /* parse a value name and create the corresponding value */
1519 static struct key_value
*parse_value_name( struct key
*key
, const char *buffer
, data_size_t
*len
,
1520 struct file_load_info
*info
)
1522 struct key_value
*value
;
1523 struct unicode_str name
;
1526 if (!get_file_tmp_space( info
, strlen(buffer
) * sizeof(WCHAR
) )) return NULL
;
1527 name
.str
= info
->tmp
;
1528 name
.len
= info
->tmplen
;
1529 if (buffer
[0] == '@')
1536 int r
= parse_strW( info
->tmp
, &name
.len
, buffer
+ 1, '\"' );
1537 if (r
== -1) goto error
;
1538 *len
= r
+ 1; /* for initial quote */
1539 name
.len
-= sizeof(WCHAR
); /* terminating null */
1541 while (isspace(buffer
[*len
])) (*len
)++;
1542 if (buffer
[*len
] != '=') goto error
;
1544 while (isspace(buffer
[*len
])) (*len
)++;
1545 if (!(value
= find_value( key
, &name
, &index
))) value
= insert_value( key
, &name
, index
);
1549 file_read_error( "Malformed value name", info
);
1553 /* load a value from the input file */
1554 static int load_value( struct key
*key
, const char *buffer
, struct file_load_info
*info
)
1558 int res
, type
, parse_type
;
1559 data_size_t maxlen
, len
;
1560 struct key_value
*value
;
1562 if (!(value
= parse_value_name( key
, buffer
, &len
, info
))) return 0;
1563 if (!(res
= get_data_type( buffer
+ len
, &type
, &parse_type
))) goto error
;
1564 buffer
+= len
+ res
;
1569 if (!get_file_tmp_space( info
, strlen(buffer
) * sizeof(WCHAR
) )) return 0;
1571 if ((res
= parse_strW( info
->tmp
, &len
, buffer
, '\"' )) == -1) goto error
;
1575 dw
= strtoul( buffer
, NULL
, 16 );
1579 case REG_BINARY
: /* hex digits */
1583 maxlen
= 1 + strlen(buffer
) / 2; /* at least 2 chars for one hex byte */
1584 if (!get_file_tmp_space( info
, len
+ maxlen
)) return 0;
1585 if ((res
= parse_hex( (unsigned char *)info
->tmp
+ len
, &maxlen
, buffer
)) == -1) goto error
;
1588 while (isspace(*buffer
)) buffer
++;
1589 if (!*buffer
) break;
1590 if (*buffer
!= '\\') goto error
;
1591 if (read_next_line( info
) != 1) goto error
;
1592 buffer
= info
->buffer
;
1593 while (isspace(*buffer
)) buffer
++;
1599 ptr
= NULL
; /* keep compiler quiet */
1603 if (!len
) newptr
= NULL
;
1604 else if (!(newptr
= memdup( ptr
, len
))) return 0;
1606 free( value
->data
);
1607 value
->data
= newptr
;
1613 file_read_error( "Malformed value", info
);
1614 free( value
->data
);
1617 value
->type
= REG_NONE
;
1621 /* return the length (in path elements) of name that is part of the key name */
1622 /* for instance if key is USER\foo\bar and name is foo\bar\baz, return 2 */
1623 static int get_prefix_len( struct key
*key
, const char *name
, struct file_load_info
*info
)
1629 if (!get_file_tmp_space( info
, strlen(name
) * sizeof(WCHAR
) )) return 0;
1632 if ((res
= parse_strW( info
->tmp
, &len
, name
, ']' )) == -1)
1634 file_read_error( "Malformed key", info
);
1637 for (p
= info
->tmp
; *p
; p
++) if (*p
== '\\') break;
1638 len
= (p
- info
->tmp
) * sizeof(WCHAR
);
1639 for (res
= 1; key
!= root_key
; res
++)
1641 if (len
== key
->namelen
&& !memicmp_strW( info
->tmp
, key
->name
, len
)) break;
1644 if (key
== root_key
) res
= 0; /* no matching name */
1648 /* load all the keys from the input file */
1649 /* prefix_len is the number of key name prefixes to skip, or -1 for autodetection */
1650 static void load_keys( struct key
*key
, const char *filename
, FILE *f
, int prefix_len
)
1652 struct key
*subkey
= NULL
;
1653 struct file_load_info info
;
1654 timeout_t modif
= current_time
;
1657 info
.filename
= filename
;
1662 if (!(info
.buffer
= mem_alloc( info
.len
))) return;
1663 if (!(info
.tmp
= mem_alloc( info
.tmplen
)))
1665 free( info
.buffer
);
1669 if ((read_next_line( &info
) != 1) ||
1670 strcmp( info
.buffer
, "WINE REGISTRY Version 2" ))
1672 set_error( STATUS_NOT_REGISTRY_FILE
);
1676 while (read_next_line( &info
) == 1)
1679 while (*p
&& isspace(*p
)) p
++;
1682 case '[': /* new key */
1685 update_key_time( subkey
, modif
);
1686 release_object( subkey
);
1688 if (prefix_len
== -1) prefix_len
= get_prefix_len( key
, p
+ 1, &info
);
1689 if (!(subkey
= load_key( key
, p
+ 1, prefix_len
, &info
, &modif
)))
1690 file_read_error( "Error creating key", &info
);
1692 case '@': /* default value */
1693 case '\"': /* value */
1694 if (subkey
) load_value( subkey
, p
, &info
);
1695 else file_read_error( "Value without key", &info
);
1697 case '#': /* option */
1698 if (subkey
) load_key_option( subkey
, p
, &info
);
1699 else if (!load_global_option( p
, &info
)) goto done
;
1701 case ';': /* comment */
1702 case 0: /* empty line */
1705 file_read_error( "Unrecognized input", &info
);
1713 update_key_time( subkey
, modif
);
1714 release_object( subkey
);
1716 free( info
.buffer
);
1720 /* load a part of the registry from a file */
1721 static void load_registry( struct key
*key
, obj_handle_t handle
)
1726 if (!(file
= get_file_obj( current
->process
, handle
, FILE_READ_DATA
))) return;
1727 fd
= dup( get_file_unix_fd( file
) );
1728 release_object( file
);
1731 FILE *f
= fdopen( fd
, "r" );
1734 load_keys( key
, NULL
, f
, -1 );
1737 else file_set_error();
1741 /* load one of the initial registry files */
1742 static int load_init_registry_from_file( const char *filename
, struct key
*key
)
1746 if ((f
= fopen( filename
, "r" )))
1748 load_keys( key
, filename
, f
, 0 );
1750 if (get_error() == STATUS_NOT_REGISTRY_FILE
)
1752 fprintf( stderr
, "%s is not a valid registry file\n", filename
);
1757 assert( save_branch_count
< MAX_SAVE_BRANCH_INFO
);
1759 save_branch_info
[save_branch_count
].path
= filename
;
1760 save_branch_info
[save_branch_count
++].key
= (struct key
*)grab_object( key
);
1761 make_object_permanent( &key
->obj
);
1765 static WCHAR
*format_user_registry_path( const SID
*sid
, struct unicode_str
*path
)
1767 char buffer
[7 + 11 + 11 + 11 * SID_MAX_SUB_AUTHORITIES
], *p
= buffer
;
1770 p
+= sprintf( p
, "User\\S-%u-%u", sid
->Revision
,
1771 MAKELONG( MAKEWORD( sid
->IdentifierAuthority
.Value
[5],
1772 sid
->IdentifierAuthority
.Value
[4] ),
1773 MAKEWORD( sid
->IdentifierAuthority
.Value
[3],
1774 sid
->IdentifierAuthority
.Value
[2] )));
1775 for (i
= 0; i
< sid
->SubAuthorityCount
; i
++) p
+= sprintf( p
, "-%u", sid
->SubAuthority
[i
] );
1776 return ascii_to_unicode_str( buffer
, path
);
1779 static void init_supported_machines(void)
1781 unsigned int count
= 0;
1783 if (prefix_type
== PREFIX_32BIT
) supported_machines
[count
++] = IMAGE_FILE_MACHINE_I386
;
1784 #elif defined(__x86_64__)
1785 if (prefix_type
== PREFIX_64BIT
) supported_machines
[count
++] = IMAGE_FILE_MACHINE_AMD64
;
1786 supported_machines
[count
++] = IMAGE_FILE_MACHINE_I386
;
1787 #elif defined(__arm__)
1788 if (prefix_type
== PREFIX_32BIT
) supported_machines
[count
++] = IMAGE_FILE_MACHINE_ARMNT
;
1789 #elif defined(__aarch64__)
1790 if (prefix_type
== PREFIX_64BIT
)
1792 supported_machines
[count
++] = IMAGE_FILE_MACHINE_ARM64
;
1793 supported_machines
[count
++] = IMAGE_FILE_MACHINE_I386
;
1795 supported_machines
[count
++] = IMAGE_FILE_MACHINE_ARMNT
;
1797 #error Unsupported machine
1799 supported_machines_count
= count
;
1800 native_machine
= supported_machines
[0];
1803 /* registry initialisation */
1804 void init_registry(void)
1806 static const WCHAR HKLM
[] = { 'M','a','c','h','i','n','e' };
1807 static const WCHAR HKU_default
[] = { 'U','s','e','r','\\','.','D','e','f','a','u','l','t' };
1808 static const WCHAR classes_i386
[] = {'S','o','f','t','w','a','r','e','\\',
1809 'C','l','a','s','s','e','s','\\',
1810 'W','o','w','6','4','3','2','N','o','d','e'};
1811 static const WCHAR classes_amd64
[] = {'S','o','f','t','w','a','r','e','\\',
1812 'C','l','a','s','s','e','s','\\',
1813 'W','o','w','6','4','6','4','N','o','d','e'};
1814 static const WCHAR classes_arm
[] = {'S','o','f','t','w','a','r','e','\\',
1815 'C','l','a','s','s','e','s','\\',
1816 'W','o','w','A','A','3','2','N','o','d','e'};
1817 static const WCHAR classes_arm64
[] = {'S','o','f','t','w','a','r','e','\\',
1818 'C','l','a','s','s','e','s','\\',
1819 'W','o','w','A','A','6','4','N','o','d','e'};
1820 static const struct unicode_str root_name
= { NULL
, 0 };
1821 static const struct unicode_str HKLM_name
= { HKLM
, sizeof(HKLM
) };
1822 static const struct unicode_str HKU_name
= { HKU_default
, sizeof(HKU_default
) };
1824 WCHAR
*current_user_path
;
1825 struct unicode_str current_user_str
;
1826 struct key
*key
, *hklm
, *hkcu
;
1830 /* switch to the config dir */
1832 if (fchdir( config_dir_fd
) == -1) fatal_error( "chdir to config dir: %s\n", strerror( errno
));
1834 /* create the root key */
1835 root_key
= alloc_key( &root_name
, current_time
);
1837 make_object_permanent( &root_key
->obj
);
1839 /* load system.reg into Registry\Machine */
1841 if (!(hklm
= create_key_recursive( root_key
, &HKLM_name
, current_time
)))
1842 fatal_error( "could not create Machine registry key\n" );
1844 if (!load_init_registry_from_file( "system.reg", hklm
))
1846 if ((p
= getenv( "WINEARCH" )) && !strcmp( p
, "win32" ))
1847 prefix_type
= PREFIX_32BIT
;
1849 prefix_type
= sizeof(void *) > sizeof(int) ? PREFIX_64BIT
: PREFIX_32BIT
;
1851 else if (prefix_type
== PREFIX_UNKNOWN
)
1852 prefix_type
= PREFIX_32BIT
;
1854 init_supported_machines();
1856 /* load userdef.reg into Registry\User\.Default */
1858 if (!(key
= create_key_recursive( root_key
, &HKU_name
, current_time
)))
1859 fatal_error( "could not create User\\.Default registry key\n" );
1861 load_init_registry_from_file( "userdef.reg", key
);
1862 release_object( key
);
1864 /* load user.reg into HKEY_CURRENT_USER */
1866 /* FIXME: match default user in token.c. should get from process token instead */
1867 current_user_path
= format_user_registry_path( security_local_user_sid
, ¤t_user_str
);
1868 if (!current_user_path
||
1869 !(hkcu
= create_key_recursive( root_key
, ¤t_user_str
, current_time
)))
1870 fatal_error( "could not create HKEY_CURRENT_USER registry key\n" );
1871 free( current_user_path
);
1872 load_init_registry_from_file( "user.reg", hkcu
);
1874 /* set the shared flag on Software\Classes\Wow6432Node for all platforms */
1875 for (i
= 1; i
< supported_machines_count
; i
++)
1877 struct unicode_str name
;
1879 switch (supported_machines
[i
])
1881 case IMAGE_FILE_MACHINE_I386
: name
.str
= classes_i386
; name
.len
= sizeof(classes_i386
); break;
1882 case IMAGE_FILE_MACHINE_ARMNT
: name
.str
= classes_arm
; name
.len
= sizeof(classes_arm
); break;
1883 case IMAGE_FILE_MACHINE_AMD64
: name
.str
= classes_amd64
; name
.len
= sizeof(classes_amd64
); break;
1884 case IMAGE_FILE_MACHINE_ARM64
: name
.str
= classes_arm64
; name
.len
= sizeof(classes_arm64
); break;
1886 if ((key
= create_key_recursive( hklm
, &name
, current_time
)))
1888 key
->flags
|= KEY_WOWSHARE
;
1889 release_object( key
);
1891 /* FIXME: handle HKCU too */
1894 release_object( hklm
);
1895 release_object( hkcu
);
1897 /* start the periodic save timer */
1898 set_periodic_save_timer();
1900 /* create windows directories */
1902 if (!mkdir( "drive_c/windows", 0777 ))
1904 mkdir( "drive_c/windows/system32", 0777 );
1905 for (i
= 1; i
< supported_machines_count
; i
++)
1907 switch (supported_machines
[i
])
1909 case IMAGE_FILE_MACHINE_I386
: mkdir( "drive_c/windows/syswow64", 0777 ); break;
1910 case IMAGE_FILE_MACHINE_ARMNT
: mkdir( "drive_c/windows/sysarm32", 0777 ); break;
1911 case IMAGE_FILE_MACHINE_AMD64
: mkdir( "drive_c/windows/sysx8664", 0777 ); break;
1912 case IMAGE_FILE_MACHINE_ARM64
: mkdir( "drive_c/windows/sysarm64", 0777 ); break;
1917 /* go back to the server dir */
1918 if (fchdir( server_dir_fd
) == -1) fatal_error( "chdir to server dir: %s\n", strerror( errno
));
1921 /* save a registry branch to a file */
1922 static void save_all_subkeys( struct key
*key
, FILE *f
)
1924 fprintf( f
, "WINE REGISTRY Version 2\n" );
1925 fprintf( f
, ";; All keys relative to " );
1926 dump_path( key
, NULL
, f
);
1928 switch (prefix_type
)
1931 fprintf( f
, "\n#arch=win32\n" );
1934 fprintf( f
, "\n#arch=win64\n" );
1939 save_subkeys( key
, key
, f
);
1942 /* save a registry branch to a file handle */
1943 static void save_registry( struct key
*key
, obj_handle_t handle
)
1948 if (!(file
= get_file_obj( current
->process
, handle
, FILE_WRITE_DATA
))) return;
1949 fd
= dup( get_file_unix_fd( file
) );
1950 release_object( file
);
1953 FILE *f
= fdopen( fd
, "w" );
1956 save_all_subkeys( key
, f
);
1957 if (fclose( f
)) file_set_error();
1967 /* save a registry branch to a file */
1968 static int save_branch( struct key
*key
, const char *path
)
1971 char *p
, *tmp
= NULL
;
1972 int fd
, count
= 0, ret
= 0;
1975 if (!(key
->flags
& KEY_DIRTY
))
1977 if (debug_level
> 1) dump_operation( key
, NULL
, "Not saving clean" );
1981 /* test the file type */
1983 if ((fd
= open( path
, O_WRONLY
)) != -1)
1985 /* if file is not a regular file or has multiple links or is accessed
1986 * via symbolic links, write directly into it; otherwise use a temp file */
1987 if (!lstat( path
, &st
) && (!S_ISREG(st
.st_mode
) || st
.st_nlink
> 1))
1995 /* create a temp file in the same directory */
1997 if (!(tmp
= malloc( strlen(path
) + 20 ))) goto done
;
1998 strcpy( tmp
, path
);
1999 if ((p
= strrchr( tmp
, '/' ))) p
++;
2003 sprintf( p
, "reg%lx%04x.tmp", (long) getpid(), count
++ );
2004 if ((fd
= open( tmp
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666 )) != -1) break;
2005 if (errno
!= EEXIST
) goto done
;
2009 /* now save to it */
2012 if (!(f
= fdopen( fd
, "w" )))
2014 if (tmp
) unlink( tmp
);
2019 if (debug_level
> 1)
2021 fprintf( stderr
, "%s: ", path
);
2022 dump_operation( key
, NULL
, "saving" );
2025 save_all_subkeys( key
, f
);
2030 /* if successfully written, rename to final name */
2031 if (ret
) ret
= !rename( tmp
, path
);
2032 if (!ret
) unlink( tmp
);
2037 if (ret
) make_clean( key
);
2041 /* periodic saving of the registry */
2042 static void periodic_save( void *arg
)
2046 if (fchdir( config_dir_fd
) == -1) return;
2047 save_timeout_user
= NULL
;
2048 for (i
= 0; i
< save_branch_count
; i
++)
2049 save_branch( save_branch_info
[i
].key
, save_branch_info
[i
].path
);
2050 if (fchdir( server_dir_fd
) == -1) fatal_error( "chdir to server dir: %s\n", strerror( errno
));
2051 set_periodic_save_timer();
2054 /* start the periodic save timer */
2055 static void set_periodic_save_timer(void)
2057 if (save_timeout_user
) remove_timeout_user( save_timeout_user
);
2058 save_timeout_user
= add_timeout_user( save_period
, periodic_save
, NULL
);
2061 /* save the modified registry branches to disk */
2062 void flush_registry(void)
2066 if (fchdir( config_dir_fd
) == -1) return;
2067 for (i
= 0; i
< save_branch_count
; i
++)
2069 if (!save_branch( save_branch_info
[i
].key
, save_branch_info
[i
].path
))
2071 fprintf( stderr
, "wineserver: could not save registry branch to %s",
2072 save_branch_info
[i
].path
);
2076 if (fchdir( server_dir_fd
) == -1) fatal_error( "chdir to server dir: %s\n", strerror( errno
));
2079 /* determine if the thread is wow64 (32-bit client running on 64-bit prefix) */
2080 static int is_wow64_thread( struct thread
*thread
)
2082 return (is_machine_64bit( native_machine
) && !is_machine_64bit( thread
->process
->machine
));
2086 /* create a registry key */
2087 DECL_HANDLER(create_key
)
2089 struct key
*key
= NULL
, *parent
;
2090 struct unicode_str name
, class;
2091 unsigned int access
= req
->access
;
2092 const struct security_descriptor
*sd
;
2093 const struct object_attributes
*objattr
= get_req_object_attributes( &sd
, &name
, NULL
);
2095 if (!objattr
) return;
2097 if (!is_wow64_thread( current
)) access
= (access
& ~KEY_WOW64_32KEY
) | KEY_WOW64_64KEY
;
2099 class.str
= get_req_data_after_objattr( objattr
, &class.len
);
2100 class.len
= (class.len
/ sizeof(WCHAR
)) * sizeof(WCHAR
);
2102 if (!objattr
->rootdir
&& name
.len
>= sizeof(root_name
) &&
2103 !memicmp_strW( name
.str
, root_name
, sizeof(root_name
) ))
2105 name
.str
+= ARRAY_SIZE( root_name
);
2106 name
.len
-= sizeof(root_name
);
2109 /* NOTE: no access rights are required from the parent handle to create a key */
2110 if ((parent
= get_parent_hkey_obj( objattr
->rootdir
)))
2112 if ((key
= create_key( parent
, &name
, &class, req
->options
, access
,
2113 objattr
->attributes
, sd
, &reply
->created
)))
2115 reply
->hkey
= alloc_handle( current
->process
, key
, access
, objattr
->attributes
);
2116 release_object( key
);
2118 release_object( parent
);
2122 /* open a registry key */
2123 DECL_HANDLER(open_key
)
2125 struct key
*key
, *parent
;
2126 struct unicode_str name
;
2127 unsigned int access
= req
->access
;
2129 if (!is_wow64_thread( current
)) access
= (access
& ~KEY_WOW64_32KEY
) | KEY_WOW64_64KEY
;
2132 /* NOTE: no access rights are required to open the parent key, only the child key */
2133 if ((parent
= get_parent_hkey_obj( req
->parent
)))
2135 get_req_path( &name
, !req
->parent
);
2136 if ((key
= open_key( parent
, &name
, access
, req
->attributes
)))
2138 reply
->hkey
= alloc_handle( current
->process
, key
, access
, req
->attributes
);
2139 release_object( key
);
2141 release_object( parent
);
2145 /* delete a registry key */
2146 DECL_HANDLER(delete_key
)
2150 if ((key
= get_hkey_obj( req
->hkey
, DELETE
)))
2152 delete_key( key
, 0);
2153 release_object( key
);
2157 /* flush a registry key */
2158 DECL_HANDLER(flush_key
)
2160 struct key
*key
= get_hkey_obj( req
->hkey
, 0 );
2163 /* we don't need to do anything here with the current implementation */
2164 release_object( key
);
2168 /* enumerate registry subkeys */
2169 DECL_HANDLER(enum_key
)
2173 if ((key
= get_hkey_obj( req
->hkey
,
2174 req
->index
== -1 ? KEY_QUERY_VALUE
: KEY_ENUMERATE_SUB_KEYS
)))
2176 enum_key( key
, req
->index
, req
->info_class
, reply
);
2177 release_object( key
);
2181 /* set a value of a registry key */
2182 DECL_HANDLER(set_key_value
)
2185 struct unicode_str name
;
2187 if (req
->namelen
> get_req_data_size())
2189 set_error( STATUS_INVALID_PARAMETER
);
2192 name
.str
= get_req_data();
2193 name
.len
= (req
->namelen
/ sizeof(WCHAR
)) * sizeof(WCHAR
);
2195 if ((key
= get_hkey_obj( req
->hkey
, KEY_SET_VALUE
)))
2197 data_size_t datalen
= get_req_data_size() - req
->namelen
;
2198 const char *data
= (const char *)get_req_data() + req
->namelen
;
2200 set_value( key
, &name
, req
->type
, data
, datalen
);
2201 release_object( key
);
2205 /* retrieve the value of a registry key */
2206 DECL_HANDLER(get_key_value
)
2209 struct unicode_str name
= get_req_unicode_str();
2212 if ((key
= get_hkey_obj( req
->hkey
, KEY_QUERY_VALUE
)))
2214 get_value( key
, &name
, &reply
->type
, &reply
->total
);
2215 release_object( key
);
2219 /* enumerate the value of a registry key */
2220 DECL_HANDLER(enum_key_value
)
2224 if ((key
= get_hkey_obj( req
->hkey
, KEY_QUERY_VALUE
)))
2226 enum_value( key
, req
->index
, req
->info_class
, reply
);
2227 release_object( key
);
2231 /* delete a value of a registry key */
2232 DECL_HANDLER(delete_key_value
)
2235 struct unicode_str name
= get_req_unicode_str();
2237 if ((key
= get_hkey_obj( req
->hkey
, KEY_SET_VALUE
)))
2239 delete_value( key
, &name
);
2240 release_object( key
);
2244 /* load a registry branch from a file */
2245 DECL_HANDLER(load_registry
)
2247 struct key
*key
, *parent
;
2248 struct unicode_str name
;
2249 const struct security_descriptor
*sd
;
2250 const struct object_attributes
*objattr
= get_req_object_attributes( &sd
, &name
, NULL
);
2252 if (!objattr
) return;
2254 if (!thread_single_check_privilege( current
, &SeRestorePrivilege
))
2256 set_error( STATUS_PRIVILEGE_NOT_HELD
);
2260 if (!objattr
->rootdir
&& name
.len
>= sizeof(root_name
) &&
2261 !memicmp_strW( name
.str
, root_name
, sizeof(root_name
) ))
2263 name
.str
+= ARRAY_SIZE( root_name
);
2264 name
.len
-= sizeof(root_name
);
2267 if ((parent
= get_parent_hkey_obj( objattr
->rootdir
)))
2270 if ((key
= create_key( parent
, &name
, NULL
, 0, KEY_WOW64_64KEY
, 0, sd
, &dummy
)))
2272 load_registry( key
, req
->file
);
2273 release_object( key
);
2275 release_object( parent
);
2279 DECL_HANDLER(unload_registry
)
2281 struct key
*key
, *parent
;
2282 struct unicode_str name
;
2283 unsigned int access
= 0;
2285 if (!thread_single_check_privilege( current
, &SeRestorePrivilege
))
2287 set_error( STATUS_PRIVILEGE_NOT_HELD
);
2291 if (!is_wow64_thread( current
)) access
= (access
& ~KEY_WOW64_32KEY
) | KEY_WOW64_64KEY
;
2293 if ((parent
= get_parent_hkey_obj( req
->parent
)))
2295 get_req_path( &name
, !req
->parent
);
2296 if ((key
= open_key( parent
, &name
, access
, req
->attributes
)))
2298 if (key
->obj
.handle_count
)
2299 set_error( STATUS_CANNOT_DELETE
);
2301 delete_key( key
, 1 ); /* FIXME */
2302 release_object( key
);
2304 release_object( parent
);
2308 /* save a registry branch to a file */
2309 DECL_HANDLER(save_registry
)
2313 if (!thread_single_check_privilege( current
, &SeBackupPrivilege
))
2315 set_error( STATUS_PRIVILEGE_NOT_HELD
);
2319 if ((key
= get_hkey_obj( req
->hkey
, 0 )))
2321 save_registry( key
, req
->file
);
2322 release_object( key
);
2326 /* add a registry key change notification */
2327 DECL_HANDLER(set_registry_notification
)
2330 struct event
*event
;
2331 struct notify
*notify
;
2333 key
= get_hkey_obj( req
->hkey
, KEY_NOTIFY
);
2336 event
= get_event_obj( current
->process
, req
->event
, SYNCHRONIZE
);
2339 notify
= find_notify( key
, current
->process
, req
->hkey
);
2342 notify
= mem_alloc( sizeof(*notify
) );
2345 notify
->events
= NULL
;
2346 notify
->event_count
= 0;
2347 notify
->subtree
= req
->subtree
;
2348 notify
->filter
= req
->filter
;
2349 notify
->hkey
= req
->hkey
;
2350 notify
->process
= current
->process
;
2351 list_add_head( &key
->notify_list
, ¬ify
->entry
);
2356 struct event
**new_array
;
2358 if ((new_array
= realloc( notify
->events
, (notify
->event_count
+ 1) * sizeof(*notify
->events
) )))
2360 notify
->events
= new_array
;
2361 notify
->events
[notify
->event_count
++] = (struct event
*)grab_object( event
);
2362 reset_event( event
);
2363 set_error( STATUS_PENDING
);
2365 else set_error( STATUS_NO_MEMORY
);
2367 release_object( event
);
2369 release_object( key
);