ReactOS  0.4.14-dev-384-g5b37caa
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 <= 'a' ) )
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 }
GLint GLint GLint GLint GLint x
Definition: gl.h:1548

Referenced by 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 }
char * LPSTR
Definition: xmlstorage.h:182
#define sprintf(buf, format,...)
Definition: sprintf.c:55
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
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
static BYTE hex(BYTE x)
Definition: pwcache.c:35
Definition: name.c:36
GLuint const GLchar * name
Definition: glext.h:6031

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 WN_SUCCESS
Definition: winnetwk.h:111
#define REG_BINARY
Definition: nt_native.h:1496
static LPSTR MPR_GetValueName(LPCSTR pbResource, WORD cbResource, BYTE nType)
Definition: pwcache.c:53
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define WARN(fmt,...)
Definition: debug.h:111
#define WN_CANCEL
Definition: winnetwk.h:114
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
char * LPSTR
Definition: xmlstorage.h:182
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
LONG WINAPI RegCreateKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1177
#define GetProcessHeap()
Definition: compat.h:403
#define debugstr_a
Definition: kernel32.h:31
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WN_ACCESS_DENIED
Definition: winnetwk.h:122
#define WN_OUT_OF_MEMORY
Definition: winnetwk.h:125
static const char mpr_key[]
Definition: pwcache.c:33
LONG WINAPI RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE *lpData, DWORD cbData)
Definition: reg.c:4812
#define HeapFree(x, y, z)
Definition: compat.h:402

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] );
302  entry = HeapAlloc( GetProcessHeap(), 0, size );
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 );
314  HeapFree( GetProcessHeap(), 0, entry );
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
#define WN_SUCCESS
Definition: winnetwk.h:111
#define REG_BINARY
Definition: nt_native.h:1496
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define HKEY_CURRENT_USER
Definition: winreg.h:11
char CHAR
Definition: xmlstorage.h:175
#define WARN(fmt,...)
Definition: debug.h:111
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
static signed char ctox(CHAR x)
Definition: pwcache.c:42
#define sprintf(buf, format,...)
Definition: sprintf.c:55
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
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
#define offsetof(TYPE, MEMBER)
LONG WINAPI RegCreateKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1177
GLuint GLfloat * val
Definition: glext.h:7180
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
GLsizeiptr size
Definition: glext.h:5919
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:2691
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
GLfloat param
Definition: glext.h:5796
unsigned long DWORD
Definition: ntddk_ex.h:95
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:47
uint32_t entry
Definition: isohybrid.c:63
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define WN_ACCESS_DENIED
Definition: winnetwk.h:122
static const char mpr_key[]
Definition: pwcache.c:33
#define HeapFree(x, y, z)
Definition: compat.h:402

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:4023
#define WN_SUCCESS
Definition: winnetwk.h:111
static LPSTR MPR_GetValueName(LPCSTR pbResource, WORD cbResource, BYTE nType)
Definition: pwcache.c:53
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define WARN(fmt,...)
Definition: debug.h:111
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define WN_CANCEL
Definition: winnetwk.h:114
char * LPSTR
Definition: xmlstorage.h:182
unsigned char * LPBYTE
Definition: typedefs.h:52
LONG WINAPI RegCreateKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1177
#define GetProcessHeap()
Definition: compat.h:403
#define debugstr_a
Definition: kernel32.h:31
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WN_ACCESS_DENIED
Definition: winnetwk.h:122
#define WN_OUT_OF_MEMORY
Definition: winnetwk.h:125
static const char mpr_key[]
Definition: pwcache.c:33
#define memset(x, y, z)
Definition: compat.h:39
#define HeapFree(x, y, z)
Definition: compat.h:402

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 }
#define WN_SUCCESS
Definition: winnetwk.h:111
static LPSTR MPR_GetValueName(LPCSTR pbResource, WORD cbResource, BYTE nType)
Definition: pwcache.c:53
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define WARN(fmt,...)
Definition: debug.h:111
char * LPSTR
Definition: xmlstorage.h:182
LONG WINAPI RegCreateKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1177
#define GetProcessHeap()
Definition: compat.h:403
#define debugstr_a
Definition: kernel32.h:31
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WN_ACCESS_DENIED
Definition: winnetwk.h:122
LONG WINAPI RegDeleteValueA(HKEY hKey, LPCSTR lpValueName)
Definition: reg.c:2319
#define WN_OUT_OF_MEMORY
Definition: winnetwk.h:125
static const char mpr_key[]
Definition: pwcache.c:33
#define HeapFree(x, y, z)
Definition: compat.h:402

Referenced by InitFunctionPtrs().

Variable Documentation

◆ mpr_key

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