bool DeleteUser(UserManager *panel,bool selection) { bool res=false; CFarPanelSelection sp((HANDLE)panel,selection); if(sp.Number()) { TCHAR warning[TINY_BUFFER]; if(sp.Number()==1) { TCHAR Truncated[MAX_PATH]; _tcscpy(Truncated,sp[0].FileName); FSF.TruncPathStr(Truncated,50); FSF.sprintf(warning,GetMsg(mDelOne),Truncated); } else FSF.sprintf(warning,GetMsg(mDelUserN+NumberType(sp.Number())),sp.Number()); const TCHAR *MsgItems[]={GetMsg(mButtonDelete),warning,GetMsg(mButtonDelete),GetMsg(mButtonCancel)}; if(!Info.Message(&MainGuid,&DelUserMessageGuid,0,NULL,MsgItems,sizeof(MsgItems)/sizeof(MsgItems[0]),2)) { res=true; for(int i=0;i<sp.Number();i++) { if(sp[i].UserData.FreeData) NetUserDel((panel->global)?(panel->domain):(panel->computer_ptr),GetWideNameFromUserData(sp[i].UserData.Data)); } } } return res; }
APIERR MNetUserDel( const TCHAR FAR * pszServer, TCHAR FAR * pszUserName ) { return (APIERR)NetUserDel( (TCHAR *)pszServer, pszUserName ); } // MNetUserDel
int main(int argc, const char **argv) { NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; const char *hostname = NULL; const char *username = NULL; poptContext pc; int opt; struct poptOption long_options[] = { POPT_AUTOHELP POPT_COMMON_LIBNETAPI_EXAMPLES POPT_TABLEEND }; status = libnetapi_init(&ctx); if (status != 0) { return status; } pc = poptGetContext("user_del", argc, argv, long_options, 0); poptSetOtherOptionHelp(pc, "hostname username"); while((opt = poptGetNextOpt(pc)) != -1) { } if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } hostname = poptGetArg(pc); if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } username = poptGetArg(pc); /* NetUserDel */ status = NetUserDel(hostname, username); if (status != 0) { printf("NetUserDel failed with: %s\n", libnetapi_get_error_string(ctx, status)); } out: libnetapi_free(ctx); poptFreeContext(pc); return status; }
bool UserUtilities::DeleteAccount(Account* account) { DWORD res = NetUserDel(NULL, account->m_StrUserName); if(res == 0) { return true; } else { return false; } return true; }
APIRET UserDel (void) { NETRET rc; /* NET_API returncode */ #define ASC2UNI(a,b) OemToChar(Options.a,Globals.b) /************************************************************************** * convert ASCII to UNICODE strings * **************************************************************************/ #ifdef _WIN32 if (Options.fsUser) ASC2UNI(pszUser, lptstrUser); if (Options.fsServer) ASC2UNI(pszServer, lptstrServer); #endif printf ("\nDeleting account %s from %s.", Options.pszUser, Options.fsServer ? Options.pszServer : "<local>"); /* @@@confirmation !! */ if (!Options.fsNoPrompt) { int iAnswer; /* answer from user */ iAnswer = ToolsConfirmationQuery(); /* ask the user yes/no */ if (iAnswer != 1) /* answer is not YES */ return (0); /* then abort the process immediately */ } #ifdef _WIN32 rc = NetUserDel(Globals.lptstrServer, Globals.lptstrUser); #endif #ifdef __OS2__ rc = Net32UserDel(Options.pszServer, Options.pszUser, NULL); #endif if (rc != NERR_Success) { UserDelError (rc, 0); } return (rc); }
/** * Delete AD user. * * @param appContext Application context reference. * @param userNameC User name. * @return 0 on success; error code on failure. */ DWORD AdtNetUserDelete( IN AppContextTP appContext, IN PSTR userNameC ) { DWORD dwError = ERROR_SUCCESS; PWSTR hostName = NULL; PWSTR userName = NULL; PSTR userNameN = NULL; dwError = NormalizeUserName(userNameC, appContext->workConn->domainName, &userNameN); ADT_BAIL_ON_ERROR_NP(dwError); dwError = LwMbsToWc16s((PCSTR) (appContext->workConn->serverName), &hostName); ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError); dwError = LwMbsToWc16s((PCSTR) userNameN, &userName); ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError); PrintStderr(appContext, LogLevelTrace, "%s: Deleting user %s ...\n", appContext->actionName, userNameN); /* Perform the delete operation. */ if(!appContext->gopts.isReadOnly) { dwError = NetUserDel((PCWSTR) hostName, (PCWSTR) userName); } if (dwError) { dwError += ADT_WIN_ERR_BASE; ADT_BAIL_ON_ERROR_NP(dwError); } PrintStderr(appContext, LogLevelTrace, "%s: Done deleting user %s\n", appContext->actionName, userNameN); cleanup: LW_SAFE_FREE_MEMORY(hostName); LW_SAFE_FREE_MEMORY(userName); LW_SAFE_FREE_MEMORY(userNameN); return dwError; error: goto cleanup; }
static BOOL UserDelete(HWND hwndDlg) { TCHAR szUserName[UNLEN]; TCHAR szText[256]; INT nItem; HWND hwndLV; NET_API_STATUS status; hwndLV = GetDlgItem(hwndDlg, IDC_USERS_LIST); nItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED); if (nItem == -1) return FALSE; /* Get the new user name */ ListView_GetItemText(hwndLV, nItem, 0, szUserName, UNLEN); /* Display a warning message because the delete operation cannot be reverted */ wsprintf(szText, TEXT("Do you really want to delete the user \"%s\"?"), szUserName); if (MessageBox(NULL, szText, TEXT("User Accounts"), MB_ICONWARNING | MB_YESNO) == IDNO) return FALSE; /* Delete the user */ #if 0 status = NetUserDel(NULL, szUserName); #else status = NERR_Success; #endif if (status != NERR_Success) { TCHAR szText[256]; wsprintf(szText, TEXT("Error: %u"), status); MessageBox(NULL, szText, TEXT("NetUserDel"), MB_ICONERROR | MB_OK); return FALSE; } /* Delete the user from the list */ (void)ListView_DeleteItem(hwndLV, nItem); return TRUE; }
////////////////////////////////////////////////////////////////////////////// // RemoveUserAccount // // Attempts to remove a user account on the local machine according // to the "instructions" provided in the CustomActionData property // // As a deferred custom action, you do not have access to the database. // The only source of information comes from a property that an immediate // custom action can set to provide the information you need. This // property is written into the script // UINT __stdcall RemoveUserAccount(MSIHANDLE hInstall) { // determine mode in which we are called BOOL bRollback = MsiGetMode(hInstall, MSIRUNMODE_ROLLBACK); // true for rollback, else regular deferred version (for uninstall) BOOL fSuccess = FALSE; // id's for error and warning messages const int iRemoveError = 25003; const int iRemoveWarning = 25004; // Grab the CustomActionData property DWORD cchCAData = 0; if (ERROR_MORE_DATA == MsiGetPropertyW(hInstall, IPROPNAME_CUSTOMACTIONDATA, L"", &cchCAData)) { WCHAR* wszCAData = new WCHAR[++cchCAData]; // add 1 for null-terminator which is not included in size on return if (wszCAData) { if (ERROR_SUCCESS == MsiGetPropertyW(hInstall, IPROPNAME_CUSTOMACTIONDATA, wszCAData, &cchCAData)) { // send ActionData message (template in ActionText table) // send ActionData message (template in ActionText table) PMSIHANDLE hRec = MsiCreateRecord(1); if (!hRec || ERROR_SUCCESS != MsiRecordSetStringW(hRec, 1, wszCAData)) { delete [] wszCAData; return ERROR_INSTALL_FAILURE; } int iRet = MsiProcessMessage(hInstall, INSTALLMESSAGE_ACTIONDATA, hRec); if (IDCANCEL == iRet || IDABORT == iRet) { delete [] wszCAData; return ERROR_INSTALL_USEREXIT; } // // Call the NetUserDel function, // NET_API_STATUS nStatus = NetUserDel(NULL /*local machine*/, wszCAData /*user name*/); if (NERR_Success != nStatus) { PMSIHANDLE hRecErr = MsiCreateRecord(3); if ( !hRecErr || ERROR_SUCCESS != MsiRecordSetStringW(hRecErr, 2, wszCAData)) { delete [] wszCAData; return ERROR_INSTALL_FAILURE; } // In rollback mode, NERR_UserNotFound means cancel button depressed in middle of deferred CA trying to create this account if (bRollback && NERR_UserNotFound == nStatus) { fSuccess = TRUE; } else if (NERR_UserNotFound == nStatus) { // treat this as a warning, but success since we are attempting to delete and it is not present if (ERROR_SUCCESS != MsiRecordSetInteger(hRecErr, 1, iRemoveWarning)) { delete [] wszCAData; return ERROR_INSTALL_FAILURE; } // just pop up an OK button // OPTIONALLY, could specify multiple buttons and cancel // install based on user selection by handling the return value // from MsiProcessMessage, but here we are ignoring the MsiProcessMessage return MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_WARNING|MB_ICONWARNING|MB_OK), hRecErr); fSuccess = TRUE; } else { if (ERROR_SUCCESS == MsiRecordSetInteger(hRecErr, 1, iRemoveError) && ERROR_SUCCESS == MsiRecordSetInteger(hRecErr, 3, nStatus)) { // returning failure anyway, so ignoring MsiProcessMessage return MsiProcessMessage(hInstall, INSTALLMESSAGE_ERROR, hRecErr); } } } else // NERR_Success { fSuccess = TRUE; } } delete [] wszCAData; } } return fSuccess ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; }
NET_API_STATUS netapitest_group(struct libnetapi_ctx *ctx, const char *hostname) { NET_API_STATUS status = 0; const char *username, *groupname, *groupname2; uint8_t *buffer = NULL; struct GROUP_INFO_0 g0; uint32_t parm_err = 0; uint32_t levels[] = { 0, 1, 2, 3}; uint32_t enum_levels[] = { 0, 1, 2, 3}; uint32_t getmem_levels[] = { 0, 1}; int i; printf("NetGroup tests\n"); username = "******"; groupname = "torture_test_group"; groupname2 = "torture_test_group2"; /* cleanup */ NetGroupDel(hostname, groupname); NetGroupDel(hostname, groupname2); NetUserDel(hostname, username); /* add a group */ g0.grpi0_name = groupname; printf("testing NetGroupAdd\n"); status = NetGroupAdd(hostname, 0, (uint8_t *)&g0, &parm_err); if (status) { NETAPI_STATUS(ctx, status, "NetGroupAdd"); goto out; } /* 2nd add must fail */ status = NetGroupAdd(hostname, 0, (uint8_t *)&g0, &parm_err); if (status == 0) { NETAPI_STATUS(ctx, status, "NetGroupAdd"); goto out; } /* test enum */ for (i=0; i<ARRAY_SIZE(enum_levels); i++) { status = test_netgroupenum(hostname, enum_levels[i], groupname); if (status) { NETAPI_STATUS(ctx, status, "NetGroupEnum"); goto out; } } /* basic queries */ for (i=0; i<ARRAY_SIZE(levels); i++) { printf("testing NetGroupGetInfo level %d\n", levels[i]); status = NetGroupGetInfo(hostname, groupname, levels[i], &buffer); if (status && status != 124) { NETAPI_STATUS(ctx, status, "NetGroupGetInfo"); goto out; } } /* group rename */ g0.grpi0_name = groupname2; printf("testing NetGroupSetInfo level 0\n"); status = NetGroupSetInfo(hostname, groupname, 0, (uint8_t *)&g0, &parm_err); switch (status) { case 0: break; case 50: /* not supported */ case 124: /* not implemented */ groupname2 = groupname; goto skip_rename; default: NETAPI_STATUS(ctx, status, "NetGroupSetInfo"); goto out; } /* should not exist anymore */ status = NetGroupDel(hostname, groupname); if (status == 0) { NETAPI_STATUS(ctx, status, "NetGroupDel"); goto out; } skip_rename: /* query info */ for (i=0; i<ARRAY_SIZE(levels); i++) { status = NetGroupGetInfo(hostname, groupname2, levels[i], &buffer); if (status && status != 124) { NETAPI_STATUS(ctx, status, "NetGroupGetInfo"); goto out; } } /* add user to group */ status = test_netuseradd(hostname, username); if (status) { NETAPI_STATUS(ctx, status, "NetUserAdd"); goto out; } /* should not be member */ for (i=0; i<ARRAY_SIZE(getmem_levels); i++) { status = test_netgroupgetusers(hostname, getmem_levels[i], groupname2, NULL); if (status) { NETAPI_STATUS(ctx, status, "NetGroupGetUsers"); goto out; } } printf("testing NetGroupAddUser\n"); status = NetGroupAddUser(hostname, groupname2, username); if (status) { NETAPI_STATUS(ctx, status, "NetGroupAddUser"); goto out; } /* should be member */ for (i=0; i<ARRAY_SIZE(getmem_levels); i++) { status = test_netgroupgetusers(hostname, getmem_levels[i], groupname2, username); if (status) { NETAPI_STATUS(ctx, status, "NetGroupGetUsers"); goto out; } } printf("testing NetGroupDelUser\n"); status = NetGroupDelUser(hostname, groupname2, username); if (status) { NETAPI_STATUS(ctx, status, "NetGroupDelUser"); goto out; } /* should not be member */ status = test_netgroupgetusers(hostname, 0, groupname2, NULL); if (status) { NETAPI_STATUS(ctx, status, "NetGroupGetUsers"); goto out; } /* set it again via exlicit member set */ status = test_netgroupsetusers(hostname, groupname2, 0, 1, &username); if (status) { NETAPI_STATUS(ctx, status, "NetGroupSetUsers"); goto out; } /* should be member */ status = test_netgroupgetusers(hostname, 0, groupname2, username); if (status) { NETAPI_STATUS(ctx, status, "NetGroupGetUsers"); goto out; } #if 0 /* wipe out member list */ status = test_netgroupsetusers(hostname, groupname2, 0, 0, NULL); if (status) { NETAPI_STATUS(ctx, status, "NetGroupSetUsers"); goto out; } /* should not be member */ status = test_netgroupgetusers(hostname, 0, groupname2, NULL); if (status) { NETAPI_STATUS(ctx, status, "NetGroupGetUsers"); goto out; } #endif status = NetUserDel(hostname, username); if (status) { NETAPI_STATUS(ctx, status, "NetUserDel"); goto out; } /* delete */ printf("testing NetGroupDel\n"); status = NetGroupDel(hostname, groupname2); if (status) { NETAPI_STATUS(ctx, status, "NetGroupDel"); goto out; }; /* should not exist anymore */ status = NetGroupGetInfo(hostname, groupname2, 0, &buffer); if (status == 0) { NETAPI_STATUS_MSG(ctx, status, "NetGroupGetInfo", "expected failure and error code"); goto out; }; status = 0; printf("NetGroup tests succeeded\n"); out: if (status != 0) { printf("NetGroup testsuite failed with: %s\n", libnetapi_get_error_string(ctx, status)); } return status; }
INT cmdUser( INT argc, WCHAR **argv) { INT i, j; INT result = 0; BOOL bAdd = FALSE; BOOL bDelete = FALSE; #if 0 BOOL bDomain = FALSE; #endif LPWSTR lpUserName = NULL; LPWSTR lpPassword = NULL; PUSER_INFO_4 pUserInfo = NULL; USER_INFO_4 UserInfo; LPWSTR p; LPWSTR endptr; DWORD value; BOOL bPasswordAllocated = FALSE; NET_API_STATUS Status; if (argc == 2) { Status = EnumerateUsers(); ConPrintf(StdOut, L"Status: %lu\n", Status); return 0; } else if (argc == 3) { Status = DisplayUser(argv[2]); ConPrintf(StdOut, L"Status: %lu\n", Status); return 0; } i = 2; if (argv[i][0] != L'/') { lpUserName = argv[i]; // ConPrintf(StdOut, L"User: %s\n", lpUserName); i++; } if (argv[i][0] != L'/') { lpPassword = argv[i]; // ConPrintf(StdOut, L"Password: %s\n", lpPassword); i++; } for (j = i; j < argc; j++) { if (_wcsicmp(argv[j], L"/help") == 0) { ConResPuts(StdOut, IDS_USER_HELP); return 0; } else if (_wcsicmp(argv[j], L"/add") == 0) { bAdd = TRUE; } else if (_wcsicmp(argv[j], L"/delete") == 0) { bDelete = TRUE; } else if (_wcsicmp(argv[j], L"/domain") == 0) { ConResPrintf(StdErr, IDS_ERROR_OPTION_NOT_SUPPORTED, L"/DOMAIN"); #if 0 bDomain = TRUE; #endif } } if (bAdd && bDelete) { result = 1; goto done; } /* Interactive password input */ if (lpPassword != NULL && wcscmp(lpPassword, L"*") == 0) { ReadPassword(&lpPassword, &bPasswordAllocated); } if (!bAdd && !bDelete) { /* Modify the user */ Status = NetUserGetInfo(NULL, lpUserName, 4, (LPBYTE*)&pUserInfo); if (Status != NERR_Success) { ConPrintf(StdOut, L"Status: %lu\n", Status); result = 1; goto done; } } else if (bAdd && !bDelete) { /* Add the user */ ZeroMemory(&UserInfo, sizeof(USER_INFO_4)); UserInfo.usri4_name = lpUserName; UserInfo.usri4_password = lpPassword; UserInfo.usri4_flags = UF_SCRIPT | UF_NORMAL_ACCOUNT; pUserInfo = &UserInfo; } for (j = i; j < argc; j++) { if (_wcsnicmp(argv[j], L"/active:", 8) == 0) { p = &argv[i][8]; if (_wcsicmp(p, L"yes") == 0) { pUserInfo->usri4_flags &= ~UF_ACCOUNTDISABLE; } else if (_wcsicmp(p, L"no") == 0) { pUserInfo->usri4_flags |= UF_ACCOUNTDISABLE; } else { ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/ACTIVE"); result = 1; goto done; } } else if (_wcsnicmp(argv[j], L"/comment:", 9) == 0) { pUserInfo->usri4_comment = &argv[j][9]; } else if (_wcsnicmp(argv[j], L"/countrycode:", 13) == 0) { p = &argv[i][13]; value = wcstoul(p, &endptr, 10); if (*endptr != 0) { ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/COUNTRYCODE"); result = 1; goto done; } /* FIXME: verify the country code */ pUserInfo->usri4_country_code = value; } else if (_wcsnicmp(argv[j], L"/expires:", 9) == 0) { p = &argv[i][9]; if (_wcsicmp(p, L"never") == 0) { pUserInfo->usri4_acct_expires = TIMEQ_FOREVER; } else { /* FIXME: Parse the date */ ConResPrintf(StdErr, IDS_ERROR_OPTION_NOT_SUPPORTED, L"/EXPIRES"); } } else if (_wcsnicmp(argv[j], L"/fullname:", 10) == 0) { pUserInfo->usri4_full_name = &argv[j][10]; } else if (_wcsnicmp(argv[j], L"/homedir:", 9) == 0) { pUserInfo->usri4_home_dir = &argv[j][9]; } else if (_wcsnicmp(argv[j], L"/passwordchg:", 13) == 0) { p = &argv[i][13]; if (_wcsicmp(p, L"yes") == 0) { pUserInfo->usri4_flags &= ~UF_PASSWD_CANT_CHANGE; } else if (_wcsicmp(p, L"no") == 0) { pUserInfo->usri4_flags |= UF_PASSWD_CANT_CHANGE; } else { ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/PASSWORDCHG"); result = 1; goto done; } } else if (_wcsnicmp(argv[j], L"/passwordreq:", 13) == 0) { p = &argv[i][13]; if (_wcsicmp(p, L"yes") == 0) { pUserInfo->usri4_flags &= ~UF_PASSWD_NOTREQD; } else if (_wcsicmp(p, L"no") == 0) { pUserInfo->usri4_flags |= UF_PASSWD_NOTREQD; } else { ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/PASSWORDREQ"); result = 1; goto done; } } else if (_wcsnicmp(argv[j], L"/profilepath:", 13) == 0) { pUserInfo->usri4_profile = &argv[j][13]; } else if (_wcsnicmp(argv[j], L"/scriptpath:", 12) == 0) { pUserInfo->usri4_script_path = &argv[j][12]; } else if (_wcsnicmp(argv[j], L"/times:", 7) == 0) { /* FIXME */ ConResPrintf(StdErr, IDS_ERROR_OPTION_NOT_SUPPORTED, L"/TIMES"); } else if (_wcsnicmp(argv[j], L"/usercomment:", 13) == 0) { pUserInfo->usri4_usr_comment = &argv[j][13]; } else if (_wcsnicmp(argv[j], L"/workstations:", 14) == 0) { /* FIXME */ ConResPrintf(StdErr, IDS_ERROR_OPTION_NOT_SUPPORTED, L"/WORKSTATIONS"); } } if (!bAdd && !bDelete) { /* Modify the user */ Status = NetUserSetInfo(NULL, lpUserName, 4, (LPBYTE)pUserInfo, NULL); ConPrintf(StdOut, L"Status: %lu\n", Status); } else if (bAdd && !bDelete) { /* Add the user */ Status = NetUserAdd(NULL, 4, (LPBYTE)pUserInfo, NULL); ConPrintf(StdOut, L"Status: %lu\n", Status); } else if (!bAdd && bDelete) { /* Delete the user */ Status = NetUserDel(NULL, lpUserName); ConPrintf(StdOut, L"Status: %lu\n", Status); } done: if (bPasswordAllocated == TRUE && lpPassword != NULL) HeapFree(GetProcessHeap(), 0, lpPassword); if (!bAdd && !bDelete && pUserInfo != NULL) NetApiBufferFree(pUserInfo); if (result != 0) ConResPuts(StdOut, IDS_USER_SYNTAX); return result; }
bool torture_libnetapi_user(struct torture_context *tctx) { NET_API_STATUS status = 0; uint8_t *buffer = NULL; uint32_t levels[] = { 0, 1, 2, 3, 4, 10, 11, 20, 23 }; uint32_t enum_levels[] = { 0, 1, 2, 3, 4, 10, 11, 20, 23 }; uint32_t getgr_levels[] = { 0, 1 }; int i; struct USER_INFO_0 u0; struct USER_INFO_1007 u1007; uint32_t parm_err = 0; const char *hostname = torture_setting_string(tctx, "host", NULL); struct libnetapi_ctx *ctx; torture_assert(tctx, torture_libnetapi_init_context(tctx, &ctx), "failed to initialize libnetapi"); torture_comment(tctx, "NetUser tests\n"); /* cleanup */ NetUserDel(hostname, TORTURE_TEST_USER); NetUserDel(hostname, TORTURE_TEST_USER2); /* add a user */ status = test_netuseradd(tctx, hostname, TORTURE_TEST_USER); if (status) { NETAPI_STATUS(tctx, ctx, status, "NetUserAdd"); goto out; } /* enum the new user */ for (i=0; i<ARRAY_SIZE(enum_levels); i++) { status = test_netuserenum(tctx, hostname, enum_levels[i], TORTURE_TEST_USER); if (status) { NETAPI_STATUS(tctx, ctx, status, "NetUserEnum"); goto out; } } /* basic queries */ for (i=0; i<ARRAY_SIZE(levels); i++) { torture_comment(tctx, "Testing NetUserGetInfo level %d\n", levels[i]); status = NetUserGetInfo(hostname, TORTURE_TEST_USER, levels[i], &buffer); if (status && status != 124) { NETAPI_STATUS(tctx, ctx, status, "NetUserGetInfo"); goto out; } } /* testing getgroups */ for (i=0; i<ARRAY_SIZE(getgr_levels); i++) { status = test_netusergetgroups(tctx, hostname, getgr_levels[i], TORTURE_TEST_USER, NULL); if (status) { NETAPI_STATUS(tctx, ctx, status, "NetUserGetGroups"); goto out; } } /* modify description */ torture_comment(tctx, "Testing NetUserSetInfo level %d\n", 1007); u1007.usri1007_comment = "NetApi modified user"; status = NetUserSetInfo(hostname, TORTURE_TEST_USER, 1007, (uint8_t *)&u1007, &parm_err); if (status) { NETAPI_STATUS(tctx, ctx, status, "NetUserSetInfo"); goto out; } /* query info */ for (i=0; i<ARRAY_SIZE(levels); i++) { status = NetUserGetInfo(hostname, TORTURE_TEST_USER, levels[i], &buffer); if (status && status != 124) { NETAPI_STATUS(tctx, ctx, status, "NetUserGetInfo"); goto out; } } torture_comment(tctx, "Testing NetUserSetInfo level 0\n"); u0.usri0_name = TORTURE_TEST_USER2; status = NetUserSetInfo(hostname, TORTURE_TEST_USER, 0, (uint8_t *)&u0, &parm_err); if (status) { NETAPI_STATUS(tctx, ctx, status, "NetUserSetInfo"); goto out; } /* delete */ torture_comment(tctx, "Testing NetUserDel\n"); status = NetUserDel(hostname, TORTURE_TEST_USER2); if (status) { NETAPI_STATUS(tctx, ctx, status, "NetUserDel"); goto out; } /* should not exist anymore */ status = NetUserGetInfo(hostname, TORTURE_TEST_USER2, 0, &buffer); if (status == 0) { NETAPI_STATUS(tctx, ctx, status, "NetUserGetInfo"); status = -1; goto out; } status = test_netusermodals(tctx, ctx, hostname); if (status) { goto out; } status = 0; torture_comment(tctx, "NetUser tests succeeded\n"); out: /* cleanup */ NetUserDel(hostname, TORTURE_TEST_USER); NetUserDel(hostname, TORTURE_TEST_USER2); if (status != 0) { torture_comment(tctx, "NetUser testsuite failed with: %s\n", libnetapi_get_error_string(ctx, status)); libnetapi_free(ctx); return false; } libnetapi_free(ctx); return true; }
INT cmdUser( INT argc, WCHAR **argv) { INT i, j; INT result = 0; BOOL bAdd = FALSE; BOOL bDelete = FALSE; #if 0 BOOL bDomain = FALSE; #endif BOOL bRandomPassword = FALSE; LPWSTR lpUserName = NULL; LPWSTR lpPassword = NULL; PUSER_INFO_4 pUserInfo = NULL; USER_INFO_4 UserInfo; LPWSTR pWorkstations = NULL; LPWSTR p; LPWSTR endptr; DWORD value; BOOL bPasswordAllocated = FALSE; NET_API_STATUS Status; i = 2; if ((i < argc) && (argv[i][0] != L'/')) { lpUserName = argv[i]; // ConPrintf(StdOut, L"User: %s\n", lpUserName); i++; } if ((i < argc) && (argv[i][0] != L'/')) { lpPassword = argv[i]; // ConPrintf(StdOut, L"Password: %s\n", lpPassword); i++; } for (j = i; j < argc; j++) { if (_wcsicmp(argv[j], L"/help") == 0) { PrintNetMessage(MSG_USER_HELP); return 0; } else if (_wcsicmp(argv[j], L"/add") == 0) { bAdd = TRUE; } else if (_wcsicmp(argv[j], L"/delete") == 0) { bDelete = TRUE; } else if (_wcsicmp(argv[j], L"/domain") == 0) { ConPuts(StdErr, L"The /DOMAIN option is not supported yet.\n"); #if 0 bDomain = TRUE; #endif } else if (_wcsicmp(argv[j], L"/random") == 0) { bRandomPassword = TRUE; GenerateRandomPassword(&lpPassword, &bPasswordAllocated); } } if (lpUserName == NULL && lpPassword == NULL) { Status = EnumerateUsers(); ConPrintf(StdOut, L"Status: %lu\n", Status); return 0; } else if (lpUserName != NULL && lpPassword == NULL) { Status = DisplayUser(lpUserName); ConPrintf(StdOut, L"Status: %lu\n", Status); return 0; } if (bAdd && bDelete) { result = 1; goto done; } /* Interactive password input */ if (lpPassword != NULL && wcscmp(lpPassword, L"*") == 0) { ReadPassword(&lpPassword, &bPasswordAllocated); } if (!bAdd && !bDelete) { /* Modify the user */ Status = NetUserGetInfo(NULL, lpUserName, 4, (LPBYTE*)&pUserInfo); if (Status != NERR_Success) { ConPrintf(StdOut, L"Status: %lu\n", Status); result = 1; goto done; } } else if (bAdd && !bDelete) { /* Add the user */ ZeroMemory(&UserInfo, sizeof(USER_INFO_4)); UserInfo.usri4_name = lpUserName; UserInfo.usri4_password = lpPassword; UserInfo.usri4_flags = UF_SCRIPT | UF_NORMAL_ACCOUNT; UserInfo.usri4_acct_expires = TIMEQ_FOREVER; UserInfo.usri4_primary_group_id = DOMAIN_GROUP_RID_USERS; pUserInfo = &UserInfo; } for (j = i; j < argc; j++) { if (_wcsnicmp(argv[j], L"/active:", 8) == 0) { p = &argv[i][8]; if (_wcsicmp(p, L"yes") == 0) { pUserInfo->usri4_flags &= ~UF_ACCOUNTDISABLE; } else if (_wcsicmp(p, L"no") == 0) { pUserInfo->usri4_flags |= UF_ACCOUNTDISABLE; } else { PrintMessageStringV(3952, L"/ACTIVE"); result = 1; goto done; } } else if (_wcsnicmp(argv[j], L"/comment:", 9) == 0) { pUserInfo->usri4_comment = &argv[j][9]; } else if (_wcsnicmp(argv[j], L"/countrycode:", 13) == 0) { p = &argv[i][13]; value = wcstoul(p, &endptr, 10); if (*endptr != 0) { PrintMessageStringV(3952, L"/COUNTRYCODE"); result = 1; goto done; } /* Verify the country code */ if (GetCountryFromCountryCode(value, 0, NULL)) pUserInfo->usri4_country_code = value; } else if (_wcsnicmp(argv[j], L"/expires:", 9) == 0) { p = &argv[i][9]; if (_wcsicmp(p, L"never") == 0) { pUserInfo->usri4_acct_expires = TIMEQ_FOREVER; } else if (!ParseDate(p, &pUserInfo->usri4_acct_expires)) { PrintMessageStringV(3952, L"/EXPIRES"); result = 1; goto done; } } else if (_wcsnicmp(argv[j], L"/fullname:", 10) == 0) { pUserInfo->usri4_full_name = &argv[j][10]; } else if (_wcsnicmp(argv[j], L"/homedir:", 9) == 0) { pUserInfo->usri4_home_dir = &argv[j][9]; } else if (_wcsnicmp(argv[j], L"/passwordchg:", 13) == 0) { p = &argv[i][13]; if (_wcsicmp(p, L"yes") == 0) { pUserInfo->usri4_flags &= ~UF_PASSWD_CANT_CHANGE; } else if (_wcsicmp(p, L"no") == 0) { pUserInfo->usri4_flags |= UF_PASSWD_CANT_CHANGE; } else { PrintMessageStringV(3952, L"/PASSWORDCHG"); result = 1; goto done; } } else if (_wcsnicmp(argv[j], L"/passwordreq:", 13) == 0) { p = &argv[i][13]; if (_wcsicmp(p, L"yes") == 0) { pUserInfo->usri4_flags &= ~UF_PASSWD_NOTREQD; } else if (_wcsicmp(p, L"no") == 0) { pUserInfo->usri4_flags |= UF_PASSWD_NOTREQD; } else { PrintMessageStringV(3952, L"/PASSWORDREQ"); result = 1; goto done; } } else if (_wcsnicmp(argv[j], L"/profilepath:", 13) == 0) { pUserInfo->usri4_profile = &argv[j][13]; } else if (_wcsnicmp(argv[j], L"/scriptpath:", 12) == 0) { pUserInfo->usri4_script_path = &argv[j][12]; } else if (_wcsnicmp(argv[j], L"/times:", 7) == 0) { /* FIXME */ ConPuts(StdErr, L"The /TIMES option is not supported yet.\n"); } else if (_wcsnicmp(argv[j], L"/usercomment:", 13) == 0) { pUserInfo->usri4_usr_comment = &argv[j][13]; } else if (_wcsnicmp(argv[j], L"/workstations:", 14) == 0) { p = &argv[i][14]; if (wcscmp(p, L"*") == 0 || wcscmp(p, L"") == 0) { pUserInfo->usri4_workstations = NULL; } else { Status = BuildWorkstationsList(&pWorkstations, p); if (Status == NERR_Success) { pUserInfo->usri4_workstations = pWorkstations; } else { ConPrintf(StdOut, L"Status %lu\n\n", Status); result = 1; goto done; } } } } if (!bAdd && !bDelete) { /* Modify the user */ Status = NetUserSetInfo(NULL, lpUserName, 4, (LPBYTE)pUserInfo, NULL); ConPrintf(StdOut, L"Status: %lu\n", Status); } else if (bAdd && !bDelete) { /* Add the user */ Status = NetUserAdd(NULL, 4, (LPBYTE)pUserInfo, NULL); ConPrintf(StdOut, L"Status: %lu\n", Status); } else if (!bAdd && bDelete) { /* Delete the user */ Status = NetUserDel(NULL, lpUserName); ConPrintf(StdOut, L"Status: %lu\n", Status); } if (Status == NERR_Success && lpPassword != NULL && bRandomPassword == TRUE) { PrintMessageStringV(3968, lpUserName, lpPassword); } done: if (pWorkstations != NULL) HeapFree(GetProcessHeap(), 0, pWorkstations); if ((bPasswordAllocated == TRUE) && (lpPassword != NULL)) HeapFree(GetProcessHeap(), 0, lpPassword); if (!bAdd && !bDelete && pUserInfo != NULL) NetApiBufferFree(pUserInfo); if (result != 0) { PrintMessageString(4381); ConPuts(StdOut, L"\n"); PrintNetMessage(MSG_USER_SYNTAX); } return result; }