Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / client_creds / mounttab.cpp
blobba4dd37a8789e0cd9b9469e6f583e20876b5bdea
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
16 #include <afs/fs_utils.h>
19 #include "afscreds.h"
23 * VARIABLES __________________________________________________________________
27 static struct l
29 int iDriveSelectLast;
30 } l;
34 * PROTOTYPES _________________________________________________________________
38 void Mount_OnInitDialog (HWND hDlg);
39 void Mount_OnUpdate (HWND hDlg, BOOL fOnInitDialog = FALSE);
40 void Mount_OnSelect (HWND hDlg);
41 void Mount_OnCheck (HWND hDlg);
42 void Mount_OnRemove (HWND hDlg);
43 void Mount_OnAdd (HWND hDlg);
44 void Mount_OnEdit (HWND hDlg);
46 void Mount_AdjustMapping (HWND hDlg, int iDrive);
47 int Mount_DriveFromItem (HWND hDlg, int iItem);
49 BOOL CALLBACK Mapping_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
50 void Mapping_OnInitDialog (HWND hDlg);
51 void Mapping_OnOK (HWND hDlg);
52 void Mapping_OnEnable (HWND hDlg);
56 * ROUTINES ___________________________________________________________________
60 BOOL CALLBACK Mount_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
62 switch (msg)
64 case WM_INITDIALOG:
65 RECT rTab;
66 GetClientRect (GetParent(hDlg), &rTab);
67 TabCtrl_AdjustRect (GetParent (hDlg), FALSE, &rTab);
68 SetWindowPos (hDlg, NULL, rTab.left, rTab.top, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
70 Mount_OnInitDialog (hDlg);
71 break;
73 case WM_COMMAND:
74 switch (LOWORD(wp))
76 case IDC_ADD:
77 Mount_OnAdd (hDlg);
78 break;
80 case IDC_EDIT:
81 Mount_OnEdit (hDlg);
82 break;
84 case IDC_REMOVE:
85 Mount_OnRemove (hDlg);
86 break;
88 case IDC_LIST:
89 if (HIWORD(wp) == LBN_CLICKED)
90 Mount_OnCheck (hDlg);
91 else if ((HIWORD(wp) == LBN_SELCHANGE) || (HIWORD(wp) == LBN_SELCANCEL))
92 Mount_OnSelect (hDlg);
93 break;
95 case IDHELP:
96 Mount_DlgProc (hDlg, WM_HELP, 0, 0);
97 break;
99 break;
101 case WM_HELP:
102 WinHelp (hDlg, g.szHelpFile, HELP_CONTEXT, IDH_AFSCREDS_TAB_DRIVES);
103 break;
105 return FALSE;
109 void Mount_OnInitDialog (HWND hDlg)
111 int xTabStop = 250;
112 SendDlgItemMessage (hDlg, IDC_LIST, LB_SETTABSTOPS, 1, (LPARAM)&xTabStop);
114 Mount_OnUpdate (hDlg, TRUE);
118 void Mount_OnUpdate (HWND hDlg, BOOL fOnInitDialog)
120 DRIVEMAPLIST List;
121 memset(&List, 0, sizeof(DRIVEMAPLIST));
122 QueryDriveMapList (&List);
124 HWND hList = GetDlgItem (hDlg, IDC_LIST);
125 int iItemSel = LB_GetSelected(hList);
126 int iDataSel = Mount_DriveFromItem (hDlg, iItemSel);
127 iItemSel = -1;
129 if (fOnInitDialog && (iDataSel == -1))
130 iDataSel = l.iDriveSelectLast;
132 LB_StartChange(hList, TRUE);
134 for (int iDrive = 25; iDrive >= 0; --iDrive)
136 if (!List.aDriveMap[ iDrive ].szMapping[0])
137 continue;
139 TCHAR szAfsPath[ MAX_PATH ];
140 AdjustAfsPath (szAfsPath, List.aDriveMap[ iDrive ].szMapping, TRUE, FALSE);
142 LPTSTR psz = FormatString (IDS_DRIVE_MAP, TEXT("%c%s"), List.aDriveMap[ iDrive ].chDrive, szAfsPath);
143 int iItem = LB_AddItem(hList, psz, List.aDriveMap[ iDrive ].fActive);
144 FreeString (psz);
146 int iCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
148 /* This really shouldn't work except that we are adding
149 * the strings in alphabetical order. Otherwise, we could
150 * identify an index value for a string that could then change.
152 if (iDrive == iDataSel)
153 iItemSel = iItem;
156 LB_EndChange(hList, NULL);
158 LB_SetSelected(hList, iItemSel);
160 Mount_OnSelect (hDlg);
161 FreeDriveMapList (&List);
165 void Mount_OnSelect (HWND hDlg)
167 BOOL fServiceRunning = IsServiceRunning();
169 HWND hList = GetDlgItem (hDlg, IDC_LIST);
170 int iItemSel = LB_GetSelected(hList);
171 int iDataSel = Mount_DriveFromItem (hDlg, iItemSel);
173 l.iDriveSelectLast = iDataSel;
175 EnableWindow (GetDlgItem (hDlg, IDC_ADD), fServiceRunning);
176 EnableWindow (GetDlgItem (hDlg, IDC_EDIT), fServiceRunning && (iDataSel != -1));
177 EnableWindow (GetDlgItem (hDlg, IDC_REMOVE), fServiceRunning && (iDataSel != -1));
181 void Mount_OnCheck (HWND hDlg)
183 DRIVEMAPLIST List;
184 QueryDriveMapList (&List);
186 HWND hList = GetDlgItem (hDlg, IDC_LIST);
187 int iItemSel = LB_GetSelected(hList);
188 int iDriveSel = Mount_DriveFromItem (hDlg, iItemSel);
189 BOOL fChecked = SendMessage (hList, LB_GETITEMDATA, iItemSel, 0);
191 if (iDriveSel != -1)
193 DWORD dwStatus;
194 if (fChecked && List.aDriveMap[ iDriveSel ].szMapping[0] && !List.aDriveMap[ iDriveSel ].fActive)
196 if (!ActivateDriveMap (List.aDriveMap[ iDriveSel ].chDrive, List.aDriveMap[ iDriveSel ].szMapping, List.aDriveMap[ iDriveSel ].szSubmount, List.aDriveMap[ iDriveSel ].fPersistent, &dwStatus))
197 Message (MB_OK | MB_ICONHAND, IDS_ERROR_MAP, IDS_ERROR_MAP_DESC, TEXT("%08lX"), dwStatus);
198 Mount_OnUpdate (hDlg);
200 else if (!fChecked && List.aDriveMap[ iDriveSel ].fActive)
202 if (!InactivateDriveMap (List.aDriveMap[ iDriveSel ].chDrive, &dwStatus))
203 Message (MB_OK | MB_ICONHAND, IDS_ERROR_UNMAP, IDS_ERROR_UNMAP_DESC, TEXT("%08lX"), dwStatus);
204 Mount_OnUpdate (hDlg);
206 WriteActiveMap(List.aDriveMap[ iDriveSel ].chDrive, fChecked && List.aDriveMap[ iDriveSel ].fPersistent );
209 FreeDriveMapList (&List);
213 void Mount_OnRemove (HWND hDlg)
215 HWND hList = GetDlgItem (hDlg, IDC_LIST);
216 int iItemSel = LB_GetSelected(hList);
217 int iDriveSel = Mount_DriveFromItem (hDlg, iItemSel);
219 if (iDriveSel != -1)
221 DRIVEMAPLIST List;
222 QueryDriveMapList (&List);
224 if (List.aDriveMap[ iDriveSel ].szMapping[0])
226 if (List.aDriveMap[ iDriveSel ].fActive)
228 DWORD dwStatus;
229 if (!InactivateDriveMap (List.aDriveMap[ iDriveSel ].chDrive, &dwStatus))
231 Message (MB_OK | MB_ICONHAND, IDS_ERROR_UNMAP, IDS_ERROR_UNMAP_DESC, TEXT("%08lX"), dwStatus);
232 return;
235 List.aDriveMap[ iDriveSel ].szMapping[0] = TEXT('\0');
236 WriteDriveMappings (&List);
238 Mount_OnUpdate (hDlg);
240 WriteActiveMap(List.aDriveMap[ iDriveSel ].chDrive, FALSE );
241 FreeDriveMapList (&List);
246 void Mount_OnAdd (HWND hDlg)
248 Mount_AdjustMapping (hDlg, -1);
252 void Mount_OnEdit (HWND hDlg)
254 HWND hList = GetDlgItem (hDlg, IDC_LIST);
255 int iItemSel = LB_GetSelected(hList);
256 int iDriveSel = Mount_DriveFromItem (hDlg, iItemSel);
258 Mount_AdjustMapping (hDlg, iDriveSel);
262 void Mount_AdjustMapping (HWND hDlg, int iDrive)
264 DRIVEMAPLIST List;
265 QueryDriveMapList (&List);
267 DRIVEMAP DriveMapOrig;
268 memset (&DriveMapOrig, 0x00, sizeof(DRIVEMAP));
270 if (iDrive != -1)
272 memcpy (&DriveMapOrig, &List.aDriveMap[ iDrive ], sizeof(DRIVEMAP));
275 DRIVEMAP DriveMap;
276 memcpy (&DriveMap, &DriveMapOrig, sizeof(DRIVEMAP));
278 if (ModalDialogParam (IDD_MAPPING, hDlg, (DLGPROC)Mapping_DlgProc, (LPARAM)&DriveMap) == IDOK)
280 TCHAR szAfsPathOrig[ MAX_PATH ];
281 if (iDrive != -1)
282 AdjustAfsPath (szAfsPathOrig, DriveMapOrig.szMapping, TRUE, TRUE);
284 TCHAR szAfsPathNew[ MAX_PATH ];
285 AdjustAfsPath (szAfsPathNew, DriveMap.szMapping, TRUE, TRUE);
287 if ( (lstrcmpi (szAfsPathOrig, szAfsPathNew)) ||
288 (lstrcmpi (DriveMapOrig.szSubmount, DriveMap.szSubmount)) ||
289 (DriveMapOrig.chDrive != DriveMap.chDrive) ||
290 (DriveMapOrig.fPersistent != DriveMap.fPersistent) )
292 DWORD dwStatus;
294 if ((iDrive != -1) && (DriveMapOrig.fActive))
296 if (!InactivateDriveMap (DriveMapOrig.chDrive, &dwStatus))
298 Message (MB_OK | MB_ICONHAND, IDS_ERROR_UNMAP, IDS_ERROR_UNMAP_DESC, TEXT("%08lX"), dwStatus);
299 Mount_OnUpdate (hDlg);
300 return;
304 if (!ActivateDriveMap (DriveMap.chDrive, szAfsPathNew, DriveMap.szSubmount, DriveMap.fPersistent, &dwStatus))
306 Message (MB_OK | MB_ICONHAND, IDS_ERROR_MAP, IDS_ERROR_MAP_DESC, TEXT("%08lX"), dwStatus);
307 Mount_OnUpdate (hDlg);
308 return;
311 if (DriveMap.szSubmount[0])
313 TCHAR szSubmountNow[ MAX_PATH ];
314 if (GetDriveSubmount (DriveMap.chDrive, szSubmountNow))
316 if (lstrcmpi (DriveMap.szSubmount, szSubmountNow))
318 int idsTitle = (g.fIsWinNT) ? IDS_NEWSUB_TITLE : IDS_NEWSUB_TITLE_95;
319 Message (MB_OK | MB_ICONASTERISK, idsTitle, IDS_NEWSUB_DESC);
324 if (iDrive != -1)
325 memset (&List.aDriveMap[ iDrive ], 0x00, sizeof(DRIVEMAP));
326 memcpy (&List.aDriveMap[ DriveMap.chDrive-chDRIVE_A ], &DriveMap, sizeof(DRIVEMAP));
327 lstrcpy (List.aDriveMap[ DriveMap.chDrive-chDRIVE_A ].szMapping, szAfsPathNew);
328 WriteDriveMappings (&List);
330 Mount_OnUpdate (hDlg);
336 int Mount_DriveFromItem (HWND hDlg, int iItem)
338 TCHAR szItem[ 1024 ] = TEXT("");
339 SendDlgItemMessage (hDlg, IDC_LIST, LB_GETTEXT, iItem, (LPARAM)szItem);
341 LPTSTR pch;
342 if ((pch = (LPTSTR)lstrchr (szItem, TEXT(':'))) != NULL)
344 if (pch > szItem)
346 pch--;
347 if ((*pch >= TEXT('A')) && (*pch <= TEXT('Z')))
348 return (*pch) - TEXT('A');
352 return -1;
356 BOOL CALLBACK Mapping_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
358 switch (msg)
360 case WM_INITDIALOG:
361 SetWindowLongPtr (hDlg, DWLP_USER, lp);
362 Mapping_OnInitDialog (hDlg);
363 break;
365 case WM_COMMAND:
366 switch (LOWORD(wp))
368 case IDOK:
369 Mapping_OnOK (hDlg);
370 break;
372 case IDCANCEL:
373 EndDialog (hDlg, IDCANCEL);
374 break;
376 case IDC_MAP_PATH:
377 Mapping_OnEnable (hDlg);
378 break;
380 case IDHELP:
381 Mapping_DlgProc (hDlg, WM_HELP, 0, 0);
382 break;
384 break;
386 case WM_HELP:
387 WinHelp (hDlg, g.szHelpFile, HELP_CONTEXT, IDH_AFSCREDS_MAPDRIVE);
388 break;
390 return FALSE;
394 void Mapping_OnInitDialog (HWND hDlg)
396 PDRIVEMAP pMap = (PDRIVEMAP)GetWindowLongPtr (hDlg, DWLP_USER);
398 // Fill in the combo box
400 DWORD dwDrives = GetLogicalDrives() | 0x07; // Always pretend A,B,C: are used
402 if (pMap->chDrive != 0)
403 dwDrives &= ~( 1 << (pMap->chDrive - chDRIVE_A) );
405 int iItemSel = -1;
406 HWND hCombo = GetDlgItem (hDlg, IDC_MAP_LETTER);
407 SendMessage (hCombo, WM_SETREDRAW, FALSE, 0);
409 for (int ii = 0; ii < 26; ++ii)
411 if (!(dwDrives & (1<<ii)))
413 TCHAR szText[ cchRESOURCE ];
414 GetString (szText, IDS_MAP_LETTER);
416 LPTSTR pch;
417 if ((pch = (LPTSTR)lstrchr (szText, TEXT('*'))) != NULL)
418 *pch = TEXT('A') + ii;
420 int iItem = SendMessage (hCombo, CB_ADDSTRING, 0, (LPARAM)szText);
421 SendMessage (hCombo, CB_SETITEMDATA, iItem, ii);
422 if (pMap->chDrive && (ii == pMap->chDrive - chDRIVE_A))
423 iItemSel = iItem;
424 else if ((!pMap->chDrive) && (iItemSel == -1))
425 iItemSel = iItem;
429 SendMessage (hCombo, WM_SETREDRAW, TRUE, 0);
430 SendMessage (hCombo, CB_SETCURSEL, iItemSel, 0);
432 TCHAR szMapping[ MAX_PATH ];
433 AdjustAfsPath (szMapping, ((pMap->szMapping[0]) ? pMap->szMapping : cm_slash_mount_root), TRUE, FALSE);
434 CHAR msg[256], msgf[256];
435 if (GetDlgItemText(hDlg,IDC_STATICSUBMOUNT,(LPSTR)msg,sizeof(msg)-1)>0)
437 wsprintf(msgf,msg,cm_back_slash_mount_root,cm_back_slash_mount_root);
438 SetDlgItemText (hDlg, IDC_STATICSUBMOUNT, msgf);
440 SetDlgItemText (hDlg, IDC_MAP_PATH, szMapping);
441 SetDlgItemText (hDlg, IDC_MAP_DESC, pMap->szSubmount);
443 CheckDlgButton (hDlg, IDC_MAP_PERSISTENT, (pMap->chDrive == 0) ? TRUE : (pMap->fPersistent));
445 Mapping_OnEnable (hDlg);
449 void Mapping_OnOK (HWND hDlg)
451 PDRIVEMAP pMap = (PDRIVEMAP)GetWindowLongPtr (hDlg, DWLP_USER);
453 int iItem = SendDlgItemMessage (hDlg, IDC_MAP_LETTER, CB_GETCURSEL, 0, 0);
454 int iDrive = SendDlgItemMessage (hDlg, IDC_MAP_LETTER, CB_GETITEMDATA, iItem, 0);
456 pMap->chDrive = chDRIVE_A + iDrive;
457 GetDlgItemText (hDlg, IDC_MAP_PATH, pMap->szMapping, MAX_PATH);
458 GetDlgItemText (hDlg, IDC_MAP_DESC, pMap->szSubmount, MAX_PATH);
459 pMap->fPersistent = IsDlgButtonChecked (hDlg, IDC_MAP_PERSISTENT);
461 if (pMap->szSubmount[0] && !IsValidSubmountName (pMap->szSubmount))
463 int idsTitle = (g.fIsWinNT) ? IDS_BADSUB_TITLE : IDS_BADSUB_TITLE_95;
464 Message (MB_ICONHAND, idsTitle, IDS_BADSUB_DESC);
465 return;
468 if ( (lstrncmpi (pMap->szMapping, cm_slash_mount_root, lstrlen(cm_slash_mount_root))) && /*TEXT("/afs")*/
469 (lstrncmpi (pMap->szMapping, cm_back_slash_mount_root, lstrlen(cm_back_slash_mount_root))) ) /*TEXT("\\afs")*/
471 Message (MB_ICONHAND, IDS_BADMAP_TITLE, IDS_BADMAP_DESC);
472 return;
475 WriteActiveMap(pMap->chDrive, pMap->fPersistent);
476 EndDialog (hDlg, IDOK);
480 void Mapping_OnEnable (HWND hDlg)
482 TCHAR szPath[ MAX_PATH ];
483 GetDlgItemText (hDlg, IDC_MAP_PATH, szPath, MAX_PATH);
484 EnableWindow (GetDlgItem (hDlg, IDOK), (szPath[0] != TEXT('\0')));