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
10 #include <ndk/ntndk.h>
12 #include <sm/helper.h>
17 /**********************************************************************
22 * Connect to SM API port and register a session "begin" port (Sb)
23 * or to issue API requests to SmApiPort.
26 * pSbApiPortName: name of the Sb port the calling subsystem
27 * server already created in the system name space;
28 * hSbApiPort: LPC port handle (checked, but not used: the
29 * subsystem is required to have already created
30 * the callback port before it connects to the SM);
31 * wSubsystem: a valid IMAGE_SUBSYSTEM_xxx value;
32 * phSmApiPort: a pointer to a HANDLE, which will be
33 * filled with a valid client-side LPC comm port.
35 * There should be only two ways to call this API:
36 * a) subsystems willing to register with SM will use it
37 * with full parameters (the function checks them);
38 * b) regular SM clients, will set to 0 the 1st, the 2nd,
39 * and the 3rd parameter.
42 * If all three optional values are omitted, an LPC status.
43 * STATUS_INVALID_PARAMETER_MIX if PortName is defined and
44 * both hSbApiPort and wSubsystem are 0.
47 SmConnectApiPort (IN PUNICODE_STRING pSbApiPortName OPTIONAL
,
48 IN HANDLE hSbApiPort OPTIONAL
,
49 IN WORD wSubSystemId OPTIONAL
,
50 IN OUT PHANDLE phSmApiPort
)
52 UNICODE_STRING SmApiPortName
;
53 SECURITY_QUALITY_OF_SERVICE SecurityQos
;
54 NTSTATUS Status
= STATUS_SUCCESS
;
55 SM_CONNECT_DATA ConnectData
= {0,0,{0}};
56 ULONG ConnectDataLength
= 0;
58 DPRINT("SMLIB: %s called\n", __FUNCTION__
);
62 if (pSbApiPortName
->Length
> (sizeof pSbApiPortName
->Buffer
[0] * SM_SB_NAME_MAX_LENGTH
))
64 return STATUS_INVALID_PARAMETER_1
;
66 if (NULL
== hSbApiPort
|| IMAGE_SUBSYSTEM_UNKNOWN
== wSubSystemId
)
68 return STATUS_INVALID_PARAMETER_MIX
;
70 RtlZeroMemory (& ConnectData
, sizeof ConnectData
);
71 ConnectData
.Unused
= 0;
72 ConnectData
.SubSystemId
= wSubSystemId
;
73 if (pSbApiPortName
->Length
> 0)
75 RtlCopyMemory (& ConnectData
.SbName
,
76 pSbApiPortName
->Buffer
,
77 pSbApiPortName
->Length
);
80 ConnectDataLength
= sizeof ConnectData
;
82 SecurityQos
.Length
= sizeof (SecurityQos
);
83 SecurityQos
.ImpersonationLevel
= SecurityIdentification
;
84 SecurityQos
.ContextTrackingMode
= TRUE
;
85 SecurityQos
.EffectiveOnly
= TRUE
;
87 RtlInitUnicodeString (& SmApiPortName
, SM_API_PORT_NAME
);
89 Status
= NtConnectPort (
99 if (NT_SUCCESS(Status
))
101 return STATUS_SUCCESS
;
103 DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__
, Status
);