- Group properties: Display the SID of well-known members.
[reactos.git] / reactos / dll / cpl / usrmgr / groupprops.c
1 /*
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
6 *
7 * PROGRAMMERS: Eric Kohl
8 */
9
10 #include "usrmgr.h"
11
12 typedef struct _GENERAL_GROUP_DATA
13 {
14 TCHAR szGroupName[1];
15 } GENERAL_GROUP_DATA, *PGENERAL_GROUP_DATA;
16
17
18 static VOID
19 GetTextSid(PSID pSid,
20 LPTSTR pTextSid)
21 {
22 PSID_IDENTIFIER_AUTHORITY psia;
23 DWORD dwSubAuthorities;
24 DWORD dwSidRev = SID_REVISION;
25 DWORD dwCounter;
26 DWORD dwSidSize;
27
28 psia = GetSidIdentifierAuthority(pSid);
29
30 dwSubAuthorities = *GetSidSubAuthorityCount(pSid);
31
32 dwSidSize = wsprintf(pTextSid, TEXT("S-%lu-"), dwSidRev);
33
34 if ((psia->Value[0] != 0) || (psia->Value[1] != 0))
35 {
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]);
44 }
45 else
46 {
47 dwSidSize += wsprintf(pTextSid + lstrlen(pTextSid),
48 TEXT("%lu"),
49 (ULONG)(psia->Value[5]) +
50 (ULONG)(psia->Value[4] << 8) +
51 (ULONG)(psia->Value[3] << 16) +
52 (ULONG)(psia->Value[2] << 24));
53 }
54
55 for (dwCounter = 0 ; dwCounter < dwSubAuthorities ; dwCounter++)
56 {
57 dwSidSize += wsprintf(pTextSid + dwSidSize, TEXT("-%lu"),
58 *GetSidSubAuthority(pSid, dwCounter));
59 }
60 }
61
62
63 static VOID
64 GetGroupData(HWND hwndDlg, LPTSTR lpGroupName)
65 {
66 PLOCALGROUP_INFO_1 groupInfo = NULL;
67 PLOCALGROUP_MEMBERS_INFO_1 membersInfo = NULL;
68 DWORD dwRead;
69 DWORD dwTotal;
70 DWORD_PTR resumeHandle = 0;
71 DWORD i;
72 LV_ITEM lvi;
73 HWND hwndLV;
74 LV_COLUMN column;
75 RECT rect;
76 HIMAGELIST hImgList;
77 HICON hIcon;
78 TCHAR szGroupName[256];
79
80
81 hwndLV = GetDlgItem(hwndDlg, IDC_GROUP_GENERAL_MEMBERS);
82
83 /* Create the image list */
84 hImgList = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 5, 5);
85 hIcon = LoadImage(hApplet, MAKEINTRESOURCE(IDI_USER), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
86 ImageList_AddIcon(hImgList, hIcon);
87 hIcon = LoadImage(hApplet, MAKEINTRESOURCE(IDI_GROUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
88 ImageList_AddIcon(hImgList, hIcon);
89 DestroyIcon(hIcon);
90
91 (void)ListView_SetImageList(hwndLV, hImgList, LVSIL_SMALL);
92
93 /* Set the list column */
94 GetClientRect(hwndLV, &rect);
95
96 memset(&column, 0x00, sizeof(column));
97 column.mask = LVCF_FMT | LVCF_WIDTH | LVCF_SUBITEM;
98 column.fmt = LVCFMT_LEFT;
99 column.cx = (INT)(rect.right - rect.left);
100 column.iSubItem = 0;
101 (void)ListView_InsertColumn(hwndLV, 0, &column);
102
103 /* Set group name */
104 SetDlgItemText(hwndDlg, IDC_GROUP_GENERAL_NAME, lpGroupName);
105
106 /* Set group description */
107 NetLocalGroupGetInfo(NULL, lpGroupName, 1, (LPBYTE*)&groupInfo);
108 SetDlgItemText(hwndDlg, IDC_GROUP_GENERAL_DESCRIPTION, groupInfo->lgrpi1_comment);
109 NetApiBufferFree(groupInfo);
110
111 /* Set group members */
112 NetLocalGroupGetMembers(NULL, lpGroupName, 1, (LPBYTE*)&membersInfo,
113 MAX_PREFERRED_LENGTH, &dwRead, &dwTotal,
114 &resumeHandle);
115
116 for (i = 0; i < dwRead; i++)
117 {
118 ZeroMemory(&lvi, sizeof(lvi));
119 lvi.mask = LVIF_TEXT | LVIF_STATE | LVIF_IMAGE;
120 lvi.pszText = membersInfo[i].lgrmi1_name;
121 lvi.state = 0;
122 lvi.iImage = (membersInfo[i].lgrmi1_sidusage == SidTypeGroup ||
123 membersInfo[i].lgrmi1_sidusage == SidTypeWellKnownGroup) ? 1 : 0;
124
125 if (membersInfo[i].lgrmi1_sidusage == SidTypeWellKnownGroup)
126 {
127 TCHAR szSid[256];
128
129 GetTextSid(membersInfo[i].lgrmi1_sid, szSid);
130
131 wsprintf(szGroupName,
132 TEXT("%s\\%s (%s)"),
133
134 membersInfo[i].lgrmi1_name,
135 szSid);
136
137 lvi.pszText = szGroupName;
138 }
139
140 (void)ListView_InsertItem(hwndLV, &lvi);
141 }
142
143 NetApiBufferFree(membersInfo);
144 }
145
146
147 INT_PTR CALLBACK
148 GroupGeneralPageProc(HWND hwndDlg,
149 UINT uMsg,
150 WPARAM wParam,
151 LPARAM lParam)
152 {
153 UNREFERENCED_PARAMETER(lParam);
154 UNREFERENCED_PARAMETER(wParam);
155 UNREFERENCED_PARAMETER(hwndDlg);
156
157 switch (uMsg)
158 {
159 case WM_INITDIALOG:
160 GetGroupData(hwndDlg,
161 (LPTSTR)((PROPSHEETPAGE *)lParam)->lParam);
162 break;
163
164 case WM_COMMAND:
165 break;
166
167 case WM_DESTROY:
168 break;
169 }
170
171 return FALSE;
172 }
173
174
175 static VOID
176 InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, LPTSTR pszGroup)
177 {
178 ZeroMemory(psp, sizeof(PROPSHEETPAGE));
179 psp->dwSize = sizeof(PROPSHEETPAGE);
180 psp->dwFlags = PSP_DEFAULT;
181 psp->hInstance = hApplet;
182 psp->pszTemplate = MAKEINTRESOURCE(idDlg);
183 psp->pfnDlgProc = DlgProc;
184 psp->lParam = (LPARAM)pszGroup;
185 }
186
187
188 BOOL
189 GroupProperties(HWND hwndDlg)
190 {
191 PROPSHEETPAGE psp[1];
192 PROPSHEETHEADER psh;
193 TCHAR szGroupName[UNLEN];
194 INT nItem;
195 HWND hwndLV;
196
197 hwndLV = GetDlgItem(hwndDlg, IDC_GROUPS_LIST);
198 nItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED);
199 if (nItem == -1)
200 return FALSE;
201
202 /* Get the new user name */
203 ListView_GetItemText(hwndLV,
204 nItem, 0,
205 szGroupName,
206 UNLEN);
207
208 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
209 psh.dwSize = sizeof(PROPSHEETHEADER);
210 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE;
211 psh.hwndParent = hwndDlg;
212 psh.hInstance = hApplet;
213 psh.hIcon = NULL;
214 psh.pszCaption = szGroupName;
215 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
216 psh.nStartPage = 0;
217 psh.ppsp = psp;
218
219 InitPropSheetPage(&psp[0], IDD_GROUP_GENERAL, (DLGPROC)GroupGeneralPageProc, szGroupName);
220
221 return (PropertySheet(&psh) == IDOK);
222 }