advapi32: Fix a typo.
[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
33 #include "wine/library.h"
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
37
38 /******************************************************************************
39  * GetUserNameA [ADVAPI32.@]
40  *
41  * Get the current user name.
42  *
43  * PARAMS
44  *  lpszName [O]   Destination for the user name.
45  *  lpSize   [I/O] Size of lpszName.
46  *
47  * RETURNS
48  *  Success: The length of the user name, including terminating NUL.
49  *  Failure: ERROR_MORE_DATA if *lpSize is too small.
50  */
51 BOOL WINAPI
52 GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
53 {
54     WCHAR *buffer;
55     BOOL ret;
56     DWORD sizeW = *lpSize * 2;
57
58     if (!(buffer = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) )))
59     {
60         SetLastError( ERROR_NOT_ENOUGH_MEMORY );
61         return FALSE;
62     }
63     ret = GetUserNameW( buffer, &sizeW );
64     if (ret)
65     {
66         if (!(*lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL )))
67         {
68             *lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
69             SetLastError( ERROR_MORE_DATA );
70             ret = FALSE;
71         }
72     }
73     else *lpSize = sizeW * 2;
74     HeapFree( GetProcessHeap(), 0, buffer );
75     return ret;
76 }
77
78 /******************************************************************************
79  * GetUserNameW [ADVAPI32.@]
80  *
81  * See GetUserNameA.
82  */
83 BOOL WINAPI
84 GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
85 {
86     const char *name = wine_get_user_name();
87     DWORD i, len = MultiByteToWideChar( CP_UNIXCP, 0, name, -1, NULL, 0 );
88
89     if (len > *lpSize)
90     {
91         SetLastError(ERROR_MORE_DATA);
92         *lpSize = len;
93         return FALSE;
94     }
95
96     *lpSize = len;
97     MultiByteToWideChar( CP_UNIXCP, 0, name, -1, lpszName, len );
98
99     /* Word uses the user name to create named mutexes and file mappings,
100      * and backslashes in the name cause the creation to fail.
101      */
102     for (i = 0; lpszName[i]; i++)
103         if (lpszName[i] == '\\' || lpszName[i] == '/') lpszName[i] = '_';
104     return TRUE;
105 }
106
107 /******************************************************************************
108  * GetCurrentHwProfileA [ADVAPI32.@]
109  *
110  * Get the current hardware profile.
111  *
112  * PARAMS
113  *  pInfo [O] Destination for hardware profile information.
114  *
115  * RETURNS
116  *  Success: TRUE. pInfo is updated with the hardware profile details.
117  *  Failure: FALSE.
118  */
119 BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA pInfo)
120 {
121         FIXME("(%p) semi-stub\n", pInfo);
122         pInfo->dwDockInfo = DOCKINFO_DOCKED;
123         strcpy(pInfo->szHwProfileGuid,"{12340001-1234-1234-1234-123456789012}");
124         strcpy(pInfo->szHwProfileName,"Wine Profile");
125         return 1;
126 }
127
128 /******************************************************************************
129  * GetCurrentHwProfileW [ADVAPI32.@]
130  *
131  * See GetCurrentHwProfileA.
132  */
133 BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW pInfo)
134 {
135        FIXME("(%p)\n", pInfo);
136        return FALSE;
137 }
138
139
140 /**************************************************************************
141  *      IsTextUnicode (ADVAPI32.@)
142  *
143  * Attempt to guess whether a text buffer is Unicode.
144  *
145  * PARAMS
146  *  buf   [I] Text buffer to test
147  *  len   [I] Length of buf
148  *  flags [O] Destination for test results
149  *
150  * RETURNS
151  *  TRUE if the buffer is likely Unicode, FALSE otherwise.
152  */
153 BOOL WINAPI IsTextUnicode( LPCVOID buf, INT len, LPINT flags )
154 {
155     return RtlIsTextUnicode( buf, len, flags );
156 }
157
158
159 /******************************************************************************
160  * AbortSystemShutdownA [ADVAPI32.@]
161  *
162  * Stop a system shutdown if one is in progress.
163  *
164  * PARAMS
165  *  lpMachineName [I] Name of machine to not shutdown.
166  *
167  * RETURNS
168  *  Success: TRUE.
169  *  Failure: FALSE.
170  *
171  * NOTES
172  *  The Wine implementation of this function is a harmless stub.
173  */
174 BOOL WINAPI AbortSystemShutdownA( LPSTR lpMachineName )
175 {
176     TRACE("stub %s (harmless)\n", lpMachineName);
177     return TRUE;
178 }
179
180 /******************************************************************************
181  * AbortSystemShutdownW [ADVAPI32.@]
182  *
183  * See AbortSystemShutdownA.
184  */
185 BOOL WINAPI AbortSystemShutdownW( LPWSTR lpMachineName )
186 {
187     TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName));
188     return TRUE;
189 }
190
191 /******************************************************************************
192  * InitiateSystemShutdownExA [ADVAPI32.@]
193  *
194  * Initiate a shutdown or optionally restart the computer.
195  *
196  * PARAMS
197  *  lpMachineName    [I] Network name of machine to shutdown.
198  *  lpMessage        [I] Message displayed in shutdown dialog box.
199  *  dwTimeout        [I] Number of seconds dialog is displayed before shutdown.
200  *  bForceAppsClosed [I] If TRUE, apps close without saving, else dialog is
201  *                       displayed requesting user to close apps.
202  *  bRebootAfterShutdown [I] If TRUE, system reboots after restart, else the
203  *                           system flushes all caches to disk and clears
204  *                           the screen
205  *  dwReason [I] Reason for shutting down.  Must be a system shutdown reason
206  *               code.
207  *
208  *  RETURNS
209  *   Success: TRUE
210  *   Failure: FALSE
211  *
212  *  NOTES
213  *   if lpMachineName is NULL, the local computer is shutdown.
214  */
215 BOOL WINAPI InitiateSystemShutdownExA( LPSTR lpMachineName, LPSTR lpMessage,
216          DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
217          DWORD dwReason)
218 {
219      FIXME("%s %s %d %d %d %d\n", debugstr_a(lpMachineName),
220             debugstr_a(lpMessage), dwTimeout, bForceAppsClosed,
221             bRebootAfterShutdown, dwReason);
222      return TRUE;
223
224
225 /******************************************************************************
226  * InitiateSystemShutdownExW [ADVAPI32.@]
227  *
228  * See InitiateSystemShutdownExA.
229  */
230 BOOL WINAPI InitiateSystemShutdownExW( LPWSTR lpMachineName, LPWSTR lpMessage,
231          DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
232          DWORD dwReason)
233 {
234      FIXME("%s %s %d %d %d %d\n", debugstr_w(lpMachineName),
235             debugstr_w(lpMessage), dwTimeout, bForceAppsClosed,
236             bRebootAfterShutdown, dwReason);
237      return TRUE;
238
239
240 BOOL WINAPI InitiateSystemShutdownA( LPSTR lpMachineName, LPSTR lpMessage, DWORD dwTimeout,
241                                      BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
242 {
243     return InitiateSystemShutdownExA( lpMachineName, lpMessage, dwTimeout,
244                                       bForceAppsClosed, bRebootAfterShutdown,
245                                       SHTDN_REASON_MAJOR_LEGACY_API );
246 }
247
248 BOOL WINAPI InitiateSystemShutdownW( LPWSTR lpMachineName, LPWSTR lpMessage, DWORD dwTimeout,
249                                      BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
250 {
251     return InitiateSystemShutdownExW( lpMachineName, lpMessage, dwTimeout,
252                                       bForceAppsClosed, bRebootAfterShutdown,
253                                       SHTDN_REASON_MAJOR_LEGACY_API );
254 }
255
256 BOOL WINAPI LogonUserA( LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
257                         DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
258 {
259     FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_a(lpszUsername),
260           debugstr_a(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
261
262     return TRUE;
263 }
264
265 BOOL WINAPI LogonUserW( LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword,
266                         DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
267 {
268     FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_w(lpszUsername),
269           debugstr_w(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
270
271     return TRUE;
272 }
273
274 typedef UINT (WINAPI *fnMsiProvideComponentFromDescriptor)(LPCWSTR,LPWSTR,DWORD*,DWORD*);
275
276 DWORD WINAPI CommandLineFromMsiDescriptor( WCHAR *szDescriptor,
277                     WCHAR *szCommandLine, DWORD *pcchCommandLine )
278 {
279     static const WCHAR szMsi[] = { 'm','s','i',0 };
280     fnMsiProvideComponentFromDescriptor mpcfd;
281     HMODULE hmsi;
282     UINT r = ERROR_CALL_NOT_IMPLEMENTED;
283
284     TRACE("%s %p %p\n", debugstr_w(szDescriptor), szCommandLine, pcchCommandLine);
285
286     hmsi = LoadLibraryW( szMsi );
287     if (!hmsi)
288         return r;
289     mpcfd = (void*) GetProcAddress( hmsi, "MsiProvideComponentFromDescriptorW" );
290     if (mpcfd)
291         r = mpcfd( szDescriptor, szCommandLine, pcchCommandLine, NULL );
292     FreeLibrary( hmsi );
293     return r;
294 }