2 * Win32 advapi functions
4 * Copyright 1995 Sven Verdoolaege
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.
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.
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
35 #include "wine/library.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 #include "advapi32_misc.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
43 /******************************************************************************
44 * GetUserNameA [ADVAPI32.@]
46 * Get the current user name.
49 * lpszName [O] Destination for the user name.
50 * lpSize [I/O] Size of lpszName.
53 * Success: The length of the user name, including terminating NUL.
54 * Failure: ERROR_MORE_DATA if *lpSize is too small.
57 GetUserNameA( LPSTR lpszName
, LPDWORD lpSize
)
61 DWORD sizeW
= *lpSize
;
63 if (!(buffer
= heap_alloc( sizeW
* sizeof(WCHAR
) )))
65 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
69 ret
= GetUserNameW( buffer
, &sizeW
);
71 *lpSize
= WideCharToMultiByte( CP_ACP
, 0, buffer
, -1, lpszName
, *lpSize
, NULL
, NULL
);
79 /******************************************************************************
80 * GetUserNameW [ADVAPI32.@]
85 GetUserNameW( LPWSTR lpszName
, LPDWORD lpSize
)
87 const char *name
= wine_get_user_name();
88 DWORD i
, len
= MultiByteToWideChar( CP_UNIXCP
, 0, name
, -1, NULL
, 0 );
93 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
99 MultiByteToWideChar( CP_UNIXCP
, 0, name
, -1, lpszName
, len
);
101 /* Word uses the user name to create named mutexes and file mappings,
102 * and backslashes in the name cause the creation to fail.
103 * Also, Windows doesn't return the domain name in the user name even when
104 * joined to a domain. A Unix box joined to a domain using winbindd will
105 * contain the domain name in the username. So we need to cut this off.
106 * FIXME: Only replaces forward and backslashes for now, should get the
107 * winbind separator char from winbindd and replace that.
109 for (i
= 0; lpszName
[i
]; i
++)
110 if (lpszName
[i
] == '/') lpszName
[i
] = '\\';
112 backslash
= strrchrW(lpszName
, '\\');
113 if (backslash
== NULL
)
116 len
= lstrlenW(backslash
);
117 memmove(lpszName
, backslash
+ 1, len
* sizeof(WCHAR
));
122 /******************************************************************************
123 * GetCurrentHwProfileA [ADVAPI32.@]
125 * Get the current hardware profile.
128 * pInfo [O] Destination for hardware profile information.
131 * Success: TRUE. pInfo is updated with the hardware profile details.
134 BOOL WINAPI
GetCurrentHwProfileA(LPHW_PROFILE_INFOA pInfo
)
136 FIXME("(%p) semi-stub\n", pInfo
);
137 pInfo
->dwDockInfo
= DOCKINFO_DOCKED
;
138 strcpy(pInfo
->szHwProfileGuid
,"{12340001-1234-1234-1234-123456789012}");
139 strcpy(pInfo
->szHwProfileName
,"Wine Profile");
143 /******************************************************************************
144 * GetCurrentHwProfileW [ADVAPI32.@]
146 * See GetCurrentHwProfileA.
148 BOOL WINAPI
GetCurrentHwProfileW(LPHW_PROFILE_INFOW pInfo
)
150 FIXME("(%p)\n", pInfo
);
155 /**************************************************************************
156 * IsTextUnicode (ADVAPI32.@)
158 * Attempt to guess whether a text buffer is Unicode.
161 * buf [I] Text buffer to test
162 * len [I] Length of buf
163 * flags [O] Destination for test results
166 * TRUE if the buffer is likely Unicode, FALSE otherwise.
168 BOOL WINAPI
IsTextUnicode( LPCVOID buf
, INT len
, LPINT flags
)
170 return RtlIsTextUnicode( buf
, len
, flags
);
174 /******************************************************************************
175 * AbortSystemShutdownA [ADVAPI32.@]
177 * Stop a system shutdown if one is in progress.
180 * lpMachineName [I] Name of machine to not shutdown.
187 * The Wine implementation of this function is a harmless stub.
189 BOOL WINAPI
AbortSystemShutdownA( LPSTR lpMachineName
)
191 TRACE("stub %s (harmless)\n", lpMachineName
);
195 /******************************************************************************
196 * AbortSystemShutdownW [ADVAPI32.@]
198 * See AbortSystemShutdownA.
200 BOOL WINAPI
AbortSystemShutdownW( LPWSTR lpMachineName
)
202 TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName
));
206 /******************************************************************************
207 * InitiateSystemShutdownExA [ADVAPI32.@]
209 * Initiate a shutdown or optionally restart the computer.
212 * lpMachineName [I] Network name of machine to shutdown.
213 * lpMessage [I] Message displayed in shutdown dialog box.
214 * dwTimeout [I] Number of seconds dialog is displayed before shutdown.
215 * bForceAppsClosed [I] If TRUE, apps close without saving, else dialog is
216 * displayed requesting user to close apps.
217 * bRebootAfterShutdown [I] If TRUE, system reboots after restart, else the
218 * system flushes all caches to disk and clears
220 * dwReason [I] Reason for shutting down. Must be a system shutdown reason
228 * if lpMachineName is NULL, the local computer is shutdown.
230 BOOL WINAPI
InitiateSystemShutdownExA( LPSTR lpMachineName
, LPSTR lpMessage
,
231 DWORD dwTimeout
, BOOL bForceAppsClosed
, BOOL bRebootAfterShutdown
,
234 FIXME("%s %s %d %d %d %d\n", debugstr_a(lpMachineName
),
235 debugstr_a(lpMessage
), dwTimeout
, bForceAppsClosed
,
236 bRebootAfterShutdown
, dwReason
);
240 /******************************************************************************
241 * InitiateSystemShutdownExW [ADVAPI32.@]
243 * See InitiateSystemShutdownExA.
245 BOOL WINAPI
InitiateSystemShutdownExW( LPWSTR lpMachineName
, LPWSTR lpMessage
,
246 DWORD dwTimeout
, BOOL bForceAppsClosed
, BOOL bRebootAfterShutdown
,
249 FIXME("%s %s %d %d %d %d\n", debugstr_w(lpMachineName
),
250 debugstr_w(lpMessage
), dwTimeout
, bForceAppsClosed
,
251 bRebootAfterShutdown
, dwReason
);
255 BOOL WINAPI
InitiateSystemShutdownA( LPSTR lpMachineName
, LPSTR lpMessage
, DWORD dwTimeout
,
256 BOOL bForceAppsClosed
, BOOL bRebootAfterShutdown
)
258 return InitiateSystemShutdownExA( lpMachineName
, lpMessage
, dwTimeout
,
259 bForceAppsClosed
, bRebootAfterShutdown
,
260 SHTDN_REASON_MAJOR_LEGACY_API
);
263 BOOL WINAPI
InitiateSystemShutdownW( LPWSTR lpMachineName
, LPWSTR lpMessage
, DWORD dwTimeout
,
264 BOOL bForceAppsClosed
, BOOL bRebootAfterShutdown
)
266 return InitiateSystemShutdownExW( lpMachineName
, lpMessage
, dwTimeout
,
267 bForceAppsClosed
, bRebootAfterShutdown
,
268 SHTDN_REASON_MAJOR_LEGACY_API
);
271 BOOL WINAPI
LogonUserA( LPCSTR lpszUsername
, LPCSTR lpszDomain
, LPCSTR lpszPassword
,
272 DWORD dwLogonType
, DWORD dwLogonProvider
, PHANDLE phToken
)
274 WCHAR
*usernameW
= NULL
, *domainW
= NULL
, *passwordW
= NULL
;
277 TRACE("%s %s %p 0x%08x 0x%08x %p\n", debugstr_a(lpszUsername
),
278 debugstr_a(lpszDomain
), lpszPassword
, dwLogonType
, dwLogonProvider
, phToken
);
280 if (lpszUsername
&& !(usernameW
= strdupAW( lpszUsername
))) return FALSE
;
281 if (lpszDomain
&& !(domainW
= strdupAW( lpszUsername
))) goto done
;
282 if (lpszPassword
&& !(passwordW
= strdupAW( lpszPassword
))) goto done
;
284 ret
= LogonUserW( usernameW
, domainW
, passwordW
, dwLogonType
, dwLogonProvider
, phToken
);
287 heap_free( usernameW
);
288 heap_free( domainW
);
289 heap_free( passwordW
);
293 BOOL WINAPI
LogonUserW( LPCWSTR lpszUsername
, LPCWSTR lpszDomain
, LPCWSTR lpszPassword
,
294 DWORD dwLogonType
, DWORD dwLogonProvider
, PHANDLE phToken
)
296 FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_w(lpszUsername
),
297 debugstr_w(lpszDomain
), lpszPassword
, dwLogonType
, dwLogonProvider
, phToken
);
299 *phToken
= (HANDLE
*)0xdeadbeef;
303 typedef UINT (WINAPI
*fnMsiProvideComponentFromDescriptor
)(LPCWSTR
,LPWSTR
,DWORD
*,DWORD
*);
305 DWORD WINAPI
CommandLineFromMsiDescriptor( WCHAR
*szDescriptor
,
306 WCHAR
*szCommandLine
, DWORD
*pcchCommandLine
)
308 static const WCHAR szMsi
[] = { 'm','s','i',0 };
309 fnMsiProvideComponentFromDescriptor mpcfd
;
311 UINT r
= ERROR_CALL_NOT_IMPLEMENTED
;
313 TRACE("%s %p %p\n", debugstr_w(szDescriptor
), szCommandLine
, pcchCommandLine
);
315 hmsi
= LoadLibraryW( szMsi
);
318 mpcfd
= (fnMsiProvideComponentFromDescriptor
)GetProcAddress( hmsi
,
319 "MsiProvideComponentFromDescriptorW" );
321 r
= mpcfd( szDescriptor
, szCommandLine
, pcchCommandLine
, NULL
);
326 /***********************************************************************
327 * RegisterWaitChainCOMCallback (ole32.@)
329 void WINAPI
RegisterWaitChainCOMCallback(PCOGETCALLSTATE call_state_cb
,
330 PCOGETACTIVATIONSTATE activation_state_cb
)
332 FIXME("%p, %p\n", call_state_cb
, activation_state_cb
);