1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
// **************************************************************************************
// File: Krb4RealmHostMaintenance.cpp
// By: Arthur David Leather
// Created: 12/02/98
// Copyright @1998 Massachusetts Institute of Technology - All rights reserved.
// Description: CPP file for Krb4RealmHostMaintenance.h. Contains variables and functions
// for Kerberos Four Properties
//
// History:
//
// MM/DD/YY Inits Description of Change
// 12/02/98 ADL Original
// **************************************************************************************
#include "stdafx.h"
#include "leash.h"
#include "KrbProperties.h"
#include "Krb4Properties.h"
#include "Krb4AddToRealmHostList.h"
#include "Krb4RealmHostMaintenance.h"
#include "Krb4EditRealmHostList.h"
#include "lglobals.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CKrb4RealmHostMaintenance dialog
IMPLEMENT_DYNCREATE(CKrb4RealmHostMaintenance, CPropertyPage)
CKrb4RealmHostMaintenance::CKrb4RealmHostMaintenance() : CPropertyPage(CKrb4RealmHostMaintenance::IDD)
{
m_defectiveLines = 0;
m_initDnsKdcLookup = m_newDnsKdcLookup = 0;
}
CKrb4RealmHostMaintenance::~CKrb4RealmHostMaintenance()
{
}
void CKrb4RealmHostMaintenance::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CKrb4RealmHostMaintenance)
DDX_Control(pDX, IDC_LIST_KRB4_REALM_HOST, m_RealmHostList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CKrb4RealmHostMaintenance, CPropertyPage)
//{{AFX_MSG_MAP(CKrb4RealmHostMaintenance)
ON_BN_CLICKED(IDC_BUTTON_KRB4_REALM_HOST_ADD, OnButtonRealmHostAdd)
ON_BN_CLICKED(IDC_BUTTON_KRB4_REALM_HOST_EDIT, OnButtonRealmHostEdit)
ON_BN_CLICKED(ID_BUTTON_KRB4_REALM_HOST_REMOVE, OnButtonRealmHostRemove)
ON_LBN_SELCHANGE(IDC_LIST_KRB4_REALM_HOST, OnSelchangeListRemoveHost)
ON_LBN_DBLCLK(IDC_LIST_KRB4_REALM_HOST, OnDblclkListRemoveHost)
ON_BN_CLICKED(IDC_BUTTON_REALMHOST_MAINT_HELP2, OnButtonRealmhostMaintHelp2)
ON_BN_CLICKED(IDC_KRB4_DNS_KDC, OnCheckDnsKdcLookup)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKrb4RealmHostMaintenance message handlers
BOOL CKrb4RealmHostMaintenance::OnInitDialog()
{
CPropertyPage::OnInitDialog();
CStdioFile krbCon;
if (!krbCon.Open(CKrbProperties::m_krbPath, CFile::modeReadWrite))
{ // can't find file, so lets set some defaults
m_RealmHostList.AddString(KRB_REALM " " KRB_MASTER);
}
else
{
memset(lineBuf, '\0', sizeof(lineBuf));
krbCon.ReadString(lineBuf, sizeof(lineBuf));
while (TRUE)
{
if (!krbCon.ReadString(lineBuf, sizeof(lineBuf)))
break;
*(lineBuf + strlen(lineBuf) - 1) = 0;
if (!strchr(lineBuf, ' ') && !strchr(lineBuf, '\t'))
{ // found a defective line
m_defectiveLines++;
}
if ( !strncmp(".KERBEROS.OPTION.",lineBuf,17) ) {
char * p = &lineBuf[17];
while (isspace(*p))
p++;
if (!strcmp("dns",p))
m_initDnsKdcLookup = m_newDnsKdcLookup = 1;
} else {
if (LB_ERR == m_RealmHostList.AddString(lineBuf))
{
LeashErrorBox("OnInitDialog::Can't read Configuration File",
CKrbProperties::m_krbPath);
krbCon.Close();
return FALSE;
}
}
}
krbCon.Close();
}
m_RealmHostList.SetCurSel(0);
if (!m_RealmHostList.GetCount())
{
GetDlgItem(ID_BUTTON_KRB4_REALM_HOST_REMOVE)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_KRB4_REALM_HOST_EDIT)->EnableWindow(FALSE);
}
return TRUE;
}
BOOL CKrb4RealmHostMaintenance::OnApply()
{
CStdioFile krbCon;
if (!krbCon.Open(CKrbProperties::m_krbPath, CFile::modeCreate |
CFile::modeNoTruncate |
CFile::modeReadWrite))
{
LeashErrorBox("OnApply::Can't open Configuration File",
CKrbProperties::m_krbPath);
return TRUE;
}
memset(lineBuf, '\0', sizeof(lineBuf));
if (!krbCon.ReadString(lineBuf, sizeof(lineBuf)))
{
//-----ADL----///strcpy(lineBuf, CKrb4ConfigOptions::m_newDefaultRealm);
strcat(lineBuf, "\n");
}
krbCon.SetLength(0);
krbCon.WriteString(lineBuf);
for (INT maxItems = m_RealmHostList.GetCount(), item = 0; item < maxItems; item++)
{
memset(lineBuf, '\0', sizeof(lineBuf));
if (!m_RealmHostList.GetText(item, lineBuf))
break;
krbCon.WriteString(lineBuf);
krbCon.WriteString("\n");
}
if ( m_newDnsKdcLookup )
krbCon.WriteString(".KERBEROS.OPTION. dns\n");
krbCon.Close();
return TRUE;
}
void CKrb4RealmHostMaintenance::OnOK()
{
CPropertyPage::OnOK();
}
void CKrb4RealmHostMaintenance::OnCancel()
{
CPropertyPage::OnCancel();
}
void CKrb4RealmHostMaintenance::OnCheckDnsKdcLookup()
{
m_newDnsKdcLookup = (BOOL)IsDlgButtonChecked(IDC_KRB4_DNS_KDC);
SetModified(TRUE);
}
void CKrb4RealmHostMaintenance::ResetDefaultRealmComboBox()
{ // krb4 is loaded without krb5
CHAR lineBuf[REALM_SZ + MAX_HSTNM + 20];
int maxItems = m_RealmHostList.GetCount();
CKrbConfigOptions::m_krbRealmEditbox.ResetContent();
for (int xItems = 0; xItems < maxItems; xItems++)
{
m_RealmHostList.GetText(xItems, lineBuf);
LPSTR space = strchr(lineBuf, ' ');
if (space)
*space = 0;
else
ASSERT(0);
if (CB_ERR == CKrbConfigOptions::m_krbRealmEditbox.FindStringExact(-1, lineBuf))
{ // no dups
if (LB_ERR == CKrbConfigOptions::m_krbRealmEditbox.AddString(lineBuf))
{
MessageBox("OnInitDialog::Can't add to Kerberos Realm Combobox",
"Leash", MB_OK);
return;
}
}
}
CHAR krbhst[MAX_HSTNM + 1];
CHAR krbrlm[REALM_SZ + 1];
strcpy(krbrlm, CKrbConfigOptions::m_newDefaultRealm);
memset(krbhst, '\0', sizeof(krbhst));
// Check for Host
// don't use KRB4 - krb_get_krbhst - would have to re-logon, on file location
// change, to use this function
extern int krb_get_krbhst(char* h, char* r, int n);
if (KFAILURE == krb_get_krbhst(krbhst, krbrlm, 1))
{
MessageBox("We can't find the Host Server for your Default Realm!!!",
"Leash", MB_OK);
return;
}
CKrbConfigOptions::m_hostServer = krbhst;
}
void CKrb4RealmHostMaintenance::OnButtonRealmHostAdd()
{
CKrb4AddToRealmHostList addToRealmHostList;
if (IDOK == addToRealmHostList.DoModal())
{
if (addToRealmHostList.GetNewRealm().IsEmpty())
ASSERT(0);
CString newLine;
newLine = addToRealmHostList.GetNewRealm() + " " + addToRealmHostList.GetNewHost();
if (addToRealmHostList.GetNewAdmin())
newLine += " admin server";
// We don't want duplicate items in Listbox
if (LB_ERR != m_RealmHostList.FindStringExact(-1, newLine))
{ // found duplicate item in Listbox
LeashErrorBox("OnButtonRealmHostAdd::Found a Duplicate Item!\nCan't add to List",
newLine);
return;
}
m_RealmHostList.InsertString(0, newLine);
m_RealmHostList.SetCurSel(0);
SetModified(TRUE);
ResetDefaultRealmComboBox();
if (1 == m_RealmHostList.GetCount())
{
GetDlgItem(ID_BUTTON_KRB4_REALM_HOST_REMOVE)->EnableWindow();
GetDlgItem(IDC_BUTTON_KRB4_REALM_HOST_EDIT)->EnableWindow();
}
}
}
void CKrb4RealmHostMaintenance::OnButtonRealmHostEdit()
{
INT selItemIndex = m_RealmHostList.GetCurSel();
LPSTR pSelItem = new char[m_RealmHostList.GetTextLen(selItemIndex) + 1];
if (!pSelItem)
ASSERT(0);
CString selItem;
m_RealmHostList.GetText(selItemIndex, selItem);
strcpy(pSelItem, selItem);
CKrb4EditRealmHostList editRealmHostList(pSelItem);
delete [] pSelItem;
if (IDOK == editRealmHostList.DoModal())
{
CString editedItem = editRealmHostList.GetEditedItem();
if (0 != selItem.CompareNoCase(editedItem) &&
LB_ERR != m_RealmHostList.FindStringExact(-1, editedItem))
{
LeashErrorBox("OnButtonRealmHostEdit::Found a Duplicate!\nCan't add to List",
editedItem);
return;
}
m_RealmHostList.DeleteString(selItemIndex);
m_RealmHostList.InsertString(selItemIndex, editRealmHostList.GetEditedItem());
m_RealmHostList.SetCurSel(selItemIndex);
SetModified(TRUE);
ResetDefaultRealmComboBox();
}
}
void CKrb4RealmHostMaintenance::OnButtonRealmHostRemove()
{
if (IDYES != AfxMessageBox("You are about to remove an item from the list!\n\nContinue?",
MB_YESNO))
return;
INT curSel = m_RealmHostList.GetCurSel();
m_RealmHostList.DeleteString(curSel); // Single Sel Listbox
if (-1 == m_RealmHostList.SetCurSel(curSel))
m_RealmHostList.SetCurSel(curSel - 1);
SetModified(TRUE);
ResetDefaultRealmComboBox();
if (!m_RealmHostList.GetCount())
{
GetDlgItem(ID_BUTTON_KRB4_REALM_HOST_REMOVE)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_KRB4_REALM_HOST_EDIT)->EnableWindow(FALSE);
}
/* For Mult. Sel Listbox
const LONG MAX_SEL_BUF = m_RealmHostList.GetSelCount();
LPINT selectBuf = new INT[MAX_SEL_BUF];
for (INT maxSelected = m_RealmHostList.GetSelItems(MAX_SEL_BUF, selectBuf), del=0, sel=0;
sel < maxSelected; sel++)
{
if (LB_ERR == m_RealmHostList.DeleteString(*(selectBuf + sel) - del))
MessageBox("Help", "Error", MB_OK);
else
del++;
}
delete selectBuf;
*/
}
void CKrb4RealmHostMaintenance::OnSelchangeListRemoveHost()
{
//SetModified(TRUE);
}
void CKrb4RealmHostMaintenance::OnDblclkListRemoveHost()
{
OnButtonRealmHostEdit();
}
BOOL CKrb4RealmHostMaintenance::PreTranslateMessage(MSG* pMsg)
{
if (m_defectiveLines)
{
if (m_defectiveLines == 1)
LeashErrorBox("Found a defective entry in file",
CKrbProperties::m_krbPath, "Warning");
else if (m_defectiveLines > 1)
LeashErrorBox("Found more then one defective entry in file",
CKrbProperties::m_krbPath, "Warning");
}
m_defectiveLines = 0;
return CPropertyPage::PreTranslateMessage(pMsg);
}
void CKrb4RealmHostMaintenance::OnButtonRealmhostMaintHelp2()
{
MessageBox("No Help Available!", "Note", MB_OK);
}
|