advapi.c 9.62 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

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

60
    if (!(buffer = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) )))
61 62 63 64
    {
        SetLastError( ERROR_NOT_ENOUGH_MEMORY );
        return FALSE;
    }
65

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

72 73
    HeapFree( GetProcessHeap(), 0, buffer );
    return ret;
74 75
}

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

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

    *lpSize = len;
96
    MultiByteToWideChar( CP_UNIXCP, 0, name, -1, lpszName, len );
97 98 99

    /* Word uses the user name to create named mutexes and file mappings,
     * and backslashes in the name cause the creation to fail.
100 101 102 103 104
     * 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.
105 106
     */
    for (i = 0; lpszName[i]; i++)
107 108 109 110 111 112 113 114 115
        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;
116
    return TRUE;
117
}
118

119 120
/******************************************************************************
 * GetCurrentHwProfileA [ADVAPI32.@]
Jon Griffiths's avatar
Jon Griffiths committed
121 122 123 124 125 126 127 128 129
 *
 * 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.
130
 */
Jon Griffiths's avatar
Jon Griffiths committed
131
BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA pInfo)
132
{
Jon Griffiths's avatar
Jon Griffiths committed
133 134
	FIXME("(%p) semi-stub\n", pInfo);
	pInfo->dwDockInfo = DOCKINFO_DOCKED;
Andrew Talbot's avatar
Andrew Talbot committed
135
	strcpy(pInfo->szHwProfileGuid,"{12340001-1234-1234-1234-123456789012}");
Jon Griffiths's avatar
Jon Griffiths committed
136
	strcpy(pInfo->szHwProfileName,"Wine Profile");
137 138 139
	return 1;
}

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

151 152 153 154 155 156 157 158 159 160

/**************************************************************************
 *	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
161 162 163
 *
 * RETURNS
 *  TRUE if the buffer is likely Unicode, FALSE otherwise.
164 165 166 167 168 169 170
 */
BOOL WINAPI IsTextUnicode( LPCVOID buf, INT len, LPINT flags )
{
    return RtlIsTextUnicode( buf, len, flags );
}


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

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

/******************************************************************************
 * InitiateSystemShutdownExA [ADVAPI32.@]
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
 *
 * 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.
226 227 228 229 230
 */
BOOL WINAPI InitiateSystemShutdownExA( LPSTR lpMachineName, LPSTR lpMessage,
         DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
         DWORD dwReason)
{
231
     FIXME("%s %s %d %d %d %d\n", debugstr_a(lpMachineName),
232 233 234 235 236 237
            debugstr_a(lpMessage), dwTimeout, bForceAppsClosed,
            bRebootAfterShutdown, dwReason);
     return TRUE;
} 

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

252 253 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 );
}

BOOL WINAPI LogonUserA( LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
                        DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
{
271
    FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_a(lpszUsername),
272 273 274 275 276 277 278 279
          debugstr_a(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);

    return TRUE;
}

BOOL WINAPI LogonUserW( LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword,
                        DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
{
280
    FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_w(lpszUsername),
281 282 283 284 285
          debugstr_w(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);

    return TRUE;
}

286 287 288 289
typedef UINT (WINAPI *fnMsiProvideComponentFromDescriptor)(LPCWSTR,LPWSTR,DWORD*,DWORD*);

DWORD WINAPI CommandLineFromMsiDescriptor( WCHAR *szDescriptor,
                    WCHAR *szCommandLine, DWORD *pcchCommandLine )
290
{
291 292 293 294 295 296 297 298 299 300
    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;
301 302
    mpcfd = (fnMsiProvideComponentFromDescriptor)GetProcAddress( hmsi,
                                                                 "MsiProvideComponentFromDescriptorW" );
303 304 305 306
    if (mpcfd)
        r = mpcfd( szDescriptor, szCommandLine, pcchCommandLine, NULL );
    FreeLibrary( hmsi );
    return r;
307
}