ReactOS Fundraising Campaign 2012
 
€ 3,873 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

userprops.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS User Manager Control Panel
00004  * FILE:            dll/cpl/usrmgr/userprops.c
00005  * PURPOSE:         User property sheet
00006  *
00007  * PROGRAMMERS:     Eric Kohl
00008  */
00009 
00010 #include "usrmgr.h"
00011 
00012 typedef struct _GENERAL_USER_DATA
00013 {
00014     DWORD dwFlags;
00015     DWORD dwPasswordExpired;
00016     TCHAR szUserName[1];
00017 } GENERAL_USER_DATA, *PGENERAL_USER_DATA;
00018 
00019 #define VALID_GENERAL_FLAGS (UF_PASSWD_CANT_CHANGE | UF_DONT_EXPIRE_PASSWD | UF_ACCOUNTDISABLE | UF_LOCKOUT)
00020 
00021 typedef struct _PROFILE_USER_DATA
00022 {
00023     TCHAR szUserName[1];
00024 } PROFILE_USER_DATA, *PPROFILE_USER_DATA;
00025 
00026 typedef struct _MEMBERSHIP_USER_DATA
00027 {
00028     PLOCALGROUP_USERS_INFO_0 pGroupData;
00029     DWORD dwGroupCount;
00030     TCHAR szUserName[1];
00031 } MEMBERSHIP_USER_DATA, *PMEMBERSHIP_USER_DATA;
00032 
00033 
00034 static VOID
00035 GetUserProfileData(HWND hwndDlg,
00036                    PPROFILE_USER_DATA pUserData)
00037 {
00038     PUSER_INFO_3 userInfo = NULL;
00039     NET_API_STATUS status;
00040     BOOL bLocal;
00041     TCHAR szDrive[8];
00042     INT i;
00043     INT nSel;
00044 
00045     status = NetUserGetInfo(NULL, pUserData->szUserName, 3, (LPBYTE*)&userInfo);
00046     if (status != NERR_Success)
00047         return;
00048 
00049     SetDlgItemText(hwndDlg, IDC_USER_PROFILE_PATH, userInfo->usri3_profile);
00050     SetDlgItemText(hwndDlg, IDC_USER_PROFILE_SCRIPT, userInfo->usri3_script_path);
00051 
00052 
00053     bLocal = (userInfo->usri3_home_dir_drive == NULL) ||
00054               (_tcslen(userInfo->usri3_home_dir_drive) == 0);
00055     CheckRadioButton(hwndDlg, IDC_USER_PROFILE_LOCAL, IDC_USER_PROFILE_REMOTE,
00056                      bLocal ? IDC_USER_PROFILE_LOCAL : IDC_USER_PROFILE_REMOTE);
00057 
00058     for (i = 0; i < 26; i++)
00059     {
00060         wsprintf(szDrive, _T("%c:"), (TCHAR)('A' + i));
00061         nSel = SendMessage(GetDlgItem(hwndDlg, IDC_USER_PROFILE_DRIVE),
00062                            CB_INSERTSTRING, -1, (LPARAM)szDrive);
00063     }
00064 
00065     if (bLocal)
00066     {
00067         SetDlgItemText(hwndDlg, IDC_USER_PROFILE_LOCAL_PATH, userInfo->usri3_home_dir);
00068         EnableWindow(GetDlgItem(hwndDlg, IDC_USER_PROFILE_DRIVE), FALSE);
00069         EnableWindow(GetDlgItem(hwndDlg, IDC_USER_PROFILE_REMOTE_PATH), FALSE);
00070     }
00071     else
00072     {
00073         SetDlgItemText(hwndDlg, IDC_USER_PROFILE_REMOTE_PATH, userInfo->usri3_home_dir);
00074         nSel = SendMessage(GetDlgItem(hwndDlg, IDC_USER_PROFILE_DRIVE),
00075                            CB_FINDSTRINGEXACT, -1, (LPARAM)userInfo->usri3_home_dir_drive);
00076     }
00077 
00078     SendMessage(GetDlgItem(hwndDlg, IDC_USER_PROFILE_DRIVE),
00079                 CB_SETCURSEL, nSel, 0);
00080 
00081     NetApiBufferFree(userInfo);
00082 }
00083 
00084 
00085 static BOOL
00086 SetUserProfileData(HWND hwndDlg,
00087                    PPROFILE_USER_DATA pUserData)
00088 {
00089     PUSER_INFO_3 pUserInfo = NULL;
00090     LPTSTR pszProfilePath = NULL;
00091     LPTSTR pszScriptPath = NULL;
00092     LPTSTR pszHomeDir = NULL;
00093     LPTSTR pszHomeDrive = NULL;
00094     NET_API_STATUS status;
00095 #if 0
00096     DWORD dwIndex;
00097 #endif
00098     INT nLength;
00099     INT nIndex;
00100 
00101     NetUserGetInfo(NULL, pUserData->szUserName, 3, (LPBYTE*)&pUserInfo);
00102 
00103     /* Get the profile path */
00104     nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_PROFILE_PATH));
00105     if (nLength == 0)
00106     {
00107         pUserInfo->usri3_profile = NULL;
00108     }
00109     else
00110     {
00111         pszProfilePath = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
00112         GetDlgItemText(hwndDlg, IDC_USER_PROFILE_PATH, pszProfilePath, nLength + 1);
00113         pUserInfo->usri3_profile = pszProfilePath;
00114     }
00115 
00116     /* Get the script path */
00117     nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_PROFILE_SCRIPT));
00118     if (nLength == 0)
00119     {
00120         pUserInfo->usri3_script_path = NULL;
00121     }
00122     else
00123     {
00124         pszScriptPath = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
00125         GetDlgItemText(hwndDlg, IDC_USER_PROFILE_SCRIPT, pszScriptPath, nLength + 1);
00126         pUserInfo->usri3_script_path = pszScriptPath;
00127     }
00128 
00129     if (IsDlgButtonChecked(hwndDlg, IDC_USER_PROFILE_LOCAL) == BST_CHECKED)
00130     {
00131         /* Local home directory */
00132         nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_PROFILE_LOCAL_PATH));
00133         if (nLength == 0)
00134         {
00135             pUserInfo->usri3_home_dir = NULL;
00136         }
00137         else
00138         {
00139             pszHomeDir = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
00140             GetDlgItemText(hwndDlg, IDC_USER_PROFILE_LOCAL_PATH, pszHomeDir, nLength + 1);
00141             pUserInfo->usri3_home_dir = pszHomeDir;
00142         }
00143     }
00144     else
00145     {
00146         /* Remote home directory */
00147         nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_PROFILE_REMOTE_PATH));
00148         if (nLength == 0)
00149         {
00150             pUserInfo->usri3_home_dir = NULL;
00151         }
00152         else
00153         {
00154             pszHomeDir = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
00155             GetDlgItemText(hwndDlg, IDC_USER_PROFILE_REMOTE_PATH, pszHomeDir, nLength + 1);
00156             pUserInfo->usri3_home_dir = pszHomeDir;
00157         }
00158 
00159         nIndex = SendMessage(GetDlgItem(hwndDlg, IDC_USER_PROFILE_DRIVE), CB_GETCURSEL, 0, 0);
00160         if (nIndex != CB_ERR)
00161         {
00162             nLength = SendMessage(GetDlgItem(hwndDlg, IDC_USER_PROFILE_DRIVE), CB_GETLBTEXTLEN, nIndex, 0);
00163             pszHomeDrive = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
00164             SendMessage(GetDlgItem(hwndDlg, IDC_USER_PROFILE_DRIVE), CB_GETLBTEXT, nIndex, (LPARAM)pszHomeDrive);
00165             pUserInfo->usri3_home_dir_drive = pszHomeDrive;
00166         }
00167     }
00168 
00169 #if 0
00170     status = NetUserSetInfo(NULL, pUserData->szUserName, 3, (LPBYTE)pUserInfo, &dwIndex);
00171     if (status != NERR_Success)
00172     {
00173         DebugPrintf(_T("Status: %lu  Index: %lu"), status, dwIndex);
00174     }
00175 #else
00176     status = NERR_Success;
00177 #endif
00178 
00179     if (pszProfilePath)
00180         HeapFree(GetProcessHeap(), 0, pszProfilePath);
00181 
00182     if (pszScriptPath)
00183         HeapFree(GetProcessHeap(), 0, pszScriptPath);
00184 
00185     if (pszHomeDir)
00186         HeapFree(GetProcessHeap(), 0, pszHomeDir);
00187 
00188     if (pszHomeDrive)
00189         HeapFree(GetProcessHeap(), 0, pszHomeDrive);
00190 
00191     NetApiBufferFree(pUserInfo);
00192 
00193     return (status == NERR_Success);
00194 }
00195 
00196 
00197 INT_PTR CALLBACK
00198 UserProfilePageProc(HWND hwndDlg,
00199                     UINT uMsg,
00200                     WPARAM wParam,
00201                     LPARAM lParam)
00202 {
00203     PPROFILE_USER_DATA pUserData;
00204 
00205     UNREFERENCED_PARAMETER(lParam);
00206     UNREFERENCED_PARAMETER(wParam);
00207     UNREFERENCED_PARAMETER(hwndDlg);
00208 
00209     pUserData= (PPROFILE_USER_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
00210 
00211     switch (uMsg)
00212     {
00213         case WM_INITDIALOG:
00214             pUserData = (PPROFILE_USER_DATA)HeapAlloc(GetProcessHeap(),
00215                                                       HEAP_ZERO_MEMORY,
00216                                                       sizeof(PROFILE_USER_DATA) + 
00217                                                       lstrlen((LPTSTR)((PROPSHEETPAGE *)lParam)->lParam) * sizeof(TCHAR));
00218             lstrcpy(pUserData->szUserName, (LPTSTR)((PROPSHEETPAGE *)lParam)->lParam);
00219 
00220             SetWindowLongPtr(hwndDlg, DWLP_USER, (INT_PTR)pUserData);
00221 
00222             GetUserProfileData(hwndDlg,
00223                                pUserData);
00224             break;
00225 
00226         case WM_COMMAND:
00227             switch (LOWORD(wParam))
00228             {
00229                 case IDC_USER_PROFILE_PATH:
00230                 case IDC_USER_PROFILE_SCRIPT:
00231                     if (HIWORD(wParam) == EN_CHANGE)
00232                         PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
00233                     break;
00234 
00235                 case IDC_USER_PROFILE_LOCAL:
00236                     EnableWindow(GetDlgItem(hwndDlg, IDC_USER_PROFILE_LOCAL_PATH), TRUE);
00237                     EnableWindow(GetDlgItem(hwndDlg, IDC_USER_PROFILE_DRIVE), FALSE);
00238                     EnableWindow(GetDlgItem(hwndDlg, IDC_USER_PROFILE_REMOTE_PATH), FALSE);
00239                     break;
00240 
00241                 case IDC_USER_PROFILE_REMOTE:
00242                     EnableWindow(GetDlgItem(hwndDlg, IDC_USER_PROFILE_LOCAL_PATH), FALSE);
00243                     EnableWindow(GetDlgItem(hwndDlg, IDC_USER_PROFILE_DRIVE), TRUE);
00244                     EnableWindow(GetDlgItem(hwndDlg, IDC_USER_PROFILE_REMOTE_PATH), TRUE);
00245                     break;
00246             }
00247             break;
00248 
00249         case WM_DESTROY:
00250             HeapFree(GetProcessHeap(), 0, pUserData);
00251             break;
00252 
00253         case WM_NOTIFY:
00254             if (((LPPSHNOTIFY)lParam)->hdr.code == PSN_APPLY)
00255             {
00256                 SetUserProfileData(hwndDlg, pUserData);
00257                 return TRUE;
00258             }
00259             break;
00260     }
00261 
00262     return FALSE;
00263 }
00264 
00265 
00266 static VOID
00267 GetUserMembershipData(HWND hwndDlg, PMEMBERSHIP_USER_DATA pUserData)
00268 {
00269     NET_API_STATUS status;
00270     DWORD dwTotal;
00271     DWORD i;
00272     HIMAGELIST hImgList;
00273     HICON hIcon;
00274     LV_ITEM lvi;
00275     HWND hwndLV;
00276     LV_COLUMN column;
00277     RECT rect;
00278 
00279 
00280     hwndLV = GetDlgItem(hwndDlg, IDC_USER_MEMBERSHIP_LIST);
00281 
00282     /* Create the image list */
00283     hImgList = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 5, 5);
00284     hIcon = LoadImage(hApplet, MAKEINTRESOURCE(IDI_GROUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
00285     ImageList_AddIcon(hImgList, hIcon);
00286     DestroyIcon(hIcon);
00287     (void)ListView_SetImageList(hwndLV, hImgList, LVSIL_SMALL);
00288 
00289     /* Set the list column */
00290     GetClientRect(hwndLV, &rect);
00291 
00292     memset(&column, 0x00, sizeof(column));
00293     column.mask = LVCF_FMT | LVCF_WIDTH | LVCF_SUBITEM;
00294     column.fmt = LVCFMT_LEFT;
00295     column.cx = (INT)(rect.right - rect.left);
00296     column.iSubItem = 0;
00297     (void)ListView_InsertColumn(hwndLV, 0, &column);
00298 
00299 
00300     status = NetUserGetLocalGroups(NULL, pUserData->szUserName, 0, 0,
00301                                    (LPBYTE*)&pUserData->pGroupData,
00302                                    MAX_PREFERRED_LENGTH,
00303                                    &pUserData->dwGroupCount,
00304                                    &dwTotal);
00305     if (status != NERR_Success)
00306         return;
00307 
00308     for (i = 0; i < pUserData->dwGroupCount; i++)
00309     {
00310         ZeroMemory(&lvi, sizeof(lvi));
00311         lvi.mask = LVIF_TEXT | LVIF_STATE | LVIF_IMAGE;
00312         lvi.pszText = pUserData->pGroupData[i].lgrui0_name;
00313         lvi.state = 0;
00314         lvi.iImage = 0; 
00315 
00316         (void)ListView_InsertItem(hwndLV, &lvi);
00317     }
00318 }
00319 
00320 
00321 static VOID
00322 RemoveGroupFromUser(HWND hwndDlg,
00323                     PMEMBERSHIP_USER_DATA pUserData)
00324 {
00325     TCHAR szGroupName[UNLEN];
00326     TCHAR szText[256];
00327     LOCALGROUP_MEMBERS_INFO_3 memberInfo;
00328     HWND hwndLV;
00329     INT nItem;
00330     NET_API_STATUS status;
00331 
00332     hwndLV = GetDlgItem(hwndDlg, IDC_USER_MEMBERSHIP_LIST);
00333     nItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED);
00334     if (nItem == -1)
00335         return;
00336 
00337     /* Get the new user name */
00338     ListView_GetItemText(hwndLV,
00339                          nItem, 0,
00340                          szGroupName,
00341                          UNLEN);
00342 
00343     /* Display a warning message because the remove operation cannot be reverted */
00344     wsprintf(szText, TEXT("Do you really want to remove the user \"%s\" from the group \"%s\"?"),
00345              pUserData->szUserName, szGroupName);
00346     if (MessageBox(NULL, szText, TEXT("User Accounts"), MB_ICONWARNING | MB_YESNO) == IDNO)
00347         return;
00348 
00349     memberInfo.lgrmi3_domainandname = pUserData->szUserName;
00350 
00351     status = NetLocalGroupDelMembers(NULL, szGroupName,
00352                                      3, (LPBYTE)&memberInfo, 1);
00353     if (status != NERR_Success)
00354     {
00355         TCHAR szText[256];
00356         wsprintf(szText, TEXT("Error: %u"), status);
00357         MessageBox(NULL, szText, TEXT("NetLocalGroupDelMembers"), MB_ICONERROR | MB_OK);
00358         return;
00359     }
00360 
00361     (void)ListView_DeleteItem(hwndLV, nItem);
00362 
00363     if (ListView_GetItemCount(hwndLV) == 0)
00364         EnableWindow(GetDlgItem(hwndDlg, IDC_USER_MEMBERSHIP_REMOVE), FALSE);
00365 }
00366 
00367 
00368 static VOID
00369 InitUserGroupsList(HWND hwndDlg)
00370 {
00371     HWND hwndLV;
00372     LV_COLUMN column;
00373     RECT rect;
00374     TCHAR szStr[32];
00375 
00376     NET_API_STATUS netStatus;
00377     PLOCALGROUP_INFO_1 pBuffer;
00378     DWORD entriesread;
00379     DWORD totalentries;
00380     DWORD_PTR resume_handle = 0;
00381     DWORD i;
00382     LV_ITEM lvi;
00383     INT iItem;
00384 
00385     HIMAGELIST hImgList;
00386     HICON hIcon;
00387 
00388     hwndLV = GetDlgItem(hwndDlg, IDC_USER_ADD_MEMBERSHIP_LIST);
00389     GetClientRect(hwndLV, &rect);
00390 
00391     hImgList = ImageList_Create(16,16,ILC_COLOR8 | ILC_MASK,5,5);
00392     hIcon = LoadImage(hApplet,MAKEINTRESOURCE(IDI_GROUP),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
00393     ImageList_AddIcon(hImgList,hIcon);
00394     DestroyIcon(hIcon);
00395 
00396     (void)ListView_SetImageList(hwndLV, hImgList, LVSIL_SMALL);
00397     (void)ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT);
00398 
00399     memset(&column, 0x00, sizeof(column));
00400     column.mask = LVCF_FMT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_TEXT;
00401     column.fmt = LVCFMT_LEFT;
00402     column.cx = (INT)((rect.right - rect.left) * 0.40);
00403     column.iSubItem = 0;
00404     LoadString(hApplet, IDS_NAME, szStr, sizeof(szStr) / sizeof(szStr[0]));
00405     column.pszText = szStr;
00406     (void)ListView_InsertColumn(hwndLV, 0, &column);
00407 
00408     column.cx = (INT)((rect.right - rect.left) * 0.60);
00409     column.iSubItem = 1;
00410     LoadString(hApplet, IDS_DESCRIPTION, szStr, sizeof(szStr) / sizeof(szStr[0]));
00411     column.pszText = szStr;
00412     (void)ListView_InsertColumn(hwndLV, 1, &column);
00413 
00414     for (;;)
00415     {
00416         netStatus = NetLocalGroupEnum(NULL, 1, (LPBYTE*)&pBuffer,
00417                                       1024, &entriesread,
00418                                       &totalentries, &resume_handle);
00419         if (netStatus != NERR_Success && netStatus != ERROR_MORE_DATA)
00420             break;
00421 
00422         for (i = 0; i < entriesread; i++)
00423         {
00424            memset(&lvi, 0x00, sizeof(lvi));
00425            lvi.mask = LVIF_TEXT | LVIF_STATE | LVIF_IMAGE;
00426            lvi.pszText = pBuffer[i].lgrpi1_name;
00427            lvi.state = 0;
00428            lvi.iImage = 0;
00429            iItem = ListView_InsertItem(hwndLV, &lvi);
00430 
00431            ListView_SetItemText(hwndLV, iItem, 1,
00432                                 pBuffer[i].lgrpi1_comment);
00433         }
00434 
00435         NetApiBufferFree(pBuffer);
00436 
00437         /* No more data left */
00438         if (netStatus != ERROR_MORE_DATA)
00439             break;
00440     }
00441 }
00442 
00443 
00444 static BOOL
00445 AddSelectedGroupsToUser(HWND hwndDlg,
00446                         PMEMBERSHIP_USER_DATA pUserData)
00447 {
00448     HWND hwndLV;
00449     INT nItem;
00450     TCHAR szGroupName[UNLEN];
00451     BOOL bResult = FALSE;
00452     BOOL bFound;
00453     DWORD i;
00454     LOCALGROUP_MEMBERS_INFO_3 memberInfo;
00455     NET_API_STATUS status;
00456 
00457     hwndLV = GetDlgItem(hwndDlg, IDC_USER_ADD_MEMBERSHIP_LIST);
00458 
00459     if (ListView_GetSelectedCount(hwndLV) > 0)
00460     {
00461         nItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED);
00462         while (nItem != -1)
00463         {
00464             /* Get the new user name */
00465             ListView_GetItemText(hwndLV,
00466                                  nItem, 0,
00467                                  szGroupName,
00468                                  UNLEN);
00469 
00470             bFound = FALSE;
00471             for (i = 0; i < pUserData->dwGroupCount; i++)
00472             {
00473                 if (_tcscmp(pUserData->pGroupData[i].lgrui0_name, szGroupName) == 0)
00474                     bFound = TRUE;
00475             }
00476 
00477             if (!bFound)
00478             {
00479                 memberInfo.lgrmi3_domainandname = pUserData->szUserName;
00480 
00481                 status = NetLocalGroupAddMembers(NULL, szGroupName, 3,
00482                                                  (LPBYTE)&memberInfo, 1);
00483                 if (status == NERR_Success)
00484                 {
00485                     DebugPrintf(_TEXT("Selected group: %s"), szGroupName);
00486                     bResult = TRUE;
00487                 }
00488                 else
00489                 {
00490                     TCHAR szText[256];
00491                     wsprintf(szText, TEXT("Error: %u"), status);
00492                     MessageBox(NULL, szText, TEXT("NetLocalGroupAddMembers"), MB_ICONERROR | MB_OK);
00493                 }
00494             }
00495 
00496             nItem = ListView_GetNextItem(hwndLV, nItem, LVNI_SELECTED);
00497         }
00498     }
00499 
00500     return bResult;
00501 }
00502 
00503 
00504 INT_PTR CALLBACK
00505 AddGroupToUserDlgProc(HWND hwndDlg,
00506                       UINT uMsg,
00507                       WPARAM wParam,
00508                       LPARAM lParam)
00509 {
00510     PMEMBERSHIP_USER_DATA pUserData;
00511 
00512     UNREFERENCED_PARAMETER(wParam);
00513 
00514     pUserData= (PMEMBERSHIP_USER_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
00515 
00516     switch (uMsg)
00517     {
00518         case WM_INITDIALOG:
00519             pUserData= (PMEMBERSHIP_USER_DATA)lParam;
00520             SetWindowLongPtr(hwndDlg, DWLP_USER, (INT_PTR)pUserData);
00521             InitUserGroupsList(hwndDlg);
00522             break;
00523 
00524         case WM_COMMAND:
00525             switch (LOWORD(wParam))
00526             {
00527                 case IDOK:
00528                     if (AddSelectedGroupsToUser(hwndDlg, pUserData))
00529                         EndDialog(hwndDlg, IDOK);
00530                     else
00531                         EndDialog(hwndDlg, IDCANCEL);
00532                     break;
00533 
00534                 case IDCANCEL:
00535                     EndDialog(hwndDlg, IDCANCEL);
00536                     break;
00537             }
00538             break;
00539 
00540         default:
00541             return FALSE;
00542     }
00543 
00544     return TRUE;
00545 }
00546 
00547 
00548 static VOID
00549 AddGroupToUser(HWND hwndDlg,
00550                PMEMBERSHIP_USER_DATA pUserData)
00551 {
00552     HWND hwndLV;
00553     NET_API_STATUS status;
00554     DWORD i;
00555     DWORD dwTotal;
00556     LV_ITEM lvi;
00557 
00558     if (DialogBoxParam(hApplet,
00559                        MAKEINTRESOURCE(IDD_USER_ADD_MEMBERSHIP),
00560                        hwndDlg,
00561                        AddGroupToUserDlgProc,
00562                        (LPARAM)pUserData) == IDOK)
00563     {
00564         // TODO: Update Membership list!
00565         hwndLV = GetDlgItem(hwndDlg, IDC_USER_MEMBERSHIP_LIST);
00566 
00567         if (pUserData->pGroupData)
00568             NetApiBufferFree(pUserData->pGroupData);
00569 
00570         (void)ListView_DeleteAllItems(hwndLV);
00571 
00572         status = NetUserGetLocalGroups(NULL, pUserData->szUserName, 0, 0,
00573                                        (LPBYTE*)&pUserData->pGroupData,
00574                                        MAX_PREFERRED_LENGTH,
00575                                        &pUserData->dwGroupCount,
00576                                        &dwTotal);
00577         if (status != NERR_Success)
00578             return;
00579 
00580         for (i = 0; i < pUserData->dwGroupCount; i++)
00581         {
00582             ZeroMemory(&lvi, sizeof(lvi));
00583             lvi.mask = LVIF_TEXT | LVIF_STATE | LVIF_IMAGE;
00584             lvi.pszText = pUserData->pGroupData[i].lgrui0_name;
00585             lvi.state = 0;
00586             lvi.iImage = 0; 
00587 
00588             (void)ListView_InsertItem(hwndLV, &lvi);
00589         }
00590     }
00591 }
00592 
00593 
00594 static BOOL
00595 OnNotify(HWND hwndDlg,
00596          PMEMBERSHIP_USER_DATA pUserData,
00597          LPARAM lParam)
00598 {
00599     LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lParam;
00600 
00601     switch (((LPNMHDR)lParam)->idFrom)
00602     {
00603         case IDC_USER_MEMBERSHIP_LIST:
00604             switch (((LPNMHDR)lParam)->code)
00605             {
00606                 case NM_CLICK:
00607                     EnableWindow(GetDlgItem(hwndDlg, IDC_USER_MEMBERSHIP_REMOVE), (lpnmlv->iItem != -1));
00608                     break;
00609 
00610                 case LVN_KEYDOWN:
00611                     if (((LPNMLVKEYDOWN)lParam)->wVKey == VK_DELETE)
00612                     {
00613                         RemoveGroupFromUser(hwndDlg, pUserData);
00614                     }
00615                     break;
00616 
00617             }
00618             break;
00619     }
00620 
00621     return FALSE;
00622 }
00623 
00624 
00625 INT_PTR CALLBACK
00626 UserMembershipPageProc(HWND hwndDlg,
00627                        UINT uMsg,
00628                        WPARAM wParam,
00629                        LPARAM lParam)
00630 {
00631     PMEMBERSHIP_USER_DATA pUserData;
00632 
00633     UNREFERENCED_PARAMETER(lParam);
00634     UNREFERENCED_PARAMETER(wParam);
00635     UNREFERENCED_PARAMETER(hwndDlg);
00636 
00637     pUserData= (PMEMBERSHIP_USER_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
00638 
00639     switch (uMsg)
00640     {
00641         case WM_INITDIALOG:
00642             pUserData = (PMEMBERSHIP_USER_DATA)HeapAlloc(GetProcessHeap(),
00643                                                          HEAP_ZERO_MEMORY,
00644                                                          sizeof(MEMBERSHIP_USER_DATA) + 
00645                                                          lstrlen((LPTSTR)((PROPSHEETPAGE *)lParam)->lParam) * sizeof(TCHAR));
00646             lstrcpy(pUserData->szUserName, (LPTSTR)((PROPSHEETPAGE *)lParam)->lParam);
00647 
00648             SetWindowLongPtr(hwndDlg, DWLP_USER, (INT_PTR)pUserData);
00649 
00650             GetUserMembershipData(hwndDlg, pUserData);
00651             break;
00652 
00653         case WM_COMMAND:
00654             switch (LOWORD(wParam))
00655             {
00656                 case IDC_USER_MEMBERSHIP_ADD:
00657                     AddGroupToUser(hwndDlg, pUserData);
00658                     break;
00659 
00660                 case IDC_USER_MEMBERSHIP_REMOVE:
00661                     RemoveGroupFromUser(hwndDlg, pUserData);
00662                     break;
00663             }
00664             break;
00665 
00666         case WM_NOTIFY:
00667             if (((LPPSHNOTIFY)lParam)->hdr.code == PSN_APPLY)
00668             {
00669                 return TRUE;
00670             }
00671             else
00672             {
00673                 return OnNotify(hwndDlg, pUserData, lParam);
00674             }
00675             break;
00676 
00677 
00678         case WM_DESTROY:
00679             if (pUserData->pGroupData)
00680                 NetApiBufferFree(pUserData->pGroupData);
00681 
00682             HeapFree(GetProcessHeap(), 0, pUserData);
00683             break;
00684     }
00685 
00686     return FALSE;
00687 }
00688 
00689 
00690 static VOID
00691 UpdateUserOptions(HWND hwndDlg,
00692                   PGENERAL_USER_DATA pUserData,
00693                   BOOL bInit)
00694 {
00695     EnableWindow(GetDlgItem(hwndDlg, IDC_USER_GENERAL_CANNOT_CHANGE),
00696                  !pUserData->dwPasswordExpired);
00697     EnableWindow(GetDlgItem(hwndDlg, IDC_USER_GENERAL_NEVER_EXPIRES),
00698                  !pUserData->dwPasswordExpired);
00699     EnableWindow(GetDlgItem(hwndDlg, IDC_USER_GENERAL_FORCE_CHANGE),
00700                  (pUserData->dwFlags & (UF_PASSWD_CANT_CHANGE | UF_DONT_EXPIRE_PASSWD)) == 0);
00701 
00702     EnableWindow(GetDlgItem(hwndDlg, IDC_USER_GENERAL_LOCKED),
00703                  (pUserData->dwFlags & UF_LOCKOUT) != 0);
00704 
00705     if (bInit)
00706     {
00707         CheckDlgButton(hwndDlg, IDC_USER_GENERAL_FORCE_CHANGE,
00708                        pUserData->dwPasswordExpired ? BST_CHECKED : BST_UNCHECKED);
00709 
00710         CheckDlgButton(hwndDlg, IDC_USER_GENERAL_CANNOT_CHANGE,
00711                        (pUserData->dwFlags & UF_PASSWD_CANT_CHANGE) ? BST_CHECKED : BST_UNCHECKED);
00712 
00713         CheckDlgButton(hwndDlg, IDC_USER_GENERAL_NEVER_EXPIRES,
00714                        (pUserData->dwFlags & UF_DONT_EXPIRE_PASSWD) ? BST_CHECKED : BST_UNCHECKED);
00715 
00716         CheckDlgButton(hwndDlg, IDC_USER_GENERAL_DISABLED,
00717                        (pUserData->dwFlags & UF_ACCOUNTDISABLE) ? BST_CHECKED : BST_UNCHECKED);
00718 
00719         CheckDlgButton(hwndDlg, IDC_USER_GENERAL_LOCKED,
00720                        (pUserData->dwFlags & UF_LOCKOUT) ? BST_CHECKED : BST_UNCHECKED);
00721     }
00722 }
00723 
00724 
00725 static VOID
00726 GetUserGeneralData(HWND hwndDlg,
00727                    PGENERAL_USER_DATA pUserData)
00728 {
00729     PUSER_INFO_3 pUserInfo = NULL;
00730 
00731     SetDlgItemText(hwndDlg, IDC_USER_GENERAL_NAME, pUserData->szUserName);
00732 
00733     NetUserGetInfo(NULL, pUserData->szUserName, 3, (LPBYTE*)&pUserInfo);
00734 
00735     SetDlgItemText(hwndDlg, IDC_USER_GENERAL_FULL_NAME, pUserInfo->usri3_full_name);
00736     SetDlgItemText(hwndDlg, IDC_USER_GENERAL_DESCRIPTION, pUserInfo->usri3_comment);
00737 
00738     pUserData->dwFlags = pUserInfo->usri3_flags;
00739     pUserData->dwPasswordExpired = pUserInfo->usri3_password_expired;
00740 
00741     NetApiBufferFree(pUserInfo);
00742 
00743     UpdateUserOptions(hwndDlg, pUserData, TRUE);
00744 }
00745 
00746 
00747 static BOOL
00748 SetUserGeneralData(HWND hwndDlg,
00749                    PGENERAL_USER_DATA pUserData)
00750 {
00751     PUSER_INFO_3 pUserInfo = NULL;
00752     LPTSTR pszFullName = NULL;
00753     LPTSTR pszComment = NULL;
00754     NET_API_STATUS status;
00755 #if 0
00756     DWORD dwIndex;
00757 #endif
00758     INT nLength;
00759 
00760     NetUserGetInfo(NULL, pUserData->szUserName, 3, (LPBYTE*)&pUserInfo);
00761 
00762     pUserInfo->usri3_flags =
00763         (pUserData->dwFlags & VALID_GENERAL_FLAGS) |
00764         (pUserInfo->usri3_flags & ~VALID_GENERAL_FLAGS);
00765 
00766     pUserInfo->usri3_password_expired = pUserData->dwPasswordExpired;
00767 
00768     nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_GENERAL_FULL_NAME));
00769     if (nLength == 0)
00770     {
00771         pUserInfo->usri3_full_name = NULL;
00772     }
00773     else
00774     {
00775         pszFullName = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
00776         GetDlgItemText(hwndDlg, IDC_USER_GENERAL_FULL_NAME, pszFullName, nLength + 1);
00777         pUserInfo->usri3_full_name = pszFullName;
00778     }
00779 
00780     nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_GENERAL_DESCRIPTION));
00781     if (nLength == 0)
00782     {
00783         pUserInfo->usri3_full_name = NULL;
00784     }
00785     else
00786     {
00787         pszComment = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
00788         GetDlgItemText(hwndDlg, IDC_USER_GENERAL_DESCRIPTION, pszComment, nLength + 1);
00789         pUserInfo->usri3_comment = pszComment;
00790     }
00791 
00792 #if 0
00793     status = NetUserSetInfo(NULL, pUserData->szUserName, 3, (LPBYTE)pUserInfo, &dwIndex);
00794     if (status != NERR_Success)
00795     {
00796         DebugPrintf(_T("Status: %lu  Index: %lu"), status, dwIndex);
00797     }
00798 #else
00799     status = NERR_Success;
00800 #endif
00801 
00802     if (pszFullName)
00803         HeapFree(GetProcessHeap(), 0, pszFullName);
00804 
00805     if (pszComment)
00806         HeapFree(GetProcessHeap(), 0, pszComment);
00807 
00808     NetApiBufferFree(pUserInfo);
00809 
00810     return (status == NERR_Success);
00811 }
00812 
00813 
00814 INT_PTR CALLBACK
00815 UserGeneralPageProc(HWND hwndDlg,
00816                     UINT uMsg,
00817                     WPARAM wParam,
00818                     LPARAM lParam)
00819 {
00820     PGENERAL_USER_DATA pUserData;
00821 
00822     UNREFERENCED_PARAMETER(lParam);
00823     UNREFERENCED_PARAMETER(wParam);
00824     UNREFERENCED_PARAMETER(hwndDlg);
00825 
00826     pUserData= (PGENERAL_USER_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
00827 
00828     switch (uMsg)
00829     {
00830         case WM_INITDIALOG:
00831             pUserData = (PGENERAL_USER_DATA)HeapAlloc(GetProcessHeap(),
00832                                                       HEAP_ZERO_MEMORY,
00833                                                       sizeof(GENERAL_USER_DATA) + 
00834                                                       lstrlen((LPTSTR)((PROPSHEETPAGE *)lParam)->lParam) * sizeof(TCHAR));
00835             lstrcpy(pUserData->szUserName, (LPTSTR)((PROPSHEETPAGE *)lParam)->lParam);
00836 
00837             SetWindowLongPtr(hwndDlg, DWLP_USER, (INT_PTR)pUserData);
00838 
00839             GetUserGeneralData(hwndDlg,
00840                                pUserData);
00841             break;
00842 
00843         case WM_COMMAND:
00844             switch (LOWORD(wParam))
00845             {
00846                 case IDC_USER_GENERAL_FULL_NAME:
00847                 case IDC_USER_GENERAL_DESCRIPTION:
00848                     if (HIWORD(wParam) == EN_CHANGE)
00849                         PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
00850                     break;
00851 
00852                 case IDC_USER_GENERAL_FORCE_CHANGE:
00853                     pUserData->dwPasswordExpired = !pUserData->dwPasswordExpired;
00854                     UpdateUserOptions(hwndDlg, pUserData, FALSE);
00855                     PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
00856                     break;
00857 
00858                 case IDC_USER_GENERAL_CANNOT_CHANGE:
00859                     pUserData->dwFlags ^= UF_PASSWD_CANT_CHANGE;
00860                     UpdateUserOptions(hwndDlg, pUserData, FALSE);
00861                     PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
00862                     break;
00863 
00864                 case IDC_USER_GENERAL_NEVER_EXPIRES:
00865                     pUserData->dwFlags ^= UF_DONT_EXPIRE_PASSWD;
00866                     UpdateUserOptions(hwndDlg, pUserData, FALSE);
00867                     PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
00868                     break;
00869 
00870                 case IDC_USER_GENERAL_DISABLED:
00871                     pUserData->dwFlags ^= UF_ACCOUNTDISABLE;
00872                     PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
00873                     break;
00874 
00875                 case IDC_USER_GENERAL_LOCKED:
00876                     pUserData->dwFlags ^= UF_LOCKOUT;
00877                     PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
00878                     break;
00879             }
00880             break;
00881 
00882         case WM_NOTIFY:
00883             if (((LPPSHNOTIFY)lParam)->hdr.code == PSN_APPLY)
00884             {
00885                 SetUserGeneralData(hwndDlg, pUserData);
00886                 return TRUE;
00887             }
00888             break;
00889 
00890         case WM_DESTROY:
00891             HeapFree(GetProcessHeap(), 0, pUserData);
00892             break;
00893     }
00894 
00895     return FALSE;
00896 }
00897 
00898 
00899 static VOID
00900 InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, LPTSTR pszUser)
00901 {
00902     ZeroMemory(psp, sizeof(PROPSHEETPAGE));
00903     psp->dwSize = sizeof(PROPSHEETPAGE);
00904     psp->dwFlags = PSP_DEFAULT;
00905     psp->hInstance = hApplet;
00906     psp->pszTemplate = MAKEINTRESOURCE(idDlg);
00907     psp->pfnDlgProc = DlgProc;
00908     psp->lParam = (LPARAM)pszUser;
00909 }
00910 
00911 
00912 BOOL
00913 UserProperties(HWND hwndDlg)
00914 {
00915     PROPSHEETPAGE psp[3];
00916     PROPSHEETHEADER psh;
00917     TCHAR szUserName[UNLEN];
00918     INT nItem;
00919     HWND hwndLV;
00920 
00921     hwndLV = GetDlgItem(hwndDlg, IDC_USERS_LIST);
00922     nItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED);
00923     if (nItem == -1)
00924         return FALSE;
00925 
00926     /* Get the new user name */
00927     ListView_GetItemText(hwndLV,
00928                          nItem, 0,
00929                          szUserName,
00930                          UNLEN);
00931 
00932     ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
00933     psh.dwSize = sizeof(PROPSHEETHEADER);
00934     psh.dwFlags =  PSH_PROPSHEETPAGE | PSH_PROPTITLE;
00935     psh.hwndParent = hwndDlg;
00936     psh.hInstance = hApplet;
00937     psh.hIcon = NULL;
00938     psh.pszCaption = szUserName;
00939     psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
00940     psh.nStartPage = 0;
00941     psh.ppsp = psp;
00942 
00943     InitPropSheetPage(&psp[0], IDD_USER_GENERAL, (DLGPROC)UserGeneralPageProc, szUserName);
00944     InitPropSheetPage(&psp[1], IDD_USER_MEMBERSHIP, (DLGPROC)UserMembershipPageProc, szUserName);
00945     InitPropSheetPage(&psp[2], IDD_USER_PROFILE, (DLGPROC)UserProfilePageProc, szUserName);
00946 
00947     return (PropertySheet(&psh) == IDOK);
00948 }

Generated on Sat May 19 2012 04:18:52 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.