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