From 5736c65128f9062b549f9a2bfdd52891755f8ec3 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 8 Jun 2008 13:34:42 +0000 Subject: [PATCH 1/1] - User properties: Fix a memory leak. Enable the Apply button when the users full name or description is changed. - Group properties: The group description can be changed. Update the group list when the group description changes. svn path=/trunk/; revision=33901 --- reactos/dll/cpl/usrmgr/groupprops.c | 78 ++++++++++++++++++++++++++--- reactos/dll/cpl/usrmgr/groups.c | 32 +++++++++++- reactos/dll/cpl/usrmgr/userprops.c | 13 ++++- 3 files changed, 113 insertions(+), 10 deletions(-) diff --git a/reactos/dll/cpl/usrmgr/groupprops.c b/reactos/dll/cpl/usrmgr/groupprops.c index fe71499bb5f..7b36751425b 100644 --- a/reactos/dll/cpl/usrmgr/groupprops.c +++ b/reactos/dll/cpl/usrmgr/groupprops.c @@ -61,7 +61,8 @@ GetTextSid(PSID pSid, 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; @@ -101,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); @@ -130,7 +131,6 @@ GetGroupData(HWND hwndDlg, LPTSTR lpGroupName) wsprintf(szGroupName, TEXT("%s\\%s (%s)"), - membersInfo[i].lgrmi1_name, szSid); @@ -144,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; } diff --git a/reactos/dll/cpl/usrmgr/groups.c b/reactos/dll/cpl/usrmgr/groups.c index 09603324e4a..d7f4254404d 100644 --- a/reactos/dll/cpl/usrmgr/groups.c +++ b/reactos/dll/cpl/usrmgr/groups.c @@ -87,6 +87,35 @@ UpdateGroupsList(HWND hwndListView) } +static VOID +UpdateGroupProperties(HWND hwndDlg) +{ + TCHAR szGroupName[UNLEN]; + INT iItem; + HWND hwndLV; + NET_API_STATUS status; + PLOCALGROUP_INFO_1 pGroupInfo = NULL; + + hwndLV = GetDlgItem(hwndDlg, IDC_GROUPS_LIST); + iItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED); + if (iItem == -1) + return; + + /* Get the group name */ + ListView_GetItemText(hwndLV, + iItem, 0, + szGroupName, + UNLEN); + + status = NetLocalGroupGetInfo(NULL, szGroupName, 1, (LPBYTE*)&pGroupInfo); + + ListView_SetItemText(hwndLV, iItem, 1, + pGroupInfo->lgrpi1_comment); + + NetApiBufferFree(pGroupInfo); +} + + INT_PTR CALLBACK NewGroupDlgProc(HWND hwndDlg, UINT uMsg, @@ -461,7 +490,8 @@ GroupsPageProc(HWND hwndDlg, break; case IDM_GROUP_PROPERTIES: - GroupProperties(hwndDlg); + if (GroupProperties(hwndDlg) == IDOK) + UpdateGroupProperties(hwndDlg); break; } break; diff --git a/reactos/dll/cpl/usrmgr/userprops.c b/reactos/dll/cpl/usrmgr/userprops.c index 0e2f050bc82..49beac6f8af 100644 --- a/reactos/dll/cpl/usrmgr/userprops.c +++ b/reactos/dll/cpl/usrmgr/userprops.c @@ -310,6 +310,9 @@ SetGeneralUserData(HWND hwndDlg, if (pszFullName) HeapFree(GetProcessHeap(), 0, pszFullName); + if (pszComment) + HeapFree(GetProcessHeap(), 0, pszComment); + NetApiBufferFree(pUserInfo); return (status == NERR_Success); @@ -339,15 +342,21 @@ UserGeneralPageProc(HWND hwndDlg, lstrlen((LPTSTR)((PROPSHEETPAGE *)lParam)->lParam) * sizeof(TCHAR)); lstrcpy(pUserData->szUserName, (LPTSTR)((PROPSHEETPAGE *)lParam)->lParam); + SetWindowLongPtr(hwndDlg, DWLP_USER, (INT_PTR)pUserData); + GetGeneralUserData(hwndDlg, pUserData); - - SetWindowLongPtr(hwndDlg, DWLP_USER, (INT_PTR)pUserData); break; case WM_COMMAND: switch (LOWORD(wParam)) { + case IDC_USER_GENERAL_FULL_NAME: + case IDC_USER_GENERAL_DESCRIPTION: + if (HIWORD(wParam) == EN_CHANGE) + PropSheet_Changed(GetParent(hwndDlg), hwndDlg); + break; + case IDC_USER_GENERAL_FORCE_CHANGE: pUserData->dwPasswordExpired = !pUserData->dwPasswordExpired; UpdateUserOptions(hwndDlg, pUserData, FALSE); -- 2.17.1