bool UserUtilities::RemoveUserToGroup(CString strUserName, CString strGroupName) { LOCALGROUP_MEMBERS_INFO_3 *group = new LOCALGROUP_MEMBERS_INFO_3(); group->lgrmi3_domainandname = strUserName.GetBuffer(); int res = NetLocalGroupDelMembers(NULL, strGroupName, 3, (LPBYTE)group, 1); if(res == 0) { return true; } return false; }
/** * Delete a member from a local domain group. * * @param appContext Application context reference. * @param aliasNameC Group name. * @param memberNameC Member name. * @return 0 on success; error code on failure. */ DWORD AdtNetLocalGroupDeleteMember( IN AppContextTP appContext, IN PSTR aliasNameC, IN PSTR memberNameC ) { DWORD dwError = ERROR_SUCCESS; LOCALGROUP_MEMBERS_INFO_3 memberinfo = {0}; PWSTR hostName = NULL; PWSTR aliasName = NULL; PWSTR memberName = NULL; PSTR memberNameN = NULL; dwError = NormalizeUserName(memberNameC, appContext->workConn->domainName, &memberNameN); ADT_BAIL_ON_ERROR_NP(dwError); dwError = LwMbsToWc16s((PCSTR) (appContext->workConn->serverName), &hostName); ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError); dwError = LwMbsToWc16s((PCSTR) aliasNameC, &aliasName); ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError); dwError = LwMbsToWc16s((PCSTR) memberNameN, &memberName); ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError); memberinfo.lgrmi3_domainandname = memberName; PrintStderr(appContext, LogLevelTrace, "%s: Deleting member %s from group %s ...\n", appContext->actionName, memberNameN, aliasNameC); /* Perform the delete operation. */ if(!appContext->gopts.isReadOnly) { dwError = NetLocalGroupDelMembers(hostName, aliasName, 3, &memberinfo, 1); } if (dwError) { dwError += ADT_WIN_ERR_BASE; ADT_BAIL_ON_ERROR_NP(dwError); } PrintStderr(appContext, LogLevelTrace, "%s: Done deleting member %s from group %s ...\n", appContext->actionName, memberNameN, aliasNameC); cleanup: LW_SAFE_FREE_MEMORY(hostName); LW_SAFE_FREE_MEMORY(aliasName); LW_SAFE_FREE_MEMORY(memberName); LW_SAFE_FREE_MEMORY(memberNameN); return dwError; error: goto cleanup; }
static VOID RemoveGroupFromUser(HWND hwndDlg, PMEMBERSHIP_USER_DATA pUserData) { TCHAR szGroupName[UNLEN]; TCHAR szText[256]; LOCALGROUP_MEMBERS_INFO_3 memberInfo; HWND hwndLV; INT nItem; NET_API_STATUS status; hwndLV = GetDlgItem(hwndDlg, IDC_USER_MEMBERSHIP_LIST); nItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED); if (nItem == -1) return; /* Get the new user name */ ListView_GetItemText(hwndLV, nItem, 0, szGroupName, UNLEN); /* Display a warning message because the remove operation cannot be reverted */ wsprintf(szText, TEXT("Do you really want to remove the user \"%s\" from the group \"%s\"?"), pUserData->szUserName, szGroupName); if (MessageBox(NULL, szText, TEXT("User Accounts"), MB_ICONWARNING | MB_YESNO) == IDNO) return; memberInfo.lgrmi3_domainandname = pUserData->szUserName; status = NetLocalGroupDelMembers(NULL, szGroupName, 3, (LPBYTE)&memberInfo, 1); if (status != NERR_Success) { TCHAR szText[256]; wsprintf(szText, TEXT("Error: %u"), status); MessageBox(NULL, szText, TEXT("NetLocalGroupDelMembers"), MB_ICONERROR | MB_OK); return; } (void)ListView_DeleteItem(hwndLV, nItem); if (ListView_GetItemCount(hwndLV) == 0) EnableWindow(GetDlgItem(hwndDlg, IDC_USER_MEMBERSHIP_REMOVE), FALSE); }
bool RemoveUser(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(mRemoveOne),Truncated); } else FSF.sprintf(warning,GetMsg(mRemoveUserN+NumberType(sp.Number())),sp.Number()); const TCHAR *MsgItems[]={GetMsg(mButtonRemove),warning,GetMsg(mButtonRemove),GetMsg(mButtonCancel)}; if(!Info.Message(&MainGuid,&RemoveUserMessageGuid,0,NULL,MsgItems,sizeof(MsgItems)/sizeof(MsgItems[0]),2)) { res=true; for(int i=0;i<sp.Number();i++) { if(sp[i].UserData.FreeData) { if(panel->global) { NetGroupDelUser(panel->domain,panel->nonfixed,GetWideNameFromUserData(sp[i].UserData.Data)); } else { LOCALGROUP_MEMBERS_INFO_0 new_member; new_member.lgrmi0_sid=GetSidFromUserData(sp[i].UserData.Data); NetLocalGroupDelMembers(panel->computer_ptr,panel->nonfixed,0,(LPBYTE)&new_member,1); } } } } } return res; }