more-rx-updates-20060504
[openafs.git] / src / WINNT / afssvrcfg / get_pw_dlg.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 /*
11  * INCLUDES ___________________________________________________________________
12  *
13  */
14 #include <winsock2.h>
15 #include <ws2tcpip.h>
16
17 extern "C" {
18 #include <afs/param.h>
19 #include <afs/stds.h>
20 }
21
22 #include "afscfg.h"             // Main header for this application
23 #include "resource.h"
24 #include "get_pw_dlg.h"
25
26
27 /*
28  * DEFINITIONS _________________________________________________________________
29  *
30  */
31 static HWND hDlg = 0;                                           // HWND for this page's dialog
32
33
34 /*
35  * PROTOTYPES _________________________________________________________________
36  *
37  */
38 static void OnInitDialog(HWND hwndDlg);
39 static void CheckEnableButtons();
40 static void SaveDlgInfo();
41 static void ShowPageInfo();
42
43 BOOL CALLBACK GetPwDlgProc(HWND hRHS, UINT msg, WPARAM wp, LPARAM lp);
44
45
46 /*
47  * EXPORTED FUNCTIONS _________________________________________________________
48  *
49  */
50 BOOL GetAfsPrincipalPassword(HWND hParent, TCHAR *&pszServerPW)
51 {       
52         int nResult = ModalDialog(IDD_GET_PW, hParent, (DLGPROC)GetPwDlgProc);
53     if (nResult == IDOK) {
54         pszServerPW = g_CfgData.szServerPW;
55         return TRUE;
56     }
57
58     pszServerPW = 0;
59
60         return FALSE;
61 }
62
63
64 /*
65  * Dialog Proc _________________________________________________________________
66  *
67  */
68 BOOL CALLBACK GetPwDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp)
69 {
70         if (AfsAppLib_HandleHelp(IDD_GET_PW, hwndDlg, msg, wp, lp))
71                 return TRUE;
72
73         switch (msg) {
74                 case WM_INITDIALOG:
75                         OnInitDialog(hwndDlg);
76                         break;
77
78                 case WM_COMMAND:
79                         switch (LOWORD(wp)) {
80                                 case IDC_PW:
81                                         if (HIWORD(wp) == EN_CHANGE)
82                                                 CheckEnableButtons();
83                                         break;
84
85                                 case IDCANCEL:
86                                         EndDialog(hDlg, IDCANCEL);
87                                         break;
88                                         
89
90                                 case IDOK:
91                                         SaveDlgInfo();
92                                         EndDialog(hDlg, IDOK);
93                                         break;
94                         }
95                 break;
96     }
97
98     return FALSE;
99 }
100
101
102 /*
103  * STATIC FUNCTIONS _________________________________________________________________
104  *
105  */
106
107 /*
108  * Event Handler Functions _________________________________________________________________
109  *
110  */
111 static void OnInitDialog(HWND hwndDlg)
112 {
113         hDlg = hwndDlg;
114 }
115
116
117 /*
118  * Utility Functions _________________________________________________________________
119  *
120  */
121 static void CheckEnableButtons()
122 {
123         BOOL bDisable = FALSE;
124
125         TCHAR szDummy[cchRESOURCE];
126
127         bDisable |= lstrlen(GetWndText(hDlg, IDC_PW, szDummy)) == 0;
128
129         SetEnable(hDlg, IDOK, (ENABLE_STATE)!bDisable);
130 }
131
132 static void SaveDlgInfo()
133 {
134         TCHAR szText[cchRESOURCE];
135         
136         lstrncpy(g_CfgData.szServerPW, GetWndText(hDlg, IDC_PW, szText), MAX_SERVER_PW_LEN);
137 }
138
139 static void ShowPageInfo()
140 {
141         SetWndText(hDlg, IDC_PW, g_CfgData.szServerPW);
142 }
143