ReactOS 0.4.15-dev-8222-g9164419
pwcache.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
#include "winnetwk.h"
#include "winreg.h"
#include "wine/debug.h"
Include dependency graph for pwcache.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (mpr)
 
static BYTE hex (BYTE x)
 
static signed char ctox (CHAR x)
 
static LPSTR MPR_GetValueName (LPCSTR pbResource, WORD cbResource, BYTE nType)
 
DWORD WINAPI WNetCachePassword (LPSTR pbResource, WORD cbResource, LPSTR pbPassword, WORD cbPassword, BYTE nType, WORD x)
 
UINT WINAPI WNetRemoveCachedPassword (LPSTR pbResource, WORD cbResource, BYTE nType)
 
DWORD WINAPI WNetGetCachedPassword (LPSTR pbResource, WORD cbResource, LPSTR pbPassword, LPWORD pcbPassword, BYTE nType)
 
UINT WINAPI WNetEnumCachedPasswords (LPSTR pbPrefix, WORD cbPrefix, BYTE nType, ENUMPASSWORDPROC enumPasswordProc, DWORD param)
 

Variables

static const char mpr_key [] = "Software\\Wine\\Wine\\Mpr\\"
 

Function Documentation

◆ ctox()

static signed char ctox ( CHAR  x)
inlinestatic

Definition at line 42 of file pwcache.c.

43{
44 if( ( x >= '0' ) && ( x <= '9' ) )
45 return x - '0';
46 if( ( x >= 'A' ) && ( x <= 'F' ) )
47 return x - 'A' + 10;
48 if( ( x >= 'a' ) && ( x <= 'f' ) )
49 return x - 'a' + 10;
50 return -1;
51}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548

Referenced by WNetEnumCachedPasswords().

◆ hex()

static BYTE hex ( BYTE  x)
inlinestatic

Definition at line 35 of file pwcache.c.

36{
37 if( x <= 9 )
38 return x + '0';
39 return x + 'A' - 10;
40}

Referenced by hex(), and MPR_GetValueName().

◆ MPR_GetValueName()

static LPSTR MPR_GetValueName ( LPCSTR  pbResource,
WORD  cbResource,
BYTE  nType 
)
static

Definition at line 53 of file pwcache.c.

54{
55 LPSTR name;
56 DWORD i;
57
58 name = HeapAlloc( GetProcessHeap(), 0, 6+cbResource*2 );
59 if( !name ) return NULL;
60
61 sprintf( name, "X-%02X-", nType );
62 for(i=0; i<cbResource; i++)
63 {
64 name[5+i*2]=hex((pbResource[i]&0xf0)>>4);
65 name[6+i*2]=hex(pbResource[i]&0x0f);
66 }
67 name[5+i*2]=0;
68 TRACE( "Value is %s\n", name );
69 return name;
70}
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static BYTE hex(BYTE x)
Definition: pwcache.c:35
#define TRACE(s)
Definition: solgame.cpp:4
Definition: name.c:39
char * LPSTR
Definition: xmlstorage.h:182

Referenced by WNetCachePassword(), WNetGetCachedPassword(), and WNetRemoveCachedPassword().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( mpr  )

◆ WNetCachePassword()

DWORD WINAPI WNetCachePassword ( LPSTR  pbResource,
WORD  cbResource,
LPSTR  pbPassword,
WORD  cbPassword,
BYTE  nType,
WORD  x 
)

Definition at line 85 of file pwcache.c.

