Author: ekohl
Date: Sat Jul 5 16:55:16 2008
New Revision: 34312
URL:
http://svn.reactos.org/svn/reactos?rev=34312&view=rev
Log:
Implement removal of a user from a user group.
Modified:
trunk/reactos/dll/cpl/usrmgr/groupprops.c
trunk/reactos/dll/cpl/usrmgr/lang/en-US.rc
trunk/reactos/dll/cpl/usrmgr/resource.h
trunk/reactos/dll/cpl/usrmgr/userprops.c
trunk/reactos/dll/cpl/usrmgr/users.c
Modified: trunk/reactos/dll/cpl/usrmgr/groupprops.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/usrmgr/groupprops.…
==============================================================================
--- trunk/reactos/dll/cpl/usrmgr/groupprops.c [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/usrmgr/groupprops.c [iso-8859-1] Sat Jul 5 16:55:16 2008
@@ -57,6 +57,84 @@
dwSidSize += wsprintf(pTextSid + dwSidSize, TEXT("-%lu"),
*GetSidSubAuthority(pSid, dwCounter));
}
+}
+
+
+static VOID
+RemoveUserFromGroup(HWND hwndDlg,
+ PGENERAL_GROUP_DATA pGroupData)
+{
+ TCHAR szUserName[UNLEN];
+ TCHAR szText[256];
+ LOCALGROUP_MEMBERS_INFO_3 memberInfo;
+ HWND hwndLV;
+ INT nItem;
+ NET_API_STATUS status;
+
+ hwndLV = GetDlgItem(hwndDlg, IDC_GROUP_GENERAL_MEMBERS);
+ nItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED);
+ if (nItem == -1)
+ return;
+
+ /* Get the new user name */
+ ListView_GetItemText(hwndLV,
+ nItem, 0,
+ szUserName,
+ 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\"?"),
+ szUserName, pGroupData->szGroupName);
+ if (MessageBox(NULL, szText, TEXT("User Accounts"), MB_ICONWARNING |
MB_YESNO) == IDNO)
+ return;
+
+ memberInfo.lgrmi3_domainandname = szUserName;
+
+ status = NetLocalGroupDelMembers(NULL, pGroupData->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_GROUP_GENERAL_REMOVE), FALSE);
+}
+
+
+static BOOL
+OnNotify(HWND hwndDlg,
+ PGENERAL_GROUP_DATA pGroupData,
+ LPARAM lParam)
+{
+ LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lParam;
+
+ switch (((LPNMHDR)lParam)->idFrom)
+ {
+ case IDC_GROUP_GENERAL_MEMBERS:
+ switch (((LPNMHDR)lParam)->code)
+ {
+ case NM_CLICK:
+ EnableWindow(GetDlgItem(hwndDlg, IDC_GROUP_GENERAL_REMOVE),
(lpnmlv->iItem != -1));
+ break;
+
+ case LVN_KEYDOWN:
+ if (((LPNMLVKEYDOWN)lParam)->wVKey == VK_DELETE)
+ {
+ RemoveUserFromGroup(hwndDlg, pGroupData);
+ }
+ break;
+
+ }
+ break;
+ }
+
+ return FALSE;
}
@@ -216,6 +294,10 @@
if (HIWORD(wParam) == EN_CHANGE)
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
+
+ case IDC_GROUP_GENERAL_REMOVE:
+ RemoveUserFromGroup(hwndDlg, pGroupData);
+ break;
}
break;
@@ -224,6 +306,10 @@
{
SetGeneralGroupData(hwndDlg, pGroupData);
return TRUE;
+ }
+ else
+ {
+ return OnNotify(hwndDlg, pGroupData, lParam);
}
break;
Modified: trunk/reactos/dll/cpl/usrmgr/lang/en-US.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/usrmgr/lang/en-US.…
==============================================================================
--- trunk/reactos/dll/cpl/usrmgr/lang/en-US.rc [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/usrmgr/lang/en-US.rc [iso-8859-1] Sat Jul 5 16:55:16 2008
@@ -62,6 +62,8 @@
LTEXT "Member of:", -1, 7, 7, 56, 8
CONTROL "", IDC_USER_MEMBERSHIP_LIST, "SysListView32", LVS_REPORT
| LVS_NOCOLUMNHEADER | LVS_SORTASCENDING | WS_BORDER | WS_TABSTOP,
7, 18, 238, 173, WS_EX_CLIENTEDGE
+ PUSHBUTTON "Add...", IDC_USER_MEMBERSHIP_ADD, 7, 197, 50, 14, WS_DISABLED
+ PUSHBUTTON "Remove", IDC_USER_MEMBERSHIP_REMOVE, 61, 197, 50, 14,
WS_DISABLED
END
@@ -97,6 +99,8 @@
LTEXT "Members:", -1, 7, 63, 45, 8
CONTROL "", IDC_GROUP_GENERAL_MEMBERS, "SysListView32",
LVS_REPORT | LVS_NOCOLUMNHEADER | LVS_SORTASCENDING | WS_BORDER | WS_TABSTOP,
7, 74, 238, 117, WS_EX_CLIENTEDGE
+ PUSHBUTTON "Add...", IDC_GROUP_GENERAL_ADD, 7, 197, 50, 14, WS_DISABLED
+ PUSHBUTTON "Remove", IDC_GROUP_GENERAL_REMOVE, 61, 197, 50, 14,
WS_DISABLED
END
Modified: trunk/reactos/dll/cpl/usrmgr/resource.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/usrmgr/resource.h?…
==============================================================================
--- trunk/reactos/dll/cpl/usrmgr/resource.h [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/usrmgr/resource.h [iso-8859-1] Sat Jul 5 16:55:16 2008
@@ -49,7 +49,8 @@
#define IDC_GROUP_GENERAL_NAME 341
#define IDC_GROUP_GENERAL_DESCRIPTION 342
#define IDC_GROUP_GENERAL_MEMBERS 343
-
+#define IDC_GROUP_GENERAL_ADD 344
+#define IDC_GROUP_GENERAL_REMOVE 345
#define IDD_CHANGE_PASSWORD 350
#define IDC_EDIT_PASSWORD1 351
@@ -67,8 +68,10 @@
#define IDC_USER_NEW_NEVER_EXPIRES 368
#define IDC_USER_NEW_DISABLED 369
-#define IDD_USER_MEMBERSHIP 370
-#define IDC_USER_MEMBERSHIP_LIST 371
+#define IDD_USER_MEMBERSHIP 370
+#define IDC_USER_MEMBERSHIP_LIST 371
+#define IDC_USER_MEMBERSHIP_ADD 372
+#define IDC_USER_MEMBERSHIP_REMOVE 373
#define IDD_USER_PROFILE 380
#define IDC_USER_PROFILE_PATH 381
Modified: trunk/reactos/dll/cpl/usrmgr/userprops.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/usrmgr/userprops.c…
==============================================================================
--- trunk/reactos/dll/cpl/usrmgr/userprops.c [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/usrmgr/userprops.c [iso-8859-1] Sat Jul 5 16:55:16 2008
@@ -23,6 +23,12 @@
TCHAR szUserName[1];
} PROFILE_USER_DATA, *PPROFILE_USER_DATA;
+typedef struct _MEMBERSHIP_USER_DATA
+{
+ PLOCALGROUP_USERS_INFO_0 pGroupData;
+ DWORD dwGroupCount;
+ TCHAR szUserName[1];
+} MEMBERSHIP_USER_DATA, *PMEMBERSHIP_USER_DATA;
static VOID
@@ -258,11 +264,9 @@
static VOID
-GetMembershipData(HWND hwndDlg, LPTSTR lpUserName)
-{
- PLOCALGROUP_USERS_INFO_0 usersInfo = NULL;
+GetUserMembershipData(HWND hwndDlg, PMEMBERSHIP_USER_DATA pUserData)
+{
NET_API_STATUS status;
- DWORD dwRead;
DWORD dwTotal;
DWORD i;
HIMAGELIST hImgList;
@@ -293,28 +297,102 @@
(void)ListView_InsertColumn(hwndLV, 0, &column);
- status = NetUserGetLocalGroups(NULL, lpUserName, 0, 0,
- (LPBYTE*)&usersInfo,
+ status = NetUserGetLocalGroups(NULL, pUserData->szUserName, 0, 0,
+ (LPBYTE*)&pUserData->pGroupData,
MAX_PREFERRED_LENGTH,
- &dwRead,
+ &pUserData->dwGroupCount,
&dwTotal);
if (status != NERR_Success)
return;
- for (i = 0; i < dwRead; i++)
+ for (i = 0; i < pUserData->dwGroupCount; i++)
{
ZeroMemory(&lvi, sizeof(lvi));
lvi.mask = LVIF_TEXT | LVIF_STATE | LVIF_IMAGE;
- lvi.pszText = usersInfo[i].lgrui0_name;
+ lvi.pszText = pUserData->pGroupData[i].lgrui0_name;
lvi.state = 0;
lvi.iImage = 0;
(void)ListView_InsertItem(hwndLV, &lvi);
}
-
-
- NetApiBufferFree(usersInfo);
-
+}
+
+
+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);
+}
+
+
+static BOOL
+OnNotify(HWND hwndDlg,
+ PMEMBERSHIP_USER_DATA pUserData,
+ LPARAM lParam)
+{
+ LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lParam;
+
+ switch (((LPNMHDR)lParam)->idFrom)
+ {
+ case IDC_USER_MEMBERSHIP_LIST:
+ switch (((LPNMHDR)lParam)->code)
+ {
+ case NM_CLICK:
+ EnableWindow(GetDlgItem(hwndDlg, IDC_USER_MEMBERSHIP_REMOVE),
(lpnmlv->iItem != -1));
+ break;
+
+ case LVN_KEYDOWN:
+ if (((LPNMLVKEYDOWN)lParam)->wVKey == VK_DELETE)
+ {
+ RemoveGroupFromUser(hwndDlg, pUserData);
+ }
+ break;
+
+ }
+ break;
+ }
+
+ return FALSE;
}
@@ -324,18 +402,55 @@
WPARAM wParam,
LPARAM lParam)
{
+ PMEMBERSHIP_USER_DATA pUserData;
UNREFERENCED_PARAMETER(lParam);
UNREFERENCED_PARAMETER(wParam);
UNREFERENCED_PARAMETER(hwndDlg);
+ pUserData= (PMEMBERSHIP_USER_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
+
switch (uMsg)
{
case WM_INITDIALOG:
- GetMembershipData(hwndDlg,
- (LPTSTR)((PROPSHEETPAGE *)lParam)->lParam);
- break;
-
+ pUserData = (PMEMBERSHIP_USER_DATA)HeapAlloc(GetProcessHeap(),
+ HEAP_ZERO_MEMORY,
+ sizeof(MEMBERSHIP_USER_DATA) +
+ lstrlen((LPTSTR)((PROPSHEETPAGE
*)lParam)->lParam) * sizeof(TCHAR));
+ lstrcpy(pUserData->szUserName, (LPTSTR)((PROPSHEETPAGE
*)lParam)->lParam);
+
+ SetWindowLongPtr(hwndDlg, DWLP_USER, (INT_PTR)pUserData);
+
+ GetUserMembershipData(hwndDlg, pUserData);
+ break;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam))
+ {
+ case IDC_USER_MEMBERSHIP_REMOVE:
+ RemoveGroupFromUser(hwndDlg, pUserData);
+ break;
+ }
+ break;
+
+ case WM_NOTIFY:
+ if (((LPPSHNOTIFY)lParam)->hdr.code == PSN_APPLY)
+ {
+ return TRUE;
+ }
+ else
+ {
+ return OnNotify(hwndDlg, pUserData, lParam);
+ }
+ break;
+
+
+ case WM_DESTROY:
+ if (pUserData->pGroupData)
+ NetApiBufferFree(pUserData->pGroupData);
+
+ HeapFree(GetProcessHeap(), 0, pUserData);
+ break;
}
return FALSE;
Modified: trunk/reactos/dll/cpl/usrmgr/users.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/usrmgr/users.c?rev…
==============================================================================
--- trunk/reactos/dll/cpl/usrmgr/users.c [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/usrmgr/users.c [iso-8859-1] Sat Jul 5 16:55:16 2008
@@ -346,7 +346,7 @@
UNLEN);
/* Display a warning message because the delete operation cannot be reverted */
- wsprintf(szText, TEXT("Dou you really want to delete the user
\"%s\"?"), szUserName);
+ 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;