advapi.c 11.2 KB
Newer Older
1 2 3 4
/*
 * Win32 advapi functions
 *
 * Copyright 1995 Sven Verdoolaege
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
#include "wct.h"
34

35
#include "wine/library.h"
36
#include "wine/unicode.h"
37
#include "wine/debug.h"
38

39 40
#include "advapi32_misc.h"

41
WINE_DEFAULT_DEBUG_CHANNEL(advapi);
42

43
/******************************************************************************
44
 * GetUserNameA [ADVAPI32.@]
45
 *
Jon Griffiths's avatar
Jon Griffiths committed
46 47 48 49 50 51 52 53 54
 * Get the current user name.
 *
 * PARAMS
 *  lpszName [O]   Destination for the user name.
 *  lpSize   [I/O] Size of lpszName.
 *
 * RETURNS
 *  Success: The length of the user name, including terminating NUL.
 *  Failure: ERROR_MORE_DATA if *lpSize is too small.
55
 */
56 57
BOOL WINAPI
GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
58
{
59 60
    WCHAR *buffer;
    BOOL ret;
61
    DWORD sizeW = *lpSize;
62

63
    if (!(buffer = heap_alloc( sizeW * sizeof(WCHAR) )))
64 65 66 67
    {
        SetLastError( ERROR_NOT_ENOUGH_MEMORY );
        return FALSE;
    }
68

69
    ret = GetUserNameW( buffer, &sizeW );
70
    if (ret)
71
        *lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL );
72 73 74
    else
        *lpSize = sizeW;

75
    heap_free( buffer );
76
    return ret;
77 78
}

79
/******************************************************************************
80
 * GetUserNameW [ADVAPI32.@]
81
 *
Jon Griffiths's avatar
Jon Griffiths committed
82
 * See GetUserNameA.
83
 */
84 85
BOOL WINAPI
GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
86
{
87
    const char *name = wine_get_user_name();
88
    DWORD i, len = MultiByteToWideChar( CP_UNIXCP, 0, name, -1, NULL, 0 );
89
    LPWSTR backslash;
90

91 92
    if (len > *lpSize)
    {
93
        SetLastError( ERROR_INSUFFICIENT_BUFFER );
94 95 96 97 98
        *lpSize = len;
        return FALSE;
    }

    *lpSize = len;
99
    MultiByteToWideChar( CP_UNIXCP, 0, name, -1, lpszName, len );
100 101 102

    /* Word uses the user name to create named mutexes and file mappings,
     * and backslashes in the name cause the creation to fail.
103 104 105 106 107
     * Also, Windows doesn't return the domain name in the user name even when
     * joined to a domain. A Unix box joined to a domain using winbindd will
     * contain the domain name in the username. So we need to cut this off.
     * FIXME: Only replaces forward and backslashes for now, should get the
     * winbind separator char from winbindd and replace that.
108 109
     */
    for (i = 0; lpszName[i]; i++)
110 111 112 113 114 115 116 117 118
        if (lpszName[i] == '/') lpszName[i] = '\\';

    backslash = strrchrW(lpszName, '\\');
    if (backslash == NULL)
        return TRUE;

    len = lstrlenW(backslash);
    memmove(lpszName, backslash + 1, len * sizeof(WCHAR));
    *lpSize = len;
119
    return TRUE;
120
}
121

122 123
/******************************************************************************
 * GetCurrentHwProfileA [ADVAPI32.@]
Jon Griffiths's avatar
Jon Griffiths committed
124 125 126 127 128 129 130 131 132
 *
 * Get the current hardware profile.
 *
 * PARAMS
 *  pInfo [O] Destination for hardware profile information.
 *
 * RETURNS
 *  Success: TRUE. pInfo is updated with the hardware profile details.
 *  Failure: FALSE.
133
 */
Jon Griffiths's avatar
Jon Griffiths committed
134
BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA pInfo)
135
{
Jon Griffiths's avatar
Jon Griffiths committed
136 137
	FIXME("(%p) semi-stub\n", pInfo);
	pInfo->dwDockInfo = DOCKINFO_DOCKED;
Andrew Talbot's avatar
Andrew Talbot committed
138
	strcpy(pInfo->szHwProfileGuid,"{12340001-1234-1234-1234-123456789012}");
Jon Griffiths's avatar
Jon Griffiths committed
139
	strcpy(pInfo->szHwProfileName,"Wine Profile");
140
	return TRUE;
141 142
}

