Added registry support to the server.
diff --git a/include/server.h b/include/server.h
index c00cab8..f187ae5 100644
--- a/include/server.h
+++ b/include/server.h
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <time.h>
+#include "windef.h"
/* Request structures */
@@ -23,6 +24,9 @@
#define OUT /*nothing*/
+/* a path name for server requests (Unicode) */
+typedef WCHAR path_t[MAX_PATH+1];
+
/* Create a new process from the context of the parent */
struct new_process_request
{
@@ -829,6 +833,138 @@
};
+/* Create a registry key */
+struct create_key_request
+{
+ IN int parent; /* handle to the parent key */
+ IN unsigned int access; /* desired access rights */
+ IN unsigned int options; /* creation options */
+ IN time_t modif; /* last modification time */
+ OUT int hkey; /* handle to the created key */
+ OUT int created; /* has it been newly created? */
+ IN path_t name; /* key name */
+ IN WCHAR class[1]; /* class name */
+};
+
+
+/* Open a registry key */
+struct open_key_request
+{
+ IN int parent; /* handle to the parent key */
+ IN unsigned int access; /* desired access rights */
+ OUT int hkey; /* handle to the open key */
+ IN path_t name; /* key name */
+};
+
+
+/* Delete a registry key */
+struct delete_key_request
+{
+ IN int hkey; /* handle to the parent key */
+ IN path_t name; /* key name */
+};
+
+
+/* Close a registry key */
+struct close_key_request
+{
+ IN int hkey; /* key to close */
+};
+
+
+/* Enumerate registry subkeys */
+struct enum_key_request
+{
+ IN int hkey; /* handle to registry key */
+ IN int index; /* index of subkey */
+ OUT time_t modif; /* last modification time */
+ OUT path_t name; /* subkey name */
+ OUT WCHAR class[1]; /* class name */
+};
+
+
+/* Query information about a registry key */
+struct query_key_info_request
+{
+ IN int hkey; /* handle to registry key */
+ OUT int subkeys; /* number of subkeys */
+ OUT int max_subkey; /* longest subkey name */
+ OUT int max_class; /* longest class name */
+ OUT int values; /* number of values */
+ OUT int max_value; /* longest value name */
+ OUT int max_data; /* longest value data */
+ OUT time_t modif; /* last modification time */
+ OUT WCHAR class[1]; /* class name */
+};
+
+
+/* Set a value of a registry key */
+struct set_key_value_request
+{
+ IN int hkey; /* handle to registry key */
+ IN int type; /* value type */
+ IN int len; /* value data len */
+ IN path_t name; /* value name */
+ IN unsigned char data[1]; /* value data */
+};
+
+
+/* Retrieve the value of a registry key */
+struct get_key_value_request
+{
+ IN int hkey; /* handle to registry key */
+ OUT int type; /* value type */
+ OUT int len; /* value data len */
+ IN WCHAR name[1]; /* value name */
+ OUT unsigned char data[1]; /* value data */
+};
+
+
+/* Enumerate a value of a registry key */
+struct enum_key_value_request
+{
+ IN int hkey; /* handle to registry key */
+ IN int index; /* value index */
+ OUT int type; /* value type */
+ OUT int len; /* value data len */
+ OUT path_t name; /* value name */
+ OUT unsigned char data[1]; /* value data */
+};
+
+
+/* Delete a value of a registry key */
+struct delete_key_value_request
+{
+ IN int hkey; /* handle to registry key */
+ IN path_t name; /* value name */
+};
+
+
+/* Load a registry branch from a file */
+struct load_registry_request
+{
+ IN int hkey; /* root key to load to */
+ IN int file; /* file to load from */
+ IN path_t name; /* subkey name */
+};
+
+
+/* Save a registry branch to a file */
+struct save_registry_request
+{
+ IN int hkey; /* key to save */
+ IN int file; /* file to save to */
+};
+
+
+/* Set the current and saving level for the registry */
+struct set_registry_levels_request
+{
+ IN int current; /* new current level */
+ IN int saving; /* new saving level */
+};
+
+
/* Everything below this line is generated automatically by tools/make_requests */
/* ### make_requests begin ### */
@@ -907,6 +1043,19 @@
REQ_DEBUG_PROCESS,
REQ_READ_PROCESS_MEMORY,
REQ_WRITE_PROCESS_MEMORY,
+ REQ_CREATE_KEY,
+ REQ_OPEN_KEY,
+ REQ_DELETE_KEY,
+ REQ_CLOSE_KEY,
+ REQ_ENUM_KEY,
+ REQ_QUERY_KEY_INFO,
+ REQ_SET_KEY_VALUE,
+ REQ_GET_KEY_VALUE,
+ REQ_ENUM_KEY_VALUE,
+ REQ_DELETE_KEY_VALUE,
+ REQ_LOAD_REGISTRY,
+ REQ_SAVE_REGISTRY,
+ REQ_SET_REGISTRY_LEVELS,
REQ_NB_REQUESTS
};
diff --git a/server/Makefile.in b/server/Makefile.in
index f1f0f1d..81f3401 100644
--- a/server/Makefile.in
+++ b/server/Makefile.in
@@ -19,10 +19,11 @@
pipe.c \
process.c \
ptrace.c \
+ registry.c \
request.c \
- snapshot.c \
select.c \
semaphore.c \
+ snapshot.c \
sock.c \
socket.c \
thread.c \
diff --git a/server/main.c b/server/main.c
index c582f2e..51490ce 100644
--- a/server/main.c
+++ b/server/main.c
@@ -29,6 +29,7 @@
create_initial_thread( fd );
if (debug_level) fprintf( stderr, "Server: exiting (pid=%ld)\n", (long) getpid() );
+ close_registry();
#ifdef DEBUG_OBJECTS
dump_objects(); /* dump any remaining objects */
#endif
diff --git a/server/object.c b/server/object.c
index d50fd7d..31d522c 100644
--- a/server/object.c
+++ b/server/object.c
@@ -55,6 +55,15 @@
return ptr;
}
+/* duplicate a block of memory */
+void *memdup( const void *data, size_t len )
+{
+ void *ptr = mem_alloc( len );
+ if (ptr) memcpy( ptr, data, len );
+ return ptr;
+}
+
+
/*****************************************************************/
static int get_name_hash( const char *name, size_t len )
diff --git a/server/object.h b/server/object.h
index 00cbd95..5c1a97b 100644
--- a/server/object.h
+++ b/server/object.h
@@ -66,7 +66,7 @@
};
extern void *mem_alloc( size_t size ); /* malloc wrapper */
-extern char *mem_strdup( const char *str );
+extern void *memdup( const void *data, size_t len );
extern void *alloc_object( const struct object_ops *ops );
extern const char *get_object_name( struct object *obj );
extern void *create_named_object( const struct object_ops *ops, const char *name, size_t len );
@@ -163,6 +163,10 @@
extern int get_page_size(void);
+/* registry functions */
+
+extern void close_registry(void);
+
extern int debug_level;
#endif /* __WINE_SERVER_OBJECT_H */
diff --git a/server/registry.c b/server/registry.c
new file mode 100644
index 0000000..1c20356
--- /dev/null
+++ b/server/registry.c
@@ -0,0 +1,1165 @@
+/*
+ * Server-side registry management
+ *
+ * Copyright (C) 1999 Alexandre Julliard
+ */
+
+/* To do:
+ * - behavior with deleted keys
+ * - values larger than request buffer
+ * - symbolic links
+ */
+
+#include <assert.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "object.h"
+#include "handle.h"
+#include "request.h"
+#include "unicode.h"
+
+#include "winbase.h"
+#include "winerror.h"
+#include "winreg.h"
+
+
+/* a registry key */
+struct key
+{
+ struct object obj; /* object header */
+ WCHAR *name; /* key name */
+ WCHAR *class; /* key class */
+ struct key *parent; /* parent key */
+ int last_subkey; /* last in use subkey */
+ int nb_subkeys; /* count of allocated subkeys */
+ struct key **subkeys; /* subkeys array */
+ int last_value; /* last in use value */
+ int nb_values; /* count of allocated values in array */
+ struct key_value *values; /* values array */
+ short flags; /* flags */
+ short level; /* saving level */
+ time_t modif; /* last modification time */
+};
+
+/* key flags */
+#define KEY_VOLATILE 0x0001 /* key is volatile (not saved to disk) */
+#define KEY_DELETED 0x0002 /* key has been deleted */
+#define KEY_ROOT 0x0004 /* key is a root key */
+
+/* a key value */
+struct key_value
+{
+ WCHAR *name; /* value name */
+ int type; /* value type */
+ size_t len; /* value data length in bytes */
+ void *data; /* pointer to value data */
+};
+
+#define MIN_SUBKEYS 8 /* min. number of allocated subkeys per key */
+#define MIN_VALUES 8 /* min. number of allocated values per key */
+
+
+/* the root keys */
+#define HKEY_ROOT_FIRST HKEY_CLASSES_ROOT
+#define HKEY_ROOT_LAST HKEY_DYN_DATA
+#define NB_ROOT_KEYS (HKEY_ROOT_LAST - HKEY_ROOT_FIRST + 1)
+#define IS_ROOT_HKEY(h) (((h) >= HKEY_ROOT_FIRST) && ((h) <= HKEY_ROOT_LAST))
+static struct key *root_keys[NB_ROOT_KEYS];
+
+static const char * const root_key_names[NB_ROOT_KEYS] =
+{
+ "HKEY_CLASSES_ROOT",
+ "HKEY_CURRENT_USER",
+ "HKEY_LOCAL_MACHINE",
+ "HKEY_USERS",
+ "HKEY_PERFORMANCE_DATA",
+ "HKEY_CURRENT_CONFIG",
+ "HKEY_DYN_DATA"
+};
+
+
+/* keys saving level */
+/* current_level is the level that is put into all newly created or modified keys */
+/* saving_level is the minimum level that a key needs in order to get saved */
+static int current_level;
+static int saving_level;
+
+static int saving_version = 1; /* file format version */
+
+
+static void key_dump( struct object *obj, int verbose );
+static void key_destroy( struct object *obj );
+
+static const struct object_ops key_ops =
+{
+ sizeof(struct key),
+ key_dump,
+ no_add_queue,
+ NULL, /* should never get called */
+ NULL, /* should never get called */
+ NULL, /* should never get called */
+ no_read_fd,
+ no_write_fd,
+ no_flush,
+ no_get_file_info,
+ key_destroy
+};
+
+
+/*
+ * The registry text file format v2 used by this code is similar to the one
+ * used by REGEDIT import/export functionality, with the following differences:
+ * - strings and key names can contain \x escapes for Unicode
+ * - key names use escapes too in order to support Unicode
+ * - the modification time optionally follows the key name
+ * - REG_EXPAND_SZ and REG_MULTI_SZ are saved as strings instead of hex
+ */
+
+/* dump a string to a text file with proper escaping */
+static int dump_strW( const WCHAR *str, int len, FILE *f, char escape[2] )
+{
+ static const char escapes[32] = ".......abtnvfr.............e....";
+ char buffer[256];
+ char *pos = buffer;
+ int count = 0;
+
+ for (; len; str++, len--)
+ {
+ if (pos > buffer + sizeof(buffer) - 8)
+ {
+ fwrite( buffer, pos - buffer, 1, f );
+ count += pos - buffer;
+ pos = buffer;
+ }
+ if (*str > 127) /* hex escape */
+ {
+ if (len > 1 && str[1] < 128 && isxdigit((char)str[1]))
+ pos += sprintf( pos, "\\x%04x", *str );
+ else
+ pos += sprintf( pos, "\\x%x", *str );
+ continue;
+ }
+ if (*str < 32) /* octal or C escape */
+ {
+ if (!*str && len == 1) continue; /* do not output terminating NULL */
+ if (escapes[*str] != '.')
+ pos += sprintf( pos, "\\%c", escapes[*str] );
+ else if (len > 1 && str[1] >= '0' && str[1] <= '7')
+ pos += sprintf( pos, "\\%03o", *str );
+ else
+ pos += sprintf( pos, "\\%o", *str );
+ continue;
+ }
+ if (*str == '\\' || *str == escape[0] || *str == escape[1]) *pos++ = '\\';
+ *pos++ = *str;
+ }
+ fwrite( buffer, pos - buffer, 1, f );
+ count += pos - buffer;
+ return count;
+}
+
+
+static inline char to_hex( char ch )
+{
+ if (isdigit(ch)) return ch - '0';
+ return tolower(ch) - 'a' + 10;
+}
+
+/* dump the full path of a key */
+static void dump_path( struct key *key, FILE *f )
+{
+ if (key->parent) dump_path( key->parent, f );
+ else if (key->name) fprintf( f, "?????" );
+
+ if (key->name)
+ {
+ fprintf( f, "\\\\" );
+ dump_strW( key->name, strlenW(key->name), f, "[]" );
+ }
+ else /* root key */
+ {
+ int i;
+ for (i = 0; i < NB_ROOT_KEYS; i++)
+ if (root_keys[i] == key) fprintf( f, "%s", root_key_names[i] );
+ }
+}
+
+/* dump a value to a text file */
+static void dump_value( struct key_value *value, FILE *f )
+{
+ int i, count;
+
+ if (value->name[0])
+ {
+ fputc( '\"', f );
+ count = 1 + dump_strW( value->name, strlenW(value->name), f, "\"\"" );
+ count += fprintf( f, "\"=" );
+ }
+ else count = fprintf( f, "@=" );
+
+ switch(value->type)
+ {
+ case REG_SZ:
+ case REG_EXPAND_SZ:
+ case REG_MULTI_SZ:
+ if (value->type != REG_SZ) fprintf( f, "str(%d):", value->type );
+ fputc( '\"', f );
+ if (value->data) dump_strW( (WCHAR *)value->data, value->len / sizeof(WCHAR), f, "\"\"" );
+ fputc( '\"', f );
+ break;
+ case REG_DWORD:
+ if (value->len == sizeof(DWORD))
+ {
+ DWORD dw;
+ memcpy( &dw, value->data, sizeof(DWORD) );
+ fprintf( f, "dword:%08lx", dw );
+ break;
+ }
+ /* else fall through */
+ default:
+ if (value->type == REG_BINARY) count += fprintf( f, "hex:" );
+ else count += fprintf( f, "hex(%x):", value->type );
+ for (i = 0; i < value->len; i++)
+ {
+ count += fprintf( f, "%02x", *((unsigned char *)value->data + i) );
+ if (i < value->len-1)
+ {
+ fputc( ',', f );
+ if (++count > 76)
+ {
+ fprintf( f, "\\\n " );
+ count = 2;
+ }
+ }
+ }
+ break;
+ }
+ fputc( '\n', f );
+}
+
+/* save a registry and all its subkeys to a text file */
+static void save_subkeys( struct key *key, FILE *f )
+{
+ int i;
+
+ if (key->flags & KEY_VOLATILE) return;
+ /* save key if it has the proper level, and has either some values or no subkeys */
+ /* keys with no values but subkeys are saved implicitly by saving the subkeys */
+ if ((key->level >= saving_level) && ((key->last_value >= 0) || (key->last_subkey == -1)))
+ {
+ fprintf( f, "\n[" );
+ dump_path( key, f );
+ fprintf( f, "] %ld\n", key->modif );
+ for (i = 0; i <= key->last_value; i++) dump_value( &key->values[i], f );
+ }
+ for (i = 0; i <= key->last_subkey; i++) save_subkeys( key->subkeys[i], f );
+}
+
+static void dump_operation( struct key *key, struct key_value *value, const char *op )
+{
+ fprintf( stderr, "%s key ", op );
+ if (key) dump_path( key, stderr );
+ else fprintf( stderr, "ERROR" );
+ if (value)
+ {
+ fprintf( stderr, " value ");
+ dump_value( value, stderr );
+ }
+ else fprintf( stderr, "\n" );
+}
+
+static void key_dump( struct object *obj, int verbose )
+{
+ struct key *key = (struct key *)obj;
+ assert( obj->ops == &key_ops );
+ fprintf( stderr, "Key flags=%x ", key->flags );
+ dump_path( key, stderr );
+ fprintf( stderr, "\n" );
+}
+
+static void key_destroy( struct object *obj )
+{
+ int i;
+ struct key *key = (struct key *)obj;
+ assert( obj->ops == &key_ops );
+
+ free( key->name );
+ if (key->class) free( key->class );
+ for (i = 0; i <= key->last_value; i++)
+ {
+ free( key->values[i].name );
+ if (key->values[i].data) free( key->values[i].data );
+ }
+ for (i = 0; i <= key->last_subkey; i++) release_object( key->subkeys[i] );
+}
+
+/* duplicate a key path from the request buffer */
+/* returns a pointer to a static buffer, so only useable once per request */
+static WCHAR *copy_path( const path_t path )
+{
+ static WCHAR buffer[MAX_PATH+1];
+ WCHAR *p = buffer;
+
+ while (p < buffer + sizeof(buffer) - 1) if (!(*p++ = *path++)) break;
+ *p = 0;
+ return buffer;
+}
+
+/* return the next token in a given path */
+/* returns a pointer to a static buffer, so only useable once per request */
+static WCHAR *get_path_token( const WCHAR *initpath, size_t maxlen )
+{
+ static const WCHAR *path;
+ static const WCHAR *end;
+ static WCHAR buffer[MAX_PATH+1];
+ WCHAR *p = buffer;
+
+ if (initpath)
+ {
+ path = initpath;
+ end = path + maxlen / sizeof(WCHAR);
+ }
+ while ((path < end) && (*path == '\\')) path++;
+ while ((path < end) && (p < buffer + sizeof(buffer) - 1))
+ {
+ WCHAR ch = *path;
+ if (!ch || (ch == '\\')) break;
+ *p++ = ch;
+ path++;
+ }
+ *p = 0;
+ return buffer;
+}
+
+/* duplicate a Unicode string from the request buffer */
+static WCHAR *req_strdupW( const WCHAR *str )
+{
+ WCHAR *name;
+ size_t len = get_req_strlenW( str );
+ if ((name = mem_alloc( (len + 1) * sizeof(WCHAR) )) != NULL)
+ {
+ memcpy( name, str, len * sizeof(WCHAR) );
+ name[len] = 0;
+ }
+ return name;
+}
+
+/* allocate a key object */
+static struct key *alloc_key( const WCHAR *name, time_t modif )
+{
+ struct key *key;
+ if ((key = (struct key *)alloc_object( &key_ops )))
+ {
+ key->name = NULL;
+ key->class = NULL;
+ key->flags = 0;
+ key->last_subkey = -1;
+ key->nb_subkeys = 0;
+ key->subkeys = NULL;
+ key->nb_values = 0;
+ key->last_value = -1;
+ key->values = NULL;
+ key->level = current_level;
+ key->modif = modif;
+ key->parent = NULL;
+ if (name && !(key->name = strdupW( name )))
+ {
+ release_object( key );
+ key = NULL;
+ }
+ }
+ return key;
+}
+
+/* update key modification time */
+static void touch_key( struct key *key )
+{
+ key->modif = time(NULL);
+ key->level = MAX( key->level, current_level );
+}
+
+/* try to grow the array of subkeys; return 1 if OK, 0 on error */
+static int grow_subkeys( struct key *key )
+{
+ struct key **new_subkeys;
+ int nb_subkeys;
+
+ if (key->nb_subkeys)
+ {
+ nb_subkeys = key->nb_subkeys + (key->nb_subkeys / 2); /* grow by 50% */
+ if (!(new_subkeys = realloc( key->subkeys, nb_subkeys * sizeof(*new_subkeys) )))
+ {
+ set_error( ERROR_OUTOFMEMORY );
+ return 0;
+ }
+ }
+ else
+ {
+ nb_subkeys = MIN_VALUES;
+ if (!(new_subkeys = mem_alloc( nb_subkeys * sizeof(*new_subkeys) ))) return 0;
+ }
+ key->subkeys = new_subkeys;
+ key->nb_subkeys = nb_subkeys;
+ return 1;
+}
+
+/* allocate a subkey for a given key, and return its index */
+static struct key *alloc_subkey( struct key *parent, const WCHAR *name, int index, time_t modif )
+{
+ struct key *key;
+ int i;
+
+ if (parent->last_subkey + 1 == parent->nb_subkeys)
+ {
+ /* need to grow the array */
+ if (!grow_subkeys( parent )) return NULL;
+ }
+ if ((key = alloc_key( name, modif )) != NULL)
+ {
+ key->parent = parent;
+ for (i = ++parent->last_subkey; i > index; i--)
+ parent->subkeys[i] = parent->subkeys[i-1];
+ parent->subkeys[index] = key;
+ }
+ return key;
+}
+
+/* free a subkey of a given key */
+static void free_subkey( struct key *parent, int index )
+{
+ struct key *key;
+ int i, nb_subkeys;
+
+ assert( index >= 0 );
+ assert( index <= parent->last_subkey );
+
+ key = parent->subkeys[index];
+ for (i = index; i < parent->last_subkey; i++) parent->subkeys[i] = parent->subkeys[i + 1];
+ parent->last_subkey--;
+ key->flags |= KEY_DELETED;
+ key->parent = NULL;
+ release_object( key );
+
+ /* try to shrink the array */
+ nb_subkeys = key->nb_subkeys;
+ if (nb_subkeys > MIN_SUBKEYS && key->last_subkey < nb_subkeys / 2)
+ {
+ struct key **new_subkeys;
+ nb_subkeys -= nb_subkeys / 3; /* shrink by 33% */
+ if (nb_subkeys < MIN_SUBKEYS) nb_subkeys = MIN_SUBKEYS;
+ if (!(new_subkeys = realloc( key->subkeys, nb_subkeys * sizeof(*new_subkeys) ))) return;
+ key->subkeys = new_subkeys;
+ key->nb_subkeys = nb_subkeys;
+ }
+}
+
+/* find the named child of a given key and return its index */
+static struct key *find_subkey( struct key *key, const WCHAR *name, int *index )
+{
+ int i, min, max, res;
+
+ min = 0;
+ max = key->last_subkey;
+ while (min <= max)
+ {
+ i = (min + max) / 2;
+ if (!(res = strcmpiW( key->subkeys[i]->name, name )))
+ {
+ *index = i;
+ return key->subkeys[i];
+ }
+ if (res > 0) max = i - 1;
+ else min = i + 1;
+ }
+ *index = min; /* this is where we should insert it */
+ return NULL;
+}
+
+/* open a subkey */
+static struct key *open_key( struct key *key, const WCHAR *name, size_t maxlen )
+{
+ int index;
+ WCHAR *path;
+
+ path = get_path_token( name, maxlen );
+ while (*path)
+ {
+ if (!(key = find_subkey( key, path, &index )))
+ {
+ set_error( ERROR_FILE_NOT_FOUND );
+ break;
+ }
+ path = get_path_token( NULL, 0 );
+ }
+
+ if (debug_level > 1) dump_operation( key, NULL, "Open" );
+ if (key) grab_object( key );
+ return key;
+}
+
+/* create a subkey */
+static struct key *create_key( struct key *key, const WCHAR *name, size_t maxlen, WCHAR *class,
+ unsigned int options, time_t modif, int *created )
+{
+ struct key *base;
+ int base_idx, index, flags = 0;
+ WCHAR *path;
+
+ if (key->flags & KEY_DELETED) /* we cannot create a subkey under a deleted key */
+ {
+ set_error( ERROR_KEY_DELETED );
+ return NULL;
+ }
+ if (options & REG_OPTION_VOLATILE) flags |= KEY_VOLATILE;
+ else if (key->flags & KEY_VOLATILE)
+ {
+ set_error( ERROR_CHILD_MUST_BE_VOLATILE );
+ return NULL;
+ }
+
+ path = get_path_token( name, maxlen );
+ *created = 0;
+ while (*path)
+ {
+ struct key *subkey;
+ if (!(subkey = find_subkey( key, path, &index ))) break;
+ key = subkey;
+ path = get_path_token( NULL, 0 );
+ }
+
+ /* create the remaining part */
+
+ if (!*path) goto done;
+ *created = 1;
+ base = key;
+ base_idx = index;
+ key = alloc_subkey( key, path, index, modif );
+ while (key)
+ {
+ key->flags |= flags;
+ path = get_path_token( NULL, 0 );
+ if (!*path) goto done;
+ /* we know the index is always 0 in a new key */
+ key = alloc_subkey( key, path, 0, modif );
+ }
+ if (base_idx != -1) free_subkey( base, base_idx );
+ return NULL;
+
+ done:
+ if (debug_level > 1) dump_operation( key, NULL, "Create" );
+ if (class) key->class = strdupW(class);
+ grab_object( key );
+ return key;
+}
+
+/* find a subkey of a given key by its index */
+static void enum_key( struct key *parent, int index, WCHAR *name, WCHAR *class, time_t *modif )
+{
+ struct key *key;
+
+ if ((index < 0) || (index > parent->last_subkey)) set_error( ERROR_NO_MORE_ITEMS );
+ else
+ {
+ key = parent->subkeys[index];
+ *modif = key->modif;
+ strcpyW( name, key->name );
+ if (key->class) strcpyW( class, key->class ); /* FIXME: length */
+ else *class = 0;
+ if (debug_level > 1) dump_operation( key, NULL, "Enum" );
+ }
+}
+
+/* query information about a key */
+static void query_key( struct key *key, struct query_key_info_request *req )
+{
+ int i, len;
+ int max_subkey = 0, max_class = 0;
+ int max_value = 0, max_data = 0;
+
+ for (i = 0; i < key->last_subkey; i++)
+ {
+ struct key *subkey = key->subkeys[i];
+ len = strlenW( subkey->name );
+ if (len > max_subkey) max_subkey = len;
+ if (!subkey->class) continue;
+ len = strlenW( subkey->class );
+ if (len > max_class) max_class = len;
+ }
+ for (i = 0; i < key->last_value; i++)
+ {
+ len = strlenW( key->values[i].name );
+ if (len > max_value) max_value = len;
+ len = key->values[i].len;
+ if (len > max_data) max_data = len;
+ }
+ req->subkeys = key->last_subkey + 1;
+ req->max_subkey = max_subkey;
+ req->max_class = max_class;
+ req->values = key->last_value + 1;
+ req->max_value = max_value;
+ req->max_data = max_data;
+ req->modif = key->modif;
+ if (key->class) strcpyW( req->class, key->class ); /* FIXME: length */
+ else req->class[0] = 0;
+ if (debug_level > 1) dump_operation( key, NULL, "Query" );
+}
+
+/* delete a key and its values */
+static void delete_key( struct key *key, const WCHAR *name, size_t maxlen )
+{
+ int index;
+ struct key *parent;
+ WCHAR *path;
+
+ path = get_path_token( name, maxlen );
+ if (!*path)
+ {
+ /* deleting this key, must find parent and index */
+ if (key->flags & KEY_ROOT)
+ {
+ set_error( ERROR_ACCESS_DENIED );
+ return;
+ }
+ if (!(parent = key->parent) || (key->flags & KEY_DELETED))
+ {
+ set_error( ERROR_KEY_DELETED );
+ return;
+ }
+ for (index = 0; index <= parent->last_subkey; index++)
+ if (parent->subkeys[index] == key) break;
+ assert( index <= parent->last_subkey );
+ }
+ else while (*path)
+ {
+ parent = key;
+ if (!(key = find_subkey( parent, path, &index )))
+ {
+ set_error( ERROR_FILE_NOT_FOUND );
+ return;
+ }
+ path = get_path_token( NULL, 0 );
+ }
+
+ /* we can only delete a key that has no subkeys (FIXME) */
+ if ((key->flags & KEY_ROOT) || (key->last_subkey >= 0))
+ {
+ set_error( ERROR_ACCESS_DENIED );
+ return;
+ }
+ if (debug_level > 1) dump_operation( key, NULL, "Delete" );
+ free_subkey( parent, index );
+ touch_key( parent );
+}
+
+/* try to grow the array of values; return 1 if OK, 0 on error */
+static int grow_values( struct key *key )
+{
+ struct key_value *new_val;
+ int nb_values;
+
+ if (key->nb_values)
+ {
+ nb_values = key->nb_values + (key->nb_values / 2); /* grow by 50% */
+ if (!(new_val = realloc( key->values, nb_values * sizeof(*new_val) )))
+ {
+ set_error( ERROR_OUTOFMEMORY );
+ return 0;
+ }
+ }
+ else
+ {
+ nb_values = MIN_VALUES;
+ if (!(new_val = mem_alloc( nb_values * sizeof(*new_val) ))) return 0;
+ }
+ key->values = new_val;
+ key->nb_values = nb_values;
+ return 1;
+}
+
+/* find the named value of a given key and return its index in the array */
+static struct key_value *find_value( const struct key *key, const WCHAR *name, int *index )
+{
+ int i, min, max, res;
+
+ min = 0;
+ max = key->last_value;
+ while (min <= max)
+ {
+ i = (min + max) / 2;
+ if (!(res = strcmpiW( key->values[i].name, name )))
+ {
+ *index = i;
+ return &key->values[i];
+ }
+ if (res > 0) max = i - 1;
+ else min = i + 1;
+ }
+ *index = min; /* this is where we should insert it */
+ return NULL;
+}
+
+/* insert a new value or return a pointer to an existing one */
+static struct key_value *insert_value( struct key *key, const WCHAR *name )
+{
+ struct key_value *value;
+ WCHAR *new_name;
+ int i, index;
+
+ if (!(value = find_value( key, name, &index )))
+ {
+ /* not found, add it */
+ if (key->last_value + 1 == key->nb_values)
+ {
+ if (!grow_values( key )) return NULL;
+ }
+ if (!(new_name = strdupW(name))) return NULL;
+ for (i = ++key->last_value; i > index; i--) key->values[i] = key->values[i - 1];
+ value = &key->values[index];
+ value->name = new_name;
+ value->len = 0;
+ value->data = NULL;
+ }
+ return value;
+}
+
+/* set a key value */
+static void set_value( struct key *key, WCHAR *name, int type, int datalen, void *data )
+{
+ struct key_value *value;
+ void *ptr = NULL;
+
+ /* first copy the data */
+ if (datalen)
+ {
+ if (!(ptr = mem_alloc( datalen ))) return;
+ memcpy( ptr, data, datalen );
+ }
+
+ if (!(value = insert_value( key, name )))
+ {
+ if (ptr) free( ptr );
+ return;
+ }
+ if (value->data) free( value->data ); /* already existing, free previous data */
+ value->type = type;
+ value->len = datalen;
+ value->data = ptr;
+ touch_key( key );
+ if (debug_level > 1) dump_operation( key, value, "Set" );
+}
+
+/* get a key value */
+static void get_value( struct key *key, WCHAR *name, int *type, int *len, void *data )
+{
+ struct key_value *value;
+ int index;
+
+ if ((value = find_value( key, name, &index )))
+ {
+ *type = value->type;
+ *len = value->len;
+ if (value->data) memcpy( data, value->data, value->len );
+ if (debug_level > 1) dump_operation( key, value, "Get" );
+ }
+ else
+ {
+ *type = -1;
+ *len = 0;
+ set_error( ERROR_FILE_NOT_FOUND );
+ }
+}
+
+/* enumerate a key value */
+static void enum_value( struct key *key, int i, WCHAR *name, int *type, int *len, void *data )
+{
+ struct key_value *value;
+
+ if (i < 0 || i > key->last_value)
+ {
+ name[0] = 0;
+ *len = 0;
+ set_error( ERROR_NO_MORE_ITEMS );
+ }
+ else
+ {
+ value = &key->values[i];
+ strcpyW( name, value->name );
+ *type = value->type;
+ *len = value->len;
+ if (value->data) memcpy( data, value->data, value->len );
+ if (debug_level > 1) dump_operation( key, value, "Enum" );
+ }
+}
+
+/* delete a value */
+static void delete_value( struct key *key, const WCHAR *name )
+{
+ struct key_value *value;
+ int i, index, nb_values;
+
+ if (!(value = find_value( key, name, &index )))
+ {
+ set_error( ERROR_FILE_NOT_FOUND );
+ return;
+ }
+ if (debug_level > 1) dump_operation( key, value, "Delete" );
+ free( value->name );
+ if (value->data) free( value->data );
+ for (i = index; i < key->last_value; i++) key->values[i] = key->values[i + 1];
+ key->last_value--;
+ touch_key( key );
+
+ /* try to shrink the array */
+ nb_values = key->nb_values;
+ if (nb_values > MIN_VALUES && key->last_value < nb_values / 2)
+ {
+ struct key_value *new_val;
+ nb_values -= nb_values / 3; /* shrink by 33% */
+ if (nb_values < MIN_VALUES) nb_values = MIN_VALUES;
+ if (!(new_val = realloc( key->values, nb_values * sizeof(*new_val) ))) return;
+ key->values = new_val;
+ key->nb_values = nb_values;
+ }
+}
+
+static struct key *get_hkey_obj( int hkey, unsigned int access );
+
+static struct key *create_root_key( int hkey )
+{
+ int dummy;
+ struct key *key;
+
+ switch(hkey)
+ {
+ case HKEY_CLASSES_ROOT:
+ {
+ static const WCHAR name[] =
+ { 'S','O','F','T','W','A','R','E','\\','C','l','a','s','s','e','s',0 };
+
+ struct key *root = get_hkey_obj( HKEY_LOCAL_MACHINE, 0 );
+ if (!root) return NULL;
+ key = create_key( root, name, sizeof(name), NULL, 0, time(NULL), &dummy );
+ release_object( root );
+ }
+ break;
+ case HKEY_CURRENT_USER: /* FIXME: should be HKEY_USERS\\the_current_user_SID */
+ case HKEY_LOCAL_MACHINE:
+ case HKEY_USERS:
+ case HKEY_PERFORMANCE_DATA:
+ case HKEY_DYN_DATA:
+ case HKEY_CURRENT_CONFIG:
+ key = alloc_key( NULL, time(NULL) );
+ break;
+ default:
+ key = NULL;
+ assert(0);
+ }
+ if (key)
+ {
+ root_keys[hkey - HKEY_ROOT_FIRST] = key;
+ key->flags |= KEY_ROOT;
+ }
+ return key;
+}
+
+/* close the top-level keys; used on server exit */
+void close_registry(void)
+{
+ int i;
+ for (i = 0; i < NB_ROOT_KEYS; i++)
+ {
+ if (root_keys[i] && !root_keys[i]->parent) release_object( root_keys[i] );
+ }
+}
+
+/* get the registry key corresponding to an hkey handle */
+static struct key *get_hkey_obj( int hkey, unsigned int access )
+{
+ struct key *key;
+
+ if (IS_ROOT_HKEY(hkey))
+ {
+ if (!(key = root_keys[hkey - HKEY_ROOT_FIRST])) key = create_root_key( hkey );
+ grab_object( key );
+ }
+ else
+ key = (struct key *)get_handle_obj( current->process, hkey, access, &key_ops );
+ return key;
+}
+
+/* update the level of the parents of a key (only needed for the old format) */
+static int update_level( struct key *key )
+{
+ int i;
+ int max = key->level;
+ for (i = 0; i <= key->last_subkey; i++)
+ {
+ int sub = update_level( key->subkeys[i] );
+ if (sub > max) max = sub;
+ }
+ key->level = max;
+ return max;
+}
+
+/* dump a string to a registry save file in the old v1 format */
+static void save_string_v1( LPCWSTR str, FILE *f )
+{
+ if (!str) return;
+ while (*str)
+ {
+ if ((*str > 0x7f) || (*str == '\n') || (*str == '='))
+ fprintf( f, "\\u%04x", *str );
+ else
+ {
+ if (*str == '\\') fputc( '\\', f );
+ fputc( (char)*str, f );
+ }
+ str++;
+ }
+}
+
+/* save a registry and all its subkeys to a text file in the old v1 format */
+static void save_subkeys_v1( struct key *key, int nesting, FILE *f )
+{
+ int i, j;
+
+ if (key->flags & KEY_VOLATILE) return;
+ if (key->level < saving_level) return;
+ for (i = 0; i <= key->last_value; i++)
+ {
+ struct key_value *value = &key->values[i];
+ for (j = nesting; j > 0; j --) fputc( '\t', f );
+ save_string_v1( value->name, f );
+ fprintf( f, "=%d,%d,", value->type, 0 );
+ if (value->type == REG_SZ || value->type == REG_EXPAND_SZ)
+ save_string_v1( (LPWSTR)value->data, f );
+ else
+ for (j = 0; j < value->len; j++)
+ fprintf( f, "%02x", *((unsigned char *)value->data + j) );
+ fputc( '\n', f );
+ }
+ for (i = 0; i <= key->last_subkey; i++)
+ {
+ for (j = nesting; j > 0; j --) fputc( '\t', f );
+ save_string_v1( key->subkeys[i]->name, f );
+ fputc( '\n', f );
+ save_subkeys_v1( key->subkeys[i], nesting + 1, f );
+ }
+}
+
+/* save a registry branch to a file handle */
+static void save_registry( struct key *key, int handle )
+{
+ struct object *obj;
+ int fd;
+
+ if (key->flags & KEY_DELETED)
+ {
+ set_error( ERROR_KEY_DELETED );
+ return;
+ }
+ if (!(obj = get_handle_obj( current->process, handle, GENERIC_WRITE, NULL ))) return;
+ fd = obj->ops->get_write_fd( obj );
+ release_object( obj );
+ if (fd != -1)
+ {
+ FILE *f = fdopen( fd, "w" );
+ if (f)
+ {
+ fprintf( f, "WINE REGISTRY Version %d\n", saving_version );
+ if (saving_version == 2) save_subkeys( key, f );
+ else
+ {
+ update_level( key );
+ save_subkeys_v1( key, 0, f );
+ }
+ if (fclose( f )) file_set_error();
+ }
+ else
+ {
+ file_set_error();
+ close( fd );
+ }
+ }
+}
+
+/* create a registry key */
+DECL_HANDLER(create_key)
+{
+ struct key *key, *parent;
+ WCHAR *class;
+ unsigned int access = req->access;
+
+ if (access & MAXIMUM_ALLOWED) access = KEY_ALL_ACCESS; /* FIXME: needs general solution */
+ req->hkey = -1;
+ if ((parent = get_hkey_obj( req->parent, KEY_CREATE_SUB_KEY )))
+ {
+ if ((class = req_strdupW( req->class )))
+ {
+ if ((key = create_key( parent, req->name, sizeof(req->name), class, req->options,
+ req->modif, &req->created )))
+ {
+ req->hkey = alloc_handle( current->process, key, access, 0 );
+ release_object( key );
+ }
+ free( class );
+ }
+ release_object( parent );
+ }
+}
+
+/* open a registry key */
+DECL_HANDLER(open_key)
+{
+ struct key *key, *parent;
+ unsigned int access = req->access;
+
+ if (access & MAXIMUM_ALLOWED) access = KEY_ALL_ACCESS; /* FIXME: needs general solution */
+ req->hkey = -1;
+ if ((parent = get_hkey_obj( req->parent, 0 /*FIXME*/ )))
+ {
+ if ((key = open_key( parent, req->name, sizeof(req->name) )))
+ {
+ req->hkey = alloc_handle( current->process, key, access, 0 );
+ release_object( key );
+ }
+ release_object( parent );
+ }
+}
+
+/* delete a registry key */
+DECL_HANDLER(delete_key)
+{
+ struct key *key;
+
+ if ((key = get_hkey_obj( req->hkey, KEY_CREATE_SUB_KEY /*FIXME*/ )))
+ {
+ delete_key( key, req->name, sizeof(req->name) );
+ release_object( key );
+ }
+}
+
+/* close a registry key */
+DECL_HANDLER(close_key)
+{
+ int hkey = req->hkey;
+ /* ignore attempts to close a root key */
+ if (!IS_ROOT_HKEY(hkey)) close_handle( current->process, hkey );
+}
+
+/* enumerate registry subkeys */
+DECL_HANDLER(enum_key)
+{
+ struct key *key;
+
+ if ((key = get_hkey_obj( req->hkey, KEY_ENUMERATE_SUB_KEYS )))
+ {
+ enum_key( key, req->index, req->name, req->class, &req->modif );
+ release_object( key );
+ }
+}
+
+/* query information about a registry key */
+DECL_HANDLER(query_key_info)
+{
+ struct key *key;
+
+ if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE )))
+ {
+ query_key( key, req );
+ release_object( key );
+ }
+}
+
+/* set a value of a registry key */
+DECL_HANDLER(set_key_value)
+{
+ struct key *key;
+ int max = get_req_size( req->data, sizeof(req->data[0]) );
+ int datalen = req->len;
+ if (datalen > max)
+ {
+ set_error( ERROR_OUTOFMEMORY ); /* FIXME */
+ return;
+ }
+ if ((key = get_hkey_obj( req->hkey, KEY_SET_VALUE )))
+ {
+ set_value( key, copy_path( req->name ), req->type, datalen, req->data );
+ release_object( key );
+ }
+}
+
+/* retrieve the value of a registry key */
+DECL_HANDLER(get_key_value)
+{
+ struct key *key;
+
+ if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE )))
+ {
+ get_value( key, copy_path( req->name ), &req->type, &req->len, req->data );
+ release_object( key );
+ }
+}
+
+/* enumerate the value of a registry key */
+DECL_HANDLER(enum_key_value)
+{
+ struct key *key;
+
+ if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE )))
+ {
+ enum_value( key, req->index, req->name, &req->type, &req->len, req->data );
+ release_object( key );
+ }
+}
+
+/* delete a value of a registry key */
+DECL_HANDLER(delete_key_value)
+{
+ WCHAR *name;
+ struct key *key;
+
+ if ((key = get_hkey_obj( req->hkey, KEY_SET_VALUE )))
+ {
+ if ((name = req_strdupW( req->name )))
+ {
+ delete_value( key, name );
+ free( name );
+ }
+ release_object( key );
+ }
+}
+
+/* load a registry branch from a file */
+DECL_HANDLER(load_registry)
+{
+ struct key *key;
+
+ if ((key = get_hkey_obj( req->hkey, KEY_SET_VALUE | KEY_CREATE_SUB_KEY )))
+ {
+ set_error( ERROR_CALL_NOT_IMPLEMENTED );
+ release_object( key );
+ }
+}
+
+/* save a registry branch to a file */
+DECL_HANDLER(save_registry)
+{
+ struct key *key;
+
+ if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS )))
+ {
+ save_registry( key, req->file );
+ release_object( key );
+ }
+}
+
+/* set the current and saving level for the registry */
+DECL_HANDLER(set_registry_levels)
+{
+ current_level = req->current;
+ saving_level = req->saving;
+}
+
diff --git a/server/request.h b/server/request.h
index 1d05bd9..0d509ac 100644
--- a/server/request.h
+++ b/server/request.h
@@ -58,6 +58,14 @@
return p - str;
}
+/* same as above for Unicode */
+static inline size_t get_req_strlenW( const WCHAR *str )
+{
+ const WCHAR *p = str;
+ while (*p && ((char *)p < (char *)current->buffer + MAX_REQUEST_LENGTH - 2)) p++;
+ return p - str;
+}
+
/* Everything below this line is generated automatically by tools/make_requests */
/* ### make_requests begin ### */
@@ -134,6 +142,19 @@
DECL_HANDLER(debug_process);
DECL_HANDLER(read_process_memory);
DECL_HANDLER(write_process_memory);
+DECL_HANDLER(create_key);
+DECL_HANDLER(open_key);
+DECL_HANDLER(delete_key);
+DECL_HANDLER(close_key);
+DECL_HANDLER(enum_key);
+DECL_HANDLER(query_key_info);
+DECL_HANDLER(set_key_value);
+DECL_HANDLER(get_key_value);
+DECL_HANDLER(enum_key_value);
+DECL_HANDLER(delete_key_value);
+DECL_HANDLER(load_registry);
+DECL_HANDLER(save_registry);
+DECL_HANDLER(set_registry_levels);
#ifdef WANT_REQUEST_HANDLERS
@@ -214,6 +235,19 @@
{ (void(*)())req_debug_process, sizeof(struct debug_process_request) },
{ (void(*)())req_read_process_memory, sizeof(struct read_process_memory_request) },
{ (void(*)())req_write_process_memory, sizeof(struct write_process_memory_request) },
+ { (void(*)())req_create_key, sizeof(struct create_key_request) },
+ { (void(*)())req_open_key, sizeof(struct open_key_request) },
+ { (void(*)())req_delete_key, sizeof(struct delete_key_request) },
+ { (void(*)())req_close_key, sizeof(struct close_key_request) },
+ { (void(*)())req_enum_key, sizeof(struct enum_key_request) },
+ { (void(*)())req_query_key_info, sizeof(struct query_key_info_request) },
+ { (void(*)())req_set_key_value, sizeof(struct set_key_value_request) },
+ { (void(*)())req_get_key_value, sizeof(struct get_key_value_request) },
+ { (void(*)())req_enum_key_value, sizeof(struct enum_key_value_request) },
+ { (void(*)())req_delete_key_value, sizeof(struct delete_key_value_request) },
+ { (void(*)())req_load_registry, sizeof(struct load_registry_request) },
+ { (void(*)())req_save_registry, sizeof(struct save_registry_request) },
+ { (void(*)())req_set_registry_levels, sizeof(struct set_registry_levels_request) },
};
#endif /* WANT_REQUEST_HANDLERS */
diff --git a/server/trace.c b/server/trace.c
index df2a4fe..8fd31d0 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -4,6 +4,7 @@
* Copyright (C) 1999 Alexandre Julliard
*/
+#include <ctype.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/uio.h>
@@ -35,14 +36,26 @@
fputc( '}', stderr );
}
+static void dump_unicode_string( const WCHAR *str )
+{
+ fprintf( stderr, "L\"" );
+ while (*str)
+ {
+ fprintf( stderr, "%c", isprint( (char)*str ) ? (char )*str : '?' );
+ str++;
+ }
+ fprintf( stderr, "\"" );
+}
+
+
/* dumping for functions for requests that have a variable part */
-static void dump_varargs_select( struct select_request *req )
+static void dump_varargs_select_request( struct select_request *req )
{
dump_ints( req->handles, req->count );
}
-static void dump_varargs_get_apcs( struct get_apcs_request *req )
+static void dump_varargs_get_apcs_reply( struct get_apcs_request *req )
{
int i;
for (i = 0; i < 2 * req->count; i++)
@@ -50,23 +63,37 @@
fprintf( stderr, "}" );
}
-static void dump_varargs_get_socket_event( struct get_socket_event_request *req )
+static void dump_varargs_get_socket_event_reply( struct get_socket_event_request *req )
{
dump_ints( req->errors, FD_MAX_EVENTS );
}
-static void dump_varargs_read_process_memory( struct read_process_memory_request *req )
+static void dump_varargs_read_process_memory_reply( struct read_process_memory_request *req )
{
int count = MIN( req->len, get_req_size( req->data, sizeof(int) ) );
dump_bytes( (unsigned char *)req->data, count * sizeof(int) );
}
-static void dump_varargs_write_process_memory( struct write_process_memory_request *req )
+static void dump_varargs_write_process_memory_request( struct write_process_memory_request *req )
{
int count = MIN( req->len, get_req_size( req->data, sizeof(int) ) );
dump_bytes( (unsigned char *)req->data, count * sizeof(int) );
}
+static void dump_varargs_set_key_value_request( struct set_key_value_request *req )
+{
+ dump_bytes( req->data, req->len );
+}
+
+static void dump_varargs_get_key_value_reply( struct get_key_value_request *req )
+{
+ dump_bytes( req->data, req->len );
+}
+
+static void dump_varargs_enum_key_value_reply( struct enum_key_value_request *req )
+{
+ dump_bytes( req->data, req->len );
+}
typedef void (*dump_func)( const void *req );
@@ -243,7 +270,7 @@
{
fprintf( stderr, " count=%d,", req->count );
fprintf( stderr, " apcs=" );
- dump_varargs_get_apcs( req );
+ dump_varargs_get_apcs_reply( req );
}
static void dump_close_handle_request( struct close_handle_request *req )
@@ -301,7 +328,7 @@
fprintf( stderr, " flags=%d,", req->flags );
fprintf( stderr, " timeout=%d,", req->timeout );
fprintf( stderr, " handles=" );
- dump_varargs_select( req );
+ dump_varargs_select_request( req );
}
static void dump_select_reply( struct select_request *req )
@@ -565,7 +592,7 @@
fprintf( stderr, " pmask=%08x,", req->pmask );
fprintf( stderr, " state=%08x,", req->state );
fprintf( stderr, " errors=" );
- dump_varargs_get_socket_event( req );
+ dump_varargs_get_socket_event_reply( req );
}
static void dump_enable_socket_event_request( struct enable_socket_event_request *req )
@@ -803,7 +830,7 @@
static void dump_read_process_memory_reply( struct read_process_memory_request *req )
{
fprintf( stderr, " data=" );
- dump_varargs_read_process_memory( req );
+ dump_varargs_read_process_memory_reply( req );
}
static void dump_write_process_memory_request( struct write_process_memory_request *req )
@@ -814,7 +841,156 @@
fprintf( stderr, " first_mask=%08x,", req->first_mask );
fprintf( stderr, " last_mask=%08x,", req->last_mask );
fprintf( stderr, " data=" );
- dump_varargs_write_process_memory( req );
+ dump_varargs_write_process_memory_request( req );
+}
+
+static void dump_create_key_request( struct create_key_request *req )
+{
+ fprintf( stderr, " parent=%d,", req->parent );
+ fprintf( stderr, " access=%08x,", req->access );
+ fprintf( stderr, " options=%08x,", req->options );
+ fprintf( stderr, " modif=%ld,", req->modif );
+ fprintf( stderr, " name=" );
+ dump_unicode_string( req->name );
+ fprintf( stderr, "," );
+ fprintf( stderr, " class=" );
+ dump_unicode_string( req->class );
+}
+
+static void dump_create_key_reply( struct create_key_request *req )
+{
+ fprintf( stderr, " hkey=%d,", req->hkey );
+ fprintf( stderr, " created=%d", req->created );
+}
+
+static void dump_open_key_request( struct open_key_request *req )
+{
+ fprintf( stderr, " parent=%d,", req->parent );
+ fprintf( stderr, " access=%08x,", req->access );
+ fprintf( stderr, " name=" );
+ dump_unicode_string( req->name );
+}
+
+static void dump_open_key_reply( struct open_key_request *req )
+{
+ fprintf( stderr, " hkey=%d", req->hkey );
+}
+
+static void dump_delete_key_request( struct delete_key_request *req )
+{
+ fprintf( stderr, " hkey=%d,", req->hkey );
+ fprintf( stderr, " name=" );
+ dump_unicode_string( req->name );
+}
+
+static void dump_close_key_request( struct close_key_request *req )
+{
+ fprintf( stderr, " hkey=%d", req->hkey );
+}
+
+static void dump_enum_key_request( struct enum_key_request *req )
+{
+ fprintf( stderr, " hkey=%d,", req->hkey );
+ fprintf( stderr, " index=%d", req->index );
+}
+
+static void dump_enum_key_reply( struct enum_key_request *req )
+{
+ fprintf( stderr, " modif=%ld,", req->modif );
+ fprintf( stderr, " name=" );
+ dump_unicode_string( req->name );
+ fprintf( stderr, "," );
+ fprintf( stderr, " class=" );
+ dump_unicode_string( req->class );
+}
+
+static void dump_query_key_info_request( struct query_key_info_request *req )
+{
+ fprintf( stderr, " hkey=%d", req->hkey );
+}
+
+static void dump_query_key_info_reply( struct query_key_info_request *req )
+{
+ fprintf( stderr, " subkeys=%d,", req->subkeys );
+ fprintf( stderr, " max_subkey=%d,", req->max_subkey );
+ fprintf( stderr, " max_class=%d,", req->max_class );
+ fprintf( stderr, " values=%d,", req->values );
+ fprintf( stderr, " max_value=%d,", req->max_value );
+ fprintf( stderr, " max_data=%d,", req->max_data );
+ fprintf( stderr, " modif=%ld,", req->modif );
+ fprintf( stderr, " class=" );
+ dump_unicode_string( req->class );
+}
+
+static void dump_set_key_value_request( struct set_key_value_request *req )
+{
+ fprintf( stderr, " hkey=%d,", req->hkey );
+ fprintf( stderr, " type=%d,", req->type );
+ fprintf( stderr, " len=%d,", req->len );
+ fprintf( stderr, " name=" );
+ dump_unicode_string( req->name );
+ fprintf( stderr, "," );
+ fprintf( stderr, " data=" );
+ dump_varargs_set_key_value_request( req );
+}
+
+static void dump_get_key_value_request( struct get_key_value_request *req )
+{
+ fprintf( stderr, " hkey=%d,", req->hkey );
+ fprintf( stderr, " name=" );
+ dump_unicode_string( req->name );
+}
+
+static void dump_get_key_value_reply( struct get_key_value_request *req )
+{
+ fprintf( stderr, " type=%d,", req->type );
+ fprintf( stderr, " len=%d,", req->len );
+ fprintf( stderr, " data=" );
+ dump_varargs_get_key_value_reply( req );
+}
+
+static void dump_enum_key_value_request( struct enum_key_value_request *req )
+{
+ fprintf( stderr, " hkey=%d,", req->hkey );
+ fprintf( stderr, " index=%d", req->index );
+}
+
+static void dump_enum_key_value_reply( struct enum_key_value_request *req )
+{
+ fprintf( stderr, " type=%d,", req->type );
+ fprintf( stderr, " len=%d,", req->len );
+ fprintf( stderr, " name=" );
+ dump_unicode_string( req->name );
+ fprintf( stderr, "," );
+ fprintf( stderr, " data=" );
+ dump_varargs_enum_key_value_reply( req );
+}
+
+static void dump_delete_key_value_request( struct delete_key_value_request *req )
+{
+ fprintf( stderr, " hkey=%d,", req->hkey );
+ fprintf( stderr, " name=" );
+ dump_unicode_string( req->name );
+}
+
+static void dump_load_registry_request( struct load_registry_request *req )
+{
+ fprintf( stderr, " hkey=%d,", req->hkey );
+ fprintf( stderr, " file=%d,", req->file );
+ fprintf( stderr, " name=" );
+ dump_unicode_string( req->name );
+}
+
+static void dump_save_registry_request( struct save_registry_request *req )
+{
+ fprintf( stderr, " hkey=%d,", req->hkey );
+ fprintf( stderr, " file=%d", req->file );
+}
+
+static void dump_set_registry_levels_request( struct set_registry_levels_request *req )
+{
+ fprintf( stderr, " current=%d,", req->current );
+ fprintf( stderr, " saving=%d", req->saving );
}
static const dump_func req_dumpers[REQ_NB_REQUESTS] = {
@@ -891,6 +1067,19 @@
(dump_func)dump_debug_process_request,
(dump_func)dump_read_process_memory_request,
(dump_func)dump_write_process_memory_request,
+ (dump_func)dump_create_key_request,
+ (dump_func)dump_open_key_request,
+ (dump_func)dump_delete_key_request,
+ (dump_func)dump_close_key_request,
+ (dump_func)dump_enum_key_request,
+ (dump_func)dump_query_key_info_request,
+ (dump_func)dump_set_key_value_request,
+ (dump_func)dump_get_key_value_request,
+ (dump_func)dump_enum_key_value_request,
+ (dump_func)dump_delete_key_value_request,
+ (dump_func)dump_load_registry_request,
+ (dump_func)dump_save_registry_request,
+ (dump_func)dump_set_registry_levels_request,
};
static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {
@@ -967,6 +1156,19 @@
(dump_func)0,
(dump_func)dump_read_process_memory_reply,
(dump_func)0,
+ (dump_func)dump_create_key_reply,
+ (dump_func)dump_open_key_reply,
+ (dump_func)0,
+ (dump_func)0,
+ (dump_func)dump_enum_key_reply,
+ (dump_func)dump_query_key_info_reply,
+ (dump_func)0,
+ (dump_func)dump_get_key_value_reply,
+ (dump_func)dump_enum_key_value_reply,
+ (dump_func)0,
+ (dump_func)0,
+ (dump_func)0,
+ (dump_func)0,
};
static const char * const req_names[REQ_NB_REQUESTS] = {
@@ -1043,6 +1245,19 @@
"debug_process",
"read_process_memory",
"write_process_memory",
+ "create_key",
+ "open_key",
+ "delete_key",
+ "close_key",
+ "enum_key",
+ "query_key_info",
+ "set_key_value",
+ "get_key_value",
+ "enum_key_value",
+ "delete_key_value",
+ "load_registry",
+ "save_registry",
+ "set_registry_levels",
};
/* ### make_requests end ### */
diff --git a/server/unicode.h b/server/unicode.h
new file mode 100644
index 0000000..614f2ca
--- /dev/null
+++ b/server/unicode.h
@@ -0,0 +1,55 @@
+/*
+ * Unicode routines for use inside the server
+ *
+ * Copyright (C) 1999 Alexandre Julliard
+ */
+
+#ifndef __WINE_SERVER_UNICODE_H
+#define __WINE_SERVER_UNICODE_H
+
+#ifndef __WINE_SERVER__
+#error This file can only be used in the Wine server
+#endif
+
+#include "config.h"
+
+#include <ctype.h>
+#ifdef HAVE_WCTYPE_H
+#include <wctype.h>
+#endif
+
+#include "windef.h"
+
+static inline size_t strlenW( const WCHAR *str )
+{
+ const WCHAR *s = str;
+ while (*s) s++;
+ return s - str;
+}
+
+static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 )
+{
+ while (*str1 && (*str1 == *str2)) { str1++; str2++; }
+ return *str1 - *str2;
+}
+
+static inline int strcmpiW( const WCHAR *str1, const WCHAR *str2 )
+{
+ while (*str1 && (towupper(*str1) == towupper(*str2))) { str1++; str2++; }
+ return towupper(*str1) - towupper(*str2);
+}
+
+static inline WCHAR *strcpyW( WCHAR *src, const WCHAR *dst )
+{
+ const WCHAR *ret = dst;
+ while ((*src++ = *dst++));
+ return (WCHAR *)ret;
+}
+
+static inline WCHAR *strdupW( const WCHAR *str )
+{
+ size_t len = (strlenW(str) + 1) * sizeof(WCHAR);
+ return memdup( str, len );
+}
+
+#endif /* __WINE_SERVER_UNICODE_H */