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
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(mpr
);
31 static const char mpr_key
[] = "Software\\Wine\\Wine\\Mpr\\";
33 static LPSTR
MPR_GetValueName( LPSTR pbResource
, WORD cbResource
, BYTE nType
)
38 /* just a hash so the value name doesn't get too large */
39 for( i
=0; i
<cbResource
; i
++ )
40 x
= ((x
<<7) | (x
>> 25)) ^ toupper(pbResource
[i
]);
42 name
= HeapAlloc( GetProcessHeap(), 0, 0x10 );
44 sprintf( name
, "I-%08lX-%02X", x
, nType
);
45 TRACE( "Value is %s\n", name
);
49 /**************************************************************************
50 * WNetCachePassword [MPR.@] Saves password in cache
53 * only the parameter count is verifyed
55 * ---- everything below this line might be wrong (js) -----
58 * Failure: WN_ACCESS_DENIED, WN_BAD_PASSWORD, WN_BADVALUE, WN_NET_ERROR,
59 * WN_NOT_SUPPORTED, WN_OUT_OF_MEMORY
61 DWORD WINAPI
WNetCachePassword(
62 LPSTR pbResource
, /* [in] Name of workgroup, computer, or resource */
63 WORD cbResource
, /* [in] Size of name */
64 LPSTR pbPassword
, /* [in] Buffer containing password */
65 WORD cbPassword
, /* [in] Size of password */
66 BYTE nType
, /* [in] Type of password to cache */
74 WARN( "(%p(%s), %d, %p(%s), %d, %d, 0x%08x): totally insecure\n",
75 pbResource
, debugstr_a(pbResource
), cbResource
,
76 pbPassword
, debugstr_a(pbPassword
), cbPassword
,
79 r
= RegCreateKeyA( HKEY_CURRENT_USER
, mpr_key
, &hkey
);
81 return WN_ACCESS_DENIED
;
83 valname
= MPR_GetValueName( pbResource
, cbResource
, nType
);
86 r
= RegSetValueExA( hkey
, valname
, 0, REG_BINARY
,
87 pbPassword
, cbPassword
);
92 HeapFree( GetProcessHeap(), 0, valname
);
102 /*****************************************************************
103 * WNetRemoveCachedPassword [MPR.@]
105 UINT WINAPI
WNetRemoveCachedPassword( LPSTR pbResource
, WORD cbResource
,
112 WARN( "(%p(%s), %d, %d): totally insecure\n",
113 pbResource
, debugstr_a(pbResource
), cbResource
, nType
);
115 r
= RegCreateKeyA( HKEY_CURRENT_USER
, mpr_key
, &hkey
);
117 return WN_ACCESS_DENIED
;
119 valname
= MPR_GetValueName( pbResource
, cbResource
, nType
);
122 r
= RegDeleteValueA( hkey
, valname
);
124 r
= WN_ACCESS_DENIED
;
127 HeapFree( GetProcessHeap(), 0, valname
);
130 r
= WN_OUT_OF_MEMORY
;
135 /*****************************************************************
136 * WNetGetCachedPassword [MPR.@] Retrieves password from cache
139 * the stub seems to be wrong:
140 * arg1: ptr 0x40xxxxxx -> (no string)
142 * arg3: ptr 0x40xxxxxx -> (no string)
143 * arg4: ptr 0x40xxxxxx -> 0xc8
146 * ---- everything below this line might be wrong (js) -----
148 * Success: WN_SUCCESS
149 * Failure: WN_ACCESS_DENIED, WN_BAD_PASSWORD, WN_BAD_VALUE,
150 * WN_NET_ERROR, WN_NOT_SUPPORTED, WN_OUT_OF_MEMORY
152 DWORD WINAPI
WNetGetCachedPassword(
153 LPSTR pbResource
, /* [in] Name of workgroup, computer, or resource */
154 WORD cbResource
, /* [in] Size of name */
155 LPSTR pbPassword
, /* [out] Buffer to receive password */
156 LPWORD pcbPassword
, /* [out] Receives size of password */
157 BYTE nType
) /* [in] Type of password to retrieve */
160 DWORD r
, type
= 0, sz
;
163 WARN( "(%p(%s), %d, %p, %p, %d): stub\n",
164 pbResource
, debugstr_a(pbResource
), cbResource
,
165 pbPassword
, pcbPassword
, nType
);
167 r
= RegCreateKeyA( HKEY_CURRENT_USER
, mpr_key
, &hkey
);
169 return WN_ACCESS_DENIED
;
171 valname
= MPR_GetValueName( pbResource
, cbResource
, nType
);
175 r
= RegQueryValueExA( hkey
, valname
, 0, &type
, pbPassword
, &sz
);
178 r
= WN_ACCESS_DENIED
;
181 HeapFree( GetProcessHeap(), 0, valname
);
184 r
= WN_OUT_OF_MEMORY
;
189 /*******************************************************************
190 * WNetEnumCachedPasswords [MPR.@]
193 * the parameter count is verifyed
195 * This function is a huge security risk, as virii and such can use
196 * it to grab all the passwords in the cache. It's bad enough to
197 * store the passwords (insecurely).
200 * arg1 ptr 0x40xxxxxx -> (no string)
203 * arg4 enumPasswordProc (verifyed)
204 * arg5 ptr 0x40xxxxxx -> 0x0
206 * ---- everything below this line might be wrong (js) -----
209 UINT WINAPI
WNetEnumCachedPasswords( LPSTR pbPrefix
, WORD cbPrefix
,
210 BYTE nType
, ENUMPASSWORDPROC enumPasswordProc
, DWORD x
)
212 WARN( "(%p(%s), %d, %d, %p, 0x%08lx): don't implement this\n",
213 pbPrefix
, debugstr_a(pbPrefix
), cbPrefix
,
214 nType
, enumPasswordProc
, x
);
216 return WN_NOT_SUPPORTED
;