directory.c 27 KB

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