- User properties:
[reactos.git] / reactos / dll / cpl / usrmgr / groupprops.c
index 29d8612..7b36751 100644 (file)
@@ -9,9 +9,60 @@
 
 #include "usrmgr.h"
 
+typedef struct _GENERAL_GROUP_DATA
+{
+    TCHAR szGroupName[1];
+} GENERAL_GROUP_DATA, *PGENERAL_GROUP_DATA;
+
+
+static VOID
+GetTextSid(PSID pSid,
+           LPTSTR pTextSid)
+{
+    PSID_IDENTIFIER_AUTHORITY psia;
+    DWORD dwSubAuthorities;
+    DWORD dwSidRev = SID_REVISION;
+    DWORD dwCounter;
+    DWORD dwSidSize;
+
+    psia = GetSidIdentifierAuthority(pSid);
+
+    dwSubAuthorities = *GetSidSubAuthorityCount(pSid);
+
+    dwSidSize = wsprintf(pTextSid, TEXT("S-%lu-"), dwSidRev);
+
+    if ((psia->Value[0] != 0) || (psia->Value[1] != 0))
+    {
+        dwSidSize += wsprintf(pTextSid + lstrlen(pTextSid),
+                              TEXT("0x%02hx%02hx%02hx%02hx%02hx%02hx"),
+                              (USHORT)psia->Value[0],
+                              (USHORT)psia->Value[1],
+                              (USHORT)psia->Value[2],
+                              (USHORT)psia->Value[3],
+                              (USHORT)psia->Value[4],
+                              (USHORT)psia->Value[5]);
+    }
+    else
+    {
+        dwSidSize += wsprintf(pTextSid + lstrlen(pTextSid),
+                              TEXT("%lu"),
+                              (ULONG)(psia->Value[5]) +
+                              (ULONG)(psia->Value[4] <<  8) +
+                              (ULONG)(psia->Value[3] << 16) +
+                              (ULONG)(psia->Value[2] << 24));
+    }
+
+    for (dwCounter = 0 ; dwCounter < dwSubAuthorities ; dwCounter++)
+    {
+        dwSidSize += wsprintf(pTextSid + dwSidSize, TEXT("-%lu"),
+                              *GetSidSubAuthority(pSid, dwCounter));
+    }
+}
+
 
 static VOID
-GetGroupData(HWND hwndDlg, LPTSTR lpGroupName)
+GetGeneralGroupData(HWND hwndDlg,
+                    PGENERAL_GROUP_DATA pGroupData)
 {
     PLOCALGROUP_INFO_1 groupInfo = NULL;
     PLOCALGROUP_MEMBERS_INFO_1 membersInfo = NULL;
@@ -25,6 +76,8 @@ GetGroupData(HWND hwndDlg, LPTSTR lpGroupName)
     RECT rect;
     HIMAGELIST hImgList;
     HICON hIcon;
+    TCHAR szGroupName[256];
+
 
     hwndLV = GetDlgItem(hwndDlg, IDC_GROUP_GENERAL_MEMBERS);
 
@@ -49,15 +102,15 @@ GetGroupData(HWND hwndDlg, LPTSTR lpGroupName)
     (void)ListView_InsertColumn(hwndLV, 0, &column);
 
     /* Set group name */
-    SetDlgItemText(hwndDlg, IDC_GROUP_GENERAL_NAME, lpGroupName);
+    SetDlgItemText(hwndDlg, IDC_GROUP_GENERAL_NAME, pGroupData->szGroupName);
 
     /* Set group description */
-    NetLocalGroupGetInfo(NULL, lpGroupName, 1, (LPBYTE*)&groupInfo);
+    NetLocalGroupGetInfo(NULL, pGroupData->szGroupName, 1, (LPBYTE*)&groupInfo);
     SetDlgItemText(hwndDlg, IDC_GROUP_GENERAL_DESCRIPTION, groupInfo->lgrpi1_comment);
     NetApiBufferFree(groupInfo);
 
     /* Set group members */
-    NetLocalGroupGetMembers(NULL, lpGroupName, 1, (LPBYTE*)&membersInfo,
+    NetLocalGroupGetMembers(NULL, pGroupData->szGroupName, 1, (LPBYTE*)&membersInfo,
                             MAX_PREFERRED_LENGTH, &dwRead, &dwTotal,
                             &resumeHandle);
 
@@ -70,6 +123,20 @@ GetGroupData(HWND hwndDlg, LPTSTR lpGroupName)
         lvi.iImage = (membersInfo[i].lgrmi1_sidusage == SidTypeGroup ||
                       membersInfo[i].lgrmi1_sidusage == SidTypeWellKnownGroup) ? 1 : 0;
 
+        if (membersInfo[i].lgrmi1_sidusage == SidTypeWellKnownGroup)
+        {
+            TCHAR szSid[256];
+
+            GetTextSid(membersInfo[i].lgrmi1_sid, szSid);
+
+            wsprintf(szGroupName,
+                     TEXT("%s\\%s (%s)"),
+                     membersInfo[i].lgrmi1_name,
+                     szSid);
+
+            lvi.pszText = szGroupName;
+        }
+
         (void)ListView_InsertItem(hwndLV, &lvi);
     }
 
@@ -77,27 +144,91 @@ GetGroupData(HWND hwndDlg, LPTSTR lpGroupName)
 }
 
 
