923d8469737f1a55b16cc18487c534e6790b312e
[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("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         static char xreason[100];
87
88         if (strCellName.IsEmpty())
89                 code = ktc_ForgetAllTokens();
90         else {
91                 strcpy(server.cell, strCellName);
92                 server.instance[0] = '\0';
93                 strcpy(server.name, "afs");
94                 code = ktc_ForgetToken(&server);
95         }
96         
97         if (code == KTC_NOCM)
98                 AfxMessageBox("AFS service may not have started");
99         else if (code) {
100                 sprintf(xreason, "Unexpected error, code %d", code);
101                 AfxMessageBox(xreason);
102         }
103         
104         return code;
105 }
106
107 void CUnlogDlg::OnChangeCellName() 
108 {
109         UpdateData();
110         
111         m_OK.EnableWindow(!m_strCellName.IsEmpty());
112 }
113
114 void CUnlogDlg::OnOK() 
115 {
116         if (kl_Unlog(m_strCellName))
117                 return;
118         
119         CDialog::OnOK();
120 }
121
122 void CUnlogDlg::OnHelp() 
123 {
124         ShowHelp(m_hWnd, DISCARD_TOKENS_HELP_ID);
125 }
126