93{
94 HKEY hkey;
95 DWORD r;
96 LPSTR valname;
97
98 WARN( "(%p(%s), %d, %p(%s), %d, %d, 0x%08x): totally insecure\n",
99 pbResource, debugstr_a(pbResource), cbResource,
100 pbPassword, debugstr_a(pbPassword), cbPassword,
101 nType, x );
102
103 /* @@ Wine registry key: HKCU\Software\Wine\Wine\Mpr */
105 if( r )
106 return WN_ACCESS_DENIED;
107
108 valname = MPR_GetValueName( pbResource, cbResource, nType );
109 if( valname )
110 {
111 r = RegSetValueExA( hkey, valname, 0, REG_BINARY,
112 (LPBYTE)pbPassword, cbPassword );
113 if( r )
114 r = WN_CANCEL;
115 else
116 r = WN_SUCCESS;
117 HeapFree( GetProcessHeap(), 0, valname );
118 }
119 else
121
122 RegCloseKey( hkey );
123
124 return r;
125}
#define WARN(fmt,...)
Definition: debug.h:115
#define RegCloseKey(hKey)
Definition: registry.h:49
LONG WINAPI RegCreateKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1179
LONG WINAPI RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE *lpData, DWORD cbData)
Definition: reg.c:4799
#define HeapFree(x, y, z)
Definition: compat.h:735
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define debugstr_a
Definition: kernel32.h:31
#define REG_BINARY
Definition: nt_native.h:1496
static LPSTR MPR_GetValueName(LPCSTR pbResource, WORD cbResource, BYTE nType)
Definition: pwcache.c:53
static const char mpr_key[]
Definition: pwcache.c:33
unsigned char * LPBYTE
Definition: typedefs.h:53
#define WN_CANCEL
Definition: winnetwk.h:114
#define WN_OUT_OF_MEMORY
Definition: winnetwk.h:125
#define WN_SUCCESS
Definition: winnetwk.h:111
#define WN_ACCESS_DENIED
Definition: winnetwk.h:122
#define HKEY_CURRENT_USER
Definition: winreg.h:11

Referenced by InitFunctionPtrs(), and WININET_GetSetPassword().

◆ WNetEnumCachedPasswords()

UINT WINAPI WNetEnumCachedPasswords ( LPSTR  pbPrefix,
WORD  cbPrefix,
BYTE  nType,
ENUMPASSWORDPROC  enumPasswordProc,
DWORD  param 
)

Definition at line 240 of file pwcache.c.

246{
247 HKEY hkey;
248 DWORD r, type, val_sz, data_sz, i, j, size;
249 PASSWORD_CACHE_ENTRY *entry;
250 CHAR val[256], prefix[6];
251
252 WARN( "(%s, %d, %d, %p, 0x%08x) totally insecure\n",
253 debugstr_an(pbPrefix,cbPrefix), cbPrefix,
254 nType, enumPasswordProc, param );
255
256 /* @@ Wine registry key: HKCU\Software\Wine\Wine\Mpr */
258 if( r )
259 return WN_ACCESS_DENIED;
260
261 sprintf(prefix, "X-%02X-", nType );
262
263 for( i=0; ; i++ )
264 {
265 val_sz = sizeof val;
266 data_sz = 0;
267 type = 0;
268 val[0] = 0;
269 r = RegEnumValueA( hkey, i, val, &val_sz, NULL, &type, NULL, &data_sz );
270 if( r != ERROR_SUCCESS )
271 break;
272 if( type != REG_BINARY )
273 continue;
274
275 /* check the value is in the format we expect */
276 if( val_sz < sizeof prefix )
277 continue;
278 if( memcmp( prefix, val, 5 ) )
279 continue;
280
281 /* decode the value */
282 for(j=5; j<val_sz; j+=2 )
283 {
284 signed char hi = ctox( val[j] ), lo = ctox( val[j+1] );
285 if( ( hi < 0 ) || ( lo < 0 ) )
286 break;
287 val[(j-5)/2] = (hi<<4) | lo;
288 }
289
290 /* find the decoded length */
291 val_sz = (j - 5)/2;
292 val[val_sz]=0;
293 if( val_sz < cbPrefix )
294 continue;
295
296 /* check the prefix matches */
297 if( memcmp(val, pbPrefix, cbPrefix) )
298 continue;
299
300 /* read the value data */
301 size = offsetof( PASSWORD_CACHE_ENTRY, abResource[val_sz + data_sz] );
303 memcpy( entry->abResource, val, val_sz );
304 entry->cbEntry = size;
305 entry->cbResource = val_sz;
306 entry->cbPassword = data_sz;
307 entry->iEntry = i;
308 entry->nType = nType;
309 size = sizeof val;
310 r = RegEnumValueA( hkey, i, val, &size, NULL, &type,
311 &entry->abResource[val_sz], &data_sz );
312 if( r == ERROR_SUCCESS )
313 enumPasswordProc( entry, param );
315 }
316
317 RegCloseKey( hkey );
318
319 return WN_SUCCESS;
320}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegEnumValueA(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpdwReserved, _Out_opt_ LPDWORD lpdwType, _Out_opt_ LPBYTE lpData, _Inout_opt_ LPDWORD lpcbData)
Definition: reg.c:2668
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:55
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLuint GLfloat * val
Definition: glext.h:7180
GLfloat param
Definition: glext.h:5796
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
uint32_t entry
Definition: isohybrid.c:63
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static signed char ctox(CHAR x)
Definition: pwcache.c:42
#define offsetof(TYPE, MEMBER)
char CHAR
Definition: xmlstorage.h:175

