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