17ba96c562ec437ea01b716823a0501abf118026
[reactos.git] / reactos / lib / smdll / connect.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: reactos/lib/smdll/connect.c
6 * PURPOSE: Connect to the API LPC port exposed by the SM
7 */
8 #define NTOS_MODE_USER
9 #include <ntos.h>
10 #include <sm/api.h>
11 #include <sm/helper.h>
12 #include <pe.h>
13
14 #define NDEBUG
15 #include <debug.h>
16
17 /**********************************************************************
18 * NAME EXPORTED
19 * SmConnectApiPort/4
20 *
21 * DESCRIPTION
22 * Connect to SM API port and register a session "begin" port (Sb)
23 * or to issue API requests to SmApiPort.
24 *
25 * ARGUMENTS
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);
29 * dwSubsystem: a valid IMAGE_SUBSYSTEM_xxx value;
30 * phSmApiPort: a pointer to a HANDLE, which will be
31 * filled with a valid client-side LPC comm port.
32 *
33 * RETURN VALUE
34 * If all three optional values are omitted, an LPC status.
35 * STATUS_INVALID_PARAMETER_MIX if PortName is defined and
36 * both hSbApiPort and dwSubsystem are 0.
37 */
38 NTSTATUS STDCALL
39 SmConnectApiPort (IN PUNICODE_STRING pSbApiPortName OPTIONAL,
40 IN HANDLE hSbApiPort OPTIONAL,
41 IN DWORD dwSubsystem OPTIONAL,
42 IN OUT PHANDLE phSmApiPort)
43 {
44 UNICODE_STRING SmApiPortName;
45 SECURITY_QUALITY_OF_SERVICE SecurityQos;
46 NTSTATUS Status = STATUS_SUCCESS;
47 SM_CONNECT_DATA ConnectData = {0,{0}};
48 ULONG ConnectDataLength = 0;
49
50 DPRINT("SMDLL: %s called\n", __FUNCTION__);
51
52 if (pSbApiPortName->Length > (sizeof pSbApiPortName->Buffer[0] * SM_SB_NAME_MAX_LENGTH))
53 {
54 return STATUS_INVALID_PARAMETER_1;
55 }
56 if (pSbApiPortName)
57 {
58 if (NULL == hSbApiPort || IMAGE_SUBSYSTEM_UNKNOWN == dwSubsystem)
59 {
60 return STATUS_INVALID_PARAMETER_MIX;
61 }
62 RtlZeroMemory (& ConnectData, sizeof ConnectData);
63 ConnectData.Subsystem = dwSubsystem;
64 RtlCopyMemory (& ConnectData.SbName,
65 pSbApiPortName->Buffer,
66 pSbApiPortName->Length);
67 }
68 ConnectDataLength = sizeof ConnectData;
69
70 SecurityQos.Length = sizeof (SecurityQos);
71 SecurityQos.ImpersonationLevel = SecurityIdentification;
72 SecurityQos.ContextTrackingMode = TRUE;
73 SecurityQos.EffectiveOnly = TRUE;
74
75 RtlInitUnicodeString (& SmApiPortName, SM_API_PORT_NAME);
76
77 Status = NtConnectPort (
78 phSmApiPort,
79 & SmApiPortName,
80 & SecurityQos,
81 NULL,
82 NULL,
83 NULL,
84 & ConnectData,
85 & ConnectDataLength
86 );
87 if (NT_SUCCESS(Status))
88 {
89 return STATUS_SUCCESS;
90 }
91 DPRINT("SMDLL: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
92 return Status;
93 }
94
95 /* EOF */