msi/tests: Drop workarounds for Windows 2000.
[wine.git] / dlls / sspicli / main.c
blobdfcc1cc02fb396eca4a1b97979c8c97ac0664642
1 /*
2 * Copyright 2016 Hans Leidekker for CodeWeavers
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
19 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "rpc.h"
24 #include "sspi.h"
25 #include "wincred.h"
27 #include "wine/debug.h"
28 #include "wine/unicode.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(sspicli);
32 /***********************************************************************
33 * SspiEncodeStringsAsAuthIdentity (SECUR32.0)
35 SECURITY_STATUS SEC_ENTRY SspiEncodeStringsAsAuthIdentity(
36 const WCHAR *username, const WCHAR *domainname, const WCHAR *creds,
37 PSEC_WINNT_AUTH_IDENTITY_OPAQUE *opaque_id )
39 SEC_WINNT_AUTH_IDENTITY_W *id;
40 DWORD len_username = 0, len_domainname = 0, len_password = 0, size;
41 WCHAR *ptr;
43 FIXME( "%s %s %s %p\n", debugstr_w(username), debugstr_w(domainname),
44 debugstr_w(creds), opaque_id );
46 if (!username && !domainname && !creds) return SEC_E_INVALID_TOKEN;
48 if (username) len_username = strlenW( username );
49 if (domainname) len_domainname = strlenW( domainname );
50 if (creds) len_password = strlenW( creds );
52 size = sizeof(*id);
53 if (username) size += (len_username + 1) * sizeof(WCHAR);
54 if (domainname) size += (len_domainname + 1) * sizeof(WCHAR);
55 if (creds) size += (len_password + 1) * sizeof(WCHAR);
56 if (!(id = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size ))) return ERROR_OUTOFMEMORY;
57 ptr = (WCHAR *)(id + 1);
59 if (username)
61 memcpy( ptr, username, (len_username + 1) * sizeof(WCHAR) );
62 id->User = ptr;
63 id->UserLength = len_username;
64 ptr += len_username + 1;
66 if (domainname)
68 memcpy( ptr, domainname, (len_domainname + 1) * sizeof(WCHAR) );
69 id->Domain = ptr;
70 id->DomainLength = len_domainname;
71 ptr += len_domainname + 1;
73 if (creds)
75 memcpy( ptr, creds, (len_password + 1) * sizeof(WCHAR) );
76 id->Password = ptr;
77 id->PasswordLength = len_password;
80 *opaque_id = id;
81 return SEC_E_OK;
84 /***********************************************************************
85 * SspiZeroAuthIdentity (SECUR32.0)
87 void SEC_ENTRY SspiZeroAuthIdentity( PSEC_WINNT_AUTH_IDENTITY_OPAQUE opaque_id )
89 SEC_WINNT_AUTH_IDENTITY_W *id = (SEC_WINNT_AUTH_IDENTITY_W *)opaque_id;
91 TRACE( "%p\n", opaque_id );
93 if (!id) return;
94 if (id->User) memset( id->User, 0, id->UserLength * sizeof(WCHAR) );
95 if (id->Domain) memset( id->Domain, 0, id->DomainLength * sizeof(WCHAR) );
96 if (id->Password) memset( id->Password, 0, id->PasswordLength * sizeof(WCHAR) );
97 memset( id, 0, sizeof(*id) );
100 static inline WCHAR *strdupW( const WCHAR *src )
102 WCHAR *dst;
103 if (!src) return NULL;
104 if ((dst = HeapAlloc( GetProcessHeap(), 0, (strlenW( src ) + 1) * sizeof(WCHAR) )))
105 strcpyW( dst, src );
106 return dst;
109 /***********************************************************************
110 * SspiEncodeAuthIdentityAsStrings (SECUR32.0)
112 SECURITY_STATUS SEC_ENTRY SspiEncodeAuthIdentityAsStrings(
113 PSEC_WINNT_AUTH_IDENTITY_OPAQUE opaque_id, PCWSTR *username,
114 PCWSTR *domainname, PCWSTR *creds )
116 SEC_WINNT_AUTH_IDENTITY_W *id = (SEC_WINNT_AUTH_IDENTITY_W *)opaque_id;
118 FIXME("%p %p %p %p\n", opaque_id, username, domainname, creds);
120 *username = strdupW( id->User );
121 *domainname = strdupW( id->Domain );
122 *creds = strdupW( id->Password );
124 return SEC_E_OK;
127 /***********************************************************************
128 * SspiFreeAuthIdentity (SECUR32.0)
130 void SEC_ENTRY SspiFreeAuthIdentity( PSEC_WINNT_AUTH_IDENTITY_OPAQUE opaque_id )
132 TRACE( "%p\n", opaque_id );
133 HeapFree( GetProcessHeap(), 0, opaque_id );
136 /***********************************************************************
137 * SspiLocalFree (SECUR32.0)
139 void SEC_ENTRY SspiLocalFree( void *ptr )
141 TRACE( "%p\n", ptr );
142 HeapFree( GetProcessHeap(), 0, ptr );
145 /***********************************************************************
146 * SspiPrepareForCredWrite (SECUR32.0)
148 SECURITY_STATUS SEC_ENTRY SspiPrepareForCredWrite( PSEC_WINNT_AUTH_IDENTITY_OPAQUE opaque_id,
149 PCWSTR target, PULONG type, PCWSTR *targetname, PCWSTR *username, PUCHAR *blob, PULONG size )
151 SEC_WINNT_AUTH_IDENTITY_W *id = (SEC_WINNT_AUTH_IDENTITY_W *)opaque_id;
152 WCHAR *str, *str2;
153 UCHAR *password;
154 ULONG len;
156 FIXME( "%p %s %p %p %p %p %p\n", opaque_id, debugstr_w(target), type, targetname, username,
157 blob, size );
159 if (id->DomainLength)
161 len = (id->DomainLength + id->UserLength + 2) * sizeof(WCHAR);
162 if (!(str = HeapAlloc(GetProcessHeap(), 0 , len ))) return SEC_E_INSUFFICIENT_MEMORY;
163 memcpy( str, id->Domain, id->DomainLength * sizeof(WCHAR) );
164 str[id->DomainLength] = '\\';
165 memcpy( str + id->DomainLength + 1, id->User, id->UserLength * sizeof(WCHAR) );
166 str[id->DomainLength + 1 + id->UserLength] = 0;
168 else
170 len = (id->UserLength + 1) * sizeof(WCHAR);
171 if (!(str = HeapAlloc(GetProcessHeap(), 0 , len ))) return SEC_E_INSUFFICIENT_MEMORY;
172 memcpy( str, id->User, id->UserLength * sizeof(WCHAR) );
173 str[id->UserLength] = 0;
176 str2 = target ? strdupW( target ) : strdupW( str );
177 if (!str2)
179 HeapFree( GetProcessHeap(), 0, str );
180 return SEC_E_INSUFFICIENT_MEMORY;
183 len = id->PasswordLength * sizeof(WCHAR);
184 if (!(password = HeapAlloc(GetProcessHeap(), 0 , len )))
186 HeapFree( GetProcessHeap(), 0, str );
187 HeapFree( GetProcessHeap(), 0, str2 );
188 return SEC_E_INSUFFICIENT_MEMORY;
190 memcpy( password, id->Password, len );
192 *type = CRED_TYPE_DOMAIN_PASSWORD;
193 *username = str;
194 *targetname = str2;
195 *blob = password;
196 *size = len;
198 return SEC_E_OK;