Commit b0e5fb43 authored by Rob Shearman's avatar Rob Shearman Committed by Alexandre Julliard

server: Make create_semaphore use struct object_attributes and set the security…

server: Make create_semaphore use struct object_attributes and set the security descriptor of semaphore objects.
parent a8df7fdd
......@@ -144,23 +144,37 @@ NTSTATUS WINAPI NtCreateSemaphore( OUT PHANDLE SemaphoreHandle,
{
DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0;
NTSTATUS ret;
struct object_attributes objattr;
struct security_descriptor *sd = NULL;
if (MaximumCount <= 0 || InitialCount < 0 || InitialCount > MaximumCount)
return STATUS_INVALID_PARAMETER;
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 )
{
req->access = access;
req->attributes = (attr) ? attr->Attributes : 0;
req->rootdir = attr ? attr->RootDirectory : 0;
req->initial = InitialCount;
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 );
ret = wine_server_call( req );
*SemaphoreHandle = reply->handle;
}
SERVER_END_REQ;
free_struct_sd( sd );
return ret;
}
......
......@@ -960,10 +960,9 @@ struct create_semaphore_request
struct request_header __header;
unsigned int access;
unsigned int attributes;
obj_handle_t rootdir;
unsigned int initial;
unsigned int max;
/* VARARG(name,unicode_str); */
/* VARARG(objattr,object_attributes); */
};
struct create_semaphore_reply
{
......@@ -4880,6 +4879,6 @@ union generic_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 */
......@@ -812,10 +812,9 @@ enum event_op { PULSE_EVENT, SET_EVENT, RESET_EVENT };
@REQ(create_semaphore)
unsigned int access; /* wanted access rights */
unsigned int attributes; /* object attributes */
obj_handle_t rootdir; /* root directory */
unsigned int initial; /* initial count */
unsigned int max; /* maximum count */
VARARG(name,unicode_str); /* object name */
VARARG(objattr,object_attributes); /* object attributes */
@REPLY
obj_handle_t handle; /* handle to the semaphore */
@END
......
......@@ -34,6 +34,7 @@
#include "handle.h"
#include "thread.h"
#include "request.h"
#include "security.h"
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,
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;
......@@ -85,6 +87,10 @@ static struct semaphore *create_semaphore( struct directory *root, const struct
/* initialize it if it didn't already exist */
sem->count = initial;
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;
......@@ -165,13 +171,23 @@ DECL_HANDLER(create_semaphore)
struct semaphore *sem;
struct unicode_str name;
struct directory *root = NULL;
const struct object_attributes *objattr = get_req_data();
const struct security_descriptor *sd;
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;
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 )))
if ((sem = create_semaphore( root, &name, req->attributes, req->initial, req->max, sd )))
{
reply->handle = alloc_handle( current->process, sem, req->access, req->attributes );
release_object( sem );
......
......@@ -1230,11 +1230,10 @@ static void dump_create_semaphore_request( const struct create_semaphore_request
{
fprintf( stderr, " access=%08x,", req->access );
fprintf( stderr, " attributes=%08x,", req->attributes );
fprintf( stderr, " rootdir=%p,", req->rootdir );
fprintf( stderr, " initial=%08x,", req->initial );
fprintf( stderr, " max=%08x,", req->max );
fprintf( stderr, " name=" );
dump_varargs_unicode_str( cur_size );
fprintf( stderr, " objattr=" );
dump_varargs_object_attributes( cur_size );
}
static void dump_create_semaphore_reply( const struct create_semaphore_reply *req )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment