- Group properties: Display the SID of well-known members.

- User properties: Store changes to the general settings.

svn path=/trunk/; revision=33890
This commit is contained in:
Eric Kohl 2008-06-07 22:31:24 +00:00
parent c844e808fd
commit 57efc6d296
6 changed files with 249 additions and 40 deletions

View file

@ -9,6 +9,56 @@
#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)
@ -25,6 +75,8 @@ GetGroupData(HWND hwndDlg, LPTSTR lpGroupName)
RECT rect;
HIMAGELIST hImgList;
HICON hIcon;
TCHAR szGroupName[256];
hwndLV = GetDlgItem(hwndDlg, IDC_GROUP_GENERAL_MEMBERS);
@ -70,6 +122,21 @@ 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);
}
@ -118,7 +185,7 @@ InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, LPTSTR pszGro
}
VOID
BOOL
GroupProperties(HWND hwndDlg)
{
PROPSHEETPAGE psp[1];
@ -130,7 +197,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 +218,5 @@ GroupProperties(HWND hwndDlg)
InitPropSheetPage(&psp[0], IDD_GROUP_GENERAL, (DLGPROC)GroupGeneralPageProc, szGroupName);
PropertySheet(&psh);
return (PropertySheet(&psh) == IDOK);
}

View file

@ -50,7 +50,7 @@ BEGIN
AUTOCHECKBOX "User cannot change the password",IDC_USER_GENERAL_CANNOT_CHANGE,7,95,210,10
AUTOCHECKBOX "Password never expires",IDC_USER_GENERAL_NEVER_EXPIRES,7,108,210,10
AUTOCHECKBOX "Account is disabled",IDC_USER_GENERAL_DISABLED,7,121,210,10
AUTOCHECKBOX "Account is locked",IDC_USER_GENERAL_LOCKED,7,134,210,10,WS_DISABLED
AUTOCHECKBOX "Account is locked",IDC_USER_GENERAL_LOCKED,7,134,210,10
END

View file

