windows-unicode-support-20080509
[openafs.git] / src / WINNT / client_exp / unlog_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 "unlog_dlg.h"
20
21 extern "C" {
22 #include <afs/auth.h>
23 #include <cm_config.h>
24 }
25
26 #ifdef _DEBUG
27 #define new DEBUG_NEW
28 #undef THIS_FILE
29 static char THIS_FILE[] = __FILE__;
30 #endif
31
32 /////////////////////////////////////////////////////////////////////////////
33 // CUnlogDlg dialog
34
35 CUnlogDlg::CUnlogDlg(CWnd* pParent /*=NULL*/)
36         : CDialog()
37 {
38         InitModalIndirect (TaLocale_GetDialogResource (CUnlogDlg::IDD), pParent);
39
40         //{{AFX_DATA_INIT(CUnlogDlg)
41         m_strCellName = _T("");
42         //}}AFX_DATA_INIT
43 }
44
45 void CUnlogDlg::DoDataExchange(CDataExchange* pDX)
46 {
47         CDialog::DoDataExchange(pDX);
48         //{{AFX_DATA_MAP(CUnlogDlg)
49         DDX_Control(pDX, IDOK, m_OK);
50         DDX_Text(pDX, IDC_CELL_NAME, m_strCellName);
51         //}}AFX_DATA_MAP
52 }
53
54 BEGIN_MESSAGE_MAP(CUnlogDlg, CDialog)
55         //{{AFX_MSG_MAP(CUnlogDlg)
56         ON_EN_CHANGE(IDC_CELL_NAME, OnChangeCellName)
57         ON_BN_CLICKED(IDHELP, OnHelp)
58         //}}AFX_MSG_MAP
59 END_MESSAGE_MAP()
60
61 /////////////////////////////////////////////////////////////////////////////
62 // CUnlogDlg message handlers
63
64 BOOL CUnlogDlg::OnInitDialog()
65 {
66         CDialog::OnInitDialog();
67
68         if (m_strCellName.IsEmpty()) {
69                 char defaultCell[256];
70                 long code = cm_GetRootCellName(defaultCell);
71                 if (code < 0)
72                     AfxMessageBox(_T("Error determining root cell name."));
73                 else
74                         m_strCellName = defaultCell;
75         }
76         
77         UpdateData(FALSE);
78
79         return TRUE;  // return TRUE  unless you set the focus to a control
80 }
81
82 int kl_Unlog(const CString& strCellName)
83 {
84         struct ktc_principal server;
85         int code;
86
87         if (strCellName.IsEmpty())
88                 code = ktc_ForgetAllTokens();
89         else {
90             CStringA astrCellName(strCellName);
91
92             strcpy(server.cell, astrCellName);
93                 server.instance[0] = '\0';
94                 strcpy(server.name, "afs");
95                 code = ktc_ForgetToken(&server);
96         }
97         
98         if (code == KTC_NOCM)
99             AfxMessageBox(_T("AFS service may not have started"));
100         else if (code) {
101             CString xreason;
102
103             xreason.Format(_T("Unexpected error, code %d"), code);
104                 AfxMessageBox(xreason);
105         }
106         
107         return code;
108 }
109
110 void CUnlogDlg::OnChangeCellName() 
111 {
112         UpdateData();
113         
114         m_OK.EnableWindow(!m_strCellName.IsEmpty());
115 }
116
117 void CUnlogDlg::OnOK() 
118 {
119         if (kl_Unlog(m_strCellName))
120                 return;
121         
122         CDialog::OnOK();
123 }
124
125 void CUnlogDlg::OnHelp() 
126 {
127         ShowHelp(m_hWnd, DISCARD_TOKENS_HELP_ID);
128 }
129