+static BOOL
+SetGeneralGroupData(HWND hwndDlg,
+                    PGENERAL_GROUP_DATA pGroupData)
+{
+    LOCALGROUP_INFO_1 groupInfo;
+    LPTSTR pszComment = NULL;
+    INT nLength;
+    NET_API_STATUS status;
+    DWORD dwIndex;
+
+    /* Get the group description */
+    nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_GROUP_GENERAL_DESCRIPTION));
+    if (nLength == 0)
+    {
+        groupInfo.lgrpi1_comment = NULL;
+    }
+    else
+    {
+        pszComment = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
+        GetDlgItemText(hwndDlg, IDC_GROUP_GENERAL_DESCRIPTION, pszComment, nLength + 1);
+        groupInfo.lgrpi1_comment = pszComment;
+    }
+
+    status = NetLocalGroupSetInfo(NULL, pGroupData->szGroupName, 1, (LPBYTE)&groupInfo, &dwIndex);
+    if (status != NERR_Success)
+    {
+        DebugPrintf(_T("Status: %lu  Index: %lu"), status, dwIndex);
+    }
+
+    if (pszComment)
+        HeapFree(GetProcessHeap(), 0, pszComment);
+
+    return TRUE;
+}
+
+
 INT_PTR CALLBACK
 GroupGeneralPageProc(HWND hwndDlg,
                      UINT uMsg,
                      WPARAM wParam,
                      LPARAM lParam)
 {
+    PGENERAL_GROUP_DATA pGroupData;
+
     UNREFERENCED_PARAMETER(lParam);
     UNREFERENCED_PARAMETER(wParam);
     UNREFERENCED_PARAMETER(hwndDlg);
 
+    pGroupData= (PGENERAL_GROUP_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
+
     switch (uMsg)
     {
         case WM_INITDIALOG:
-            GetGroupData(hwndDlg,
-                         (LPTSTR)((PROPSHEETPAGE *)lParam)->lParam);
+            pGroupData = (PGENERAL_GROUP_DATA)HeapAlloc(GetProcessHeap(),
+                                                        HEAP_ZERO_MEMORY,
+                                                        sizeof(GENERAL_GROUP_DATA) + 
+                                                        lstrlen((LPTSTR)((PROPSHEETPAGE *)lParam)->lParam) * sizeof(TCHAR));
+            lstrcpy(pGroupData->szGroupName, (LPTSTR)((PROPSHEETPAGE *)lParam)->lParam);
+
+            SetWindowLongPtr(hwndDlg, DWLP_USER, (INT_PTR)pGroupData);
+
+            GetGeneralGroupData(hwndDlg,
+                                pGroupData);
             break;
 
         case WM_COMMAND:
+            switch (LOWORD(wParam))
+            {
+                case IDC_GROUP_GENERAL_DESCRIPTION:
+                    if (HIWORD(wParam) == EN_CHANGE)
+                        PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+                    break;
+            }
+            break;
+
+        case WM_NOTIFY:
+            if (((LPPSHNOTIFY)lParam)->hdr.code == PSN_APPLY)
+            {
+                SetGeneralGroupData(hwndDlg, pGroupData);
+                return TRUE;
+            }
             break;
 
         case WM_DESTROY:
+            HeapFree(GetProcessHeap(), 0, pGroupData);
             break;
     }
 
@@ -118,7 +249,7 @@ InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, LPTSTR pszGro
 }
 
 
-VOID
+BOOL
 GroupProperties(HWND hwndDlg)
 {
     PROPSHEETPAGE psp[1];
@@ -130,7 +261,7 @@ GroupProperties(HWND hwndDlg)
     hwndLV = GetDlgItem(hwndDlg, IDC_GROUPS_LIST);
     nItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED);
     if (nItem == -1)
-        return;
+        return FALSE;
 
     /* Get the new user name */
     ListView_GetItemText(hwndLV,
@@ -151,5 +282,5 @@ GroupProperties(HWND hwndDlg)
 
     InitPropSheetPage(&psp[0], IDD_GROUP_GENERAL, (DLGPROC)GroupGeneralPageProc, szGroupName);
 
-    PropertySheet(&psh);
+    return (PropertySheet(&psh) == IDOK);
 }