@ -9,6 +9,16 @@
#include "usrmgr.h"
typedef struct _GENERAL_USER_DATA
{
DWORD dwFlags;
DWORD dwPasswordExpired;
TCHAR szUserName[1];
} GENERAL_USER_DATA, *PGENERAL_USER_DATA;
#define VALID_GENERAL_FLAGS (UF_PASSWD_CANT_CHANGE | UF_DONT_EXPIRE_PASSWD | UF_ACCOUNTDISABLE | UF_LOCKOUT)
static VOID
GetProfileData(HWND hwndDlg, LPTSTR lpUserName)
@ -187,48 +197,116 @@ UserMembershipPageProc(HWND hwndDlg,
static VOID
UpdateUserOptions(HWND hwndDlg,
PUSER_INFO_3 userInfo,
PGENERAL_USER_DATA pUserData,
BOOL bInit)
{
EnableWindow(GetDlgItem(hwndDlg, IDC_USER_GENERAL_CANNOT_CHANGE),
!userInfo->usri3_password_expired);
!pUserData->dwPasswordExpired);
EnableWindow(GetDlgItem(hwndDlg, IDC_USER_GENERAL_NEVER_EXPIRES),
!userInfo->usri3_password_expired);
!pUserData->dwPasswordExpired);
EnableWindow(GetDlgItem(hwndDlg, IDC_USER_GENERAL_FORCE_CHANGE),
(userInfo->usri3_flags & (UF_PASSWD_CANT_CHANGE | UF_DONT_EXPIRE_PASSWD)) == 0);
(pUserData->dwFlags & (UF_PASSWD_CANT_CHANGE | UF_DONT_EXPIRE_PASSWD)) == 0);
EnableWindow(GetDlgItem(hwndDlg, IDC_USER_GENERAL_LOCKED),
(pUserData->dwFlags & UF_LOCKOUT) != 0);
if (bInit)
{
CheckDlgButton(hwndDlg, IDC_USER_GENERAL_FORCE_CHANGE,
userInfo->usri3_password_expired ? BST_CHECKED : BST_UNCHECKED);
pUserData->dwPasswordExpired ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_USER_GENERAL_CANNOT_CHANGE,
(userInfo->usri3_flags & UF_PASSWD_CANT_CHANGE) ? BST_CHECKED : BST_UNCHECKED);
(pUserData->dwFlags & UF_PASSWD_CANT_CHANGE) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_USER_GENERAL_NEVER_EXPIRES,
(userInfo->usri3_flags & UF_DONT_EXPIRE_PASSWD) ? BST_CHECKED : BST_UNCHECKED);
(pUserData->dwFlags & UF_DONT_EXPIRE_PASSWD) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_USER_GENERAL_DISABLED,
(userInfo->usri3_flags & UF_ACCOUNTDISABLE) ? BST_CHECKED : BST_UNCHECKED);
(pUserData->dwFlags & UF_ACCOUNTDISABLE) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_USER_GENERAL_LOCKED,
(pUserData->dwFlags & UF_LOCKOUT) ? BST_CHECKED : BST_UNCHECKED);
}
}
static VOID
GetUserData(HWND hwndDlg, LPTSTR lpUserName, PUSER_INFO_3 *usrInfo)
GetGeneralUserData(HWND hwndDlg,
PGENERAL_USER_DATA pUserData)
{
PUSER_INFO_3 userInfo = NULL;
PUSER_INFO_3 pUserInfo = NULL;
SetDlgItemText(hwndDlg, IDC_USER_GENERAL_NAME, lpUserName);
SetDlgItemText(hwndDlg, IDC_USER_GENERAL_NAME, pUserData->szUserName);
NetUserGetInfo(NULL, lpUserName, 3, (LPBYTE*)&userInfo);
NetUserGetInfo(NULL, pUserData->szUserName, 3, (LPBYTE*)&pUserInfo);
SetDlgItemText(hwndDlg, IDC_USER_GENERAL_FULL_NAME, userInfo->usri3_full_name);
SetDlgItemText(hwndDlg, IDC_USER_GENERAL_DESCRIPTION, userInfo->usri3_comment);
SetDlgItemText(hwndDlg, IDC_USER_GENERAL_FULL_NAME, pUserInfo->usri3_full_name);
SetDlgItemText(hwndDlg, IDC_USER_GENERAL_DESCRIPTION, pUserInfo->usri3_comment);
UpdateUserOptions(hwndDlg, userInfo, TRUE);
pUserData->dwFlags = pUserInfo->usri3_flags;
pUserData->dwPasswordExpired = pUserInfo->usri3_password_expired;
*usrInfo = userInfo;
NetApiBufferFree(pUserInfo);
UpdateUserOptions(hwndDlg, pUserData, TRUE);
}
static BOOL
SetGeneralUserData(HWND hwndDlg,
PGENERAL_USER_DATA pUserData)
{
PUSER_INFO_3 pUserInfo = NULL;
LPTSTR pszFullName = NULL;
LPTSTR pszComment = NULL;
NET_API_STATUS status;
DWORD dwIndex;
INT nLength;
NetUserGetInfo(NULL, pUserData->szUserName, 3, (LPBYTE*)&pUserInfo);
pUserInfo->usri3_flags =
(pUserData->dwFlags & VALID_GENERAL_FLAGS) |
(pUserInfo->usri3_flags & ~VALID_GENERAL_FLAGS);
pUserInfo->usri3_password_expired = pUserData->dwPasswordExpired;
nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_GENERAL_FULL_NAME));
if (nLength == 0)
{
pUserInfo->usri3_full_name = NULL;
}
else
{
pszFullName = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
GetDlgItemText(hwndDlg, IDC_USER_GENERAL_FULL_NAME, pszFullName, nLength + 1);
pUserInfo->usri3_full_name = pszFullName;
}
nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_GENERAL_DESCRIPTION));
if (nLength == 0)
{
pUserInfo->usri3_full_name = NULL;
}
else
{
pszComment = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
GetDlgItemText(hwndDlg, IDC_USER_GENERAL_DESCRIPTION, pszComment, nLength + 1);
pUserInfo->usri3_comment = pszComment;
}
status = NetUserSetInfo(NULL, pUserData->szUserName, 3, (LPBYTE)pUserInfo, &dwIndex);
if (status != NERR_Success)
{
DebugPrintf(_T("Status: %lu Index: %lu"), status, dwIndex);
}
if (pszFullName)
HeapFree(GetProcessHeap(), 0, pszFullName);
NetApiBufferFree(pUserInfo);
return (status == NERR_Success);
}
@ -238,52 +316,72 @@ UserGeneralPageProc(HWND hwndDlg,
WPARAM wParam,
LPARAM lParam)
{
PUSER_INFO_3 userInfo;
PGENERAL_USER_DATA pUserData;
UNREFERENCED_PARAMETER(lParam);
UNREFERENCED_PARAMETER(wParam);
UNREFERENCED_PARAMETER(hwndDlg);
userInfo = (PUSER_INFO_3)GetWindowLongPtr(hwndDlg, DWLP_USER);
pUserData= (PGENERAL_USER_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
switch (uMsg)
{
case WM_INITDIALOG:
GetUserData(hwndDlg,
(LPTSTR)((PROPSHEETPAGE *)lParam)->lParam,
&userInfo);
SetWindowLongPtr(hwndDlg, DWLP_USER, (INT_PTR)userInfo);
pUserData = (PGENERAL_USER_DATA)HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(GENERAL_USER_DATA) +
lstrlen((LPTSTR)((PROPSHEETPAGE *)lParam)->lParam) * sizeof(TCHAR));
lstrcpy(pUserData->szUserName, (LPTSTR)((PROPSHEETPAGE *)lParam)->lParam);
GetGeneralUserData(hwndDlg,
pUserData);
SetWindowLongPtr(hwndDlg, DWLP_USER, (INT_PTR)pUserData);
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_USER_GENERAL_FORCE_CHANGE:
userInfo->usri3_password_expired = !userInfo->usri3_password_expired;
UpdateUserOptions(hwndDlg, userInfo, FALSE);
pUserData->dwPasswordExpired = !pUserData->dwPasswordExpired;
UpdateUserOptions(hwndDlg, pUserData, FALSE);
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
case IDC_USER_GENERAL_CANNOT_CHANGE:
userInfo->usri3_flags ^= UF_PASSWD_CANT_CHANGE;
UpdateUserOptions(hwndDlg, userInfo, FALSE);
pUserData->dwFlags ^= UF_PASSWD_CANT_CHANGE;
UpdateUserOptions(hwndDlg, pUserData, FALSE);
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
case IDC_USER_GENERAL_NEVER_EXPIRES:
userInfo->usri3_flags ^= UF_DONT_EXPIRE_PASSWD;
UpdateUserOptions(hwndDlg, userInfo, FALSE);
pUserData->dwFlags ^= UF_DONT_EXPIRE_PASSWD;
UpdateUserOptions(hwndDlg, pUserData, FALSE);
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
case IDC_USER_GENERAL_DISABLED:
userInfo->usri3_flags ^= UF_ACCOUNTDISABLE;
pUserData->dwFlags ^= UF_ACCOUNTDISABLE;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
case IDC_USER_GENERAL_LOCKED:
pUserData->dwFlags ^= UF_LOCKOUT;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
}
break;
case WM_NOTIFY:
if (((LPPSHNOTIFY)lParam)->hdr.code == PSN_APPLY)
{
SetGeneralUserData(hwndDlg, pUserData);
return TRUE;
}
break;
case WM_DESTROY:
NetApiBufferFree(userInfo);
HeapFree(GetProcessHeap(), 0, pUserData);
break;
}
@ -304,7 +402,7 @@ InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, LPTSTR pszUse
}
VOID
BOOL
UserProperties(HWND hwndDlg)
{
PROPSHEETPAGE psp[3];
@ -316,7 +414,7 @@ UserProperties(HWND hwndDlg)
hwndLV = GetDlgItem(hwndDlg, IDC_USERS_LIST);
nItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED);
if (nItem == -1)
return;
return FALSE;
/* Get the new user name */
ListView_GetItemText(hwndLV,
@ -339,5 +437,5 @@ UserProperties(HWND hwndDlg)
InitPropSheetPage(&psp[1], IDD_USER_MEMBERSHIP, (DLGPROC)UserMembershipPageProc, szUserName);
InitPropSheetPage(&psp[2], IDD_USER_PROFILE, (DLGPROC)UserProfilePageProc, szUserName);
PropertySheet(&psh);
return (PropertySheet(&psh) == IDOK);
}

View file

@ -596,6 +596,46 @@ OnNotify(HWND hwndDlg, PUSER_DATA pUserData, NMHDR *phdr)
}
static VOID
UpdateUserProperties(HWND hwndDlg)
{
TCHAR szUserName[UNLEN];
INT iItem;
HWND hwndLV;
NET_API_STATUS status;
PUSER_INFO_2 pUserInfo = NULL;
LV_ITEM lvi;
hwndLV = GetDlgItem(hwndDlg, IDC_USERS_LIST);
iItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED);
if (iItem == -1)
return;
/* Get the new user name */
ListView_GetItemText(hwndLV,
iItem, 0,
szUserName,
UNLEN);
status = NetUserGetInfo(NULL, szUserName, 2, (LPBYTE*)&pUserInfo);
memset(&lvi, 0x00, sizeof(lvi));
lvi.iItem = iItem;
lvi.iSubItem = 0;
lvi.mask = LVIF_IMAGE;
lvi.iImage = (pUserInfo->usri2_flags & UF_ACCOUNTDISABLE) ? 1 : 0;
(void)ListView_SetItem(hwndLV, &lvi);
ListView_SetItemText(hwndLV, iItem, 1,
pUserInfo->usri2_full_name);
ListView_SetItemText(hwndLV, iItem, 2,
pUserInfo->usri2_comment);
NetApiBufferFree(pUserInfo);
}
INT_PTR CALLBACK
UsersPageProc(HWND hwndDlg,
UINT uMsg,
@ -646,7 +686,10 @@ UsersPageProc(HWND hwndDlg,
break;
case IDM_USER_PROPERTIES:
UserProperties(hwndDlg);
if (UserProperties(hwndDlg))
{
UpdateUserProperties(hwndDlg);
}
break;
}
break;

View file

@ -30,7 +30,7 @@ INT_PTR CALLBACK GroupsPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
INT_PTR CALLBACK ExtraPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
/* groupprops.c */
VOID
BOOL
GroupProperties(HWND hwndDlg);
/* misc.c */
@ -43,7 +43,7 @@ CheckAccountName(HWND hwndDlg,
LPTSTR lpAccountName);
/* userprops.c */
VOID
BOOL
UserProperties(HWND hwndDlg);
#endif /* __CPL_DESK_H__ */

View file

@ -7,6 +7,7 @@
<define name="_WIN32_WINNT">0x501</define>
<define name="WINVER">0x609</define>
<library>kernel32</library>
<library>advapi32</library>
<library>user32</library>
<library>gdi32</library>
<library>comctl32</library>