2005-11-30 19:22:57 +01:00
|
|
|
/*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-11-30 19:22:57 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.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"
|
|
|
|
|
2021-02-04 13:44:18 +01:00
|
|
|
static const WCHAR symlink_name[] = {'S','y','m','b','o','l','i','c','L','i','n','k'};
|
|
|
|
|
|
|
|
struct type_descr symlink_type =
|
|
|
|
{
|
|
|
|
{ symlink_name, sizeof(symlink_name) }, /* name */
|
2021-02-05 12:08:42 +01:00
|
|
|
SYMBOLIC_LINK_ALL_ACCESS, /* valid_access */
|
|
|
|
{ /* mapping */
|
|
|
|
STANDARD_RIGHTS_READ | SYMBOLIC_LINK_QUERY,
|
|
|
|
STANDARD_RIGHTS_WRITE,
|
|
|
|
STANDARD_RIGHTS_EXECUTE | SYMBOLIC_LINK_QUERY,
|
|
|
|
SYMBOLIC_LINK_ALL_ACCESS
|
|
|
|
},
|
2021-02-04 13:44:18 +01:00
|
|
|
};
|
|
|
|
|
2005-11-30 19:22:57 +01:00
|
|
|
struct symlink
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
WCHAR *target; /* target of the symlink */
|
2006-07-26 10:43:25 +02:00
|
|
|
data_size_t len; /* target len in bytes */
|
2005-11-30 19:22:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void symlink_dump( struct object *obj, int verbose );
|
|
|
|
static struct object *symlink_lookup_name( struct object *obj, struct unicode_str *name,
|
2020-11-25 19:42:42 +01:00
|
|
|
unsigned int attr, struct object *root );
|
2005-11-30 19:22:57 +01:00
|
|
|
static void symlink_destroy( struct object *obj );
|
|
|
|
|
|
|
|
static const struct object_ops symlink_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct symlink), /* size */
|
2021-02-04 13:44:18 +01:00
|
|
|
&symlink_type, /* type */
|
2005-11-30 19:22:57 +01:00
|
|
|
symlink_dump, /* dump */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
no_get_fd, /* get_fd */
|
2021-02-05 12:10:44 +01:00
|
|
|
default_map_access, /* map_access */
|
2007-10-03 14:10:37 +02:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2020-09-22 16:52:31 +02:00
|
|
|
default_get_full_name, /* get_full_name */
|
2005-11-30 19:22:57 +01:00
|
|
|
symlink_lookup_name, /* lookup_name */
|
2016-02-04 13:08:02 +01:00
|
|
|
directory_link_name, /* link_name */
|
|
|
|
default_unlink_name, /* unlink_name */
|
2007-03-22 11:44:29 +01:00
|
|
|
no_open_file, /* open_file */
|
2019-03-25 14:37:09 +01:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2005-11-30 19:22:57 +01:00
|
|
|
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 );
|
|
|
|
|
2016-01-21 13:08:56 +01:00
|
|
|
fputs( "Symlink target=\"", stderr );
|
2020-03-21 11:36:33 +01:00
|
|
|
dump_strW( symlink->target, symlink->len, stderr, "\"\"" );
|
2016-01-21 13:08:56 +01:00
|
|
|
fputs( "\"\n", stderr );
|
2005-11-30 19:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct object *symlink_lookup_name( struct object *obj, struct unicode_str *name,
|
2020-11-25 19:42:42 +01:00
|
|
|
unsigned int attr, struct object *root )
|
2005-11-30 19:22:57 +01:00
|
|
|
{
|
|
|
|
struct symlink *symlink = (struct symlink *)obj;
|
|
|
|
struct unicode_str target_str, name_left;
|
|
|
|
struct object *target;
|
|
|
|
|
|
|
|
assert( obj->ops == &symlink_ops );
|
2016-02-09 12:16:27 +01:00
|
|
|
|
|
|
|
if (!name) return NULL;
|
2008-10-09 12:43:36 +02:00
|
|
|
if (!name->len && (attr & OBJ_OPENLINK)) return NULL;
|
2020-11-25 19:42:42 +01:00
|
|
|
if (obj == root) return NULL;
|
2005-11-30 19:22:57 +01:00
|
|
|
|
2021-11-24 17:29:29 +01:00
|
|
|
if (!symlink->len) return get_root_directory();
|
|
|
|
|
2005-11-30 19:22:57 +01:00
|
|
|
target_str.str = symlink->target;
|
|
|
|
target_str.len = symlink->len;
|
2016-02-09 12:16:27 +01:00
|
|
|
if ((target = lookup_named_object( NULL, &target_str, attr, &name_left )))
|
2005-11-30 19:22:57 +01:00
|
|
|
{
|
|
|
|
if (name_left.len)
|
|
|
|
{
|
|
|
|
release_object( target );
|
|
|
|
target = NULL;
|
|
|
|
set_error( STATUS_OBJECT_PATH_NOT_FOUND );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void symlink_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct symlink *symlink = (struct symlink *)obj;
|
|
|
|
assert( obj->ops == &symlink_ops );
|
|
|
|
free( symlink->target );
|
|
|
|
}
|
|
|
|
|
2021-11-24 17:29:29 +01:00
|
|
|
struct object *create_root_symlink( struct object *root, const struct unicode_str *name,
|
|
|
|
unsigned int attr, const struct security_descriptor *sd )
|
|
|
|
{
|
|
|
|
struct symlink *symlink;
|
|
|
|
|
|
|
|
if (!(symlink = create_named_object( root, &symlink_ops, name, attr, sd ))) return NULL;
|
|
|
|
symlink->target = NULL;
|
|
|
|
symlink->len = 0;
|
|
|
|
return &symlink->obj;
|
|
|
|
}
|
|
|
|
|
2020-06-25 22:27:19 +02:00
|
|
|
struct object *create_symlink( struct object *root, const struct unicode_str *name,
|
|
|
|
unsigned int attr, const struct unicode_str *target,
|
|
|
|
const struct security_descriptor *sd )
|
2005-11-30 19:22:57 +01:00
|
|
|
{
|
|
|
|
struct symlink *symlink;
|
|
|
|
|
|
|
|
if (!target->len)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-06-25 22:27:19 +02:00
|
|
|
if (!(symlink = create_named_object( root, &symlink_ops, name, attr, sd ))) return NULL;
|
|
|
|
if (get_error() != STATUS_OBJECT_NAME_EXISTS && !(symlink->target = memdup( target->str, target->len )))
|
2005-11-30 19:22:57 +01:00
|
|
|
{
|
2020-06-25 22:27:19 +02:00
|
|
|
release_object( symlink );
|
|
|
|
return NULL;
|
2005-11-30 19:22:57 +01:00
|
|
|
}
|
2020-06-25 22:27:19 +02:00
|
|
|
symlink->len = target->len;
|
|
|
|
return &symlink->obj;
|
2005-11-30 19:22:57 +01:00
|
|
|
}
|
|
|
|
|
2016-07-18 08:34:08 +02:00
|
|
|
/* create a symlink pointing to an existing object */
|
|
|
|
struct object *create_obj_symlink( struct object *root, const struct unicode_str *name,
|
|
|
|
unsigned int attr, struct object *target,
|
|
|
|
const struct security_descriptor *sd )
|
|
|
|
{
|
|
|
|
struct symlink *symlink;
|
|
|
|
data_size_t len;
|
|
|
|
WCHAR *target_name;
|
|
|
|
|
2020-09-22 16:52:31 +02:00
|
|
|
if (!(target_name = target->ops->get_full_name( target, &len )))
|
2016-07-18 08:34:08 +02:00
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if ((symlink = create_named_object( root, &symlink_ops, name, attr, sd )) &&
|
|
|
|
(get_error() != STATUS_OBJECT_NAME_EXISTS))
|
|
|
|
{
|
|
|
|
symlink->target = target_name;
|
|
|
|
symlink->len = len;
|
|
|
|
}
|
|
|
|
else free( target_name );
|
|
|
|
|
|
|
|
return &symlink->obj;
|
|
|
|
}
|
|
|
|
|
2005-11-30 19:22:57 +01:00
|
|
|
|
|
|
|
/* create a symbolic link object */
|
|
|
|
DECL_HANDLER(create_symlink)
|
|
|
|
{
|
2020-06-25 22:27:19 +02:00
|
|
|
struct object *symlink;
|
2005-11-30 19:22:57 +01:00
|
|
|
struct unicode_str name, target;
|
2016-02-12 13:00:41 +01:00
|
|
|
struct object *root;
|
2016-01-15 12:33:20 +01:00
|
|
|
const struct security_descriptor *sd;
|
2016-02-01 06:57:37 +01:00
|
|
|
const struct object_attributes *objattr = get_req_object_attributes( &sd, &name, &root );
|
2005-11-30 19:22:57 +01:00
|
|
|
|
2016-01-15 12:33:20 +01:00
|
|
|
if (!objattr) return;
|
|
|
|
|
2016-01-19 07:00:21 +01:00
|
|
|
target.str = get_req_data_after_objattr( objattr, &target.len );
|
|
|
|
target.len = (target.len / sizeof(WCHAR)) * sizeof(WCHAR);
|
2005-11-30 19:22:57 +01:00
|
|
|
|
2016-01-15 12:33:20 +01:00
|
|
|
if ((symlink = create_symlink( root, &name, objattr->attributes, &target, sd )))
|
2005-11-30 19:22:57 +01:00
|
|
|
{
|
2016-01-15 12:33:20 +01:00
|
|
|
reply->handle = alloc_handle( current->process, symlink, req->access, objattr->attributes );
|
2005-11-30 19:22:57 +01:00
|
|
|
release_object( symlink );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (root) release_object( root );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open a symbolic link object */
|
|
|
|
DECL_HANDLER(open_symlink)
|
|
|
|
{
|
2016-01-29 08:36:45 +01:00
|
|
|
struct unicode_str name = get_req_unicode_str();
|
2005-11-30 19:22:57 +01:00
|
|
|
|
2016-01-29 08:23:29 +01:00
|
|
|
reply->handle = open_object( current->process, req->rootdir, req->access,
|
|
|
|
&symlink_ops, &name, req->attributes | OBJ_OPENLINK );
|
2005-11-30 19:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2010-06-30 16:11:03 +02:00
|
|
|
reply->total = symlink->len;
|
2005-11-30 19:22:57 +01:00
|
|
|
if (get_reply_max_size() < symlink->len)
|
|
|
|
set_error( STATUS_BUFFER_TOO_SMALL );
|
|
|
|
else
|
|
|
|
set_reply_data( symlink->target, symlink->len );
|
|
|
|
release_object( symlink );
|
|
|
|
}
|