cb222ce7f1da87829f57172a894268bac567abe2
[public/netxms.git] / src / console / win32 / UserEditor.cpp
1 // UserEditor.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "nxcon.h"
6 #include "UserEditor.h"
7
8 #ifdef _DEBUG
9 #define new DEBUG_NEW
10 #undef THIS_FILE
11 static char THIS_FILE[] = __FILE__;
12 #endif
13
14 /////////////////////////////////////////////////////////////////////////////
15 // CUserEditor
16
17 IMPLEMENT_DYNCREATE(CUserEditor, CMDIChildWnd)
18
19 CUserEditor::CUserEditor()
20 {
21 m_dwCurrentUser = INVALID_UID;
22 }
23
24 CUserEditor::~CUserEditor()
25 {
26 }
27
28
29 BEGIN_MESSAGE_MAP(CUserEditor, CMDIChildWnd)
30 //{{AFX_MSG_MAP(CUserEditor)
31 ON_WM_CLOSE()
32 ON_WM_DESTROY()
33 ON_WM_CREATE()
34 ON_WM_SIZE()
35 ON_COMMAND(ID_VIEW_REFRESH, OnViewRefresh)
36 ON_COMMAND(ID_USER_CREATE_GROUP, OnUserCreateGroup)
37 ON_COMMAND(ID_USER_CREATE_USER, OnUserCreateUser)
38 ON_WM_SETFOCUS()
39 ON_COMMAND(ID_USER_PROPERTIES, OnUserProperties)
40 ON_COMMAND(ID_USER_DELETE, OnUserDelete)
41 ON_WM_CONTEXTMENU()
42 ON_UPDATE_COMMAND_UI(ID_USER_PROPERTIES, OnUpdateUserProperties)
43 ON_UPDATE_COMMAND_UI(ID_USER_DELETE, OnUpdateUserDelete)
44 ON_COMMAND(ID_USER_SETPASSWORD, OnUserSetpassword)
45 ON_UPDATE_COMMAND_UI(ID_USER_SETPASSWORD, OnUpdateUserSetpassword)
46 //}}AFX_MSG_MAP
47 ON_MESSAGE(NXCM_USERDB_CHANGE, OnUserDBChange)
48 ON_NOTIFY(NM_DBLCLK, IDC_LIST_VIEW, OnListViewDblClk)
49 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_VIEW, OnListViewItemChange)
50 END_MESSAGE_MAP()
51
52 /////////////////////////////////////////////////////////////////////////////
53 // CUserEditor message handlers
54
55 BOOL CUserEditor::PreCreateWindow(CREATESTRUCT& cs)
56 {
57 if (cs.lpszClass == NULL)
58 cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW,
59 NULL,
60 GetSysColorBrush(COLOR_WINDOW),
61 AfxGetApp()->LoadIcon(IDI_USER_GROUP));
62 return CMDIChildWnd::PreCreateWindow(cs);
63 }
64
65
66 //
67 // WM_CLOSE message handler
68 //
69
70 void CUserEditor::OnClose()
71 {
72 DoRequestArg1(NXCUnlockUserDB, g_hSession, _T("Unlocking user database..."));
73 CMDIChildWnd::OnClose();
74 }
75
76
77 //
78 // WM_DESTROY message handler
79 //
80
81 void CUserEditor::OnDestroy()
82 {
83 theApp.OnViewDestroy(VIEW_USER_MANAGER, this);
84 CMDIChildWnd::OnDestroy();
85 }
86
87
88 //
89 // WM_CREATE message handler
90 //
91
92 int CUserEditor::OnCreate(LPCREATESTRUCT lpCreateStruct)
93 {
94 RECT rect;
95 CImageList *pImageList;
96
97 if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
98 return -1;
99
100 theApp.OnViewCreate(VIEW_USER_MANAGER, this);
101
102 // Create list view control
103 GetClientRect(&rect);
104 m_wndListCtrl.Create(WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SINGLESEL, rect, this, IDC_LIST_VIEW);
105 m_wndListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
106 m_wndListCtrl.SetHoverTime(0x7FFFFFFF);
107
108 // Create image list
109 pImageList = new CImageList;
110 pImageList->Create(16, 16, ILC_COLOR8 | ILC_MASK, 8, 8);
111 pImageList->Add(AfxGetApp()->LoadIcon(IDI_USER));
112 pImageList->Add(AfxGetApp()->LoadIcon(IDI_USER_GROUP));
113 pImageList->Add(AfxGetApp()->LoadIcon(IDI_EVERYONE));
114 pImageList->Add(AfxGetApp()->LoadIcon(IDI_OVL_STATUS_CRITICAL));
115 pImageList->SetOverlayImage(3, 1);
116 m_wndListCtrl.SetImageList(pImageList, LVSIL_SMALL);
117
118 // Setup columns
119 m_wndListCtrl.InsertColumn(0, _T("Name"), LVCFMT_LEFT, 100);
120 m_wndListCtrl.InsertColumn(1, _T("Full Name"), LVCFMT_LEFT, 170);
121 m_wndListCtrl.InsertColumn(2, _T("Description"), LVCFMT_LEFT, 300);
122
123 PostMessage(WM_COMMAND, ID_VIEW_REFRESH, 0);
124
125 return 0;
126 }
127
128
129 //
130 // Handler for WM_NOTIFY::NM_DBLCLK from IDC_LIST_VIEW
131 //
132
133 void CUserEditor::OnListViewDblClk(LPNMITEMACTIVATE pNMHDR, LRESULT *pResult)
134 {
135 PostMessage(WM_COMMAND, ID_USER_PROPERTIES, 0);
136 *pResult = 0;
137 }
138
139
140 //
141 // WM_SIZE message handler
142 //
143
144 void CUserEditor::OnSize(UINT nType, int cx, int cy)
145 {
146 CMDIChildWnd::OnSize(nType, cx, cy);
147 m_wndListCtrl.SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOZORDER);
148 }
149
150
151 //
152 // Add new item to list
153 //
154
155 int CUserEditor::AddListItem(NXC_USER *pUser)
156 {
157 int iItem;
158
159 iItem = m_wndListCtrl.InsertItem(0x7FFFFFFF, pUser->szName,
160 (pUser->dwId == GROUP_EVERYONE) ? 2 : ((pUser->dwId & GROUP_FLAG) ? 1 : 0));
161 if (iItem != -1)
162 {
163 m_wndListCtrl.SetItemData(iItem, pUser->dwId);
164 m_wndListCtrl.SetItemText(iItem, 1, pUser->szFullName);
165 m_wndListCtrl.SetItemText(iItem, 2, pUser->szDescription);
166 m_wndListCtrl.SetItemState(iItem, INDEXTOOVERLAYMASK(pUser->wFlags & UF_DISABLED ? 1 : 0), LVIS_OVERLAYMASK);
167 }
168 return iItem;
169 }
170
171
172 //
173 // WM_COMMAND::ID_VIEW_REFRESH message handler
174 //
175
176 void CUserEditor::OnViewRefresh()
177 {
178 NXC_USER *pUserList;
179 DWORD i, dwNumUsers;
180
181 m_wndListCtrl.DeleteAllItems();
182
183 // Fill in list view
184 if (NXCGetUserDB(g_hSession, &pUserList, &dwNumUsers))
185 {
186 for(i = 0; i < dwNumUsers; i++)
187 if (!(pUserList[i].wFlags & UF_DELETED))
188 AddListItem(&pUserList[i]);
189 }
190 }
191
192
193 //
194 // WM_COMMAND::ID_USER_CREATE_USER message handler
195 //
196
197 void CUserEditor::OnUserCreateUser()
198 {
199 CNewUserDlg wndDialog;
200
201 wndDialog.m_strTitle = _T("New User");
202 wndDialog.m_strHeader = _T("Login name");
203 wndDialog.m_bDefineProperties = TRUE;
204 if (wndDialog.DoModal() == IDOK)
205 CreateUserObject((LPCTSTR)wndDialog.m_strName, FALSE, wndDialog.m_bDefineProperties);
206 }
207
208
209 //
210 // WM_COMMAND::ID_USER_CREATE_GROUP message handler
211 //
212
213 void CUserEditor::OnUserCreateGroup()
214 {
215 CNewUserDlg wndDialog;
216
217 wndDialog.m_strTitle = _T("New Group");
218 wndDialog.m_strHeader = _T("Group name");
219 wndDialog.m_bDefineProperties = TRUE;
220 if (wndDialog.DoModal() == IDOK)
221 CreateUserObject((LPCTSTR)wndDialog.m_strName, TRUE, wndDialog.m_bDefineProperties);
222 }
223
224
225 //
226 // Create user or group
227 //
228
229 void CUserEditor::CreateUserObject(const TCHAR *pszName, BOOL bIsGroup, BOOL bShowProp)
230 {
231 DWORD dwResult, dwNewId;
232
233 // Send request to server
234 dwResult = DoRequestArg4(NXCCreateUser, g_hSession, (void *)pszName, (void *)bIsGroup,
235 &dwNewId, bIsGroup ? _T("Creating new group...") : _T("Creating new user..."));
236 if (dwResult == RCC_SUCCESS)
237 {
238 int iItem, iOldItem;
239 LVFINDINFO lvfi;
240
241 // Find related item
242 lvfi.flags = LVFI_PARAM;
243 lvfi.lParam = dwNewId;
244 iItem = m_wndListCtrl.FindItem(&lvfi, -1);
245
246 if (iItem == -1)
247 {
248 NXC_USER user;
249
250 memset(&user, 0, sizeof(NXC_USER));
251 user.dwId = dwNewId;
252 nx_strncpy(user.szName, pszName, MAX_USER_NAME);
253 iItem = AddListItem(&user);
254 }
255
256 // Select newly created item
257 iOldItem = m_wndListCtrl.GetNextItem(-1, LVNI_FOCUSED);
258 if (iOldItem != -1)
259 m_wndListCtrl.SetItemState(iOldItem, 0, LVIS_SELECTED | LVIS_FOCUSED);
260 m_wndListCtrl.EnsureVisible(iItem, FALSE);
261 m_wndListCtrl.SetItemState(iItem, LVIS_SELECTED | LVIS_FOCUSED,
262 LVIS_SELECTED | LVIS_FOCUSED);
263
264 if (bShowProp)
265 PostMessage(WM_COMMAND, ID_USER_PROPERTIES, 0);
266 }
267 else
268 {
269 TCHAR szBuffer[256];
270
271 _stprintf(szBuffer, _T("Error creating %s object: %s"),
272 bIsGroup ? _T("group") : _T("user"), NXCGetErrorText(dwResult));
273 MessageBox(szBuffer, _T("Error"), MB_OK | MB_ICONSTOP);
274 }
275 }
276
277
278 //
279 // WM_USERDB_CHANGE message handler
280 //
281
282 void CUserEditor::OnUserDBChange(int iCode, NXC_USER *pUserInfo)
283 {
284 int iItem;
285 LVFINDINFO lvfi;
286
287 // Find related item
288 lvfi.flags = LVFI_PARAM;
289 lvfi.lParam = pUserInfo->dwId;
290 iItem = m_wndListCtrl.FindItem(&lvfi, -1);
291
292 // Modify list control
293 switch(iCode)
294 {
295 case USER_DB_CREATE:
296 if (iItem == -1)
297 AddListItem(pUserInfo);
298 break;
299 case USER_DB_MODIFY:
300 if (iItem == -1)
301 {
302 AddListItem(pUserInfo);
303 }
304 else
305 {
306 m_wndListCtrl.SetItemText(iItem, 0, pUserInfo->szName);
307 m_wndListCtrl.SetItemText(iItem, 1, pUserInfo->szFullName);
308 m_wndListCtrl.SetItemText(iItem, 2, pUserInfo->szDescription);
309 m_wndListCtrl.SetItemState(iItem, INDEXTOOVERLAYMASK(pUserInfo->wFlags & UF_DISABLED ? 1 : 0), LVIS_OVERLAYMASK);
310 }
311 break;
312 case USER_DB_DELETE:
313 if (iItem != -1)
314 m_wndListCtrl.DeleteItem(iItem);
315 break;
316 }
317 }
318
319
320 //
321 // WM_SETFOCUS message handler
322 //
323
324 void CUserEditor::OnSetFocus(CWnd* pOldWnd)
325 {
326 CMDIChildWnd::OnSetFocus(pOldWnd);
327 m_wndListCtrl.SetFocus();
328 }
329
330
331 //
332 // WM_COMMAND::ID_USER_PROPERTIES message handler
333 //
334
335 void CUserEditor::OnUserProperties()
336 {
337 int iItem;
338
339 iItem = m_wndListCtrl.GetNextItem(-1, LVNI_FOCUSED);
340 if (iItem != -1)
341 {
342 DWORD dwId;
343 NXC_USER *pUser;
344
345 dwId = m_wndListCtrl.GetItemData(iItem);
346 pUser = NXCFindUserById(g_hSession, dwId);
347 if (pUser != NULL)
348 {
349 NXC_USER userInfo;
350 BOOL bModify = FALSE;
351
352 memset(&userInfo, 0, sizeof(NXC_USER));
353 if (dwId & GROUP_FLAG)
354 {
355 CGroupPropDlg dlg;
356
357 dlg.m_pGroup = pUser;
358 dlg.m_strName = pUser->szName;
359 dlg.m_strDescription = pUser->szDescription;
360 dlg.m_bDisabled = (pUser->wFlags & UF_DISABLED) ? TRUE : FALSE;
361 dlg.m_bDropConn = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_SESSIONS) ? TRUE : FALSE;
362 dlg.m_bManageConfig = (pUser->dwSystemRights & SYSTEM_ACCESS_SERVER_CONFIG) ? TRUE : FALSE;
363 dlg.m_bConfigureTraps = (pUser->dwSystemRights & SYSTEM_ACCESS_CONFIGURE_TRAPS) ? TRUE : FALSE;
364 dlg.m_bEditEventDB = (pUser->dwSystemRights & SYSTEM_ACCESS_EDIT_EVENT_DB) ? TRUE : FALSE;
365 dlg.m_bViewEventDB = (pUser->dwSystemRights & SYSTEM_ACCESS_VIEW_EVENT_DB) ? TRUE : FALSE;
366 dlg.m_bManageUsers = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_USERS) ? TRUE : FALSE;
367 dlg.m_bManageActions = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_ACTIONS) ? TRUE : FALSE;
368 dlg.m_bManageEPP = (pUser->dwSystemRights & SYSTEM_ACCESS_EPP) ? TRUE : FALSE;
369 dlg.m_bDeleteAlarms = (pUser->dwSystemRights & SYSTEM_ACCESS_DELETE_ALARMS) ? TRUE : FALSE;
370 dlg.m_bManagePkg = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_PACKAGES) ? TRUE : FALSE;
371 dlg.m_bManageTools = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_TOOLS) ? TRUE : FALSE;
372 dlg.m_bManageScripts = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_SCRIPTS) ? TRUE : FALSE;
373 dlg.m_bViewTrapLog = (pUser->dwSystemRights & SYSTEM_ACCESS_VIEW_TRAP_LOG) ? TRUE : FALSE;
374 dlg.m_bManageAgentCfg = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_AGENT_CFG) ? TRUE : FALSE;
375 dlg.m_bManageModules = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_MODULES) ? TRUE : FALSE;
376 if (dlg.DoModal() == IDOK)
377 {
378 userInfo.dwId = pUser->dwId;
379 nx_strncpy(userInfo.szName, (LPCTSTR)dlg.m_strName, MAX_USER_NAME);
380 nx_strncpy(userInfo.szDescription, (LPCTSTR)dlg.m_strDescription, MAX_USER_DESCR);
381 userInfo.wFlags = dlg.m_bDisabled ? UF_DISABLED : 0;
382 userInfo.dwSystemRights = (dlg.m_bDropConn ? SYSTEM_ACCESS_MANAGE_SESSIONS : 0) |
383 (dlg.m_bManageUsers ? SYSTEM_ACCESS_MANAGE_USERS : 0) |
384 (dlg.m_bManageActions ? SYSTEM_ACCESS_MANAGE_ACTIONS : 0) |
385 (dlg.m_bManageEPP ? SYSTEM_ACCESS_EPP : 0) |
386 (dlg.m_bManageConfig ? SYSTEM_ACCESS_SERVER_CONFIG : 0) |
387 (dlg.m_bConfigureTraps ? SYSTEM_ACCESS_CONFIGURE_TRAPS : 0) |
388 (dlg.m_bEditEventDB ? SYSTEM_ACCESS_EDIT_EVENT_DB : 0) |
389 (dlg.m_bViewEventDB ? SYSTEM_ACCESS_VIEW_EVENT_DB : 0) |
390 (dlg.m_bDeleteAlarms ? SYSTEM_ACCESS_DELETE_ALARMS : 0) |
391 (dlg.m_bManagePkg ? SYSTEM_ACCESS_MANAGE_PACKAGES : 0) |
392 (dlg.m_bManageTools ? SYSTEM_ACCESS_MANAGE_TOOLS : 0) |
393 (dlg.m_bManageScripts ? SYSTEM_ACCESS_MANAGE_SCRIPTS : 0) |
394 (dlg.m_bViewTrapLog ? SYSTEM_ACCESS_VIEW_TRAP_LOG : 0) |
395 (dlg.m_bManageAgentCfg ? SYSTEM_ACCESS_MANAGE_AGENT_CFG : 0) |
396 (dlg.m_bManageModules ? SYSTEM_ACCESS_MANAGE_MODULES : 0);
397 userInfo.dwNumMembers = dlg.m_dwNumMembers;
398 if (userInfo.dwNumMembers > 0)
399 {
400 userInfo.pdwMemberList = (DWORD *)malloc(sizeof(DWORD) * userInfo.dwNumMembers);
401 memcpy(userInfo.pdwMemberList, dlg.m_pdwMembers, sizeof(DWORD) * userInfo.dwNumMembers);
402 }
403 bModify = TRUE;
404 }
405 }
406 else
407 {
408 CUserPropDlg dlg;
409
410 dlg.m_pUser = pUser;
411 dlg.m_strLogin = pUser->szName;
412 dlg.m_strFullName = pUser->szFullName;
413 dlg.m_strDescription = pUser->szDescription;
414 dlg.m_nAuthMethod = pUser->nAuthMethod;
415 dlg.m_nMappingMethod = pUser->nCertMappingMethod;
416 dlg.m_strMappingData = CHECK_NULL_EX(pUser->pszCertMappingData);
417 dlg.m_bAccountDisabled = (pUser->wFlags & UF_DISABLED) ? TRUE : FALSE;
418 dlg.m_bChangePassword = (pUser->wFlags & UF_CHANGE_PASSWORD) ? TRUE : FALSE;
419 dlg.m_bDropConn = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_SESSIONS) ? TRUE : FALSE;
420 dlg.m_bManageConfig = (pUser->dwSystemRights & SYSTEM_ACCESS_SERVER_CONFIG) ? TRUE : FALSE;
421 dlg.m_bConfigureTraps = (pUser->dwSystemRights & SYSTEM_ACCESS_CONFIGURE_TRAPS) ? TRUE : FALSE;
422 dlg.m_bEditEventDB = (pUser->dwSystemRights & SYSTEM_ACCESS_EDIT_EVENT_DB) ? TRUE : FALSE;
423 dlg.m_bViewEventDB = (pUser->dwSystemRights & SYSTEM_ACCESS_VIEW_EVENT_DB) ? TRUE : FALSE;
424 dlg.m_bManageUsers = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_USERS) ? TRUE : FALSE;
425 dlg.m_bManageActions = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_ACTIONS) ? TRUE : FALSE;
426 dlg.m_bManageEPP = (pUser->dwSystemRights & SYSTEM_ACCESS_EPP) ? TRUE : FALSE;
427 dlg.m_bDeleteAlarms = (pUser->dwSystemRights & SYSTEM_ACCESS_DELETE_ALARMS) ? TRUE : FALSE;
428 dlg.m_bManagePkg = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_PACKAGES) ? TRUE : FALSE;
429 dlg.m_bManageTools = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_TOOLS) ? TRUE : FALSE;
430 dlg.m_bManageScripts = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_SCRIPTS) ? TRUE : FALSE;
431 dlg.m_bViewTrapLog = (pUser->dwSystemRights & SYSTEM_ACCESS_VIEW_TRAP_LOG) ? TRUE : FALSE;
432 dlg.m_bManageAgentCfg = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_AGENT_CFG) ? TRUE : FALSE;
433 dlg.m_bManageModules = (pUser->dwSystemRights & SYSTEM_ACCESS_MANAGE_MODULES) ? TRUE : FALSE;
434 if (dlg.DoModal() == IDOK)
435 {
436 userInfo.dwId = pUser->dwId;
437 nx_strncpy(userInfo.szName, (LPCTSTR)dlg.m_strLogin, MAX_USER_NAME);
438 nx_strncpy(userInfo.szFullName, (LPCTSTR)dlg.m_strFullName, MAX_USER_FULLNAME);
439 nx_strncpy(userInfo.szDescription, (LPCTSTR)dlg.m_strDescription, MAX_USER_DESCR);
440 userInfo.nAuthMethod = dlg.m_nAuthMethod;
441 userInfo.nCertMappingMethod = dlg.m_nMappingMethod;
442 userInfo.pszCertMappingData = _tcsdup((LPCTSTR)dlg.m_strMappingData);
443 userInfo.wFlags = (dlg.m_bAccountDisabled ? UF_DISABLED : 0) |
444 (dlg.m_bChangePassword ? UF_CHANGE_PASSWORD : 0);
445 userInfo.dwSystemRights = (dlg.m_bDropConn ? SYSTEM_ACCESS_MANAGE_SESSIONS : 0) |
446 (dlg.m_bManageUsers ? SYSTEM_ACCESS_MANAGE_USERS : 0) |
447 (dlg.m_bManageActions ? SYSTEM_ACCESS_MANAGE_ACTIONS : 0) |
448 (dlg.m_bManageEPP ? SYSTEM_ACCESS_EPP : 0) |
449 (dlg.m_bManageConfig ? SYSTEM_ACCESS_SERVER_CONFIG : 0) |
450 (dlg.m_bConfigureTraps ? SYSTEM_ACCESS_CONFIGURE_TRAPS : 0) |
451 (dlg.m_bEditEventDB ? SYSTEM_ACCESS_EDIT_EVENT_DB : 0) |
452 (dlg.m_bViewEventDB ? SYSTEM_ACCESS_VIEW_EVENT_DB : 0) |
453 (dlg.m_bDeleteAlarms ? SYSTEM_ACCESS_DELETE_ALARMS : 0) |
454 (dlg.m_bManagePkg ? SYSTEM_ACCESS_MANAGE_PACKAGES : 0) |
455 (dlg.m_bManageTools ? SYSTEM_ACCESS_MANAGE_TOOLS : 0) |
456 (dlg.m_bManageScripts ? SYSTEM_ACCESS_MANAGE_SCRIPTS : 0) |
457 (dlg.m_bViewTrapLog ? SYSTEM_ACCESS_VIEW_TRAP_LOG : 0) |
458 (dlg.m_bManageAgentCfg ? SYSTEM_ACCESS_MANAGE_AGENT_CFG : 0) |
459 (dlg.m_bManageModules ? SYSTEM_ACCESS_MANAGE_MODULES : 0);
460 bModify = TRUE;
461 }
462 }
463
464 // Modify user if OK was pressed
465 if (bModify)
466 {
467 DWORD dwResult;
468
469 dwResult = DoRequestArg2(NXCModifyUser, g_hSession, &userInfo, _T("Updating user database..."));
470 if (dwResult != RCC_SUCCESS)
471 theApp.ErrorBox(dwResult, _T("Cannot modify user record: %s"));
472
473 // Cleanup
474 safe_free(userInfo.pdwMemberList);
475 safe_free(userInfo.pszCertMappingData);
476 }
477 }
478 else
479 {
480 MessageBox(_T("Attempt to edit non-existing user record"), _T("Internal Error"), MB_ICONSTOP | MB_OK);
481 PostMessage(WM_COMMAND, ID_VIEW_REFRESH, 0);
482 }
483 }
484 }
485
486
487 //
488 // WM_COMMAND::ID_USER_DELETE message handler
489 //
490
491 void CUserEditor::OnUserDelete()
492 {
493 int iItem;
494
495 iItem = m_wndListCtrl.GetNextItem(-1, LVNI_FOCUSED);
496 if (iItem != -1)
497 {
498 DWORD dwId;
499
500 dwId = m_wndListCtrl.GetItemData(iItem);
501 if (dwId == 0)
502 {
503 MessageBox(_T("System administrator account cannot be deleted"),
504 _T("Warning"), MB_ICONEXCLAMATION | MB_OK);
505 }
506 else if (dwId == GROUP_EVERYONE)
507 {
508 MessageBox(_T("Everyone group cannot be deleted"),
509 _T("Warning"), MB_ICONEXCLAMATION | MB_OK);
510 }
511 else
512 {
513 NXC_USER *pUser;
514
515 pUser = NXCFindUserById(g_hSession, dwId);
516 if (pUser != NULL)
517 {
518 TCHAR szBuffer[256];
519
520 _stprintf(szBuffer, _T("Do you really wish to delete %s %s ?"),
521 dwId & GROUP_FLAG ? _T("group") : _T("user"), pUser->szName);
522 if (MessageBox(szBuffer, _T("Delete account"), MB_ICONQUESTION | MB_YESNO) == IDYES)
523 {
524 DWORD dwResult;
525
526 dwResult = DoRequestArg2(NXCDeleteUser, g_hSession, (void *)dwId, _T("Deleting user..."));
527 if (dwResult != RCC_SUCCESS)
528 theApp.ErrorBox(dwResult, _T("Cannot delete user record: %s"));
529 }
530 }
531 else
532 {
533 MessageBox(_T("Attempt to delete non-existing user record"), _T("Internal Error"), MB_ICONSTOP | MB_OK);
534 PostMessage(WM_COMMAND, ID_VIEW_REFRESH, 0);
535 }
536 }
537 }
538 }
539
540
541 //
542 // WM_CONTEXTMENU message handler
543 //
544
545 void CUserEditor::OnContextMenu(CWnd* pWnd, CPoint point)
546 {
547 CMenu *pMenu;
548
549 pMenu = theApp.GetContextMenu(0);
550 pMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this, NULL);
551 }
552
553
554 //
555 // WM_NOTIFY::LVN_ITEMACTIVATE message handler
556 //
557
558 void CUserEditor::OnListViewItemChange(LPNMLISTVIEW pNMHDR, LRESULT *pResult)
559 {
560 if (pNMHDR->iItem != -1)
561 if (pNMHDR->uChanged & LVIF_STATE)
562 {
563 if (pNMHDR->uNewState & LVIS_FOCUSED)
564 {
565 m_dwCurrentUser = m_wndListCtrl.GetItemData(pNMHDR->iItem);
566 }
567 else
568 {
569 m_dwCurrentUser = INVALID_UID;
570 }
571 }
572 }
573
574
575 //
576 // WM_COMMAND::ID_USER_SETPASSWORD message handler
577 //
578
579 void CUserEditor::OnUserSetpassword()
580 {
581 int iItem;
582
583 iItem = m_wndListCtrl.GetNextItem(-1, LVNI_FOCUSED);
584 if (iItem != -1)
585 {
586 DWORD dwId;
587 NXC_USER *pUser;
588
589 dwId = m_wndListCtrl.GetItemData(iItem);
590
591 pUser = NXCFindUserById(g_hSession, dwId);
592 if (pUser != NULL)
593 {
594 CPasswordChangeDlg dlg(IDD_SET_PASSWORD);
595
596 if (dlg.DoModal() == IDOK)
597 {
598 DWORD dwResult;
599
600 dwResult = DoRequestArg3(NXCSetPassword, g_hSession, (void *)dwId, dlg.m_szPassword, _T("Changing password..."));
601 if (dwResult != RCC_SUCCESS)
602 theApp.ErrorBox(dwResult, _T("Cannot change password: %s"));
603 else
604 MessageBox(_T("Password was successfully changed"), _T("Information"), MB_ICONINFORMATION | MB_OK);
605 }
606 }
607 else
608 {
609 MessageBox(_T("Attempt to modify non-existing user record"), _T("Internal Error"), MB_ICONSTOP | MB_OK);
610 PostMessage(WM_COMMAND, ID_VIEW_REFRESH, 0);
611 }
612 }
613 }
614
615
616 //
617 // UPDATE_COMMAND_UI handlers
618 //
619
620 void CUserEditor::OnUpdateUserProperties(CCmdUI* pCmdUI)
621 {
622 pCmdUI->Enable(m_dwCurrentUser != INVALID_UID);
623 }
624
625 void CUserEditor::OnUpdateUserDelete(CCmdUI* pCmdUI)
626 {
627 pCmdUI->Enable(m_dwCurrentUser != INVALID_UID);
628 }
629
630 void CUserEditor::OnUpdateUserSetpassword(CCmdUI* pCmdUI)
631 {
632 pCmdUI->Enable((m_dwCurrentUser != INVALID_UID) && (!(m_dwCurrentUser & GROUP_FLAG)));
633 }