directory.c 27 KB

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