comctl32: A couple fixes for tab icon offsets.
[wine] / dlls / secur32 / schannel.c
1 /* Copyright (C) 2005 Juan Lang
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  *
17  * This file implements the schannel provider, or, the SSL/TLS implementations.
18  * FIXME: It should be rather obvious that this file is empty of any
19  * implementation.
20  */
21 #include <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "sspi.h"
25 #include "schannel.h"
26 #include "secur32_priv.h"
27 #include "wine/debug.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(secur32);
30
31 static SECURITY_STATUS schan_QueryCredentialsAttributes(
32  PCredHandle phCredential, ULONG ulAttribute, PVOID pBuffer)
33 {
34     SECURITY_STATUS ret;
35
36     switch (ulAttribute)
37     {
38     case SECPKG_ATTR_SUPPORTED_ALGS:
39         if (pBuffer)
40         {
41             /* FIXME: get from CryptoAPI */
42             FIXME("%ld: stub\n", ulAttribute);
43             ret = SEC_E_UNSUPPORTED_FUNCTION;
44         }
45         else
46             ret = SEC_E_INTERNAL_ERROR;
47         break;
48     case SECPKG_ATTR_CIPHER_STRENGTHS:
49         if (pBuffer)
50         {
51             /* FIXME: get from CryptoAPI */
52             FIXME("%ld: stub\n", ulAttribute);
53             ret = SEC_E_UNSUPPORTED_FUNCTION;
54         }
55         else
56             ret = SEC_E_INTERNAL_ERROR;
57         break;
58     case SECPKG_ATTR_SUPPORTED_PROTOCOLS:
59         if (pBuffer)
60         {
61             /* FIXME: get from OpenSSL? */
62             FIXME("%ld: stub\n", ulAttribute);
63             ret = SEC_E_UNSUPPORTED_FUNCTION;
64         }
65         else
66             ret = SEC_E_INTERNAL_ERROR;
67         break;
68     default:
69         ret = SEC_E_UNSUPPORTED_FUNCTION;
70     }
71     return ret;
72 }
73
74 static SECURITY_STATUS SEC_ENTRY schan_QueryCredentialsAttributesA(
75  PCredHandle phCredential, ULONG ulAttribute, PVOID pBuffer)
76 {
77     SECURITY_STATUS ret;
78
79     TRACE("(%p, %ld, %p)\n", phCredential, ulAttribute, pBuffer);
80
81     switch (ulAttribute)
82     {
83     case SECPKG_CRED_ATTR_NAMES:
84         FIXME("SECPKG_CRED_ATTR_NAMES: stub\n");
85         ret = SEC_E_UNSUPPORTED_FUNCTION;
86         break;
87     default:
88         ret = schan_QueryCredentialsAttributes(phCredential, ulAttribute,
89          pBuffer);
90     }
91     return ret;
92 }
93
94 static SECURITY_STATUS SEC_ENTRY schan_QueryCredentialsAttributesW(
95  PCredHandle phCredential, ULONG ulAttribute, PVOID pBuffer)
96 {
97     SECURITY_STATUS ret;
98
99     TRACE("(%p, %ld, %p)\n", phCredential, ulAttribute, pBuffer);
100
101     switch (ulAttribute)
102     {
103     case SECPKG_CRED_ATTR_NAMES:
104         FIXME("SECPKG_CRED_ATTR_NAMES: stub\n");
105         ret = SEC_E_UNSUPPORTED_FUNCTION;
106         break;
107     default:
108         ret = schan_QueryCredentialsAttributes(phCredential, ulAttribute,
109          pBuffer);
110     }
111     return ret;
112 }
113
114 static SECURITY_STATUS schan_AcquireCredentialsHandle(ULONG fCredentialUse,
115  PCredHandle phCredential, PTimeStamp ptsExpiry)
116 {
117     SECURITY_STATUS ret;
118
119     if (fCredentialUse == SECPKG_CRED_BOTH)
120         ret = SEC_E_NO_CREDENTIALS;
121     else
122     {
123         /* For now, the only thing I'm interested in is the direction of the
124          * connection, so just store it.
125          */
126         phCredential->dwUpper = fCredentialUse;
127         /* According to MSDN, all versions prior to XP do this */
128         if (ptsExpiry)
129             ptsExpiry->QuadPart = 0;
130         ret = SEC_E_OK;
131     }
132     return ret;
133 }
134
135 static SECURITY_STATUS SEC_ENTRY schan_AcquireCredentialsHandleA(
136  SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialUse,
137  PLUID pLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
138  PVOID pGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
139 {
140     TRACE("(%s, %s, 0x%08lx, %p, %p, %p, %p, %p, %p)\n",
141      debugstr_a(pszPrincipal), debugstr_a(pszPackage), fCredentialUse,
142      pLogonID, pAuthData, pGetKeyFn, pGetKeyArgument, phCredential, ptsExpiry);
143     return schan_AcquireCredentialsHandle(fCredentialUse, phCredential,
144      ptsExpiry);
145 }
146
147 static SECURITY_STATUS SEC_ENTRY schan_AcquireCredentialsHandleW(
148  SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialUse,
149  PLUID pLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
150  PVOID pGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
151 {
152     TRACE("(%s, %s, 0x%08lx, %p, %p, %p, %p, %p, %p)\n",
153      debugstr_w(pszPrincipal), debugstr_w(pszPackage), fCredentialUse,
154      pLogonID, pAuthData, pGetKeyFn, pGetKeyArgument, phCredential, ptsExpiry);
155     return schan_AcquireCredentialsHandle(fCredentialUse, phCredential,
156      ptsExpiry);
157 }
158
159 /***********************************************************************
160  *              InitializeSecurityContextA
161  */
162 static SECURITY_STATUS SEC_ENTRY schan_InitializeSecurityContextA(
163  PCredHandle phCredential, PCtxtHandle phContext, SEC_CHAR *pszTargetName,
164  ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep,
165  PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext,
166  PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
167 {
168     SECURITY_STATUS ret;
169
170     TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
171      debugstr_a(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
172      Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
173     if(phCredential){
174         ret = SEC_E_UNSUPPORTED_FUNCTION;
175     }
176     else
177     {
178         ret = SEC_E_INVALID_HANDLE;
179     }
180     return ret;
181 }
182
183 /***********************************************************************
184  *              InitializeSecurityContextW
185  */
186 static SECURITY_STATUS SEC_ENTRY schan_InitializeSecurityContextW(
187  PCredHandle phCredential, PCtxtHandle phContext, SEC_WCHAR *pszTargetName,
188  ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep,
189  PSecBufferDesc pInput,ULONG Reserved2, PCtxtHandle phNewContext,
190  PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
191 {
192     SECURITY_STATUS ret;
193
194     TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
195      debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
196      Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
197     if (phCredential)
198     {
199         ret = SEC_E_UNSUPPORTED_FUNCTION;
200     }
201     else
202     {
203         ret = SEC_E_INVALID_HANDLE;
204     }
205     return ret;
206 }
207
208 static SecurityFunctionTableA schanTableA = {
209     1,
210     NULL, /* EnumerateSecurityPackagesA */
211     schan_QueryCredentialsAttributesA,
212     schan_AcquireCredentialsHandleA,
213     NULL, /* FreeCredentialsHandle */
214     NULL, /* Reserved2 */
215     schan_InitializeSecurityContextA, 
216     NULL, /* AcceptSecurityContext */
217     NULL, /* CompleteAuthToken */
218     NULL, /* DeleteSecurityContext */
219     NULL, /* ApplyControlToken */
220     NULL, /* QueryContextAttributesA */
221     NULL, /* ImpersonateSecurityContext */
222     NULL, /* RevertSecurityContext */
223     NULL, /* MakeSignature */
224     NULL, /* VerifySignature */
225     FreeContextBuffer,
226     NULL, /* QuerySecurityPackageInfoA */
227     NULL, /* Reserved3 */
228     NULL, /* Reserved4 */
229     NULL, /* ExportSecurityContext */
230     NULL, /* ImportSecurityContextA */
231     NULL, /* AddCredentialsA */
232     NULL, /* Reserved8 */
233     NULL, /* QuerySecurityContextToken */
234     NULL, /* EncryptMessage */
235     NULL, /* DecryptMessage */
236     NULL, /* SetContextAttributesA */
237 };
238
239 static SecurityFunctionTableW schanTableW = {
240     1,
241     NULL, /* EnumerateSecurityPackagesW */
242     schan_QueryCredentialsAttributesW,
243     schan_AcquireCredentialsHandleW,
244     NULL, /* FreeCredentialsHandle */
245     NULL, /* Reserved2 */
246     schan_InitializeSecurityContextW, 
247     NULL, /* AcceptSecurityContext */
248     NULL, /* CompleteAuthToken */
249     NULL, /* DeleteSecurityContext */
250     NULL, /* ApplyControlToken */
251     NULL, /* QueryContextAttributesW */
252     NULL, /* ImpersonateSecurityContext */
253     NULL, /* RevertSecurityContext */
254     NULL, /* MakeSignature */
255     NULL, /* VerifySignature */
256     FreeContextBuffer,
257     NULL, /* QuerySecurityPackageInfoW */
258     NULL, /* Reserved3 */
259     NULL, /* Reserved4 */
260     NULL, /* ExportSecurityContext */
261     NULL, /* ImportSecurityContextW */
262     NULL, /* AddCredentialsW */
263     NULL, /* Reserved8 */
264     NULL, /* QuerySecurityContextToken */
265     NULL, /* EncryptMessage */
266     NULL, /* DecryptMessage */
267     NULL, /* SetContextAttributesW */
268 };
269
270 static const WCHAR schannelComment[] = { 'S','c','h','a','n','n','e','l',' ',
271  'S','e','c','u','r','i','t','y',' ','P','a','c','k','a','g','e',0 };
272
273 void SECUR32_initSchannelSP(void)
274 {
275     SecureProvider *provider = SECUR32_addProvider(&schanTableA, &schanTableW,
276      NULL);
277
278     if (provider)
279     {
280         /* This is what Windows reports.  This shouldn't break any applications
281          * even though the functions are missing, because the wrapper will
282          * return SEC_E_UNSUPPORTED_FUNCTION if our function is NULL.
283          */
284         static const long caps =
285          SECPKG_FLAG_INTEGRITY |
286          SECPKG_FLAG_PRIVACY |
287          SECPKG_FLAG_CONNECTION |
288          SECPKG_FLAG_MULTI_REQUIRED |
289          SECPKG_FLAG_EXTENDED_ERROR |
290          SECPKG_FLAG_IMPERSONATION |
291          SECPKG_FLAG_ACCEPT_WIN32_NAME |
292          SECPKG_FLAG_STREAM;
293         static const short version = 1;
294         static const long maxToken = 16384;
295         SEC_WCHAR *uniSPName = (SEC_WCHAR *)UNISP_NAME_W,
296          *schannel = (SEC_WCHAR *)SCHANNEL_NAME_W;
297
298         const SecPkgInfoW info[] = {
299          { caps, version, UNISP_RPC_ID, maxToken, uniSPName, uniSPName },
300          { caps, version, UNISP_RPC_ID, maxToken, schannel,
301           (SEC_WCHAR *)schannelComment },
302         };
303
304         SECUR32_addPackages(provider, sizeof(info) / sizeof(info[0]), NULL,
305          info);
306     }
307 }