|
|
dd89bb |
/********************************************************/
|
|
|
dd89bb |
/* ntapi: Native API core library */
|
|
|
dde53a |
/* Copyright (C) 2013--2017 Z. Gilboa */
|
|
|
dd89bb |
/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */
|
|
|
dd89bb |
/********************************************************/
|
|
|
dd89bb |
|
|
|
dd89bb |
#include <psxtypes/psxtypes.h>
|
|
|
dd89bb |
#include <ntapi/ntapi.h>
|
|
|
dd89bb |
#include "ntapi_impl.h"
|
|
|
dd89bb |
|
|
|
dd89bb |
int32_t __stdcall __ntapi_tty_join_session(
|
|
|
dd89bb |
__out void ** hport,
|
|
|
dd89bb |
__out nt_port_name * port_name,
|
|
|
dd89bb |
__in nt_port_attr * port_attr,
|
|
|
dd89bb |
__in nt_tty_session_type type)
|
|
|
dd89bb |
{
|
|
|
dd89bb |
nt_status status;
|
|
|
dd89bb |
ntapi_internals * __internals;
|
|
|
dd89bb |
|
|
|
dd89bb |
/* init */
|
|
|
dd89bb |
__internals = __ntapi_internals();
|
|
|
dd89bb |
|
|
|
dd89bb |
if (type == NT_TTY_SESSION_PRIMARY) {
|
|
|
dd89bb |
hport = hport ? hport : &__internals->hport_tty_session;
|
|
|
dd89bb |
port_name = port_name ? port_name : __internals->subsystem;
|
|
|
dd89bb |
}
|
|
|
dd89bb |
|
|
|
dd89bb |
/* port name */
|
|
|
6d5726 |
__ntapi->tt_port_name_from_attr(
|
|
|
dd89bb |
port_name,
|
|
|
dd89bb |
port_attr);
|
|
|
dd89bb |
|
|
|
dd89bb |
/* connect to subsystem */
|
|
|
dd89bb |
if ((status = __ntapi->tty_connect(
|
|
|
dd89bb |
hport,
|
|
|
dd89bb |
(wchar16_t *)port_name,
|
|
|
dd89bb |
NT_SECURITY_IMPERSONATION)))
|
|
|
dd89bb |
return status;
|
|
|
dd89bb |
|
|
|
dd89bb |
/* finalize primary session */
|
|
|
dd89bb |
if (type == NT_TTY_SESSION_PRIMARY) {
|
|
|
dd89bb |
if (hport != &__internals->hport_tty_session)
|
|
|
dd89bb |
__internals->hport_tty_session = *hport;
|
|
|
dd89bb |
|
|
|
d9600b |
if (__internals->rtdata)
|
|
|
d9600b |
__internals->rtdata->hsession = *hport;
|
|
|
d9600b |
|
|
|
dd89bb |
if (port_name != __internals->subsystem)
|
|
|
dd89bb |
__ntapi->tt_memcpy_utf16(
|
|
|
dd89bb |
__internals->subsystem->base_named_objects,
|
|
|
dd89bb |
port_name->base_named_objects,
|
|
|
dd89bb |
sizeof(*port_name));
|
|
|
dd89bb |
};
|
|
|
dd89bb |
|
|
|
dd89bb |
return status;
|
|
|
dd89bb |
}
|