msi: Only insert entries into listbox if property value matches.
[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 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     return TRUE;
99 }
100
101 /******************************************************************************
102  * GetCurrentHwProfileA [ADVAPI32.@]
103  *
104  * Get the current hardware profile.
105  *
106  * PARAMS
107  *  pInfo [O] Destination for hardware profile information.
108  *
109  * RETURNS
110  *  Success: TRUE. pInfo is updated with the hardware profile details.
111  *  Failure: FALSE.
112  */
113 BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA pInfo)
114 {
115         FIXME("(%p) semi-stub\n", pInfo);
116         pInfo->dwDockInfo = DOCKINFO_DOCKED;
117         strcpy(pInfo->szHwProfileGuid,"{12340001-1234-1234-1234-1233456789012}");
118         strcpy(pInfo->szHwProfileName,"Wine Profile");
119         return 1;
120 }
121
122 /******************************************************************************
123  * GetCurrentHwProfileW [ADVAPI32.@]
124  *
125  * See GetCurrentHwProfileA.
126  */
127 BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW pInfo)
128 {
129        FIXME("(%p)\n", pInfo);
130        return FALSE;
131 }
132
133
134 /**************************************************************************
135  *      IsTextUnicode (ADVAPI32.@)
136  *
137  * Attempt to guess whether a text buffer is Unicode.
138  *
139  * PARAMS
140  *  buf   [I] Text buffer to test
141  *  len   [I] Length of buf
142  *  flags [O] Destination for test results
143  *
144  * RETURNS
145  *  TRUE if the buffer is likely Unicode, FALSE otherwise.
146  */
147 BOOL WINAPI IsTextUnicode( LPCVOID buf, INT len, LPINT flags )
148 {
149     return RtlIsTextUnicode( buf, len, flags );
150 }
151
152
153 /******************************************************************************
154  * AbortSystemShutdownA [ADVAPI32.@]
155  *
156  * Stop a system shutdown if one is in progress.
157  *
158  * PARAMS
159  *  lpMachineName [I] Name of machine to not shutdown.
160  *
161  * RETURNS
162  *  Success: TRUE.
163  *  Failure: FALSE.
164  *
165  * NOTES
166  *  The Wine implementation of this function is a harmless stub.
167  */
168 BOOL WINAPI AbortSystemShutdownA( LPSTR lpMachineName )
169 {
170     TRACE("stub %s (harmless)\n", lpMachineName);
171     return TRUE;
172 }
173
174 /******************************************************************************
175  * AbortSystemShutdownW [ADVAPI32.@]
176  *
177  * See AbortSystemShutdownA.
178  */
179 BOOL WINAPI AbortSystemShutdownW( LPWSTR lpMachineName )
180 {
181     TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName));
182     return TRUE;
183 }
184
185 /******************************************************************************
186  * InitiateSystemShutdownExA [ADVAPI32.@]
187  *
188  * Initiate a shutdown or optionally restart the computer.
189  *
190  * PARAMS
191  *  lpMachineName    [I] Network name of machine to shutdown.
192  *  lpMessage        [I] Message displayed in shutdown dialog box.
193  *  dwTimeout        [I] Number of seconds dialog is displayed before shutdown.
194  *  bForceAppsClosed [I] If TRUE, apps close without saving, else dialog is
195  *                       displayed requesting user to close apps.
196  *  bRebootAfterShutdown [I] If TRUE, system reboots after restart, else the
197  *                           system flushes all caches to disk and clears
198  *                           the screen
199  *  dwReason [I] Reason for shutting down.  Must be a system shutdown reason
200  *               code.
201  *
202  *  RETURNS
203  *   Success: TRUE
204  *   Failure: FALSE
205  *
206  *  NOTES
207  *   if lpMachineName is NULL, the local computer is shutdown.
208  */
209 BOOL WINAPI InitiateSystemShutdownExA( LPSTR lpMachineName, LPSTR lpMessage,
210          DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
211          DWORD dwReason)
212 {
213      FIXME("%s %s %d %d %d %d\n", debugstr_a(lpMachineName),
214             debugstr_a(lpMessage), dwTimeout, bForceAppsClosed,
215             bRebootAfterShutdown, dwReason);
216      return TRUE;
217
218
219 /******************************************************************************
220  * InitiateSystemShutdownExW [ADVAPI32.@]
221  *
222  * See InitiateSystemShutdownExA.
223  */
224 BOOL WINAPI InitiateSystemShutdownExW( LPWSTR lpMachineName, LPWSTR lpMessage,
225          DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
226          DWORD dwReason)
227 {
228      FIXME("%s %s %d %d %d %d\n", debugstr_w(lpMachineName),
229             debugstr_w(lpMessage), dwTimeout, bForceAppsClosed,
230             bRebootAfterShutdown, dwReason);
231      return TRUE;
232
233
234 BOOL WINAPI InitiateSystemShutdownA( LPSTR lpMachineName, LPSTR lpMessage, DWORD dwTimeout,
235                                      BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
236 {
237     return InitiateSystemShutdownExA( lpMachineName, lpMessage, dwTimeout,
238                                       bForceAppsClosed, bRebootAfterShutdown,
239                                       SHTDN_REASON_MAJOR_LEGACY_API );
240 }
241
242 BOOL WINAPI InitiateSystemShutdownW( LPWSTR lpMachineName, LPWSTR lpMessage, DWORD dwTimeout,
243                                      BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
244 {
245     return InitiateSystemShutdownExW( lpMachineName, lpMessage, dwTimeout,
246                                       bForceAppsClosed, bRebootAfterShutdown,
247                                       SHTDN_REASON_MAJOR_LEGACY_API );
248 }
249
250 BOOL WINAPI LogonUserA( LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
251                         DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
252 {
253     FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_a(lpszUsername),
254           debugstr_a(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
255
256     return TRUE;
257 }
258
259 BOOL WINAPI LogonUserW( LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword,
260                         DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
261 {
262     FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_w(lpszUsername),
263           debugstr_w(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
264
265     return TRUE;
266 }
267
268 typedef UINT (WINAPI *fnMsiProvideComponentFromDescriptor)(LPCWSTR,LPWSTR,DWORD*,DWORD*);
269
270 DWORD WINAPI CommandLineFromMsiDescriptor( WCHAR *szDescriptor,
271                     WCHAR *szCommandLine, DWORD *pcchCommandLine )
272 {
273     static const WCHAR szMsi[] = { 'm','s','i',0 };
274     fnMsiProvideComponentFromDescriptor mpcfd;
275     HMODULE hmsi;
276     UINT r = ERROR_CALL_NOT_IMPLEMENTED;
277
278     TRACE("%s %p %p\n", debugstr_w(szDescriptor), szCommandLine, pcchCommandLine);
279
280     hmsi = LoadLibraryW( szMsi );
281     if (!hmsi)
282         return r;
283     mpcfd = (void*) GetProcAddress( hmsi, "MsiProvideComponentFromDescriptorW" );
284     if (mpcfd)
285         r = mpcfd( szDescriptor, szCommandLine, pcchCommandLine, NULL );
286     FreeLibrary( hmsi );
287     return r;
288 }