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