Added class factories for DirectSoundCapture, DirectSoundFullDuplex
[wine/multimedia.git] / dlls / mpr / pwcache.c
blob6a43305be37d62943c9bc8bd27b319b3e0e93ba0
1 /*
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
22 #include <stdio.h>
24 #include "winbase.h"
25 #include "winnetwk.h"
26 #include "winreg.h"
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 )
35 LPSTR name;
36 DWORD i, x = 0;
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 );
43 if( name )
44 sprintf( name, "I-%08lX-%02X", x, nType );
45 TRACE( "Value is %s\n", name );
46 return name;
49 /**************************************************************************
50 * WNetCachePassword [MPR.@] Saves password in cache
52 * NOTES
53 * only the parameter count is verifyed
55 * ---- everything below this line might be wrong (js) -----
56 * RETURNS
57 * Success: WN_SUCCESS
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 */
67 WORD x)
70 HKEY hkey;
71 DWORD r;
72 LPSTR valname;
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,
77 nType, x );
79 r = RegCreateKeyA( HKEY_CURRENT_USER, mpr_key, &hkey );
80 if( r )
81 return WN_ACCESS_DENIED;
83 valname = MPR_GetValueName( pbResource, cbResource, nType );
84 if( valname )
86 r = RegSetValueExA( hkey, valname, 0, REG_BINARY,
87 pbPassword, cbPassword );
88 if( r )
89 r = WN_ACCESS_DENIED;
90 else
91 r = WN_SUCCESS;
92 HeapFree( GetProcessHeap(), 0, valname );
94 else
95 r = WN_OUT_OF_MEMORY;
97 RegCloseKey( hkey );
99 return r;
102 /*****************************************************************
103 * WNetRemoveCachedPassword [MPR.@]
105 UINT WINAPI WNetRemoveCachedPassword( LPSTR pbResource, WORD cbResource,
106 BYTE nType )
108 HKEY hkey;
109 DWORD r;
110 LPSTR valname;
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 );
116 if( r )
117 return WN_ACCESS_DENIED;
119 valname = MPR_GetValueName( pbResource, cbResource, nType );
120 if( valname )
122 r = RegDeleteValueA( hkey, valname );
123 if( r )
124 r = WN_ACCESS_DENIED;
125 else
126 r = WN_SUCCESS;
127 HeapFree( GetProcessHeap(), 0, valname );
129 else
130 r = WN_OUT_OF_MEMORY;
132 return r;
135 /*****************************************************************
136 * WNetGetCachedPassword [MPR.@] Retrieves password from cache
138 * NOTES
139 * the stub seems to be wrong:
140 * arg1: ptr 0x40xxxxxx -> (no string)
141 * arg2: len 36
142 * arg3: ptr 0x40xxxxxx -> (no string)
143 * arg4: ptr 0x40xxxxxx -> 0xc8
144 * arg5: type? 4
146 * ---- everything below this line might be wrong (js) -----
147 * RETURNS
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 */
159 HKEY hkey;
160 DWORD r, type = 0, sz;
161 LPSTR valname;
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 );
168 if( r )
169 return WN_ACCESS_DENIED;
171 valname = MPR_GetValueName( pbResource, cbResource, nType );
172 if( valname )
174 sz = *pcbPassword;
175 r = RegQueryValueExA( hkey, valname, 0, &type, pbPassword, &sz );
176 *pcbPassword = sz;
177 if( r )
178 r = WN_ACCESS_DENIED;
179 else
180 r = WN_SUCCESS;
181 HeapFree( GetProcessHeap(), 0, valname );
183 else
184 r = WN_OUT_OF_MEMORY;
186 return r;
189 /*******************************************************************
190 * WNetEnumCachedPasswords [MPR.@]
192 * NOTES
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).
199 * observed values:
200 * arg1 ptr 0x40xxxxxx -> (no string)
201 * arg2 int 32
202 * arg3 type? 4
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;