secur32/tests: Use importlib for functions available since Windows XP.
[wine.git] / dlls / sspicli / main.c
blob34f0a643745ed6692e8b465ddbfc405acdb60aa5
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"
26 #include "wine/debug.h"
27 #include "wine/unicode.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 = strlenW( username );
48 if (domainname) len_domainname = strlenW( domainname );
49 if (creds) len_password = strlenW( 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, (strlenW( src ) + 1) * sizeof(WCHAR) )))
104 strcpyW( 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 );