3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: reactos/lib/smlib/connect.c
6 * PURPOSE: Connect to the API LPC port exposed by the SM
14 /**********************************************************************
19 * Connect to SM API port and register a session "begin" port (Sb)
20 * or to issue API requests to SmApiPort.
23 * pSbApiPortName: name of the Sb port the calling subsystem
24 * server already created in the system name space;
25 * hSbApiPort: LPC port handle (checked, but not used: the
26 * subsystem is required to have already created
27 * the callback port before it connects to the SM);
28 * wSubsystem: a valid IMAGE_SUBSYSTEM_xxx value;
29 * phSmApiPort: a pointer to a HANDLE, which will be
30 * filled with a valid client-side LPC comm port.
32 * There should be only two ways to call this API:
33 * a) subsystems willing to register with SM will use it
34 * with full parameters (the function checks them);
35 * b) regular SM clients, will set to 0 the 1st, the 2nd,
36 * and the 3rd parameter.
39 * If all three optional values are omitted, an LPC status.
40 * STATUS_INVALID_PARAMETER_MIX if PortName is defined and
41 * both hSbApiPort and wSubsystem are 0.
44 SmConnectApiPort (IN PUNICODE_STRING pSbApiPortName OPTIONAL
,
45 IN HANDLE hSbApiPort OPTIONAL
,
46 IN WORD wSubSystemId OPTIONAL
,
47 IN OUT PHANDLE phSmApiPort
)
49 UNICODE_STRING SmApiPortName
;
50 SECURITY_QUALITY_OF_SERVICE SecurityQos
;
51 NTSTATUS Status
= STATUS_SUCCESS
;
52 SM_CONNECT_DATA ConnectData
= {0,0,{0}};
53 ULONG ConnectDataLength
= 0;
55 DPRINT("SMLIB: %s called\n", __FUNCTION__
);
59 if (pSbApiPortName
->Length
> (sizeof pSbApiPortName
->Buffer
[0] * SM_SB_NAME_MAX_LENGTH
))
61 return STATUS_INVALID_PARAMETER_1
;
63 if (NULL
== hSbApiPort
|| IMAGE_SUBSYSTEM_UNKNOWN
== wSubSystemId
)
65 return STATUS_INVALID_PARAMETER_MIX
;
67 RtlZeroMemory (& ConnectData
, sizeof ConnectData
);
68 ConnectData
.Unused
= 0;
69 ConnectData
.SubSystemId
= wSubSystemId
;
70 if (pSbApiPortName
->Length
> 0)
72 RtlCopyMemory (& ConnectData
.SbName
,
73 pSbApiPortName
->Buffer
,
74 pSbApiPortName
->Length
);
77 ConnectDataLength
= sizeof ConnectData
;
79 SecurityQos
.Length
= sizeof (SecurityQos
);
80 SecurityQos
.ImpersonationLevel
= SecurityIdentification
;
81 SecurityQos
.ContextTrackingMode
= SECURITY_DYNAMIC_TRACKING
;
82 SecurityQos
.EffectiveOnly
= TRUE
;
84 RtlInitUnicodeString (& SmApiPortName
, SM_API_PORT_NAME
);
86 Status
= NtConnectPort (
96 if (NT_SUCCESS(Status
))
98 return STATUS_SUCCESS
;
100 DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__
, Status
);