server: Implement CreateJobObject.

This commit is contained in:
Andrew Cook 2015-02-26 12:25:23 +11:00 committed by Alexandre Julliard
parent e30a6bbcbd
commit 0e78b0248d
6 changed files with 193 additions and 4 deletions

View File

@ -565,9 +565,36 @@ NTSTATUS WINAPI NtQueryMutant(IN HANDLE handle,
*/
NTSTATUS WINAPI NtCreateJobObject( PHANDLE handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
{
FIXME( "stub: %p %x %s\n", handle, access, attr ? debugstr_us(attr->ObjectName) : "" );
*handle = (HANDLE)0xdead;
return STATUS_SUCCESS;
DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0;
NTSTATUS ret;
struct security_descriptor *sd = NULL;
struct object_attributes objattr;
if (len >= MAX_PATH * sizeof(WCHAR)) return STATUS_NAME_TOO_LONG;
objattr.rootdir = wine_server_obj_handle( attr ? attr->RootDirectory : 0 );
objattr.sd_len = 0;
objattr.name_len = len;
if (attr)
{
ret = NTDLL_create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
if (ret != STATUS_SUCCESS) return ret;
}
SERVER_START_REQ( create_job )
{
req->access = access;
req->attributes = attr ? attr->Attributes : 0;
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 );
*handle = wine_server_ptr_handle( reply->handle );
}
SERVER_END_REQ;
NTDLL_free_struct_sd( sd );
return ret;
}
/******************************************************************************

View File

@ -5082,6 +5082,23 @@ struct set_suspend_context_reply
};
struct create_job_request
{
struct request_header __header;
unsigned int access;
unsigned int attributes;
/* VARARG(objattr,object_attributes); */
char __pad_20[4];
};
struct create_job_reply
{
struct reply_header __header;
obj_handle_t handle;
char __pad_12[4];
};
enum request
{
REQ_new_process,
@ -5340,6 +5357,7 @@ enum request
REQ_update_rawinput_devices,
REQ_get_suspend_context,
REQ_set_suspend_context,
REQ_create_job,
REQ_NB_REQUESTS
};
@ -5603,6 +5621,7 @@ union generic_request
struct update_rawinput_devices_request update_rawinput_devices_request;
struct get_suspend_context_request get_suspend_context_request;
struct set_suspend_context_request set_suspend_context_request;
struct create_job_request create_job_request;
};
union generic_reply
{
@ -5864,8 +5883,9 @@ union generic_reply
struct update_rawinput_devices_reply update_rawinput_devices_reply;
struct get_suspend_context_reply get_suspend_context_reply;
struct set_suspend_context_reply set_suspend_context_reply;
struct create_job_reply create_job_reply;
};
#define SERVER_PROTOCOL_VERSION 460
#define SERVER_PROTOCOL_VERSION 461
#endif /* __WINE_WINE_SERVER_PROTOCOL_H */

View File

@ -133,6 +133,89 @@ static const struct object_ops startup_info_ops =
startup_info_destroy /* destroy */
};
/* job object */
static void job_dump( struct object *obj, int verbose );
static struct object_type *job_get_type( struct object *obj );
static int job_signaled( struct object *obj, struct wait_queue_entry *entry );
static unsigned int job_map_access( struct object *obj, unsigned int access );
static void job_destroy( struct object *obj );
struct job
{
struct object obj; /* object header */
};
static const struct object_ops job_ops =
{
sizeof(struct job), /* size */
job_dump, /* dump */
job_get_type, /* get_type */
add_queue, /* add_queue */
remove_queue, /* remove_queue */
job_signaled, /* signaled */
no_satisfied, /* satisfied */
no_signal, /* signal */
no_get_fd, /* get_fd */
job_map_access, /* map_access */
default_get_sd, /* get_sd */
default_set_sd, /* set_sd */
no_lookup_name, /* lookup_name */
no_open_file, /* open_file */
no_close_handle, /* close_handle */
job_destroy /* destroy */
};
static struct job *create_job_object( struct directory *root, const struct unicode_str *name,
unsigned int attr, const struct security_descriptor *sd )
{
struct job *job;
if ((job = create_named_object_dir( root, name, attr, &job_ops )))
{
if (get_error() != STATUS_OBJECT_NAME_EXISTS)
{
/* initialize it if it didn't already exist */
if (sd) default_set_sd( &job->obj, sd, OWNER_SECURITY_INFORMATION |
GROUP_SECURITY_INFORMATION |
DACL_SECURITY_INFORMATION |
SACL_SECURITY_INFORMATION );
}
}
return job;
}
static struct object_type *job_get_type( struct object *obj )
{
static const WCHAR name[] = {'J','o','b'};
static const struct unicode_str str = { name, sizeof(name) };
return get_object_type( &str );
};
static unsigned int job_map_access( struct object *obj, unsigned int access )
{
if (access & GENERIC_READ) access |= STANDARD_RIGHTS_READ;
if (access & GENERIC_WRITE) access |= STANDARD_RIGHTS_WRITE;
if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE;
if (access & GENERIC_ALL) access |= JOB_OBJECT_ALL_ACCESS;
return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
}
static void job_destroy( struct object *obj )
{
assert( obj->ops == &job_ops );
}
static void job_dump( struct object *obj, int verbose )
{
assert( obj->ops == &job_ops );
fprintf( stderr, "Job\n");
}
static int job_signaled( struct object *obj, struct wait_queue_entry *entry )
{
return 0;
}
struct ptid_entry
{
@ -1308,3 +1391,30 @@ DECL_HANDLER(make_process_system)
shutdown_timeout = add_timeout_user( master_socket_timeout, server_shutdown_timeout, NULL );
}
}
/* create a new job object */
DECL_HANDLER(create_job)
{
struct job *job;
struct unicode_str name;
struct directory *root = NULL;
const struct object_attributes *objattr = get_req_data();
const struct security_descriptor *sd;
if (!objattr_is_valid( objattr, get_req_data_size() )) return;
sd = objattr->sd_len ? (const struct security_descriptor *)(objattr + 1) : NULL;
objattr_get_name( objattr, &name );
if (objattr->rootdir && !(root = get_directory_obj( current->process, objattr->rootdir, 0 ))) return;
if ((job = create_job_object( root, &name, req->attributes, sd )))
{
if (get_error() == STATUS_OBJECT_NAME_EXISTS)
reply->handle = alloc_handle( current->process, job, req->access, req->attributes );
else
reply->handle = alloc_handle_no_access_check( current->process, job, req->access, req->attributes );
release_object( job );
}
if (root) release_object( root );
}

