1 //****************************************************************************
2 // File: Krb5Properties.cpp
3 // By: Arthur David Leather
5 // Copyright: 1998 Massachusetts Institute of Technology - All rights
7 // Description: CPP file for Krb5Properties.h. Contains variables and functions
8 // for Kerberos Five Properties
12 // MM/DD/YY Inits Description of Change
13 // 12/02/98 ADL Original
14 //*****************************************************************************
18 #include "LeashFileDialog.h"
19 #include "Krb5Properties.h"
22 #include "LeashView.h"
27 static char THIS_FILE[] = __FILE__;
31 /////////////////////////////////////////////////////////////////////////////
32 // CKrb5ConfigFileLocation dialog
34 IMPLEMENT_DYNCREATE(CKrb5ConfigFileLocation, CPropertyPage)
36 CKrb5ConfigFileLocation::CKrb5ConfigFileLocation()
37 : CPropertyPage(CKrb5ConfigFileLocation::IDD)
39 m_initConfigFile = _T("");
40 m_initTicketFile = _T("");
41 m_newConfigFile = _T("");
42 m_newTicketFile = _T("");
43 m_startupPage1 = TRUE;
45 //{{AFX_DATA_INIT(CKrb5ConfigFileLocation)
49 void CKrb5ConfigFileLocation::DoDataExchange(CDataExchange* pDX)
51 CDialog::DoDataExchange(pDX);
52 //{{AFX_DATA_MAP(CKrb5ConfigFileLocation)
53 DDX_Control(pDX, IDC_EDIT_KRB5_TXT_FILE, m_ticketEditBox);
57 BEGIN_MESSAGE_MAP(CKrb5ConfigFileLocation, CDialog)
58 //{{AFX_MSG_MAP(CKrb5ConfigFileLocation)
59 ON_BN_CLICKED(IDC_BUTTON_KRB5INI_BROWSE, OnButtonKrb5iniBrowse)
60 ON_BN_CLICKED(IDC_BUTTON_KRB5_TICKETFILE_BROWSE, OnButtonKrb5TicketfileBrowse)
61 ON_EN_CHANGE(IDC_EDIT_KRB5_TXT_FILE, OnChangeEditKrb5TxtFile)
62 ON_EN_CHANGE(IDC_EDIT_KRB5INI_LOCATION, OnChangeEditKrb5iniLocation)
68 BOOL CKrb5ConfigFileLocation::OnApply()
70 BOOL tooManySlashes = FALSE;
71 BOOL foundError = FALSE;
73 if( getenv("RENEW_TILL") != NULL)
75 MessageBox("The ticket renewable time is being controlled by the environment"
76 "variable RENEW_TILL instead of the registry. Leash cannot modify"
77 "the environment. Use the System control panel instead.",
82 if( getenv("RENEWABLE") != NULL)
84 MessageBox("Ticket renewability is being controlled by the environment"
85 "variable RENEWABLE instead of the registry. Leash cannot modify"
86 "the environment. Use the System control panel instead.",
91 if( getenv("FORWARDABLE") != NULL)
93 MessageBox("Ticket forwarding is being controlled by the environment"
94 "variable FORWARDABLE instead of the registry. Leash cannot modify"
95 "the environment. Use the System control panel instead.",
100 if( getenv("PROXIABLE") != NULL)
102 MessageBox("Ticket proxying is being controlled by the environment"
103 "variable PROXIABLE instead of the registry. Leash cannot modify"
104 "the environment. Use the System control panel instead.",
109 if( getenv("NOADDRESSES") != NULL)
111 MessageBox("Addressless tickets are being controlled by the environment"
112 "variable NOADDRESSES instead of the registry. Leash cannot modify"
113 "the environment. Use the System control panel instead.",
120 if (!CLeashApp::m_krbv5_profile ||
121 0 != m_newConfigFile.CompareNoCase(m_initConfigFile))
122 { // Different path for Krb5.ini
124 if (IsDlgButtonChecked(IDC_CHECK_CONFIRM_KRB5_EXISTS))
126 // Check for extra slashes at end of path
127 LPSTR pSlash = strrchr(m_newConfigFile.GetBuffer(0), '\\');
128 if (pSlash && *(pSlash - 1) == '\\')
129 { // don't commit changes
130 tooManySlashes = TRUE;
132 else if (pSlash && *(pSlash + 1) == '\0')
133 { // commit changes, but take out slash at the end of path
137 m_newConfigFile.ReleaseBuffer(-1);
139 // Check for invalid path
140 Directory directory(m_newConfigFile);
141 if (tooManySlashes || !directory.IsValidFile())
142 { // don't commit changes
146 LeashErrorBox("OnApply::Too Many Slashes At End of "
147 "Selected Directory",
150 LeashErrorBox("OnApply::Selected file doesn't exist",
153 SetDlgItemText(IDC_EDIT_KRB5INI_LOCATION, m_initConfigFile);
157 // more error checking
158 CHAR confname[MAX_PATH];
160 const char *filenames[2];
161 filenames[0] = m_newConfigFile;
164 const char* rootSection[] = {"realms", NULL};
165 const char** rootsec = rootSection;
166 char **sections = NULL;
168 long retval = pprofile_init(filenames, &CLeashApp::m_krbv5_profile);
170 retval = pprofile_get_subsection_names(CLeashApp::m_krbv5_profile,
173 if (retval || !*sections )
176 MessageBox("Your file selection is either corrupt or not a Kerberos Five Config. file",
179 pprofile_free_list(sections);
181 // Restore old 'valid' config. file
182 if (CLeashApp::GetProfileFile(confname, sizeof(confname)))
185 MessageBox("Can't locate Kerberos Five Config. file!",
190 filenames[0] = confname;
193 retval = pprofile_init(filenames, &CLeashApp::m_krbv5_profile);
195 retval = pprofile_get_subsection_names(CLeashApp::m_krbv5_profile,
197 if (retval || !*sections)
200 MessageBox("OnApply::There is a problem with your "
201 "Kerberos Five Config. file!\n"
202 "Contact your Administrator.",
206 pprofile_free_list(sections);
207 SetDlgItemText(IDC_EDIT_KRB5INI_LOCATION, m_initConfigFile);
209 pprofile_release(CLeashApp::m_krbv5_profile);
213 pprofile_free_list(sections);
220 if (SetRegistryVariable("config", m_newConfigFile,
221 "Software\\MIT\\Kerberos5"))
223 MessageBox("Failed to set \"Krb.conf\"!", "Error", MB_OK);
226 m_initConfigFile = m_newConfigFile;
231 // Credential cache (ticket) file
233 if (0 != m_initTicketFile.CompareNoCase(m_newTicketFile))
235 if (getenv("KRB5_ENV_CCNAME"))
237 // Just in case they set (somehow) KRB5_ENV_CCNAME while this box is up
238 MessageBox("OnApply::Ticket file is set in your System's"
239 "Environment!\nYou must first remove it.",
246 if (SetRegistryVariable("ccname", m_newTicketFile,
247 "Software\\MIT\\Kerberos5"))
249 MessageBox("Failed to set \"ccname\"!", "Error", MB_OK);
251 if ( CLeashApp::m_krbv5_context )
252 pkrb5_cc_set_default_name(CLeashApp::m_krbv5_context,m_newTicketFile);
254 m_initTicketFile = m_newTicketFile;
261 BOOL CKrb5ConfigFileLocation::OnInitDialog()
263 CDialog::OnInitDialog();
265 CHAR confname[MAX_PATH];
266 CHAR ticketName[MAX_PATH];
268 CheckDlgButton(IDC_CHECK_CONFIRM_KRB5_EXISTS, TRUE);
270 // Config. file (Krb5.ini)
271 if (CLeashApp::GetProfileFile(confname, sizeof(confname)))
273 MessageBox("Can't locate Kerberos Five config. file!", "Error", MB_OK);
277 m_initConfigFile = m_newConfigFile = confname;
278 SetDlgItemText(IDC_EDIT_KRB5INI_LOCATION, m_initConfigFile);
280 if (pLeash_get_lock_file_locations() || getenv("KRB5_CONFIG"))
282 GetDlgItem(IDC_EDIT_KRB5INI_LOCATION)->EnableWindow(FALSE);
283 GetDlgItem(IDC_BUTTON_KRB5INI_BROWSE)->EnableWindow(FALSE);
284 GetDlgItem(IDC_CHECK_CONFIRM_KRB5_EXISTS)->EnableWindow(FALSE);
286 else if ( !(getenv("KRB5_CONFIG")) )
288 GetDlgItem(IDC_STATIC_INIFILES)->ShowWindow(FALSE);
292 // Set TICKET.KRB file Editbox
294 if (CLeashApp::m_krbv5_context)
296 const char *pticketName = pkrb5_cc_default_name(CLeashApp::m_krbv5_context);
299 strcpy(ticketName, pticketName);
304 MessageBox("OnInitDialog::Can't locate Kerberos Five ticket file!",
310 m_initTicketFile = m_newTicketFile = ticketName;
311 SetDlgItemText(IDC_EDIT_KRB5_TXT_FILE, m_initTicketFile);
314 if (getenv("KRB5CCNAME"))
315 GetDlgItem(IDC_EDIT_KRB5_TXT_FILE)->EnableWindow(FALSE);
317 GetDlgItem(IDC_STATIC_TICKETFILE)->ShowWindow(FALSE);
322 void CKrb5ConfigFileLocation::OnButtonKrb5iniBrowse()
324 CLeashFileDialog dlgFile(TRUE, NULL, "*.*",
325 "Kerbereos Five Config. File (.ini)");
326 dlgFile.m_ofn.lpstrTitle = "Select the Kerberos Five Config. File";
329 if (IDOK == dlgFile.DoModal())
331 m_newConfigFile = dlgFile.GetPathName();
332 SetDlgItemText(IDC_EDIT_KRB5INI_LOCATION, m_newConfigFile);
340 void CKrb5ConfigFileLocation::OnButtonKrb5TicketfileBrowse()
342 CString ticket_path = "*.*";
343 CLeashFileDialog dlgFile(TRUE, NULL, ticket_path,
344 "Kerbereos Five Ticket File (Krb5cc)");
345 dlgFile.m_ofn.lpstrTitle = "Select Credential Cache (Ticket) File";
347 if (IDOK == dlgFile.DoModal())
349 m_newTicketFile = dlgFile.GetPathName();
350 SetDlgItemText(IDC_EDIT_KRB5_TXT_FILE, m_newTicketFile);
354 void CKrb5ConfigFileLocation::OnChangeEditKrb5iniLocation()
358 GetDlgItemText(IDC_EDIT_KRB5INI_LOCATION, m_newConfigFile);
363 void CKrb5ConfigFileLocation::OnChangeEditKrb5TxtFile()
367 GetDlgItemText(IDC_EDIT_KRB5_TXT_FILE, m_newTicketFile);
372 void CKrb5ConfigFileLocation::OnShowWindow(BOOL bShow, UINT nStatus)
374 CDialog::OnShowWindow(bShow, nStatus);
375 m_startupPage1 = FALSE;
379 /////////////////////////////////////////////////////////////////////////////
380 // CKrb5ConfigOptions dialog
382 IMPLEMENT_DYNCREATE(CKrb5ConfigOptions, CPropertyPage)
384 CKrb5ConfigOptions::CKrb5ConfigOptions()
385 : CPropertyPage(CKrb5ConfigOptions::IDD)
387 m_initForwardable = 0;
388 m_newForwardable = 0;
398 #endif /* SET_PUBLIC_IP */
400 //{{AFX_DATA_INIT(CKrb5ConfigOptions)
401 // NOTE: the ClassWizard will add member initialization here
406 void CKrb5ConfigOptions::DoDataExchange(CDataExchange* pDX)
408 CDialog::DoDataExchange(pDX);
410 //{{AFX_DATA_MAP(CKrb5ConfigOptions)
411 // NOTE: the ClassWizard will add DDX and DDV calls here
416 BEGIN_MESSAGE_MAP(CKrb5ConfigOptions, CDialog)
417 //{{AFX_MSG_MAP(CKrb5ConfigOptions)
418 ON_BN_CLICKED(IDC_CHECK_FORWARDABLE, OnCheckForwardable)
419 ON_BN_CLICKED(IDC_CHECK_PROXIABLE, OnCheckProxiable)
420 ON_BN_CLICKED(IDC_CHECK_RENEWABLE, OnCheckRenewable)
421 ON_BN_CLICKED(IDC_CHECK_NO_ADDRESS, OnCheckNoAddress)
427 BOOL CKrb5ConfigOptions::OnApply()
430 SendDlgItemMessage( IDC_IPADDRESS_PUBLIC,
433 (LPARAM)(LPDWORD)&m_newIPAddress
435 #endif /* SET_PUBLIC_IP */
437 if ((m_initForwardable == m_newForwardable) &&
438 (m_initProxiable == m_newProxiable) &&
439 (m_initRenewable == m_newRenewable) &&
440 (m_initNoAddress == m_newNoAddress)
442 && (m_initIPAddress == m_newIPAddress)
443 #endif /* SET_PUBLIC_IP */
447 CWinApp *pApp = NULL;
451 MessageBox("There is a problem finding Leash application "
457 if ( m_newNoAddress == FALSE ) {
458 CHAR confname[MAX_PATH];
459 if (!CLeashApp::GetProfileFile(confname, sizeof(confname)))
461 const char *filenames[2];
463 long retval, noaddresses = 1;
464 filenames[0] = confname;
466 retval = pprofile_init(filenames, &CLeashApp::m_krbv5_profile);
468 retval = pprofile_get_string(CLeashApp::m_krbv5_profile, "libdefaults","noaddresses", 0, "true", &value);
470 noaddresses = config_boolean_to_int(value);
471 pprofile_release_string(value);
473 pprofile_release(CLeashApp::m_krbv5_profile);
478 MessageBox("The No Addresses setting cannot be disabled unless the setting\n"
479 " noaddresses=false\n"
480 "is added to the [libdefaults] section of the KRB5.INI file.",
488 pLeash_set_default_forwardable(m_newForwardable);
489 pLeash_set_default_proxiable(m_newProxiable);
490 pLeash_set_default_renewable(m_newRenewable);
491 pLeash_set_default_noaddresses(m_newNoAddress);
493 pLeash_set_default_publicip(m_newIPAddress);
494 #endif /* SET_PUBLIC_IP */
496 CLeashView::m_forwardableTicket = m_initForwardable = m_newForwardable;
497 CLeashView::m_proxiableTicket = m_initProxiable = m_newProxiable;
498 CLeashView::m_renewableTicket = m_initRenewable = m_newRenewable;
499 CLeashView::m_noaddressTicket = m_initNoAddress = m_newNoAddress;
501 CLeashView::m_publicIPAddress = m_initIPAddress = m_newIPAddress;
502 #endif /* SET_PUBLIC_IP */
506 BOOL CKrb5ConfigOptions::OnInitDialog()
508 CDialog::OnInitDialog();
510 CWinApp *pApp = NULL;
514 MessageBox("There is a problem finding Leash application "
520 m_initForwardable = pLeash_get_default_forwardable();
521 m_initProxiable = pLeash_get_default_proxiable();
522 m_initRenewable = pLeash_get_default_renewable();
523 m_initNoAddress = pLeash_get_default_noaddresses();
524 m_initIPAddress = pLeash_get_default_publicip();
527 CheckDlgButton(IDC_CHECK_FORWARDABLE, m_initForwardable);
528 m_newForwardable = m_initForwardable;
530 CheckDlgButton(IDC_CHECK_PROXIABLE, m_initProxiable);
531 m_newProxiable = m_initProxiable;
533 CheckDlgButton(IDC_CHECK_RENEWABLE, m_initRenewable);
534 m_newRenewable = m_initRenewable;
536 CheckDlgButton(IDC_CHECK_NO_ADDRESS, m_initNoAddress);
537 m_newNoAddress = m_initNoAddress;
539 if ( m_initNoAddress ) {
540 // Disable the control - jaltman
542 SendDlgItemMessage( IDC_IPADDRESS_PUBLIC,
549 SendDlgItemMessage( IDC_IPADDRESS_PUBLIC,
552 (LPARAM)m_initIPAddress
556 m_newIPAddress = m_initIPAddress;
557 #endif /* SET_PUBLIC_IP */
559 return TRUE; // return TRUE unless you set the focus to a control
560 // EXCEPTION: OCX Property Pages should return FALSE
563 void CKrb5ConfigOptions::OnCheckForwardable()
565 m_newForwardable = (BOOL)IsDlgButtonChecked(IDC_CHECK_FORWARDABLE);
569 void CKrb5ConfigOptions::OnCheckProxiable()
571 m_newProxiable = (BOOL)IsDlgButtonChecked(IDC_CHECK_PROXIABLE);
575 void CKrb5ConfigOptions::OnCheckRenewable()
577 m_newRenewable = (BOOL)IsDlgButtonChecked(IDC_CHECK_RENEWABLE);
581 void CKrb5ConfigOptions::OnCheckNoAddress()
583 m_newNoAddress = (BOOL)IsDlgButtonChecked(IDC_CHECK_NO_ADDRESS);
586 if ( m_newNoAddress ) {
587 // Disable the control - jaltman
589 SendDlgItemMessage( IDC_IPADDRESS_PUBLIC,
595 // Enable the IP Address Control - jaltman
597 SendDlgItemMessage( IDC_IPADDRESS_PUBLIC,
600 (LPARAM)m_initIPAddress
605 ///////////////////////////////////////////////////////////////////////
608 IMPLEMENT_DYNAMIC(CKrb5Properties, CPropertySheet)
610 CKrb5Properties::CKrb5Properties(UINT nIDCaption, CWnd* pParentWnd,
612 :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
616 CKrb5Properties::CKrb5Properties(LPCTSTR pszCaption, CWnd* pParentWnd,
618 :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
620 AddPage(&m_fileLocation);
621 AddPage(&m_configOptions);
624 CKrb5Properties::~CKrb5Properties()
628 void CKrb5Properties::OnHelp()
631 AfxGetApp()->HtmlHelp(HID_KRB5_PROPERTIES_COMMAND);
633 AfxGetApp()->WinHelp(HID_KRB5_PROPERTIES_COMMAND);
639 BEGIN_MESSAGE_MAP(CKrb5Properties, CPropertySheet)
640 //{{AFX_MSG_MAP(CKrb5Properties)
641 // NOTE - the ClassWizard will add and remove mapping macros here.
642 ON_COMMAND(ID_HELP, OnHelp)