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