diff --git a/src/daemon/toks_daemon_loop.c b/src/daemon/toks_daemon_loop.c index 7c64888..2f7a4cf 100644 --- a/src/daemon/toks_daemon_loop.c +++ b/src/daemon/toks_daemon_loop.c @@ -35,6 +35,12 @@ static toks_daemon_routine * toks_client_vtbl[TOKS_VTBL_ELEMENTS] = { TOKS_HANDLER(TTYSIGNAL, toks_daemon_signal), }; +static const nt_guid g_pidmap = NT_PROCESS_GUID_PIDMAP; +static const wchar16_t p_pidmap[6] = NT_PROCESS_OBJDIR_PREFIX_PIDMAP; + +static const nt_guid g_ntpipc = NT_PROCESS_GUID_NTPIPC; +static const wchar16_t p_ntpipc[6] = NT_PROCESS_OBJDIR_PREFIX_NTPIPC; + static void toks_daemon_ctrlpid_abort(struct toks_daemon_ctx * dctx) { void * hport; @@ -149,6 +155,75 @@ static int32_t toks_daemon_ctrlpid_instance(struct toks_daemon_ctx * dctx) return NT_STATUS_SUCCESS; } +static int toks_server_init_pidmap_object_directory(nt_rtdata * rtdata) +{ + return rtdata->hpidmapdir + ? NT_STATUS_SUCCESS + : ntapi->tt_open_ipc_object_directory( + &rtdata->hpidmapdir, + NT_SEC_READ_CONTROL + | NT_DIRECTORY_QUERY + | NT_DIRECTORY_TRAVERSE + | NT_DIRECTORY_CREATE_OBJECT + | NT_DIRECTORY_CREATE_SUBDIRECTORY, + p_pidmap,&g_pidmap); +} + +static int toks_server_init_ntpipc_object_directory(nt_rtdata * rtdata) +{ + return rtdata->hntpipcdir + ? NT_STATUS_SUCCESS + : ntapi->tt_open_ipc_object_directory( + &rtdata->hntpipcdir, + NT_SEC_READ_CONTROL + | NT_DIRECTORY_QUERY + | NT_DIRECTORY_TRAVERSE + | NT_DIRECTORY_CREATE_OBJECT + | NT_DIRECTORY_CREATE_SUBDIRECTORY, + p_ntpipc,&g_ntpipc); +} + +static int toks_init_pidmap_target_symlink(struct toks_daemon_ctx * dctx) +{ + int status; + void * hkeydir; + + struct toks_driver_ctx_impl * ictx = toks_get_driver_ictx(dctx->driver_ctx); + + if ((status = ntapi->tt_create_keyed_object_directory( + &hkeydir, + NT_SYMBOLIC_LINK_ALL_ACCESS, + ictx->rtdata->hpidmapdir, + pe_get_current_process_id()))) + return status; + + if ((status = ntapi->zw_set_information_object( + hkeydir, + NT_OBJECT_HANDLE_INFORMATION, + &(nt_object_handle_information){0,0}, + sizeof(nt_object_handle_information)))) + return status; + + return ntapi->tt_create_keyed_object_directory_entry( + &ictx->hntpipc, + NT_SYMBOLIC_LINK_ALL_ACCESS, + hkeydir, + dctx->hport_daemon,0, + pe_get_current_process_id()); +} + +static int toks_init_ntpipc_target_symlink(struct toks_daemon_ctx * dctx) +{ + struct toks_driver_ctx_impl * ictx = toks_get_driver_ictx(dctx->driver_ctx); + + return ntapi->tt_create_keyed_object_directory_entry( + &ictx->hntpipc, + NT_SYMBOLIC_LINK_ALL_ACCESS, + ictx->rtdata->hntpipcdir, + dctx->hport_daemon,0, + pe_get_current_process_id()); +} + int32_t __stdcall toks_daemon_loop(void * ctx) { struct toks_daemon_ctx * dctx; @@ -193,6 +268,22 @@ int32_t __stdcall toks_daemon_loop(void * ctx) if (svcvtbl == toks_daemon_vtbl) toks_log_service_info(dctx); + /* pidmap object directory */ + if ((status = toks_server_init_pidmap_object_directory(rtdata))) + return status; + + /* pidmap daemon symlink */ + if ((status = toks_init_pidmap_target_symlink(dctx))) + return status; + + /* ntpipc object directory */ + if ((status = toks_server_init_ntpipc_object_directory(rtdata))) + return status; + + /* ntpipc daemon symlink */ + if ((status = toks_init_ntpipc_target_symlink(dctx))) + return status; + /* init */ request = &dctx->request; reply = &dctx->reply; diff --git a/src/internal/toksvc_driver_impl.h b/src/internal/toksvc_driver_impl.h index a7b135a..6dc8541 100644 --- a/src/internal/toksvc_driver_impl.h +++ b/src/internal/toksvc_driver_impl.h @@ -70,6 +70,8 @@ struct toks_driver_ctx_impl { int64_t timeout; char * refstr; void * hevent; + void * hpidnap; + void * hntpipc; void * hsvcdir; void * hpiddir; void * hsvclink;