/* * 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 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #include #include #include #include #include #include #include #include "wine/test.h" static WCHAR user_name[UNLEN + 1]; static WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1]; static WCHAR sTooLongName[] = L"This is a bad username"; static WCHAR sTooLongPassword[] = L"abcdefghabcdefghabcdefghabcdefghabcdefgh" "abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefgh" "abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefgh" "abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefgha"; static WCHAR sTestUserOldPass[] = L"OldPassW0rdSet!~"; static DWORD (WINAPI *pDavGetHTTPFromUNCPath)(LPCWSTR,LPWSTR,LPDWORD); static DWORD (WINAPI *pDavGetUNCFromHTTPPath)(LPCWSTR,LPWSTR,LPDWORD); static NET_API_STATUS create_test_user(void) { USER_INFO_1 usri; usri.usri1_name = (WCHAR *)L"testuser"; usri.usri1_password = sTestUserOldPass; usri.usri1_priv = USER_PRIV_USER; usri.usri1_home_dir = NULL; usri.usri1_comment = NULL; usri.usri1_flags = UF_SCRIPT; usri.usri1_script_path = NULL; return NetUserAdd(NULL, 1, (BYTE *)&usri, NULL); } static NET_API_STATUS delete_test_user(void) { return NetUserDel(NULL, L"testuser"); } static void run_usergetinfo_tests(void) { NET_API_STATUS rc; PUSER_INFO_0 ui0 = NULL; PUSER_INFO_10 ui10 = NULL; DWORD dwSize; if((rc = create_test_user()) != NERR_Success ) { skip("Skipping usergetinfo_tests, create_test_user failed: 0x%08x\n", rc); return; } /* Level 0 */ rc = NetUserGetInfo(NULL, L"testuser", 0, (BYTE **)&ui0); ok(rc == NERR_Success, "NetUserGetInfo level 0 failed: 0x%08x.\n", rc); ok(!wcscmp(L"testuser", ui0->usri0_name), "Got level 0 name %s.\n", debugstr_w(ui0->usri0_name)); NetApiBufferSize(ui0, &dwSize); ok(dwSize >= (sizeof(USER_INFO_0) + (wcslen(ui0->usri0_name) + 1) * sizeof(WCHAR)), "Is allocated with NetApiBufferAllocate\n"); /* Level 10 */ rc = NetUserGetInfo(NULL, L"testuser", 10, (BYTE **)&ui10); ok(rc == NERR_Success, "NetUserGetInfo level 10 failed: 0x%08x.\n", rc); ok(!wcscmp(L"testuser", ui10->usri10_name), "Got level 10 name %s.\n", debugstr_w(ui10->usri10_name)); NetApiBufferSize(ui10, &dwSize); ok(dwSize >= (sizeof(USER_INFO_10) + (wcslen(ui10->usri10_name) + 1 + wcslen(ui10->usri10_comment) + 1 + wcslen(ui10->usri10_usr_comment) + 1 + wcslen(ui10->usri10_full_name) + 1) * sizeof(WCHAR)), "Is allocated with NetApiBufferAllocate\n"); NetApiBufferFree(ui0); NetApiBufferFree(ui10); /* NetUserGetInfo should always work for the current user. */ rc = NetUserGetInfo(NULL, user_name, 0, (BYTE **)&ui0); ok(rc == NERR_Success, "NetUsetGetInfo for current user failed: 0x%08x.\n", rc); NetApiBufferFree(ui0); /* errors handling */ rc = NetUserGetInfo(NULL, L"testuser", 10000, (BYTE **)&ui0); ok(rc == ERROR_INVALID_LEVEL,"Invalid Level: rc=%d\n",rc); rc = NetUserGetInfo(NULL, L"Nonexistent User", 0, (BYTE **)&ui0); ok(rc == NERR_UserNotFound,"Invalid User Name: rc=%d\n",rc); todo_wine { /* FIXME - Currently Wine can't verify whether the network path is good or bad */ rc = NetUserGetInfo(L"\\\\Ba path", L"testuser", 0, (BYTE **)&ui0); ok(rc == ERROR_BAD_NETPATH || rc == ERROR_NETWORK_UNREACHABLE || rc == RPC_S_SERVER_UNAVAILABLE || rc == NERR_WkstaNotStarted || /* workstation service not running */ rc == RPC_S_INVALID_NET_ADDR, /* Some Win7 */ "Bad Network Path: rc=%d\n",rc); } rc = NetUserGetInfo(L"", L"testuser", 0, (BYTE **)&ui0); ok(rc == ERROR_BAD_NETPATH || rc == NERR_Success, "Bad Network Path: rc=%d\n",rc); rc = NetUserGetInfo(L"\\", L"testuser", 0, (BYTE **)&ui0); ok(rc == ERROR_INVALID_NAME || rc == ERROR_INVALID_HANDLE,"Invalid Server Name: rc=%d\n",rc); rc = NetUserGetInfo(L"\\\\", L"testuser", 0, (BYTE **)&ui0); ok(rc == ERROR_INVALID_NAME || rc == ERROR_INVALID_HANDLE,"Invalid Server Name: rc=%d\n",rc); if(delete_test_user() != NERR_Success) trace("Deleting the test user failed. You might have to manually delete it.\n"); } /* Checks Level 1 of NetQueryDisplayInformation */ static void run_querydisplayinformation1_tests(void) { PNET_DISPLAY_USER Buffer, rec; DWORD Result, EntryCount; DWORD i = 0; BOOL hasAdmin = FALSE; BOOL hasGuest = FALSE; do { Result = NetQueryDisplayInformation( NULL, 1, i, 1000, MAX_PREFERRED_LENGTH, &EntryCount, (PVOID *)&Buffer); ok((Result == ERROR_SUCCESS) || (Result == ERROR_MORE_DATA), "Information Retrieved\n"); rec = Buffer; for(; EntryCount > 0; EntryCount--) { if (rec->usri1_user_id == DOMAIN_USER_RID_ADMIN) { 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"); hasAdmin = TRUE; } else if (rec->usri1_user_id == DOMAIN_USER_RID_GUEST) { 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"); hasGuest = TRUE; } i = rec->usri1_next_index; rec++; } NetApiBufferFree(Buffer); } while (Result == ERROR_MORE_DATA); ok(hasAdmin, "Doesn't have 'Administrator' account\n"); } static void run_usermodalsget_tests(void) { NET_API_STATUS rc; USER_MODALS_INFO_2 * umi2 = NULL; rc = NetUserModalsGet(NULL, 2, (BYTE **)&umi2); ok(rc == ERROR_SUCCESS, "NetUserModalsGet failed, rc = %d\n", rc); if (umi2) NetApiBufferFree(umi2); } static void run_userhandling_tests(void) { NET_API_STATUS ret; USER_INFO_1 usri; usri.usri1_priv = USER_PRIV_USER; usri.usri1_home_dir = NULL; usri.usri1_comment = NULL; usri.usri1_flags = UF_SCRIPT; usri.usri1_script_path = NULL; usri.usri1_name = sTooLongName; usri.usri1_password = sTestUserOldPass; ret = NetUserAdd(NULL, 1, (BYTE *)&usri, NULL); if (ret == ERROR_ACCESS_DENIED) { skip("not enough permissions to add a user\n"); return; } else ok(ret == NERR_BadUsername, "Got %u.\n", ret); usri.usri1_name = (WCHAR *)L"testuser"; usri.usri1_password = sTooLongPassword; ret = NetUserAdd(NULL, 1, (BYTE *)&usri, NULL); ok(ret == NERR_PasswordTooShort || ret == ERROR_ACCESS_DENIED /* Win2003 */, "Adding user with too long password returned 0x%08x\n", ret); usri.usri1_name = sTooLongName; usri.usri1_password = sTooLongPassword; ret = NetUserAdd(NULL, 1, (BYTE *)&usri, NULL); /* NT4 doesn't have a problem with the username so it will report the too long password * as the error. NERR_PasswordTooShort is reported for all kind of password related errors. */ ok(ret == NERR_BadUsername || ret == NERR_PasswordTooShort, "Adding user with too long username/password returned 0x%08x\n", ret); usri.usri1_name = (WCHAR *)L"testuser"; usri.usri1_password = sTestUserOldPass; ret = NetUserAdd(NULL, 5, (BYTE *)&usri, NULL); ok(ret == ERROR_INVALID_LEVEL, "Adding user with level 5 returned 0x%08x\n", ret); ret = NetUserAdd(NULL, 1, (BYTE *)&usri, NULL); if(ret == ERROR_ACCESS_DENIED) { skip("Insufficient permissions to add users. Skipping test.\n"); return; } if(ret == NERR_UserExists) { skip("User already exists, skipping test to not mess up the system\n"); return; } ok(!ret, "Got %u.\n", ret); /* On Windows XP (and newer), calling NetUserChangePassword with a NULL * domainname parameter creates a user home directory, iff the machine is * not member of a domain. * Using \\127.0.0.1 as domain name does not work on standalone machines * either, unless the ForceGuest option in the registry is turned off. * So let's not test NetUserChangePassword for now. */ ret = NetUserDel(NULL, L"testuser"); ok(ret == NERR_Success, "Deleting the user failed.\n"); ret = NetUserDel(NULL, L"testuser"); ok(ret == NERR_UserNotFound, "Deleting a nonexistent user returned 0x%08x\n",ret); } static void run_localgroupgetinfo_tests(void) { NET_API_STATUS status; PLOCALGROUP_INFO_1 lgi = NULL; PLOCALGROUP_MEMBERS_INFO_3 buffer = NULL; DWORD entries_read = 0, total_entries =0; int i; status = NetLocalGroupGetInfo(NULL, L"Administrators", 1, (BYTE **)&lgi); ok(status == NERR_Success || broken(status == NERR_GroupNotFound), "NetLocalGroupGetInfo unexpectedly returned %d\n", status); if (status != NERR_Success) return; trace("Local groupname:%s\n", wine_dbgstr_w( lgi->lgrpi1_name)); trace("Comment: %s\n", wine_dbgstr_w( lgi->lgrpi1_comment)); NetApiBufferFree(lgi); status = NetLocalGroupGetMembers(NULL, L"Administrators", 3, (BYTE **)&buffer, MAX_PREFERRED_LENGTH, &entries_read, &total_entries, NULL); ok(status == NERR_Success, "NetLocalGroupGetMembers unexpectedly returned %d\n", status); ok(entries_read > 0 && total_entries > 0, "Amount of entries is unexpectedly 0\n"); for(i=0;i