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