- Implement the creation and removal of user accounts.
authorEric Kohl <eric.kohl@reactos.org>
Tue, 13 May 2008 20:55:37 +0000 (20:55 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Tue, 13 May 2008 20:55:37 +0000 (20:55 +0000)
- User name and passwords are NOT checked upon the creation of a new user account.
- Disable all unimplemented popup menu items.

svn path=/trunk/; revision=33505

reactos/dll/cpl/usrmgr/lang/en-US.rc
reactos/dll/cpl/usrmgr/resource.h
reactos/dll/cpl/usrmgr/users.c

index 6b58949..bdfb932 100644 (file)
@@ -46,37 +46,60 @@ BEGIN
 END
 
 
-
 IDD_CHANGE_PASSWORD DIALOGEX DISCARDABLE  0, 0, 267, 74
-STYLE DS_SHELLFONT | WS_POPUP | WS_CAPTION | WS_SYSMENU
+STYLE  DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_SHELLFONT
 CAPTION "Change Password"
 FONT 8, "MS Shell Dlg"
 BEGIN
-    EDITTEXT        IDC_EDIT_PASSWORD1,107,7,153,14,ES_AUTOHSCROLL
+    EDITTEXT        IDC_EDIT_PASSWORD1,107,7,153,14,ES_AUTOHSCROLL | ES_PASSWORD
     RTEXT           "New Password:", -1,7,10,96,8
-    EDITTEXT        IDC_EDIT_PASSWORD2,107,25,153,14,ES_AUTOHSCROLL
+    EDITTEXT        IDC_EDIT_PASSWORD2,107,25,153,14,ES_AUTOHSCROLL | ES_PASSWORD
     RTEXT           "Repeat Password:", -1,7,28,96,8
     DEFPUSHBUTTON   "OK",IDOK,156,53,50,14
     PUSHBUTTON      "Cancel",IDCANCEL,210,53,50,14
 END
 
 
+IDD_USER_NEW DIALOGEX DISCARDABLE  0, 0, 267, 200
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_SHELLFONT
+CAPTION "New User"
+FONT 8, "MS Shell Dlg"
+BEGIN
+    EDITTEXT        IDC_USER_NEW_NAME,107,7,153,14,ES_AUTOHSCROLL
+    RTEXT           "User name:", -1,7,10,96,8
+    EDITTEXT        IDC_USER_NEW_FULL_NAME,107,25,153,14,ES_AUTOHSCROLL
+    RTEXT           "Full user name:", -1,7,28,96,8
+    EDITTEXT        IDC_USER_NEW_DESCRIPTION,107,43,153,14,ES_AUTOHSCROLL
+    RTEXT           "Description:", -1,7,46,96,8
+    EDITTEXT        IDC_USER_NEW_PASSWORD1,107,67,153,14,ES_AUTOHSCROLL | ES_PASSWORD
+    RTEXT           "Password:", -1,7,70,96,8
+    EDITTEXT        IDC_USER_NEW_PASSWORD2,107,85,153,14,ES_AUTOHSCROLL | ES_PASSWORD
+    RTEXT           "Repeat Password:", -1,7,88,96,8
+    AUTOCHECKBOX    "User must change the password upon first logon",IDC_USER_NEW_FORCE_CHANGE,7,109,200,10
+    AUTOCHECKBOX    "User cannot change the password",IDC_USER_NEW_CANNOT_CHANGE,7,123,200,10,WS_DISABLED
+    AUTOCHECKBOX    "Password never expires",IDC_USER_NEW_NEVER_EXPIRES,7,137,200,10,WS_DISABLED
+    AUTOCHECKBOX    "Account is disabled",IDC_USER_NEW_DISABLED,7,151,200,10
+    DEFPUSHBUTTON   "OK",IDOK,156,179,50,14,WS_DISABLED
+    PUSHBUTTON      "Cancel",IDCANCEL,210,179,50,14
+END
+
+
 /* Menus */
 
 IDM_POPUP_GROUP MENU DISCARDABLE
 BEGIN
     POPUP ""
     BEGIN
-        MENUITEM "New Group...", IDM_GROUP_NEW
+        MENUITEM "New Group...", IDM_GROUP_NEW, GRAYED
     END
     POPUP ""
     BEGIN
-        MENUITEM "Add Member", IDM_GROUP_ADD_MEMBER
+        MENUITEM "Add Member", IDM_GROUP_ADD_MEMBER, GRAYED
         MENUITEM SEPARATOR
-        MENUITEM "Delete", IDM_GROUP_DELETE
-        MENUITEM "Rename", IDM_GROUP_RENAME
+        MENUITEM "Delete", IDM_GROUP_DELETE, GRAYED
+        MENUITEM "Rename", IDM_GROUP_RENAME, GRAYED
         MENUITEM SEPARATOR
-        MENUITEM "Properties", IDM_GROUP_PROPERTIES
+        MENUITEM "Properties", IDM_GROUP_PROPERTIES, GRAYED
     END
 END
 
@@ -94,7 +117,7 @@ BEGIN
         MENUITEM "Delete", IDM_USER_DELETE
         MENUITEM "Rename", IDM_USER_RENAME
         MENUITEM SEPARATOR
-        MENUITEM "Properties", IDM_USER_PROPERTIES
+        MENUITEM "Properties", IDM_USER_PROPERTIES, GRAYED
     END
 END
 
index cd413e8..5a6c7c3 100644 (file)
 #define IDC_EDIT_PASSWORD2          352\r
 \r
 \r
+#define IDD_USER_NEW                360\r
+#define IDC_USER_NEW_NAME           361\r
+#define IDC_USER_NEW_FULL_NAME      362\r
+#define IDC_USER_NEW_DESCRIPTION    363\r
+#define IDC_USER_NEW_PASSWORD1      364\r
+#define IDC_USER_NEW_PASSWORD2      365\r
+#define IDC_USER_NEW_FORCE_CHANGE   366\r
+#define IDC_USER_NEW_CANNOT_CHANGE  367\r
+#define IDC_USER_NEW_NEVER_EXPIRES  368\r
+#define IDC_USER_NEW_DISABLED       369\r
+\r
+\r
 /* Strings */\r
 \r
 #define IDS_CPLNAME                 2000\r
index fa5f92a..5868b68 100644 (file)
@@ -1,5 +1,4 @@
-/* $Id$\r
- *\r
+/*\r
  * COPYRIGHT:       See COPYING in the top level directory\r
  * PROJECT:         ReactOS User Manager Control Panel\r
  * FILE:            dll/cpl/usrmgr/users.c\r
@@ -8,6 +7,16 @@
  * PROGRAMMERS:     Eric Kohl\r
  */\r
 \r
+/*\r
+ * TODO:\r
+ *  - Add new user to the users group.\r
+ *  - Check a new users name for illegal characters.\r
+ *  - Check whether both passwords are the same for a new user.\r
+ *  - Remove a user from all groups.\r
+ *  - Implement user property pages.\r
+ *  - Use localized messages.\r
+ */\r
+\r
 #include "usrmgr.h"\r
 \r
 \r
@@ -22,15 +31,17 @@ typedef struct _USER_DATA
 \r
 \r
 static BOOL\r
-SetPassword(HWND hwndDlg)\r
+CheckPasswords(HWND hwndDlg,\r
+               INT nIdDlgItem1,\r
+               INT nIdDlgItem2)\r
 {\r
     TCHAR szPassword1[256];\r
     TCHAR szPassword2[256];\r
     UINT uLen1;\r
     UINT uLen2;\r
 \r
-    uLen1 = GetDlgItemText(hwndDlg, IDC_EDIT_PASSWORD1, szPassword1, 256);\r
-    uLen2 = GetDlgItemText(hwndDlg, IDC_EDIT_PASSWORD2, szPassword2, 256);\r
+    uLen1 = GetDlgItemText(hwndDlg, nIdDlgItem1, szPassword1, 256);\r
+    uLen2 = GetDlgItemText(hwndDlg, nIdDlgItem2, szPassword2, 256);\r
 \r
     /* Check the passwords */\r
     if (uLen1 != uLen2 || _tcscmp(szPassword1, szPassword2) != 0)\r
@@ -64,7 +75,7 @@ ChangePasswordDlgProc(HWND hwndDlg,
             switch (LOWORD(wParam))\r
             {\r
                 case IDOK:\r
-                    if (SetPassword(hwndDlg))\r
+                    if (CheckPasswords(hwndDlg, IDC_EDIT_PASSWORD1, IDC_EDIT_PASSWORD2))\r
                         EndDialog(hwndDlg, 0);\r
                     break;\r
 \r
@@ -82,6 +93,204 @@ ChangePasswordDlgProc(HWND hwndDlg,
 }\r
 \r
 \r
+INT_PTR CALLBACK\r
+NewUserDlgProc(HWND hwndDlg,\r
+               UINT uMsg,\r
+               WPARAM wParam,\r
+               LPARAM lParam)\r
+{\r
+    PUSER_INFO_3 userInfo;\r
+    INT nLength;\r
+\r
+    UNREFERENCED_PARAMETER(wParam);\r
+\r
+    switch (uMsg)\r
+    {\r
+        case WM_INITDIALOG:\r
+            SetWindowLongPtr(hwndDlg, DWLP_USER, lParam);\r
+            CheckDlgButton(hwndDlg, IDC_USER_NEW_FORCE_CHANGE, BST_CHECKED);\r
+            break;\r
+\r
+        case WM_COMMAND:\r
+            switch (LOWORD(wParam))\r
+            {\r
+                case IDC_USER_NEW_NAME:\r
+                    if (HIWORD(wParam) == EN_CHANGE)\r
+                    {\r
+                        nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_NAME, WM_GETTEXTLENGTH, 0, 0);\r
+                        EnableWindow(GetDlgItem(hwndDlg, IDOK), (nLength > 0));\r
+                    }\r
+                    break;\r
+\r
+                case IDOK:\r
+                    userInfo = (LPUSER_INFO_3)GetWindowLongPtr(hwndDlg, DWLP_USER);\r
+\r
+                    nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_NAME, WM_GETTEXTLENGTH, 0, 0);\r
+                    if (nLength > 0)\r
+                    {\r
+                        userInfo->usri3_name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));\r
+                        GetDlgItemText(hwndDlg, IDC_USER_NEW_NAME, userInfo->usri3_name, nLength + 1);\r
+                    }\r
+\r
+                    nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_FULL_NAME, WM_GETTEXTLENGTH, 0, 0);\r
+                    if (nLength > 0)\r
+                    {\r
+                        userInfo->usri3_full_name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));\r
+                        GetDlgItemText(hwndDlg, IDC_USER_NEW_FULL_NAME, userInfo->usri3_full_name, nLength + 1);\r
+                    }\r
+\r
+                    nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_DESCRIPTION, WM_GETTEXTLENGTH, 0, 0);\r
+                    if (nLength > 0)\r
+                    {\r
+                        userInfo->usri3_comment = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));\r
+                        GetDlgItemText(hwndDlg, IDC_USER_NEW_DESCRIPTION, userInfo->usri3_comment, nLength + 1);\r
+                    }\r
+\r
+                    /* Store the password */\r
+                    nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_PASSWORD1, WM_GETTEXTLENGTH, 0, 0);\r
+                    if (nLength > 0)\r
+                    {\r
+                        userInfo->usri3_password = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));\r
+                        GetDlgItemText(hwndDlg, IDC_USER_NEW_PASSWORD1, userInfo->usri3_password, nLength + 1);\r
+                    }\r
+\r
+                    if (IsDlgButtonChecked(hwndDlg, IDC_USER_NEW_FORCE_CHANGE) == BST_CHECKED)\r
+                        userInfo->usri3_password_expired = TRUE;\r
+\r
+                    if (IsDlgButtonChecked(hwndDlg, IDC_USER_NEW_DISABLED) == BST_CHECKED)\r
+                        userInfo->usri3_flags |= UF_ACCOUNTDISABLE;\r
+\r
+                    EndDialog(hwndDlg, IDOK);\r
+                    break;\r
+\r
+                case IDCANCEL:\r
+                    EndDialog(hwndDlg, IDCANCEL);\r
+                    break;\r
+            }\r
+            break;\r
+\r
+        default:\r
+            return FALSE;\r
+    }\r
+\r
+    return TRUE;\r
+}\r
+\r
+\r
+static VOID\r
+UserNew(HWND hwndDlg)\r
+{\r
+    USER_INFO_3 user;\r
+    NET_API_STATUS status;\r
+    LV_ITEM lvi;\r
+    INT iItem;\r
+    HWND hwndLV;\r
+\r
+    ZeroMemory(&user, sizeof(USER_INFO_3));\r
+\r
+    user.usri3_priv = USER_PRIV_USER;\r
+    user.usri3_flags = UF_SCRIPT;\r
+    user.usri3_acct_expires = TIMEQ_FOREVER;\r
+    user.usri3_max_storage = USER_MAXSTORAGE_UNLIMITED;\r
+    user.usri3_primary_group_id = DOMAIN_GROUP_RID_USERS;\r
+\r
+    if (DialogBoxParam(hApplet,\r
+                       MAKEINTRESOURCE(IDD_USER_NEW),\r
+                       hwndDlg,\r
+                       NewUserDlgProc,\r
+                       (LPARAM)&user) == IDOK)\r
+    {\r
+#if 0\r
+        status = NetUserAdd(NULL,\r
+                            3,\r
+                            (LPBYTE)&user,\r
+                            NULL);\r
+#else\r
+        status = NERR_Success;\r
+#endif\r
+        if (status != NERR_Success)\r
+        {\r
+            TCHAR szText[256];\r
+            wsprintf(szText, TEXT("Error: %u"), status);\r
+            MessageBox(NULL, szText, TEXT("NetUserAdd"), MB_ICONERROR | MB_OK);\r
+            return;\r
+        }\r
+\r
+        hwndLV = GetDlgItem(hwndDlg, IDC_USERS_LIST);\r
+\r
+        ZeroMemory(&lvi, sizeof(lvi));\r
+        lvi.mask = LVIF_TEXT | LVIF_STATE | LVIF_IMAGE;\r
+        lvi.pszText = user.usri3_name;\r
+        lvi.state = 0;\r
+        lvi.iImage = (user.usri3_flags & UF_ACCOUNTDISABLE) ? 1 : 0;\r
+        iItem = ListView_InsertItem(hwndLV, &lvi);\r
+\r
+        ListView_SetItemText(hwndLV, iItem, 1,\r
+                             user.usri3_full_name);\r
+\r
+        ListView_SetItemText(hwndLV, iItem, 2,\r
+                             user.usri3_comment);\r
+    }\r
+\r
+    if (user.usri3_name)\r
+        HeapFree(GetProcessHeap, 0, user.usri3_name);\r
+\r
+    if (user.usri3_full_name)\r
+        HeapFree(GetProcessHeap, 0, user.usri3_full_name);\r
+\r
+    if (user.usri3_comment)\r
+        HeapFree(GetProcessHeap, 0, user.usri3_comment);\r
+\r
+    if (user.usri3_password)\r
+        HeapFree(GetProcessHeap, 0, user.usri3_password);\r
+}\r
+\r
+\r
+static BOOL\r
+UserDelete(HWND hwndDlg)\r
+{\r
+    TCHAR szUserName[UNLEN];\r
+    TCHAR szText[256];\r
+    INT nItem;\r
+    HWND hwndLV;\r
+    NET_API_STATUS status;\r
+\r
+    hwndLV = GetDlgItem(hwndDlg, IDC_USERS_LIST);\r
+    nItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED);\r
+    if (nItem == -1)\r
+        return FALSE;\r
+\r
+    /* Get the new user name */\r
+    ListView_GetItemText(hwndLV,\r
+                         nItem, 0,\r
+                         szUserName,\r
+                         UNLEN);\r
+\r
+    /* Display a warning message because the delete operation cannot be reverted */\r
+    wsprintf(szText, TEXT("Dou you really want to delete the user \"%s\"?"), szUserName);\r
+    if (MessageBox(NULL, szText, TEXT("User Accounts"), MB_ICONWARNING | MB_YESNO) == IDNO)\r
+        return FALSE;\r
+\r
+    /* Delete the user */\r
+#if 0\r
+    status = NetUserDel(NULL, szUserName);\r
+#else\r
+    status = NERR_Success;\r
+#endif\r
+    if (status != NERR_Success)\r
+    {\r
+        TCHAR szText[256];\r
+        wsprintf(szText, TEXT("Error: %u"), status);\r
+        MessageBox(NULL, szText, TEXT("NetUserDel"), MB_ICONERROR | MB_OK);\r
+        return FALSE;\r
+    }\r
+\r
+    /* Delete the user from the list */\r
+    (void)ListView_DeleteItem(hwndLV, nItem);\r
+\r
+    return TRUE;\r
+}\r
+\r
 \r
 static VOID\r
 SetUsersListColumns(HWND hwndListView)\r
