winnt-servermgr-use-existing-creds-option-20020401
[openafs.git] / src / WINNT / afssvrmgr / options.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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  */
9
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 }
14
15 #include "svrmgr.h"
16 #include "options.h"
17 #include "display.h"
18 #include "propcache.h"
19 #include "creds.h"
20 #include "set_general.h"
21 #include "command.h"
22
23
24 /*
25  * PROTOTYPES _________________________________________________________________
26  *
27  */
28
29 BOOL CALLBACK Options_General_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
30 void Options_General_OnInitDialog (HWND hDlg);
31 void Options_General_OnApply (HWND hDlg);
32
33
34 /*
35  * ROUTINES ___________________________________________________________________
36  *
37  */
38
39 void ShowOptionsDialog (void)
40 {
41    TCHAR szCell[ cchNAME ];
42    if (g.lpiCell)
43       g.lpiCell->GetCellName (szCell);
44    else
45       AfsAppLib_GetLocalCell (szCell);
46
47    LPPROPSHEET psh = PropSheet_Create (IDS_OPTIONS_TITLE, FALSE);
48    psh->sh.hwndParent = g.hMain;
49    PropSheet_AddTab (psh, IDS_OPTIONS_GENERAL_TAB, IDD_OPTIONS_GENERAL, (DLGPROC)Options_General_DlgProc, 0, TRUE);
50    PropSheet_ShowModal (psh, PumpMessage);
51 }
52
53
54 BOOL CALLBACK Options_General_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
55 {
56    if (AfsAppLib_HandleHelp (IDD_OPTIONS_GENERAL, hDlg, msg, wp, lp))
57       return TRUE;
58
59    switch (msg)
60       {
61       case WM_INITDIALOG_SHEET:
62          PropCache_Add (pcGENERAL, 0, hDlg);
63          break;
64
65       case WM_DESTROY_SHEET:
66          PropCache_Delete (hDlg);
67          break;
68
69       case WM_INITDIALOG:
70          PropCache_Add (pcGENERAL, NULL, hDlg);
71          Options_General_OnInitDialog (hDlg);
72          break;
73
74       case WM_COMMAND:
75          switch (LOWORD(wp))
76             {
77             case IDAPPLY:
78                Options_General_OnApply (hDlg);
79                break;
80
81             case IDC_OPT_SVR_LONGNAMES:
82             case IDC_OPT_SVR_DBL_PROP:
83             case IDC_OPT_SVR_DBL_DEPENDS:
84             case IDC_OPT_SVR_DBL_OPEN:
85             case IDC_OPT_SVR_OPENMON:
86             case IDC_OPT_SVR_CLOSEUNMON:
87             case IDC_OPT_WARN_BADCREDS:
88                PropSheetChanged (hDlg);
89                break;
90             }
91          break;
92       }
93
94    return FALSE;
95 }
96
97
98 void Options_General_OnInitDialog (HWND hDlg)
99 {
100    CheckDlgButton (hDlg, IDC_OPT_SVR_LONGNAMES,   (gr.fServerLongNames));
101    CheckDlgButton (hDlg, IDC_OPT_SVR_DBL_PROP,    (gr.fDoubleClickOpens == 0));
102    CheckDlgButton (hDlg, IDC_OPT_SVR_DBL_DEPENDS, (gr.fDoubleClickOpens == 2));
103    CheckDlgButton (hDlg, IDC_OPT_SVR_DBL_OPEN,    (gr.fDoubleClickOpens == 1));
104    CheckDlgButton (hDlg, IDC_OPT_SVR_OPENMON,     (gr.fOpenMonitors));
105    CheckDlgButton (hDlg, IDC_OPT_SVR_CLOSEUNMON,  (gr.fCloseUnmonitors));
106    CheckDlgButton (hDlg, IDC_OPT_WARN_BADCREDS,   (gr.fWarnBadCreds));
107 }
108
109
110 void Options_General_OnApply (HWND hDlg)
111 {
112    BOOL fServerLongNamesOld = gr.fServerLongNames;
113
114    gr.fServerLongNames = IsDlgButtonChecked (hDlg, IDC_OPT_SVR_LONGNAMES);
115
116    if (IsDlgButtonChecked (hDlg, IDC_OPT_SVR_DBL_PROP))
117       gr.fDoubleClickOpens = 0;
118    else if (IsDlgButtonChecked (hDlg, IDC_OPT_SVR_DBL_OPEN))
119       gr.fDoubleClickOpens = 1;
120    else // (IsDlgButtonChecked (hDlg, IDC_OPT_SVR_DBL_DEPENDS))
121       gr.fDoubleClickOpens = 2;
122
123    gr.fOpenMonitors = IsDlgButtonChecked (hDlg, IDC_OPT_SVR_OPENMON);
124    gr.fCloseUnmonitors = IsDlgButtonChecked (hDlg, IDC_OPT_SVR_CLOSEUNMON);
125    gr.fWarnBadCreds = IsDlgButtonChecked (hDlg, IDC_OPT_WARN_BADCREDS);
126
127    StoreSettings (REGSTR_SETTINGS_BASE, REGSTR_SETTINGS_PATH, REGVAL_SETTINGS, &gr, sizeof(gr), wVerGLOBALS_RESTORED);
128
129    if (fServerLongNamesOld != gr.fServerLongNames)
130       {
131       AfsClass_RequestLongServerNames (gr.fServerLongNames);
132
133       // repopulate the list of server names.
134       UpdateDisplay_Servers (FALSE, NULL, 0);
135       }
136
137    if (gr.fWarnBadCreds)
138       {
139       if (!CheckCredentials (TRUE)) // user needs new creds?
140          {
141          PostMessage (g.hMain, WM_COMMAND, MAKELONG(M_CREDENTIALS,0), 0);
142          }
143       }
144 }
145