1 /* $Id: connect.c 14015 2005-03-13 17:00:19Z ea $
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 <sm/helper.h>
16 /**********************************************************************
21 * Connect to SM API port and register a session "begin" port (Sb)
22 * or to issue API requests to SmApiPort.
25 * pSbApiPortName: name of the Sb port the calling subsystem
26 * server already created in the system name space;
27 * hSbApiPort: LPC port handle (checked, but not used: the
28 * subsystem is required to have already created
29 * the callback port before it connects to the SM);
30 * wSubsystem: a valid IMAGE_SUBSYSTEM_xxx value;
31 * phSmApiPort: a pointer to a HANDLE, which will be
32 * filled with a valid client-side LPC comm port.
34 * There should be only two ways to call this API:
35 * a) subsystems willing to register with SM will use it
36 * with full parameters (the function checks them);
37 * b) regular SM clients, will set to 0 the 1st, the 2nd,
38 * and the 3rd parameter.
41 * If all three optional values are omitted, an LPC status.
42 * STATUS_INVALID_PARAMETER_MIX if PortName is defined and
43 * both hSbApiPort and wSubsystem are 0.
46 SmConnectApiPort (IN PUNICODE_STRING pSbApiPortName OPTIONAL
,
47 IN HANDLE hSbApiPort OPTIONAL
,
48 IN WORD wSubSystemId OPTIONAL
,
49 IN OUT PHANDLE phSmApiPort
)
51 UNICODE_STRING SmApiPortName
;
52 SECURITY_QUALITY_OF_SERVICE SecurityQos
;
53 NTSTATUS Status
= STATUS_SUCCESS
;
54 SM_CONNECT_DATA ConnectData
= {0,0,{0}};
55 ULONG ConnectDataLength
= 0;
57 DPRINT("SMLIB: %s called\n", __FUNCTION__
);
61 if (pSbApiPortName
->Length
> (sizeof pSbApiPortName
->Buffer
[0] * SM_SB_NAME_MAX_LENGTH
))
63 return STATUS_INVALID_PARAMETER_1
;
65 if (NULL
== hSbApiPort
|| IMAGE_SUBSYSTEM_UNKNOWN
== wSubSystemId
)
67 return STATUS_INVALID_PARAMETER_MIX
;
69 RtlZeroMemory (& ConnectData
, sizeof ConnectData
);
70 ConnectData
.Unused
= 0;
71 ConnectData
.SubSystemId
= wSubSystemId
;
72 if (pSbApiPortName
->Length
> 0)
74 RtlCopyMemory (& ConnectData
.SbName
,
75 pSbApiPortName
->Buffer
,
76 pSbApiPortName
->Length
);
79 ConnectDataLength
= sizeof ConnectData
;
81 SecurityQos
.Length
= sizeof (SecurityQos
);
82 SecurityQos
.ImpersonationLevel
= SecurityIdentification
;
83 SecurityQos
.ContextTrackingMode
= TRUE
;
84 SecurityQos
.EffectiveOnly
= TRUE
;
86 RtlInitUnicodeString (& SmApiPortName
, SM_API_PORT_NAME
);
88 Status
= NtConnectPort (
98 if (NT_SUCCESS(Status
))
100 return STATUS_SUCCESS
;
102 DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__
, Status
);