2 * MPR Password Cache functions
4 * Copyright 1999 Ulrich Weigand
5 * Copyright 2003 Mike McCormack for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(mpr
);
33 static const char mpr_key
[] = "Software\\Wine\\Wine\\Mpr\\";
35 static LPSTR
MPR_GetValueName( LPSTR pbResource
, WORD cbResource
, BYTE nType
)
40 /* just a hash so the value name doesn't get too large */
41 for( i
=0; i
<cbResource
; i
++ )
42 x
= ((x
<<7) | (x
>> 25)) ^ toupper(pbResource
[i
]);
44 name
= HeapAlloc( GetProcessHeap(), 0, 0x10 );
46 sprintf( name
, "I-%08lX-%02X", x
, nType
);
47 TRACE( "Value is %s\n", name
);
51 /**************************************************************************
52 * WNetCachePassword [MPR.@] Saves password in cache
55 * only the parameter count is verifyed
57 * ---- everything below this line might be wrong (js) -----
60 * Failure: WN_ACCESS_DENIED, WN_BAD_PASSWORD, WN_BADVALUE, WN_NET_ERROR,
61 * WN_NOT_SUPPORTED, WN_OUT_OF_MEMORY
63 DWORD WINAPI
WNetCachePassword(
64 LPSTR pbResource
, /* [in] Name of workgroup, computer, or resource */
65 WORD cbResource
, /* [in] Size of name */
66 LPSTR pbPassword
, /* [in] Buffer containing password */
67 WORD cbPassword
, /* [in] Size of password */
68 BYTE nType
, /* [in] Type of password to cache */
76 WARN( "(%p(%s), %d, %p(%s), %d, %d, 0x%08x): totally insecure\n",
77 pbResource
, debugstr_a(pbResource
), cbResource
,
78 pbPassword
, debugstr_a(pbPassword
), cbPassword
,
81 r
= RegCreateKeyA( HKEY_CURRENT_USER
, mpr_key
, &hkey
);
83 return WN_ACCESS_DENIED
;
85 valname
= MPR_GetValueName( pbResource
, cbResource
, nType
);
88 r
= RegSetValueExA( hkey
, valname
, 0, REG_BINARY
,
89 pbPassword
, cbPassword
);
94 HeapFree( GetProcessHeap(), 0, valname
);
104 /*****************************************************************
105 * WNetRemoveCachedPassword [MPR.@]
107 UINT WINAPI
WNetRemoveCachedPassword( LPSTR pbResource
, WORD cbResource
,
114 WARN( "(%p(%s), %d, %d): totally insecure\n",
115 pbResource
, debugstr_a(pbResource
), cbResource
, nType
);
117 r
= RegCreateKeyA( HKEY_CURRENT_USER
, mpr_key
, &hkey
);
119 return WN_ACCESS_DENIED
;
121 valname
= MPR_GetValueName( pbResource
, cbResource
, nType
);
124 r
= RegDeleteValueA( hkey
, valname
);
126 r
= WN_ACCESS_DENIED
;
129 HeapFree( GetProcessHeap(), 0, valname
);
132 r
= WN_OUT_OF_MEMORY
;
137 /*****************************************************************
138 * WNetGetCachedPassword [MPR.@] Retrieves password from cache
141 * the stub seems to be wrong:
142 * arg1: ptr 0x40xxxxxx -> (no string)
144 * arg3: ptr 0x40xxxxxx -> (no string)
145 * arg4: ptr 0x40xxxxxx -> 0xc8
148 * ---- everything below this line might be wrong (js) -----
150 * Success: WN_SUCCESS
151 * Failure: WN_ACCESS_DENIED, WN_BAD_PASSWORD, WN_BAD_VALUE,
152 * WN_NET_ERROR, WN_NOT_SUPPORTED, WN_OUT_OF_MEMORY
154 DWORD WINAPI
WNetGetCachedPassword(
155 LPSTR pbResource
, /* [in] Name of workgroup, computer, or resource */
156 WORD cbResource
, /* [in] Size of name */
157 LPSTR pbPassword
, /* [out] Buffer to receive password */
158 LPWORD pcbPassword
, /* [out] Receives size of password */
159 BYTE nType
) /* [in] Type of password to retrieve */
162 DWORD r
, type
= 0, sz
;
165 WARN( "(%p(%s), %d, %p, %p, %d): stub\n",
166 pbResource
, debugstr_a(pbResource
), cbResource
,
167 pbPassword
, pcbPassword
, nType
);
169 r
= RegCreateKeyA( HKEY_CURRENT_USER
, mpr_key
, &hkey
);
171 return WN_ACCESS_DENIED
;
173 valname
= MPR_GetValueName( pbResource
, cbResource
, nType
);
177 r
= RegQueryValueExA( hkey
, valname
, 0, &type
, pbPassword
, &sz
);
180 r
= WN_ACCESS_DENIED
;
183 HeapFree( GetProcessHeap(), 0, valname
);
186 r
= WN_OUT_OF_MEMORY
;
191 /*******************************************************************
192 * WNetEnumCachedPasswords [MPR.@]
195 * the parameter count is verifyed
197 * This function is a huge security risk, as virii and such can use
198 * it to grab all the passwords in the cache. It's bad enough to
199 * store the passwords (insecurely).
202 * arg1 ptr 0x40xxxxxx -> (no string)
205 * arg4 enumPasswordProc (verifyed)
206 * arg5 ptr 0x40xxxxxx -> 0x0
208 * ---- everything below this line might be wrong (js) -----
211 UINT WINAPI
WNetEnumCachedPasswords( LPSTR pbPrefix
, WORD cbPrefix
,
212 BYTE nType
, ENUMPASSWORDPROC enumPasswordProc
, DWORD x
)
214 WARN( "(%p(%s), %d, %d, %p, 0x%08lx): don't implement this\n",
215 pbPrefix
, debugstr_a(pbPrefix
), cbPrefix
,
216 nType
, enumPasswordProc
, x
);
218 return WN_NOT_SUPPORTED
;