Implement symbolic link object in wineserver.

Vitaliy Margolen wine-patch at kievinfo.com
Tue Nov 29 13:11:38 CST 2005


ChangeLog:
Implement symbolic link object in wineserver.
Implement Nt[Create|Open|Query]SymbolicLinkObject.
Change tests accordingly.

 dlls/ntdll/om.c       |  147 ++++++++++++++++++++++++++------
 dlls/ntdll/tests/om.c |   32 +++----
 server/Makefile.in    |    1 
 server/main.c         |    1 
 server/object.h       |    5 +
 server/protocol.def   |   32 +++++++
 server/request.c      |    1 
 server/symlink.c      |  225 +++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 402 insertions(+), 42 deletions(-)
 create mode 100644 server/symlink.c
-------------- next part --------------
9e09bb2117aac78b6a94c5d4f51b12e43bc16e5c
diff --git a/dlls/ntdll/om.c b/dlls/ntdll/om.c
index bd314a3..51c76a7 100644
--- a/dlls/ntdll/om.c
+++ b/dlls/ntdll/om.c
@@ -2,6 +2,7 @@
  *	Object management functions
  *
  * Copyright 1999, 2000 Juergen Schmied
+ * Copyright 2005 Vitaliy Margolen
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -470,45 +471,139 @@ NTSTATUS WINAPI NtQueryDirectoryObject(I
 
 /******************************************************************************
  *  NtOpenSymbolicLinkObject	[NTDLL.@]
+ *  ZwOpenSymbolicLinkObject	[NTDLL.@]
+ *
+ * Open a namespace symbolic link object.
+ * 
+ * PARAMS
+ *  LinkHandle       [O] Destination for the new symbolic link handle
+ *  DesiredAccess    [I] Desired access to the symbolic link
+ *  ObjectAttributes [I] Structure describing the symbolic link
+ *
+ * RETURNS
+ *  Success: ERROR_SUCCESS.
+ *  Failure: An NTSTATUS error code.
  */
-NTSTATUS WINAPI NtOpenSymbolicLinkObject(
-	OUT PHANDLE LinkHandle,
-	IN ACCESS_MASK DesiredAccess,
-	IN POBJECT_ATTRIBUTES ObjectAttributes)
-{
-	FIXME("(%p,0x%08lx,%p) stub\n",
-	LinkHandle, DesiredAccess, ObjectAttributes);
-	dump_ObjectAttributes(ObjectAttributes);
-        return STATUS_OBJECT_NAME_NOT_FOUND;
+NTSTATUS WINAPI NtOpenSymbolicLinkObject(OUT PHANDLE LinkHandle, IN ACCESS_MASK DesiredAccess,
+                                         IN POBJECT_ATTRIBUTES ObjectAttributes)
+{
+    NTSTATUS ret;
+    TRACE("(%p,0x%08lx,%p)\n",LinkHandle, DesiredAccess, ObjectAttributes);
+    dump_ObjectAttributes(ObjectAttributes);
+
+    if (!LinkHandle) return STATUS_ACCESS_VIOLATION;
+    if (!ObjectAttributes) return STATUS_INVALID_PARAMETER;
+    /* Have to test it here because server won't know difference between
+     * ObjectName == NULL and ObjectName == "" */
+    if (!ObjectAttributes->ObjectName)
+    {
+        if (ObjectAttributes->RootDirectory)
+            return STATUS_OBJECT_NAME_INVALID;
+        else
+            return STATUS_OBJECT_PATH_SYNTAX_BAD;
+    }
+
+    SERVER_START_REQ(open_symlink)
+    {
+        req->access = DesiredAccess;
+        req->attributes = ObjectAttributes ? ObjectAttributes->Attributes : 0;
+        req->rootdir = ObjectAttributes ? ObjectAttributes->RootDirectory : 0;
+        if (ObjectAttributes->ObjectName)
+            wine_server_add_data(req, ObjectAttributes->ObjectName->Buffer,
+                                 ObjectAttributes->ObjectName->Length);
+        ret = wine_server_call( req );
+        *LinkHandle = reply->handle;
+    }
+    SERVER_END_REQ;
+    return ret;
 }
 
 /******************************************************************************
  *  NtCreateSymbolicLinkObject	[NTDLL.@]
+ *  ZwCreateSymbolicLinkObject	[NTDLL.@]
+ *
+ * Open a namespace symbolic link object.
+ * 
+ * PARAMS
+ *  SymbolicLinkHandle [O] Destination for the new symbolic link handle
+ *  DesiredAccess      [I] Desired access to the symbolic link
+ *  ObjectAttributes   [I] Structure describing the symbolic link
+ *  TargetName         [I] Name of the target symbolic link points to
+ *
+ * RETURNS
+ *  Success: ERROR_SUCCESS.
+ *  Failure: An NTSTATUS error code.
  */
-NTSTATUS WINAPI NtCreateSymbolicLinkObject(
-	OUT PHANDLE SymbolicLinkHandle,
-	IN ACCESS_MASK DesiredAccess,
-	IN POBJECT_ATTRIBUTES ObjectAttributes,
-	IN PUNICODE_STRING Name)
-{
-	FIXME("(%p,0x%08lx,%p, %p) stub\n",
-	SymbolicLinkHandle, DesiredAccess, ObjectAttributes, debugstr_us(Name));
-	dump_ObjectAttributes(ObjectAttributes);
-	return 0;
+NTSTATUS WINAPI NtCreateSymbolicLinkObject(OUT PHANDLE SymbolicLinkHandle,IN ACCESS_MASK DesiredAccess,
+	                                   IN POBJECT_ATTRIBUTES ObjectAttributes,
+                                           IN PUNICODE_STRING TargetName)
+{
+    NTSTATUS ret;
+    TRACE("(%p,0x%08lx,%p, -> %s)\n", SymbolicLinkHandle, DesiredAccess, ObjectAttributes,
+                                      debugstr_us(TargetName));
+    dump_ObjectAttributes(ObjectAttributes);
+
+    if (!SymbolicLinkHandle || !TargetName) return STATUS_ACCESS_VIOLATION;
+    if (!TargetName->Buffer) return STATUS_INVALID_PARAMETER;
+
+    SERVER_START_REQ(create_symlink)
+    {
+        req->access = DesiredAccess;
+        req->attributes = ObjectAttributes ? ObjectAttributes->Attributes : 0;
+        req->rootdir = ObjectAttributes ? ObjectAttributes->RootDirectory : 0;
+        if (ObjectAttributes->ObjectName)
+        {
+            req->symlink_name_len = ObjectAttributes->ObjectName->Length;
+            wine_server_add_data(req, ObjectAttributes->ObjectName->Buffer,
+                                 ObjectAttributes->ObjectName->Length);
+        }
+        else
+            req->symlink_name_len = 0;
+        wine_server_add_data(req, TargetName->Buffer, TargetName->Length);
+        ret = wine_server_call( req );
+        *SymbolicLinkHandle = reply->handle;
+    }
+    SERVER_END_REQ;
+    return ret;
 }
 
 /******************************************************************************
  *  NtQuerySymbolicLinkObject	[NTDLL.@]
+ *  ZwQuerySymbolicLinkObject	[NTDLL.@]
+ *
+ * Query a namespace symbolic link object target name.
+ * 
+ * PARAMS
+ *  LinkHandle     [I] Handle to a symbolic link object
+ *  LinkTarget     [O] Destination for the symbolic link target
+ *  ReturnedLength [O] Size of returned data
+ *
+ * RETURNS
+ *  Success: ERROR_SUCCESS.
+ *  Failure: An NTSTATUS error code.
  */
-NTSTATUS WINAPI NtQuerySymbolicLinkObject(
-	IN HANDLE LinkHandle,
-	IN OUT PUNICODE_STRING LinkTarget,
-	OUT PULONG ReturnedLength OPTIONAL)
+NTSTATUS WINAPI NtQuerySymbolicLinkObject(IN HANDLE LinkHandle, IN OUT PUNICODE_STRING LinkTarget,
+                                          OUT PULONG ReturnedLength OPTIONAL)
 {
-	FIXME("(%p,%p,%p) stub\n",
-	LinkHandle, debugstr_us(LinkTarget), ReturnedLength);
+    NTSTATUS ret;
+    TRACE("(%p,%p,%p)\n", LinkHandle, LinkTarget, ReturnedLength);
 
-	return 0;
+    if (!LinkTarget) return STATUS_ACCESS_VIOLATION;
+
+    SERVER_START_REQ(query_symlink)
+    {
+        req->handle = LinkHandle;
+        wine_server_set_reply( req, LinkTarget->Buffer, LinkTarget->MaximumLength );
+        if (!(ret = wine_server_call( req )))
+        {
+            size_t len = wine_server_reply_size(reply);
+            LinkTarget->Length = len;
+            LinkTarget->MaximumLength = len;
+            if (ReturnedLength) *ReturnedLength = len;
+        }
+    }
+    SERVER_END_REQ;
+    return ret;
 }
 
 /******************************************************************************
diff --git a/dlls/ntdll/tests/om.c b/dlls/ntdll/tests/om.c
index 747c477..ce47bea 100644
--- a/dlls/ntdll/tests/om.c
+++ b/dlls/ntdll/tests/om.c
@@ -336,11 +336,11 @@ void test_directory(void)
     pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\Local");
     InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
     status = pNtOpenSymbolicLinkObject(&dir, SYMBOLIC_LINK_QUERY, &attr);\
-    todo_wine ok(status == STATUS_SUCCESS, "Failed to open SymbolicLink(%08lx)\n", status);
+    ok(status == STATUS_SUCCESS, "Failed to open SymbolicLink(%08lx)\n", status);
     pRtlFreeUnicodeString(&str);
     InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
     pRtlCreateUnicodeStringFromAsciiz(&str, "one more level");
-    todo_wine{ DIR_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_TYPE_MISMATCH) }
+    DIR_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_TYPE_MISMATCH)
     pRtlFreeUnicodeString(&str);
     pNtClose(h);
     pNtClose(dir);
@@ -396,15 +396,15 @@ void test_directory(void)
 
     InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
     pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\Global\\om.c-test");
-    todo_wine{ DIR_TEST_CREATE_SUCCESS(&dir) }
+    DIR_TEST_CREATE_SUCCESS(&dir)
     pRtlFreeUnicodeString(&str);
     pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\Local\\om.c-test\\one more level");
-    todo_wine{ DIR_TEST_CREATE_SUCCESS(&h) }
+    DIR_TEST_CREATE_SUCCESS(&h)
     pRtlFreeUnicodeString(&str);
     pNtClose(h);
     InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
     pRtlCreateUnicodeStringFromAsciiz(&str, "one more level");
-    todo_wine{ DIR_TEST_CREATE_SUCCESS(&dir) }
+    DIR_TEST_CREATE_SUCCESS(&dir)
     pRtlFreeUnicodeString(&str);
     pNtClose(h);
 
@@ -476,18 +476,18 @@ void test_symboliclink(void)
     IO_STATUS_BLOCK iosb;
 
     /* No name and/or no attributes */
-    todo_wine{ SYMLNK_TEST_CREATE_OPEN_FAILURE(NULL, "", "", STATUS_ACCESS_VIOLATION) }
+    SYMLNK_TEST_CREATE_OPEN_FAILURE(NULL, "", "", STATUS_ACCESS_VIOLATION)
 
     status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL, NULL);
-    todo_wine ok(status == STATUS_ACCESS_VIOLATION,
+    ok(status == STATUS_ACCESS_VIOLATION,
         "NtCreateSymbolicLinkObject should have failed with STATUS_ACCESS_VIOLATION got(%08lx)\n", status);
     status = pNtOpenSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL);
-    todo_wine ok(status == STATUS_INVALID_PARAMETER,
+    ok(status == STATUS_INVALID_PARAMETER,
         "NtOpenSymbolicLinkObject should have failed with STATUS_INVALID_PARAMETER got(%08lx)\n", status);
 
     InitializeObjectAttributes(&attr, NULL, 0, 0, NULL);
-    todo_wine{ SYMLNK_TEST_CREATE_FAILURE(&link, STATUS_INVALID_PARAMETER) }
-    todo_wine{ SYMLNK_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_PATH_SYNTAX_BAD) }
+    SYMLNK_TEST_CREATE_FAILURE(&link, STATUS_INVALID_PARAMETER)
+    SYMLNK_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_PATH_SYNTAX_BAD)
 
     /* Bad name */
     pRtlCreateUnicodeStringFromAsciiz(&target, "anywhere");
@@ -495,7 +495,7 @@ void test_symboliclink(void)
 
     pRtlCreateUnicodeStringFromAsciiz(&str, "");
     SYMLNK_TEST_CREATE_SUCCESS(&link)
-    todo_wine{ SYMLNK_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_PATH_SYNTAX_BAD) }
+    SYMLNK_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_PATH_SYNTAX_BAD)
     pNtClose(link);
     pRtlFreeUnicodeString(&str);
 
