2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS User Manager Control Panel
4 * FILE: dll/cpl/usrmgr/groupprops.c
5 * PURPOSE: Group property sheet
7 * PROGRAMMERS: Eric Kohl
12 typedef struct _GENERAL_GROUP_DATA
15 } GENERAL_GROUP_DATA
, *PGENERAL_GROUP_DATA
;
22 PSID_IDENTIFIER_AUTHORITY psia
;
23 DWORD dwSubAuthorities
;
24 DWORD dwSidRev
= SID_REVISION
;
28 psia
= GetSidIdentifierAuthority(pSid
);
30 dwSubAuthorities
= *GetSidSubAuthorityCount(pSid
);
32 dwSidSize
= wsprintf(pTextSid
, TEXT("S-%lu-"), dwSidRev
);
34 if ((psia
->Value
[0] != 0) || (psia
->Value
[1] != 0))
36 dwSidSize
+= wsprintf(pTextSid
+ lstrlen(pTextSid
),
37 TEXT("0x%02hx%02hx%02hx%02hx%02hx%02hx"),
38 (USHORT
)psia
->Value
[0],
39 (USHORT
)psia
->Value
[1],
40 (USHORT
)psia
->Value
[2],
41 (USHORT
)psia
->Value
[3],
42 (USHORT
)psia
->Value
[4],
43 (USHORT
)psia
->Value
[5]);
47 dwSidSize
+= wsprintf(pTextSid
+ lstrlen(pTextSid
),
49 (ULONG
)(psia
->Value
[5]) +
50 (ULONG
)(psia
->Value
[4] << 8) +
51 (ULONG
)(psia
->Value
[3] << 16) +
52 (ULONG
)(psia
->Value
[2] << 24));
55 for (dwCounter
= 0 ; dwCounter
< dwSubAuthorities
; dwCounter
++)
57 dwSidSize
+= wsprintf(pTextSid
+ dwSidSize
, TEXT("-%lu"),
58 *GetSidSubAuthority(pSid
, dwCounter
));
64 RemoveUserFromGroup(HWND hwndDlg
,
65 PGENERAL_GROUP_DATA pGroupData
)
67 TCHAR szUserName
[UNLEN
];
69 LOCALGROUP_MEMBERS_INFO_3 memberInfo
;
72 NET_API_STATUS status
;
74 hwndLV
= GetDlgItem(hwndDlg
, IDC_GROUP_GENERAL_MEMBERS
);
75 nItem
= ListView_GetNextItem(hwndLV
, -1, LVNI_SELECTED
);
79 /* Get the new user name */
80 ListView_GetItemText(hwndLV
,
85 /* Display a warning message because the remove operation cannot be reverted */
86 wsprintf(szText
, TEXT("Do you really want to remove the user \"%s\" from the group \"%s\"?"),
87 szUserName
, pGroupData
->szGroupName
);
88 if (MessageBox(NULL
, szText
, TEXT("User Accounts"), MB_ICONWARNING
| MB_YESNO
) == IDNO
)
91 memberInfo
.lgrmi3_domainandname
= szUserName
;
93 status
= NetLocalGroupDelMembers(NULL
, pGroupData
->szGroupName
,
94 3, (LPBYTE
)&memberInfo
, 1);
95 if (status
!= NERR_Success
)
98 wsprintf(szText
, TEXT("Error: %u"), status
);
99 MessageBox(NULL
, szText
, TEXT("NetLocalGroupDelMembers"), MB_ICONERROR
| MB_OK
);
103 (void)ListView_DeleteItem(hwndLV
, nItem
);
105 if (ListView_GetItemCount(hwndLV
) == 0)
106 EnableWindow(GetDlgItem(hwndDlg
, IDC_GROUP_GENERAL_REMOVE
), FALSE
);
111 OnNotify(HWND hwndDlg
,
112 PGENERAL_GROUP_DATA pGroupData
,
115 LPNMLISTVIEW lpnmlv
= (LPNMLISTVIEW
)lParam
;
117 switch (((LPNMHDR
)lParam
)->idFrom
)
119 case IDC_GROUP_GENERAL_MEMBERS
:
120 switch (((LPNMHDR
)lParam
)->code
)
123 EnableWindow(GetDlgItem(hwndDlg
, IDC_GROUP_GENERAL_REMOVE
), (lpnmlv
->iItem
!= -1));
127 if (((LPNMLVKEYDOWN
)lParam
)->wVKey
== VK_DELETE
)
129 RemoveUserFromGroup(hwndDlg
, pGroupData
);
142 GetGeneralGroupData(HWND hwndDlg
,
143 PGENERAL_GROUP_DATA pGroupData
)
145 PLOCALGROUP_INFO_1 groupInfo
= NULL
;
146 PLOCALGROUP_MEMBERS_INFO_1 membersInfo
= NULL
;
149 DWORD_PTR resumeHandle
= 0;
157 TCHAR szGroupName
[256];
160 hwndLV
= GetDlgItem(hwndDlg
, IDC_GROUP_GENERAL_MEMBERS
);
162 /* Create the image list */
163 hImgList
= ImageList_Create(16, 16, ILC_COLOR8
| ILC_MASK
, 5, 5);
164 hIcon
= LoadImage(hApplet
, MAKEINTRESOURCE(IDI_USER
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
);
165 ImageList_AddIcon(hImgList
, hIcon
);
166 hIcon
= LoadImage(hApplet
, MAKEINTRESOURCE(IDI_GROUP
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
);
167 ImageList_AddIcon(hImgList
, hIcon
);
170 (void)ListView_SetImageList(hwndLV
, hImgList
, LVSIL_SMALL
);
172 /* Set the list column */
173 GetClientRect(hwndLV
, &rect
);
175 memset(&column
, 0x00, sizeof(column
));
176 column
.mask
= LVCF_FMT
| LVCF_WIDTH
| LVCF_SUBITEM
;
177 column
.fmt
= LVCFMT_LEFT
;
178 column
.cx
= (INT
)(rect
.right
- rect
.left
);
180 (void)ListView_InsertColumn(hwndLV
, 0, &column
);
183 SetDlgItemText(hwndDlg
, IDC_GROUP_GENERAL_NAME
, pGroupData
->szGroupName
);
185 /* Set group description */
186 NetLocalGroupGetInfo(NULL
, pGroupData
->szGroupName
, 1, (LPBYTE
*)&groupInfo
);
187 SetDlgItemText(hwndDlg
, IDC_GROUP_GENERAL_DESCRIPTION
, groupInfo
->lgrpi1_comment
);
188 NetApiBufferFree(groupInfo
);
190 /* Set group members */
191 NetLocalGroupGetMembers(NULL
, pGroupData
->szGroupName
, 1, (LPBYTE
*)&membersInfo
,
192 MAX_PREFERRED_LENGTH
, &dwRead
, &dwTotal
,
195 for (i
= 0; i
< dwRead
; i
++)
197 ZeroMemory(&lvi
, sizeof(lvi
));
198 lvi
.mask
= LVIF_TEXT
| LVIF_STATE
| LVIF_IMAGE
;
199 lvi
.pszText
= membersInfo
[i
].lgrmi1_name
;
201 lvi
.iImage
= (membersInfo
[i
].lgrmi1_sidusage
== SidTypeGroup
||
202 membersInfo
[i
].lgrmi1_sidusage
== SidTypeWellKnownGroup
) ? 1 : 0;
204 if (membersInfo
[i
].lgrmi1_sidusage
== SidTypeWellKnownGroup
)
208 GetTextSid(membersInfo
[i
].lgrmi1_sid
, szSid
);
210 wsprintf(szGroupName
,
212 membersInfo
[i
].lgrmi1_name
,
215 lvi
.pszText
= szGroupName
;
218 (void)ListView_InsertItem(hwndLV
, &lvi
);
221 NetApiBufferFree(membersInfo
);
226 SetGeneralGroupData(HWND hwndDlg
,
227 PGENERAL_GROUP_DATA pGroupData
)
229 LOCALGROUP_INFO_1 groupInfo
;
230 LPTSTR pszComment
= NULL
;
232 NET_API_STATUS status
;
235 /* Get the group description */
236 nLength
= GetWindowTextLength(GetDlgItem(hwndDlg
, IDC_GROUP_GENERAL_DESCRIPTION
));
239 groupInfo
.lgrpi1_comment
= NULL
;
243 pszComment
= HeapAlloc(GetProcessHeap(), 0, (nLength
+ 1) * sizeof(TCHAR
));
244 GetDlgItemText(hwndDlg
, IDC_GROUP_GENERAL_DESCRIPTION
, pszComment
, nLength
+ 1);
245 groupInfo
.lgrpi1_comment
= pszComment
;
248 status
= NetLocalGroupSetInfo(NULL
, pGroupData
->szGroupName
, 1, (LPBYTE
)&groupInfo
, &dwIndex
);
249 if (status
!= NERR_Success
)
251 DebugPrintf(_T("Status: %lu Index: %lu"), status
, dwIndex
);
255 HeapFree(GetProcessHeap(), 0, pszComment
);
262 GroupGeneralPageProc(HWND hwndDlg
,
267 PGENERAL_GROUP_DATA pGroupData
;
269 UNREFERENCED_PARAMETER(lParam
);
270 UNREFERENCED_PARAMETER(wParam
);
271 UNREFERENCED_PARAMETER(hwndDlg
);
273 pGroupData
= (PGENERAL_GROUP_DATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
278 pGroupData
= (PGENERAL_GROUP_DATA
)HeapAlloc(GetProcessHeap(),
280 sizeof(GENERAL_GROUP_DATA
) +
281 lstrlen((LPTSTR
)((PROPSHEETPAGE
*)lParam
)->lParam
) * sizeof(TCHAR
));
282 lstrcpy(pGroupData
->szGroupName
, (LPTSTR
)((PROPSHEETPAGE
*)lParam
)->lParam
);
284 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (INT_PTR
)pGroupData
);
286 GetGeneralGroupData(hwndDlg
,
291 switch (LOWORD(wParam
))
293 case IDC_GROUP_GENERAL_DESCRIPTION
:
294 if (HIWORD(wParam
) == EN_CHANGE
)
295 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
298 case IDC_GROUP_GENERAL_REMOVE
:
299 RemoveUserFromGroup(hwndDlg
, pGroupData
);
305 if (((LPPSHNOTIFY
)lParam
)->hdr
.code
== PSN_APPLY
)
307 SetGeneralGroupData(hwndDlg
, pGroupData
);
312 return OnNotify(hwndDlg
, pGroupData
, lParam
);
317 HeapFree(GetProcessHeap(), 0, pGroupData
);
326 InitPropSheetPage(PROPSHEETPAGE
*psp
, WORD idDlg
, DLGPROC DlgProc
, LPTSTR pszGroup
)
328 ZeroMemory(psp
, sizeof(PROPSHEETPAGE
));
329 psp
->dwSize
= sizeof(PROPSHEETPAGE
);
330 psp
->dwFlags
= PSP_DEFAULT
;
331 psp
->hInstance
= hApplet
;
332 psp
->pszTemplate
= MAKEINTRESOURCE(idDlg
);
333 psp
->pfnDlgProc
= DlgProc
;
334 psp
->lParam
= (LPARAM
)pszGroup
;
339 GroupProperties(HWND hwndDlg
)
341 PROPSHEETPAGE psp
[1];
343 TCHAR szGroupName
[UNLEN
];
347 hwndLV
= GetDlgItem(hwndDlg
, IDC_GROUPS_LIST
);
348 nItem
= ListView_GetNextItem(hwndLV
, -1, LVNI_SELECTED
);
352 /* Get the new user name */
353 ListView_GetItemText(hwndLV
,
358 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
359 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
360 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_PROPTITLE
;
361 psh
.hwndParent
= hwndDlg
;
362 psh
.hInstance
= hApplet
;
364 psh
.pszCaption
= szGroupName
;
365 psh
.nPages
= sizeof(psp
) / sizeof(PROPSHEETPAGE
);
369 InitPropSheetPage(&psp
[0], IDD_GROUP_GENERAL
, (DLGPROC
)GroupGeneralPageProc
, szGroupName
);
371 return (PropertySheet(&psh
) == IDOK
);