user32: Remove _wassert workaround.
[wine.git] / dlls / sspicli / main.c
blob186a6acd65b16673653c2924ca8fc868975d4208
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"
29 WINE_DEFAULT_DEBUG_CHANNEL(sspicli);
31 /***********************************************************************
32 * SspiEncodeStringsAsAuthIdentity (SECUR32.0)
34 SECURITY_STATUS SEC_ENTRY SspiEncodeStringsAsAuthIdentity(
35 const WCHAR *username, const WCHAR *domainname, const WCHAR *creds,
36 PSEC_WINNT_AUTH_IDENTITY_OPAQUE *opaque_id )
38 SEC_WINNT_AUTH_IDENTITY_W *id;
39 DWORD len_username = 0, len_domainname = 0, len_password = 0, size;
40 WCHAR *ptr;
42 FIXME( "%s %s %s %p\n", debugstr_w(username), debugstr_w(domainname),
43 debugstr_w(creds), opaque_id );
45 if (!username && !domainname && !creds) return SEC_E_INVALID_TOKEN;
47 if (username) len_username = lstrlenW( username );
48 if (domainname) len_domainname = lstrlenW( domainname );
49 if (creds) len_password = lstrlenW( creds );
51 size = sizeof(*id);
52 if (username) size += (len_username + 1) * sizeof(WCHAR);
53 if (domainname) size += (len_domainname + 1) * sizeof(WCHAR);
54 if (creds) size += (len_password + 1) * sizeof(WCHAR);
55 if (!(id = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size ))) return ERROR_OUTOFMEMORY;
56 ptr = (WCHAR *)(id + 1);
58 if (username)
60 memcpy( ptr, username, (len_username + 1) * sizeof(WCHAR) );
61 id->User = ptr;
62 id->UserLength = len_username;
63 ptr += len_username + 1;
65 if (domainname)
67 memcpy( ptr, domainname, (len_domainname + 1) * sizeof(WCHAR) );
68 id->Domain = ptr;
69 id->DomainLength = len_domainname;
70 ptr += len_domainname + 1;
72 if (creds)
74 memcpy( ptr, creds, (len_password + 1) * sizeof(WCHAR) );
75 id->Password = ptr;
76 id->PasswordLength = len_password;
79 *opaque_id = id;
80 return SEC_E_OK;
83 /***********************************************************************
84 * SspiZeroAuthIdentity (SECUR32.0)
86 void SEC_ENTRY SspiZeroAuthIdentity( PSEC_WINNT_AUTH_IDENTITY_OPAQUE opaque_id )
88 SEC_WINNT_AUTH_IDENTITY_W *id = (SEC_WINNT_AUTH_IDENTITY_W *)opaque_id;
90 TRACE( "%p\n", opaque_id );
92 if (!id) return;
93 if (id->User) memset( id->User, 0, id->UserLength * sizeof(WCHAR) );
94 if (id->Domain) memset( id->Domain, 0, id->DomainLength * sizeof(WCHAR) );
95 if (id->Password) memset( id->Password, 0, id->PasswordLength * sizeof(WCHAR) );
96 memset( id, 0, sizeof(*id) );
99 static inline WCHAR *strdupW( const WCHAR *src )
101 WCHAR *dst;
102 if (!src) return NULL;
103 if ((dst = HeapAlloc( GetProcessHeap(), 0, (lstrlenW( src ) + 1) * sizeof(WCHAR) )))
104 lstrcpyW( dst, src );
105 return dst;
108 /***********************************************************************
109 * SspiEncodeAuthIdentityAsStrings (SECUR32.0)
111 SECURITY_STATUS SEC_ENTRY SspiEncodeAuthIdentityAsStrings(
112 PSEC_WINNT_AUTH_IDENTITY_OPAQUE opaque_id, PCWSTR *username,
113 PCWSTR *domainname, PCWSTR *creds )
115 SEC_WINNT_AUTH_IDENTITY_W *id = (SEC_WINNT_AUTH_IDENTITY_W *)opaque_id;
117 FIXME("%p %p %p %p\n", opaque_id, username, domainname, creds);
119 *username = strdupW( id->User );
120 *domainname = strdupW( id->Domain );
121 *creds = strdupW( id->Password );
123 return SEC_E_OK;
126 /***********************************************************************
127 * SspiFreeAuthIdentity (SECUR32.0)
129 void SEC_ENTRY SspiFreeAuthIdentity( PSEC_WINNT_AUTH_IDENTITY_OPAQUE opaque_id )
131 TRACE( "%p\n", opaque_id );
132 HeapFree( GetProcessHeap(), 0, opaque_id );
135 /***********************************************************************
136 * SspiLocalFree (SECUR32.0)
138 void SEC_ENTRY SspiLocalFree( void *ptr )
140 TRACE( "%p\n", ptr );
141 HeapFree( GetProcessHeap(), 0, ptr );
144 /***********************************************************************
145 * SspiPrepareForCredWrite (SECUR32.0)
147 SECURITY_STATUS SEC_ENTRY SspiPrepareForCredWrite( PSEC_WINNT_AUTH_IDENTITY_OPAQUE opaque_id,
148 PCWSTR target, PULONG type, PCWSTR *targetname, PCWSTR *username, PUCHAR *blob, PULONG size )
150 SEC_WINNT_AUTH_IDENTITY_W *id = (SEC_WINNT_AUTH_IDENTITY_W *)opaque_id;
151 WCHAR *str, *str2;
152 UCHAR *password;
153 ULONG len;
155 FIXME( "%p %s %p %p %p %p %p\n", opaque_id, debugstr_w(target), type, targetname, username,
156 blob, size );
158 if (id->DomainLength)
160 len = (id->DomainLength + id->UserLength + 2) * sizeof(WCHAR);
161 if (!(str = HeapAlloc(GetProcessHeap(), 0 , len ))) return SEC_E_INSUFFICIENT_MEMORY;
162 memcpy( str, id->Domain, id->DomainLength * sizeof(WCHAR) );
163 str[id->DomainLength] = '\\';
164 memcpy( str + id->DomainLength + 1, id->User, id->UserLength * sizeof(WCHAR) );
165 str[id->DomainLength + 1 + id->UserLength] = 0;
167 else
169 len = (id->UserLength + 1) * sizeof(WCHAR);
170 if (!(str = HeapAlloc(GetProcessHeap(), 0 , len ))) return SEC_E_INSUFFICIENT_MEMORY;
171 memcpy( str, id->User, id->UserLength * sizeof(WCHAR) );
172 str[id->UserLength] = 0;
175 str2 = target ? strdupW( target ) : strdupW( str );
176 if (!str2)
178 HeapFree( GetProcessHeap(), 0, str );
179 return SEC_E_INSUFFICIENT_MEMORY;
182 len = id->PasswordLength * sizeof(WCHAR);
183 if (!(password = HeapAlloc(GetProcessHeap(), 0 , len )))
185 HeapFree( GetProcessHeap(), 0, str );
186 HeapFree( GetProcessHeap(), 0, str2 );
187 return SEC_E_INSUFFICIENT_MEMORY;
189 memcpy( password, id->Password, len );
191 *type = CRED_TYPE_DOMAIN_PASSWORD;
192 *username = str;
193 *targetname = str2;
194 *blob = password;
195 *size = len;
197 return SEC_E_OK;