advapi.c 9.1 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 32
#include "winerror.h"

33
#include "wine/library.h"
34
#include "wine/debug.h"
35

36
WINE_DEFAULT_DEBUG_CHANNEL(advapi);
37

38
/******************************************************************************
39
 * GetUserNameA [ADVAPI32.@]
40
 *
Jon Griffiths's avatar
Jon Griffiths committed
41 42 43 44 45 46 47 48 49
 * 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.
50
 */
51 52
BOOL WINAPI
GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
53
{
54 55
    WCHAR *buffer;
    BOOL ret;
56
    DWORD sizeW = *lpSize * 2;
57

58
    if (!(buffer = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) )))
59 60 61 62
    {
        SetLastError( ERROR_NOT_ENOUGH_MEMORY );
        return FALSE;
    }
63
    ret = GetUserNameW( buffer, &sizeW );
64 65 66 67 68 69 70 71 72
    if (ret)
    {
        if (!(*lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL )))
        {
            *lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
            SetLastError( ERROR_MORE_DATA );
            ret = FALSE;
        }
    }
73
    else *lpSize = sizeW * 2;
74 75
    HeapFree( GetProcessHeap(), 0, buffer );
    return ret;
76 77
}

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

89 90 91 92 93 94 95 96
    if (len > *lpSize)
    {
        SetLastError(ERROR_MORE_DATA);
        *lpSize = len;
        return FALSE;
    }

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

    /* Word uses the user name to create named mutexes and file mappings,
     * and backslashes in the name cause the creation to fail.
     */
    for (i = 0; lpszName[i]; i++)
        if (lpszName[i] == '\\' || lpszName[i] == '/') lpszName[i] = '_';
104
    return TRUE;
105
}
106

107 108
/******************************************************************************
 * GetCurrentHwProfileA [ADVAPI32.@]
Jon Griffiths's avatar
Jon Griffiths committed
109 110 111 112 113 114 115 116 117
 *
 * 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.
118
 */
Jon Griffiths's avatar
Jon Griffiths committed
119
BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA pInfo)
120
{
Jon Griffiths's avatar
Jon Griffiths committed
121 122 123 124
	FIXME("(%p) semi-stub\n", pInfo);
	pInfo->dwDockInfo = DOCKINFO_DOCKED;
	strcpy(pInfo->szHwProfileGuid,"{12340001-1234-1234-1234-1233456789012}");
	strcpy(pInfo->szHwProfileName,"Wine Profile");
125 126 127
	return 1;
}

128 129 130 131 132
/******************************************************************************
 * GetCurrentHwProfileW [ADVAPI32.@]
 *
 * See GetCurrentHwProfileA.
 */
133 134 135 136 137 138
BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW pInfo)
{
       FIXME("(%p)\n", pInfo);
       return FALSE;
}

139 140 141 142 143 144 145 146 147 148

/**************************************************************************
 *	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
149 150 151
 *
 * RETURNS
 *  TRUE if the buffer is likely Unicode, FALSE otherwise.
152 153 154 155 156 157 158
 */
BOOL WINAPI IsTextUnicode( LPCVOID buf, INT len, LPINT flags )
{
    return RtlIsTextUnicode( buf, len, flags );
}


159 160 161
/******************************************************************************
 * AbortSystemShutdownA [ADVAPI32.@]
 *
Jon Griffiths's avatar
Jon Griffiths committed
162 163
 * Stop a system shutdown if one is in progress.
 *
164
 * PARAMS
Jon Griffiths's avatar
Jon Griffiths committed
165 166 167 168 169 170 171 172
 *  lpMachineName [I] Name of machine to not shutdown.
 *
 * RETURNS
 *  Success: TRUE.
 *  Failure: FALSE.
 *
 * NOTES
 *  The Wine implementation of this function is a harmless stub.
173 174 175 176 177 178 179 180 181 182
 */
BOOL WINAPI AbortSystemShutdownA( LPSTR lpMachineName )
{
    TRACE("stub %s (harmless)\n", lpMachineName);
    return TRUE;
}

/******************************************************************************
 * AbortSystemShutdownW [ADVAPI32.@]
 *
Jon Griffiths's avatar
Jon Griffiths committed
183
 * See AbortSystemShutdownA.
184
 */
185
BOOL WINAPI AbortSystemShutdownW( LPWSTR lpMachineName )
186 187 188 189
{
    TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName));
    return TRUE;
}
190 191 192

/******************************************************************************
 * InitiateSystemShutdownExA [ADVAPI32.@]
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
 *
 * 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.
214 215 216 217 218
 */
BOOL WINAPI InitiateSystemShutdownExA( LPSTR lpMachineName, LPSTR lpMessage,
         DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
         DWORD dwReason)
{
219
     FIXME("%s %s %d %d %d %d\n", debugstr_a(lpMachineName),
220 221 222 223 224 225
            debugstr_a(lpMessage), dwTimeout, bForceAppsClosed,
            bRebootAfterShutdown, dwReason);
     return TRUE;
} 

/******************************************************************************
226 227
 * InitiateSystemShutdownExW [ADVAPI32.@]
 *
228
 * See InitiateSystemShutdownExA.
229 230 231 232 233
 */
BOOL WINAPI InitiateSystemShutdownExW( LPWSTR lpMachineName, LPWSTR lpMessage,
         DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
         DWORD dwReason)
{
234
     FIXME("%s %s %d %d %d %d\n", debugstr_w(lpMachineName),
235 236 237 238
            debugstr_w(lpMessage), dwTimeout, bForceAppsClosed,
            bRebootAfterShutdown, dwReason);
     return TRUE;
} 
239

240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
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 );
}

BOOL WINAPI LogonUserA( LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
                        DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
{
259
    FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_a(lpszUsername),
260 261 262 263 264 265 266 267
          debugstr_a(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);

    return TRUE;
}

BOOL WINAPI LogonUserW( LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword,
                        DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
{
268
    FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_w(lpszUsername),
269 270 271 272 273
          debugstr_w(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);

    return TRUE;
}

274 275 276 277
typedef UINT (WINAPI *fnMsiProvideComponentFromDescriptor)(LPCWSTR,LPWSTR,DWORD*,DWORD*);

DWORD WINAPI CommandLineFromMsiDescriptor( WCHAR *szDescriptor,
                    WCHAR *szCommandLine, DWORD *pcchCommandLine )
278
{
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
    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;
    mpcfd = (void*) GetProcAddress( hmsi, "MsiProvideComponentFromDescriptorW" );
    if (mpcfd)
        r = mpcfd( szDescriptor, szCommandLine, pcchCommandLine, NULL );
    FreeLibrary( hmsi );
    return r;
294
}