143 144 145 146 147
/******************************************************************************
 * GetCurrentHwProfileW [ADVAPI32.@]
 *
 * See GetCurrentHwProfileA.
 */
148 149 150 151 152 153
BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW pInfo)
{
       FIXME("(%p)\n", pInfo);
       return FALSE;
}

154 155 156 157 158 159 160 161 162 163

/**************************************************************************
 *	IsTextUnicode (ADVAPI32.@)
 *
 * Attempt to guess whether a text buffer is Unicode.
 *
 * PARAMS
 *  buf   [I] Text buffer to test
 *  len   [I] Length of buf
 *  flags [O] Destination for test results
164 165 166
 *
 * RETURNS
 *  TRUE if the buffer is likely Unicode, FALSE otherwise.
167 168 169 170 171 172 173
 */
BOOL WINAPI IsTextUnicode( LPCVOID buf, INT len, LPINT flags )
{
    return RtlIsTextUnicode( buf, len, flags );
}


174 175 176
/******************************************************************************
 * AbortSystemShutdownA [ADVAPI32.@]
 *
Jon Griffiths's avatar
Jon Griffiths committed
177 178
 * Stop a system shutdown if one is in progress.
 *
179
 * PARAMS
Jon Griffiths's avatar
Jon Griffiths committed
180 181 182 183 184 185 186 187
 *  lpMachineName [I] Name of machine to not shutdown.
 *
 * RETURNS
 *  Success: TRUE.
 *  Failure: FALSE.
 *
 * NOTES
 *  The Wine implementation of this function is a harmless stub.
188 189 190
 */
BOOL WINAPI AbortSystemShutdownA( LPSTR lpMachineName )
{
191
    TRACE("stub %s (harmless)\n", debugstr_a(lpMachineName));
192 193 194 195 196 197
    return TRUE;
}

/******************************************************************************
 * AbortSystemShutdownW [ADVAPI32.@]
 *
Jon Griffiths's avatar
Jon Griffiths committed
198
 * See AbortSystemShutdownA.
199
 */
200
BOOL WINAPI AbortSystemShutdownW( LPWSTR lpMachineName )
201 202 203 204
{
    TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName));
    return TRUE;
}
205 206 207

/******************************************************************************
 * InitiateSystemShutdownExA [ADVAPI32.@]
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
 *
 * Initiate a shutdown or optionally restart the computer.
 *
 * PARAMS
 *  lpMachineName    [I] Network name of machine to shutdown.
 *  lpMessage        [I] Message displayed in shutdown dialog box.
 *  dwTimeout        [I] Number of seconds dialog is displayed before shutdown.
 *  bForceAppsClosed [I] If TRUE, apps close without saving, else dialog is
 *                       displayed requesting user to close apps.
 *  bRebootAfterShutdown [I] If TRUE, system reboots after restart, else the
 *                           system flushes all caches to disk and clears
 *                           the screen
 *  dwReason [I] Reason for shutting down.  Must be a system shutdown reason
 *               code.
 *
 *  RETURNS
 *   Success: TRUE
 *   Failure: FALSE
 *
 *  NOTES
 *   if lpMachineName is NULL, the local computer is shutdown.
229 230 231 232 233
 */
BOOL WINAPI InitiateSystemShutdownExA( LPSTR lpMachineName, LPSTR lpMessage,
         DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
         DWORD dwReason)
{
234
     FIXME("%s %s %d %d %d %#x\n", debugstr_a(lpMachineName),
235 236 237 238 239 240
            debugstr_a(lpMessage), dwTimeout, bForceAppsClosed,
            bRebootAfterShutdown, dwReason);
     return TRUE;
} 

/******************************************************************************
241 242
 * InitiateSystemShutdownExW [ADVAPI32.@]
 *
243
 * See InitiateSystemShutdownExA.
244 245 246 247 248
 */
BOOL WINAPI InitiateSystemShutdownExW( LPWSTR lpMachineName, LPWSTR lpMessage,
         DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
         DWORD dwReason)
{
249
     FIXME("%s %s %d %d %d %#x\n", debugstr_w(lpMachineName),
250 251 252 253
            debugstr_w(lpMessage), dwTimeout, bForceAppsClosed,
            bRebootAfterShutdown, dwReason);
     return TRUE;
} 
254

