Blame src/tty/ntapi_tty_join_session.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
dd89bb
/*  Copyright (C) 2013,2014,2015  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 */
dd89bb
	__ntapi->tt_port_name_from_attributes(
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
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
}