Branch setupapi (again)
[reactos.git] / reactos / ntoskrnl / lpc / create.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/lpc/create.c
6 * PURPOSE: Communication mechanism
7 * PROGRAMMER: David Welch (welch@cwcom.net)
8 * UPDATE HISTORY:
9 * Created 22/05/98
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ntoskrnl.h>
15 #define NDEBUG
16 #include <internal/debug.h>
17
18 /**********************************************************************
19 * NAME
20 * LpcpVerifyCreateParameters/5
21 *
22 * DESCRIPTION
23 * Verify user parameters in NtCreatePort and in
24 * NtCreateWaitablePort.
25 *
26 * ARGUMENTS
27 *
28 * RETURN VALUE
29 */
30 STATIC NTSTATUS STDCALL
31 LpcpVerifyCreateParameters (IN PHANDLE PortHandle,
32 IN POBJECT_ATTRIBUTES ObjectAttributes,
33 IN ULONG MaxConnectInfoLength,
34 IN ULONG MaxDataLength,
35 IN ULONG MaxPoolUsage)
36 {
37 if (NULL == PortHandle)
38 {
39 return (STATUS_INVALID_PARAMETER_1);
40 }
41 if (NULL == ObjectAttributes)
42 {
43 return (STATUS_INVALID_PARAMETER_2);
44 }
45 if ((ObjectAttributes->Attributes & OBJ_OPENLINK)
46 || (ObjectAttributes->Attributes & OBJ_OPENIF)
47 || (ObjectAttributes->Attributes & OBJ_EXCLUSIVE)
48 || (ObjectAttributes->Attributes & OBJ_PERMANENT)
49 || (ObjectAttributes->Attributes & OBJ_INHERIT))
50 {
51 return (STATUS_INVALID_PORT_ATTRIBUTES);
52 }
53 if (MaxConnectInfoLength > PORT_MAX_DATA_LENGTH)
54 {
55 return (STATUS_INVALID_PARAMETER_3);
56 }
57 if (MaxDataLength > PORT_MAX_MESSAGE_LENGTH)
58 {
59 return (STATUS_INVALID_PARAMETER_4);
60 }
61 /* TODO: some checking is done also on MaxPoolUsage
62 * to avoid choking the executive */
63 return (STATUS_SUCCESS);
64 }
65
66
67 /**********************************************************************
68 * NAME
69 * NiCreatePort/4
70 *
71 * DESCRIPTION
72 *
73 * ARGUMENTS
74 *
75 * RETURN VALUE
76 */
77 NTSTATUS STDCALL
78 NiCreatePort (PVOID ObjectBody,
79 PVOID Parent,
80 PWSTR RemainingPath,
81 POBJECT_ATTRIBUTES ObjectAttributes)
82 {
83 if (RemainingPath == NULL)
84 {
85 return (STATUS_SUCCESS);
86 }
87
88 if (wcschr(RemainingPath+1, '\\') != NULL)
89 {
90 return (STATUS_UNSUCCESSFUL);
91 }
92
93 return (STATUS_SUCCESS);
94 }
95
96
97 /**********************************************************************
98 * NAME EXPORTED
99 * NtCreatePort/5
100 *
101 * DESCRIPTION
102 *
103 * ARGUMENTS
104 * PortHandle,
105 * ObjectAttributes,
106 * MaxConnectInfoLength,
107 * MaxDataLength,
108 * MaxPoolUsage: size of NP zone the NP part of msgs is kept in
109 *
110 * RETURN VALUE
111 */
112 /*EXPORTED*/ NTSTATUS STDCALL
113 NtCreatePort (PHANDLE PortHandle,
114 POBJECT_ATTRIBUTES ObjectAttributes,
115 ULONG MaxConnectInfoLength,
116 ULONG MaxDataLength,
117 ULONG MaxPoolUsage)
118 {
119 PEPORT Port;
120 NTSTATUS Status;
121
122 DPRINT("NtCreatePort() Name %x\n", ObjectAttributes->ObjectName->Buffer);
123
124 /* Verify parameters */
125 Status = LpcpVerifyCreateParameters (PortHandle,
126 ObjectAttributes,
127 MaxConnectInfoLength,
128 MaxDataLength,
129 MaxPoolUsage);
130 if (STATUS_SUCCESS != Status)
131 {
132 return (Status);
133 }
134
135 /* Ask Ob to create the object */
136 Status = ObCreateObject (ExGetPreviousMode(),
137 & LpcPortObjectType,
138 ObjectAttributes,
139 ExGetPreviousMode(),
140 NULL,
141 sizeof(EPORT),
142 0,
143 0,
144 (PVOID*)&Port);
145 if (!NT_SUCCESS(Status))
146 {
147 return (Status);
148 }
149
150 Status = ObInsertObject ((PVOID)Port,
151 NULL,
152 PORT_ALL_ACCESS,
153 0,
154 NULL,
155 PortHandle);
156 if (!NT_SUCCESS(Status))
157 {
158 ObDereferenceObject (Port);
159 return (Status);
160 }
161
162 Status = NiInitializePort (Port, EPORT_TYPE_SERVER_RQST_PORT, NULL);
163 Port->MaxConnectInfoLength = PORT_MAX_DATA_LENGTH;
164 Port->MaxDataLength = PORT_MAX_MESSAGE_LENGTH;
165 Port->MaxPoolUsage = MaxPoolUsage;
166
167 ObDereferenceObject (Port);
168
169 return (Status);
170 }
171
172 /**********************************************************************
173 * NAME EXPORTED
174 * NtCreateWaitablePort/5
175 *
176 * DESCRIPTION
177 * Waitable ports can be connected to with NtSecureConnectPort.
178 * No port interface can be used with waitable ports but
179 * NtReplyWaitReceivePort and NtReplyWaitReceivePortEx.
180 * Present only in w2k+.
181 *
182 * ARGUMENTS
183 * PortHandle,
184 * ObjectAttributes,
185 * MaxConnectInfoLength,
186 * MaxDataLength,
187 * MaxPoolUsage
188 *
189 * RETURN VALUE
190 */
191 /*EXPORTED*/ NTSTATUS STDCALL
192 NtCreateWaitablePort (OUT PHANDLE PortHandle,
193 IN POBJECT_ATTRIBUTES ObjectAttributes,
194 IN ULONG MaxConnectInfoLength,
195 IN ULONG MaxDataLength,
196 IN ULONG MaxPoolUsage)
197 {
198 NTSTATUS Status;
199
200 /* Verify parameters */
201 Status = LpcpVerifyCreateParameters (PortHandle,
202 ObjectAttributes,
203 MaxConnectInfoLength,
204 MaxDataLength,
205 MaxPoolUsage);
206 if (STATUS_SUCCESS != Status)
207 {
208 return (Status);
209 }
210 /* TODO */
211 return (STATUS_NOT_IMPLEMENTED);
212 }
213
214 /* EOF */