View File

@ -3504,3 +3504,13 @@ enum coords_relative
@REQ(set_suspend_context)
VARARG(context,context); /* thread context */
@END
/* Create a new job object */
@REQ(create_job)
unsigned int access; /* wanted access rights */
unsigned int attributes; /* object attributes */
VARARG(objattr,object_attributes); /* object attributes */
@REPLY
obj_handle_t handle; /* handle to the job */
@END

View File

@ -362,6 +362,7 @@ DECL_HANDLER(set_cursor);
DECL_HANDLER(update_rawinput_devices);
DECL_HANDLER(get_suspend_context);
DECL_HANDLER(set_suspend_context);
DECL_HANDLER(create_job);
#ifdef WANT_REQUEST_HANDLERS
@ -624,6 +625,7 @@ static const req_handler req_handlers[REQ_NB_REQUESTS] =
(req_handler)req_update_rawinput_devices,
(req_handler)req_get_suspend_context,
(req_handler)req_set_suspend_context,
(req_handler)req_create_job,
};
C_ASSERT( sizeof(affinity_t) == 8 );
@ -2204,6 +2206,11 @@ C_ASSERT( sizeof(struct update_rawinput_devices_request) == 16 );
C_ASSERT( sizeof(struct get_suspend_context_request) == 16 );
C_ASSERT( sizeof(struct get_suspend_context_reply) == 8 );
C_ASSERT( sizeof(struct set_suspend_context_request) == 16 );
C_ASSERT( FIELD_OFFSET(struct create_job_request, access) == 12 );
C_ASSERT( FIELD_OFFSET(struct create_job_request, attributes) == 16 );
C_ASSERT( sizeof(struct create_job_request) == 24 );
C_ASSERT( FIELD_OFFSET(struct create_job_reply, handle) == 8 );
C_ASSERT( sizeof(struct create_job_reply) == 16 );
#endif /* WANT_REQUEST_HANDLERS */

View File

@ -4095,6 +4095,18 @@ static void dump_set_suspend_context_request( const struct set_suspend_context_r
dump_varargs_context( " context=", cur_size );
}
static void dump_create_job_request( const struct create_job_request *req )
{
fprintf( stderr, " access=%08x", req->access );
fprintf( stderr, ", attributes=%08x", req->attributes );
dump_varargs_object_attributes( ", objattr=", cur_size );
}
static void dump_create_job_reply( const struct create_job_reply *req )
{
fprintf( stderr, " handle=%04x", req->handle );
}
static const dump_func req_dumpers[REQ_NB_REQUESTS] = {
(dump_func)dump_new_process_request,
(dump_func)dump_get_new_process_info_request,
@ -4352,6 +4364,7 @@ static const dump_func req_dumpers[REQ_NB_REQUESTS] = {
(dump_func)dump_update_rawinput_devices_request,
(dump_func)dump_get_suspend_context_request,
(dump_func)dump_set_suspend_context_request,
(dump_func)dump_create_job_request,
};
static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {
@ -4611,6 +4624,7 @@ static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {
NULL,
(dump_func)dump_get_suspend_context_reply,
NULL,
(dump_func)dump_create_job_reply,
};
static const char * const req_names[REQ_NB_REQUESTS] = {
@ -4870,6 +4884,7 @@ static const char * const req_names[REQ_NB_REQUESTS] = {
"update_rawinput_devices",
"get_suspend_context",
"set_suspend_context",
"create_job",
};
static const struct