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::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();
	}
}
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;
}
Example #4
0
CKrb4EditDomainRealmList::CKrb4EditDomainRealmList(LPSTR editItem, CWnd* pParent)
	: CDialog(CKrb4EditDomainRealmList::IDD, pParent)
{
    m_startup = TRUE;
	m_editItem = _T("");

	// Parse the passed in item
	LPSTR pEditItem = editItem;
	LPSTR findSpace = strchr(editItem, ' ');
	if (findSpace)
	  *findSpace = 0;
	else
	{
		 LeashErrorBox("This is a defective entry in file",
					   CKrb4ConfigFileLocation::m_newKrbrealmFile);
		 ASSERT(0);
		 m_initDomainHost = m_newDomainHost = editItem;
		 m_initRealm = m_newRealm = _T("");
		 return;
	}

	m_initDomainHost = m_newDomainHost = editItem;  // first token

	pEditItem = strchr(editItem, '\0');
	if (pEditItem)
	{
		pEditItem++;
		findSpace++;
	}
	else
	  ASSERT(0);

	findSpace = strchr(pEditItem, ' ');
	if (findSpace)
	{
		*findSpace = 0;
	}

	m_initRealm = m_newRealm = pEditItem; // second token

	//{{AFX_DATA_INIT(CKrb4EditDomainRealmList)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}
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();
		}
	}
}
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;
}
Example #7
0
BOOL CKrb4ConfigFileLocation::OnInitDialog()
{
	CPropertyPage::OnInitDialog();

	INT krbCreate = 0;
	INT krbrealmCreate = 0;
    CHAR krb_path[MAX_PATH];
	CHAR krbrealm_path[MAX_PATH];
    CHAR ticketName[MAX_PATH];
	unsigned int krb_path_sz = sizeof(krb_path);
    unsigned int krbrealm_path_sz = sizeof(krbrealm_path);
    CString strMessage;


	// Set KRB.CON
	memset(krb_path, '\0', sizeof(krb_path));
	if (!pkrb_get_krbconf2(krb_path, &krb_path_sz))
	{ // Error has happened
		m_noKrbFileStartupWarning = TRUE;
	}
	else
	{ // normal find
		m_initKrbFile = krb_path;
	    m_newKrbFile = m_initKrbFile;
        SetDlgItemText(IDC_EDIT_KRB_LOC, m_initKrbFile);
    }

    // Set KRBREALM.CON
    memset(krbrealm_path, '\0', sizeof(krbrealm_path));
    if (!pkrb_get_krbrealm2(krbrealm_path, &krbrealm_path_sz))
	{
        // Error has happened
		m_noKrbrealmFileStartupWarning = TRUE;
	}
	else
	{
        // normal find
		m_initKrbrealmFile = krbrealm_path;
        m_newKrbrealmFile = m_initKrbrealmFile;
        SetDlgItemText(IDC_EDIT_KRBREALM_LOC, m_initKrbrealmFile);
    }

	if (pLeash_get_lock_file_locations() ||
        getenv("KRB4_KRB.REALMS") || getenv("KRB4_KRB.CONF") || getenv("KRB4_CONFIG"))
    {
        GetDlgItem(IDC_EDIT_KRB_LOC)->EnableWindow(FALSE);
        GetDlgItem(IDC_EDIT_KRBREALM_LOC)->EnableWindow(FALSE);
        GetDlgItem(IDC_BUTTON_KRB_BROWSE)->EnableWindow(FALSE);
        GetDlgItem(IDC_BUTTON_KRBREALM_BROWSE)->EnableWindow(FALSE);
    }
    else if ( !(getenv("KRB4_KRB.REALMS") || getenv("KRB4_KRB.CONF") || getenv("KRB4_CONFIG")) )
    {
        GetDlgItem(IDC_STATIC_CONFILES)->ShowWindow(FALSE);
    }


    // Set TICKET.KRB file Editbox
    *ticketName = NULL;
	pkrb_set_tkt_string(0);

    char *pticketName = ptkt_string();
    if (pticketName)
        strcpy(ticketName, pticketName);

    if (!*ticketName)
	{
		LeashErrorBox("OnInitDialog::Can't locate ticket file", TICKET_FILE);
	}
	else
	{
        m_initTicketFile = m_newTicketFile = ticketName;
		m_ticketEditBox.ReplaceSel(m_initTicketFile);
	}

	if (getenv("KRBTKFILE"))
        GetDlgItem(IDC_EDIT_TICKET_FILE)->EnableWindow(FALSE);
    else
        GetDlgItem(IDC_STATIC_TXT)->ShowWindow(FALSE);

    return FALSE;
}