skyrope-mit-merge-hell-20040226
[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 #define PCCHAR(str)     ((char *)(const char *)str)
32
33
34 /////////////////////////////////////////////////////////////////////////////
35 // CKlogDlg dialog
36
37 int kl_Authenticate(const CString& strCellName, const CString& strName, const CString& strPassword, char **reason)
38 {
39         afs_int32 pw_exp;
40
41         return ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION, PCCHAR(strName), "", PCCHAR(strCellName), PCCHAR(strPassword), 0, &pw_exp, 0, reason);
42 }
43
44 CKlogDlg::CKlogDlg(CWnd* pParent /*=NULL*/)
45         : CDialog()
46 {
47         InitModalIndirect (TaLocale_GetDialogResource (CKlogDlg::IDD), pParent);
48
49         //{{AFX_DATA_INIT(CKlogDlg)
50         m_strName = _T("");
51         m_strPassword = _T("");
52         m_strCellName = _T("");
53         //}}AFX_DATA_INIT
54         // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
55 }
56
57 void CKlogDlg::DoDataExchange(CDataExchange* pDX)
58 {
59         CDialog::DoDataExchange(pDX);
60         //{{AFX_DATA_MAP(CKlogDlg)
61         DDX_Control(pDX, IDOK, m_OK);
62         DDX_Text(pDX, IDC_NAME, m_strName);
63         DDX_Text(pDX, IDC_PASSWORD, m_strPassword);
64         DDX_Text(pDX, IDC_CELL_NAME, m_strCellName);
65         //}}AFX_DATA_MAP
66 }
67
68 BEGIN_MESSAGE_MAP(CKlogDlg, CDialog)
69         //{{AFX_MSG_MAP(CKlogDlg)
70         ON_EN_CHANGE(IDC_NAME, OnChangeName)
71         ON_EN_CHANGE(IDC_CELL_NAME, OnChangeCellName)
72         ON_EN_CHANGE(IDC_PASSWORD, OnChangePassword)
73         ON_BN_CLICKED(IDHELP, OnHelp)
74         //}}AFX_MSG_MAP
75 END_MESSAGE_MAP()
76
77 /////////////////////////////////////////////////////////////////////////////
78 // CKlogDlg message handlers
79
80 BOOL CKlogDlg::OnInitDialog()
81 {
82         CDialog::OnInitDialog();
83
84         if (m_strCellName.IsEmpty()) {
85                 char defaultCell[256];
86                 long code = cm_GetRootCellName(defaultCell);
87                 if (code < 0)
88                         AfxMessageBox("Error determining root cell name.");
89                 else
90                         m_strCellName = defaultCell;
91         }
92
93         UpdateData(FALSE);
94
95         return TRUE;  // return TRUE  unless you set the focus to a control
96 }
97
98 void CKlogDlg::OnOK() 
99 {
100         char *reason;
101
102         UpdateData();
103
104         HOURGLASS hg;
105
106         if (kl_Authenticate(m_strCellName, m_strName, m_strPassword, &reason)) {
107                 AfxMessageBox(reason);
108                 return;
109         }
110
111         CDialog::OnOK();
112 }
113
114 void CKlogDlg::OnChangeName() 
115 {
116         CheckEnableOk();
117 }
118
119 void CKlogDlg::OnChangeCellName() 
120 {
121         CheckEnableOk();
122 }
123
124 void CKlogDlg:: CheckEnableOk()
125 {
126         UpdateData();
127         
128         m_OK.EnableWindow(!m_strCellName.IsEmpty() && !m_strName.IsEmpty() && !m_strPassword.IsEmpty());
129 }
130
131 void CKlogDlg::OnChangePassword() 
132 {
133         CheckEnableOk();
134 }
135
136 void CKlogDlg::OnHelp() 
137 {
138         ShowHelp(m_hWnd, GET_TOKENS_HELP_ID);
139 }
140