rx: Remove RX_CALL_BUSY
[openafs.git] / src / WINNT / client_exp / klog_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 #include "stdafx.h"
11 #include <winsock2.h>
12 #include <ws2tcpip.h>
13
14 extern "C" {
15 #include <afsconfig.h>
16 #include <afs/param.h>
17 #include <afs/stds.h>
18 #include <roken.h>
19 }
20
21 #include "klog_dlg.h"
22 #include "hourglass.h"
23
24 extern "C" {
25 #include <afs/kautils.h>
26 #include "cm_config.h"
27 }
28
29 #ifdef _DEBUG
30 #define new DEBUG_NEW
31 #undef THIS_FILE
32 static char THIS_FILE[] = __FILE__;
33 #endif
34
35 #ifdef UNICODE
36 CStringA CStringToCStringA(const CString& str)
37 {
38     CStringA astr(str);
39     return astr;
40 }
41 #define PCCHAR(str)     ((char *)(const char *)CStringToCStringA(str))
42 #else
43 #define PCCHAR(str)     ((char *)(const char *)str)
44 #endif
45
46 /////////////////////////////////////////////////////////////////////////////
47 // CKlogDlg dialog
48
49 int kl_Authenticate(const CString& strCellName, const CString& strName,
50                     const CString& strPassword, char **reason)
51 {
52         afs_int32 pw_exp;
53
54         return ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION,
55                                           PCCHAR(strName), "",
56                                           PCCHAR(strCellName),
57                                           PCCHAR(strPassword),
58                                           0,
59                                           &pw_exp, 0, reason);
60 }
61
62 CKlogDlg::CKlogDlg(CWnd* pParent /*=NULL*/)
63         : CDialog()
64 {
65         InitModalIndirect (TaLocale_GetDialogResource (CKlogDlg::IDD), pParent);
66
67         //{{AFX_DATA_INIT(CKlogDlg)
68         m_strName = _T("");
69         m_strPassword = _T("");
70         m_strCellName = _T("");
71         //}}AFX_DATA_INIT
72         // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
73 }
74
75 void CKlogDlg::DoDataExchange(CDataExchange* pDX)
76 {
77         CDialog::DoDataExchange(pDX);
78         //{{AFX_DATA_MAP(CKlogDlg)
79         DDX_Control(pDX, IDOK, m_OK);
80         DDX_Text(pDX, IDC_NAME, m_strName);
81         DDX_Text(pDX, IDC_PASSWORD, m_strPassword);
82         DDX_Text(pDX, IDC_CELL_NAME, m_strCellName);
83         //}}AFX_DATA_MAP
84 }
85
86 BEGIN_MESSAGE_MAP(CKlogDlg, CDialog)
87         //{{AFX_MSG_MAP(CKlogDlg)
88         ON_EN_CHANGE(IDC_NAME, OnChangeName)
89         ON_EN_CHANGE(IDC_CELL_NAME, OnChangeCellName)
90         ON_EN_CHANGE(IDC_PASSWORD, OnChangePassword)
91         ON_BN_CLICKED(IDHELP, OnHelp)
92         //}}AFX_MSG_MAP
93 END_MESSAGE_MAP()
94
95 /////////////////////////////////////////////////////////////////////////////
96 // CKlogDlg message handlers
97
98 BOOL CKlogDlg::OnInitDialog()
99 {
100         CDialog::OnInitDialog();
101
102         if (m_strCellName.IsEmpty()) {
103                 char defaultCell[256];
104                 long code = cm_GetRootCellName(defaultCell);
105                 if (code < 0)
106                     AfxMessageBox(_T("Error determining root cell name."));
107                 else
108                         m_strCellName = defaultCell;
109         }
110
111         UpdateData(FALSE);
112
113         return TRUE;  // return TRUE  unless you set the focus to a control
114 }
115
116 void CKlogDlg::OnOK()
117 {
118         char *reason;
119
120         UpdateData();
121
122         HOURGLASS hg;
123
124         if (kl_Authenticate(m_strCellName, m_strName, m_strPassword, &reason)) {
125             CString strReason(reason);
126             AfxMessageBox(strReason);
127                 return;
128         }
129
130         CDialog::OnOK();
131 }
132
133 void CKlogDlg::OnChangeName()
134 {
135         CheckEnableOk();
136 }
137
138 void CKlogDlg::OnChangeCellName()
139 {
140         CheckEnableOk();
141 }
142
143 void CKlogDlg:: CheckEnableOk()
144 {
145         UpdateData();
146
147         m_OK.EnableWindow(!m_strCellName.IsEmpty() && !m_strName.IsEmpty() && !m_strPassword.IsEmpty());
148 }
149
150 void CKlogDlg::OnChangePassword()
151 {
152         CheckEnableOk();
153 }
154
155 void CKlogDlg::OnHelp()
156 {
157         ShowHelp(m_hWnd, GET_TOKENS_HELP_ID);
158 }
159