winmm: Get rid of TIME_MS format support in waveOutGetPosition().
[wine.git] / server / handle.c
blob2556a03901ea15f0722719ce23958d0fdf2b0b84
1 /*
2 * Server-side handle management
4 * Copyright (C) 1998 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <limits.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include <stdlib.h>
31 #include "ntstatus.h"
32 #define WIN32_NO_STATUS
33 #include "windef.h"
34 #include "winternl.h"
36 #include "handle.h"
37 #include "process.h"
38 #include "thread.h"
39 #include "security.h"
40 #include "request.h"
42 struct handle_entry
44 struct object *ptr; /* object */
45 unsigned int access; /* access rights */
48 struct handle_table
50 struct object obj; /* object header */
51 struct process *process; /* process owning this table */
52 int count; /* number of allocated entries */
53 int last; /* last used entry */
54 int free; /* first entry that may be free */
55 struct handle_entry *entries; /* handle entries */
58 static struct handle_table *global_table;
60 /* reserved handle access rights */
61 #define RESERVED_SHIFT 26
62 #define RESERVED_INHERIT (HANDLE_FLAG_INHERIT << RESERVED_SHIFT)
63 #define RESERVED_CLOSE_PROTECT (HANDLE_FLAG_PROTECT_FROM_CLOSE << RESERVED_SHIFT)
64 #define RESERVED_ALL (RESERVED_INHERIT | RESERVED_CLOSE_PROTECT)
66 #define MIN_HANDLE_ENTRIES 32
67 #define MAX_HANDLE_ENTRIES 0x00ffffff
70 /* handle to table index conversion */
72 /* handles are a multiple of 4 under NT; handle 0 is not used */
73 static inline obj_handle_t index_to_handle( int index )
75 return (obj_handle_t)((index + 1) << 2);
77 static inline int handle_to_index( obj_handle_t handle )
79 return (handle >> 2) - 1;
82 /* global handle conversion */
84 #define HANDLE_OBFUSCATOR 0x544a4def
86 static inline int handle_is_global( obj_handle_t handle)
88 return (handle ^ HANDLE_OBFUSCATOR) <= (MAX_HANDLE_ENTRIES << 2);
90 static inline obj_handle_t handle_local_to_global( obj_handle_t handle )
92 if (!handle) return 0;
93 return handle ^ HANDLE_OBFUSCATOR;
95 static inline obj_handle_t handle_global_to_local( obj_handle_t handle )
97 return handle ^ HANDLE_OBFUSCATOR;
100 /* grab an object and increment its handle count */
101 static struct object *grab_object_for_handle( struct object *obj )
103 obj->handle_count++;
104 return grab_object( obj );
107 /* release an object and decrement its handle count */
108 static void release_object_from_handle( struct object *obj )
110 assert( obj->handle_count );
111 obj->handle_count--;
112 release_object( obj );
115 static void handle_table_dump( struct object *obj, int verbose );
116 static void handle_table_destroy( struct object *obj );
118 static const struct object_ops handle_table_ops =
120 sizeof(struct handle_table), /* size */
121 handle_table_dump, /* dump */
122 no_get_type, /* get_type */
123 no_add_queue, /* add_queue */
124 NULL, /* remove_queue */
125 NULL, /* signaled */
126 NULL, /* satisfied */
127 no_signal, /* signal */
128 no_get_fd, /* get_fd */
129 no_map_access, /* map_access */
130 default_get_sd, /* get_sd */
131 default_set_sd, /* set_sd */
132 no_get_full_name, /* get_full_name */
133 no_lookup_name, /* lookup_name */
134 no_link_name, /* link_name */
135 NULL, /* unlink_name */
136 no_open_file, /* open_file */
137 no_kernel_obj_list, /* get_kernel_obj_list */
138 no_close_handle, /* close_handle */
139 handle_table_destroy /* destroy */
142 /* dump a handle table */
143 static void handle_table_dump( struct object *obj, int verbose )
145 int i;
146 struct handle_table *table = (struct handle_table *)obj;
147 struct handle_entry *entry;
149 assert( obj->ops == &handle_table_ops );
151 fprintf( stderr, "Handle table last=%d count=%d process=%p\n",
152 table->last, table->count, table->process );
153 if (!verbose) return;
154 entry = table->entries;
155 for (i = 0; i <= table->last; i++, entry++)
157 if (!entry->ptr) continue;
158 fprintf( stderr, " %04x: %p %08x ",
159 index_to_handle(i), entry->ptr, entry->access );
160 dump_object_name( entry->ptr );
161 entry->ptr->ops->dump( entry->ptr, 0 );
165 /* destroy a handle table */
166 static void handle_table_destroy( struct object *obj )
168 int i;
169 struct handle_table *table = (struct handle_table *)obj;
170 struct handle_entry *entry;
172 assert( obj->ops == &handle_table_ops );
174 /* first notify all objects that handles are being closed */
175 if (table->process)
177 for (i = 0, entry = table->entries; i <= table->last; i++, entry++)
179 struct object *obj = entry->ptr;
180 if (obj) obj->ops->close_handle( obj, table->process, index_to_handle(i) );
184 for (i = 0, entry = table->entries; i <= table->last; i++, entry++)
186 struct object *obj = entry->ptr;
187 entry->ptr = NULL;
188 if (obj) release_object_from_handle( obj );
190 free( table->entries );
193 /* close all the process handles and free the handle table */
194 void close_process_handles( struct process *process )
196 struct handle_table *table = process->handles;
198 process->handles = NULL;
199 if (table) release_object( table );
202 /* allocate a new handle table */
203 struct handle_table *alloc_handle_table( struct process *process, int count )
205 struct handle_table *table;
207 if (count < MIN_HANDLE_ENTRIES) count = MIN_HANDLE_ENTRIES;
208 if (!(table = alloc_object( &handle_table_ops )))
209 return NULL;
210 table->process = process;
211 table->count = count;
212 table->last = -1;
213 table->free = 0;
214 if ((table->entries = mem_alloc( count * sizeof(*table->entries) ))) return table;
215 release_object( table );
216 return NULL;
219 /* grow a handle table */
220 static int grow_handle_table( struct handle_table *table )
222 struct handle_entry *new_entries;
223 int count = min( table->count * 2, MAX_HANDLE_ENTRIES );
225 if (count == table->count ||
226 !(new_entries = realloc( table->entries, count * sizeof(struct handle_entry) )))
228 set_error( STATUS_INSUFFICIENT_RESOURCES );
229 return 0;
231 table->entries = new_entries;
232 table->count = count;
233 return 1;
236 /* allocate the first free entry in the handle table */
237 static obj_handle_t alloc_entry( struct handle_table *table, void *obj, unsigned int access )
239 struct handle_entry *entry = table->entries + table->free;
240 int i;
242 for (i = table->free; i <= table->last; i++, entry++) if (!entry->ptr) goto found;
243 if (i >= table->count)
245 if (!grow_handle_table( table )) return 0;
246 entry = table->entries + i; /* the entries may have moved */
248 table->last = i;
249 found:
250 table->free = i + 1;
251 entry->ptr = grab_object_for_handle( obj );
252 entry->access = access;
253 return index_to_handle(i);
256 /* allocate a handle for an object, incrementing its refcount */
257 static obj_handle_t alloc_handle_entry( struct process *process, void *ptr,
258 unsigned int access, unsigned int attr )
260 struct object *obj = ptr;
262 assert( !(access & RESERVED_ALL) );
263 if (attr & OBJ_INHERIT) access |= RESERVED_INHERIT;
264 if (!process->handles)
266 set_error( STATUS_PROCESS_IS_TERMINATING );
267 return 0;
269 return alloc_entry( process->handles, obj, access );
272 /* allocate a handle for an object, incrementing its refcount */
273 /* return the handle, or 0 on error */
274 obj_handle_t alloc_handle_no_access_check( struct process *process, void *ptr, unsigned int access, unsigned int attr )
276 struct object *obj = ptr;
277 if (access & MAXIMUM_ALLOWED) access = GENERIC_ALL;
278 access = obj->ops->map_access( obj, access ) & ~RESERVED_ALL;
279 return alloc_handle_entry( process, ptr, access, attr );
282 /* allocate a handle for an object, checking the dacl allows the process to */
283 /* access it and incrementing its refcount */
284 /* return the handle, or 0 on error */
285 obj_handle_t alloc_handle( struct process *process, void *ptr, unsigned int access, unsigned int attr )
287 struct object *obj = ptr;
288 access = obj->ops->map_access( obj, access ) & ~RESERVED_ALL;
289 if (access && !check_object_access( NULL, obj, &access )) return 0;
290 return alloc_handle_entry( process, ptr, access, attr );
293 /* allocate a global handle for an object, incrementing its refcount */
294 /* return the handle, or 0 on error */
295 static obj_handle_t alloc_global_handle_no_access_check( void *obj, unsigned int access )
297 if (!global_table)
299 if (!(global_table = alloc_handle_table( NULL, 0 )))
300 return 0;
301 make_object_permanent( &global_table->obj );
303 return handle_local_to_global( alloc_entry( global_table, obj, access ));
306 /* allocate a global handle for an object, checking the dacl allows the */
307 /* process to access it and incrementing its refcount and incrementing its refcount */
308 /* return the handle, or 0 on error */
309 static obj_handle_t alloc_global_handle( void *obj, unsigned int access )
311 if (access && !check_object_access( NULL, obj, &access )) return 0;
312 return alloc_global_handle_no_access_check( obj, access );
315 /* return a handle entry, or NULL if the handle is invalid */
316 static struct handle_entry *get_handle( struct process *process, obj_handle_t handle )
318 struct handle_table *table = process->handles;
319 struct handle_entry *entry;
320 int index;
322 if (handle_is_global(handle))
324 handle = handle_global_to_local(handle);
325 table = global_table;
327 if (!table) return NULL;
328 index = handle_to_index( handle );
329 if (index < 0) return NULL;
330 if (index > table->last) return NULL;
331 entry = table->entries + index;
332 if (!entry->ptr) return NULL;
333 return entry;
336 /* attempt to shrink a table */
337 static void shrink_handle_table( struct handle_table *table )
339 struct handle_entry *entry = table->entries + table->last;
340 struct handle_entry *new_entries;
341 int count = table->count;
343 while (table->last >= 0)
345 if (entry->ptr) break;
346 table->last--;
347 entry--;
349 if (table->last >= count / 4) return; /* no need to shrink */
350 if (count < MIN_HANDLE_ENTRIES * 2) return; /* too small to shrink */
351 count /= 2;
352 if (!(new_entries = realloc( table->entries, count * sizeof(*new_entries) ))) return;
353 table->count = count;
354 table->entries = new_entries;
357 static void inherit_handle( struct process *parent, const obj_handle_t handle, struct handle_table *table )
359 struct handle_entry *dst, *src;
360 int index;
362 dst = table->entries;
364 src = get_handle( parent, handle );
365 if (!src || !(src->access & RESERVED_INHERIT)) return;
366 index = handle_to_index( handle );
367 if (dst[index].ptr) return;
368 grab_object_for_handle( src->ptr );
369 dst[index] = *src;
370 table->last = max( table->last, index );
373 /* copy the handle table of the parent process */
374 /* return 1 if OK, 0 on error */
375 struct handle_table *copy_handle_table( struct process *process, struct process *parent,
376 const obj_handle_t *handles, unsigned int handle_count,
377 const obj_handle_t *std_handles )
379 struct handle_table *parent_table = parent->handles;
380 struct handle_table *table;
381 int i;
383 assert( parent_table );
384 assert( parent_table->obj.ops == &handle_table_ops );
386 if (!(table = alloc_handle_table( process, parent_table->count )))
387 return NULL;
389 if (handles)
391 memset( table->entries, 0, parent_table->count * sizeof(*table->entries) );
393 for (i = 0; i < handle_count; i++)
395 inherit_handle( parent, handles[i], table );
398 for (i = 0; i < 3; i++)
400 inherit_handle( parent, std_handles[i], table );
403 else
405 if ((table->last = parent_table->last) >= 0)
407 struct handle_entry *ptr = table->entries;
408 memcpy( ptr, parent_table->entries, (table->last + 1) * sizeof(struct handle_entry) );
409 for (i = 0; i <= table->last; i++, ptr++)
411 if (!ptr->ptr) continue;
412 if (ptr->access & RESERVED_INHERIT) grab_object_for_handle( ptr->ptr );
413 else ptr->ptr = NULL; /* don't inherit this entry */
417 /* attempt to shrink the table */
418 shrink_handle_table( table );
419 return table;
422 /* close a handle and decrement the refcount of the associated object */
423 unsigned int close_handle( struct process *process, obj_handle_t handle )
425 struct handle_table *table;
426 struct handle_entry *entry;
427 struct object *obj;
429 if (!(entry = get_handle( process, handle ))) return STATUS_INVALID_HANDLE;
430 if (entry->access & RESERVED_CLOSE_PROTECT) return STATUS_HANDLE_NOT_CLOSABLE;
431 obj = entry->ptr;
432 if (!obj->ops->close_handle( obj, process, handle )) return STATUS_HANDLE_NOT_CLOSABLE;
433 entry->ptr = NULL;
434 table = handle_is_global(handle) ? global_table : process->handles;
435 if (entry < table->entries + table->free) table->free = entry - table->entries;
436 if (entry == table->entries + table->last) shrink_handle_table( table );
437 release_object_from_handle( obj );
438 return STATUS_SUCCESS;
441 /* retrieve the object corresponding to one of the magic pseudo-handles */
442 static inline struct object *get_magic_handle( obj_handle_t handle )
444 switch(handle)
446 case 0xfffffffa: /* current thread impersonation token pseudo-handle */
447 return (struct object *)thread_get_impersonation_token( current );
448 case 0xfffffffb: /* current thread token pseudo-handle */
449 return (struct object *)current->token;
450 case 0xfffffffc: /* current process token pseudo-handle */
451 return (struct object *)current->process->token;
452 case 0xfffffffe: /* current thread pseudo-handle */
453 return &current->obj;
454 case 0x7fffffff: /* current process pseudo-handle */
455 case 0xffffffff: /* current process pseudo-handle */
456 return (struct object *)current->process;
457 default:
458 return NULL;
462 /* retrieve the object corresponding to a handle, incrementing its refcount */
463 struct object *get_handle_obj( struct process *process, obj_handle_t handle,
464 unsigned int access, const struct object_ops *ops )
466 struct handle_entry *entry;
467 struct object *obj;
469 if (!(obj = get_magic_handle( handle )))
471 if (!(entry = get_handle( process, handle )))
473 set_error( STATUS_INVALID_HANDLE );
474 return NULL;
476 obj = entry->ptr;
477 if (ops && (obj->ops != ops))
479 set_error( STATUS_OBJECT_TYPE_MISMATCH ); /* not the right type */
480 return NULL;
482 if ((entry->access & access) != access)
484 set_error( STATUS_ACCESS_DENIED );
485 return NULL;
488 else if (ops && (obj->ops != ops))
490 set_error( STATUS_OBJECT_TYPE_MISMATCH ); /* not the right type */
491 return NULL;
493 return grab_object( obj );
496 /* retrieve the access rights of a given handle */
497 unsigned int get_handle_access( struct process *process, obj_handle_t handle )
499 struct handle_entry *entry;
501 if (get_magic_handle( handle )) return ~RESERVED_ALL; /* magic handles have all access rights */
502 if (!(entry = get_handle( process, handle ))) return 0;
503 return entry->access & ~RESERVED_ALL;
506 /* find the first inherited handle of the given type */
507 /* this is needed for window stations and desktops (don't ask...) */
508 obj_handle_t find_inherited_handle( struct process *process, const struct object_ops *ops )
510 struct handle_table *table = process->handles;
511 struct handle_entry *ptr;
512 int i;
514 if (!table) return 0;
516 for (i = 0, ptr = table->entries; i <= table->last; i++, ptr++)
518 if (!ptr->ptr) continue;
519 if (ptr->ptr->ops != ops) continue;
520 if (ptr->access & RESERVED_INHERIT) return index_to_handle(i);
522 return 0;
525 /* get/set the handle reserved flags */
526 /* return the old flags (or -1 on error) */
527 static int set_handle_flags( struct process *process, obj_handle_t handle, int mask, int flags )
529 struct handle_entry *entry;
530 unsigned int old_access;
532 if (get_magic_handle( handle ))
534 /* we can retrieve but not set info for magic handles */
535 if (mask) set_error( STATUS_ACCESS_DENIED );
536 return 0;
538 if (!(entry = get_handle( process, handle )))
540 set_error( STATUS_INVALID_HANDLE );
541 return -1;
543 old_access = entry->access;
544 mask = (mask << RESERVED_SHIFT) & RESERVED_ALL;
545 flags = (flags << RESERVED_SHIFT) & mask;
546 entry->access = (entry->access & ~mask) | flags;
547 return (old_access & RESERVED_ALL) >> RESERVED_SHIFT;
550 /* duplicate a handle */
551 obj_handle_t duplicate_handle( struct process *src, obj_handle_t src_handle, struct process *dst,
552 unsigned int access, unsigned int attr, unsigned int options )
554 obj_handle_t res;
555 struct handle_entry *entry;
556 unsigned int src_access;
557 struct object *obj = get_handle_obj( src, src_handle, 0, NULL );
559 if (!obj) return 0;
560 if ((entry = get_handle( src, src_handle )))
561 src_access = entry->access;
562 else /* pseudo-handle, give it full access */
563 src_access = obj->ops->map_access( obj, GENERIC_ALL );
564 src_access &= ~RESERVED_ALL;
566 if (options & DUP_HANDLE_SAME_ACCESS)
567 access = src_access;
568 else
569 access = obj->ops->map_access( obj, access ) & ~RESERVED_ALL;
571 /* asking for the more access rights than src_access? */
572 if (access & ~src_access)
574 if ((current->token && !check_object_access( current->token, obj, &access )) ||
575 !check_object_access( dst->token, obj, &access ))
577 release_object( obj );
578 return 0;
581 if (options & DUP_HANDLE_MAKE_GLOBAL)
582 res = alloc_global_handle( obj, access );
583 else
584 res = alloc_handle_no_access_check( dst, obj, access, attr );
586 else
588 if (options & DUP_HANDLE_MAKE_GLOBAL)
589 res = alloc_global_handle_no_access_check( obj, access );
590 else if ((options & DUP_HANDLE_CLOSE_SOURCE) && src == dst &&
591 entry && !(entry->access & RESERVED_CLOSE_PROTECT))
593 if (attr & OBJ_INHERIT) access |= RESERVED_INHERIT;
594 entry->access = access;
595 res = src_handle;
597 else
598 res = alloc_handle_entry( dst, obj, access, attr );
601 release_object( obj );
602 return res;
605 /* open a new handle to an existing object */
606 obj_handle_t open_object( struct process *process, obj_handle_t parent, unsigned int access,
607 const struct object_ops *ops, const struct unicode_str *name,
608 unsigned int attributes )
610 obj_handle_t handle = 0;
611 struct object *obj, *root = NULL;
613 if (name->len >= 65534)
615 set_error( STATUS_OBJECT_NAME_INVALID );
616 return 0;
619 if (parent)
621 if (name->len)
622 root = get_directory_obj( process, parent );
623 else /* opening the object itself can work for non-directories too */
624 root = get_handle_obj( process, parent, 0, NULL );
625 if (!root) return 0;
628 if ((obj = open_named_object( root, ops, name, attributes )))
630 handle = alloc_handle( process, obj, access, attributes );
631 release_object( obj );
633 if (root) release_object( root );
634 return handle;
637 /* return the size of the handle table of a given process */
638 unsigned int get_handle_table_count( struct process *process )
640 if (!process->handles) return 0;
641 return process->handles->count;
644 /* close a handle */
645 DECL_HANDLER(close_handle)
647 unsigned int err = close_handle( current->process, req->handle );
648 set_error( err );
651 /* set a handle information */
652 DECL_HANDLER(set_handle_info)
654 reply->old_flags = set_handle_flags( current->process, req->handle, req->mask, req->flags );
657 /* duplicate a handle */
658 DECL_HANDLER(dup_handle)
660 struct process *src, *dst = NULL;
662 reply->handle = 0;
663 if ((src = get_process_from_handle( req->src_process, PROCESS_DUP_HANDLE )))
665 if (req->options & DUP_HANDLE_MAKE_GLOBAL)
667 reply->handle = duplicate_handle( src, req->src_handle, NULL,
668 req->access, req->attributes, req->options );
670 else if ((dst = get_process_from_handle( req->dst_process, PROCESS_DUP_HANDLE )))
672 reply->handle = duplicate_handle( src, req->src_handle, dst,
673 req->access, req->attributes, req->options );
674 release_object( dst );
676 /* close the handle no matter what happened */
677 if ((req->options & DUP_HANDLE_CLOSE_SOURCE) && (src != dst || req->src_handle != reply->handle))
678 reply->closed = !close_handle( src, req->src_handle );
679 reply->self = (src == current->process);
680 release_object( src );
684 DECL_HANDLER(get_object_info)
686 struct object *obj;
687 WCHAR *name;
689 if (!(obj = get_handle_obj( current->process, req->handle, 0, NULL ))) return;
691 reply->access = get_handle_access( current->process, req->handle );
692 reply->ref_count = obj->refcount;
693 reply->handle_count = obj->handle_count;
694 if ((name = obj->ops->get_full_name( obj, &reply->total )))
695 set_reply_data_ptr( name, min( reply->total, get_reply_max_size() ));
696 release_object( obj );
699 DECL_HANDLER(set_security_object)
701 data_size_t sd_size = get_req_data_size();
702 const struct security_descriptor *sd = get_req_data();
703 struct object *obj;
704 unsigned int access = 0;
706 if (!sd_is_valid( sd, sd_size ))
708 set_error( STATUS_ACCESS_VIOLATION );
709 return;
712 if (req->security_info & OWNER_SECURITY_INFORMATION ||
713 req->security_info & GROUP_SECURITY_INFORMATION ||
714 req->security_info & LABEL_SECURITY_INFORMATION)
715 access |= WRITE_OWNER;
716 if (req->security_info & SACL_SECURITY_INFORMATION)
717 access |= ACCESS_SYSTEM_SECURITY;
718 if (req->security_info & DACL_SECURITY_INFORMATION)
719 access |= WRITE_DAC;
721 if (!(obj = get_handle_obj( current->process, req->handle, access, NULL ))) return;
723 obj->ops->set_sd( obj, sd, req->security_info );
724 release_object( obj );
727 DECL_HANDLER(get_security_object)
729 const struct security_descriptor *sd;
730 struct object *obj;
731 unsigned int access = READ_CONTROL;
732 struct security_descriptor req_sd;
733 int present;
734 const SID *owner, *group;
735 const ACL *sacl, *dacl;
736 ACL *label_acl = NULL;
738 if (req->security_info & SACL_SECURITY_INFORMATION)
739 access |= ACCESS_SYSTEM_SECURITY;
741 if (!(obj = get_handle_obj( current->process, req->handle, access, NULL ))) return;
743 sd = obj->ops->get_sd( obj );
744 if (sd)
746 req_sd.control = sd->control & ~SE_SELF_RELATIVE;
748 owner = sd_get_owner( sd );
749 if (req->security_info & OWNER_SECURITY_INFORMATION)
750 req_sd.owner_len = sd->owner_len;
751 else
752 req_sd.owner_len = 0;
754 group = sd_get_group( sd );
755 if (req->security_info & GROUP_SECURITY_INFORMATION)
756 req_sd.group_len = sd->group_len;
757 else
758 req_sd.group_len = 0;
760 sacl = sd_get_sacl( sd, &present );
761 if (req->security_info & SACL_SECURITY_INFORMATION && present)
762 req_sd.sacl_len = sd->sacl_len;
763 else if (req->security_info & LABEL_SECURITY_INFORMATION && present && sacl)
765 if (!(label_acl = extract_security_labels( sacl ))) goto done;
766 req_sd.sacl_len = label_acl->AclSize;
767 sacl = label_acl;
769 else
770 req_sd.sacl_len = 0;
772 dacl = sd_get_dacl( sd, &present );
773 if (req->security_info & DACL_SECURITY_INFORMATION && present)
774 req_sd.dacl_len = sd->dacl_len;
775 else
776 req_sd.dacl_len = 0;
778 reply->sd_len = sizeof(req_sd) + req_sd.owner_len + req_sd.group_len +
779 req_sd.sacl_len + req_sd.dacl_len;
780 if (reply->sd_len <= get_reply_max_size())
782 char *ptr = set_reply_data_size(reply->sd_len);
784 memcpy( ptr, &req_sd, sizeof(req_sd) );
785 ptr += sizeof(req_sd);
786 memcpy( ptr, owner, req_sd.owner_len );
787 ptr += req_sd.owner_len;
788 memcpy( ptr, group, req_sd.group_len );
789 ptr += req_sd.group_len;
790 memcpy( ptr, sacl, req_sd.sacl_len );
791 ptr += req_sd.sacl_len;
792 memcpy( ptr, dacl, req_sd.dacl_len );
794 else
795 set_error(STATUS_BUFFER_TOO_SMALL);
798 done:
799 release_object( obj );
800 free( label_acl );
803 struct enum_handle_info
805 unsigned int count;
806 struct handle_info *handle;
809 static int enum_handles( struct process *process, void *user )
811 struct enum_handle_info *info = user;
812 struct handle_table *table = process->handles;
813 struct handle_entry *entry;
814 struct handle_info *handle;
815 unsigned int i;
817 if (!table)
818 return 0;
820 for (i = 0, entry = table->entries; i <= table->last; i++, entry++)
822 if (!entry->ptr) continue;
823 if (!info->handle)
825 info->count++;
826 continue;
828 assert( info->count );
829 handle = info->handle++;
830 handle->owner = process->id;
831 handle->handle = index_to_handle(i);
832 handle->access = entry->access & ~RESERVED_ALL;
833 info->count--;
836 return 0;
839 DECL_HANDLER(get_system_handles)
841 struct enum_handle_info info;
842 struct handle_info *handle;
843 data_size_t max_handles = get_reply_max_size() / sizeof(*handle);
845 info.handle = NULL;
846 info.count = 0;
847 enum_processes( enum_handles, &info );
848 reply->count = info.count;
850 if (max_handles < info.count)
851 set_error( STATUS_BUFFER_TOO_SMALL );
852 else if ((handle = set_reply_data_size( info.count * sizeof(*handle) )))
854 info.handle = handle;
855 enum_processes( enum_handles, &info );
859 DECL_HANDLER(make_temporary)
861 struct object *obj;
863 if (!(obj = get_handle_obj( current->process, req->handle, 0, NULL ))) return;
865 if (obj->is_permanent)
867 make_object_temporary( obj );
868 release_object( obj );
870 release_object( obj );