winewayland.drv: Update desktop window size on display changes.
[wine.git] / dlls / sspicli / main.c
blob2190fc5956a27faf2295ea45c20f4b4b93b144fc
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>
20 #include <stdlib.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "rpc.h"
25 #include "sspi.h"
26 #include "wincred.h"
28 #include "wine/debug.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 = lstrlenW( username );
49 if (domainname) len_domainname = lstrlenW( domainname );
50 if (creds) len_password = lstrlenW( 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 = calloc( 1, 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 /***********************************************************************
101 * SspiEncodeAuthIdentityAsStrings (SECUR32.0)
103 SECURITY_STATUS SEC_ENTRY SspiEncodeAuthIdentityAsStrings(
104 PSEC_WINNT_AUTH_IDENTITY_OPAQUE opaque_id, PCWSTR *username,
105 PCWSTR *domainname, PCWSTR *creds )
107 SEC_WINNT_AUTH_IDENTITY_W *id = (SEC_WINNT_AUTH_IDENTITY_W *)opaque_id;
109 FIXME("%p %p %p %p\n", opaque_id, username, domainname, creds);
111 *username = wcsdup( id->User );
112 *domainname = wcsdup( id->Domain );
113 *creds = wcsdup( id->Password );
115 return SEC_E_OK;
118 /***********************************************************************
119 * SspiFreeAuthIdentity (SECUR32.0)
121 void SEC_ENTRY SspiFreeAuthIdentity( PSEC_WINNT_AUTH_IDENTITY_OPAQUE opaque_id )
123 TRACE( "%p\n", opaque_id );
124 free( opaque_id );
127 /***********************************************************************
128 * SspiLocalFree (SECUR32.0)
130 void SEC_ENTRY SspiLocalFree( void *ptr )
132 TRACE( "%p\n", ptr );
133 free( ptr );
136 /***********************************************************************
137 * SspiPrepareForCredWrite (SECUR32.0)
139 SECURITY_STATUS SEC_ENTRY SspiPrepareForCredWrite( PSEC_WINNT_AUTH_IDENTITY_OPAQUE opaque_id,
140 PCWSTR target, PULONG type, PCWSTR *targetname, PCWSTR *username, PUCHAR *blob, PULONG size )
142 SEC_WINNT_AUTH_IDENTITY_W *id = (SEC_WINNT_AUTH_IDENTITY_W *)opaque_id;
143 WCHAR *str, *str2;
144 UCHAR *password;
145 ULONG len;
147 FIXME( "%p %s %p %p %p %p %p\n", opaque_id, debugstr_w(target), type, targetname, username,
148 blob, size );
150 if (id->DomainLength)
152 len = (id->DomainLength + id->UserLength + 2) * sizeof(WCHAR);
153 if (!(str = malloc( len ))) return SEC_E_INSUFFICIENT_MEMORY;
154 memcpy( str, id->Domain, id->DomainLength * sizeof(WCHAR) );
155 str[id->DomainLength] = '\\';
156 memcpy( str + id->DomainLength + 1, id->User, id->UserLength * sizeof(WCHAR) );
157 str[id->DomainLength + 1 + id->UserLength] = 0;
159 else
161 len = (id->UserLength + 1) * sizeof(WCHAR);
162 if (!(str = malloc( len ))) return SEC_E_INSUFFICIENT_MEMORY;
163 memcpy( str, id->User, id->UserLength * sizeof(WCHAR) );
164 str[id->UserLength] = 0;
167 str2 = target ? wcsdup( target ) : wcsdup( str );
168 if (!str2)
170 free( str );
171 return SEC_E_INSUFFICIENT_MEMORY;
174 len = id->PasswordLength * sizeof(WCHAR);
175 if (!(password = malloc( len )))
177 free( str );
178 free( str2 );
179 return SEC_E_INSUFFICIENT_MEMORY;
181 memcpy( password, id->Password, len );
183 *type = CRED_TYPE_DOMAIN_PASSWORD;
184 *username = str;
185 *targetname = str2;
186 *blob = password;
187 *size = len;
189 return SEC_E_OK;