server: Make create_semaphore use struct object_attributes and set the security descriptor of semaphore objects.

This commit is contained in:
Rob Shearman 2007-10-25 15:42:53 +01:00 committed by Alexandre Julliard
parent a8df7fddd5
commit b0e5fb4384
5 changed files with 40 additions and 13 deletions

View file

@ -144,23 +144,37 @@ NTSTATUS WINAPI NtCreateSemaphore( OUT PHANDLE SemaphoreHandle,
{ {
DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0; DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0;
NTSTATUS ret; NTSTATUS ret;
struct object_attributes objattr;
struct security_descriptor *sd = NULL;
if (MaximumCount <= 0 || InitialCount < 0 || InitialCount > MaximumCount) if (MaximumCount <= 0 || InitialCount < 0 || InitialCount > MaximumCount)
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
if (len >= MAX_PATH * sizeof(WCHAR)) return STATUS_NAME_TOO_LONG; if (len >= MAX_PATH * sizeof(WCHAR)) return STATUS_NAME_TOO_LONG;
objattr.rootdir = attr ? attr->RootDirectory : 0;
objattr.sd_len = 0;
if (attr)
{
ret = create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
if (ret != STATUS_SUCCESS) return ret;
}
SERVER_START_REQ( create_semaphore ) SERVER_START_REQ( create_semaphore )
{ {
req->access = access; req->access = access;
req->attributes = (attr) ? attr->Attributes : 0; req->attributes = (attr) ? attr->Attributes : 0;
req->rootdir = attr ? attr->RootDirectory : 0;
req->initial = InitialCount; req->initial = InitialCount;
req->max = MaximumCount; req->max = MaximumCount;
wine_server_add_data( req, &objattr, sizeof(objattr) );
if (objattr.sd_len) wine_server_add_data( req, sd, objattr.sd_len );
if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len ); if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len );
ret = wine_server_call( req ); ret = wine_server_call( req );
*SemaphoreHandle = reply->handle; *SemaphoreHandle = reply->handle;
} }
SERVER_END_REQ; SERVER_END_REQ;
free_struct_sd( sd );
return ret; return ret;
} }

View file

@ -960,10 +960,9 @@ struct create_semaphore_request
struct request_header __header; struct request_header __header;
unsigned int access; unsigned int access;
unsigned int attributes; unsigned int attributes;
obj_handle_t rootdir;
unsigned int initial; unsigned int initial;
unsigned int max; unsigned int max;
/* VARARG(name,unicode_str); */ /* VARARG(objattr,object_attributes); */
}; };
struct create_semaphore_reply struct create_semaphore_reply
{ {
@ -4880,6 +4879,6 @@ union generic_reply
struct set_completion_info_reply set_completion_info_reply; struct set_completion_info_reply set_completion_info_reply;
}; };
#define SERVER_PROTOCOL_VERSION 318 #define SERVER_PROTOCOL_VERSION 319
#endif /* __WINE_WINE_SERVER_PROTOCOL_H */ #endif /* __WINE_WINE_SERVER_PROTOCOL_H */

View file

@ -812,10 +812,9 @@ enum event_op { PULSE_EVENT, SET_EVENT, RESET_EVENT };
@REQ(create_semaphore) @REQ(create_semaphore)
unsigned int access; /* wanted access rights */ unsigned int access; /* wanted access rights */
unsigned int attributes; /* object attributes */ unsigned int attributes; /* object attributes */
obj_handle_t rootdir; /* root directory */
unsigned int initial; /* initial count */ unsigned int initial; /* initial count */
unsigned int max; /* maximum count */ unsigned int max; /* maximum count */
VARARG(name,unicode_str); /* object name */ VARARG(objattr,object_attributes); /* object attributes */
@REPLY @REPLY
obj_handle_t handle; /* handle to the semaphore */ obj_handle_t handle; /* handle to the semaphore */
@END @END

View file

@ -34,6 +34,7 @@
#include "handle.h" #include "handle.h"
#include "thread.h" #include "thread.h"
#include "request.h" #include "request.h"
#include "security.h"
struct semaphore struct semaphore
{ {
@ -69,7 +70,8 @@ static const struct object_ops semaphore_ops =
static struct semaphore *create_semaphore( struct directory *root, const struct unicode_str *name, static struct semaphore *create_semaphore( struct directory *root, const struct unicode_str *name,
unsigned int attr, unsigned int initial, unsigned int max ) unsigned int attr, unsigned int initial, unsigned int max,
const struct security_descriptor *sd )
{ {
struct semaphore *sem; struct semaphore *sem;
@ -85,6 +87,10 @@ static struct semaphore *create_semaphore( struct directory *root, const struct
/* initialize it if it didn't already exist */ /* initialize it if it didn't already exist */
sem->count = initial; sem->count = initial;
sem->max = max; sem->max = max;
if (sd) default_set_sd( &sem->obj, sd, OWNER_SECURITY_INFORMATION|
GROUP_SECURITY_INFORMATION|
DACL_SECURITY_INFORMATION|
SACL_SECURITY_INFORMATION );
} }
} }
return sem; return sem;
@ -165,13 +171,23 @@ DECL_HANDLER(create_semaphore)
struct semaphore *sem; struct semaphore *sem;
struct unicode_str name; struct unicode_str name;
struct directory *root = NULL; struct directory *root = NULL;
const struct object_attributes *objattr = get_req_data();
const struct security_descriptor *sd;
reply->handle = 0; reply->handle = 0;
get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) if (!objattr_is_valid( objattr, get_req_data_size() ))
return; return;
if ((sem = create_semaphore( root, &name, req->attributes, req->initial, req->max ))) sd = objattr->sd_len ? (const struct security_descriptor *)(objattr + 1) : NULL;
/* get unicode string */
name.len = ((get_req_data_size() - sizeof(*objattr) - objattr->sd_len) / sizeof(WCHAR)) * sizeof(WCHAR);
name.str = (const WCHAR *)get_req_data() + (sizeof(*objattr) + objattr->sd_len) / sizeof(WCHAR);
if (objattr->rootdir && !(root = get_directory_obj( current->process, objattr->rootdir, 0 )))
return;
if ((sem = create_semaphore( root, &name, req->attributes, req->initial, req->max, sd )))
{ {
reply->handle = alloc_handle( current->process, sem, req->access, req->attributes ); reply->handle = alloc_handle( current->process, sem, req->access, req->attributes );
release_object( sem ); release_object( sem );

View file

@ -1230,11 +1230,10 @@ static void dump_create_semaphore_request( const struct create_semaphore_request
{ {
fprintf( stderr, " access=%08x,", req->access ); fprintf( stderr, " access=%08x,", req->access );
fprintf( stderr, " attributes=%08x,", req->attributes ); fprintf( stderr, " attributes=%08x,", req->attributes );
fprintf( stderr, " rootdir=%p,", req->rootdir );
fprintf( stderr, " initial=%08x,", req->initial ); fprintf( stderr, " initial=%08x,", req->initial );
fprintf( stderr, " max=%08x,", req->max ); fprintf( stderr, " max=%08x,", req->max );
fprintf( stderr, " name=" ); fprintf( stderr, " objattr=" );
dump_varargs_unicode_str( cur_size ); dump_varargs_object_attributes( cur_size );
} }
static void dump_create_semaphore_reply( const struct create_semaphore_reply *req ) static void dump_create_semaphore_reply( const struct create_semaphore_reply *req )