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
22 #include "wine/port.h"
32 #define WIN32_NO_STATUS
44 struct object
*ptr
; /* object */
45 unsigned int access
; /* access rights */
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
)
104 obj
->ops
->type
->handle_count
++;
105 obj
->ops
->type
->handle_max
= max( obj
->ops
->type
->handle_max
, obj
->ops
->type
->handle_count
);
106 return grab_object( obj
);
109 /* release an object and decrement its handle count */
110 static void release_object_from_handle( struct object
*obj
)
112 assert( obj
->handle_count
);
113 obj
->ops
->type
->handle_count
--;
115 release_object( obj
);
118 static void handle_table_dump( struct object
*obj
, int verbose
);
119 static void handle_table_destroy( struct object
*obj
);
121 static const struct object_ops handle_table_ops
=
123 sizeof(struct handle_table
), /* size */
125 handle_table_dump
, /* dump */
126 no_add_queue
, /* add_queue */
127 NULL
, /* remove_queue */
129 NULL
, /* satisfied */
130 no_signal
, /* signal */
131 no_get_fd
, /* get_fd */
132 default_map_access
, /* map_access */
133 default_get_sd
, /* get_sd */
134 default_set_sd
, /* set_sd */
135 no_get_full_name
, /* get_full_name */
136 no_lookup_name
, /* lookup_name */
137 no_link_name
, /* link_name */
138 NULL
, /* unlink_name */
139 no_open_file
, /* open_file */
140 no_kernel_obj_list
, /* get_kernel_obj_list */
141 no_close_handle
, /* close_handle */
142 handle_table_destroy
/* destroy */
145 /* dump a handle table */
146 static void handle_table_dump( struct object
*obj
, int verbose
)
149 struct handle_table
*table
= (struct handle_table
*)obj
;
150 struct handle_entry
*entry
;
152 assert( obj
->ops
== &handle_table_ops
);
154 fprintf( stderr
, "Handle table last=%d count=%d process=%p\n",
155 table
->last
, table
->count
, table
->process
);
156 if (!verbose
) return;
157 entry
= table
->entries
;
158 for (i
= 0; i
<= table
->last
; i
++, entry
++)
160 if (!entry
->ptr
) continue;
161 fprintf( stderr
, " %04x: %p %08x ",
162 index_to_handle(i
), entry
->ptr
, entry
->access
);
163 dump_object_name( entry
->ptr
);
164 entry
->ptr
->ops
->dump( entry
->ptr
, 0 );
168 /* destroy a handle table */
169 static void handle_table_destroy( struct object
*obj
)
172 struct handle_table
*table
= (struct handle_table
*)obj
;
173 struct handle_entry
*entry
;
175 assert( obj
->ops
== &handle_table_ops
);
177 /* first notify all objects that handles are being closed */
180 for (i
= 0, entry
= table
->entries
; i
<= table
->last
; i
++, entry
++)
182 struct object
*obj
= entry
->ptr
;
183 if (obj
) obj
->ops
->close_handle( obj
, table
->process
, index_to_handle(i
) );
187 for (i
= 0, entry
= table
->entries
; i
<= table
->last
; i
++, entry
++)
189 struct object
*obj
= entry
->ptr
;
191 if (obj
) release_object_from_handle( obj
);
193 free( table
->entries
);
196 /* close all the process handles and free the handle table */
197 void close_process_handles( struct process
*process
)
199 struct handle_table
*table
= process
->handles
;
201 process
->handles
= NULL
;
202 if (table
) release_object( table
);
205 /* allocate a new handle table */
206 struct handle_table
*alloc_handle_table( struct process
*process
, int count
)
208 struct handle_table
*table
;
210 if (count
< MIN_HANDLE_ENTRIES
) count
= MIN_HANDLE_ENTRIES
;
211 if (!(table
= alloc_object( &handle_table_ops
)))
213 table
->process
= process
;
214 table
->count
= count
;
217 if ((table
->entries
= mem_alloc( count
* sizeof(*table
->entries
) ))) return table
;
218 release_object( table
);
222 /* grow a handle table */
223 static int grow_handle_table( struct handle_table
*table
)
225 struct handle_entry
*new_entries
;
226 int count
= min( table
->count
* 2, MAX_HANDLE_ENTRIES
);
228 if (count
== table
->count
||
229 !(new_entries
= realloc( table
->entries
, count
* sizeof(struct handle_entry
) )))
231 set_error( STATUS_INSUFFICIENT_RESOURCES
);
234 table
->entries
= new_entries
;
235 table
->count
= count
;
239 /* allocate the first free entry in the handle table */
240 static obj_handle_t
alloc_entry( struct handle_table
*table
, void *obj
, unsigned int access
)
242 struct handle_entry
*entry
= table
->entries
+ table
->free
;
245 for (i
= table
->free
; i
<= table
->last
; i
++, entry
++) if (!entry
->ptr
) goto found
;
246 if (i
>= table
->count
)
248 if (!grow_handle_table( table
)) return 0;
249 entry
= table
->entries
+ i
; /* the entries may have moved */
254 entry
->ptr
= grab_object_for_handle( obj
);
255 entry
->access
= access
;
256 return index_to_handle(i
);
259 /* allocate a handle for an object, incrementing its refcount */
260 static obj_handle_t
alloc_handle_entry( struct process
*process
, void *ptr
,
261 unsigned int access
, unsigned int attr
)
263 struct object
*obj
= ptr
;
265 assert( !(access
& RESERVED_ALL
) );
266 if (attr
& OBJ_INHERIT
) access
|= RESERVED_INHERIT
;
267 if (!process
->handles
)
269 set_error( STATUS_PROCESS_IS_TERMINATING
);
272 return alloc_entry( process
->handles
, obj
, access
);
275 /* allocate a handle for an object, incrementing its refcount */
276 /* return the handle, or 0 on error */
277 obj_handle_t
alloc_handle_no_access_check( struct process
*process
, void *ptr
, unsigned int access
, unsigned int attr
)
279 struct object
*obj
= ptr
;
280 if (access
& MAXIMUM_ALLOWED
) access
= GENERIC_ALL
;
281 access
= obj
->ops
->map_access( obj
, access
) & ~RESERVED_ALL
;
282 return alloc_handle_entry( process
, ptr
, access
, attr
);
285 /* allocate a handle for an object, checking the dacl allows the process to */
286 /* access it and incrementing its refcount */
287 /* return the handle, or 0 on error */
288 obj_handle_t
alloc_handle( struct process
*process
, void *ptr
, unsigned int access
, unsigned int attr
)
290 struct object
*obj
= ptr
;
291 access
= obj
->ops
->map_access( obj
, access
) & ~RESERVED_ALL
;
292 if (access
&& !check_object_access( NULL
, obj
, &access
)) return 0;
293 return alloc_handle_entry( process
, ptr
, access
, attr
);
296 /* allocate a global handle for an object, incrementing its refcount */
297 /* return the handle, or 0 on error */
298 static obj_handle_t
alloc_global_handle_no_access_check( void *obj
, unsigned int access
)
302 if (!(global_table
= alloc_handle_table( NULL
, 0 )))
304 make_object_permanent( &global_table
->obj
);
306 return handle_local_to_global( alloc_entry( global_table
, obj
, access
));
309 /* allocate a global handle for an object, checking the dacl allows the */
310 /* process to access it and incrementing its refcount and incrementing its refcount */
311 /* return the handle, or 0 on error */
312 static obj_handle_t
alloc_global_handle( void *obj
, unsigned int access
)
314 if (access
&& !check_object_access( NULL
, obj
, &access
)) return 0;
315 return alloc_global_handle_no_access_check( obj
, access
);
318 /* return a handle entry, or NULL if the handle is invalid */
319 static struct handle_entry
*get_handle( struct process
*process
, obj_handle_t handle
)
321 struct handle_table
*table
= process
->handles
;
322 struct handle_entry
*entry
;
325 if (handle_is_global(handle
))
327 handle
= handle_global_to_local(handle
);
328 table
= global_table
;
330 if (!table
) return NULL
;
331 index
= handle_to_index( handle
);
332 if (index
< 0) return NULL
;
333 if (index
> table
->last
) return NULL
;
334 entry
= table
->entries
+ index
;
335 if (!entry
->ptr
) return NULL
;
339 /* attempt to shrink a table */
340 static void shrink_handle_table( struct handle_table
*table
)
342 struct handle_entry
*entry
= table
->entries
+ table
->last
;
343 struct handle_entry
*new_entries
;
344 int count
= table
->count
;
346 while (table
->last
>= 0)
348 if (entry
->ptr
) break;
352 if (table
->last
>= count
/ 4) return; /* no need to shrink */
353 if (count
< MIN_HANDLE_ENTRIES
* 2) return; /* too small to shrink */
355 if (!(new_entries
= realloc( table
->entries
, count
* sizeof(*new_entries
) ))) return;
356 table
->count
= count
;
357 table
->entries
= new_entries
;
360 static void inherit_handle( struct process
*parent
, const obj_handle_t handle
, struct handle_table
*table
)
362 struct handle_entry
*dst
, *src
;
365 dst
= table
->entries
;
367 src
= get_handle( parent
, handle
);
368 if (!src
|| !(src
->access
& RESERVED_INHERIT
)) return;
369 index
= handle_to_index( handle
);
370 if (dst
[index
].ptr
) return;
371 grab_object_for_handle( src
->ptr
);
373 table
->last
= max( table
->last
, index
);
376 /* copy the handle table of the parent process */
377 /* return 1 if OK, 0 on error */
378 struct handle_table
*copy_handle_table( struct process
*process
, struct process
*parent
,
379 const obj_handle_t
*handles
, unsigned int handle_count
,
380 const obj_handle_t
*std_handles
)
382 struct handle_table
*parent_table
= parent
->handles
;
383 struct handle_table
*table
;
386 assert( parent_table
);
387 assert( parent_table
->obj
.ops
== &handle_table_ops
);
389 if (!(table
= alloc_handle_table( process
, parent_table
->count
)))
394 memset( table
->entries
, 0, parent_table
->count
* sizeof(*table
->entries
) );
396 for (i
= 0; i
< handle_count
; i
++)
398 inherit_handle( parent
, handles
[i
], table
);
401 for (i
= 0; i
< 3; i
++)
403 inherit_handle( parent
, std_handles
[i
], table
);
408 if ((table
->last
= parent_table
->last
) >= 0)
410 struct handle_entry
*ptr
= table
->entries
;
411 memcpy( ptr
, parent_table
->entries
, (table
->last
+ 1) * sizeof(struct handle_entry
) );
412 for (i
= 0; i
<= table
->last
; i
++, ptr
++)
414 if (!ptr
->ptr
) continue;
415 if (ptr
->access
& RESERVED_INHERIT
) grab_object_for_handle( ptr
->ptr
);
416 else ptr
->ptr
= NULL
; /* don't inherit this entry */
420 /* attempt to shrink the table */
421 shrink_handle_table( table
);
425 /* close a handle and decrement the refcount of the associated object */
426 unsigned int close_handle( struct process
*process
, obj_handle_t handle
)
428 struct handle_table
*table
;
429 struct handle_entry
*entry
;
432 if (!(entry
= get_handle( process
, handle
))) return STATUS_INVALID_HANDLE
;
433 if (entry
->access
& RESERVED_CLOSE_PROTECT
) return STATUS_HANDLE_NOT_CLOSABLE
;
435 if (!obj
->ops
->close_handle( obj
, process
, handle
)) return STATUS_HANDLE_NOT_CLOSABLE
;
437 table
= handle_is_global(handle
) ? global_table
: process
->handles
;
438 if (entry
< table
->entries
+ table
->free
) table
->free
= entry
- table
->entries
;
439 if (entry
== table
->entries
+ table
->last
) shrink_handle_table( table
);
440 release_object_from_handle( obj
);
441 return STATUS_SUCCESS
;
444 /* retrieve the object corresponding to one of the magic pseudo-handles */
445 static inline struct object
*get_magic_handle( obj_handle_t handle
)
449 case 0xfffffffa: /* current thread impersonation token pseudo-handle */
450 return (struct object
*)thread_get_impersonation_token( current
);
451 case 0xfffffffb: /* current thread token pseudo-handle */
452 return (struct object
*)current
->token
;
453 case 0xfffffffc: /* current process token pseudo-handle */
454 return (struct object
*)current
->process
->token
;
455 case 0xfffffffe: /* current thread pseudo-handle */
456 return ¤t
->obj
;
457 case 0x7fffffff: /* current process pseudo-handle */
458 case 0xffffffff: /* current process pseudo-handle */
459 return (struct object
*)current
->process
;
465 /* retrieve the object corresponding to a handle, incrementing its refcount */
466 struct object
*get_handle_obj( struct process
*process
, obj_handle_t handle
,
467 unsigned int access
, const struct object_ops
*ops
)
469 struct handle_entry
*entry
;
472 if (!(obj
= get_magic_handle( handle
)))
474 if (!(entry
= get_handle( process
, handle
)))
476 set_error( STATUS_INVALID_HANDLE
);
480 if (ops
&& (obj
->ops
!= ops
))
482 set_error( STATUS_OBJECT_TYPE_MISMATCH
); /* not the right type */
485 if ((entry
->access
& access
) != access
)
487 set_error( STATUS_ACCESS_DENIED
);
491 else if (ops
&& (obj
->ops
!= ops
))
493 set_error( STATUS_OBJECT_TYPE_MISMATCH
); /* not the right type */
496 return grab_object( obj
);
499 /* retrieve the access rights of a given handle */
500 unsigned int get_handle_access( struct process
*process
, obj_handle_t handle
)
502 struct handle_entry
*entry
;
504 if (get_magic_handle( handle
)) return ~RESERVED_ALL
; /* magic handles have all access rights */
505 if (!(entry
= get_handle( process
, handle
))) return 0;
506 return entry
->access
& ~RESERVED_ALL
;
509 /* find the first inherited handle of the given type */
510 /* this is needed for window stations and desktops (don't ask...) */
511 obj_handle_t
find_inherited_handle( struct process
*process
, const struct object_ops
*ops
)
513 struct handle_table
*table
= process
->handles
;
514 struct handle_entry
*ptr
;
517 if (!table
) return 0;
519 for (i
= 0, ptr
= table
->entries
; i
<= table
->last
; i
++, ptr
++)
521 if (!ptr
->ptr
) continue;
522 if (ptr
->ptr
->ops
!= ops
) continue;
523 if (ptr
->access
& RESERVED_INHERIT
) return index_to_handle(i
);
528 /* get/set the handle reserved flags */
529 /* return the old flags (or -1 on error) */
530 static int set_handle_flags( struct process
*process
, obj_handle_t handle
, int mask
, int flags
)
532 struct handle_entry
*entry
;
533 unsigned int old_access
;
535 if (get_magic_handle( handle
))
537 /* we can retrieve but not set info for magic handles */
538 if (mask
) set_error( STATUS_ACCESS_DENIED
);
541 if (!(entry
= get_handle( process
, handle
)))
543 set_error( STATUS_INVALID_HANDLE
);
546 old_access
= entry
->access
;
547 mask
= (mask
<< RESERVED_SHIFT
) & RESERVED_ALL
;
548 flags
= (flags
<< RESERVED_SHIFT
) & mask
;
549 entry
->access
= (entry
->access
& ~mask
) | flags
;
550 return (old_access
& RESERVED_ALL
) >> RESERVED_SHIFT
;
553 /* duplicate a handle */
554 obj_handle_t
duplicate_handle( struct process
*src
, obj_handle_t src_handle
, struct process
*dst
,
555 unsigned int access
, unsigned int attr
, unsigned int options
)
558 struct handle_entry
*entry
;
559 unsigned int src_access
;
560 struct object
*obj
= get_handle_obj( src
, src_handle
, 0, NULL
);
563 if ((entry
= get_handle( src
, src_handle
)))
564 src_access
= entry
->access
;
565 else /* pseudo-handle, give it full access */
566 src_access
= obj
->ops
->map_access( obj
, GENERIC_ALL
);
567 src_access
&= ~RESERVED_ALL
;
569 if (options
& DUPLICATE_SAME_ACCESS
)
572 access
= obj
->ops
->map_access( obj
, access
) & ~RESERVED_ALL
;
574 /* asking for the more access rights than src_access? */
575 if (access
& ~src_access
)
577 if ((current
->token
&& !check_object_access( current
->token
, obj
, &access
)) ||
578 !check_object_access( dst
->token
, obj
, &access
))
580 release_object( obj
);
584 if (options
& DUPLICATE_MAKE_GLOBAL
)
585 res
= alloc_global_handle( obj
, access
);
587 res
= alloc_handle_no_access_check( dst
, obj
, access
, attr
);
591 if (options
& DUPLICATE_MAKE_GLOBAL
)
592 res
= alloc_global_handle_no_access_check( obj
, access
);
593 else if ((options
& DUPLICATE_CLOSE_SOURCE
) && src
== dst
&&
594 entry
&& !(entry
->access
& RESERVED_CLOSE_PROTECT
))
596 if (attr
& OBJ_INHERIT
) access
|= RESERVED_INHERIT
;
597 entry
->access
= access
;
601 res
= alloc_handle_entry( dst
, obj
, access
, attr
);
604 release_object( obj
);
608 /* open a new handle to an existing object */
609 obj_handle_t
open_object( struct process
*process
, obj_handle_t parent
, unsigned int access
,
610 const struct object_ops
*ops
, const struct unicode_str
*name
,
611 unsigned int attributes
)
613 obj_handle_t handle
= 0;
614 struct object
*obj
, *root
= NULL
;
616 if (name
->len
>= 65534)
618 set_error( STATUS_OBJECT_NAME_INVALID
);
625 root
= get_directory_obj( process
, parent
);
626 else /* opening the object itself can work for non-directories too */
627 root
= get_handle_obj( process
, parent
, 0, NULL
);
631 if ((obj
= open_named_object( root
, ops
, name
, attributes
)))
633 handle
= alloc_handle( process
, obj
, access
, attributes
);
634 release_object( obj
);
636 if (root
) release_object( root
);
640 /* return the size of the handle table of a given process */
641 unsigned int get_handle_table_count( struct process
*process
)
643 if (!process
->handles
) return 0;
644 return process
->handles
->count
;
648 DECL_HANDLER(close_handle
)
650 unsigned int err
= close_handle( current
->process
, req
->handle
);
654 /* set a handle information */
655 DECL_HANDLER(set_handle_info
)
657 reply
->old_flags
= set_handle_flags( current
->process
, req
->handle
, req
->mask
, req
->flags
);
660 /* duplicate a handle */
661 DECL_HANDLER(dup_handle
)
663 struct process
*src
, *dst
= NULL
;
666 if ((src
= get_process_from_handle( req
->src_process
, PROCESS_DUP_HANDLE
)))
668 if (req
->options
& DUPLICATE_MAKE_GLOBAL
)
670 reply
->handle
= duplicate_handle( src
, req
->src_handle
, NULL
,
671 req
->access
, req
->attributes
, req
->options
);
673 else if ((dst
= get_process_from_handle( req
->dst_process
, PROCESS_DUP_HANDLE
)))
675 reply
->handle
= duplicate_handle( src
, req
->src_handle
, dst
,
676 req
->access
, req
->attributes
, req
->options
);
677 release_object( dst
);
679 /* close the handle no matter what happened */
680 if ((req
->options
& DUPLICATE_CLOSE_SOURCE
) && (src
!= dst
|| req
->src_handle
!= reply
->handle
))
681 reply
->closed
= !close_handle( src
, req
->src_handle
);
682 reply
->self
= (src
== current
->process
);
683 release_object( src
);
687 DECL_HANDLER(get_object_info
)
692 if (!(obj
= get_handle_obj( current
->process
, req
->handle
, 0, NULL
))) return;
694 reply
->access
= get_handle_access( current
->process
, req
->handle
);
695 reply
->ref_count
= obj
->refcount
;
696 reply
->handle_count
= obj
->handle_count
;
697 if ((name
= obj
->ops
->get_full_name( obj
, &reply
->total
)))
698 set_reply_data_ptr( name
, min( reply
->total
, get_reply_max_size() ));
699 release_object( obj
);
702 DECL_HANDLER(set_security_object
)
704 data_size_t sd_size
= get_req_data_size();
705 const struct security_descriptor
*sd
= get_req_data();
707 unsigned int access
= 0;
709 if (!sd_is_valid( sd
, sd_size
))
711 set_error( STATUS_ACCESS_VIOLATION
);
715 if (req
->security_info
& OWNER_SECURITY_INFORMATION
||
716 req
->security_info
& GROUP_SECURITY_INFORMATION
||
717 req
->security_info
& LABEL_SECURITY_INFORMATION
)
718 access
|= WRITE_OWNER
;
719 if (req
->security_info
& SACL_SECURITY_INFORMATION
)
720 access
|= ACCESS_SYSTEM_SECURITY
;
721 if (req
->security_info
& DACL_SECURITY_INFORMATION
)
724 if (!(obj
= get_handle_obj( current
->process
, req
->handle
, access
, NULL
))) return;
726 obj
->ops
->set_sd( obj
, sd
, req
->security_info
);
727 release_object( obj
);
730 DECL_HANDLER(get_security_object
)
732 const struct security_descriptor
*sd
;
734 unsigned int access
= READ_CONTROL
;
735 struct security_descriptor req_sd
;
737 const SID
*owner
, *group
;
738 const ACL
*sacl
, *dacl
;
739 ACL
*label_acl
= NULL
;
741 if (req
->security_info
& SACL_SECURITY_INFORMATION
)
742 access
|= ACCESS_SYSTEM_SECURITY
;
744 if (!(obj
= get_handle_obj( current
->process
, req
->handle
, access
, NULL
))) return;
746 sd
= obj
->ops
->get_sd( obj
);
749 req_sd
.control
= sd
->control
& ~SE_SELF_RELATIVE
;
751 owner
= sd_get_owner( sd
);
752 if (req
->security_info
& OWNER_SECURITY_INFORMATION
)
753 req_sd
.owner_len
= sd
->owner_len
;
755 req_sd
.owner_len
= 0;
757 group
= sd_get_group( sd
);
758 if (req
->security_info
& GROUP_SECURITY_INFORMATION
)
759 req_sd
.group_len
= sd
->group_len
;
761 req_sd
.group_len
= 0;
763 sacl
= sd_get_sacl( sd
, &present
);
764 if (req
->security_info
& SACL_SECURITY_INFORMATION
&& present
)
765 req_sd
.sacl_len
= sd
->sacl_len
;
766 else if (req
->security_info
& LABEL_SECURITY_INFORMATION
&& present
&& sacl
)
768 if (!(label_acl
= extract_security_labels( sacl
))) goto done
;
769 req_sd
.sacl_len
= label_acl
->AclSize
;
775 dacl
= sd_get_dacl( sd
, &present
);
776 if (req
->security_info
& DACL_SECURITY_INFORMATION
&& present
)
777 req_sd
.dacl_len
= sd
->dacl_len
;
781 reply
->sd_len
= sizeof(req_sd
) + req_sd
.owner_len
+ req_sd
.group_len
+
782 req_sd
.sacl_len
+ req_sd
.dacl_len
;
783 if (reply
->sd_len
<= get_reply_max_size())
785 char *ptr
= set_reply_data_size(reply
->sd_len
);
787 memcpy( ptr
, &req_sd
, sizeof(req_sd
) );
788 ptr
+= sizeof(req_sd
);
789 memcpy( ptr
, owner
, req_sd
.owner_len
);
790 ptr
+= req_sd
.owner_len
;
791 memcpy( ptr
, group
, req_sd
.group_len
);
792 ptr
+= req_sd
.group_len
;
793 memcpy( ptr
, sacl
, req_sd
.sacl_len
);
794 ptr
+= req_sd
.sacl_len
;
795 memcpy( ptr
, dacl
, req_sd
.dacl_len
);
798 set_error(STATUS_BUFFER_TOO_SMALL
);
802 release_object( obj
);
806 struct enum_handle_info
809 struct handle_info
*handle
;
812 static int enum_handles( struct process
*process
, void *user
)
814 struct enum_handle_info
*info
= user
;
815 struct handle_table
*table
= process
->handles
;
816 struct handle_entry
*entry
;
817 struct handle_info
*handle
;
823 for (i
= 0, entry
= table
->entries
; i
<= table
->last
; i
++, entry
++)
825 if (!entry
->ptr
) continue;
831 assert( info
->count
);
832 handle
= info
->handle
++;
833 handle
->owner
= process
->id
;
834 handle
->handle
= index_to_handle(i
);
835 handle
->access
= entry
->access
& ~RESERVED_ALL
;
836 handle
->type
= entry
->ptr
->ops
->type
->index
;
837 handle
->attributes
= 0;
838 if (entry
->access
& RESERVED_INHERIT
) handle
->attributes
|= OBJ_INHERIT
;
839 if (entry
->access
& RESERVED_CLOSE_PROTECT
) handle
->attributes
|= OBJ_PROTECT_CLOSE
;
846 DECL_HANDLER(get_system_handles
)
848 struct enum_handle_info info
;
849 struct handle_info
*handle
;
850 data_size_t max_handles
= get_reply_max_size() / sizeof(*handle
);
854 enum_processes( enum_handles
, &info
);
855 reply
->count
= info
.count
;
857 if (max_handles
< info
.count
)
858 set_error( STATUS_BUFFER_TOO_SMALL
);
859 else if ((handle
= set_reply_data_size( info
.count
* sizeof(*handle
) )))
861 info
.handle
= handle
;
862 enum_processes( enum_handles
, &info
);
866 DECL_HANDLER(make_temporary
)
870 if (!(obj
= get_handle_obj( current
->process
, req
->handle
, 0, NULL
))) return;
872 if (obj
->is_permanent
)
874 make_object_temporary( obj
);
875 release_object( obj
);
877 release_object( obj
);