object.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. /*
  2. * Server-side objects
  3. *
  4. * Copyright (C) 1998 Alexandre Julliard
  5. *
  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.
  10. *
  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.
  15. *
  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
  19. */
  20. #include "config.h"
  21. #include "wine/port.h"
  22. #include <assert.h>
  23. #include <limits.h>
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <unistd.h>
  28. #include <stdarg.h>
  29. #ifdef HAVE_VALGRIND_MEMCHECK_H
  30. #include <valgrind/memcheck.h>
  31. #endif
  32. #include "ntstatus.h"
  33. #define WIN32_NO_STATUS
  34. #include "winternl.h"
  35. #include "file.h"
  36. #include "process.h"
  37. #include "thread.h"
  38. #include "unicode.h"
  39. #include "security.h"
  40. struct namespace
  41. {
  42. unsigned int hash_size; /* size of hash table */
  43. struct list names[1]; /* array of hash entry lists */
  44. };
  45. #ifdef DEBUG_OBJECTS
  46. static struct list object_list = LIST_INIT(object_list);
  47. static struct list static_object_list = LIST_INIT(static_object_list);
  48. void dump_objects(void)
  49. {
  50. struct list *p;
  51. LIST_FOR_EACH( p, &static_object_list )
  52. {
  53. struct object *ptr = LIST_ENTRY( p, struct object, obj_list );
  54. fprintf( stderr, "%p:%d: ", ptr, ptr->refcount );
  55. dump_object_name( ptr );
  56. ptr->ops->dump( ptr, 1 );
  57. }
  58. LIST_FOR_EACH( p, &object_list )
  59. {
  60. struct object *ptr = LIST_ENTRY( p, struct object, obj_list );
  61. fprintf( stderr, "%p:%d: ", ptr, ptr->refcount );
  62. dump_object_name( ptr );
  63. ptr->ops->dump( ptr, 1 );
  64. }
  65. }
  66. void close_objects(void)
  67. {
  68. struct list *ptr;
  69. /* release the static objects */
  70. while ((ptr = list_head( &static_object_list )))
  71. {
  72. struct object *obj = LIST_ENTRY( ptr, struct object, obj_list );
  73. /* move it back to the standard list before freeing */
  74. list_remove( &obj->obj_list );
  75. list_add_head( &object_list, &obj->obj_list );
  76. release_object( obj );
  77. }
  78. dump_objects(); /* dump any remaining objects */
  79. }
  80. #endif /* DEBUG_OBJECTS */
  81. /*****************************************************************/
  82. /* mark a block of memory as uninitialized for debugging purposes */
  83. static inline void mark_block_uninitialized( void *ptr, size_t size )
  84. {
  85. memset( ptr, 0x55, size );
  86. #if defined(VALGRIND_MAKE_MEM_UNDEFINED)
  87. VALGRIND_DISCARD( VALGRIND_MAKE_MEM_UNDEFINED( ptr, size ));
  88. #elif defined(VALGRIND_MAKE_WRITABLE)
  89. VALGRIND_DISCARD( VALGRIND_MAKE_WRITABLE( ptr, size ));
  90. #endif
  91. }
  92. /* malloc replacement */
  93. void *mem_alloc( size_t size )
  94. {
  95. void *ptr = malloc( size );
  96. if (ptr) mark_block_uninitialized( ptr, size );
  97. else set_error( STATUS_NO_MEMORY );
  98. return ptr;
  99. }
  100. /* duplicate a block of memory */
  101. void *memdup( const void *data, size_t len )
  102. {
  103. void *ptr = malloc( len );
  104. if (ptr) memcpy( ptr, data, len );
  105. else set_error( STATUS_NO_MEMORY );
  106. return ptr;
  107. }
  108. /*****************************************************************/
  109. void namespace_add( struct namespace *namespace, struct object_name *ptr )
  110. {
  111. unsigned int hash = hash_strW( ptr->name, ptr->len, namespace->hash_size );
  112. list_add_head( &namespace->names[hash], &ptr->entry );
  113. }
  114. /* allocate a name for an object */
  115. static struct object_name *alloc_name( const struct unicode_str *name )
  116. {
  117. struct object_name *ptr;
  118. if ((ptr = mem_alloc( sizeof(*ptr) + name->len - sizeof(ptr->name) )))
  119. {
  120. ptr->len = name->len;
  121. ptr->parent = NULL;
  122. memcpy( ptr->name, name->str, name->len );
  123. }
  124. return ptr;
  125. }
  126. /* get the name of an existing object */
  127. const WCHAR *get_object_name( struct object *obj, data_size_t *len )
  128. {
  129. struct object_name *ptr = obj->name;
  130. if (!ptr) return NULL;
  131. *len = ptr->len;
  132. return ptr->name;
  133. }
  134. /* get the full path name of an existing object */
  135. WCHAR *get_object_full_name( struct object *obj, data_size_t *ret_len )
  136. {
  137. static const WCHAR backslash = '\\';
  138. struct object *ptr = obj;
  139. data_size_t len = 0;
  140. char *ret;
  141. while (ptr && ptr->name)
  142. {
  143. struct object_name *name = ptr->name;
  144. len += name->len + sizeof(WCHAR);
  145. ptr = name->parent;
  146. }
  147. if (!len) return NULL;
  148. if (!(ret = malloc( len ))) return NULL;
  149. *ret_len = len;
  150. while (obj && obj->name)
  151. {
  152. struct object_name *name = obj->name;
  153. memcpy( ret + len - name->len, name->name, name->len );
  154. len -= name->len + sizeof(WCHAR);
  155. memcpy( ret + len, &backslash, sizeof(WCHAR) );
  156. obj = name->parent;
  157. }
  158. return (WCHAR *)ret;
  159. }
  160. /* allocate and initialize an object */
  161. void *alloc_object( const struct object_ops *ops )
  162. {
  163. struct object *obj = mem_alloc( ops->size );
  164. if (obj)
  165. {
  166. obj->refcount = 1;
  167. obj->handle_count = 0;
  168. obj->ops = ops;
  169. obj->name = NULL;
  170. obj->sd = NULL;
  171. list_init( &obj->wait_queue );
  172. #ifdef DEBUG_OBJECTS
  173. list_add_head( &object_list, &obj->obj_list );
  174. #endif
  175. return obj;
  176. }
  177. return NULL;
  178. }
  179. /* free an object once it has been destroyed */
  180. static void free_object( struct object *obj )
  181. {
  182. free( obj->sd );
  183. #ifdef DEBUG_OBJECTS
  184. list_remove( &obj->obj_list );
  185. memset( obj, 0xaa, obj->ops->size );
  186. #endif
  187. free( obj );
  188. }
  189. /* find an object by name starting from the specified root */
  190. /* if it doesn't exist, its parent is returned, and name_left contains the remaining name */
  191. struct object *lookup_named_object( struct object *root, const struct unicode_str *name,
  192. unsigned int attr, struct unicode_str *name_left )
  193. {
  194. struct object *obj, *parent;
  195. struct unicode_str name_tmp = *name, *ptr = &name_tmp;
  196. if (root)
  197. {
  198. /* if root is specified path shouldn't start with backslash */
  199. if (name_tmp.len && name_tmp.str[0] == '\\')
  200. {
  201. set_error( STATUS_OBJECT_PATH_SYNTAX_BAD );
  202. return NULL;
  203. }
  204. parent = grab_object( root );
  205. }
  206. else
  207. {
  208. if (!name_tmp.len || name_tmp.str[0] != '\\')
  209. {
  210. set_error( STATUS_OBJECT_PATH_SYNTAX_BAD );
  211. return NULL;
  212. }
  213. /* skip leading backslash */
  214. name_tmp.str++;
  215. name_tmp.len -= sizeof(WCHAR);
  216. parent = get_root_directory();
  217. }
  218. if (!name_tmp.len) ptr = NULL; /* special case for empty path */
  219. clear_error();
  220. while ((obj = parent->ops->lookup_name( parent, ptr, attr )))
  221. {
  222. /* move to the next element */
  223. release_object ( parent );
  224. parent = obj;
  225. }
  226. if (get_error())
  227. {
  228. release_object( parent );
  229. return NULL;
  230. }
  231. if (name_left) *name_left = name_tmp;
  232. return parent;
  233. }
  234. /* return length of first path element in name */
  235. data_size_t get_path_element( const WCHAR *name, data_size_t len )
  236. {
  237. data_size_t i;
  238. for (i = 0; i < len / sizeof(WCHAR); i++) if (name[i] == '\\') break;
  239. return i * sizeof(WCHAR);
  240. }
  241. static struct object *create_object( struct object *parent, const struct object_ops *ops,
  242. const struct unicode_str *name, const struct security_descriptor *sd )
  243. {
  244. struct object *obj;
  245. struct object_name *name_ptr;
  246. if (!(name_ptr = alloc_name( name ))) return NULL;
  247. if (!(obj = alloc_object( ops ))) goto failed;
  248. if (sd && !default_set_sd( obj, sd, OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
  249. DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION ))
  250. goto failed;
  251. if (!obj->ops->link_name( obj, name_ptr, parent )) goto failed;
  252. name_ptr->obj = obj;
  253. obj->name = name_ptr;
  254. return obj;
  255. failed:
  256. if (obj) free_object( obj );
  257. free( name_ptr );
  258. return NULL;
  259. }
  260. /* create an object as named child under the specified parent */
  261. void *create_named_object( struct object *parent, const struct object_ops *ops,
  262. const struct unicode_str *name, unsigned int attributes,
  263. const struct security_descriptor *sd )
  264. {
  265. struct object *obj, *new_obj;
  266. struct unicode_str new_name;
  267. clear_error();
  268. if (!name || !name->len)
  269. {
  270. if (!(new_obj = alloc_object( ops ))) return NULL;
  271. if (sd && !default_set_sd( new_obj, sd, OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
  272. DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION ))
  273. {
  274. free_object( new_obj );
  275. return NULL;
  276. }
  277. return new_obj;
  278. }
  279. if (!(obj = lookup_named_object( parent, name, attributes, &new_name ))) return NULL;
  280. if (!new_name.len)
  281. {
  282. if (attributes & OBJ_OPENIF && obj->ops == ops)
  283. set_error( STATUS_OBJECT_NAME_EXISTS );
  284. else
  285. {
  286. release_object( obj );
  287. obj = NULL;
  288. if (attributes & OBJ_OPENIF)
  289. set_error( STATUS_OBJECT_TYPE_MISMATCH );
  290. else
  291. set_error( STATUS_OBJECT_NAME_COLLISION );
  292. }
  293. return obj;
  294. }
  295. new_obj = create_object( obj, ops, &new_name, sd );
  296. release_object( obj );
  297. return new_obj;
  298. }
  299. /* open a object by name under the specified parent */
  300. void *open_named_object( struct object *parent, const struct object_ops *ops,
  301. const struct unicode_str *name, unsigned int attributes )
  302. {
  303. struct unicode_str name_left;
  304. struct object *obj;
  305. if ((obj = lookup_named_object( parent, name, attributes, &name_left )))
  306. {
  307. if (name_left.len) /* not fully parsed */
  308. set_error( STATUS_OBJECT_NAME_NOT_FOUND );
  309. else if (ops && obj->ops != ops)
  310. set_error( STATUS_OBJECT_TYPE_MISMATCH );
  311. else
  312. return obj;
  313. release_object( obj );
  314. }
  315. return NULL;
  316. }
  317. /* recursive helper for dump_object_name */
  318. static void dump_name( struct object *obj )
  319. {
  320. struct object_name *name = obj->name;
  321. if (!name) return;
  322. if (name->parent) dump_name( name->parent );
  323. fputs( "\\\\", stderr );
  324. dump_strW( name->name, name->len, stderr, "[]" );
  325. }
  326. /* dump the name of an object to stderr */
  327. void dump_object_name( struct object *obj )
  328. {
  329. if (!obj->name) return;
  330. fputc( '[', stderr );
  331. dump_name( obj );
  332. fputs( "] ", stderr );
  333. }
  334. /* unlink a named object from its namespace, without freeing the object itself */
  335. void unlink_named_object( struct object *obj )
  336. {
  337. struct object_name *name_ptr = obj->name;
  338. if (!name_ptr) return;
  339. obj->name = NULL;
  340. obj->ops->unlink_name( obj, name_ptr );
  341. if (name_ptr->parent) release_object( name_ptr->parent );
  342. free( name_ptr );
  343. }
  344. /* mark an object as being stored statically, i.e. only released at shutdown */
  345. void make_object_static( struct object *obj )
  346. {
  347. #ifdef DEBUG_OBJECTS
  348. list_remove( &obj->obj_list );
  349. list_add_head( &static_object_list, &obj->obj_list );
  350. #endif
  351. }
  352. /* grab an object (i.e. increment its refcount) and return the object */
  353. struct object *grab_object( void *ptr )
  354. {
  355. struct object *obj = (struct object *)ptr;
  356. assert( obj->refcount < INT_MAX );
  357. obj->refcount++;
  358. return obj;
  359. }
  360. /* release an object (i.e. decrement its refcount) */
  361. void release_object( void *ptr )
  362. {
  363. struct object *obj = (struct object *)ptr;
  364. assert( obj->refcount );
  365. if (!--obj->refcount)
  366. {
  367. assert( !obj->handle_count );
  368. /* if the refcount is 0, nobody can be in the wait queue */
  369. assert( list_empty( &obj->wait_queue ));
  370. free_kernel_objects( obj );
  371. unlink_named_object( obj );
  372. obj->ops->destroy( obj );
  373. free_object( obj );
  374. }
  375. }
  376. /* find an object by its name; the refcount is incremented */
  377. struct object *find_object( const struct namespace *namespace, const struct unicode_str *name,
  378. unsigned int attributes )
  379. {
  380. const struct list *list;
  381. struct list *p;
  382. if (!name || !name->len) return NULL;
  383. list = &namespace->names[ hash_strW( name->str, name->len, namespace->hash_size ) ];
  384. LIST_FOR_EACH( p, list )
  385. {
  386. const struct object_name *ptr = LIST_ENTRY( p, struct object_name, entry );
  387. if (ptr->len != name->len) continue;
  388. if (attributes & OBJ_CASE_INSENSITIVE)
  389. {
  390. if (!memicmp_strW( ptr->name, name->str, name->len ))
  391. return grab_object( ptr->obj );
  392. }
  393. else
  394. {
  395. if (!memcmp( ptr->name, name->str, name->len ))
  396. return grab_object( ptr->obj );
  397. }
  398. }
  399. return NULL;
  400. }
  401. /* find an object by its index; the refcount is incremented */
  402. struct object *find_object_index( const struct namespace *namespace, unsigned int index )
  403. {
  404. unsigned int i;
  405. /* FIXME: not efficient at all */
  406. for (i = 0; i < namespace->hash_size; i++)
  407. {
  408. const struct object_name *ptr;
  409. LIST_FOR_EACH_ENTRY( ptr, &namespace->names[i], const struct object_name, entry )
  410. {
  411. if (!index--) return grab_object( ptr->obj );
  412. }
  413. }
  414. set_error( STATUS_NO_MORE_ENTRIES );
  415. return NULL;
  416. }
  417. /* allocate a namespace */
  418. struct namespace *create_namespace( unsigned int hash_size )
  419. {
  420. struct namespace *namespace;
  421. unsigned int i;
  422. namespace = mem_alloc( sizeof(*namespace) + (hash_size - 1) * sizeof(namespace->names[0]) );
  423. if (namespace)
  424. {
  425. namespace->hash_size = hash_size;
  426. for (i = 0; i < hash_size; i++) list_init( &namespace->names[i] );
  427. }
  428. return namespace;
  429. }
  430. /* functions for unimplemented/default object operations */
  431. struct object_type *no_get_type( struct object *obj )
  432. {
  433. return NULL;
  434. }
  435. int no_add_queue( struct object *obj, struct wait_queue_entry *entry )
  436. {
  437. set_error( STATUS_OBJECT_TYPE_MISMATCH );
  438. return 0;
  439. }
  440. void no_satisfied( struct object *obj, struct wait_queue_entry *entry )
  441. {
  442. }
  443. int no_signal( struct object *obj, unsigned int access )
  444. {
  445. set_error( STATUS_OBJECT_TYPE_MISMATCH );
  446. return 0;
  447. }
  448. struct fd *no_get_fd( struct object *obj )
  449. {
  450. set_error( STATUS_OBJECT_TYPE_MISMATCH );
  451. return NULL;
  452. }
  453. unsigned int no_map_access( struct object *obj, unsigned int access )
  454. {
  455. if (access & GENERIC_READ) access |= STANDARD_RIGHTS_READ;
  456. if (access & GENERIC_WRITE) access |= STANDARD_RIGHTS_WRITE;
  457. if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE;
  458. if (access & GENERIC_ALL) access |= STANDARD_RIGHTS_ALL;
  459. return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
  460. }
  461. struct security_descriptor *default_get_sd( struct object *obj )
  462. {
  463. return obj->sd;
  464. }
  465. struct security_descriptor *set_sd_from_token_internal( const struct security_descriptor *sd,
  466. const struct security_descriptor *old_sd,
  467. unsigned int set_info, struct token *token )
  468. {
  469. struct security_descriptor new_sd, *new_sd_ptr;
  470. int present;
  471. const SID *owner = NULL, *group = NULL;
  472. const ACL *sacl, *dacl;
  473. ACL *replaced_sacl = NULL;
  474. char *ptr;
  475. new_sd.control = sd->control & ~SE_SELF_RELATIVE;
  476. if (set_info & OWNER_SECURITY_INFORMATION && sd->owner_len)
  477. {
  478. owner = sd_get_owner( sd );
  479. new_sd.owner_len = sd->owner_len;
  480. }
  481. else if (old_sd && old_sd->owner_len)
  482. {
  483. owner = sd_get_owner( old_sd );
  484. new_sd.owner_len = old_sd->owner_len;
  485. }
  486. else if (token)
  487. {
  488. owner = token_get_user( token );
  489. new_sd.owner_len = security_sid_len( owner );
  490. }
  491. else new_sd.owner_len = 0;
  492. if (set_info & GROUP_SECURITY_INFORMATION && sd->group_len)
  493. {
  494. group = sd_get_group( sd );
  495. new_sd.group_len = sd->group_len;
  496. }
  497. else if (old_sd && old_sd->group_len)
  498. {
  499. group = sd_get_group( old_sd );
  500. new_sd.group_len = old_sd->group_len;
  501. }
  502. else if (token)
  503. {
  504. group = token_get_primary_group( token );
  505. new_sd.group_len = security_sid_len( group );
  506. }
  507. else new_sd.group_len = 0;
  508. sacl = sd_get_sacl( sd, &present );
  509. if (set_info & SACL_SECURITY_INFORMATION && present)
  510. {
  511. new_sd.control |= SE_SACL_PRESENT;
  512. new_sd.sacl_len = sd->sacl_len;
  513. }
  514. else if (set_info & LABEL_SECURITY_INFORMATION && present)
  515. {
  516. const ACL *old_sacl = NULL;
  517. if (old_sd && old_sd->control & SE_SACL_PRESENT) old_sacl = sd_get_sacl( old_sd, &present );
  518. if (!(replaced_sacl = replace_security_labels( old_sacl, sacl ))) return NULL;
  519. new_sd.control |= SE_SACL_PRESENT;
  520. new_sd.sacl_len = replaced_sacl->AclSize;
  521. sacl = replaced_sacl;
  522. }
  523. else
  524. {
  525. if (old_sd) sacl = sd_get_sacl( old_sd, &present );
  526. if (old_sd && present)
  527. {
  528. new_sd.control |= SE_SACL_PRESENT;
  529. new_sd.sacl_len = old_sd->sacl_len;
  530. }
  531. else
  532. new_sd.sacl_len = 0;
  533. }
  534. dacl = sd_get_dacl( sd, &present );
  535. if (set_info & DACL_SECURITY_INFORMATION && present)
  536. {
  537. new_sd.control |= SE_DACL_PRESENT;
  538. new_sd.dacl_len = sd->dacl_len;
  539. }
  540. else
  541. {
  542. if (old_sd) dacl = sd_get_dacl( old_sd, &present );
  543. if (old_sd && present)
  544. {
  545. new_sd.control |= SE_DACL_PRESENT;
  546. new_sd.dacl_len = old_sd->dacl_len;
  547. }
  548. else if (token)
  549. {
  550. dacl = token_get_default_dacl( token );
  551. new_sd.control |= SE_DACL_PRESENT;
  552. new_sd.dacl_len = dacl->AclSize;
  553. }
  554. else new_sd.dacl_len = 0;
  555. }
  556. ptr = mem_alloc( sizeof(new_sd) + new_sd.owner_len + new_sd.group_len +
  557. new_sd.sacl_len + new_sd.dacl_len );
  558. if (!ptr)
  559. {
  560. free( replaced_sacl );
  561. return NULL;
  562. }
  563. new_sd_ptr = (struct security_descriptor*)ptr;
  564. memcpy( ptr, &new_sd, sizeof(new_sd) );
  565. ptr += sizeof(new_sd);
  566. memcpy( ptr, owner, new_sd.owner_len );
  567. ptr += new_sd.owner_len;
  568. memcpy( ptr, group, new_sd.group_len );
  569. ptr += new_sd.group_len;
  570. memcpy( ptr, sacl, new_sd.sacl_len );
  571. ptr += new_sd.sacl_len;
  572. memcpy( ptr, dacl, new_sd.dacl_len );
  573. free( replaced_sacl );
  574. return new_sd_ptr;
  575. }
  576. int set_sd_defaults_from_token( struct object *obj, const struct security_descriptor *sd,
  577. unsigned int set_info, struct token *token )
  578. {
  579. struct security_descriptor *new_sd;
  580. if (!set_info) return 1;
  581. new_sd = set_sd_from_token_internal( sd, obj->sd, set_info, token );
  582. if (new_sd)
  583. {
  584. free( obj->sd );
  585. obj->sd = new_sd;
  586. return 1;
  587. }
  588. return 0;
  589. }
  590. /** Set the security descriptor using the current primary token for defaults. */
  591. int default_set_sd( struct object *obj, const struct security_descriptor *sd,
  592. unsigned int set_info )
  593. {
  594. return set_sd_defaults_from_token( obj, sd, set_info, current->process->token );
  595. }
  596. struct object *no_lookup_name( struct object *obj, struct unicode_str *name,
  597. unsigned int attr )
  598. {
  599. if (!name) set_error( STATUS_OBJECT_TYPE_MISMATCH );
  600. return NULL;
  601. }
  602. int no_link_name( struct object *obj, struct object_name *name, struct object *parent )
  603. {
  604. set_error( STATUS_OBJECT_TYPE_MISMATCH );
  605. return 0;
  606. }
  607. void default_unlink_name( struct object *obj, struct object_name *name )
  608. {
  609. list_remove( &name->entry );
  610. }
  611. struct object *no_open_file( struct object *obj, unsigned int access, unsigned int sharing,
  612. unsigned int options )
  613. {
  614. set_error( STATUS_OBJECT_TYPE_MISMATCH );
  615. return NULL;
  616. }
  617. void no_alloc_handle( struct object *obj, struct process *process, obj_handle_t handle )
  618. {
  619. }
  620. int no_close_handle( struct object *obj, struct process *process, obj_handle_t handle )
  621. {
  622. return 1; /* ok to close */
  623. }
  624. void no_destroy( struct object *obj )
  625. {
  626. }
  627. static const struct unicode_str type_array[] =
  628. {
  629. {type_Type, sizeof(type_Type)},
  630. {type_Directory, sizeof(type_Directory)},
  631. {type_SymbolicLink, sizeof(type_SymbolicLink)},
  632. {type_Token, sizeof(type_Token)},
  633. {type_Job, sizeof(type_Job)},
  634. {type_Process, sizeof(type_Process)},
  635. {type_Thread, sizeof(type_Thread)},
  636. {type_Event, sizeof(type_Event)},
  637. {type_Mutant, sizeof(type_Mutant)},
  638. {type_Semaphore, sizeof(type_Semaphore)},
  639. {type_Timer, sizeof(type_Timer)},
  640. {type_KeyedEvent, sizeof(type_KeyedEvent)},
  641. {type_WindowStation, sizeof(type_WindowStation)},
  642. {type_Desktop, sizeof(type_Desktop)},
  643. {type_Device, sizeof(type_Device)},
  644. /* Driver */
  645. {type_IoCompletion, sizeof(type_IoCompletion)},
  646. {type_File, sizeof(type_File)},
  647. {type_Section, sizeof(type_Section)},
  648. {type_Key, sizeof(type_Key)},
  649. };
  650. void init_types(void)
  651. {
  652. struct object_type *type;
  653. unsigned int i;
  654. for (i = 0; i < sizeof(type_array) / sizeof(type_array[0]); i++)
  655. {
  656. type = get_object_type(&type_array[i]);
  657. if (type) release_object(type);
  658. }
  659. }