Copy wininet to branch
[reactos.git] / reactos / lib / smlib / connect.c
1 /* $Id: connect.c 14015 2005-03-13 17:00:19Z ea $
2 *
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
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("SMLIB: %s called\n", __FUNCTION__);
51
52 if (pSbApiPortName)
53 {
54 if (pSbApiPortName->Length > (sizeof pSbApiPortName->Buffer[0] * SM_SB_NAME_MAX_LENGTH))
55 {
56 return STATUS_INVALID_PARAMETER_1;
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 if (pSbApiPortName->Length > 0)
65 {
66 RtlCopyMemory (& ConnectData.SbName,
67 pSbApiPortName->Buffer,
68 pSbApiPortName->Length);
69 }
70 }
71 ConnectDataLength = sizeof ConnectData;
72
73 SecurityQos.Length = sizeof (SecurityQos);
74 SecurityQos.ImpersonationLevel = SecurityIdentification;
75 SecurityQos.ContextTrackingMode = TRUE;
76 SecurityQos.EffectiveOnly = TRUE;
77
78 RtlInitUnicodeString (& SmApiPortName, SM_API_PORT_NAME);
79
80 Status = NtConnectPort (
81 phSmApiPort,
82 & SmApiPortName,
83 & SecurityQos,
84 NULL,
85 NULL,
86 NULL,
87 & ConnectData,
88 & ConnectDataLength
89 );
90 if (NT_SUCCESS(Status))
91 {
92 return STATUS_SUCCESS;
93 }
94 DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
95 return Status;
96 }
97
98 /* EOF */