Try2: Implement symbolic link object
Vitaliy Margolen
wine-patch at kievinfo.com
Tue Nov 29 19:27:33 CST 2005
This time using "symlink" everywhere. Also moved symlink initialization
into directory.c to keep it in one place with directories as suggested by
Robert.
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/directory.c | 28 ++++++-
server/object.h | 6 +
server/protocol.def | 32 ++++++++
server/symlink.c | 197 +++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 397 insertions(+), 46 deletions(-)
create mode 100644 server/symlink.c
-------------- next part --------------
a98e965bf0c6df33cf5392900199cdda4783faab
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/directory.c b/server/directory.c
index 716ad66..695433f 100644
--- a/server/directory.c
+++ b/server/directory.c
@@ -286,29 +286,49 @@ obj_handle_t open_object_dir( struct dir
/* Global initialization */
static struct directory *dir_global, *dir_driver, *dir_device, *dir_basenamed;
+static struct symlink *link_dosdev, *link_global1, *link_global2, *link_local;
void init_directories(void)
{
/* Directories */
- static const WCHAR dir_globalW[] = {'?','?'};
+ static const WCHAR dir_globalW[] = {'\\','?','?'};
static const WCHAR dir_driverW[] = {'D','r','i','v','e','r'};
static const WCHAR dir_deviceW[] = {'D','e','v','i','c','e'};
- static const WCHAR dir_basenamedW[] = {'B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s'};
+ 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_driver_str = {dir_driverW, sizeof(dir_driverW)};
static const struct unicode_str dir_device_str = {dir_deviceW, sizeof(dir_deviceW)};
static const struct unicode_str dir_basenamed_str = {dir_basenamedW, sizeof(dir_basenamedW)};
+ /* symlinks */
+ static const WCHAR link_dosdevW[] = {'D','o','s','D','e','v','i','c','e','s'};
+ static const WCHAR link_globalW[] = {'G','l','o','b','a','l'};
+ static const WCHAR link_localW[] = {'L','o','c','a','l'};
+ static const struct unicode_str link_dosdev_str = {link_dosdevW, sizeof(link_dosdevW)};
+ static const struct unicode_str link_global_str = {link_globalW, sizeof(link_globalW)};
+ static const struct unicode_str link_local_str = {link_localW, sizeof(link_localW)};
+
root_directory = create_directory( NULL, NULL, 0, HASH_SIZE );
- dir_global = create_directory( root_directory, &dir_global_str, 0, HASH_SIZE );
+ dir_global = create_directory( NULL, &dir_global_str, 0, HASH_SIZE );
dir_driver = create_directory( root_directory, &dir_driver_str, 0, HASH_SIZE );
dir_device = create_directory( root_directory, &dir_device_str, 0, HASH_SIZE );
/* use a larger hash table for this one since it can contain a lot of objects */
- dir_basenamed = create_directory( root_directory, &dir_basenamed_str, 0, 37 );
+ dir_basenamed = create_directory( NULL, &dir_basenamed_str, 0, 37 );
+
+ /* symlinks */
+ link_dosdev = create_symlink( root_directory, &link_dosdev_str, 0, &dir_global_str );
+ link_global1 = create_symlink( dir_global, &link_global_str, 0, &dir_global_str );
+ link_global2 = create_symlink( dir_basenamed, &link_global_str, 0, &dir_basenamed_str );
+ link_local = create_symlink( dir_basenamed, &link_local_str, 0, &dir_basenamed_str );
}
void close_directories(void)
{
+ release_object( link_dosdev );
+ release_object( link_global1 );
+ release_object( link_global2 );
+ release_object( link_local );
+
release_object( dir_global );
release_object( dir_driver );
release_object( dir_device );
diff --git a/server/object.h b/server/object.h
index 0c2ee1a..c30c137 100644
--- a/server/object.h
+++ b/server/object.h
@@ -193,6 +193,12 @@ extern obj_handle_t open_object_dir( str
extern void init_directories(void);
extern void close_directories(void);
+/* symbolic link functions */
+
+extern struct symlink *create_symlink( struct directory *root, const struct unicode_str *name,
+ unsigned int attr, const struct unicode_str *target );
+
+
/* global variables */
/* command-line options */
diff --git a/server/protocol.def b/server/protocol.def
index 56d0bc1..b1b19ff 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 symbolic 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 symbolic 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 symbolic 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/symlink.c b/server/symlink.c
new file mode 100644
index 0000000..10cb7a9
--- /dev/null
+++ b/server/symlink.c
@@ -0,0 +1,197 @@
+/*
+ * 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 symlink
+{
+ struct object obj; /* object header */
+ struct unicode_str target; /* target of the symlink */
+};
+
+static void symlink_dump( struct object *obj, int verbose );
+static struct object *symlink_lookup_name( struct object *obj, struct unicode_str *name,
+ unsigned int attr );
+static void symlink_destroy( struct object *obj );
+
+static const struct object_ops symlink_ops =
+{
+ sizeof(struct symlink), /* size */
+ symlink_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 */
+ symlink_destroy /* destroy */
+};
+
+static void symlink_dump( struct object *obj, int verbose )
+{
+ struct symlink *symlink = (struct symlink *)obj;
+ assert( obj->ops == &symlink_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 symlink *symlink = (struct symlink *)obj;
+ struct unicode_str lookup_name = *name; /* Need to preserve the name */
+ struct object *target;
+
+ assert( obj->ops == &symlink_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 symlink_destroy( struct object *obj )
+{
+ struct symlink *symlink = (struct symlink *)obj;
+ assert( obj->ops == &symlink_ops );
+ free( (WCHAR*)symlink->target.str );
+}
+
+struct symlink *create_symlink( struct directory *root, const struct unicode_str *name,
+ unsigned int attr, const struct unicode_str *target )
+{
+ struct symlink *symlink;
+
+ if (!target || !target->len)
+ {
+ set_error( STATUS_ACCESS_VIOLATION );
+ return NULL;
+ }
+
+ if ((symlink = create_named_object_dir( root, name, attr, &symlink_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 */
+
+
+void init_symlinks(void)
+{
+
+}
+
+/* create a symbolic link object */
+DECL_HANDLER(create_symlink)
+{
+ struct symlink *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_symlink( 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,
+ &symlink_ops, req->access );
+
+ if (root) release_object( root );
+}
+
+/* query a symbolic link object */
+DECL_HANDLER(query_symlink)
+{
+ struct symlink *symlink;
+
+ symlink = (struct symlink *)get_handle_obj( current->process, req->handle,
+ SYMBOLIC_LINK_QUERY, &symlink_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