1999-08-07 16:32:33 +02:00
|
|
|
/*
|
|
|
|
* MPR Password Cache functions
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* Copyright 1999 Ulrich Weigand
|
2003-07-19 00:59:07 +02:00
|
|
|
* Copyright 2003 Mike McCormack for Codeweavers
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1999-08-07 16:32:33 +02:00
|
|
|
*/
|
|
|
|
|
2003-07-19 00:59:07 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
1999-08-07 16:32:33 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnetwk.h"
|
2003-07-19 00:59:07 +02:00
|
|
|
#include "winreg.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-08-07 16:32:33 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mpr);
|
1999-08-07 16:32:33 +02:00
|
|
|
|
2003-07-19 00:59:07 +02:00
|
|
|
static const char mpr_key[] = "Software\\Wine\\Wine\\Mpr\\";
|
|
|
|
|
|
|
|
static LPSTR MPR_GetValueName( LPSTR pbResource, WORD cbResource, BYTE nType )
|
|
|
|
{
|
|
|
|
LPSTR name;
|
|
|
|
DWORD i, x = 0;
|
|
|
|
|
|
|
|
/* just a hash so the value name doesn't get too large */
|
|
|
|
for( i=0; i<cbResource; i++ )
|
|
|
|
x = ((x<<7) | (x >> 25)) ^ toupper(pbResource[i]);
|
|
|
|
|
|
|
|
name = HeapAlloc( GetProcessHeap(), 0, 0x10 );
|
|
|
|
if( name )
|
|
|
|
sprintf( name, "I-%08lX-%02X", x, nType );
|
|
|
|
TRACE( "Value is %s\n", name );
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
1999-08-07 16:32:33 +02:00
|
|
|
/**************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* WNetCachePassword [MPR.@] Saves password in cache
|
1999-08-07 16:32:33 +02:00
|
|
|
*
|
1999-11-23 23:27:03 +01:00
|
|
|
* NOTES
|
2002-06-01 01:06:46 +02:00
|
|
|
* only the parameter count is verifyed
|
1999-11-23 23:27:03 +01:00
|
|
|
*
|
|
|
|
* ---- everything below this line might be wrong (js) -----
|
1999-08-07 16:32:33 +02:00
|
|
|
* RETURNS
|
|
|
|
* Success: WN_SUCCESS
|
|
|
|
* Failure: WN_ACCESS_DENIED, WN_BAD_PASSWORD, WN_BADVALUE, WN_NET_ERROR,
|
|
|
|
* WN_NOT_SUPPORTED, WN_OUT_OF_MEMORY
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WNetCachePassword(
|
|
|
|
LPSTR pbResource, /* [in] Name of workgroup, computer, or resource */
|
|
|
|
WORD cbResource, /* [in] Size of name */
|
|
|
|
LPSTR pbPassword, /* [in] Buffer containing password */
|
|
|
|
WORD cbPassword, /* [in] Size of password */
|
1999-11-23 23:27:03 +01:00
|
|
|
BYTE nType, /* [in] Type of password to cache */
|
|
|
|
WORD x)
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-08-07 16:32:33 +02:00
|
|
|
{
|
2003-07-19 00:59:07 +02:00
|
|
|
HKEY hkey;
|
|
|
|
DWORD r;
|
|
|
|
LPSTR valname;
|
|
|
|
|
|
|
|
WARN( "(%p(%s), %d, %p(%s), %d, %d, 0x%08x): totally insecure\n",
|
1999-11-23 23:27:03 +01:00
|
|
|
pbResource, debugstr_a(pbResource), cbResource,
|
|
|
|
pbPassword, debugstr_a(pbPassword), cbPassword,
|
|
|
|
nType, x );
|
1999-08-07 16:32:33 +02:00
|
|
|
|
2003-07-19 00:59:07 +02:00
|
|
|
r = RegCreateKeyA( HKEY_CURRENT_USER, mpr_key, &hkey );
|
|
|
|
if( r )
|
|
|
|
return WN_ACCESS_DENIED;
|
|
|
|
|
|
|
|
valname = MPR_GetValueName( pbResource, cbResource, nType );
|
|
|
|
if( valname )
|
|
|
|
{
|
|
|
|
r = RegSetValueExA( hkey, valname, 0, REG_BINARY,
|
|
|
|
pbPassword, cbPassword );
|
|
|
|
if( r )
|
|
|
|
r = WN_ACCESS_DENIED;
|
|
|
|
else
|
|
|
|
r = WN_SUCCESS;
|
|
|
|
HeapFree( GetProcessHeap(), 0, valname );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
r = WN_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
|
|
|
|
return r;
|
1999-08-07 16:32:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* WNetRemoveCachedPassword [MPR.@]
|
1999-08-07 16:32:33 +02:00
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
UINT WINAPI WNetRemoveCachedPassword( LPSTR pbResource, WORD cbResource,
|
1999-08-07 16:32:33 +02:00
|
|
|
BYTE nType )
|
|
|
|
{
|
2003-07-19 00:59:07 +02:00
|
|
|
HKEY hkey;
|
|
|
|
DWORD r;
|
|
|
|
LPSTR valname;
|
|
|
|
|
|
|
|
WARN( "(%p(%s), %d, %d): totally insecure\n",
|
1999-11-23 23:27:03 +01:00
|
|
|
pbResource, debugstr_a(pbResource), cbResource, nType );
|
1999-08-07 16:32:33 +02:00
|
|
|
|
2003-07-19 00:59:07 +02:00
|
|
|
r = RegCreateKeyA( HKEY_CURRENT_USER, mpr_key, &hkey );
|
|
|
|
if( r )
|
|
|
|
return WN_ACCESS_DENIED;
|
|
|
|
|
|
|
|
valname = MPR_GetValueName( pbResource, cbResource, nType );
|
|
|
|
if( valname )
|
|
|
|
{
|
|
|
|
r = RegDeleteValueA( hkey, valname );
|
|
|
|
if( r )
|
|
|
|
r = WN_ACCESS_DENIED;
|
|
|
|
else
|
|
|
|
r = WN_SUCCESS;
|
|
|
|
HeapFree( GetProcessHeap(), 0, valname );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
r = WN_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return r;
|
1999-08-07 16:32:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* WNetGetCachedPassword [MPR.@] Retrieves password from cache
|
1999-08-07 16:32:33 +02:00
|
|
|
*
|
1999-11-23 23:27:03 +01:00
|
|
|
* NOTES
|
|
|
|
* the stub seems to be wrong:
|
|
|
|
* arg1: ptr 0x40xxxxxx -> (no string)
|
|
|
|
* arg2: len 36
|
|
|
|
* arg3: ptr 0x40xxxxxx -> (no string)
|
|
|
|
* arg4: ptr 0x40xxxxxx -> 0xc8
|
|
|
|
* arg5: type? 4
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-11-23 23:27:03 +01:00
|
|
|
* ---- everything below this line might be wrong (js) -----
|
1999-08-07 16:32:33 +02:00
|
|
|
* RETURNS
|
|
|
|
* Success: WN_SUCCESS
|
2002-06-01 01:06:46 +02:00
|
|
|
* Failure: WN_ACCESS_DENIED, WN_BAD_PASSWORD, WN_BAD_VALUE,
|
1999-08-07 16:32:33 +02:00
|
|
|
* WN_NET_ERROR, WN_NOT_SUPPORTED, WN_OUT_OF_MEMORY
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WNetGetCachedPassword(
|
|
|
|
LPSTR pbResource, /* [in] Name of workgroup, computer, or resource */
|
|
|
|
WORD cbResource, /* [in] Size of name */
|
|
|
|
LPSTR pbPassword, /* [out] Buffer to receive password */
|
|
|
|
LPWORD pcbPassword, /* [out] Receives size of password */
|
|
|
|
BYTE nType) /* [in] Type of password to retrieve */
|
|
|
|
{
|
2003-07-19 00:59:07 +02:00
|
|
|
HKEY hkey;
|
|
|
|
DWORD r, type = 0, sz;
|
|
|
|
LPSTR valname;
|
|
|
|
|
|
|
|
WARN( "(%p(%s), %d, %p, %p, %d): stub\n",
|
1999-11-23 23:27:03 +01:00
|
|
|
pbResource, debugstr_a(pbResource), cbResource,
|
|
|
|
pbPassword, pcbPassword, nType );
|
1999-08-07 16:32:33 +02:00
|
|
|
|
2003-07-19 00:59:07 +02:00
|
|
|
r = RegCreateKeyA( HKEY_CURRENT_USER, mpr_key, &hkey );
|
|
|
|
if( r )
|
|
|
|
return WN_ACCESS_DENIED;
|
|
|
|
|
|
|
|
valname = MPR_GetValueName( pbResource, cbResource, nType );
|
|
|
|
if( valname )
|
|
|
|
{
|
|
|
|
sz = *pcbPassword;
|
|
|
|
r = RegQueryValueExA( hkey, valname, 0, &type, pbPassword, &sz );
|
|
|
|
*pcbPassword = sz;
|
|
|
|
if( r )
|
|
|
|
r = WN_ACCESS_DENIED;
|
|
|
|
else
|
|
|
|
r = WN_SUCCESS;
|
|
|
|
HeapFree( GetProcessHeap(), 0, valname );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
r = WN_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return r;
|
1999-08-07 16:32:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* WNetEnumCachedPasswords [MPR.@]
|
1999-11-23 23:27:03 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
2002-06-01 01:06:46 +02:00
|
|
|
* the parameter count is verifyed
|
2003-07-19 00:59:07 +02:00
|
|
|
*
|
|
|
|
* This function is a huge security risk, as virii and such can use
|
|
|
|
* it to grab all the passwords in the cache. It's bad enough to
|
|
|
|
* store the passwords (insecurely).
|
1999-11-23 23:27:03 +01:00
|
|
|
*
|
|
|
|
* observed values:
|
|
|
|
* arg1 ptr 0x40xxxxxx -> (no string)
|
|
|
|
* arg2 int 32
|
|
|
|
* arg3 type? 4
|
|
|
|
* arg4 enumPasswordProc (verifyed)
|
|
|
|
* arg5 ptr 0x40xxxxxx -> 0x0
|
|
|
|
*
|
|
|
|
* ---- everything below this line might be wrong (js) -----
|
1999-08-07 16:32:33 +02:00
|
|
|
*/
|
1999-11-23 23:27:03 +01:00
|
|
|
|
1999-08-07 16:32:33 +02:00
|
|
|
UINT WINAPI WNetEnumCachedPasswords( LPSTR pbPrefix, WORD cbPrefix,
|
1999-11-23 23:27:03 +01:00
|
|
|
BYTE nType, ENUMPASSWORDPROC enumPasswordProc, DWORD x)
|
1999-08-07 16:32:33 +02:00
|
|
|
{
|
2003-07-19 00:59:07 +02:00
|
|
|
WARN( "(%p(%s), %d, %d, %p, 0x%08lx): don't implement this\n",
|
1999-11-23 23:27:03 +01:00
|
|
|
pbPrefix, debugstr_a(pbPrefix), cbPrefix,
|
|
|
|
nType, enumPasswordProc, x );
|
1999-08-07 16:32:33 +02:00
|
|
|
|
2003-05-12 05:29:50 +02:00
|
|
|
return WN_NOT_SUPPORTED;
|
1999-08-07 16:32:33 +02:00
|
|
|
}
|