@@ -504,11 +504,11 @@ void test_symboliclink(void)
     pRtlFreeUnicodeString(&str);
     pRtlFreeUnicodeString(&target);
 
-    todo_wine{ SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "BaseNamedObjects", "->Somewhere", STATUS_OBJECT_PATH_SYNTAX_BAD) }
-    todo_wine{ SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\", "->Somewhere", STATUS_OBJECT_NAME_INVALID) }
-    todo_wine{ SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\\\BaseNamedObjects", "->Somewhere", STATUS_OBJECT_NAME_INVALID) }
-    todo_wine{ SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\\\om.c-test", "->Somewhere", STATUS_OBJECT_NAME_INVALID) }
-    todo_wine{ SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\om.c-test\\", "->Somewhere", STATUS_OBJECT_NAME_INVALID) }
+    SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "BaseNamedObjects", "->Somewhere", STATUS_OBJECT_PATH_SYNTAX_BAD)
+    SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
+    SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\\\BaseNamedObjects", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
+    SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\\\om.c-test", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
+    SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\om.c-test\\", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
 
 
     /* Compaund test */
diff --git a/server/Makefile.in b/server/Makefile.in
index 50a5049..ee4a15a 100644
--- a/server/Makefile.in
+++ b/server/Makefile.in
@@ -40,6 +40,7 @@ C_SRCS = \
 	signal.c \
 	snapshot.c \
 	sock.c \
+	symlink.c \
 	thread.c \
 	timer.c \
 	token.c \
diff --git a/server/main.c b/server/main.c
index 7f07aac..09846ea 100644
--- a/server/main.c
+++ b/server/main.c
@@ -136,6 +136,7 @@ int main( int argc, char *argv[] )
     if (debug_level) fprintf( stderr, "wineserver: starting (pid=%ld)\n", (long) getpid() );
     init_signals();
     init_directories();
+    init_syboliclinks();
     init_registry();
     main_loop();
     return 0;
diff --git a/server/object.h b/server/object.h
index 0c2ee1a..1154e0a 100644
--- a/server/object.h
+++ b/server/object.h
@@ -193,6 +193,11 @@ extern obj_handle_t open_object_dir( str
 extern void init_directories(void);
 extern void close_directories(void);
 
+/* sybmolic link functions */
+
+extern void init_syboliclinks(void);
+extern void close_syboliclinks(void);
+
 /* global variables */
 
   /* command-line options */
diff --git a/server/protocol.def b/server/protocol.def
index 56d0bc1..f6c91af 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -2527,3 +2527,35 @@ enum message_type
 @REPLY
     obj_handle_t   handle;        /* handle to the directory */
 @END
+
+
+/* Create symbolik link */
+ at REQ(create_symlink)
+    unsigned int   access;        /* access flags */
+    unsigned int   attributes;    /* object attributes */
+    obj_handle_t   rootdir;       /* root directory */
+    size_t         symlink_name_len; /* length of target_name in bytes */
+    VARARG(symlink_name,unicode_str,symlink_name_len); /* SymbolicLink name */
+    VARARG(target_name,unicode_str); /* Target name */
+ at REPLY
+    obj_handle_t   handle;        /* handle to the symlink */
+ at END
+
+
+/* Open symbolik link */
+ at REQ(open_symlink)
+    unsigned int   access;        /* access flags */
+    unsigned int   attributes;    /* object attributes */
+    obj_handle_t   rootdir;       /* root directory */
+    VARARG(symlink_name,unicode_str); /* SymbolicLink name */
+ at REPLY
+    obj_handle_t   handle;        /* handle to the symlink */
+ at END
+
+
+/* Query symbolik link */
+ at REQ(query_symlink)
+    obj_handle_t   handle;        /* handle to the symlink */
+ at REPLY
+    VARARG(target_name,unicode_str); /* Target name */
+ at END
diff --git a/server/request.c b/server/request.c
index 7c3b50a..8080fba 100644
--- a/server/request.c
+++ b/server/request.c
@@ -801,6 +801,7 @@ static void close_socket_timeout( void *
     close_signals();
     close_global_handles();
     close_registry();
+    close_syboliclinks();
     close_directories();
     dump_objects();  /* dump any remaining objects */
 #else
diff --git a/server/symlink.c b/server/symlink.c
new file mode 100644
index 0000000..5a07df3
--- /dev/null
+++ b/server/symlink.c
@@ -0,0 +1,225 @@
+/*
+ * Server-side symbolic link object management
+ *
+ * Copyright (C) 2005 Vitaliy Margolen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include <assert.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+
+#include "ntstatus.h"
+#define WIN32_NO_STATUS
+#include "winternl.h"
+#include "ddk/wdm.h"
+
+#include "handle.h"
+#include "request.h"
+#include "object.h"
+#include "unicode.h"
+
+struct syboliclink
+{
+    struct object      obj;       /* object header */
+    struct unicode_str target;    /* target of the symlink */
+};
+
+static void syboliclink_dump( struct object *obj, int verbose );
+static struct object *symlink_lookup_name( struct object *obj, struct unicode_str *name,
+                                           unsigned int attr );
+static void syboliclink_destroy( struct object *obj );
+
+static const struct object_ops syboliclink_ops =
+{
+    sizeof(struct syboliclink),   /* size */
+    syboliclink_dump,             /* dump */
+    no_add_queue,                 /* add_queue */
+    NULL,                         /* remove_queue */
+    NULL,                         /* signaled */
+    NULL,                         /* satisfied */
+    no_signal,                    /* signal */
+    no_get_fd,                    /* get_fd */
+    symlink_lookup_name,          /* lookup_name */
+    no_close_handle,              /* close_handle */
+    syboliclink_destroy           /* destroy */
+};
+
+static void syboliclink_dump( struct object *obj, int verbose )
+{
+    struct syboliclink *symlink = (struct syboliclink *)obj;
+    assert( obj->ops == &syboliclink_ops );
+
+    fputs( "Symbolic Link ", stderr );
+    dump_object_name( obj );
+    fprintf( stderr, " -> L\"" );
+    dump_strW( symlink->target.str, symlink->target.len / sizeof(WCHAR), stderr, "\"\"" );
+    fputs( "\"\n", stderr );
+}
+
+static struct object *symlink_lookup_name( struct object *obj, struct unicode_str *name,
+                                           unsigned int attr )
+{
+    struct syboliclink *symlink = (struct syboliclink *)obj;
+    struct unicode_str lookup_name = *name; /* Need to preserve the name */
+    struct object *target;
+
+    assert( obj->ops == &syboliclink_ops );
+    if (attr & OBJ_OPENLINK) return NULL;
+
+    if ((target = find_object_dir( NULL, &symlink->target, attr, name )))
+    {
+        if (!name->len)
+            *name = lookup_name;
+        else
+        {
+            release_object( target );
+            target = NULL;
+        }
+    }
+    return target;
+}
+
+static void syboliclink_destroy( struct object *obj )
+{
+    struct syboliclink *symlink = (struct syboliclink *)obj;
+    assert( obj->ops == &syboliclink_ops );
+    free( (WCHAR*)symlink->target.str );
+}
+
+struct syboliclink *create_syboliclink( struct directory *root, const struct unicode_str *name,
+                                        unsigned int attr, const struct unicode_str *target )
+{
+    struct syboliclink *symlink;
+
+    if (!target || !target->len)
+    {
+        set_error( STATUS_ACCESS_VIOLATION );
+        return NULL;
+    }
+
+    if ((symlink = create_named_object_dir( root, name, attr, &syboliclink_ops )) &&
+        (get_error() != STATUS_OBJECT_NAME_EXISTS))
+    {
+        if ((symlink->target.str = memdup( target->str, target->len )))
+            symlink->target.len = target->len;
+        else
+        {
+            release_object( symlink );
+            symlink = NULL;
+        }
+    }
+    return symlink;
+}
+
+/* Global initialization */
+
+static struct syboliclink *link_dosdev, *link_global1, *link_global2, *link_local;
+
+void init_syboliclinks(void)
+{
+    static const WCHAR dir_globalW[] = {'\\','?','?'};
+    static const WCHAR dir_basenamedW[] = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s'};
+    static const struct unicode_str dir_global_str = {dir_globalW, sizeof(dir_globalW)};
+    static const struct unicode_str dir_basenamed_str = {dir_basenamedW, sizeof(dir_basenamedW)};
+
+    static const WCHAR link_dosdevW[]  = {'\\','D','o','s','D','e','v','i','c','e','s'};
+    static const WCHAR link_global1W[] = {'\\','?','?','\\','G','l','o','b','a','l'};
+    static const WCHAR link_global2W[] = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s','\\','G','l','o','b','a','l'};
+    static const WCHAR link_localW[]   = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s','\\','L','o','c','a','l'};
+    static const struct unicode_str link_dosdev_str = {link_dosdevW, sizeof(link_dosdevW)};
+    static const struct unicode_str link_global1_str = {link_global1W, sizeof(link_global1W)};
+    static const struct unicode_str link_global2_str = {link_global2W, sizeof(link_global2W)};
+    static const struct unicode_str link_local_str = {link_localW, sizeof(link_localW)};
+
+    link_dosdev  = create_syboliclink( NULL, &link_dosdev_str, 0, &dir_global_str );
+    link_global1 = create_syboliclink( NULL, &link_global1_str, 0, &dir_global_str );
+    link_global2 = create_syboliclink( NULL, &link_global2_str, 0, &dir_basenamed_str );
+    link_local   = create_syboliclink( NULL, &link_local_str, 0, &dir_basenamed_str );
+}
+
+void close_syboliclinks(void)
+{
+    release_object( link_dosdev );
+    release_object( link_global1 );
+    release_object( link_global2 );
+    release_object( link_local );
+}
+
+
+/* create a symbolic link object */
+DECL_HANDLER(create_symlink)
+{
+    struct syboliclink *symlink;
+    struct unicode_str name, target;
+    struct directory *root = NULL;
+
+    get_req_unicode_str( &name );
+    target.str = name.str + req->symlink_name_len / sizeof(WCHAR);
+    target.len = name.len - req->symlink_name_len;
+    name.len = req->symlink_name_len;
+    
+    if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
+        return;
+
+    if ((symlink = create_syboliclink( root, &name, req->attributes, &target )))
+    {
+        reply->handle = alloc_handle( current->process, symlink, req->access,
+                                      req->attributes & OBJ_INHERIT );
+        release_object( symlink );
+    }
+
+    if (root) release_object( root );
+}
+
+/* open a symbolic link object */
+DECL_HANDLER(open_symlink)
+{
+    struct unicode_str name;
+    struct directory *root = NULL;
+
+    get_req_unicode_str( &name );
+    if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
+        return;
+
+    reply->handle = open_object_dir( root, &name, req->attributes | OBJ_OPENLINK,
+                                     &syboliclink_ops, req->access );
+
+    if (root) release_object( root );
+}
+
+/* query a symbolic link object */
+DECL_HANDLER(query_symlink)
+{
+    struct syboliclink *symlink;
+
+    symlink = (struct syboliclink *)get_handle_obj( current->process, req->handle,
+                                                    SYMBOLIC_LINK_QUERY,
+                                                    &syboliclink_ops );
+    if (!symlink) return;
+
+    if (get_reply_max_size() < symlink->target.len)
+        set_error( STATUS_BUFFER_TOO_SMALL );
+    else
+        set_reply_data( symlink->target.str, symlink->target.len );
+    release_object( symlink );
+}


More information about the wine-patches mailing list