255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
BOOL WINAPI InitiateSystemShutdownA( LPSTR lpMachineName, LPSTR lpMessage, DWORD dwTimeout,
                                     BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
{
    return InitiateSystemShutdownExA( lpMachineName, lpMessage, dwTimeout,
                                      bForceAppsClosed, bRebootAfterShutdown,
                                      SHTDN_REASON_MAJOR_LEGACY_API );
}

BOOL WINAPI InitiateSystemShutdownW( LPWSTR lpMachineName, LPWSTR lpMessage, DWORD dwTimeout,
                                     BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
{
    return InitiateSystemShutdownExW( lpMachineName, lpMessage, dwTimeout,
                                      bForceAppsClosed, bRebootAfterShutdown,
                                      SHTDN_REASON_MAJOR_LEGACY_API );
}

271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
/***********************************************************************
 *     InitiateShutdownA [ADVAPI32.@]
 */
DWORD WINAPI InitiateShutdownA(char *name, char *message, DWORD seconds, DWORD flags, DWORD reason)
{
    FIXME("%s, %s, %d, %d, %d stub\n", debugstr_a(name), debugstr_a(message), seconds, flags, reason);
    return ERROR_CALL_NOT_IMPLEMENTED;
}

/***********************************************************************
 *     InitiateShutdownW [ADVAPI32.@]
 */
DWORD WINAPI InitiateShutdownW(WCHAR *name, WCHAR *message, DWORD seconds, DWORD flags, DWORD reason)
{
    FIXME("%s, %s, %d, %d, %d stub\n", debugstr_w(name), debugstr_w(message), seconds, flags, reason);
    return ERROR_CALL_NOT_IMPLEMENTED;
}

289 290 291
BOOL WINAPI LogonUserA( LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
                        DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
{
292 293 294 295
    WCHAR *usernameW = NULL, *domainW = NULL, *passwordW = NULL;
    BOOL ret = FALSE;

    TRACE("%s %s %p 0x%08x 0x%08x %p\n", debugstr_a(lpszUsername),
296 297
          debugstr_a(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);

298 299 300 301 302 303 304 305 306 307 308
    if (lpszUsername && !(usernameW = strdupAW( lpszUsername ))) return FALSE;
    if (lpszDomain && !(domainW = strdupAW( lpszUsername ))) goto done;
    if (lpszPassword && !(passwordW = strdupAW( lpszPassword ))) goto done;

    ret = LogonUserW( usernameW, domainW, passwordW, dwLogonType, dwLogonProvider, phToken );

done:
    heap_free( usernameW );
    heap_free( domainW );
    heap_free( passwordW );
    return ret;
309 310 311 312 313
}

BOOL WINAPI LogonUserW( LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword,
                        DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
{
314
    FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_w(lpszUsername),
315 316
          debugstr_w(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);

317
    *phToken = (HANDLE *)0xdeadbeef;
318 319 320
    return TRUE;
}

321 322 323 324
typedef UINT (WINAPI *fnMsiProvideComponentFromDescriptor)(LPCWSTR,LPWSTR,DWORD*,DWORD*);

DWORD WINAPI CommandLineFromMsiDescriptor( WCHAR *szDescriptor,
                    WCHAR *szCommandLine, DWORD *pcchCommandLine )
325
{
326 327 328 329 330 331 332 333 334 335
    static const WCHAR szMsi[] = { 'm','s','i',0 };
    fnMsiProvideComponentFromDescriptor mpcfd;
    HMODULE hmsi;
    UINT r = ERROR_CALL_NOT_IMPLEMENTED;

    TRACE("%s %p %p\n", debugstr_w(szDescriptor), szCommandLine, pcchCommandLine);

    hmsi = LoadLibraryW( szMsi );
    if (!hmsi)
        return r;
336 337
    mpcfd = (fnMsiProvideComponentFromDescriptor)GetProcAddress( hmsi,
                                                                 "MsiProvideComponentFromDescriptorW" );
338 339 340 341
    if (mpcfd)
        r = mpcfd( szDescriptor, szCommandLine, pcchCommandLine, NULL );
    FreeLibrary( hmsi );
    return r;
342
}
343 344 345 346 347 348 349 350 351

/***********************************************************************
 *      RegisterWaitChainCOMCallback (ole32.@)
 */
void WINAPI RegisterWaitChainCOMCallback(PCOGETCALLSTATE call_state_cb,
                                         PCOGETACTIVATIONSTATE activation_state_cb)
{
    FIXME("%p, %p\n", call_state_cb, activation_state_cb);
}