d3d9/tests: Add a software vertexprocessing buffer discard test.
[wine] / dlls / advapi32 / advapi.c
1 /*
2  * Win32 advapi functions
3  *
4  * Copyright 1995 Sven Verdoolaege
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <errno.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
29 #include "winreg.h"
30 #include "winternl.h"
31 #include "winerror.h"
32 #include "wincred.h"
33
34 #include "wine/library.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
39
40 /******************************************************************************
41  * GetUserNameA [ADVAPI32.@]
42  *
43  * Get the current user name.
44  *
45  * PARAMS
46  *  lpszName [O]   Destination for the user name.
47  *  lpSize   [I/O] Size of lpszName.
48  *
49  * RETURNS
50  *  Success: The length of the user name, including terminating NUL.
51  *  Failure: ERROR_MORE_DATA if *lpSize is too small.
52  */
53 BOOL WINAPI
54 GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
55 {
56     WCHAR *buffer;
57     BOOL ret;
58     DWORD sizeW = *lpSize;
59
60     if (!(buffer = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) )))
61     {
62         SetLastError( ERROR_NOT_ENOUGH_MEMORY );
63         return FALSE;
64     }
65
66     ret = GetUserNameW( buffer, &sizeW );
67     if (ret)
68         *lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL );
69     else
70         *lpSize = sizeW;
71
72     HeapFree( GetProcessHeap(), 0, buffer );
73     return ret;
74 }
75
76 /******************************************************************************
77  * GetUserNameW [ADVAPI32.@]
78  *
79  * See GetUserNameA.
80  */
81 BOOL WINAPI
82 GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
83 {
84     const char *name = wine_get_user_name();
85     DWORD i, len = MultiByteToWideChar( CP_UNIXCP, 0, name, -1, NULL, 0 );
86     LPWSTR backslash;
87
88     if (len > *lpSize)
89     {
90         SetLastError( ERROR_INSUFFICIENT_BUFFER );
91         *lpSize = len;
92         return FALSE;
93     }
94
95     *lpSize = len;
96     MultiByteToWideChar( CP_UNIXCP, 0, name, -1, lpszName, len );
97
98     /* Word uses the user name to create named mutexes and file mappings,
99      * and backslashes in the name cause the creation to fail.
100      * Also, Windows doesn't return the domain name in the user name even when
101      * joined to a domain. A Unix box joined to a domain using winbindd will
102      * contain the domain name in the username. So we need to cut this off.
103      * FIXME: Only replaces forward and backslashes for now, should get the
104      * winbind separator char from winbindd and replace that.
105      */
106     for (i = 0; lpszName[i]; i++)
107         if (lpszName[i] == '/') lpszName[i] = '\\';
108
109     backslash = strrchrW(lpszName, '\\');
110     if (backslash == NULL)
111         return TRUE;
112
113     len = lstrlenW(backslash);
114     memmove(lpszName, backslash + 1, len * sizeof(WCHAR));
115     *lpSize = len;
116     return TRUE;
117 }
118
119 /******************************************************************************
120  * GetCurrentHwProfileA [ADVAPI32.@]
121  *
122  * Get the current hardware profile.
123  *
124  * PARAMS
125  *  pInfo [O] Destination for hardware profile information.
126  *
127  * RETURNS
128  *  Success: TRUE. pInfo is updated with the hardware profile details.
129  *  Failure: FALSE.
130  */
131 BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA pInfo)
132 {
133         FIXME("(%p) semi-stub\n", pInfo);
134         pInfo->dwDockInfo = DOCKINFO_DOCKED;
135         strcpy(pInfo->szHwProfileGuid,"{12340001-1234-1234-1234-123456789012}");
136         strcpy(pInfo->szHwProfileName,"Wine Profile");
137         return 1;
138 }
139
140 /******************************************************************************
141  * GetCurrentHwProfileW [ADVAPI32.@]
142  *
143  * See GetCurrentHwProfileA.
144  */
145 BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW pInfo)
146 {
147        FIXME("(%p)\n", pInfo);
148        return FALSE;
149 }
150
151
152 /**************************************************************************
153  *      IsTextUnicode (ADVAPI32.@)
154  *
155  * Attempt to guess whether a text buffer is Unicode.
156  *
157  * PARAMS
158  *  buf   [I] Text buffer to test
159  *  len   [I] Length of buf
160  *  flags [O] Destination for test results
161  *
162  * RETURNS
163  *  TRUE if the buffer is likely Unicode, FALSE otherwise.
164  */
165 BOOL WINAPI IsTextUnicode( LPCVOID buf, INT len, LPINT flags )
166 {
167     return RtlIsTextUnicode( buf, len, flags );
168 }
169
170
171 /******************************************************************************
172  * AbortSystemShutdownA [ADVAPI32.@]
173  *
174  * Stop a system shutdown if one is in progress.
175  *
176  * PARAMS
177  *  lpMachineName [I] Name of machine to not shutdown.
178  *
179  * RETURNS
180  *  Success: TRUE.
181  *  Failure: FALSE.
182  *
183  * NOTES
184  *  The Wine implementation of this function is a harmless stub.
185  */
186 BOOL WINAPI AbortSystemShutdownA( LPSTR lpMachineName )
187 {
188     TRACE("stub %s (harmless)\n", lpMachineName);
189     return TRUE;
190 }
191
192 /******************************************************************************
193  * AbortSystemShutdownW [ADVAPI32.@]
194  *
195  * See AbortSystemShutdownA.
196  */
197 BOOL WINAPI AbortSystemShutdownW( LPWSTR lpMachineName )
198 {
199     TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName));
200     return TRUE;
201 }
202
203 /******************************************************************************
204  * InitiateSystemShutdownExA [ADVAPI32.@]
205  *
206  * Initiate a shutdown or optionally restart the computer.
207  *
208  * PARAMS
209  *  lpMachineName    [I] Network name of machine to shutdown.
210  *  lpMessage        [I] Message displayed in shutdown dialog box.
211  *  dwTimeout        [I] Number of seconds dialog is displayed before shutdown.
212  *  bForceAppsClosed [I] If TRUE, apps close without saving, else dialog is
213  *                       displayed requesting user to close apps.
214  *  bRebootAfterShutdown [I] If TRUE, system reboots after restart, else the
215  *                           system flushes all caches to disk and clears
216  *                           the screen
217  *  dwReason [I] Reason for shutting down.  Must be a system shutdown reason
218  *               code.
219  *
220  *  RETURNS
221  *   Success: TRUE
222  *   Failure: FALSE
223  *
224  *  NOTES
225  *   if lpMachineName is NULL, the local computer is shutdown.
226  */
227 BOOL WINAPI InitiateSystemShutdownExA( LPSTR lpMachineName, LPSTR lpMessage,
228          DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
229          DWORD dwReason)
230 {
231      FIXME("%s %s %d %d %d %d\n", debugstr_a(lpMachineName),
232             debugstr_a(lpMessage), dwTimeout, bForceAppsClosed,
233             bRebootAfterShutdown, dwReason);
234      return TRUE;
235
236
237 /******************************************************************************
238  * InitiateSystemShutdownExW [ADVAPI32.@]
239  *
240  * See InitiateSystemShutdownExA.
241  */
242 BOOL WINAPI InitiateSystemShutdownExW( LPWSTR lpMachineName, LPWSTR lpMessage,
243          DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
244          DWORD dwReason)
245 {
246      FIXME("%s %s %d %d %d %d\n", debugstr_w(lpMachineName),
247             debugstr_w(lpMessage), dwTimeout, bForceAppsClosed,
248             bRebootAfterShutdown, dwReason);
249      return TRUE;
250
251
252 BOOL WINAPI InitiateSystemShutdownA( LPSTR lpMachineName, LPSTR lpMessage, DWORD dwTimeout,
253                                      BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
254 {
255     return InitiateSystemShutdownExA( lpMachineName, lpMessage, dwTimeout,
256                                       bForceAppsClosed, bRebootAfterShutdown,
257                                       SHTDN_REASON_MAJOR_LEGACY_API );
258 }
259
260 BOOL WINAPI InitiateSystemShutdownW( LPWSTR lpMachineName, LPWSTR lpMessage, DWORD dwTimeout,
261                                      BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
262 {
263     return InitiateSystemShutdownExW( lpMachineName, lpMessage, dwTimeout,
264                                       bForceAppsClosed, bRebootAfterShutdown,
265                                       SHTDN_REASON_MAJOR_LEGACY_API );
266 }
267
268 BOOL WINAPI LogonUserA( LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
269                         DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
270 {
271     FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_a(lpszUsername),
272           debugstr_a(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
273
274     return TRUE;
275 }
276
277 BOOL WINAPI LogonUserW( LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword,
278                         DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
279 {
280     FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_w(lpszUsername),
281           debugstr_w(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
282
283     return TRUE;
284 }
285
286 typedef UINT (WINAPI *fnMsiProvideComponentFromDescriptor)(LPCWSTR,LPWSTR,DWORD*,DWORD*);
287
288 DWORD WINAPI CommandLineFromMsiDescriptor( WCHAR *szDescriptor,
289                     WCHAR *szCommandLine, DWORD *pcchCommandLine )
290 {
291     static const WCHAR szMsi[] = { 'm','s','i',0 };
292     fnMsiProvideComponentFromDescriptor mpcfd;
293     HMODULE hmsi;
294     UINT r = ERROR_CALL_NOT_IMPLEMENTED;
295
296     TRACE("%s %p %p\n", debugstr_w(szDescriptor), szCommandLine, pcchCommandLine);
297
298     hmsi = LoadLibraryW( szMsi );
299     if (!hmsi)
300         return r;
301     mpcfd = (fnMsiProvideComponentFromDescriptor)GetProcAddress( hmsi,
302                                                                  "MsiProvideComponentFromDescriptorW" );
303     if (mpcfd)
304         r = mpcfd( szDescriptor, szCommandLine, pcchCommandLine, NULL );
305     FreeLibrary( hmsi );
306     return r;
307 }