directory.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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. static const WCHAR objtype_name[] = {'T','y','p','e'};
  39. struct type_descr objtype_type =
  40. {
  41. { objtype_name, sizeof(objtype_name) }, /* name */
  42. STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1, /* valid_access */
  43. { /* mapping */
  44. STANDARD_RIGHTS_READ,
  45. STANDARD_RIGHTS_WRITE,
  46. STANDARD_RIGHTS_EXECUTE,
  47. STANDARD_RIGHTS_REQUIRED | 0x1
  48. },
  49. };
  50. struct object_type
  51. {
  52. struct object obj; /* object header */
  53. };
  54. static void object_type_dump( struct object *obj, int verbose );
  55. static const struct object_ops object_type_ops =
  56. {
  57. sizeof(struct object_type), /* size */
  58. &objtype_type, /* type */
  59. object_type_dump, /* dump */
  60. no_add_queue, /* add_queue */
  61. NULL, /* remove_queue */
  62. NULL, /* signaled */
  63. NULL, /* satisfied */
  64. no_signal, /* signal */
  65. no_get_fd, /* get_fd */
  66. default_map_access, /* map_access */
  67. default_get_sd, /* get_sd */
  68. default_set_sd, /* set_sd */
  69. default_get_full_name, /* get_full_name */
  70. no_lookup_name, /* lookup_name */
  71. directory_link_name, /* link_name */
  72. default_unlink_name, /* unlink_name */
  73. no_open_file, /* open_file */
  74. no_kernel_obj_list, /* get_kernel_obj_list */
  75. no_close_handle, /* close_handle */
  76. no_destroy /* destroy */
  77. };
  78. static const WCHAR directory_name[] = {'D','i','r','e','c','t','o','r','y'};
  79. struct type_descr directory_type =
  80. {
  81. { directory_name, sizeof(directory_name) }, /* name */
  82. DIRECTORY_ALL_ACCESS, /* valid_access */
  83. { /* mapping */
  84. STANDARD_RIGHTS_READ | DIRECTORY_TRAVERSE | DIRECTORY_QUERY,
  85. STANDARD_RIGHTS_WRITE | DIRECTORY_CREATE_SUBDIRECTORY | DIRECTORY_CREATE_OBJECT,
  86. STANDARD_RIGHTS_EXECUTE | DIRECTORY_TRAVERSE | DIRECTORY_QUERY,
  87. DIRECTORY_ALL_ACCESS
  88. },
  89. };
  90. struct directory
  91. {
  92. struct object obj; /* object header */
  93. struct namespace *entries; /* directory's name space */
  94. };
  95. static void directory_dump( struct object *obj, int verbose );
  96. static struct object *directory_lookup_name( struct object *obj, struct unicode_str *name,
  97. unsigned int attr, struct object *root );
  98. static void directory_destroy( struct object *obj );
  99. static const struct object_ops directory_ops =
  100. {
  101. sizeof(struct directory), /* size */
  102. &directory_type, /* type */
  103. directory_dump, /* dump */
  104. no_add_queue, /* add_queue */
  105. NULL, /* remove_queue */
  106. NULL, /* signaled */
  107. NULL, /* satisfied */
  108. no_signal, /* signal */
  109. no_get_fd, /* get_fd */
  110. default_map_access, /* map_access */
  111. default_get_sd, /* get_sd */
  112. default_set_sd, /* set_sd */
  113. default_get_full_name, /* get_full_name */
  114. directory_lookup_name, /* lookup_name */
  115. directory_link_name, /* link_name */
  116. default_unlink_name, /* unlink_name */
  117. no_open_file, /* open_file */
  118. no_kernel_obj_list, /* get_kernel_obj_list */
  119. no_close_handle, /* close_handle */
  120. directory_destroy /* destroy */
  121. };
  122. static struct directory *root_directory;
  123. static struct directory *dir_objtype;
  124. static struct type_descr *types[] =
  125. {
  126. &objtype_type,
  127. &directory_type,
  128. &symlink_type,
  129. &token_type,
  130. &job_type,
  131. &process_type,
  132. &thread_type,
  133. &debug_obj_type,
  134. &event_type,
  135. &mutex_type,
  136. &semaphore_type,
  137. &timer_type,
  138. &keyed_event_type,
  139. &winstation_type,
  140. &desktop_type,
  141. &device_type,
  142. &completion_type,
  143. &file_type,
  144. &mapping_type,
  145. &key_type,
  146. };
  147. static void object_type_dump( struct object *obj, int verbose )
  148. {
  149. fputs( "Object type\n", stderr );
  150. }
  151. static struct object_type *create_object_type( struct object *root, unsigned int index,
  152. unsigned int attr, const struct security_descriptor *sd )
  153. {
  154. struct type_descr *descr = types[index];
  155. struct object_type *type;
  156. if ((type = create_named_object( root, &object_type_ops, &descr->name, attr, sd )))
  157. {
  158. descr->index = index;
  159. }
  160. return type;
  161. }
  162. static void directory_dump( struct object *obj, int verbose )
  163. {
  164. fputs( "Directory\n", stderr );
  165. }
  166. static struct object *directory_lookup_name( struct object *obj, struct unicode_str *name,
  167. unsigned int attr, struct object *root )
  168. {
  169. struct directory *dir = (struct directory *)obj;
  170. struct object *found;
  171. struct unicode_str tmp;
  172. assert( obj->ops == &directory_ops );
  173. if (!name) return NULL; /* open the directory itself */
  174. tmp.str = name->str;
  175. tmp.len = get_path_element( name->str, name->len );
  176. if ((found = find_object( dir->entries, &tmp, attr )))
  177. {
  178. /* Skip trailing \\ and move to the next element */
  179. if (tmp.len < name->len)
  180. {
  181. tmp.len += sizeof(WCHAR);
  182. name->str += tmp.len / sizeof(WCHAR);
  183. name->len -= tmp.len;
  184. }
  185. else
  186. {
  187. name->str = NULL;
  188. name->len = 0;
  189. }
  190. return found;
  191. }
  192. if (name->str) /* not the last element */
  193. {
  194. if (tmp.len == 0) /* Double backslash */
  195. set_error( STATUS_OBJECT_NAME_INVALID );
  196. else if (tmp.len < name->len) /* Path still has backslashes */
  197. set_error( STATUS_OBJECT_PATH_NOT_FOUND );
  198. }
  199. return NULL;
  200. }
  201. int directory_link_name( struct object *obj, struct object_name *name, struct object *parent )
  202. {
  203. struct directory *dir = (struct directory *)parent;
  204. if (parent->ops != &directory_ops)
  205. {
  206. set_error( STATUS_OBJECT_TYPE_MISMATCH );
  207. return 0;
  208. }
  209. namespace_add( dir->entries, name );
  210. name->parent = grab_object( parent );
  211. return 1;
  212. }
  213. static void directory_destroy( struct object *obj )
  214. {
  215. struct directory *dir = (struct directory *)obj;
  216. assert( obj->ops == &directory_ops );
  217. free( dir->entries );
  218. }
  219. static struct directory *create_directory( struct object *root, const struct unicode_str *name,
  220. unsigned int attr, unsigned int hash_size,
  221. const struct security_descriptor *sd )
  222. {
  223. struct directory *dir;
  224. if ((dir = create_named_object( root, &directory_ops, name, attr, sd )) &&
  225. get_error() != STATUS_OBJECT_NAME_EXISTS)
  226. {
  227. if (!(dir->entries = create_namespace( hash_size )))
  228. {
  229. release_object( dir );
  230. return NULL;
  231. }
  232. }
  233. return dir;
  234. }
  235. struct object *get_root_directory(void)
  236. {
  237. return grab_object( root_directory );
  238. }
  239. /* return a directory object for creating/opening some object; no access rights are required */
  240. struct object *get_directory_obj( struct process *process, obj_handle_t handle )
  241. {
  242. return get_handle_obj( process, handle, 0, &directory_ops );
  243. }
  244. /* Global initialization */
  245. static void create_session( unsigned int id )
  246. {
  247. /* directories */
  248. static const WCHAR dir_sessionsW[] = {'S','e','s','s','i','o','n','s'};
  249. static const WCHAR dir_bnolinksW[] = {'B','N','O','L','I','N','K','S'};
  250. static const WCHAR dir_bnoW[] = {'B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s'};
  251. static const WCHAR dir_dosdevicesW[] = {'D','o','s','D','e','v','i','c','e','s'};
  252. static const WCHAR dir_windowsW[] = {'W','i','n','d','o','w','s'};
  253. static const WCHAR dir_winstationsW[] = {'W','i','n','d','o','w','S','t','a','t','i','o','n','s'};
  254. static const struct unicode_str dir_sessions_str = {dir_sessionsW, sizeof(dir_sessionsW)};
  255. static const struct unicode_str dir_bnolinks_str = {dir_bnolinksW, sizeof(dir_bnolinksW)};
  256. static const struct unicode_str dir_bno_str = {dir_bnoW, sizeof(dir_bnoW)};
  257. static const struct unicode_str dir_dosdevices_str = {dir_dosdevicesW, sizeof(dir_dosdevicesW)};
  258. static const struct unicode_str dir_windows_str = {dir_windowsW, sizeof(dir_windowsW)};
  259. static const struct unicode_str dir_winstations_str = {dir_winstationsW, sizeof(dir_winstationsW)};
  260. /* symlinks */
  261. static const WCHAR link_globalW[] = {'G','l','o','b','a','l'};
  262. static const WCHAR link_localW[] = {'L','o','c','a','l'};
  263. static const WCHAR link_sessionW[] = {'S','e','s','s','i','o','n'};
  264. static const struct unicode_str link_global_str = {link_globalW, sizeof(link_globalW)};
  265. static const struct unicode_str link_local_str = {link_localW, sizeof(link_localW)};
  266. static const struct unicode_str link_session_str = {link_sessionW, sizeof(link_sessionW)};
  267. static struct directory *dir_bno_global, *dir_sessions, *dir_bnolinks;
  268. struct directory *dir_id, *dir_bno, *dir_dosdevices, *dir_windows, *dir_winstation;
  269. struct object *link_global, *link_local, *link_session, *link_bno, *link_windows;
  270. struct unicode_str id_str;
  271. char id_strA[10];
  272. WCHAR *id_strW;
  273. if (!id)
  274. {
  275. dir_bno_global = create_directory( &root_directory->obj, &dir_bno_str, OBJ_PERMANENT, HASH_SIZE, NULL );
  276. dir_sessions = create_directory( &root_directory->obj, &dir_sessions_str, OBJ_PERMANENT, HASH_SIZE, NULL );
  277. dir_bnolinks = create_directory( &dir_sessions->obj, &dir_bnolinks_str, OBJ_PERMANENT, HASH_SIZE, NULL );
  278. release_object( dir_bno_global );
  279. release_object( dir_bnolinks );
  280. release_object( dir_sessions );
  281. }
  282. sprintf( id_strA, "%u", id );
  283. id_strW = ascii_to_unicode_str( id_strA, &id_str );
  284. dir_id = create_directory( &dir_sessions->obj, &id_str, 0, HASH_SIZE, NULL );
  285. dir_dosdevices = create_directory( &dir_id->obj, &dir_dosdevices_str, OBJ_PERMANENT, HASH_SIZE, NULL );
  286. /* for session 0, directories are created under the root */
  287. if (!id)
  288. {
  289. dir_bno = (struct directory *)grab_object( dir_bno_global );
  290. dir_windows = create_directory( &root_directory->obj, &dir_windows_str, 0, HASH_SIZE, NULL );
  291. link_bno = create_obj_symlink( &dir_id->obj, &dir_bno_str, OBJ_PERMANENT, &dir_bno->obj, NULL );
  292. link_windows = create_obj_symlink( &dir_id->obj, &dir_windows_str, OBJ_PERMANENT, &dir_windows->obj, NULL );
  293. release_object( link_bno );
  294. release_object( link_windows );
  295. }
  296. else
  297. {
  298. /* use a larger hash table for this one since it can contain a lot of objects */
  299. dir_bno = create_directory( &dir_id->obj, &dir_bno_str, 0, 37, NULL );
  300. dir_windows = create_directory( &dir_id->obj, &dir_windows_str, 0, HASH_SIZE, NULL );
  301. }
  302. dir_winstation = create_directory( &dir_windows->obj, &dir_winstations_str, OBJ_PERMANENT, HASH_SIZE, NULL );
  303. link_global = create_obj_symlink( &dir_bno->obj, &link_global_str, OBJ_PERMANENT, &dir_bno_global->obj, NULL );
  304. link_local = create_obj_symlink( &dir_bno->obj, &link_local_str, OBJ_PERMANENT, &dir_bno->obj, NULL );
  305. link_session = create_obj_symlink( &dir_bno->obj, &link_session_str, OBJ_PERMANENT, &dir_bnolinks->obj, NULL );
  306. link_bno = create_obj_symlink( &dir_bnolinks->obj, &id_str, OBJ_PERMANENT, &dir_bno->obj, NULL );
  307. release_object( link_global );
  308. release_object( link_local );
  309. release_object( link_session );
  310. release_object( link_bno );
  311. release_object( dir_dosdevices );
  312. release_object( dir_winstation );
  313. release_object( dir_windows );
  314. release_object( dir_bno );
  315. release_object( dir_id );
  316. free( id_strW );
  317. }
  318. void init_directories( struct fd *intl_fd )
  319. {
  320. /* Directories */
  321. static const WCHAR dir_globalW[] = {'?','?'};
  322. static const WCHAR dir_driverW[] = {'D','r','i','v','e','r'};
  323. static const WCHAR dir_deviceW[] = {'D','e','v','i','c','e'};
  324. static const WCHAR dir_objtypeW[] = {'O','b','j','e','c','t','T','y','p','e','s'};
  325. static const WCHAR dir_kernelW[] = {'K','e','r','n','e','l','O','b','j','e','c','t','s'};
  326. static const WCHAR dir_nlsW[] = {'N','L','S'};
  327. static const struct unicode_str dir_global_str = {dir_globalW, sizeof(dir_globalW)};
  328. static const struct unicode_str dir_driver_str = {dir_driverW, sizeof(dir_driverW)};
  329. static const struct unicode_str dir_device_str = {dir_deviceW, sizeof(dir_deviceW)};
  330. static const struct unicode_str dir_objtype_str = {dir_objtypeW, sizeof(dir_objtypeW)};
  331. static const struct unicode_str dir_kernel_str = {dir_kernelW, sizeof(dir_kernelW)};
  332. static const struct unicode_str dir_nls_str = {dir_nlsW, sizeof(dir_nlsW)};
  333. /* symlinks */
  334. static const WCHAR link_dosdevW[] = {'D','o','s','D','e','v','i','c','e','s'};
  335. static const WCHAR link_globalW[] = {'G','l','o','b','a','l'};
  336. static const WCHAR link_nulW[] = {'N','U','L'};
  337. static const WCHAR link_pipeW[] = {'P','I','P','E'};
  338. static const WCHAR link_mailslotW[] = {'M','A','I','L','S','L','O','T'};
  339. static const WCHAR link_coninW[] = {'C','O','N','I','N','$'};
  340. static const WCHAR link_conoutW[] = {'C','O','N','O','U','T','$'};
  341. static const WCHAR link_conW[] = {'C','O','N'};
  342. static const WCHAR link_currentinW[] = {'\\','D','e','v','i','c','e','\\','C','o','n','D','r','v',
  343. '\\','C','u','r','r','e','n','t','I','n'};
  344. static const WCHAR link_currentoutW[] = {'\\','D','e','v','i','c','e','\\','C','o','n','D','r','v',
  345. '\\','C','u','r','r','e','n','t','O','u','t'};
  346. static const WCHAR link_consoleW[] = {'\\','D','e','v','i','c','e','\\','C','o','n','D','r','v',
  347. '\\','C','o','n','s','o','l','e'};
  348. static const struct unicode_str link_dosdev_str = {link_dosdevW, sizeof(link_dosdevW)};
  349. static const struct unicode_str link_global_str = {link_globalW, sizeof(link_globalW)};
  350. static const struct unicode_str link_nul_str = {link_nulW, sizeof(link_nulW)};
  351. static const struct unicode_str link_pipe_str = {link_pipeW, sizeof(link_pipeW)};
  352. static const struct unicode_str link_mailslot_str = {link_mailslotW, sizeof(link_mailslotW)};
  353. static const struct unicode_str link_con_str = {link_conW, sizeof(link_conW)};
  354. static const struct unicode_str link_conin_str = {link_coninW, sizeof(link_coninW)};
  355. static const struct unicode_str link_conout_str = {link_conoutW, sizeof(link_conoutW)};
  356. static const struct unicode_str link_currentin_str = {link_currentinW, sizeof(link_currentinW)};
  357. static const struct unicode_str link_currentout_str = {link_currentoutW, sizeof(link_currentoutW)};
  358. static const struct unicode_str link_console_str = {link_consoleW, sizeof(link_consoleW)};
  359. /* devices */
  360. static const WCHAR named_pipeW[] = {'N','a','m','e','d','P','i','p','e'};
  361. static const WCHAR mailslotW[] = {'M','a','i','l','S','l','o','t'};
  362. static const WCHAR condrvW[] = {'C','o','n','D','r','v'};
  363. static const WCHAR nullW[] = {'N','u','l','l'};
  364. static const WCHAR afdW[] = {'A','f','d'};
  365. static const struct unicode_str named_pipe_str = {named_pipeW, sizeof(named_pipeW)};
  366. static const struct unicode_str mailslot_str = {mailslotW, sizeof(mailslotW)};
  367. static const struct unicode_str condrv_str = {condrvW, sizeof(condrvW)};
  368. static const struct unicode_str null_str = {nullW, sizeof(nullW)};
  369. static const struct unicode_str afd_str = {afdW, sizeof(afdW)};
  370. /* events */
  371. static const WCHAR event_low_memW[] = {'L','o','w','M','e','m','o','r','y','C','o','n','d','i','t','i','o','n'};
  372. 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'};
  373. 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'};
  374. 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'};
  375. 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'};
  376. 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'};
  377. 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'};
  378. static const struct unicode_str kernel_events[] =
  379. {
  380. { event_low_memW, sizeof(event_low_memW) },
  381. { event_low_pagedW, sizeof(event_low_pagedW) },
  382. { event_low_nonpgW, sizeof(event_low_nonpgW) },
  383. { event_high_memW, sizeof(event_high_memW) },
  384. { event_high_pagedW, sizeof(event_high_pagedW) },
  385. { event_high_nonpgW, sizeof(event_high_nonpgW) }
  386. };
  387. static const struct unicode_str keyed_event_crit_sect_str = {keyed_event_crit_sectW, sizeof(keyed_event_crit_sectW)};
  388. /* mappings */
  389. static const WCHAR intlW[] = {'N','l','s','S','e','c','t','i','o','n','L','A','N','G','_','I','N','T','L'};
  390. static const WCHAR user_dataW[] = {'_','_','w','i','n','e','_','u','s','e','r','_','s','h','a','r','e','d','_','d','a','t','a'};
  391. static const struct unicode_str intl_str = {intlW, sizeof(intlW)};
  392. static const struct unicode_str user_data_str = {user_dataW, sizeof(user_dataW)};
  393. struct directory *dir_driver, *dir_device, *dir_global, *dir_kernel, *dir_nls;
  394. struct object *named_pipe_device, *mailslot_device, *null_device;
  395. unsigned int i;
  396. root_directory = create_directory( NULL, NULL, OBJ_PERMANENT, HASH_SIZE, NULL );
  397. dir_driver = create_directory( &root_directory->obj, &dir_driver_str, OBJ_PERMANENT, HASH_SIZE, NULL );
  398. dir_device = create_directory( &root_directory->obj, &dir_device_str, OBJ_PERMANENT, HASH_SIZE, NULL );
  399. dir_objtype = create_directory( &root_directory->obj, &dir_objtype_str, OBJ_PERMANENT, HASH_SIZE, NULL );
  400. dir_kernel = create_directory( &root_directory->obj, &dir_kernel_str, OBJ_PERMANENT, HASH_SIZE, NULL );
  401. dir_global = create_directory( &root_directory->obj, &dir_global_str, OBJ_PERMANENT, HASH_SIZE, NULL );
  402. dir_nls = create_directory( &root_directory->obj, &dir_nls_str, OBJ_PERMANENT, HASH_SIZE, NULL );
  403. /* devices */
  404. named_pipe_device = create_named_pipe_device( &dir_device->obj, &named_pipe_str, OBJ_PERMANENT, NULL );
  405. mailslot_device = create_mailslot_device( &dir_device->obj, &mailslot_str, OBJ_PERMANENT, NULL );
  406. null_device = create_unix_device( &dir_device->obj, &null_str, OBJ_PERMANENT, NULL, "/dev/null" );
  407. release_object( create_console_device( &dir_device->obj, &condrv_str, OBJ_PERMANENT, NULL ));
  408. release_object( create_socket_device( &dir_device->obj, &afd_str, OBJ_PERMANENT, NULL ));
  409. /* sessions */
  410. create_session( 0 );
  411. create_session( 1 );
  412. /* object types */
  413. for (i = 0; i < ARRAY_SIZE(types); i++)
  414. release_object( create_object_type( &dir_objtype->obj, i, OBJ_PERMANENT, NULL ));
  415. /* symlinks */
  416. release_object( create_obj_symlink( &root_directory->obj, &link_dosdev_str, OBJ_PERMANENT, &dir_global->obj, NULL ));
  417. release_object( create_obj_symlink( &dir_global->obj, &link_global_str, OBJ_PERMANENT, &dir_global->obj, NULL ));
  418. release_object( create_obj_symlink( &dir_global->obj, &link_nul_str, OBJ_PERMANENT, null_device, NULL ));
  419. release_object( create_obj_symlink( &dir_global->obj, &link_pipe_str, OBJ_PERMANENT, named_pipe_device, NULL ));
  420. release_object( create_obj_symlink( &dir_global->obj, &link_mailslot_str, OBJ_PERMANENT, mailslot_device, NULL ));
  421. release_object( create_symlink( &dir_global->obj, &link_conin_str, OBJ_PERMANENT, &link_currentin_str, NULL ));
  422. release_object( create_symlink( &dir_global->obj, &link_conout_str, OBJ_PERMANENT, &link_currentout_str, NULL ));
  423. release_object( create_symlink( &dir_global->obj, &link_con_str, OBJ_PERMANENT, &link_console_str, NULL ));
  424. /* events */
  425. for (i = 0; i < ARRAY_SIZE( kernel_events ); i++)
  426. release_object( create_event( &dir_kernel->obj, &kernel_events[i], OBJ_PERMANENT, 1, 0, NULL ));
  427. release_object( create_keyed_event( &dir_kernel->obj, &keyed_event_crit_sect_str, OBJ_PERMANENT, NULL ));
  428. /* mappings */
  429. release_object( create_fd_mapping( &dir_nls->obj, &intl_str, intl_fd, OBJ_PERMANENT, NULL ));
  430. release_object( create_user_data_mapping( &dir_kernel->obj, &user_data_str, OBJ_PERMANENT, NULL ));
  431. release_object( intl_fd );
  432. release_object( named_pipe_device );
  433. release_object( mailslot_device );
  434. release_object( null_device );
  435. release_object( root_directory );
  436. release_object( dir_driver );
  437. release_object( dir_device );
  438. release_object( dir_objtype );
  439. release_object( dir_kernel );
  440. release_object( dir_nls );
  441. release_object( dir_global );
  442. }
  443. /* create a directory object */
  444. DECL_HANDLER(create_directory)
  445. {
  446. struct unicode_str name;
  447. struct object *root;
  448. struct directory *dir;
  449. const struct security_descriptor *sd;
  450. const struct object_attributes *objattr = get_req_object_attributes( &sd, &name, &root );
  451. if (!objattr) return;
  452. if ((dir = create_directory( root, &name, objattr->attributes, HASH_SIZE, sd )))
  453. {
  454. reply->handle = alloc_handle( current->process, dir, req->access, objattr->attributes );
  455. release_object( dir );
  456. }
  457. if (root) release_object( root );
  458. }
  459. /* open a directory object */
  460. DECL_HANDLER(open_directory)
  461. {
  462. struct unicode_str name = get_req_unicode_str();
  463. reply->handle = open_object( current->process, req->rootdir, req->access,
  464. &directory_ops, &name, req->attributes );
  465. }
  466. /* get a directory entry by index */
  467. DECL_HANDLER(get_directory_entry)
  468. {
  469. struct directory *dir = (struct directory *)get_handle_obj( current->process, req->handle,
  470. DIRECTORY_QUERY, &directory_ops );
  471. if (dir)
  472. {
  473. struct object *obj = find_object_index( dir->entries, req->index );
  474. if (obj)
  475. {
  476. data_size_t name_len;
  477. const struct unicode_str *type_name = &obj->ops->type->name;
  478. const WCHAR *name = get_object_name( obj, &name_len );
  479. if (name_len + type_name->len <= get_reply_max_size())
  480. {
  481. void *ptr = set_reply_data_size( name_len + type_name->len );
  482. if (ptr)
  483. {
  484. reply->name_len = name_len;
  485. memcpy( ptr, name, name_len );
  486. memcpy( (char *)ptr + name_len, type_name->str, type_name->len );
  487. }
  488. }
  489. else set_error( STATUS_BUFFER_OVERFLOW );
  490. release_object( obj );
  491. }
  492. release_object( dir );
  493. }
  494. }
  495. /* query object type name information */
  496. DECL_HANDLER(get_object_type)
  497. {
  498. struct object *obj;
  499. struct type_descr *type;
  500. struct object_type_info *info;
  501. if (!(obj = get_handle_obj( current->process, req->handle, 0, NULL ))) return;
  502. type = obj->ops->type;
  503. if (sizeof(*info) + type->name.len <= get_reply_max_size())
  504. {
  505. if ((info = set_reply_data_size( sizeof(*info) + type->name.len )))
  506. {
  507. info->name_len = type->name.len;
  508. info->index = type->index;
  509. info->obj_count = type->obj_count;
  510. info->handle_count = type->handle_count;
  511. info->obj_max = type->obj_max;
  512. info->handle_max = type->handle_max;
  513. info->valid_access = type->valid_access;
  514. info->mapping = type->mapping;
  515. memcpy( info + 1, type->name.str, type->name.len );
  516. }
  517. }
  518. else set_error( STATUS_BUFFER_OVERFLOW );
  519. release_object( obj );
  520. }
  521. /* query type information for all types */
  522. DECL_HANDLER(get_object_types)
  523. {
  524. struct object_type_info *info;
  525. data_size_t size = ARRAY_SIZE(types) * sizeof(*info);
  526. unsigned int i;
  527. char *next;
  528. for (i = 0; i < ARRAY_SIZE(types); i++) size += (types[i]->name.len + 3) & ~3;
  529. if (size <= get_reply_max_size())
  530. {
  531. if ((info = set_reply_data_size( size )))
  532. {
  533. for (i = 0; i < ARRAY_SIZE(types); i++)
  534. {
  535. info->name_len = types[i]->name.len;
  536. info->index = types[i]->index;
  537. info->obj_count = types[i]->obj_count;
  538. info->handle_count = types[i]->handle_count;
  539. info->obj_max = types[i]->obj_max;
  540. info->handle_max = types[i]->handle_max;
  541. info->valid_access = types[i]->valid_access;
  542. info->mapping = types[i]->mapping;
  543. memcpy( info + 1, types[i]->name.str, types[i]->name.len );
  544. next = (char *)(info + 1) + types[i]->name.len;
  545. if (types[i]->name.len & 3)
  546. {
  547. memset( next, 0, 4 - (types[i]->name.len & 3) );
  548. next += 4 - (types[i]->name.len & 3);
  549. }
  550. info = (struct object_type_info *)next;
  551. }
  552. reply->count = i;
  553. }
  554. }
  555. else set_error( STATUS_BUFFER_OVERFLOW );
  556. }