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
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
;
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
);
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);
61 memcpy( ptr
, username
, (len_username
+ 1) * sizeof(WCHAR
) );
63 id
->UserLength
= len_username
;
64 ptr
+= len_username
+ 1;
68 memcpy( ptr
, domainname
, (len_domainname
+ 1) * sizeof(WCHAR
) );
70 id
->DomainLength
= len_domainname
;
71 ptr
+= len_domainname
+ 1;
75 memcpy( ptr
, creds
, (len_password
+ 1) * sizeof(WCHAR
) );
77 id
->PasswordLength
= len_password
;
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
);
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
)
103 if (!src
) return NULL
;
104 if ((dst
= HeapAlloc( GetProcessHeap(), 0, (strlenW( src
) + 1) * sizeof(WCHAR
) )))
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
);
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
;
156 FIXME( "%p %s %p %p %p %p %p\n", opaque_id
, debugstr_w(target
), type
, targetname
, username
,
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;
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
);
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
;