ReactOS 0.4.17-dev-769-g1500a35
main.c
Go to the documentation of this file.
1/*
2 * Copyright 2016 Hans Leidekker for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include <stdarg.h>
20#include <stdlib.h>
21
22#include "windef.h"
23#include "winbase.h"
24#include "rpc.h"
25#include "sspi.h"
26#include "wincred.h"
27
28#include "wine/debug.h"
29
31
32/***********************************************************************
33 * SspiEncodeStringsAsAuthIdentity (SECUR32.0)
34 */
36 const WCHAR *username, const WCHAR *domainname, const WCHAR *creds,
38{
40 DWORD len_username = 0, len_domainname = 0, len_password = 0, size;
41 WCHAR *ptr;
42
43 FIXME( "%s %s %s %p\n", debugstr_w(username), debugstr_w(domainname),
44 debugstr_w(creds), opaque_id );
45
46 if (!username && !domainname && !creds) return SEC_E_INVALID_TOKEN;
47
48 if (username) len_username = lstrlenW( username );
49 if (domainname) len_domainname = lstrlenW( domainname );
50 if (creds) len_password = lstrlenW( creds );
51
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);
58
59 if (username)
60 {
61 memcpy( ptr, username, (len_username + 1) * sizeof(WCHAR) );
62 id->User = ptr;
63 id->UserLength = len_username;
64 ptr += len_username + 1;
65 }
66 if (domainname)
67 {
68 memcpy( ptr, domainname, (len_domainname + 1) * sizeof(WCHAR) );
69 id->Domain = ptr;
70 id->DomainLength = len_domainname;
71 ptr += len_domainname + 1;
72 }
73 if (creds)
74 {
75 memcpy( ptr, creds, (len_password + 1) * sizeof(WCHAR) );
76 id->Password = ptr;
77 id->PasswordLength = len_password;
78 }
79
80 *opaque_id = id;
81 return SEC_E_OK;
82}
83
84/***********************************************************************
85 * SspiZeroAuthIdentity (SECUR32.0)
86 */
88{
90
91 TRACE( "%p\n", opaque_id );
92
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) );
98}
99
100/***********************************************************************
101 * SspiEncodeAuthIdentityAsStrings (SECUR32.0)
102 */
105 PCWSTR *domainname, PCWSTR *creds )
106{
108
109 FIXME("%p %p %p %p\n", opaque_id, username, domainname, creds);
110
111 *username = wcsdup( id->User );
112 *domainname = wcsdup( id->Domain );
113 *creds = wcsdup( id->Password );
114
115 return SEC_E_OK;
116}
117
118/***********************************************************************
119 * SspiFreeAuthIdentity (SECUR32.0)
120 */
122{
123 TRACE( "%p\n", opaque_id );
124 free( opaque_id );
125}
126
127/***********************************************************************
128 * SspiLocalFree (SECUR32.0)
129 */
131{
132 TRACE( "%p\n", ptr );
133 free( ptr );
134}
135
136/***********************************************************************
137 * SspiPrepareForCredWrite (SECUR32.0)
138 */
141{
143 WCHAR *str, *str2;
145 ULONG len;
146
147 FIXME( "%p %s %p %p %p %p %p\n", opaque_id, debugstr_w(target), type, targetname, username,
148 blob, size );
149
150 if (id->DomainLength)
151 {
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;
158 }
159 else
160 {
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;
165 }
166
167 str2 = target ? wcsdup( target ) : wcsdup( str );
168 if (!str2)
169 {
170 free( str );
172 }
173
174 len = id->PasswordLength * sizeof(WCHAR);
175 if (!(password = malloc( len )))
176 {
177 free( str );
178 free( str2 );
180 }
181 memcpy( password, id->Password, len );
182
184 *username = str;
185 *targetname = str2;
186 *blob = password;
187 *size = len;
188
189 return SEC_E_OK;
190}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: precomp.h:53
static UCHAR password[]
Definition: bcrypt.c:520
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
int id
Definition: main.c:4882
#define lstrlenW
Definition: compat.h:750
static wchar_t * wcsdup(const wchar_t *str)
Definition: string.h:94
#define SEC_ENTRY
Definition: stubs.c:6
SECURITY_STATUS SEC_ENTRY SspiEncodeStringsAsAuthIdentity(const WCHAR *username, const WCHAR *domainname, const WCHAR *creds, PSEC_WINNT_AUTH_IDENTITY_OPAQUE *opaque_id)
Definition: main.c:35
void SEC_ENTRY SspiFreeAuthIdentity(PSEC_WINNT_AUTH_IDENTITY_OPAQUE opaque_id)
Definition: main.c:121
SECURITY_STATUS SEC_ENTRY SspiPrepareForCredWrite(PSEC_WINNT_AUTH_IDENTITY_OPAQUE opaque_id, PCWSTR target, PULONG type, PCWSTR *targetname, PCWSTR *username, PUCHAR *blob, PULONG size)
Definition: main.c:139
void SEC_ENTRY SspiLocalFree(void *ptr)
Definition: main.c:130
SECURITY_STATUS SEC_ENTRY SspiEncodeAuthIdentityAsStrings(PSEC_WINNT_AUTH_IDENTITY_OPAQUE opaque_id, PCWSTR *username, PCWSTR *domainname, PCWSTR *creds)
Definition: main.c:103
void SEC_ENTRY SspiZeroAuthIdentity(PSEC_WINNT_AUTH_IDENTITY_OPAQUE opaque_id)
Definition: main.c:87
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLenum GLsizei len
Definition: glext.h:6722
GLuint id
Definition: glext.h:5910
#define debugstr_w
Definition: kernel32.h:32
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
static WCHAR username[]
Definition: url.c:32
short WCHAR
Definition: pedump.c:58
LONG SECURITY_STATUS
Definition: sspi.h:34
#define calloc
Definition: rosglue.h:14
const WCHAR * str
XML_HIDDEN void xmlParserErrors const char const xmlChar const xmlChar * str2
Definition: parser.h:35
#define memset(x, y, z)
Definition: compat.h:39
#define TRACE(s)
Definition: solgame.cpp:4
Definition: image.c:134
Definition: tools.h:99
uint32_t * PULONG
Definition: typedefs.h:59
const uint16_t * PCWSTR
Definition: typedefs.h:57
unsigned char UCHAR
Definition: typedefs.h:53
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define CRED_TYPE_DOMAIN_PASSWORD
Definition: wincred.h:205
#define SEC_E_OK
Definition: winerror.h:3450
#define SEC_E_INVALID_TOKEN
Definition: winerror.h:4314
#define SEC_E_INSUFFICIENT_MEMORY
Definition: winerror.h:4306