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