access.c 7.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright 2002 Andriy Palamarchuk
 *
 * Conformance test of the access functions.
 *
 * 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 22
#include <stdarg.h>

23
#include <wine/test.h>
24
#include <windef.h>
25 26 27 28 29 30 31 32 33
#include <winbase.h>
#include <winerror.h>
#include <lmaccess.h>
#include <lmerr.h>
#include <lmapibuf.h>

WCHAR user_name[UNLEN + 1];
WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];

34
static const WCHAR sAdminUserName[] = {'A','d','m','i','n','i','s','t','r','a','t',
35
                                'o','r',0};
36 37
static const WCHAR sGuestUserName[] = {'G','u','e','s','t',0};
static const WCHAR sNonexistentUser[] = {'N','o','n','e','x','i','s','t','e','n','t',' ',
38
                                'U','s','e','r',0};
39 40 41 42
static const WCHAR sBadNetPath[] = {'\\','\\','B','a',' ',' ','p','a','t','h',0};
static const WCHAR sInvalidName[] = {'\\',0};
static const WCHAR sInvalidName2[] = {'\\','\\',0};
static const WCHAR sEmptyStr[] = { 0 };
43

44 45 46 47
static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)=NULL;
static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD)=NULL;
static NET_API_STATUS (WINAPI *pNetQueryDisplayInformation)(LPWSTR,DWORD,DWORD,DWORD,DWORD,LPDWORD,PVOID*)=NULL;
static NET_API_STATUS (WINAPI *pNetUserGetInfo)(LPCWSTR,LPCWSTR,DWORD,LPBYTE*)=NULL;
48
static NET_API_STATUS (WINAPI *pNetUserModalsGet)(LPCWSTR,DWORD,LPBYTE*)=NULL;
49

50
static int init_access_tests(void)
51 52
{
    DWORD dwSize;
53
    BOOL rc;
54 55 56

    user_name[0] = 0;
    dwSize = sizeof(user_name);
57 58 59
    rc=GetUserNameW(user_name, &dwSize);
    if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
        return 0;
60
    ok(rc, "User Name Retrieved\n");
61 62 63

    computer_name[0] = 0;
    dwSize = sizeof(computer_name);
64
    ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved\n");
65
    return 1;
66 67
}

68
static void run_usergetinfo_tests(void)
69
{
70
    NET_API_STATUS rc;
71 72 73 74
    PUSER_INFO_0 ui0 = NULL;
    PUSER_INFO_10 ui10 = NULL;
    DWORD dwSize;

75 76 77 78
    /* If this one is not defined then none of the others will be defined */
    if (!pNetUserGetInfo)
        return;

79
    /* Level 0 */
80
    rc=pNetUserGetInfo(NULL, sAdminUserName, 0, (LPBYTE *)&ui0);
81
    if (rc != NERR_Success) {
82
        trace ("Aborting usergetinfo_tests().   NetUserGetInfo: rc=%d\n", rc);
83 84
	return;
    }
85
    ok(!lstrcmpW(sAdminUserName, ui0->usri0_name), "This is really user name\n");
86
    pNetApiBufferSize(ui0, &dwSize);
87 88
    ok(dwSize >= (sizeof(USER_INFO_0) +
                  (lstrlenW(ui0->usri0_name) + 1) * sizeof(WCHAR)),
89
       "Is allocated with NetApiBufferAllocate\n");
90 91

    /* Level 10 */
92
    rc=pNetUserGetInfo(NULL, sAdminUserName, 10, (LPBYTE *)&ui10);
93
    ok(rc == NERR_Success, "NetUserGetInfo: rc=%d\n", rc);
94
    ok(!lstrcmpW(sAdminUserName, ui10->usri10_name), "This is really user name\n");
95
    pNetApiBufferSize(ui10, &dwSize);
96 97 98 99 100
    ok(dwSize >= (sizeof(USER_INFO_10) +
                  (lstrlenW(ui10->usri10_name) + 1 +
                   lstrlenW(ui10->usri10_comment) + 1 +
                   lstrlenW(ui10->usri10_usr_comment) + 1 +
                   lstrlenW(ui10->usri10_full_name) + 1) * sizeof(WCHAR)),
101
       "Is allocated with NetApiBufferAllocate\n");
102

103 104
    pNetApiBufferFree(ui0);
    pNetApiBufferFree(ui10);
105 106

    /* errors handling */
107
    rc=pNetUserGetInfo(NULL, sAdminUserName, 10000, (LPBYTE *)&ui0);
108
    ok(rc == ERROR_INVALID_LEVEL,"Invalid Level: rc=%d\n",rc);
109
    rc=pNetUserGetInfo(NULL, sNonexistentUser, 0, (LPBYTE *)&ui0);
110
    ok(rc == NERR_UserNotFound,"Invalid User Name: rc=%d\n",rc);
111 112
    todo_wine {
        /* FIXME - Currently Wine can't verify whether the network path is good or bad */
113
        rc=pNetUserGetInfo(sBadNetPath, sAdminUserName, 0, (LPBYTE *)&ui0);
114
        ok(rc == ERROR_BAD_NETPATH || rc == ERROR_NETWORK_UNREACHABLE,
115
           "Bad Network Path: rc=%d\n",rc);
116
    }
117
    rc=pNetUserGetInfo(sEmptyStr, sAdminUserName, 0, (LPBYTE *)&ui0);
118
    ok(rc == ERROR_BAD_NETPATH || rc == NERR_Success,
119
       "Bad Network Path: rc=%d\n",rc);
120
    rc=pNetUserGetInfo(sInvalidName, sAdminUserName, 0, (LPBYTE *)&ui0);
121
    ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%d\n",rc);
122
    rc=pNetUserGetInfo(sInvalidName2, sAdminUserName, 0, (LPBYTE *)&ui0);
123
    ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%d\n",rc);
124 125 126
}