Referenced by InitFunctionPtrs().

◆ WNetGetCachedPassword()

DWORD WINAPI WNetGetCachedPassword ( LPSTR  pbResource,
WORD  cbResource,
LPSTR  pbPassword,
LPWORD  pcbPassword,
BYTE  nType 
)

Definition at line 180 of file pwcache.c.

186{
187 HKEY hkey;
188 DWORD r, type = 0, sz;
189 LPSTR valname;
190
191 WARN( "(%p(%s), %d, %p, %p, %d): totally insecure\n",
192 pbResource, debugstr_a(pbResource), cbResource,
193 pbPassword, pcbPassword, nType );
194
195 memset( pbPassword, 0, *pcbPassword);
196
197 /* @@ Wine registry key: HKCU\Software\Wine\Wine\Mpr */
199 if( r )
200 return WN_ACCESS_DENIED;
201
202 valname = MPR_GetValueName( pbResource, cbResource, nType );
203 if( valname )
204 {
205 sz = *pcbPassword;
206 r = RegQueryValueExA( hkey, valname, 0, &type, (LPBYTE)pbPassword, &sz );
207 *pcbPassword = sz;
208 if( r )
209 r = WN_CANCEL;
210 else
211 r = WN_SUCCESS;
212 HeapFree( GetProcessHeap(), 0, valname );
213 }
214 else
216
217 return r;
218}
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4009
#define memset(x, y, z)
Definition: compat.h:39

Referenced by InitFunctionPtrs(), and WININET_GetSetPassword().

◆ WNetRemoveCachedPassword()

UINT WINAPI WNetRemoveCachedPassword ( LPSTR  pbResource,
WORD  cbResource,
BYTE  nType 
)

Definition at line 130 of file pwcache.c.

134{
135 HKEY hkey;
136 DWORD r;
137 LPSTR valname;
138
139 WARN( "(%p(%s), %d, %d): totally insecure\n",
140 pbResource, debugstr_a(pbResource), cbResource, nType );
141
142 /* @@ Wine registry key: HKCU\Software\Wine\Wine\Mpr */
144 if( r )
145 return WN_ACCESS_DENIED;
146
147 valname = MPR_GetValueName( pbResource, cbResource, nType );
148 if( valname )
149 {
150 r = RegDeleteValueA( hkey, valname );
151 if( r )
153 else
154 r = WN_SUCCESS;
155 HeapFree( GetProcessHeap(), 0, valname );
156 }
157 else
159
160 return r;
161}
LONG WINAPI RegDeleteValueA(HKEY hKey, LPCSTR lpValueName)
Definition: reg.c:2287

Referenced by InitFunctionPtrs().

Variable Documentation

◆ mpr_key

const char mpr_key[] = "Software\\Wine\\Wine\\Mpr\\"
static