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
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
;
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
);
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);
60 memcpy( ptr
, username
, (len_username
+ 1) * sizeof(WCHAR
) );
62 id
->UserLength
= len_username
;
63 ptr
+= len_username
+ 1;
67 memcpy( ptr
, domainname
, (len_domainname
+ 1) * sizeof(WCHAR
) );
69 id
->DomainLength
= len_domainname
;
70 ptr
+= len_domainname
+ 1;
74 memcpy( ptr
, creds
, (len_password
+ 1) * sizeof(WCHAR
) );
76 id
->PasswordLength
= len_password
;
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
);
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
)
102 if (!src
) return NULL
;
103 if ((dst
= HeapAlloc( GetProcessHeap(), 0, (strlenW( src
) + 1) * sizeof(WCHAR
) )))
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
);
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
);