riched20: Sign-compare warnings fix.
[wine/multimedia.git] / dlls / secur32 / negotiate.c
blob8c36bc15e4cca08387a2151643c78aa2282ceb0b
1 /*
2 * Copyright 2005 Kai Blin
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 * This file implements the negotiate provider.
19 * FIXME: So far, this beast doesn't do anything.
21 #include <assert.h>
22 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "sspi.h"
26 #include "secur32_priv.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(secur32);
31 static char nego_name_A[] = "Negotiate";
32 static WCHAR nego_name_W[] = {'N', 'e', 'g', 'o', 't', 'i', 'a', 't', 'e', 0};
34 static SECURITY_STATUS nego_QueryCredentialsAttributes(PCredHandle phCredential,
35 ULONG ulAttribute, PVOID pBuffer)
37 SECURITY_STATUS ret;
39 /* FIXME: More attributes to be added here. Need to fix the sspi.h header
40 * for that, too.
42 switch(ulAttribute)
44 default:
45 ret = SEC_E_UNSUPPORTED_FUNCTION;
47 return ret;
50 /***********************************************************************
51 * QueryCredentialsAttributesA
53 static SECURITY_STATUS SEC_ENTRY nego_QueryCredentialsAttributesA(
54 PCredHandle phCredential, ULONG ulAttribute, PVOID pBuffer)
56 SECURITY_STATUS ret;
58 TRACE("(%p, %d, %p)\n", phCredential, ulAttribute, pBuffer);
60 switch(ulAttribute)
62 case SECPKG_CRED_ATTR_NAMES:
63 FIXME("SECPKG_CRED_ATTR_NAMES: stub\n");
64 ret = SEC_E_UNSUPPORTED_FUNCTION;
65 break;
66 default:
67 ret = nego_QueryCredentialsAttributes(phCredential, ulAttribute,
68 pBuffer);
70 return ret;
73 /***********************************************************************
74 * QueryCredentialsAttributesW
76 static SECURITY_STATUS SEC_ENTRY nego_QueryCredentialsAttributesW(
77 PCredHandle phCredential, ULONG ulAttribute, PVOID pBuffer)
79 SECURITY_STATUS ret;
81 TRACE("(%p, %d, %p)\n", phCredential, ulAttribute, pBuffer);
83 switch(ulAttribute)
85 case SECPKG_CRED_ATTR_NAMES:
86 FIXME("SECPKG_CRED_ATTR_NAMES: stub\n");
87 ret = SEC_E_UNSUPPORTED_FUNCTION;
88 break;
89 default:
90 ret = nego_QueryCredentialsAttributes(phCredential, ulAttribute,
91 pBuffer);
93 return ret;
97 /***********************************************************************
98 * AcquireCredentialsHandleA
100 static SECURITY_STATUS SEC_ENTRY nego_AcquireCredentialsHandleA(
101 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialUse,
102 PLUID pLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
103 PVOID pGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
105 TRACE("(%s, %s, 0x%08x, %p, %p, %p, %p, %p, %p) stub\n",
106 debugstr_a(pszPrincipal), debugstr_a(pszPackage), fCredentialUse,
107 pLogonID, pAuthData, pGetKeyFn, pGetKeyArgument, phCredential, ptsExpiry);
108 return SEC_E_UNSUPPORTED_FUNCTION;
111 /***********************************************************************
112 * AcquireCredentialsHandleW
114 static SECURITY_STATUS SEC_ENTRY nego_AcquireCredentialsHandleW(
115 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialUse,
116 PLUID pLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
117 PVOID pGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
119 TRACE("(%s, %s, 0x%08x, %p, %p, %p, %p, %p, %p) stub\n",
120 debugstr_w(pszPrincipal), debugstr_w(pszPackage), fCredentialUse,
121 pLogonID, pAuthData, pGetKeyFn, pGetKeyArgument, phCredential, ptsExpiry);
122 return SEC_E_UNSUPPORTED_FUNCTION;
125 /***********************************************************************
126 * InitializeSecurityContextA
128 static SECURITY_STATUS SEC_ENTRY nego_InitializeSecurityContextA(
129 PCredHandle phCredential, PCtxtHandle phContext, SEC_CHAR *pszTargetName,
130 ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep,
131 PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext,
132 PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
134 SECURITY_STATUS ret;
136 TRACE("%p %p %s %d %d %d %p %d %p %p %p %p\n", phCredential, phContext,
137 debugstr_a(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
138 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
139 if(phCredential){
140 ret = SEC_E_UNSUPPORTED_FUNCTION;
142 else
144 ret = SEC_E_INVALID_HANDLE;
146 return ret;
149 /***********************************************************************
150 * InitializeSecurityContextW
152 static SECURITY_STATUS SEC_ENTRY nego_InitializeSecurityContextW(
153 PCredHandle phCredential, PCtxtHandle phContext, SEC_WCHAR *pszTargetName,
154 ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep,
155 PSecBufferDesc pInput,ULONG Reserved2, PCtxtHandle phNewContext,
156 PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
158 SECURITY_STATUS ret;
160 TRACE("%p %p %s %d %d %d %p %d %p %p %p %p\n", phCredential, phContext,
161 debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
162 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
163 if (phCredential)
165 ret = SEC_E_UNSUPPORTED_FUNCTION;
167 else
169 ret = SEC_E_INVALID_HANDLE;
171 return ret;
174 /***********************************************************************
175 * AcceptSecurityContext
177 static SECURITY_STATUS SEC_ENTRY nego_AcceptSecurityContext(
178 PCredHandle phCredential, PCtxtHandle phContext, PSecBufferDesc pInput,
179 ULONG fContextReq, ULONG TargetDataRep, PCtxtHandle phNewContext,
180 PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
182 SECURITY_STATUS ret;
184 TRACE("%p %p %p %d %d %p %p %p %p\n", phCredential, phContext, pInput,
185 fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr,
186 ptsExpiry);
187 if (phCredential)
189 ret = SEC_E_UNSUPPORTED_FUNCTION;
191 else
193 ret = SEC_E_INVALID_HANDLE;
195 return ret;
198 /***********************************************************************
199 * CompleteAuthToken
201 static SECURITY_STATUS SEC_ENTRY nego_CompleteAuthToken(PCtxtHandle phContext,
202 PSecBufferDesc pToken)
204 SECURITY_STATUS ret;
206 TRACE("%p %p\n", phContext, pToken);
207 if (phContext)
209 ret = SEC_E_UNSUPPORTED_FUNCTION;
211 else
213 ret = SEC_E_INVALID_HANDLE;
215 return ret;
218 /***********************************************************************
219 * DeleteSecurityContext
221 static SECURITY_STATUS SEC_ENTRY nego_DeleteSecurityContext(PCtxtHandle phContext)
223 SECURITY_STATUS ret;
225 TRACE("%p\n", phContext);
226 if (phContext)
228 ret = SEC_E_UNSUPPORTED_FUNCTION;
230 else
232 ret = SEC_E_INVALID_HANDLE;
234 return ret;
237 /***********************************************************************
238 * ApplyControlToken
240 static SECURITY_STATUS SEC_ENTRY nego_ApplyControlToken(PCtxtHandle phContext,
241 PSecBufferDesc pInput)
243 SECURITY_STATUS ret;
245 TRACE("%p %p\n", phContext, pInput);
246 if (phContext)
248 ret = SEC_E_UNSUPPORTED_FUNCTION;
250 else
252 ret = SEC_E_INVALID_HANDLE;
254 return ret;
257 /***********************************************************************
258 * QueryContextAttributesW
260 static SECURITY_STATUS SEC_ENTRY nego_QueryContextAttributesW(PCtxtHandle phContext,
261 ULONG ulAttribute, void *pBuffer)
263 SECURITY_STATUS ret;
265 /* FIXME: From reading wrapper.h, I think the dwUpper part of a context is
266 * the SecurePackage part and the dwLower part is the actual context
267 * handle. It should be easy to extract the context attributes from that.
269 TRACE("%p %d %p\n", phContext, ulAttribute, pBuffer);
270 if (phContext)
272 ret = SEC_E_UNSUPPORTED_FUNCTION;
274 else
276 ret = SEC_E_INVALID_HANDLE;
278 return ret;
281 /***********************************************************************
282 * QueryContextAttributesA
284 static SECURITY_STATUS SEC_ENTRY nego_QueryContextAttributesA(PCtxtHandle phContext,
285 ULONG ulAttribute, void *pBuffer)
287 return nego_QueryContextAttributesW(phContext, ulAttribute, pBuffer);
290 /***********************************************************************
291 * ImpersonateSecurityContext
293 static SECURITY_STATUS SEC_ENTRY nego_ImpersonateSecurityContext(PCtxtHandle phContext)
295 SECURITY_STATUS ret;
297 TRACE("%p\n", phContext);
298 if (phContext)
300 ret = SEC_E_UNSUPPORTED_FUNCTION;
302 else
304 ret = SEC_E_INVALID_HANDLE;
306 return ret;
309 /***********************************************************************
310 * RevertSecurityContext
312 static SECURITY_STATUS SEC_ENTRY nego_RevertSecurityContext(PCtxtHandle phContext)
314 SECURITY_STATUS ret;
316 TRACE("%p\n", phContext);
317 if (phContext)
319 ret = SEC_E_UNSUPPORTED_FUNCTION;
321 else
323 ret = SEC_E_INVALID_HANDLE;
325 return ret;
328 /***********************************************************************
329 * MakeSignature
331 static SECURITY_STATUS SEC_ENTRY nego_MakeSignature(PCtxtHandle phContext, ULONG fQOP,
332 PSecBufferDesc pMessage, ULONG MessageSeqNo)
334 SECURITY_STATUS ret;
336 TRACE("%p %d %p %d\n", phContext, fQOP, pMessage, MessageSeqNo);
337 if (phContext)
339 ret = SEC_E_UNSUPPORTED_FUNCTION;
341 else
343 ret = SEC_E_INVALID_HANDLE;
345 return ret;
348 /***********************************************************************
349 * VerifySignature
351 static SECURITY_STATUS SEC_ENTRY nego_VerifySignature(PCtxtHandle phContext,
352 PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP)
354 SECURITY_STATUS ret;
356 TRACE("%p %p %d %p\n", phContext, pMessage, MessageSeqNo, pfQOP);
357 if (phContext)
359 ret = SEC_E_UNSUPPORTED_FUNCTION;
361 else
363 ret = SEC_E_INVALID_HANDLE;
365 return ret;
370 static const SecurityFunctionTableA negoTableA = {
372 NULL, /* EnumerateSecurityPackagesA */
373 nego_QueryCredentialsAttributesA, /* QueryCredentialsAttributesA */
374 nego_AcquireCredentialsHandleA, /* AcquireCredentialsHandleA */
375 FreeCredentialsHandle, /* FreeCredentialsHandle */
376 NULL, /* Reserved2 */
377 nego_InitializeSecurityContextA, /* InitializeSecurityContextA */
378 nego_AcceptSecurityContext, /* AcceptSecurityContext */
379 nego_CompleteAuthToken, /* CompleteAuthToken */
380 nego_DeleteSecurityContext, /* DeleteSecurityContext */
381 nego_ApplyControlToken, /* ApplyControlToken */
382 nego_QueryContextAttributesA, /* QueryContextAttributesA */
383 nego_ImpersonateSecurityContext, /* ImpersonateSecurityContext */
384 nego_RevertSecurityContext, /* RevertSecurityContext */
385 nego_MakeSignature, /* MakeSignature */
386 nego_VerifySignature, /* VerifySignature */
387 FreeContextBuffer, /* FreeContextBuffer */
388 NULL, /* QuerySecurityPackageInfoA */
389 NULL, /* Reserved3 */
390 NULL, /* Reserved4 */
391 NULL, /* ExportSecurityContext */
392 NULL, /* ImportSecurityContextA */
393 NULL, /* AddCredentialsA */
394 NULL, /* Reserved8 */
395 NULL, /* QuerySecurityContextToken */
396 NULL, /* EncryptMessage */
397 NULL, /* DecryptMessage */
398 NULL, /* SetContextAttributesA */
401 static const SecurityFunctionTableW negoTableW = {
403 NULL, /* EnumerateSecurityPackagesW */
404 nego_QueryCredentialsAttributesW, /* QueryCredentialsAttributesW */
405 nego_AcquireCredentialsHandleW, /* AcquireCredentialsHandleW */
406 FreeCredentialsHandle, /* FreeCredentialsHandle */
407 NULL, /* Reserved2 */
408 nego_InitializeSecurityContextW, /* InitializeSecurityContextW */
409 nego_AcceptSecurityContext, /* AcceptSecurityContext */
410 nego_CompleteAuthToken, /* CompleteAuthToken */
411 nego_DeleteSecurityContext, /* DeleteSecurityContext */
412 nego_ApplyControlToken, /* ApplyControlToken */
413 nego_QueryContextAttributesW, /* QueryContextAttributesW */
414 nego_ImpersonateSecurityContext, /* ImpersonateSecurityContext */
415 nego_RevertSecurityContext, /* RevertSecurityContext */
416 nego_MakeSignature, /* MakeSignature */
417 nego_VerifySignature, /* VerifySignature */
418 FreeContextBuffer, /* FreeContextBuffer */
419 NULL, /* QuerySecurityPackageInfoW */
420 NULL, /* Reserved3 */
421 NULL, /* Reserved4 */
422 NULL, /* ExportSecurityContext */
423 NULL, /* ImportSecurityContextW */
424 NULL, /* AddCredentialsW */
425 NULL, /* Reserved8 */
426 NULL, /* QuerySecurityContextToken */
427 NULL, /* EncryptMessage */
428 NULL, /* DecryptMessage */
429 NULL, /* SetContextAttributesW */
432 static WCHAR negotiate_comment_W[] = { 'M', 'i', 'c', 'r', 'o', 's', 'o',
433 'f', 't', ' ', 'P', 'a', 'c', 'k', 'a', 'g', 'e', ' ', 'N', 'e', 'g', 'o',
434 't', 'i', 'a', 't', 'o', 'r', 0};
436 static CHAR negotiate_comment_A[] = "Microsoft Package Negotiator";
440 void SECUR32_initNegotiateSP(void)
442 SecureProvider *provider = SECUR32_addProvider(&negoTableA, &negoTableW,
443 NULL);
444 /* According to Windows, Negotiate has the following capabilities.
447 static const LONG caps =
448 SECPKG_FLAG_INTEGRITY |
449 SECPKG_FLAG_PRIVACY |
450 SECPKG_FLAG_CONNECTION |
451 SECPKG_FLAG_MULTI_REQUIRED |
452 SECPKG_FLAG_EXTENDED_ERROR |
453 SECPKG_FLAG_IMPERSONATION |
454 SECPKG_FLAG_ACCEPT_WIN32_NAME |
455 SECPKG_FLAG_READONLY_WITH_CHECKSUM;
457 static const USHORT version = 1;
458 static const USHORT rpcid = 15;
459 static const ULONG max_token = 12000;
460 const SecPkgInfoW infoW = { caps, version, rpcid, max_token, nego_name_W,
461 negotiate_comment_W};
462 const SecPkgInfoA infoA = { caps, version, rpcid, max_token, nego_name_A,
463 negotiate_comment_A};
465 SECUR32_addPackages(provider, 1L, &infoA, &infoW);