/* checks Level 1 of NetQueryDisplayInformation */
127
static void run_querydisplayinformation1_tests(void)
128 129 130 131 132 133 134
{
    PNET_DISPLAY_USER Buffer, rec;
    DWORD Result, EntryCount;
    DWORD i = 0;
    BOOL hasAdmin = FALSE;
    BOOL hasGuest = FALSE;

135 136 137
    if (!pNetQueryDisplayInformation)
        return;

138 139
    do
    {
140
        Result = pNetQueryDisplayInformation(
141 142 143 144
            NULL, 1, i, 1000, MAX_PREFERRED_LENGTH, &EntryCount,
            (PVOID *)&Buffer);

        ok((Result == ERROR_SUCCESS) || (Result == ERROR_MORE_DATA),
145
           "Information Retrieved\n");
146 147 148 149 150
        rec = Buffer;
        for(; EntryCount > 0; EntryCount--)
        {
            if (!lstrcmpW(rec->usri1_name, sAdminUserName))
            {
151 152 153
                ok(!hasAdmin, "One admin user\n");
                ok(rec->usri1_flags & UF_SCRIPT, "UF_SCRIPT flag is set\n");
                ok(rec->usri1_flags & UF_NORMAL_ACCOUNT, "UF_NORMAL_ACCOUNT flag is set\n");
154 155 156 157
                hasAdmin = TRUE;
            }
            else if (!lstrcmpW(rec->usri1_name, sGuestUserName))
            {
158 159 160
                ok(!hasGuest, "One guest record\n");
                ok(rec->usri1_flags & UF_SCRIPT, "UF_SCRIPT flag is set\n");
                ok(rec->usri1_flags & UF_NORMAL_ACCOUNT, "UF_NORMAL_ACCOUNT flag is set\n");
161 162 163 164 165 166 167
                hasGuest = TRUE;
            }

            i = rec->usri1_next_index;
            rec++;
        }

168
        pNetApiBufferFree(Buffer);
169 170
    } while (Result == ERROR_MORE_DATA);

171
    ok(hasAdmin, "Has Administrator account\n");
172 173
}

174 175 176 177 178 179
static void run_usermodalsget_tests(void)
{
    NET_API_STATUS rc;
    USER_MODALS_INFO_2 * umi2 = NULL;

    rc = pNetUserModalsGet(NULL, 2, (LPBYTE *)&umi2);
180
    ok(rc == ERROR_SUCCESS, "NetUserModalsGet failed, rc = %d\n", rc);
181 182 183 184 185

    if (umi2)
        pNetApiBufferFree(umi2);
}

186 187
START_TEST(access)
{
188 189 190 191 192
    HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
    pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
    pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
    pNetQueryDisplayInformation=(void*)GetProcAddress(hnetapi32,"NetQueryDisplayInformation");
    pNetUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetUserGetInfo");
193 194
    pNetUserModalsGet=(void*)GetProcAddress(hnetapi32,"NetUserModalsGet");

195 196 197 198 199 200
    if (!pNetApiBufferSize)
        trace("It appears there is no netapi32 functionality on this platform\n");

    if (init_access_tests()) {
        run_usergetinfo_tests();
        run_querydisplayinformation1_tests();
201
        run_usermodalsget_tests();
202
    }
203
}