2005-11-29 17:21:05 +01:00
|
|
|
/*
|
|
|
|
* Server-side directory 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-29 17:21:05 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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 "process.h"
|
2007-10-02 14:20:15 +02:00
|
|
|
#include "file.h"
|
2005-11-29 17:21:05 +01:00
|
|
|
#include "unicode.h"
|
|
|
|
|
|
|
|
#define HASH_SIZE 7 /* default hash size */
|
|
|
|
|
2007-12-05 18:16:42 +01:00
|
|
|
struct object_type
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void object_type_dump( struct object *obj, int verbose );
|
|
|
|
static struct object_type *object_type_get_type( struct object *obj );
|
|
|
|
|
|
|
|
static const struct object_ops object_type_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct object_type), /* size */
|
|
|
|
object_type_dump, /* dump */
|
|
|
|
object_type_get_type, /* get_type */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
no_get_fd, /* get_fd */
|
|
|
|
no_map_access, /* map_access */
|
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
|
|
|
no_lookup_name, /* lookup_name */
|
2016-02-04 13:08:02 +01:00
|
|
|
directory_link_name, /* link_name */
|
|
|
|
default_unlink_name, /* unlink_name */
|
2007-12-05 18:16:42 +01:00
|
|
|
no_open_file, /* open_file */
|
|
|
|
no_close_handle, /* close_handle */
|
|
|
|
no_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-11-29 17:21:05 +01:00
|
|
|
struct directory
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
struct namespace *entries; /* directory's name space */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void directory_dump( struct object *obj, int verbose );
|
2007-12-05 18:16:42 +01:00
|
|
|
static struct object_type *directory_get_type( struct object *obj );
|
2005-11-29 17:21:05 +01:00
|
|
|
static struct object *directory_lookup_name( struct object *obj, struct unicode_str *name,
|
|
|
|
unsigned int attr );
|
|
|
|
static void directory_destroy( struct object *obj );
|
|
|
|
|
|
|
|
static const struct object_ops directory_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct directory), /* size */
|
|
|
|
directory_dump, /* dump */
|
2007-12-05 18:16:42 +01:00
|
|
|
directory_get_type, /* get_type */
|
2005-11-29 17:21:05 +01:00
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
no_get_fd, /* get_fd */
|
2007-10-02 14:20:15 +02:00
|
|
|
default_fd_map_access, /* map_access */
|
2007-10-03 14:10:37 +02:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2005-11-29 17:21:05 +01:00
|
|
|
directory_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 */
|
2005-11-29 17:21:05 +01:00
|
|
|
no_close_handle, /* close_handle */
|
|
|
|
directory_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct directory *root_directory;
|
2007-12-05 18:16:42 +01:00
|
|
|
static struct directory *dir_objtype;
|
2005-11-29 17:21:05 +01:00
|
|
|
|
|
|
|
|
2007-12-05 18:16:42 +01:00
|
|
|
static void object_type_dump( struct object *obj, int verbose )
|
|
|
|
{
|
2016-01-21 13:08:56 +01:00
|
|
|
fputs( "Object type\n", stderr );
|
2007-12-05 18:16:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct object_type *object_type_get_type( struct object *obj )
|
|
|
|
{
|
|
|
|
static const WCHAR name[] = {'O','b','j','e','c','t','T','y','p','e'};
|
|
|
|
static const struct unicode_str str = { name, sizeof(name) };
|
|
|
|
return get_object_type( &str );
|
|
|
|
}
|
|
|
|
|
2005-11-29 17:21:05 +01:00
|
|
|
static void directory_dump( struct object *obj, int verbose )
|
|
|
|
{
|
2016-01-21 13:08:56 +01:00
|
|
|
fputs( "Directory\n", stderr );
|
2005-11-29 17:21:05 +01:00
|
|
|
}
|
|
|
|
|
2007-12-05 18:16:42 +01:00
|
|
|
static struct object_type *directory_get_type( struct object *obj )
|
|
|
|
{
|
|
|
|
static const WCHAR name[] = {'D','i','r','e','c','t','o','r','y'};
|
|
|
|
static const struct unicode_str str = { name, sizeof(name) };
|
|
|
|
return get_object_type( &str );
|
|
|
|
}
|
|
|
|
|
2005-11-29 17:21:05 +01:00
|
|
|
static struct object *directory_lookup_name( struct object *obj, struct unicode_str *name,
|
|
|
|
unsigned int attr )
|
|
|
|
{
|
|
|
|
struct directory *dir = (struct directory *)obj;
|
|
|
|
struct object *found;
|
|
|
|
struct unicode_str tmp;
|
|
|
|
const WCHAR *p;
|
|
|
|
|
|
|
|
assert( obj->ops == &directory_ops );
|
|
|
|
|
|
|
|
if (!(p = memchrW( name->str, '\\', name->len / sizeof(WCHAR) )))
|
|
|
|
/* Last element in the path name */
|
|
|
|
tmp.len = name->len;
|
|
|
|
else
|
|
|
|
tmp.len = (p - name->str) * sizeof(WCHAR);
|
|
|
|
|
|
|
|
tmp.str = name->str;
|
|
|
|
if ((found = find_object( dir->entries, &tmp, attr )))
|
|
|
|
{
|
|
|
|
/* Skip trailing \\ */
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
tmp.len += sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
/* Move to the next element*/
|
|
|
|
name->str = p;
|
|
|
|
name->len -= tmp.len;
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name->str)
|
|
|
|
{
|
|
|
|
if (tmp.len == 0) /* Double backslash */
|
|
|
|
set_error( STATUS_OBJECT_NAME_INVALID );
|
|
|
|
else if (p) /* Path still has backslashes */
|
|
|
|
set_error( STATUS_OBJECT_PATH_NOT_FOUND );
|
2007-12-05 18:16:42 +01:00
|
|
|
else
|
|
|
|
clear_error();
|
2005-11-29 17:21:05 +01:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-04 13:08:02 +01:00
|
|
|
int directory_link_name( struct object *obj, struct object_name *name, struct object *parent )
|
|
|
|
{
|
|
|
|
struct directory *dir = (struct directory *)parent;
|
|
|
|
|
|
|
|
if (parent->ops != &directory_ops)
|
|
|
|
{
|
|
|
|
set_error( STATUS_OBJECT_TYPE_MISMATCH );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
namespace_add( dir->entries, name );
|
|
|
|
name->parent = grab_object( parent );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-11-29 17:21:05 +01:00
|
|
|
static void directory_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct directory *dir = (struct directory *)obj;
|
|
|
|
assert( obj->ops == &directory_ops );
|
|
|
|
free( dir->entries );
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct directory *create_directory( struct directory *root, const struct unicode_str *name,
|
2016-01-15 11:02:18 +01:00
|
|
|
unsigned int attr, unsigned int hash_size,
|
|
|
|
const struct security_descriptor *sd )
|
2005-11-29 17:21:05 +01:00
|
|
|
{
|
|
|
|
struct directory *dir;
|
|
|
|
|
|
|
|
if ((dir = create_named_object_dir( root, name, attr, &directory_ops )) &&
|
|
|
|
get_error() != STATUS_OBJECT_NAME_EXISTS)
|
|
|
|
{
|
|
|
|
if (!(dir->entries = create_namespace( hash_size )))
|
|
|
|
{
|
|
|
|
release_object( dir );
|
2016-01-24 18:50:56 +01:00
|
|
|
return NULL;
|
2005-11-29 17:21:05 +01:00
|
|
|
}
|
2016-01-15 11:02:18 +01:00
|
|
|
if (sd) default_set_sd( &dir->obj, sd, OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
|
|
|
|
DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION );
|
2005-11-29 17:21:05 +01:00
|
|
|
}
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2016-02-08 06:09:36 +01:00
|
|
|
struct object *get_root_directory(void)
|
|
|
|
{
|
|
|
|
return grab_object( root_directory );
|
|
|
|
}
|
|
|
|
|
2005-11-29 17:21:05 +01:00
|
|
|
struct directory *get_directory_obj( struct process *process, obj_handle_t handle, unsigned int access )
|
|
|
|
{
|
|
|
|
return (struct directory *)get_handle_obj( process, handle, access, &directory_ops );
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Find an object by its name in a given root object
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* root [I] directory to start search from or NULL to start from \\
|
|
|
|
* name [I] object name to search for
|
|
|
|
* attr [I] OBJECT_ATTRIBUTES.Attributes
|
|
|
|
* name_left [O] [optional] leftover name if object is not found
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* NULL: If params are invalid
|
|
|
|
* Found: If object with exact name is found returns that object
|
|
|
|
* (name_left->len == 0). Object's refcount is incremented
|
|
|
|
* Not found: The last matched parent. (name_left->len > 0)
|
|
|
|
* Parent's refcount is incremented.
|
|
|
|
*/
|
|
|
|
struct object *find_object_dir( struct directory *root, const struct unicode_str *name,
|
|
|
|
unsigned int attr, struct unicode_str *name_left )
|
|
|
|
{
|
2016-02-08 06:09:36 +01:00
|
|
|
return lookup_named_object( &root->obj, name, attr, name_left );
|
2005-11-29 17:21:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create a named (if name is present) or unnamed object. */
|
|
|
|
void *create_named_object_dir( struct directory *root, const struct unicode_str *name,
|
|
|
|
unsigned int attributes, const struct object_ops *ops )
|
|
|
|
{
|
2016-02-08 06:10:18 +01:00
|
|
|
return create_named_object( &root->obj, ops, name, attributes );
|
2005-11-29 17:21:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* open a new handle to an existing object */
|
2005-12-05 12:52:05 +01:00
|
|
|
void *open_object_dir( struct directory *root, const struct unicode_str *name,
|
|
|
|
unsigned int attr, const struct object_ops *ops )
|
2005-11-29 17:21:05 +01:00
|
|
|
{
|
|
|
|
struct unicode_str name_left;
|
|
|
|
struct object *obj;
|
|
|
|
|
|
|
|
if ((obj = find_object_dir( root, name, attr, &name_left )))
|
|
|
|
{
|
|
|
|
if (name_left.len) /* not fully parsed */
|
|
|
|
set_error( STATUS_OBJECT_NAME_NOT_FOUND );
|
|
|
|
else if (ops && obj->ops != ops)
|
|
|
|
set_error( STATUS_OBJECT_TYPE_MISMATCH );
|
|
|
|
else
|
2005-12-05 12:52:05 +01:00
|
|
|
return obj;
|
2005-11-29 17:21:05 +01:00
|
|
|
|
|
|
|
release_object( obj );
|
|
|
|
}
|
2005-12-05 12:52:05 +01:00
|
|
|
return NULL;
|
2005-11-29 17:21:05 +01:00
|
|
|
}
|
|
|
|
|
2007-12-05 18:16:42 +01:00
|
|
|
/* retrieve an object type, creating it if needed */
|
|
|
|
struct object_type *get_object_type( const struct unicode_str *name )
|
|
|
|
{
|
|
|
|
struct object_type *type;
|
|
|
|
|
|
|
|
if ((type = open_object_dir( dir_objtype, name, 0, &object_type_ops )))
|
|
|
|
return type;
|
|
|
|
|
|
|
|
if ((type = create_named_object_dir( dir_objtype, name, 0, &object_type_ops )))
|
|
|
|
{
|
|
|
|
grab_object( type );
|
|
|
|
make_object_static( &type->obj );
|
|
|
|
clear_error();
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
2005-11-29 17:21:05 +01:00
|
|
|
|
|
|
|
/* Global initialization */
|
|
|
|
|
|
|
|
void init_directories(void)
|
|
|
|
{
|
|
|
|
/* Directories */
|
2005-11-30 19:22:57 +01:00
|
|
|
static const WCHAR dir_globalW[] = {'\\','?','?'};
|
2005-11-29 17:21:05 +01:00
|
|
|
static const WCHAR dir_driverW[] = {'D','r','i','v','e','r'};
|
|
|
|
static const WCHAR dir_deviceW[] = {'D','e','v','i','c','e'};
|
2015-05-21 10:19:51 +02:00
|
|
|
static const WCHAR dir_nullW[] = {'\\','D','e','v','i','c','e','\\','N','u','l','l'};
|
2005-11-30 19:22:57 +01:00
|
|
|
static const WCHAR dir_basenamedW[] = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s'};
|
2007-03-22 12:01:16 +01:00
|
|
|
static const WCHAR dir_named_pipeW[] = {'\\','D','e','v','i','c','e','\\','N','a','m','e','d','P','i','p','e'};
|
|
|
|
static const WCHAR dir_mailslotW[] = {'\\','D','e','v','i','c','e','\\','M','a','i','l','S','l','o','t'};
|
2015-05-07 08:31:12 +02:00
|
|
|
static const WCHAR dir_objtypeW[] = {'O','b','j','e','c','t','T','y','p','e','s'};
|
2012-02-17 15:21:45 +01:00
|
|
|
static const WCHAR dir_sessionsW[] = {'S','e','s','s','i','o','n','s'};
|
2012-03-12 10:27:40 +01:00
|
|
|
static const WCHAR dir_kernelW[] = {'K','e','r','n','e','l','O','b','j','e','c','t','s'};
|
2016-01-20 14:02:03 +01:00
|
|
|
static const WCHAR dir_windowsW[] = {'W','i','n','d','o','w','s'};
|
|
|
|
static const WCHAR dir_winstationsW[] = {'W','i','n','d','o','w','S','t','a','t','i','o','n','s'};
|
2005-11-29 17:21:05 +01:00
|
|
|
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)};
|
2015-05-21 10:19:51 +02:00
|
|
|
static const struct unicode_str dir_null_str = {dir_nullW, sizeof(dir_nullW)};
|
2005-11-29 17:21:05 +01:00
|
|
|
static const struct unicode_str dir_basenamed_str = {dir_basenamedW, sizeof(dir_basenamedW)};
|
2007-03-22 12:01:16 +01:00
|
|
|
static const struct unicode_str dir_named_pipe_str = {dir_named_pipeW, sizeof(dir_named_pipeW)};
|
|
|
|
static const struct unicode_str dir_mailslot_str = {dir_mailslotW, sizeof(dir_mailslotW)};
|
2007-12-05 18:16:42 +01:00
|
|
|
static const struct unicode_str dir_objtype_str = {dir_objtypeW, sizeof(dir_objtypeW)};
|
2012-02-17 15:21:45 +01:00
|
|
|
static const struct unicode_str dir_sessions_str = {dir_sessionsW, sizeof(dir_sessionsW)};
|
2012-03-12 10:27:40 +01:00
|
|
|
static const struct unicode_str dir_kernel_str = {dir_kernelW, sizeof(dir_kernelW)};
|
2016-01-20 14:02:03 +01:00
|
|
|
static const struct unicode_str dir_windows_str = {dir_windowsW, sizeof(dir_windowsW)};
|
|
|
|
static const struct unicode_str dir_winstations_str = {dir_winstationsW, sizeof(dir_winstationsW)};
|
2005-11-29 17:21:05 +01:00
|
|
|
|
2005-11-30 19:22:57 +01:00
|
|
|
/* 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'};
|
2015-05-21 10:19:51 +02:00
|
|
|
static const WCHAR link_nulW[] = {'N','U','L'};
|
2007-03-22 12:01:16 +01:00
|
|
|
static const WCHAR link_pipeW[] = {'P','I','P','E'};
|
|
|
|
static const WCHAR link_mailslotW[] = {'M','A','I','L','S','L','O','T'};
|
2012-02-17 15:21:45 +01:00
|
|
|
static const WCHAR link_0W[] = {'0'};
|
|
|
|
static const WCHAR link_sessionW[] = {'S','e','s','s','i','o','n'};
|
|
|
|
static const WCHAR link_sessionsW[] = {'\\','S','e','s','s','i','o','n','s'};
|
2005-11-30 19:22:57 +01:00
|
|
|
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)};
|
2015-05-21 10:19:51 +02:00
|
|
|
static const struct unicode_str link_nul_str = {link_nulW, sizeof(link_nulW)};
|
2007-03-22 12:01:16 +01:00
|
|
|
static const struct unicode_str link_pipe_str = {link_pipeW, sizeof(link_pipeW)};
|
|
|
|
static const struct unicode_str link_mailslot_str = {link_mailslotW, sizeof(link_mailslotW)};
|
2012-02-17 15:21:45 +01:00
|
|
|
static const struct unicode_str link_0_str = {link_0W, sizeof(link_0W)};
|
|
|
|
static const struct unicode_str link_session_str = {link_sessionW, sizeof(link_sessionW)};
|
|
|
|
static const struct unicode_str link_sessions_str = {link_sessionsW, sizeof(link_sessionsW)};
|
2005-11-30 19:22:57 +01:00
|
|
|
|
2005-12-05 14:52:02 +01:00
|
|
|
/* devices */
|
2007-03-22 12:01:16 +01:00
|
|
|
static const WCHAR named_pipeW[] = {'N','a','m','e','d','P','i','p','e'};
|
|
|
|
static const WCHAR mailslotW[] = {'M','a','i','l','S','l','o','t'};
|
2015-05-21 10:19:51 +02:00
|
|
|
static const WCHAR nullW[] = {'N','u','l','l'};
|
2007-03-22 12:01:16 +01:00
|
|
|
static const struct unicode_str named_pipe_str = {named_pipeW, sizeof(named_pipeW)};
|
2005-12-05 14:52:02 +01:00
|
|
|
static const struct unicode_str mailslot_str = {mailslotW, sizeof(mailslotW)};
|
2015-05-21 10:19:51 +02:00
|
|
|
static const struct unicode_str null_str = {nullW, sizeof(nullW)};
|
2005-12-05 14:52:02 +01:00
|
|
|
|
2012-03-12 10:27:40 +01:00
|
|
|
/* events */
|
|
|
|
static const WCHAR event_low_memW[] = {'L','o','w','M','e','m','o','r','y','C','o','n','d','i','t','i','o','n'};
|
|
|
|
static const WCHAR event_low_pagedW[] = {'L','o','w','P','a','g','e','d','P','o','o','l','C','o','n','d','i','t','i','o','n'};
|
|
|
|
static const WCHAR event_low_nonpgW[] = {'L','o','w','N','o','n','P','a','g','e','d','P','o','o','l','C','o','n','d','i','t','i','o','n'};
|
|
|
|
static const WCHAR event_high_memW[] = {'H','i','g','h','M','e','m','o','r','y','C','o','n','d','i','t','i','o','n'};
|
|
|
|
static const WCHAR event_high_pagedW[] = {'H','i','g','h','P','a','g','e','d','P','o','o','l','C','o','n','d','i','t','i','o','n'};
|
|
|
|
static const WCHAR event_high_nonpgW[] = {'H','i','g','h','N','o','n','P','a','g','e','d','P','o','o','l','C','o','n','d','i','t','i','o','n'};
|
2013-08-21 12:51:31 +02:00
|
|
|
static const WCHAR keyed_event_crit_sectW[] = {'C','r','i','t','S','e','c','O','u','t','O','f','M','e','m','o','r','y','E','v','e','n','t'};
|
2012-03-12 10:27:40 +01:00
|
|
|
static const struct unicode_str kernel_events[] =
|
|
|
|
{
|
|
|
|
{ event_low_memW, sizeof(event_low_memW) },
|
|
|
|
{ event_low_pagedW, sizeof(event_low_pagedW) },
|
|
|
|
{ event_low_nonpgW, sizeof(event_low_nonpgW) },
|
|
|
|
{ event_high_memW, sizeof(event_high_memW) },
|
|
|
|
{ event_high_pagedW, sizeof(event_high_pagedW) },
|
|
|
|
{ event_high_nonpgW, sizeof(event_high_nonpgW) }
|
|
|
|
};
|
2013-08-21 12:51:31 +02:00
|
|
|
static const struct unicode_str keyed_event_crit_sect_str = {keyed_event_crit_sectW, sizeof(keyed_event_crit_sectW)};
|
2012-03-12 10:27:40 +01:00
|
|
|
|
2016-01-20 14:02:03 +01:00
|
|
|
struct directory *dir_driver, *dir_device, *dir_global, *dir_basenamed, *dir_sessions, *dir_kernel, *dir_windows, *dir_winstation;
|
2015-05-21 10:19:51 +02:00
|
|
|
struct symlink *link_dosdev, *link_global1, *link_global2, *link_local, *link_nul, *link_pipe, *link_mailslot, *link_0, *link_session;
|
2013-08-21 12:51:31 +02:00
|
|
|
struct keyed_event *keyed_event;
|
2012-03-12 10:27:40 +01:00
|
|
|
unsigned int i;
|
2005-11-30 19:22:57 +01:00
|
|
|
|
2016-01-15 11:02:18 +01:00
|
|
|
root_directory = create_directory( NULL, NULL, 0, HASH_SIZE, NULL );
|
|
|
|
dir_driver = create_directory( root_directory, &dir_driver_str, 0, HASH_SIZE, NULL );
|
|
|
|
dir_device = create_directory( root_directory, &dir_device_str, 0, HASH_SIZE, NULL );
|
|
|
|
dir_objtype = create_directory( root_directory, &dir_objtype_str, 0, HASH_SIZE, NULL );
|
|
|
|
dir_sessions = create_directory( root_directory, &dir_sessions_str, 0, HASH_SIZE, NULL );
|
|
|
|
dir_kernel = create_directory( root_directory, &dir_kernel_str, 0, HASH_SIZE, NULL );
|
2016-01-20 14:02:03 +01:00
|
|
|
dir_windows = create_directory( root_directory, &dir_windows_str, 0, HASH_SIZE, NULL );
|
|
|
|
dir_winstation = create_directory( dir_windows, &dir_winstations_str, 0, HASH_SIZE, NULL );
|
2006-03-22 20:32:04 +01:00
|
|
|
make_object_static( &root_directory->obj );
|
|
|
|
make_object_static( &dir_driver->obj );
|
2007-12-05 18:16:42 +01:00
|
|
|
make_object_static( &dir_objtype->obj );
|
2016-01-20 14:02:03 +01:00
|
|
|
make_object_static( &dir_winstation->obj );
|
2005-11-30 19:22:57 +01:00
|
|
|
|
2016-01-15 11:02:18 +01:00
|
|
|
dir_global = create_directory( NULL, &dir_global_str, 0, HASH_SIZE, NULL );
|
2005-11-29 17:21:05 +01:00
|
|
|
/* use a larger hash table for this one since it can contain a lot of objects */
|
2016-01-15 11:02:18 +01:00
|
|
|
dir_basenamed = create_directory( NULL, &dir_basenamed_str, 0, 37, NULL );
|
2005-11-30 19:22:57 +01:00
|
|
|
|
2007-03-22 12:01:16 +01:00
|
|
|
/* devices */
|
|
|
|
create_named_pipe_device( dir_device, &named_pipe_str );
|
|
|
|
create_mailslot_device( dir_device, &mailslot_str );
|
2015-05-21 10:19:51 +02:00
|
|
|
create_unix_device( dir_device, &null_str, "/dev/null" );
|
2007-03-22 12:01:16 +01:00
|
|
|
|
2005-11-30 19:22:57 +01:00
|
|
|
/* symlinks */
|
2016-01-15 12:33:20 +01:00
|
|
|
link_dosdev = create_symlink( root_directory, &link_dosdev_str, 0, &dir_global_str, NULL );
|
|
|
|
link_global1 = create_symlink( dir_global, &link_global_str, 0, &dir_global_str, NULL );
|
|
|
|
link_global2 = create_symlink( dir_basenamed, &link_global_str, 0, &dir_basenamed_str, NULL );
|
|
|
|
link_local = create_symlink( dir_basenamed, &link_local_str, 0, &dir_basenamed_str, NULL );
|
|
|
|
link_nul = create_symlink( dir_global, &link_nul_str, 0, &dir_null_str, NULL );
|
|
|
|
link_pipe = create_symlink( dir_global, &link_pipe_str, 0, &dir_named_pipe_str, NULL );
|
|
|
|
link_mailslot = create_symlink( dir_global, &link_mailslot_str, 0, &dir_mailslot_str, NULL );
|
|
|
|
link_0 = create_symlink( dir_sessions, &link_0_str, 0, &dir_basenamed_str, NULL );
|
|
|
|
link_session = create_symlink( dir_basenamed, &link_session_str, 0, &link_sessions_str, NULL );
|
2006-03-22 20:32:04 +01:00
|
|
|
make_object_static( (struct object *)link_dosdev );
|
|
|
|
make_object_static( (struct object *)link_global1 );
|
|
|
|
make_object_static( (struct object *)link_global2 );
|
|
|
|
make_object_static( (struct object *)link_local );
|
2015-05-21 10:19:51 +02:00
|
|
|
make_object_static( (struct object *)link_nul );
|
2007-03-22 12:01:16 +01:00
|
|
|
make_object_static( (struct object *)link_pipe );
|
|
|
|
make_object_static( (struct object *)link_mailslot );
|
2012-02-17 15:21:45 +01:00
|
|
|
make_object_static( (struct object *)link_0 );
|
|
|
|
make_object_static( (struct object *)link_session );
|
2005-12-05 13:09:35 +01:00
|
|
|
|
2012-03-12 10:27:40 +01:00
|
|
|
/* events */
|
|
|
|
for (i = 0; i < sizeof(kernel_events)/sizeof(kernel_events[0]); i++)
|
|
|
|
{
|
|
|
|
struct event *event = create_event( dir_kernel, &kernel_events[i], 0, 1, 0, NULL );
|
|
|
|
make_object_static( (struct object *)event );
|
|
|
|
}
|
2013-08-21 12:51:31 +02:00
|
|
|
keyed_event = create_keyed_event( dir_kernel, &keyed_event_crit_sect_str, 0, NULL );
|
|
|
|
make_object_static( (struct object *)keyed_event );
|
2012-03-12 10:27:40 +01:00
|
|
|
|
|
|
|
/* the objects hold references so we can release these directories */
|
2005-11-30 19:22:57 +01:00
|
|
|
release_object( dir_global );
|
2007-03-22 12:01:16 +01:00
|
|
|
release_object( dir_device );
|
2005-11-30 19:22:57 +01:00
|
|
|
release_object( dir_basenamed );
|
2012-03-12 10:27:40 +01:00
|
|
|
release_object( dir_sessions );
|
|
|
|
release_object( dir_kernel );
|
2016-01-20 14:02:03 +01:00
|
|
|
release_object( dir_windows );
|
2005-11-29 17:21:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create a directory object */
|
|
|
|
DECL_HANDLER(create_directory)
|
|
|
|
{
|
|
|
|
struct unicode_str name;
|
2016-02-01 06:57:37 +01:00
|
|
|
struct directory *dir, *root;
|
2016-01-15 11:02:18 +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-29 17:21:05 +01:00
|
|
|
|
2016-01-15 11:02:18 +01:00
|
|
|
if (!objattr) return;
|
2005-11-29 17:21:05 +01:00
|
|
|
|
2016-01-15 11:02:18 +01:00
|
|
|
if ((dir = create_directory( root, &name, objattr->attributes, HASH_SIZE, sd )))
|
2005-11-29 17:21:05 +01:00
|
|
|
{
|
2016-01-15 11:02:18 +01:00
|
|
|
reply->handle = alloc_handle( current->process, dir, req->access, objattr->attributes );
|
2005-11-29 17:21:05 +01:00
|
|
|
release_object( dir );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (root) release_object( root );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open a directory object */
|
|
|
|
DECL_HANDLER(open_directory)
|
|
|
|
{
|
2016-01-29 08:36:45 +01:00
|
|
|
struct unicode_str name = get_req_unicode_str();
|
2005-11-29 17:21:05 +01:00
|
|
|
|
2016-01-29 08:23:29 +01:00
|
|
|
reply->handle = open_object( current->process, req->rootdir, req->access,
|
|
|
|
&directory_ops, &name, req->attributes );
|
2005-11-29 17:21:05 +01:00
|
|
|
}
|
2007-12-05 16:57:41 +01:00
|
|
|
|
|
|
|
/* get a directory entry by index */
|
|
|
|
DECL_HANDLER(get_directory_entry)
|
|
|
|
{
|
|
|
|
struct directory *dir = get_directory_obj( current->process, req->handle, DIRECTORY_QUERY );
|
|
|
|
if (dir)
|
|
|
|
{
|
|
|
|
struct object *obj = find_object_index( dir->entries, req->index );
|
|
|
|
if (obj)
|
|
|
|
{
|
2007-12-07 18:42:48 +01:00
|
|
|
data_size_t name_len, type_len = 0;
|
2007-12-05 18:16:42 +01:00
|
|
|
const WCHAR *type_name = NULL;
|
2007-12-05 16:57:41 +01:00
|
|
|
const WCHAR *name = get_object_name( obj, &name_len );
|
2007-12-05 18:16:42 +01:00
|
|
|
struct object_type *type = obj->ops->get_type( obj );
|
|
|
|
|
|
|
|
if (type) type_name = get_object_name( &type->obj, &type_len );
|
2007-12-05 16:57:41 +01:00
|
|
|
|
|
|
|
if (name_len + type_len <= get_reply_max_size())
|
|
|
|
{
|
|
|
|
void *ptr = set_reply_data_size( name_len + type_len );
|
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
reply->name_len = name_len;
|
|
|
|
memcpy( ptr, name, name_len );
|
2007-12-05 18:16:42 +01:00
|
|
|
memcpy( (char *)ptr + name_len, type_name, type_len );
|
2007-12-05 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else set_error( STATUS_BUFFER_OVERFLOW );
|
|
|
|
|
2007-12-05 18:16:42 +01:00
|
|
|
if (type) release_object( type );
|
2007-12-05 16:57:41 +01:00
|
|
|
release_object( obj );
|
|
|
|
}
|
|
|
|
release_object( dir );
|
|
|
|
}
|
|
|
|
}
|
2008-10-20 16:21:06 +02:00
|
|
|
|
|
|
|
/* unlink a named object */
|
|
|
|
DECL_HANDLER(unlink_object)
|
|
|
|
{
|
|
|
|
struct object *obj = get_handle_obj( current->process, req->handle, 0, NULL );
|
|
|
|
|
|
|
|
if (obj)
|
|
|
|
{
|
|
|
|
unlink_named_object( obj );
|
|
|
|
release_object( obj );
|
|
|
|
}
|
|
|
|
}
|
2015-06-02 16:09:48 +02:00
|
|
|
|
|
|
|
/* query object type name information */
|
|
|
|
DECL_HANDLER(get_object_type)
|
|
|
|
{
|
|
|
|
struct object *obj;
|
|
|
|
struct object_type *type;
|
|
|
|
const WCHAR *name;
|
|
|
|
|
|
|
|
if (!(obj = get_handle_obj( current->process, req->handle, 0, NULL ))) return;
|
|
|
|
|
|
|
|
if ((type = obj->ops->get_type( obj )))
|
|
|
|
{
|
|
|
|
if ((name = get_object_name( &type->obj, &reply->total )))
|
|
|
|
set_reply_data( name, min( reply->total, get_reply_max_size() ) );
|
|
|
|
release_object( type );
|
|
|
|
}
|
|
|
|
release_object( obj );
|
|
|
|
}
|