directory.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. /*
  2. * Server-side directory object management
  3. *
  4. * Copyright (C) 2005 Vitaliy Margolen
  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. */
  21. #include "config.h"
  22. #include "wine/port.h"
  23. #include <assert.h>
  24. #include <stdarg.h>
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <sys/types.h>
  28. #include "ntstatus.h"
  29. #define WIN32_NO_STATUS
  30. #include "winternl.h"
  31. #include "ddk/wdm.h"
  32. #include "handle.h"
  33. #include "request.h"
  34. #include "process.h"
  35. #include "file.h"
  36. #include "unicode.h"
  37. #define HASH_SIZE 7 /* default hash size */
  38. struct object_type
  39. {
  40. struct object obj; /* object header */
  41. unsigned int index; /* type index */
  42. };
  43. static void object_type_dump( struct object *obj, int verbose );
  44. static struct object_type *object_type_get_type( struct object *obj );
  45. static const struct object_ops object_type_ops =
  46. {
  47. sizeof(struct object_type), /* size */
  48. object_type_dump, /* dump */
  49. object_type_get_type, /* get_type */
  50. no_add_queue, /* add_queue */
  51. NULL, /* remove_queue */
  52. NULL, /* signaled */
  53. NULL, /* get_esync_fd */
  54. NULL, /* satisfied */
  55. no_signal, /* signal */
  56. no_get_fd, /* get_fd */
  57. no_map_access, /* map_access */
  58. default_get_sd, /* get_sd */
  59. default_set_sd, /* set_sd */
  60. no_lookup_name, /* lookup_name */
  61. directory_link_name, /* link_name */
  62. default_unlink_name, /* unlink_name */
  63. no_open_file, /* open_file */
  64. no_kernel_obj_list, /* get_kernel_obj_list */
  65. no_alloc_handle, /* alloc_handle */
  66. no_close_handle, /* close_handle */
  67. no_destroy /* destroy */
  68. };
  69. static struct object_type *object_type_list[64];
  70. static unsigned int object_type_count;
  71. struct directory
  72. {
  73. struct object obj; /* object header */
  74. struct list kernel_object; /* list of kernel object pointers */
  75. struct namespace *entries; /* directory's name space */
  76. };
  77. static void directory_dump( struct object *obj, int verbose );
  78. static struct object_type *directory_get_type( struct object *obj );
  79. static struct object *directory_lookup_name( struct object *obj, struct unicode_str *name,
  80. unsigned int attr );
  81. static void directory_destroy( struct object *obj );
  82. static struct list *directory_get_kernel_obj_list( struct object *obj );
  83. static const struct object_ops directory_ops =
  84. {
  85. sizeof(struct directory), /* size */
  86. directory_dump, /* dump */
  87. directory_get_type, /* get_type */
  88. no_add_queue, /* add_queue */
  89. NULL, /* remove_queue */
  90. NULL, /* signaled */
  91. NULL, /* get_esync_fd */
  92. NULL, /* satisfied */
  93. no_signal, /* signal */
  94. no_get_fd, /* get_fd */
  95. default_fd_map_access, /* map_access */
  96. default_get_sd, /* get_sd */
  97. default_set_sd, /* set_sd */
  98. directory_lookup_name, /* lookup_name */
  99. directory_link_name, /* link_name */
  100. default_unlink_name, /* unlink_name */
  101. no_open_file, /* open_file */
  102. directory_get_kernel_obj_list,/* get_kernel_obj_list */
  103. no_alloc_handle, /* alloc_handle */
  104. no_close_handle, /* close_handle */
  105. directory_destroy /* destroy */
  106. };
  107. static struct directory *root_directory;
  108. static struct directory *dir_objtype;
  109. static void object_type_dump( struct object *obj, int verbose )
  110. {
  111. fputs( "Object type\n", stderr );
  112. }
  113. static struct object_type *object_type_get_type( struct object *obj )
  114. {
  115. static const struct unicode_str str = { type_Type, sizeof(type_Type) };
  116. return get_object_type( &str );
  117. }
  118. static void directory_dump( struct object *obj, int verbose )
  119. {
  120. fputs( "Directory\n", stderr );
  121. }
  122. static struct object_type *directory_get_type( struct object *obj )
  123. {
  124. static const struct unicode_str str = { type_Directory, sizeof(type_Directory) };
  125. return get_object_type( &str );
  126. }
  127. static struct object *directory_lookup_name( struct object *obj, struct unicode_str *name,
  128. unsigned int attr )
  129. {
  130. struct directory *dir = (struct directory *)obj;
  131. struct object *found;
  132. struct unicode_str tmp;
  133. assert( obj->ops == &directory_ops );
  134. if (!name) return NULL; /* open the directory itself */
  135. tmp.str = name->str;
  136. tmp.len = get_path_element( name->str, name->len );
  137. if ((found = find_object( dir->entries, &tmp, attr )))
  138. {
  139. /* Skip trailing \\ and move to the next element */
  140. if (tmp.len < name->len)
  141. {
  142. tmp.len += sizeof(WCHAR);
  143. name->str += tmp.len / sizeof(WCHAR);
  144. name->len -= tmp.len;
  145. }
  146. else
  147. {
  148. name->str = NULL;
  149. name->len = 0;
  150. }
  151. return found;
  152. }
  153. if (name->str) /* not the last element */
  154. {
  155. if (tmp.len == 0) /* Double backslash */
  156. set_error( STATUS_OBJECT_NAME_INVALID );
  157. else if (tmp.len < name->len) /* Path still has backslashes */
  158. set_error( STATUS_OBJECT_PATH_NOT_FOUND );
  159. }
  160. return NULL;
  161. }
  162. int directory_link_name( struct object *obj, struct object_name *name, struct object *parent )
  163. {
  164. struct directory *dir = (struct directory *)parent;
  165. if (parent->ops != &directory_ops)
  166. {
  167. set_error( STATUS_OBJECT_TYPE_MISMATCH );
  168. return 0;
  169. }
  170. namespace_add( dir->entries, name );
  171. name->parent = grab_object( parent );
  172. return 1;
  173. }
  174. static void directory_destroy( struct object *obj )
  175. {
  176. struct directory *dir = (struct directory *)obj;
  177. assert( obj->ops == &directory_ops );
  178. free( dir->entries );
  179. }
  180. static struct list *directory_get_kernel_obj_list( struct object *obj )
  181. {
  182. struct directory *dir = (struct event *)obj;
  183. return &dir->kernel_object;
  184. }
  185. static struct directory *create_directory( struct object *root, const struct unicode_str *name,
  186. unsigned int attr, unsigned int hash_size,
  187. const struct security_descriptor *sd )
  188. {
  189. struct directory *dir;
  190. if ((dir = create_named_object( root, &directory_ops, name, attr, sd )) &&
  191. get_error() != STATUS_OBJECT_NAME_EXISTS)
  192. {
  193. if (!(dir->entries = create_namespace( hash_size )))
  194. {
  195. release_object( dir );
  196. return NULL;
  197. }
  198. list_init( &dir->kernel_object );
  199. }
  200. return dir;
  201. }
  202. struct object *get_root_directory(void)
  203. {
  204. return grab_object( root_directory );
  205. }
  206. /* return a directory object for creating/opening some object; no access rights are required */
  207. struct object *get_directory_obj( struct process *process, obj_handle_t handle )
  208. {
  209. return get_handle_obj( process, handle, 0, &directory_ops );
  210. }
  211. /* retrieve an object type, creating it if needed */
  212. struct object_type *get_object_type( const struct unicode_str *name )
  213. {
  214. struct object_type *type;
  215. if ((type = create_named_object( &dir_objtype->obj, &object_type_ops, name, OBJ_OPENIF, NULL )))
  216. {
  217. if (get_error() != STATUS_OBJECT_NAME_EXISTS)
  218. {
  219. assert( object_type_count < sizeof(object_type_list)/sizeof(object_type_list[0]) );
  220. type->index = object_type_count++;
  221. object_type_list[ type->index ] = (struct object_type *)grab_object( type );
  222. make_object_static( &type->obj );
  223. }
  224. clear_error();
  225. }
  226. return type;
  227. }
  228. /* retrieve the object type index */
  229. unsigned int type_get_index( struct object_type *type )
  230. {
  231. return type->index;
  232. }
  233. /* Global initialization */
  234. static void create_session( unsigned int id )
  235. {
  236. /* directories */
  237. static const WCHAR dir_sessionsW[] = {'S','e','s','s','i','o','n','s'};
  238. static const WCHAR dir_bnolinksW[] = {'B','N','O','L','I','N','K','S'};
  239. static const WCHAR dir_bnoW[] = {'B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s'};
  240. static const WCHAR dir_dosdevicesW[] = {'D','o','s','D','e','v','i','c','e','s'};
  241. static const WCHAR dir_windowsW[] = {'W','i','n','d','o','w','s'};
  242. static const WCHAR dir_winstationsW[] = {'W','i','n','d','o','w','S','t','a','t','i','o','n','s'};
  243. static const struct unicode_str dir_sessions_str = {dir_sessionsW, sizeof(dir_sessionsW)};
  244. static const struct unicode_str dir_bnolinks_str = {dir_bnolinksW, sizeof(dir_bnolinksW)};
  245. static const struct unicode_str dir_bno_str = {dir_bnoW, sizeof(dir_bnoW)};
  246. static const struct unicode_str dir_dosdevices_str = {dir_dosdevicesW, sizeof(dir_dosdevicesW)};
  247. static const struct unicode_str dir_windows_str = {dir_windowsW, sizeof(dir_windowsW)};
  248. static const struct unicode_str dir_winstations_str = {dir_winstationsW, sizeof(dir_winstationsW)};
  249. /* symlinks */
  250. static const WCHAR link_globalW[] = {'G','l','o','b','a','l'};
  251. static const WCHAR link_localW[] = {'L','o','c','a','l'};
  252. static const WCHAR link_sessionW[] = {'S','e','s','s','i','o','n'};
  253. static const struct unicode_str link_global_str = {link_globalW, sizeof(link_globalW)};
  254. static const struct unicode_str link_local_str = {link_localW, sizeof(link_localW)};
  255. static const struct unicode_str link_session_str = {link_sessionW, sizeof(link_sessionW)};
  256. static struct directory *dir_bno_global, *dir_sessions, *dir_bnolinks;
  257. struct directory *dir_id, *dir_bno, *dir_dosdevices, *dir_windows, *dir_winstation;
  258. struct object *link_global, *link_local, *link_session, *link_bno, *link_windows;
  259. struct unicode_str id_str;
  260. char id_strA[10];
  261. WCHAR *id_strW;
  262. if (!id)
  263. {
  264. dir_bno_global = create_directory( &root_directory->obj, &dir_bno_str, 0, HASH_SIZE, NULL );
  265. dir_sessions = create_directory( &root_directory->obj, &dir_sessions_str, 0, HASH_SIZE, NULL );
  266. dir_bnolinks = create_directory( &dir_sessions->obj, &dir_bnolinks_str, 0, HASH_SIZE, NULL );
  267. make_object_static( (struct object *)dir_bno_global );
  268. make_object_static( (struct object *)dir_bnolinks );
  269. make_object_static( (struct object *)dir_sessions );
  270. }
  271. sprintf( id_strA, "%u", id );
  272. id_strW = ascii_to_unicode_str( id_strA, &id_str );
  273. dir_id = create_directory( &dir_sessions->obj, &id_str, 0, HASH_SIZE, NULL );
  274. dir_dosdevices = create_directory( &dir_id->obj, &dir_dosdevices_str, 0, HASH_SIZE, NULL );
  275. /* for session 0, directories are created under the root */
  276. if (!id)
  277. {
  278. dir_bno = (struct directory *)grab_object( dir_bno_global );
  279. dir_windows = create_directory( &root_directory->obj, &dir_windows_str, 0, HASH_SIZE, NULL );
  280. link_bno = create_obj_symlink( &dir_id->obj, &dir_bno_str, 0, &dir_bno->obj, NULL );
  281. link_windows = create_obj_symlink( &dir_id->obj, &dir_windows_str, 0, &dir_windows->obj, NULL );
  282. make_object_static( link_bno );
  283. make_object_static( link_windows );
  284. }
  285. else
  286. {
  287. /* use a larger hash table for this one since it can contain a lot of objects */
  288. dir_bno = create_directory( &dir_id->obj, &dir_bno_str, 0, 37, NULL );
  289. dir_windows = create_directory( &dir_id->obj, &dir_windows_str, 0, HASH_SIZE, NULL );
  290. }
  291. dir_winstation = create_directory( &dir_windows->obj, &dir_winstations_str, 0, HASH_SIZE, NULL );
  292. link_global = create_obj_symlink( &dir_bno->obj, &link_global_str, 0, &dir_bno_global->obj, NULL );
  293. link_local = create_obj_symlink( &dir_bno->obj, &link_local_str, 0, &dir_bno->obj, NULL );
  294. link_session = create_obj_symlink( &dir_bno->obj, &link_session_str, 0, &dir_bnolinks->obj, NULL );
  295. link_bno = create_obj_symlink( &dir_bnolinks->obj, &id_str, 0, &dir_bno->obj, NULL );
  296. make_object_static( link_global );
  297. make_object_static( link_local );
  298. make_object_static( link_session );
  299. make_object_static( link_bno );
  300. make_object_static( &dir_dosdevices->obj );
  301. make_object_static( &dir_winstation->obj );
  302. release_object( dir_windows );
  303. release_object( dir_bno );
  304. release_object( dir_id );
  305. free( id_strW );
  306. }
  307. void init_directories(void)
  308. {
  309. /* Directories */
  310. static const WCHAR dir_globalW[] = {'?','?'};
  311. static const WCHAR dir_driverW[] = {'D','r','i','v','e','r'};
  312. static const WCHAR dir_deviceW[] = {'D','e','v','i','c','e'};
  313. static const WCHAR dir_objtypeW[] = {'O','b','j','e','c','t','T','y','p','e','s'};
  314. static const WCHAR dir_kernelW[] = {'K','e','r','n','e','l','O','b','j','e','c','t','s'};
  315. static const struct unicode_str dir_global_str = {dir_globalW, sizeof(dir_globalW)};
  316. static const struct unicode_str dir_driver_str = {dir_driverW, sizeof(dir_driverW)};
  317. static const struct unicode_str dir_device_str = {dir_deviceW, sizeof(dir_deviceW)};
  318. static const struct unicode_str dir_objtype_str = {dir_objtypeW, sizeof(dir_objtypeW)};
  319. static const struct unicode_str dir_kernel_str = {dir_kernelW, sizeof(dir_kernelW)};
  320. /* symlinks */
  321. static const WCHAR link_dosdevW[] = {'D','o','s','D','e','v','i','c','e','s'};
  322. static const WCHAR link_globalW[] = {'G','l','o','b','a','l'};
  323. static const WCHAR link_nulW[] = {'N','U','L'};
  324. static const WCHAR link_pipeW[] = {'P','I','P','E'};
  325. static const WCHAR link_mailslotW[] = {'M','A','I','L','S','L','O','T'};
  326. static const struct unicode_str link_dosdev_str = {link_dosdevW, sizeof(link_dosdevW)};
  327. static const struct unicode_str link_global_str = {link_globalW, sizeof(link_globalW)};
  328. static const struct unicode_str link_nul_str = {link_nulW, sizeof(link_nulW)};
  329. static const struct unicode_str link_pipe_str = {link_pipeW, sizeof(link_pipeW)};
  330. static const struct unicode_str link_mailslot_str = {link_mailslotW, sizeof(link_mailslotW)};
  331. /* devices */
  332. static const WCHAR named_pipeW[] = {'N','a','m','e','d','P','i','p','e'};
  333. static const WCHAR mailslotW[] = {'M','a','i','l','S','l','o','t'};
  334. static const WCHAR nullW[] = {'N','u','l','l'};
  335. static const struct unicode_str named_pipe_str = {named_pipeW, sizeof(named_pipeW)};
  336. static const struct unicode_str mailslot_str = {mailslotW, sizeof(mailslotW)};
  337. static const struct unicode_str null_str = {nullW, sizeof(nullW)};
  338. /* events */
  339. static const WCHAR event_low_memW[] = {'L','o','w','M','e','m','o','r','y','C','o','n','d','i','t','i','o','n'};
  340. static const WCHAR event_low_pagedW[] = {'L','o','w','P','a','g','e','d','P','o','o','l','C','o','n','d','i','t','i','o','n'};
  341. static const WCHAR event_low_nonpgW[] = {'L','o','w','N','o','n','P','a','g','e','d','P','o','o','l','C','o','n','d','i','t','i','o','n'};
  342. static const WCHAR event_high_memW[] = {'H','i','g','h','M','e','m','o','r','y','C','o','n','d','i','t','i','o','n'};
  343. static const WCHAR event_high_pagedW[] = {'H','i','g','h','P','a','g','e','d','P','o','o','l','C','o','n','d','i','t','i','o','n'};
  344. static const WCHAR event_high_nonpgW[] = {'H','i','g','h','N','o','n','P','a','g','e','d','P','o','o','l','C','o','n','d','i','t','i','o','n'};
  345. static const WCHAR keyed_event_crit_sectW[] = {'C','r','i','t','S','e','c','O','u','t','O','f','M','e','m','o','r','y','E','v','e','n','t'};
  346. static const struct unicode_str kernel_events[] =
  347. {
  348. { event_low_memW, sizeof(event_low_memW) },
  349. { event_low_pagedW, sizeof(event_low_pagedW) },
  350. { event_low_nonpgW, sizeof(event_low_nonpgW) },
  351. { event_high_memW, sizeof(event_high_memW) },
  352. { event_high_pagedW, sizeof(event_high_pagedW) },
  353. { event_high_nonpgW, sizeof(event_high_nonpgW) }
  354. };
  355. static const struct unicode_str keyed_event_crit_sect_str = {keyed_event_crit_sectW, sizeof(keyed_event_crit_sectW)};
  356. struct directory *dir_driver, *dir_device, *dir_global, *dir_kernel;
  357. struct object *link_dosdev, *link_global, *link_nul, *link_pipe, *link_mailslot;
  358. struct object *named_pipe_device, *mailslot_device, *null_device;
  359. struct keyed_event *keyed_event;
  360. unsigned int i;
  361. root_directory = create_directory( NULL, NULL, 0, HASH_SIZE, NULL );
  362. dir_driver = create_directory( &root_directory->obj, &dir_driver_str, 0, HASH_SIZE, NULL );
  363. dir_device = create_directory( &root_directory->obj, &dir_device_str, 0, HASH_SIZE, NULL );
  364. dir_objtype = create_directory( &root_directory->obj, &dir_objtype_str, 0, HASH_SIZE, NULL );
  365. dir_kernel = create_directory( &root_directory->obj, &dir_kernel_str, 0, HASH_SIZE, NULL );
  366. dir_global = create_directory( &root_directory->obj, &dir_global_str, 0, HASH_SIZE, NULL );
  367. make_object_static( &root_directory->obj );
  368. make_object_static( &dir_driver->obj );
  369. make_object_static( &dir_objtype->obj );
  370. /* devices */
  371. named_pipe_device = create_named_pipe_device( &dir_device->obj, &named_pipe_str );
  372. mailslot_device = create_mailslot_device( &dir_device->obj, &mailslot_str );
  373. null_device = create_unix_device( &dir_device->obj, &null_str, "/dev/null" );
  374. make_object_static( named_pipe_device );
  375. make_object_static( mailslot_device );
  376. make_object_static( null_device );
  377. /* sessions */
  378. create_session( 0 );
  379. create_session( 1 );
  380. /* symlinks */
  381. link_dosdev = create_obj_symlink( &root_directory->obj, &link_dosdev_str, 0, &dir_global->obj, NULL );
  382. link_global = create_obj_symlink( &dir_global->obj, &link_global_str, 0, &dir_global->obj, NULL );
  383. link_nul = create_obj_symlink( &dir_global->obj, &link_nul_str, 0, null_device, NULL );
  384. link_pipe = create_obj_symlink( &dir_global->obj, &link_pipe_str, 0, named_pipe_device, NULL );
  385. link_mailslot = create_obj_symlink( &dir_global->obj, &link_mailslot_str, 0, mailslot_device, NULL );
  386. make_object_static( link_dosdev );
  387. make_object_static( link_global );
  388. make_object_static( link_nul );
  389. make_object_static( link_pipe );
  390. make_object_static( link_mailslot );
  391. /* events */
  392. for (i = 0; i < ARRAY_SIZE( kernel_events ); i++)
  393. {
  394. struct event *event = create_event( &dir_kernel->obj, &kernel_events[i], 0, 1, 0, NULL );
  395. make_object_static( (struct object *)event );
  396. }
  397. keyed_event = create_keyed_event( &dir_kernel->obj, &keyed_event_crit_sect_str, 0, NULL );
  398. make_object_static( (struct object *)keyed_event );
  399. /* the objects hold references so we can release these directories */
  400. release_object( dir_global );
  401. release_object( dir_device );
  402. release_object( dir_kernel );
  403. }
  404. /* create a directory object */
  405. DECL_HANDLER(create_directory)
  406. {
  407. struct unicode_str name;
  408. struct object *root;
  409. struct directory *dir;
  410. const struct security_descriptor *sd;
  411. const struct object_attributes *objattr = get_req_object_attributes( &sd, &name, &root );
  412. if (!objattr) return;
  413. if ((dir = create_directory( root, &name, objattr->attributes, HASH_SIZE, sd )))
  414. {
  415. reply->handle = alloc_handle( current->process, dir, req->access, objattr->attributes );
  416. release_object( dir );
  417. }
  418. if (root) release_object( root );
  419. }
  420. /* open a directory object */
  421. DECL_HANDLER(open_directory)
  422. {
  423. struct unicode_str name = get_req_unicode_str();
  424. reply->handle = open_object( current->process, req->rootdir, req->access,
  425. &directory_ops, &name, req->attributes );
  426. }
  427. /* get a directory entry by index */
  428. DECL_HANDLER(get_directory_entry)
  429. {
  430. struct directory *dir = (struct directory *)get_handle_obj( current->process, req->handle,
  431. DIRECTORY_QUERY, &directory_ops );
  432. if (dir)
  433. {
  434. struct object *obj = find_object_index( dir->entries, req->index );
  435. if (obj)
  436. {
  437. data_size_t name_len, type_len = 0;
  438. const WCHAR *type_name = NULL;
  439. const WCHAR *name = get_object_name( obj, &name_len );
  440. struct object_type *type = obj->ops->get_type( obj );
  441. if (type) type_name = get_object_name( &type->obj, &type_len );
  442. if (name_len + type_len <= get_reply_max_size())
  443. {
  444. void *ptr = set_reply_data_size( name_len + type_len );
  445. if (ptr)
  446. {
  447. reply->name_len = name_len;
  448. memcpy( ptr, name, name_len );
  449. memcpy( (char *)ptr + name_len, type_name, type_len );
  450. }
  451. }
  452. else set_error( STATUS_BUFFER_OVERFLOW );
  453. if (type) release_object( type );
  454. release_object( obj );
  455. }
  456. release_object( dir );
  457. }
  458. }
  459. /* unlink a named object */
  460. DECL_HANDLER(unlink_object)
  461. {
  462. struct object *obj = get_handle_obj( current->process, req->handle, 0, NULL );
  463. if (obj)
  464. {
  465. unlink_named_object( obj );
  466. release_object( obj );
  467. }
  468. }
  469. /* query object type name information */
  470. DECL_HANDLER(get_object_type)
  471. {
  472. struct object *obj;
  473. struct object_type *type;
  474. const WCHAR *name;
  475. if (!(obj = get_handle_obj( current->process, req->handle, 0, NULL ))) return;
  476. if ((type = obj->ops->get_type( obj )))
  477. {
  478. if ((name = get_object_name( &type->obj, &reply->total )))
  479. set_reply_data( name, min( reply->total, get_reply_max_size() ) );
  480. reply->index = type->index;
  481. release_object( type );
  482. }
  483. release_object( obj );
  484. }
  485. /* query object type name information by index */
  486. DECL_HANDLER(get_object_type_by_index)
  487. {
  488. struct object_type *type;
  489. const WCHAR *name;
  490. if (req->index < object_type_count && (type = object_type_list[ req->index ]))
  491. {
  492. if ((name = get_object_name( &type->obj, &reply->total )))
  493. set_reply_data( name, min( reply->total, get_reply_max_size() ) );
  494. }
  495. else set_error( STATUS_NO_MORE_ENTRIES );
  496. }