@@ -124,7 +333,6 @@ UpdateUsersList(HWND hwndListView)
     DWORD totalentries;\r
     DWORD resume_handle = 0;\r
     DWORD i;\r
-\r
     LV_ITEM lvi;\r
     INT iItem;\r
 \r
@@ -141,10 +349,9 @@ UpdateUsersList(HWND hwndListView)
         for (i = 0; i < entriesread; i++)\r
         {\r
            memset(&lvi, 0x00, sizeof(lvi));\r
-           lvi.mask = LVIF_TEXT | LVIF_STATE | LVIF_IMAGE; // | LVIF_PARAM;\r
-//           lvi.lParam = (LPARAM)VarData;\r
+           lvi.mask = LVIF_TEXT | LVIF_STATE | LVIF_IMAGE;\r
            lvi.pszText = pBuffer[i].usri20_name;\r
-           lvi.state = 0; //(i == 0) ? LVIS_SELECTED : 0;\r
+           lvi.state = 0;\r
            lvi.iImage = (pBuffer[i].usri20_flags & UF_ACCOUNTDISABLE) ? 1 : 0;\r
            iItem = ListView_InsertItem(hwndListView, &lvi);\r
 \r
@@ -189,9 +396,6 @@ OnInitDialog(HWND hwndDlg)
     SetUsersListColumns(hwndListView);\r
 \r
     UpdateUsersList(hwndListView);\r
-\r
-//    (void)ListView_SetColumnWidth(hwndListView, 3, LVSCW_AUTOSIZE_USEHEADER);\r
-//    (void)ListView_Update(hwndListView, 0);\r
 }\r
 \r
 \r
@@ -337,6 +541,14 @@ UsersPageProc(HWND hwndDlg,
                     }\r
                     break;\r
 \r
+                case IDM_USER_NEW:\r
+                    UserNew(hwndDlg);\r
+                    break;\r
+\r
+                case IDM_USER_DELETE:\r
+                    UserDelete(hwndDlg);\r
+                    break;\r
+\r
                 case IDM_USER_PROPERTIES:\r
                     MessageBeep(-1);\r
                     break;\r