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 GetGeneralGroupData(HWND hwndDlg
,
65 PGENERAL_GROUP_DATA pGroupData
)
67 PLOCALGROUP_INFO_1 groupInfo
= NULL
;
68 PLOCALGROUP_MEMBERS_INFO_1 membersInfo
= NULL
;
71 DWORD_PTR resumeHandle
= 0;
79 TCHAR szGroupName
[256];
82 hwndLV
= GetDlgItem(hwndDlg
, IDC_GROUP_GENERAL_MEMBERS
);
84 /* Create the image list */
85 hImgList
= ImageList_Create(16, 16, ILC_COLOR8
| ILC_MASK
, 5, 5);
86 hIcon
= LoadImage(hApplet
, MAKEINTRESOURCE(IDI_USER
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
);
87 ImageList_AddIcon(hImgList
, hIcon
);
88 hIcon
= LoadImage(hApplet
, MAKEINTRESOURCE(IDI_GROUP
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
);
89 ImageList_AddIcon(hImgList
, hIcon
);
92 (void)ListView_SetImageList(hwndLV
, hImgList
, LVSIL_SMALL
);
94 /* Set the list column */
95 GetClientRect(hwndLV
, &rect
);
97 memset(&column
, 0x00, sizeof(column
));
98 column
.mask
= LVCF_FMT
| LVCF_WIDTH
| LVCF_SUBITEM
;
99 column
.fmt
= LVCFMT_LEFT
;
100 column
.cx
= (INT
)(rect
.right
- rect
.left
);
102 (void)ListView_InsertColumn(hwndLV
, 0, &column
);
105 SetDlgItemText(hwndDlg
, IDC_GROUP_GENERAL_NAME
, pGroupData
->szGroupName
);
107 /* Set group description */
108 NetLocalGroupGetInfo(NULL
, pGroupData
->szGroupName
, 1, (LPBYTE
*)&groupInfo
);
109 SetDlgItemText(hwndDlg
, IDC_GROUP_GENERAL_DESCRIPTION
, groupInfo
->lgrpi1_comment
);
110 NetApiBufferFree(groupInfo
);
112 /* Set group members */
113 NetLocalGroupGetMembers(NULL
, pGroupData
->szGroupName
, 1, (LPBYTE
*)&membersInfo
,
114 MAX_PREFERRED_LENGTH
, &dwRead
, &dwTotal
,
117 for (i
= 0; i
< dwRead
; i
++)
119 ZeroMemory(&lvi
, sizeof(lvi
));
120 lvi
.mask
= LVIF_TEXT
| LVIF_STATE
| LVIF_IMAGE
;
121 lvi
.pszText
= membersInfo
[i
].lgrmi1_name
;
123 lvi
.iImage
= (membersInfo
[i
].lgrmi1_sidusage
== SidTypeGroup
||
124 membersInfo
[i
].lgrmi1_sidusage
== SidTypeWellKnownGroup
) ? 1 : 0;
126 if (membersInfo
[i
].lgrmi1_sidusage
== SidTypeWellKnownGroup
)
130 GetTextSid(membersInfo
[i
].lgrmi1_sid
, szSid
);
132 wsprintf(szGroupName
,
134 membersInfo
[i
].lgrmi1_name
,
137 lvi
.pszText
= szGroupName
;
140 (void)ListView_InsertItem(hwndLV
, &lvi
);
143 NetApiBufferFree(membersInfo
);
148 SetGeneralGroupData(HWND hwndDlg
,
149 PGENERAL_GROUP_DATA pGroupData
)
151 LOCALGROUP_INFO_1 groupInfo
;
152 LPTSTR pszComment
= NULL
;
154 NET_API_STATUS status
;
157 /* Get the group description */
158 nLength
= GetWindowTextLength(GetDlgItem(hwndDlg
, IDC_GROUP_GENERAL_DESCRIPTION
));
161 groupInfo
.lgrpi1_comment
= NULL
;
165 pszComment
= HeapAlloc(GetProcessHeap(), 0, (nLength
+ 1) * sizeof(TCHAR
));
166 GetDlgItemText(hwndDlg
, IDC_GROUP_GENERAL_DESCRIPTION
, pszComment
, nLength
+ 1);
167 groupInfo
.lgrpi1_comment
= pszComment
;
170 status
= NetLocalGroupSetInfo(NULL
, pGroupData
->szGroupName
, 1, (LPBYTE
)&groupInfo
, &dwIndex
);
171 if (status
!= NERR_Success
)
173 DebugPrintf(_T("Status: %lu Index: %lu"), status
, dwIndex
);
177 HeapFree(GetProcessHeap(), 0, pszComment
);
184 GroupGeneralPageProc(HWND hwndDlg
,
189 PGENERAL_GROUP_DATA pGroupData
;
191 UNREFERENCED_PARAMETER(lParam
);
192 UNREFERENCED_PARAMETER(wParam
);
193 UNREFERENCED_PARAMETER(hwndDlg
);
195 pGroupData
= (PGENERAL_GROUP_DATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
200 pGroupData
= (PGENERAL_GROUP_DATA
)HeapAlloc(GetProcessHeap(),
202 sizeof(GENERAL_GROUP_DATA
) +
203 lstrlen((LPTSTR
)((PROPSHEETPAGE
*)lParam
)->lParam
) * sizeof(TCHAR
));
204 lstrcpy(pGroupData
->szGroupName
, (LPTSTR
)((PROPSHEETPAGE
*)lParam
)->lParam
);
206 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (INT_PTR
)pGroupData
);
208 GetGeneralGroupData(hwndDlg
,
213 switch (LOWORD(wParam
))
215 case IDC_GROUP_GENERAL_DESCRIPTION
:
216 if (HIWORD(wParam
) == EN_CHANGE
)
217 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
223 if (((LPPSHNOTIFY
)lParam
)->hdr
.code
== PSN_APPLY
)
225 SetGeneralGroupData(hwndDlg
, pGroupData
);
231 HeapFree(GetProcessHeap(), 0, pGroupData
);
240 InitPropSheetPage(PROPSHEETPAGE
*psp
, WORD idDlg
, DLGPROC DlgProc
, LPTSTR pszGroup
)
242 ZeroMemory(psp
, sizeof(PROPSHEETPAGE
));
243 psp
->dwSize
= sizeof(PROPSHEETPAGE
);
244 psp
->dwFlags
= PSP_DEFAULT
;
245 psp
->hInstance
= hApplet
;
246 psp
->pszTemplate
= MAKEINTRESOURCE(idDlg
);
247 psp
->pfnDlgProc
= DlgProc
;
248 psp
->lParam
= (LPARAM
)pszGroup
;
253 GroupProperties(HWND hwndDlg
)
255 PROPSHEETPAGE psp
[1];
257 TCHAR szGroupName
[UNLEN
];
261 hwndLV
= GetDlgItem(hwndDlg
, IDC_GROUPS_LIST
);
262 nItem
= ListView_GetNextItem(hwndLV
, -1, LVNI_SELECTED
);
266 /* Get the new user name */
267 ListView_GetItemText(hwndLV
,
272 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
273 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
274 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_PROPTITLE
;
275 psh
.hwndParent
= hwndDlg
;
276 psh
.hInstance
= hApplet
;
278 psh
.pszCaption
= szGroupName
;
279 psh
.nPages
= sizeof(psp
) / sizeof(PROPSHEETPAGE
);
283 InitPropSheetPage(&psp
[0], IDD_GROUP_GENERAL
, (DLGPROC
)GroupGeneralPageProc
, szGroupName
);
285 return (PropertySheet(&psh
) == IDOK
);