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
37 #include <sys/types.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) */
104 #define KEY_PREDEF 0x0040 /* key is marked as predefined */
109 WCHAR
*name
; /* value name */
110 unsigned short namelen
; /* length of value name */
111 unsigned int type
; /* value type */
112 data_size_t len
; /* value data length in bytes */
113 void *data
; /* pointer to value data */
116 #define MIN_SUBKEYS 8 /* min. number of allocated subkeys per key */
117 #define MIN_VALUES 8 /* min. number of allocated values per key */
119 #define MAX_NAME_LEN 256 /* max. length of a key name */
120 #define MAX_VALUE_LEN 16383 /* max. length of a value name */
122 /* the root of the registry tree */
123 static struct key
*root_key
;
125 static const timeout_t ticks_1601_to_1970
= (timeout_t
)86400 * (369 * 365 + 89) * TICKS_PER_SEC
;
126 static const timeout_t save_period
= 30 * -TICKS_PER_SEC
; /* delay between periodic saves */
127 static struct timeout_user
*save_timeout_user
; /* saving timer */
128 static enum prefix_type
{ PREFIX_UNKNOWN
, PREFIX_32BIT
, PREFIX_64BIT
} prefix_type
;
130 static const WCHAR root_name
[] = { '\\','R','e','g','i','s','t','r','y','\\' };
131 static const WCHAR wow6432node
[] = {'W','o','w','6','4','3','2','N','o','d','e'};
132 static const WCHAR symlink_value
[] = {'S','y','m','b','o','l','i','c','L','i','n','k','V','a','l','u','e'};
133 static const struct unicode_str symlink_str
= { symlink_value
, sizeof(symlink_value
) };
135 static void set_periodic_save_timer(void);
136 static struct key_value
*find_value( const struct key
*key
, const struct unicode_str
*name
, int *index
);
138 /* information about where to save a registry branch */
139 struct save_branch_info
145 #define MAX_SAVE_BRANCH_INFO 3
146 static int save_branch_count
;
147 static struct save_branch_info save_branch_info
[MAX_SAVE_BRANCH_INFO
];
149 unsigned int supported_machines_count
= 0;
150 unsigned short supported_machines
[8];
151 unsigned short native_machine
= 0;
153 /* information about a file being loaded */
154 struct file_load_info
156 const char *filename
; /* input file name */
157 FILE *file
; /* input file */
158 char *buffer
; /* line buffer */
159 int len
; /* buffer length */
160 int line
; /* current input line */
161 WCHAR
*tmp
; /* temp buffer to use while parsing input */
162 size_t tmplen
; /* length of temp buffer */
166 static void key_dump( struct object
*obj
, int verbose
);
167 static unsigned int key_map_access( struct object
*obj
, unsigned int access
);
168 static struct security_descriptor
*key_get_sd( struct object
*obj
);
169 static WCHAR
*key_get_full_name( struct object
*obj
, data_size_t
*len
);
170 static int key_close_handle( struct object
*obj
, struct process
*process
, obj_handle_t handle
);
171 static void key_destroy( struct object
*obj
);
173 static const struct object_ops key_ops
=
175 sizeof(struct key
), /* size */
176 &key_type
, /* type */
178 no_add_queue
, /* add_queue */
179 NULL
, /* remove_queue */
181 NULL
, /* satisfied */
182 no_signal
, /* signal */
183 no_get_fd
, /* get_fd */
184 key_map_access
, /* map_access */
185 key_get_sd
, /* get_sd */
186 default_set_sd
, /* set_sd */
187 key_get_full_name
, /* get_full_name */
188 no_lookup_name
, /* lookup_name */
189 no_link_name
, /* link_name */
190 NULL
, /* unlink_name */
191 no_open_file
, /* open_file */
192 no_kernel_obj_list
, /* get_kernel_obj_list */
193 key_close_handle
, /* close_handle */
194 key_destroy
/* destroy */
198 static inline int is_wow6432node( const WCHAR
*name
, unsigned int len
)
200 return (len
== sizeof(wow6432node
) && !memicmp_strW( name
, wow6432node
, sizeof( wow6432node
)));
204 * The registry text file format v2 used by this code is similar to the one
205 * used by REGEDIT import/export functionality, with the following differences:
206 * - strings and key names can contain \x escapes for Unicode
207 * - key names use escapes too in order to support Unicode
208 * - the modification time optionally follows the key name
209 * - REG_EXPAND_SZ and REG_MULTI_SZ are saved as strings instead of hex
212 /* dump the full path of a key */
213 static void dump_path( const struct key
*key
, const struct key
*base
, FILE *f
)
215 if (key
->parent
&& key
->parent
!= base
)
217 dump_path( key
->parent
, base
, f
);
218 fprintf( f
, "\\\\" );
220 dump_strW( key
->name
, key
->namelen
, f
, "[]" );
223 /* dump a value to a text file */
224 static void dump_value( const struct key_value
*value
, FILE *f
)
232 count
= 1 + dump_strW( value
->name
, value
->namelen
, f
, "\"\"" );
233 count
+= fprintf( f
, "\"=" );
235 else count
= fprintf( f
, "@=" );
242 /* only output properly terminated strings in string format */
243 if (value
->len
< sizeof(WCHAR
)) break;
244 if (value
->len
% sizeof(WCHAR
)) break;
245 if (((WCHAR
*)value
->data
)[value
->len
/ sizeof(WCHAR
) - 1]) break;
246 if (value
->type
!= REG_SZ
) fprintf( f
, "str(%x):", value
->type
);
248 dump_strW( (WCHAR
*)value
->data
, value
->len
, f
, "\"\"" );
249 fprintf( f
, "\"\n" );
253 if (value
->len
!= sizeof(dw
)) break;
254 memcpy( &dw
, value
->data
, sizeof(dw
) );
255 fprintf( f
, "dword:%08x\n", dw
);
259 if (value
->type
== REG_BINARY
) count
+= fprintf( f
, "hex:" );
260 else count
+= fprintf( f
, "hex(%x):", value
->type
);
261 for (i
= 0; i
< value
->len
; i
++)
263 count
+= fprintf( f
, "%02x", *((unsigned char *)value
->data
+ i
) );
264 if (i
< value
->len
-1)
269 fprintf( f
, "\\\n " );
277 /* save a registry and all its subkeys to a text file */
278 static void save_subkeys( const struct key
*key
, const struct key
*base
, FILE *f
)
282 if (key
->flags
& KEY_VOLATILE
) return;
283 /* save key if it has either some values or no subkeys, or needs special options */
284 /* keys with no values but subkeys are saved implicitly by saving the subkeys */
285 if ((key
->last_value
>= 0) || (key
->last_subkey
== -1) || key
->class || (key
->flags
& KEY_SYMLINK
))
288 if (key
!= base
) dump_path( key
, base
, f
);
289 fprintf( f
, "] %u\n", (unsigned int)((key
->modif
- ticks_1601_to_1970
) / TICKS_PER_SEC
) );
290 fprintf( f
, "#time=%x%08x\n", (unsigned int)(key
->modif
>> 32), (unsigned int)key
->modif
);
293 fprintf( f
, "#class=\"" );
294 dump_strW( key
->class, key
->classlen
, f
, "\"\"" );
295 fprintf( f
, "\"\n" );
297 if (key
->flags
& KEY_SYMLINK
) fputs( "#link\n", f
);
298 for (i
= 0; i
<= key
->last_value
; i
++) dump_value( &key
->values
[i
], f
);
300 for (i
= 0; i
<= key
->last_subkey
; i
++) save_subkeys( key
->subkeys
[i
], base
, f
);
303 static void dump_operation( const struct key
*key
, const struct key_value
*value
, const char *op
)
305 fprintf( stderr
, "%s key ", op
);
306 if (key
) dump_path( key
, NULL
, stderr
);
307 else fprintf( stderr
, "ERROR" );
310 fprintf( stderr
, " value ");
311 dump_value( value
, stderr
);
313 else fprintf( stderr
, "\n" );
316 static void key_dump( struct object
*obj
, int verbose
)
318 struct key
*key
= (struct key
*)obj
;
319 assert( obj
->ops
== &key_ops
);
320 fprintf( stderr
, "Key flags=%x ", key
->flags
);
321 dump_path( key
, NULL
, stderr
);
322 fprintf( stderr
, "\n" );
325 /* notify waiter and maybe delete the notification */
326 static void do_notification( struct key
*key
, struct notify
*notify
, int del
)
330 for (i
= 0; i
< notify
->event_count
; ++i
)
332 set_event( notify
->events
[i
] );
333 release_object( notify
->events
[i
] );
335 free( notify
->events
);
336 notify
->events
= NULL
;
337 notify
->event_count
= 0;
341 list_remove( ¬ify
->entry
);
346 static inline struct notify
*find_notify( struct key
*key
, struct process
*process
, obj_handle_t hkey
)
348 struct notify
*notify
;
350 LIST_FOR_EACH_ENTRY( notify
, &key
->notify_list
, struct notify
, entry
)
352 if (notify
->process
== process
&& notify
->hkey
== hkey
) return notify
;
357 static unsigned int key_map_access( struct object
*obj
, unsigned int access
)
359 access
= default_map_access( obj
, access
);
360 /* filter the WOW64 masks, as they aren't real access bits */
361 return access
& ~(KEY_WOW64_64KEY
| KEY_WOW64_32KEY
);
364 static struct security_descriptor
*key_get_sd( struct object
*obj
)
366 static struct security_descriptor
*key_default_sd
;
368 if (obj
->sd
) return obj
->sd
;
375 size_t users_sid_len
= sid_len( &builtin_users_sid
);
376 size_t admins_sid_len
= sid_len( &builtin_admins_sid
);
377 size_t dacl_len
= sizeof(*dacl
) + 2 * sizeof(*ace
) + users_sid_len
+ admins_sid_len
;
379 key_default_sd
= mem_alloc( sizeof(*key_default_sd
) + 2 * admins_sid_len
+ dacl_len
);
380 key_default_sd
->control
= SE_DACL_PRESENT
;
381 key_default_sd
->owner_len
= admins_sid_len
;
382 key_default_sd
->group_len
= admins_sid_len
;
383 key_default_sd
->sacl_len
= 0;
384 key_default_sd
->dacl_len
= dacl_len
;
385 sid
= (struct sid
*)(key_default_sd
+ 1);
386 sid
= copy_sid( sid
, &builtin_admins_sid
);
387 sid
= copy_sid( sid
, &builtin_admins_sid
);
389 dacl
= (struct acl
*)((char *)(key_default_sd
+ 1) + 2 * admins_sid_len
);
390 dacl
->revision
= ACL_REVISION
;
392 dacl
->size
= dacl_len
;
395 ace
= set_ace( ace_first( dacl
), &builtin_users_sid
, ACCESS_ALLOWED_ACE_TYPE
,
396 INHERIT_ONLY_ACE
| CONTAINER_INHERIT_ACE
, GENERIC_READ
);
397 set_ace( ace_next( ace
), &builtin_admins_sid
, ACCESS_ALLOWED_ACE_TYPE
, 0, KEY_ALL_ACCESS
);
399 return key_default_sd
;
402 static WCHAR
*key_get_full_name( struct object
*obj
, data_size_t
*ret_len
)
404 static const WCHAR backslash
= '\\';
405 struct key
*key
= (struct key
*) obj
;
406 data_size_t len
= sizeof(root_name
) - sizeof(WCHAR
);
409 if (key
->flags
& KEY_DELETED
)
411 set_error( STATUS_KEY_DELETED
);
415 for (key
= (struct key
*)obj
; key
!= root_key
; key
= key
->parent
) len
+= key
->namelen
+ sizeof(WCHAR
);
416 if (!(ret
= malloc( len
))) return NULL
;
419 key
= (struct key
*)obj
;
420 for (key
= (struct key
*)obj
; key
!= root_key
; key
= key
->parent
)
422 memcpy( ret
+ len
- key
->namelen
, key
->name
, key
->namelen
);
423 len
-= key
->namelen
+ sizeof(WCHAR
);
424 memcpy( ret
+ len
, &backslash
, sizeof(WCHAR
) );
426 memcpy( ret
, root_name
, sizeof(root_name
) - sizeof(WCHAR
) );
430 /* close the notification associated with a handle */
431 static int key_close_handle( struct object
*obj
, struct process
*process
, obj_handle_t handle
)
433 struct key
* key
= (struct key
*) obj
;
434 struct notify
*notify
= find_notify( key
, process
, handle
);
435 if (notify
) do_notification( key
, notify
, 1 );
436 return 1; /* ok to close */
439 static void key_destroy( struct object
*obj
)
443 struct key
*key
= (struct key
*)obj
;
444 assert( obj
->ops
== &key_ops
);
448 for (i
= 0; i
<= key
->last_value
; i
++)
450 free( key
->values
[i
].name
);
451 free( key
->values
[i
].data
);
454 for (i
= 0; i
<= key
->last_subkey
; i
++)
456 key
->subkeys
[i
]->parent
= NULL
;
457 release_object( key
->subkeys
[i
] );
459 free( key
->subkeys
);
460 /* unconditionally notify everything waiting on this key */
461 while ((ptr
= list_head( &key
->notify_list
)))
463 struct notify
*notify
= LIST_ENTRY( ptr
, struct notify
, entry
);
464 do_notification( key
, notify
, 1 );
468 /* get the request vararg as registry path */
469 static inline void get_req_path( struct unicode_str
*str
, int skip_root
)
471 str
->str
= get_req_data();
472 str
->len
= (get_req_data_size() / sizeof(WCHAR
)) * sizeof(WCHAR
);
474 if (skip_root
&& str
->len
>= sizeof(root_name
) && !memicmp_strW( str
->str
, root_name
, sizeof(root_name
) ))
476 str
->str
+= ARRAY_SIZE( root_name
);
477 str
->len
-= sizeof(root_name
);
481 /* return the next token in a given path */
482 /* token->str must point inside the path, or be NULL for the first call */
483 static struct unicode_str
*get_path_token( const struct unicode_str
*path
, struct unicode_str
*token
)
485 data_size_t i
= 0, len
= path
->len
/ sizeof(WCHAR
);
487 if (!token
->str
) /* first time */
489 /* path cannot start with a backslash */
490 if (len
&& path
->str
[0] == '\\')
492 set_error( STATUS_OBJECT_PATH_INVALID
);
498 i
= token
->str
- path
->str
;
499 i
+= token
->len
/ sizeof(WCHAR
);
500 while (i
< len
&& path
->str
[i
] == '\\') i
++;
502 token
->str
= path
->str
+ i
;
503 while (i
< len
&& path
->str
[i
] != '\\') i
++;
504 token
->len
= (path
->str
+ i
- token
->str
) * sizeof(WCHAR
);
508 /* allocate a key object */
509 static struct key
*alloc_key( const struct unicode_str
*name
, timeout_t modif
)
512 if ((key
= alloc_object( &key_ops
)))
516 key
->namelen
= name
->len
;
519 key
->last_subkey
= -1;
523 key
->last_value
= -1;
527 list_init( &key
->notify_list
);
528 if (name
->len
&& !(key
->name
= memdup( name
->str
, name
->len
)))
530 release_object( key
);
537 /* mark a key and all its parents as dirty (modified) */
538 static void make_dirty( struct key
*key
)
542 if (key
->flags
& (KEY_DIRTY
|KEY_VOLATILE
)) return; /* nothing to do */
543 key
->flags
|= KEY_DIRTY
;
548 /* mark a key and all its subkeys as clean (not modified) */
549 static void make_clean( struct key
*key
)
553 if (key
->flags
& KEY_VOLATILE
) return;
554 if (!(key
->flags
& KEY_DIRTY
)) return;
555 key
->flags
&= ~KEY_DIRTY
;
556 for (i
= 0; i
<= key
->last_subkey
; i
++) make_clean( key
->subkeys
[i
] );
559 /* go through all the notifications and send them if necessary */
560 static void check_notify( struct key
*key
, unsigned int change
, int not_subtree
)
562 struct list
*ptr
, *next
;
564 LIST_FOR_EACH_SAFE( ptr
, next
, &key
->notify_list
)
566 struct notify
*n
= LIST_ENTRY( ptr
, struct notify
, entry
);
567 if ( ( not_subtree
|| n
->subtree
) && ( change
& n
->filter
) )
568 do_notification( key
, n
, 0 );
572 /* update key modification time */
573 static void touch_key( struct key
*key
, unsigned int change
)
577 key
->modif
= current_time
;
580 /* do notifications */
581 check_notify( key
, change
, 1 );
582 for ( k
= key
->parent
; k
; k
= k
->parent
)
583 check_notify( k
, change
, 0 );
586 /* try to grow the array of subkeys; return 1 if OK, 0 on error */
587 static int grow_subkeys( struct key
*key
)
589 struct key
**new_subkeys
;
594 nb_subkeys
= key
->nb_subkeys
+ (key
->nb_subkeys
/ 2); /* grow by 50% */
595 if (!(new_subkeys
= realloc( key
->subkeys
, nb_subkeys
* sizeof(*new_subkeys
) )))
597 set_error( STATUS_NO_MEMORY
);
603 nb_subkeys
= MIN_SUBKEYS
;
604 if (!(new_subkeys
= mem_alloc( nb_subkeys
* sizeof(*new_subkeys
) ))) return 0;
606 key
->subkeys
= new_subkeys
;
607 key
->nb_subkeys
= nb_subkeys
;
611 /* allocate a subkey for a given key, and return its index */
612 static struct key
*alloc_subkey( struct key
*parent
, const struct unicode_str
*name
,
613 int index
, timeout_t modif
)
618 if (name
->len
> MAX_NAME_LEN
* sizeof(WCHAR
))
620 set_error( STATUS_INVALID_PARAMETER
);
623 if (parent
->last_subkey
+ 1 == parent
->nb_subkeys
)
625 /* need to grow the array */
626 if (!grow_subkeys( parent
)) return NULL
;
628 if ((key
= alloc_key( name
, modif
)) != NULL
)
630 key
->parent
= parent
;
631 for (i
= ++parent
->last_subkey
; i
> index
; i
--)
632 parent
->subkeys
[i
] = parent
->subkeys
[i
-1];
633 parent
->subkeys
[index
] = key
;
634 if (is_wow6432node( key
->name
, key
->namelen
) && !is_wow6432node( parent
->name
, parent
->namelen
))
635 parent
->flags
|= KEY_WOW64
;
640 /* free a subkey of a given key */
641 static void free_subkey( struct key
*parent
, int index
)
646 assert( index
>= 0 );
647 assert( index
<= parent
->last_subkey
);
649 key
= parent
->subkeys
[index
];
650 for (i
= index
; i
< parent
->last_subkey
; i
++) parent
->subkeys
[i
] = parent
->subkeys
[i
+ 1];
651 parent
->last_subkey
--;
652 key
->flags
|= KEY_DELETED
;
654 if (is_wow6432node( key
->name
, key
->namelen
)) parent
->flags
&= ~KEY_WOW64
;
655 release_object( key
);
657 /* try to shrink the array */
658 nb_subkeys
= parent
->nb_subkeys
;
659 if (nb_subkeys
> MIN_SUBKEYS
&& parent
->last_subkey
< nb_subkeys
/ 2)
661 struct key
**new_subkeys
;
662 nb_subkeys
-= nb_subkeys
/ 3; /* shrink by 33% */
663 if (nb_subkeys
< MIN_SUBKEYS
) nb_subkeys
= MIN_SUBKEYS
;
664 if (!(new_subkeys
= realloc( parent
->subkeys
, nb_subkeys
* sizeof(*new_subkeys
) ))) return;
665 parent
->subkeys
= new_subkeys
;
666 parent
->nb_subkeys
= nb_subkeys
;
670 /* find the named child of a given key and return its index */
671 static struct key
*find_subkey( const struct key
*key
, const struct unicode_str
*name
, int *index
)
673 int i
, min
, max
, res
;
677 max
= key
->last_subkey
;
681 len
= min( key
->subkeys
[i
]->namelen
, name
->len
);
682 res
= memicmp_strW( key
->subkeys
[i
]->name
, name
->str
, len
);
683 if (!res
) res
= key
->subkeys
[i
]->namelen
- name
->len
;
687 return key
->subkeys
[i
];
689 if (res
> 0) max
= i
- 1;
692 *index
= min
; /* this is where we should insert it */
696 /* return the wow64 variant of the key, or the key itself if none */
697 static struct key
*find_wow64_subkey( struct key
*key
, const struct unicode_str
*name
)
699 static const struct unicode_str wow6432node_str
= { wow6432node
, sizeof(wow6432node
) };
702 if (!(key
->flags
& KEY_WOW64
)) return key
;
703 if (!is_wow6432node( name
->str
, name
->len
))
705 key
= find_subkey( key
, &wow6432node_str
, &index
);
706 assert( key
); /* if KEY_WOW64 is set we must find it */
712 /* follow a symlink and return the resolved key */
713 static struct key
*follow_symlink( struct key
*key
, int iteration
)
715 struct unicode_str path
, token
;
716 struct key_value
*value
;
719 if (iteration
> 16) return NULL
;
720 if (!(key
->flags
& KEY_SYMLINK
)) return key
;
721 if (!(value
= find_value( key
, &symlink_str
, &index
))) return NULL
;
723 path
.str
= value
->data
;
724 path
.len
= (value
->len
/ sizeof(WCHAR
)) * sizeof(WCHAR
);
725 if (path
.len
<= sizeof(root_name
)) return NULL
;
726 if (memicmp_strW( path
.str
, root_name
, sizeof(root_name
) )) return NULL
;
727 path
.str
+= ARRAY_SIZE( root_name
);
728 path
.len
-= sizeof(root_name
);
732 if (!get_path_token( &path
, &token
)) return NULL
;
735 if (!(key
= find_subkey( key
, &token
, &index
))) break;
736 if (!(key
= follow_symlink( key
, iteration
+ 1 ))) break;
737 get_path_token( &path
, &token
);
742 /* open a key until we find an element that doesn't exist */
743 /* helper for open_key and create_key */
744 static struct key
*open_key_prefix( struct key
*key
, const struct unicode_str
*name
,
745 unsigned int access
, struct unicode_str
*token
, int *index
)
748 if (!get_path_token( name
, token
)) return NULL
;
749 if (access
& KEY_WOW64_32KEY
) key
= find_wow64_subkey( key
, token
);
753 if (!(subkey
= find_subkey( key
, token
, index
)))
755 if ((key
->flags
& KEY_WOWSHARE
) && !(access
& KEY_WOW64_64KEY
))
757 /* try in the 64-bit parent */
759 subkey
= find_subkey( key
, token
, index
);
764 get_path_token( name
, token
);
765 if (!token
->len
) break;
766 if (!(access
& KEY_WOW64_64KEY
)) key
= find_wow64_subkey( key
, token
);
767 if (!(key
= follow_symlink( key
, 0 )))
769 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
777 static struct key
*open_key( struct key
*key
, const struct unicode_str
*name
, unsigned int access
,
778 unsigned int attributes
)
781 struct unicode_str token
;
783 if (!(key
= open_key_prefix( key
, name
, access
, &token
, &index
))) return NULL
;
787 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
790 if (!(access
& KEY_WOW64_64KEY
)) key
= find_wow64_subkey( key
, &token
);
791 if (!(attributes
& OBJ_OPENLINK
) && !(key
= follow_symlink( key
, 0 )))
793 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
796 if (debug_level
> 1) dump_operation( key
, NULL
, "Open" );
797 if (key
->flags
& KEY_PREDEF
) set_error( STATUS_PREDEFINED_HANDLE
);
802 /* create a subkey */
803 static struct key
*create_key( struct key
*key
, const struct unicode_str
*name
,
804 const struct unicode_str
*class, unsigned int options
,
805 unsigned int access
, unsigned int attributes
,
806 const struct security_descriptor
*sd
, int *created
)
809 struct unicode_str token
, next
;
812 if (!(key
= open_key_prefix( key
, name
, access
, &token
, &index
))) return NULL
;
814 if (!token
.len
) /* the key already exists */
816 if (!(access
& KEY_WOW64_64KEY
)) key
= find_wow64_subkey( key
, &token
);
817 if (options
& REG_OPTION_CREATE_LINK
)
819 set_error( STATUS_OBJECT_NAME_COLLISION
);
822 if (!(attributes
& OBJ_OPENLINK
) && !(key
= follow_symlink( key
, 0 )))
824 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
827 if (debug_level
> 1) dump_operation( key
, NULL
, "Open" );
828 if (key
->flags
& KEY_PREDEF
) set_error( STATUS_PREDEFINED_HANDLE
);
833 /* token must be the last path component at this point */
835 get_path_token( name
, &next
);
838 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
842 if ((key
->flags
& KEY_VOLATILE
) && !(options
& REG_OPTION_VOLATILE
))
844 set_error( STATUS_CHILD_MUST_BE_VOLATILE
);
849 if (!(key
= alloc_subkey( key
, &token
, index
, current_time
))) return NULL
;
851 if (options
& REG_OPTION_CREATE_LINK
) key
->flags
|= KEY_SYMLINK
;
852 if (options
& REG_OPTION_VOLATILE
) key
->flags
|= KEY_VOLATILE
;
853 else key
->flags
|= KEY_DIRTY
;
855 if (sd
) default_set_sd( &key
->obj
, sd
, OWNER_SECURITY_INFORMATION
| GROUP_SECURITY_INFORMATION
|
856 DACL_SECURITY_INFORMATION
| SACL_SECURITY_INFORMATION
);
858 if (debug_level
> 1) dump_operation( key
, NULL
, "Create" );
859 if (class && class->len
)
861 key
->classlen
= class->len
;
863 if (!(key
->class = memdup( class->str
, key
->classlen
))) key
->classlen
= 0;
865 touch_key( key
->parent
, REG_NOTIFY_CHANGE_NAME
);
870 /* recursively create a subkey (for internal use only) */
871 static struct key
*create_key_recursive( struct key
*key
, const struct unicode_str
*name
, timeout_t modif
)
875 struct unicode_str token
;
878 if (!get_path_token( name
, &token
)) return NULL
;
882 if (!(subkey
= find_subkey( key
, &token
, &index
))) break;
884 if (!(key
= follow_symlink( key
, 0 )))
886 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
889 get_path_token( name
, &token
);
894 if (!(key
= alloc_subkey( key
, &token
, index
, modif
))) return NULL
;
898 get_path_token( name
, &token
);
899 if (!token
.len
) break;
900 /* we know the index is always 0 in a new key */
901 if (!(key
= alloc_subkey( key
, &token
, 0, modif
)))
903 free_subkey( base
, index
);
913 /* query information about a key or a subkey */
914 static void enum_key( struct key
*key
, int index
, int info_class
, struct enum_key_reply
*reply
)
917 data_size_t len
, namelen
, classlen
;
918 data_size_t max_subkey
= 0, max_class
= 0;
919 data_size_t max_value
= 0, max_data
= 0;
920 WCHAR
*fullname
= NULL
;
923 if (key
->flags
& KEY_PREDEF
)
925 set_error( STATUS_INVALID_HANDLE
);
929 if (index
!= -1) /* -1 means use the specified key directly */
931 if ((index
< 0) || (index
> key
->last_subkey
))
933 set_error( STATUS_NO_MORE_ENTRIES
);
936 key
= key
->subkeys
[index
];
939 namelen
= key
->namelen
;
940 classlen
= key
->classlen
;
944 case KeyNameInformation
:
945 if (!(fullname
= key
->obj
.ops
->get_full_name( &key
->obj
, &namelen
))) return;
947 case KeyBasicInformation
:
948 classlen
= 0; /* only return the name */
950 case KeyNodeInformation
:
951 reply
->max_subkey
= 0;
952 reply
->max_class
= 0;
953 reply
->max_value
= 0;
956 case KeyFullInformation
:
957 case KeyCachedInformation
:
958 for (i
= 0; i
<= key
->last_subkey
; i
++)
960 if (key
->subkeys
[i
]->namelen
> max_subkey
) max_subkey
= key
->subkeys
[i
]->namelen
;
961 if (key
->subkeys
[i
]->classlen
> max_class
) max_class
= key
->subkeys
[i
]->classlen
;
963 for (i
= 0; i
<= key
->last_value
; i
++)
965 if (key
->values
[i
].namelen
> max_value
) max_value
= key
->values
[i
].namelen
;
966 if (key
->values
[i
].len
> max_data
) max_data
= key
->values
[i
].len
;
968 reply
->max_subkey
= max_subkey
;
969 reply
->max_class
= max_class
;
970 reply
->max_value
= max_value
;
971 reply
->max_data
= max_data
;
972 reply
->namelen
= namelen
;
973 if (info_class
== KeyCachedInformation
)
974 classlen
= 0; /* don't return any data, only its size */
975 namelen
= 0; /* don't return name */
978 set_error( STATUS_INVALID_PARAMETER
);
981 reply
->subkeys
= key
->last_subkey
+ 1;
982 reply
->values
= key
->last_value
+ 1;
983 reply
->modif
= key
->modif
;
984 reply
->total
= namelen
+ classlen
;
986 len
= min( reply
->total
, get_reply_max_size() );
987 if (len
&& (data
= set_reply_data_size( len
)))
991 reply
->namelen
= namelen
;
992 memcpy( data
, key
->name
, namelen
);
993 memcpy( data
+ namelen
, key
->class, len
- namelen
);
995 else if (info_class
== KeyNameInformation
)
997 reply
->namelen
= namelen
;
998 memcpy( data
, fullname
, len
);
1002 reply
->namelen
= len
;
1003 memcpy( data
, key
->name
, len
);
1007 if (debug_level
> 1) dump_operation( key
, NULL
, "Enum" );
1010 /* delete a key and its values */
1011 static int delete_key( struct key
*key
, int recurse
)
1014 struct key
*parent
= key
->parent
;
1016 /* must find parent and index */
1017 if (key
== root_key
)
1019 set_error( STATUS_ACCESS_DENIED
);
1024 if (key
->flags
& KEY_PREDEF
)
1026 set_error( STATUS_INVALID_HANDLE
);
1030 while (recurse
&& (key
->last_subkey
>=0))
1031 if (0 > delete_key(key
->subkeys
[key
->last_subkey
], 1))
1034 for (index
= 0; index
<= parent
->last_subkey
; index
++)
1035 if (parent
->subkeys
[index
] == key
) break;
1036 assert( index
<= parent
->last_subkey
);
1038 /* we can only delete a key that has no subkeys */
1039 if (key
->last_subkey
>= 0)
1041 set_error( STATUS_ACCESS_DENIED
);
1045 if (debug_level
> 1) dump_operation( key
, NULL
, "Delete" );
1046 free_subkey( parent
, index
);
1047 touch_key( parent
, REG_NOTIFY_CHANGE_NAME
);
1051 /* try to grow the array of values; return 1 if OK, 0 on error */
1052 static int grow_values( struct key
*key
)
1054 struct key_value
*new_val
;
1059 nb_values
= key
->nb_values
+ (key
->nb_values
/ 2); /* grow by 50% */
1060 if (!(new_val
= realloc( key
->values
, nb_values
* sizeof(*new_val
) )))
1062 set_error( STATUS_NO_MEMORY
);
1068 nb_values
= MIN_VALUES
;
1069 if (!(new_val
= mem_alloc( nb_values
* sizeof(*new_val
) ))) return 0;
1071 key
->values
= new_val
;
1072 key
->nb_values
= nb_values
;
1076 /* find the named value of a given key and return its index in the array */
1077 static struct key_value
*find_value( const struct key
*key
, const struct unicode_str
*name
, int *index
)
1079 int i
, min
, max
, res
;
1083 max
= key
->last_value
;
1086 i
= (min
+ max
) / 2;
1087 len
= min( key
->values
[i
].namelen
, name
->len
);
1088 res
= memicmp_strW( key
->values
[i
].name
, name
->str
, len
);
1089 if (!res
) res
= key
->values
[i
].namelen
- name
->len
;
1093 return &key
->values
[i
];
1095 if (res
> 0) max
= i
- 1;
1098 *index
= min
; /* this is where we should insert it */
1102 /* insert a new value; the index must have been returned by find_value */
1103 static struct key_value
*insert_value( struct key
*key
, const struct unicode_str
*name
, int index
)
1105 struct key_value
*value
;
1106 WCHAR
*new_name
= NULL
;
1109 if (name
->len
> MAX_VALUE_LEN
* sizeof(WCHAR
))
1111 set_error( STATUS_NAME_TOO_LONG
);
1114 if (key
->last_value
+ 1 == key
->nb_values
)
1116 if (!grow_values( key
)) return NULL
;
1118 if (name
->len
&& !(new_name
= memdup( name
->str
, name
->len
))) return NULL
;
1119 for (i
= ++key
->last_value
; i
> index
; i
--) key
->values
[i
] = key
->values
[i
- 1];
1120 value
= &key
->values
[index
];
1121 value
->name
= new_name
;
1122 value
->namelen
= name
->len
;
1128 /* set a key value */
1129 static void set_value( struct key
*key
, const struct unicode_str
*name
,
1130 int type
, const void *data
, data_size_t len
)
1132 struct key_value
*value
;
1136 if (key
->flags
& KEY_PREDEF
)
1138 set_error( STATUS_INVALID_HANDLE
);
1142 if ((value
= find_value( key
, name
, &index
)))
1144 /* check if the new value is identical to the existing one */
1145 if (value
->type
== type
&& value
->len
== len
&&
1146 value
->data
&& !memcmp( value
->data
, data
, len
))
1148 if (debug_level
> 1) dump_operation( key
, value
, "Skip setting" );
1153 if (key
->flags
& KEY_SYMLINK
)
1155 if (type
!= REG_LINK
|| name
->len
!= symlink_str
.len
||
1156 memicmp_strW( name
->str
, symlink_str
.str
, name
->len
))
1158 set_error( STATUS_ACCESS_DENIED
);
1163 if (len
&& !(ptr
= memdup( data
, len
))) return;
1167 if (!(value
= insert_value( key
, name
, index
)))
1173 else free( value
->data
); /* already existing, free previous data */
1178 touch_key( key
, REG_NOTIFY_CHANGE_LAST_SET
);
1179 if (debug_level
> 1) dump_operation( key
, value
, "Set" );
1182 /* get a key value */
1183 static void get_value( struct key
*key
, const struct unicode_str
*name
, int *type
, data_size_t
*len
)
1185 struct key_value
*value
;
1188 if (key
->flags
& KEY_PREDEF
)
1190 set_error( STATUS_INVALID_HANDLE
);
1194 if ((value
= find_value( key
, name
, &index
)))
1196 *type
= value
->type
;
1198 if (value
->data
) set_reply_data( value
->data
, min( value
->len
, get_reply_max_size() ));
1199 if (debug_level
> 1) dump_operation( key
, value
, "Get" );
1204 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
1208 /* enumerate a key value */
1209 static void enum_value( struct key
*key
, int i
, int info_class
, struct enum_key_value_reply
*reply
)
1211 struct key_value
*value
;
1213 if (key
->flags
& KEY_PREDEF
)
1215 set_error( STATUS_INVALID_HANDLE
);
1219 if (i
< 0 || i
> key
->last_value
) set_error( STATUS_NO_MORE_ENTRIES
);
1223 data_size_t namelen
, maxlen
;
1225 value
= &key
->values
[i
];
1226 reply
->type
= value
->type
;
1227 namelen
= value
->namelen
;
1231 case KeyValueBasicInformation
:
1232 reply
->total
= namelen
;
1234 case KeyValueFullInformation
:
1235 reply
->total
= namelen
+ value
->len
;
1237 case KeyValuePartialInformation
:
1238 reply
->total
= value
->len
;
1242 set_error( STATUS_INVALID_PARAMETER
);
1246 maxlen
= min( reply
->total
, get_reply_max_size() );
1247 if (maxlen
&& ((data
= set_reply_data_size( maxlen
))))
1249 if (maxlen
> namelen
)
1251 reply
->namelen
= namelen
;
1252 memcpy( data
, value
->name
, namelen
);
1253 memcpy( (char *)data
+ namelen
, value
->data
, maxlen
- namelen
);
1257 reply
->namelen
= maxlen
;
1258 memcpy( data
, value
->name
, maxlen
);
1261 if (debug_level
> 1) dump_operation( key
, value
, "Enum" );
1265 /* delete a value */
1266 static void delete_value( struct key
*key
, const struct unicode_str
*name
)
1268 struct key_value
*value
;
1269 int i
, index
, nb_values
;
1271 if (key
->flags
& KEY_PREDEF
)
1273 set_error( STATUS_INVALID_HANDLE
);
1277 if (!(value
= find_value( key
, name
, &index
)))
1279 set_error( STATUS_OBJECT_NAME_NOT_FOUND
);
1282 if (debug_level
> 1) dump_operation( key
, value
, "Delete" );
1283 free( value
->name
);
1284 free( value
->data
);
1285 for (i
= index
; i
< key
->last_value
; i
++) key
->values
[i
] = key
->values
[i
+ 1];
1287 touch_key( key
, REG_NOTIFY_CHANGE_LAST_SET
);
1289 /* try to shrink the array */
1290 nb_values
= key
->nb_values
;
1291 if (nb_values
> MIN_VALUES
&& key
->last_value
< nb_values
/ 2)
1293 struct key_value
*new_val
;
1294 nb_values
-= nb_values
/ 3; /* shrink by 33% */
1295 if (nb_values
< MIN_VALUES
) nb_values
= MIN_VALUES
;
1296 if (!(new_val
= realloc( key
->values
, nb_values
* sizeof(*new_val
) ))) return;
1297 key
->values
= new_val
;
1298 key
->nb_values
= nb_values
;
1302 /* get the registry key corresponding to an hkey handle */
1303 static struct key
*get_hkey_obj( obj_handle_t hkey
, unsigned int access
)
1305 struct key
*key
= (struct key
*)get_handle_obj( current
->process
, hkey
, access
, &key_ops
);
1307 if (key
&& key
->flags
& KEY_DELETED
)
1309 set_error( STATUS_KEY_DELETED
);
1310 release_object( key
);
1316 /* get the registry key corresponding to a parent key handle */
1317 static inline struct key
*get_parent_hkey_obj( obj_handle_t hkey
)
1319 if (!hkey
) return (struct key
*)grab_object( root_key
);
1320 return get_hkey_obj( hkey
, 0 );
1323 /* read a line from the input file */
1324 static int read_next_line( struct file_load_info
*info
)
1327 int newlen
, pos
= 0;
1332 if (!fgets( info
->buffer
+ pos
, info
->len
- pos
, info
->file
))
1333 return (pos
!= 0); /* EOF */
1334 pos
= strlen(info
->buffer
);
1335 if (info
->buffer
[pos
-1] == '\n')
1337 /* got a full line */
1338 info
->buffer
[--pos
] = 0;
1339 if (pos
> 0 && info
->buffer
[pos
-1] == '\r') info
->buffer
[pos
-1] = 0;
1342 if (pos
< info
->len
- 1) return 1; /* EOF but something was read */
1344 /* need to enlarge the buffer */
1345 newlen
= info
->len
+ info
->len
/ 2;
1346 if (!(newbuf
= realloc( info
->buffer
, newlen
)))
1348 set_error( STATUS_NO_MEMORY
);
1351 info
->buffer
= newbuf
;
1356 /* make sure the temp buffer holds enough space */
1357 static int get_file_tmp_space( struct file_load_info
*info
, size_t size
)
1360 if (info
->tmplen
>= size
) return 1;
1361 if (!(tmp
= realloc( info
->tmp
, size
)))
1363 set_error( STATUS_NO_MEMORY
);
1367 info
->tmplen
= size
;
1371 /* report an error while loading an input file */
1372 static void file_read_error( const char *err
, struct file_load_info
*info
)
1375 fprintf( stderr
, "%s:%d: %s '%s'\n", info
->filename
, info
->line
, err
, info
->buffer
);
1377 fprintf( stderr
, "<fd>:%d: %s '%s'\n", info
->line
, err
, info
->buffer
);
1380 /* convert a data type tag to a value type */
1381 static int get_data_type( const char *buffer
, int *type
, int *parse_type
)
1383 struct data_type
{ const char *tag
; int len
; int type
; int parse_type
; };
1385 static const struct data_type data_types
[] =
1386 { /* actual type */ /* type to assume for parsing */
1387 { "\"", 1, REG_SZ
, REG_SZ
},
1388 { "str:\"", 5, REG_SZ
, REG_SZ
},
1389 { "str(2):\"", 8, REG_EXPAND_SZ
, REG_SZ
},
1390 { "str(7):\"", 8, REG_MULTI_SZ
, REG_SZ
},
1391 { "hex:", 4, REG_BINARY
, REG_BINARY
},
1392 { "dword:", 6, REG_DWORD
, REG_DWORD
},
1393 { "hex(", 4, -1, REG_BINARY
},
1397 const struct data_type
*ptr
;
1400 for (ptr
= data_types
; ptr
->tag
; ptr
++)
1402 if (strncmp( ptr
->tag
, buffer
, ptr
->len
)) continue;
1403 *parse_type
= ptr
->parse_type
;
1404 if ((*type
= ptr
->type
) != -1) return ptr
->len
;
1405 /* "hex(xx):" is special */
1406 *type
= (int)strtoul( buffer
+ 4, &end
, 16 );
1407 if ((end
<= buffer
) || strncmp( end
, "):", 2 )) return 0;
1408 return end
+ 2 - buffer
;
1413 /* load and create a key from the input file */
1414 static struct key
*load_key( struct key
*base
, const char *buffer
, int prefix_len
,
1415 struct file_load_info
*info
, timeout_t
*modif
)
1418 struct unicode_str name
;
1423 if (!get_file_tmp_space( info
, strlen(buffer
) * sizeof(WCHAR
) )) return NULL
;
1426 if ((res
= parse_strW( info
->tmp
, &len
, buffer
, ']' )) == -1)
1428 file_read_error( "Malformed key", info
);
1431 if (sscanf( buffer
+ res
, " %u", &mod
) == 1)
1432 *modif
= (timeout_t
)mod
* TICKS_PER_SEC
+ ticks_1601_to_1970
;
1434 *modif
= current_time
;
1437 while (prefix_len
&& *p
) { if (*p
++ == '\\') prefix_len
--; }
1443 file_read_error( "Malformed key", info
);
1446 /* empty key name, return base key */
1447 return (struct key
*)grab_object( base
);
1450 name
.len
= len
- (p
- info
->tmp
+ 1) * sizeof(WCHAR
);
1451 return create_key_recursive( base
, &name
, 0 );
1454 /* update the modification time of a key (and its parents) after it has been loaded from a file */
1455 static void update_key_time( struct key
*key
, timeout_t modif
)
1457 while (key
&& !key
->modif
)
1464 /* load a global option from the input file */
1465 static int load_global_option( const char *buffer
, struct file_load_info
*info
)
1469 if (!strncmp( buffer
, "#arch=", 6 ))
1471 enum prefix_type type
;
1473 if (!strcmp( p
, "win32" )) type
= PREFIX_32BIT
;
1474 else if (!strcmp( p
, "win64" )) type
= PREFIX_64BIT
;
1477 file_read_error( "Unknown architecture", info
);
1478 set_error( STATUS_NOT_REGISTRY_FILE
);
1481 if (prefix_type
== PREFIX_UNKNOWN
) prefix_type
= type
;
1482 else if (type
!= prefix_type
)
1484 file_read_error( "Mismatched architecture", info
);
1485 set_error( STATUS_NOT_REGISTRY_FILE
);
1489 /* ignore unknown options */
1493 /* load a key option from the input file */
1494 static int load_key_option( struct key
*key
, const char *buffer
, struct file_load_info
*info
)
1499 if (!strncmp( buffer
, "#time=", 6 ))
1501 timeout_t modif
= 0;
1502 for (p
= buffer
+ 6; *p
; p
++)
1504 if (*p
>= '0' && *p
<= '9') modif
= (modif
<< 4) | (*p
- '0');
1505 else if (*p
>= 'A' && *p
<= 'F') modif
= (modif
<< 4) | (*p
- 'A' + 10);
1506 else if (*p
>= 'a' && *p
<= 'f') modif
= (modif
<< 4) | (*p
- 'a' + 10);
1509 update_key_time( key
, modif
);
1511 if (!strncmp( buffer
, "#class=", 7 ))
1514 if (*p
++ != '"') return 0;
1515 if (!get_file_tmp_space( info
, strlen(p
) * sizeof(WCHAR
) )) return 0;
1517 if (parse_strW( info
->tmp
, &len
, p
, '\"' ) == -1) return 0;
1519 if (!(key
->class = memdup( info
->tmp
, len
))) len
= 0;
1520 key
->classlen
= len
;
1522 if (!strncmp( buffer
, "#link", 5 )) key
->flags
|= KEY_SYMLINK
;
1523 /* ignore unknown options */
1527 /* parse a comma-separated list of hex digits */
1528 static int parse_hex( unsigned char *dest
, data_size_t
*len
, const char *buffer
)
1530 const char *p
= buffer
;
1531 data_size_t count
= 0;
1534 while (isxdigit(*p
))
1536 unsigned int val
= strtoul( p
, &end
, 16 );
1537 if (end
== p
|| val
> 0xff) return -1;
1538 if (count
++ >= *len
) return -1; /* dest buffer overflow */
1541 while (isspace(*p
)) p
++;
1543 while (isspace(*p
)) p
++;
1549 /* parse a value name and create the corresponding value */
1550 static struct key_value
*parse_value_name( struct key
*key
, const char *buffer
, data_size_t
*len
,
1551 struct file_load_info
*info
)
1553 struct key_value
*value
;
1554 struct unicode_str name
;
1557 if (!get_file_tmp_space( info
, strlen(buffer
) * sizeof(WCHAR
) )) return NULL
;
1558 name
.str
= info
->tmp
;
1559 name
.len
= info
->tmplen
;
1560 if (buffer
[0] == '@')
1567 int r
= parse_strW( info
->tmp
, &name
.len
, buffer
+ 1, '\"' );
1568 if (r
== -1) goto error
;
1569 *len
= r
+ 1; /* for initial quote */
1570 name
.len
-= sizeof(WCHAR
); /* terminating null */
1572 while (isspace(buffer
[*len
])) (*len
)++;
1573 if (buffer
[*len
] != '=') goto error
;
1575 while (isspace(buffer
[*len
])) (*len
)++;
1576 if (!(value
= find_value( key
, &name
, &index
))) value
= insert_value( key
, &name
, index
);
1580 file_read_error( "Malformed value name", info
);
1584 /* load a value from the input file */
1585 static int load_value( struct key
*key
, const char *buffer
, struct file_load_info
*info
)
1589 int res
, type
, parse_type
;
1590 data_size_t maxlen
, len
;
1591 struct key_value
*value
;
1593 if (!(value
= parse_value_name( key
, buffer
, &len
, info
))) return 0;
1594 if (!(res
= get_data_type( buffer
+ len
, &type
, &parse_type
))) goto error
;
1595 buffer
+= len
+ res
;
1600 if (!get_file_tmp_space( info
, strlen(buffer
) * sizeof(WCHAR
) )) return 0;
1602 if ((res
= parse_strW( info
->tmp
, &len
, buffer
, '\"' )) == -1) goto error
;
1606 dw
= strtoul( buffer
, NULL
, 16 );
1610 case REG_BINARY
: /* hex digits */
1614 maxlen
= 1 + strlen(buffer
) / 2; /* at least 2 chars for one hex byte */
1615 if (!get_file_tmp_space( info
, len
+ maxlen
)) return 0;
1616 if ((res
= parse_hex( (unsigned char *)info
->tmp
+ len
, &maxlen
, buffer
)) == -1) goto error
;
1619 while (isspace(*buffer
)) buffer
++;
1620 if (!*buffer
) break;
1621 if (*buffer
!= '\\') goto error
;
1622 if (read_next_line( info
) != 1) goto error
;
1623 buffer
= info
->buffer
;
1624 while (isspace(*buffer
)) buffer
++;
1630 ptr
= NULL
; /* keep compiler quiet */
1634 if (!len
) newptr
= NULL
;
1635 else if (!(newptr
= memdup( ptr
, len
))) return 0;
1637 free( value
->data
);
1638 value
->data
= newptr
;
1644 file_read_error( "Malformed value", info
);
1645 free( value
->data
);
1648 value
->type
= REG_NONE
;
1652 /* return the length (in path elements) of name that is part of the key name */
1653 /* for instance if key is USER\foo\bar and name is foo\bar\baz, return 2 */
1654 static int get_prefix_len( struct key
*key
, const char *name
, struct file_load_info
*info
)
1660 if (!get_file_tmp_space( info
, strlen(name
) * sizeof(WCHAR
) )) return 0;
1663 if ((res
= parse_strW( info
->tmp
, &len
, name
, ']' )) == -1)
1665 file_read_error( "Malformed key", info
);
1668 for (p
= info
->tmp
; *p
; p
++) if (*p
== '\\') break;
1669 len
= (p
- info
->tmp
) * sizeof(WCHAR
);
1670 for (res
= 1; key
!= root_key
; res
++)
1672 if (len
== key
->namelen
&& !memicmp_strW( info
->tmp
, key
->name
, len
)) break;
1675 if (key
== root_key
) res
= 0; /* no matching name */
1679 /* load all the keys from the input file */
1680 /* prefix_len is the number of key name prefixes to skip, or -1 for autodetection */
1681 static void load_keys( struct key
*key
, const char *filename
, FILE *f
, int prefix_len
)
1683 struct key
*subkey
= NULL
;
1684 struct file_load_info info
;
1685 timeout_t modif
= current_time
;
1688 info
.filename
= filename
;
1693 if (!(info
.buffer
= mem_alloc( info
.len
))) return;
1694 if (!(info
.tmp
= mem_alloc( info
.tmplen
)))
1696 free( info
.buffer
);
1700 if ((read_next_line( &info
) != 1) ||
1701 strcmp( info
.buffer
, "WINE REGISTRY Version 2" ))
1703 set_error( STATUS_NOT_REGISTRY_FILE
);
1707 while (read_next_line( &info
) == 1)
1710 while (*p
&& isspace(*p
)) p
++;
1713 case '[': /* new key */
1716 update_key_time( subkey
, modif
);
1717 release_object( subkey
);
1719 if (prefix_len
== -1) prefix_len
= get_prefix_len( key
, p
+ 1, &info
);
1720 if (!(subkey
= load_key( key
, p
+ 1, prefix_len
, &info
, &modif
)))
1721 file_read_error( "Error creating key", &info
);
1723 case '@': /* default value */
1724 case '\"': /* value */
1725 if (subkey
) load_value( subkey
, p
, &info
);
1726 else file_read_error( "Value without key", &info
);
1728 case '#': /* option */
1729 if (subkey
) load_key_option( subkey
, p
, &info
);
1730 else if (!load_global_option( p
, &info
)) goto done
;
1732 case ';': /* comment */
1733 case 0: /* empty line */
1736 file_read_error( "Unrecognized input", &info
);
1744 update_key_time( subkey
, modif
);
1745 release_object( subkey
);
1747 free( info
.buffer
);
1751 /* load a part of the registry from a file */
1752 static void load_registry( struct key
*key
, obj_handle_t handle
)
1757 if (!(file
= get_file_obj( current
->process
, handle
, FILE_READ_DATA
))) return;
1758 fd
= dup( get_file_unix_fd( file
) );
1759 release_object( file
);
1762 FILE *f
= fdopen( fd
, "r" );
1765 load_keys( key
, NULL
, f
, -1 );
1768 else file_set_error();
1772 /* load one of the initial registry files */
1773 static int load_init_registry_from_file( const char *filename
, struct key
*key
)
1777 if ((f
= fopen( filename
, "r" )))
1779 load_keys( key
, filename
, f
, 0 );
1781 if (get_error() == STATUS_NOT_REGISTRY_FILE
)
1783 fprintf( stderr
, "%s is not a valid registry file\n", filename
);
1788 assert( save_branch_count
< MAX_SAVE_BRANCH_INFO
);
1790 save_branch_info
[save_branch_count
].path
= filename
;
1791 save_branch_info
[save_branch_count
++].key
= (struct key
*)grab_object( key
);
1792 make_object_permanent( &key
->obj
);
1796 static WCHAR
*format_user_registry_path( const struct sid
*sid
, struct unicode_str
*path
)
1798 char buffer
[7 + 11 + 11 + 11 * ARRAY_SIZE(sid
->sub_auth
)], *p
= buffer
;
1801 p
+= sprintf( p
, "User\\S-%u-%u", sid
->revision
,
1802 ((unsigned int)sid
->id_auth
[2] << 24) |
1803 ((unsigned int)sid
->id_auth
[3] << 16) |
1804 ((unsigned int)sid
->id_auth
[4] << 8) |
1805 ((unsigned int)sid
->id_auth
[5]) );
1806 for (i
= 0; i
< sid
->sub_count
; i
++) p
+= sprintf( p
, "-%u", sid
->sub_auth
[i
] );
1807 return ascii_to_unicode_str( buffer
, path
);
1810 static void init_supported_machines(void)
1812 unsigned int count
= 0;
1814 if (prefix_type
== PREFIX_32BIT
) supported_machines
[count
++] = IMAGE_FILE_MACHINE_I386
;
1815 #elif defined(__x86_64__)
1816 if (prefix_type
== PREFIX_64BIT
) supported_machines
[count
++] = IMAGE_FILE_MACHINE_AMD64
;
1817 supported_machines
[count
++] = IMAGE_FILE_MACHINE_I386
;
1818 #elif defined(__arm__)
1819 if (prefix_type
== PREFIX_32BIT
) supported_machines
[count
++] = IMAGE_FILE_MACHINE_ARMNT
;
1820 #elif defined(__aarch64__)
1821 if (prefix_type
== PREFIX_64BIT
)
1823 supported_machines
[count
++] = IMAGE_FILE_MACHINE_ARM64
;
1824 supported_machines
[count
++] = IMAGE_FILE_MACHINE_I386
;
1826 supported_machines
[count
++] = IMAGE_FILE_MACHINE_ARMNT
;
1828 #error Unsupported machine
1830 supported_machines_count
= count
;
1831 native_machine
= supported_machines
[0];
1834 /* registry initialisation */
1835 void init_registry(void)
1837 static const WCHAR HKLM
[] = { 'M','a','c','h','i','n','e' };
1838 static const WCHAR HKU_default
[] = { 'U','s','e','r','\\','.','D','e','f','a','u','l','t' };
1839 static const WCHAR classes_i386
[] = {'S','o','f','t','w','a','r','e','\\',
1840 'C','l','a','s','s','e','s','\\',
1841 'W','o','w','6','4','3','2','N','o','d','e'};
1842 static const WCHAR classes_amd64
[] = {'S','o','f','t','w','a','r','e','\\',
1843 'C','l','a','s','s','e','s','\\',
1844 'W','o','w','6','4','6','4','N','o','d','e'};
1845 static const WCHAR classes_arm
[] = {'S','o','f','t','w','a','r','e','\\',
1846 'C','l','a','s','s','e','s','\\',
1847 'W','o','w','A','A','3','2','N','o','d','e'};
1848 static const WCHAR classes_arm64
[] = {'S','o','f','t','w','a','r','e','\\',
1849 'C','l','a','s','s','e','s','\\',
1850 'W','o','w','A','A','6','4','N','o','d','e'};
1851 static const WCHAR perflib
[] = {'S','o','f','t','w','a','r','e','\\',
1852 'M','i','c','r','o','s','o','f','t','\\',
1853 'W','i','n','d','o','w','s',' ','N','T','\\',
1854 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1855 'P','e','r','f','l','i','b','\\',
1857 static const struct unicode_str root_name
= { NULL
, 0 };
1858 static const struct unicode_str HKLM_name
= { HKLM
, sizeof(HKLM
) };
1859 static const struct unicode_str HKU_name
= { HKU_default
, sizeof(HKU_default
) };
1860 static const struct unicode_str perflib_name
= { perflib
, sizeof(perflib
) };
1862 WCHAR
*current_user_path
;
1863 struct unicode_str current_user_str
;
1864 struct key
*key
, *hklm
, *hkcu
;
1868 /* switch to the config dir */
1870 if (fchdir( config_dir_fd
) == -1) fatal_error( "chdir to config dir: %s\n", strerror( errno
));
1872 /* create the root key */
1873 root_key
= alloc_key( &root_name
, current_time
);
1875 make_object_permanent( &root_key
->obj
);
1877 /* load system.reg into Registry\Machine */
1879 if (!(hklm
= create_key_recursive( root_key
, &HKLM_name
, current_time
)))
1880 fatal_error( "could not create Machine registry key\n" );
1882 if (!load_init_registry_from_file( "system.reg", hklm
))
1884 if ((p
= getenv( "WINEARCH" )) && !strcmp( p
, "win32" ))
1885 prefix_type
= PREFIX_32BIT
;
1887 prefix_type
= sizeof(void *) > sizeof(int) ? PREFIX_64BIT
: PREFIX_32BIT
;
1889 else if (prefix_type
== PREFIX_UNKNOWN
)
1890 prefix_type
= PREFIX_32BIT
;
1892 init_supported_machines();
1894 /* load userdef.reg into Registry\User\.Default */
1896 if (!(key
= create_key_recursive( root_key
, &HKU_name
, current_time
)))
1897 fatal_error( "could not create User\\.Default registry key\n" );
1899 load_init_registry_from_file( "userdef.reg", key
);
1900 release_object( key
);
1902 /* load user.reg into HKEY_CURRENT_USER */
1904 /* FIXME: match default user in token.c. should get from process token instead */
1905 current_user_path
= format_user_registry_path( &local_user_sid
, ¤t_user_str
);
1906 if (!current_user_path
||
1907 !(hkcu
= create_key_recursive( root_key
, ¤t_user_str
, current_time
)))
1908 fatal_error( "could not create HKEY_CURRENT_USER registry key\n" );
1909 free( current_user_path
);
1910 load_init_registry_from_file( "user.reg", hkcu
);
1912 /* set the shared flag on Software\Classes\Wow6432Node for all platforms */
1913 for (i
= 1; i
< supported_machines_count
; i
++)
1915 struct unicode_str name
;
1917 switch (supported_machines
[i
])
1919 case IMAGE_FILE_MACHINE_I386
: name
.str
= classes_i386
; name
.len
= sizeof(classes_i386
); break;
1920 case IMAGE_FILE_MACHINE_ARMNT
: name
.str
= classes_arm
; name
.len
= sizeof(classes_arm
); break;
1921 case IMAGE_FILE_MACHINE_AMD64
: name
.str
= classes_amd64
; name
.len
= sizeof(classes_amd64
); break;
1922 case IMAGE_FILE_MACHINE_ARM64
: name
.str
= classes_arm64
; name
.len
= sizeof(classes_arm64
); break;
1924 if ((key
= create_key_recursive( hklm
, &name
, current_time
)))
1926 key
->flags
|= KEY_WOWSHARE
;
1927 release_object( key
);
1929 /* FIXME: handle HKCU too */
1932 if ((key
= create_key_recursive( hklm
, &perflib_name
, current_time
)))
1934 key
->flags
|= KEY_PREDEF
;
1935 release_object( key
);
1938 release_object( hklm
);
1939 release_object( hkcu
);
1941 /* start the periodic save timer */
1942 set_periodic_save_timer();
1944 /* create windows directories */
1946 if (!mkdir( "drive_c/windows", 0777 ))
1948 mkdir( "drive_c/windows/system32", 0777 );
1949 for (i
= 1; i
< supported_machines_count
; i
++)
1951 switch (supported_machines
[i
])
1953 case IMAGE_FILE_MACHINE_I386
: mkdir( "drive_c/windows/syswow64", 0777 ); break;
1954 case IMAGE_FILE_MACHINE_ARMNT
: mkdir( "drive_c/windows/sysarm32", 0777 ); break;
1955 case IMAGE_FILE_MACHINE_AMD64
: mkdir( "drive_c/windows/sysx8664", 0777 ); break;
1956 case IMAGE_FILE_MACHINE_ARM64
: mkdir( "drive_c/windows/sysarm64", 0777 ); break;
1961 /* go back to the server dir */
1962 if (fchdir( server_dir_fd
) == -1) fatal_error( "chdir to server dir: %s\n", strerror( errno
));
1965 /* save a registry branch to a file */
1966 static void save_all_subkeys( struct key
*key
, FILE *f
)
1968 fprintf( f
, "WINE REGISTRY Version 2\n" );
1969 fprintf( f
, ";; All keys relative to " );
1970 dump_path( key
, NULL
, f
);
1972 switch (prefix_type
)
1975 fprintf( f
, "\n#arch=win32\n" );
1978 fprintf( f
, "\n#arch=win64\n" );
1983 save_subkeys( key
, key
, f
);
1986 /* save a registry branch to a file handle */
1987 static void save_registry( struct key
*key
, obj_handle_t handle
)
1992 if (!(file
= get_file_obj( current
->process
, handle
, FILE_WRITE_DATA
))) return;
1993 fd
= dup( get_file_unix_fd( file
) );
1994 release_object( file
);
1997 FILE *f
= fdopen( fd
, "w" );
2000 save_all_subkeys( key
, f
);
2001 if (fclose( f
)) file_set_error();
2011 /* save a registry branch to a file */
2012 static int save_branch( struct key
*key
, const char *path
)
2015 char *p
, *tmp
= NULL
;
2016 int fd
, count
= 0, ret
= 0;
2019 if (!(key
->flags
& KEY_DIRTY
))
2021 if (debug_level
> 1) dump_operation( key
, NULL
, "Not saving clean" );
2025 /* test the file type */
2027 if ((fd
= open( path
, O_WRONLY
)) != -1)
2029 /* if file is not a regular file or has multiple links or is accessed
2030 * via symbolic links, write directly into it; otherwise use a temp file */
2031 if (!lstat( path
, &st
) && (!S_ISREG(st
.st_mode
) || st
.st_nlink
> 1))
2039 /* create a temp file in the same directory */
2041 if (!(tmp
= malloc( strlen(path
) + 20 ))) goto done
;
2042 strcpy( tmp
, path
);
2043 if ((p
= strrchr( tmp
, '/' ))) p
++;
2047 sprintf( p
, "reg%lx%04x.tmp", (long) getpid(), count
++ );
2048 if ((fd
= open( tmp
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666 )) != -1) break;
2049 if (errno
!= EEXIST
) goto done
;
2053 /* now save to it */
2056 if (!(f
= fdopen( fd
, "w" )))
2058 if (tmp
) unlink( tmp
);
2063 if (debug_level
> 1)
2065 fprintf( stderr
, "%s: ", path
);
2066 dump_operation( key
, NULL
, "saving" );
2069 save_all_subkeys( key
, f
);
2074 /* if successfully written, rename to final name */
2075 if (ret
) ret
= !rename( tmp
, path
);
2076 if (!ret
) unlink( tmp
);
2081 if (ret
) make_clean( key
);
2085 /* periodic saving of the registry */
2086 static void periodic_save( void *arg
)
2090 if (fchdir( config_dir_fd
) == -1) return;
2091 save_timeout_user
= NULL
;
2092 for (i
= 0; i
< save_branch_count
; i
++)
2093 save_branch( save_branch_info
[i
].key
, save_branch_info
[i
].path
);
2094 if (fchdir( server_dir_fd
) == -1) fatal_error( "chdir to server dir: %s\n", strerror( errno
));
2095 set_periodic_save_timer();
2098 /* start the periodic save timer */
2099 static void set_periodic_save_timer(void)
2101 if (save_timeout_user
) remove_timeout_user( save_timeout_user
);
2102 save_timeout_user
= add_timeout_user( save_period
, periodic_save
, NULL
);
2105 /* save the modified registry branches to disk */
2106 void flush_registry(void)
2110 if (fchdir( config_dir_fd
) == -1) return;
2111 for (i
= 0; i
< save_branch_count
; i
++)
2113 if (!save_branch( save_branch_info
[i
].key
, save_branch_info
[i
].path
))
2115 fprintf( stderr
, "wineserver: could not save registry branch to %s",
2116 save_branch_info
[i
].path
);
2120 if (fchdir( server_dir_fd
) == -1) fatal_error( "chdir to server dir: %s\n", strerror( errno
));
2123 /* determine if the thread is wow64 (32-bit client running on 64-bit prefix) */
2124 static int is_wow64_thread( struct thread
*thread
)
2126 return (is_machine_64bit( native_machine
) && !is_machine_64bit( thread
->process
->machine
));
2130 /* create a registry key */
2131 DECL_HANDLER(create_key
)
2133 struct key
*key
= NULL
, *parent
;
2134 struct unicode_str name
, class;
2135 unsigned int access
= req
->access
;
2136 const struct security_descriptor
*sd
;
2137 const struct object_attributes
*objattr
= get_req_object_attributes( &sd
, &name
, NULL
);
2139 if (!objattr
) return;
2141 if (!is_wow64_thread( current
)) access
= (access
& ~KEY_WOW64_32KEY
) | KEY_WOW64_64KEY
;
2143 class.str
= get_req_data_after_objattr( objattr
, &class.len
);
2144 class.len
= (class.len
/ sizeof(WCHAR
)) * sizeof(WCHAR
);
2146 if (!objattr
->rootdir
&& name
.len
>= sizeof(root_name
) &&
2147 !memicmp_strW( name
.str
, root_name
, sizeof(root_name
) ))
2149 name
.str
+= ARRAY_SIZE( root_name
);
2150 name
.len
-= sizeof(root_name
);
2153 /* NOTE: no access rights are required from the parent handle to create a key */
2154 if ((parent
= get_parent_hkey_obj( objattr
->rootdir
)))
2156 if ((key
= create_key( parent
, &name
, &class, req
->options
, access
,
2157 objattr
->attributes
, sd
, &reply
->created
)))
2159 reply
->hkey
= alloc_handle( current
->process
, key
, access
, objattr
->attributes
);
2160 release_object( key
);
2162 release_object( parent
);
2166 /* open a registry key */
2167 DECL_HANDLER(open_key
)
2169 struct key
*key
, *parent
;
2170 struct unicode_str name
;
2171 unsigned int access
= req
->access
;
2173 if (!is_wow64_thread( current
)) access
= (access
& ~KEY_WOW64_32KEY
) | KEY_WOW64_64KEY
;
2176 /* NOTE: no access rights are required to open the parent key, only the child key */
2177 if ((parent
= get_parent_hkey_obj( req
->parent
)))
2179 get_req_path( &name
, !req
->parent
);
2180 if ((key
= open_key( parent
, &name
, access
, req
->attributes
)))
2182 reply
->hkey
= alloc_handle( current
->process
, key
, access
, req
->attributes
);
2183 release_object( key
);
2185 release_object( parent
);
2189 /* delete a registry key */
2190 DECL_HANDLER(delete_key
)
2194 if ((key
= get_hkey_obj( req
->hkey
, DELETE
)))
2196 delete_key( key
, 0);
2197 release_object( key
);
2201 /* flush a registry key */
2202 DECL_HANDLER(flush_key
)
2204 struct key
*key
= get_hkey_obj( req
->hkey
, 0 );
2207 /* we don't need to do anything here with the current implementation */
2208 release_object( key
);
2212 /* enumerate registry subkeys */
2213 DECL_HANDLER(enum_key
)
2217 if ((key
= get_hkey_obj( req
->hkey
,
2218 req
->index
== -1 ? KEY_QUERY_VALUE
: KEY_ENUMERATE_SUB_KEYS
)))
2220 enum_key( key
, req
->index
, req
->info_class
, reply
);
2221 release_object( key
);
2225 /* set a value of a registry key */
2226 DECL_HANDLER(set_key_value
)
2229 struct unicode_str name
;
2231 if (req
->namelen
> get_req_data_size())
2233 set_error( STATUS_INVALID_PARAMETER
);
2236 name
.str
= get_req_data();
2237 name
.len
= (req
->namelen
/ sizeof(WCHAR
)) * sizeof(WCHAR
);
2239 if ((key
= get_hkey_obj( req
->hkey
, KEY_SET_VALUE
)))
2241 data_size_t datalen
= get_req_data_size() - req
->namelen
;
2242 const char *data
= (const char *)get_req_data() + req
->namelen
;
2244 set_value( key
, &name
, req
->type
, data
, datalen
);
2245 release_object( key
);
2249 /* retrieve the value of a registry key */
2250 DECL_HANDLER(get_key_value
)
2253 struct unicode_str name
= get_req_unicode_str();
2256 if ((key
= get_hkey_obj( req
->hkey
, KEY_QUERY_VALUE
)))
2258 get_value( key
, &name
, &reply
->type
, &reply
->total
);
2259 release_object( key
);
2263 /* enumerate the value of a registry key */
2264 DECL_HANDLER(enum_key_value
)
2268 if ((key
= get_hkey_obj( req
->hkey
, KEY_QUERY_VALUE
)))
2270 enum_value( key
, req
->index
, req
->info_class
, reply
);
2271 release_object( key
);
2275 /* delete a value of a registry key */
2276 DECL_HANDLER(delete_key_value
)
2279 struct unicode_str name
= get_req_unicode_str();
2281 if ((key
= get_hkey_obj( req
->hkey
, KEY_SET_VALUE
)))
2283 delete_value( key
, &name
);
2284 release_object( key
);
2288 /* load a registry branch from a file */
2289 DECL_HANDLER(load_registry
)
2291 struct key
*key
, *parent
;
2292 struct unicode_str name
;
2293 const struct security_descriptor
*sd
;
2294 const struct object_attributes
*objattr
= get_req_object_attributes( &sd
, &name
, NULL
);
2296 if (!objattr
) return;
2298 if (!thread_single_check_privilege( current
, SeRestorePrivilege
))
2300 set_error( STATUS_PRIVILEGE_NOT_HELD
);
2304 if (!objattr
->rootdir
&& name
.len
>= sizeof(root_name
) &&
2305 !memicmp_strW( name
.str
, root_name
, sizeof(root_name
) ))
2307 name
.str
+= ARRAY_SIZE( root_name
);
2308 name
.len
-= sizeof(root_name
);
2311 if ((parent
= get_parent_hkey_obj( objattr
->rootdir
)))
2314 if ((key
= create_key( parent
, &name
, NULL
, 0, KEY_WOW64_64KEY
, 0, sd
, &dummy
)))
2316 load_registry( key
, req
->file
);
2317 release_object( key
);
2319 release_object( parent
);
2323 DECL_HANDLER(unload_registry
)
2325 struct key
*key
, *parent
;
2326 struct unicode_str name
;
2327 unsigned int access
= 0;
2329 if (!thread_single_check_privilege( current
, SeRestorePrivilege
))
2331 set_error( STATUS_PRIVILEGE_NOT_HELD
);
2335 if (!is_wow64_thread( current
)) access
= (access
& ~KEY_WOW64_32KEY
) | KEY_WOW64_64KEY
;
2337 if ((parent
= get_parent_hkey_obj( req
->parent
)))
2339 get_req_path( &name
, !req
->parent
);
2340 if ((key
= open_key( parent
, &name
, access
, req
->attributes
)))
2342 if (key
->obj
.handle_count
)
2343 set_error( STATUS_CANNOT_DELETE
);
2345 delete_key( key
, 1 ); /* FIXME */
2346 release_object( key
);
2348 release_object( parent
);
2352 /* save a registry branch to a file */
2353 DECL_HANDLER(save_registry
)
2357 if (!thread_single_check_privilege( current
, SeBackupPrivilege
))
2359 set_error( STATUS_PRIVILEGE_NOT_HELD
);
2363 if ((key
= get_hkey_obj( req
->hkey
, 0 )))
2365 save_registry( key
, req
->file
);
2366 release_object( key
);
2370 /* add a registry key change notification */
2371 DECL_HANDLER(set_registry_notification
)
2374 struct event
*event
;
2375 struct notify
*notify
;
2377 key
= get_hkey_obj( req
->hkey
, KEY_NOTIFY
);
2380 event
= get_event_obj( current
->process
, req
->event
, SYNCHRONIZE
);
2383 notify
= find_notify( key
, current
->process
, req
->hkey
);
2386 notify
= mem_alloc( sizeof(*notify
) );
2389 notify
->events
= NULL
;
2390 notify
->event_count
= 0;
2391 notify
->subtree
= req
->subtree
;
2392 notify
->filter
= req
->filter
;
2393 notify
->hkey
= req
->hkey
;
2394 notify
->process
= current
->process
;
2395 list_add_head( &key
->notify_list
, ¬ify
->entry
);
2400 struct event
**new_array
;
2402 if ((new_array
= realloc( notify
->events
, (notify
->event_count
+ 1) * sizeof(*notify
->events
) )))
2404 notify
->events
= new_array
;
2405 notify
->events
[notify
->event_count
++] = (struct event
*)grab_object( event
);
2406 reset_event( event
);
2407 set_error( STATUS_PENDING
);
2409 else set_error( STATUS_NO_MEMORY
);
2411 release_object( event
);
2413 release_object( key
);