From 94684957020e61e1089cbe2ea4357d86a4de9c55 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 20 May 2012 14:37:46 -0500 Subject: [PATCH] Now ready to add kadmin interaction code --- src/ldap.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++- src/ldap.h | 5 +++++ src/ldapconfigbase.ui | 21 ++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/ldap.cpp b/src/ldap.cpp index 2394b03..3197f28 100644 --- a/src/ldap.cpp +++ b/src/ldap.cpp @@ -18,6 +18,10 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include +#include +#include + #include #include @@ -98,6 +102,11 @@ LDAPConfig::LDAPConfig(TQWidget *parent, const char *name, const TQStringList&) connect(base->passwordHash, TQT_SIGNAL(activated(int)), this, TQT_SLOT(changed())); connect(base->ignoredUsers, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(changed())); + m_fqdn = getMachineFQDN(); + base->hostFQDN->setEnabled(false); + base->hostFQDN->clear(); + base->hostFQDN->insertItem(m_fqdn); + load(); if (getuid() != 0 || !systemconfig->checkConfigFilesWritable( true )) { @@ -111,6 +120,33 @@ LDAPConfig::~LDAPConfig() { delete systemconfig; } +// FIXME +// This should be moved to a TDE core library +TQString LDAPConfig::getMachineFQDN() { + struct addrinfo hints, *info, *p; + int gai_result; + + char hostname[1024]; + hostname[1023] = '\0'; + gethostname(hostname, 1023); + + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_UNSPEC; // IPV4 or IPV6 + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_CANONNAME; + + if ((gai_result = getaddrinfo(hostname, NULL, &hints, &info)) != 0) { + return TQString(hostname); + } + TQString fqdn = TQString(hostname); + for (p=info; p!=NULL; p=p->ai_next) { + fqdn = TQString(p->ai_canonname); + } + freeaddrinfo(info); + + return fqdn; +} + void LDAPConfig::load() { kgs = new KGlobalSettings(); @@ -120,6 +156,7 @@ void LDAPConfig::load() { void LDAPConfig::load(bool useDefaults ) { int i; + bool thisIsMyMachine; //Update the toggle buttons with the current configuration systemconfig->setReadDefaults( useDefaults ); @@ -128,6 +165,12 @@ void LDAPConfig::load(bool useDefaults ) base->systemEnableSupport->setChecked(systemconfig->readBoolEntry("EnableLDAP", false)); m_defaultRealm = systemconfig->readEntry("DefaultRealm", TQString::null); m_ticketLifetime = systemconfig->readNumEntry("TicketLifetime", 86400); + if (m_fqdn == systemconfig->readEntry("HostFQDN", "")) { + thisIsMyMachine = true; + } + else { + thisIsMyMachine = false; + } m_ldapVersion = systemconfig->readNumEntry("ConnectionLDAPVersion", 3); m_ldapTimeout = systemconfig->readNumEntry("ConnectionLDAPTimeout", 2); @@ -148,7 +191,12 @@ void LDAPConfig::load(bool useDefaults ) // Read in realm data LDAPRealmConfig realmcfg; realmcfg.name = realmName; - realmcfg.bonded = systemconfig->readBoolEntry("bonded"); + if (thisIsMyMachine) { + realmcfg.bonded = systemconfig->readBoolEntry("bonded"); + } + else { + realmcfg.bonded = false; + } realmcfg.uid_offset = systemconfig->readNumEntry("uid_offset"); realmcfg.gid_offset = systemconfig->readNumEntry("gid_offset"); realmcfg.domain_mappings = systemconfig->readListEntry("domain_mappings"); @@ -220,6 +268,7 @@ void LDAPConfig::save() { // Write system configuration systemconfig->setGroup(NULL); systemconfig->writeEntry("EnableLDAP", base->systemEnableSupport->isChecked()); + systemconfig->writeEntry("HostFQDN", m_fqdn); m_defaultRealm = base->defaultRealm->currentText(); m_ticketLifetime = base->ticketLifetime->value(); diff --git a/src/ldap.h b/src/ldap.h index 7e2e236..e974034 100644 --- a/src/ldap.h +++ b/src/ldap.h @@ -77,6 +77,10 @@ class LDAPConfig: public KCModule int bondRealm(LDAPRealmConfig realmcfg, TQString adminUserName, const char * adminPassword, TQString adminRealm, TQString *errstr=0); int unbondRealm(LDAPRealmConfig realmcfg, TQString adminUserName, const char * adminPassword, TQString adminRealm, TQString *errstr=0); + // FIXME + // This should be moved to a TDE core library + TQString getMachineFQDN(); + private slots: void processLockouts(); void bondToNewRealm(); @@ -95,6 +99,7 @@ class LDAPConfig: public KCModule KGlobalSettings *kgs; LDAPConfigBase *base; LDAPRealmConfigList m_realms; + TQString m_fqdn; TQString m_defaultRealm; int m_ticketLifetime; diff --git a/src/ldapconfigbase.ui b/src/ldapconfigbase.ui index ee6e963..aa1d15e 100644 --- a/src/ldapconfigbase.ui +++ b/src/ldapconfigbase.ui @@ -53,6 +53,27 @@ &Enable LDAP Realm Support + + + unnamed + + + Fully Qualified Domain Name + + + + 0 + 0 + 0 + 0 + + + + + + hostFQDN + +