summaryrefslogtreecommitdiffstats
path: root/src/libtdeldap.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-06-03 00:02:24 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-06-03 00:02:24 -0500
commit50a7026e7f9c5ab6738e0ed0445a9aaef7141d68 (patch)
tree59641060fe78b02098042754808f623a81f95ab9 /src/libtdeldap.cpp
parentfb7be0231c63a621beab13d893ce587c8cdc82fb (diff)
downloadlibtdeldap-50a7026e7f9c5ab6738e0ed0445a9aaef7141d68.tar.gz
libtdeldap-50a7026e7f9c5ab6738e0ed0445a9aaef7141d68.zip
Moved realm conffile writing to this library
Diffstat (limited to 'src/libtdeldap.cpp')
-rw-r--r--src/libtdeldap.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/libtdeldap.cpp b/src/libtdeldap.cpp
index 680a81f..39dc65c 100644
--- a/src/libtdeldap.cpp
+++ b/src/libtdeldap.cpp
@@ -18,10 +18,13 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+#include <tqfile.h>
+
#include <klocale.h>
#include <kmessagebox.h>
#include <klineedit.h>
#include <kpassdlg.h>
+#include <ksimpleconfig.h>
#include <ldap.h>
#include <stdlib.h>
@@ -34,6 +37,11 @@
#define LDAP_INSECURE_PORT 389
#define LDAP_SECURE_PORT 636
+// FIXME
+// Connect this to CMake/Automake
+#define KDE_CONFDIR "/etc/trinity"
+#define LDAP_FILE "/etc/ldap.conf"
+
int requested_ldap_version = LDAP_VERSION3;
int requested_ldap_auth_method = LDAP_AUTH_SIMPLE; // Is this safe and secure over an untrusted connection?
char* ldap_user_and_operational_attributes[2] = {"*", "+"};
@@ -1207,6 +1215,91 @@ printf("[RAJA DEBUG 140.3] Moving %s to relative DN %s and parent %s", dn, id.as
return -1;
}
+void LDAPManager::writeLDAPConfFile(LDAPRealmConfig realmcfg) {
+ KSimpleConfig* systemconfig;
+ TQString m_defaultRealm;
+ int m_ticketLifetime;
+ int m_ldapVersion;
+ int m_ldapTimeout;
+ TQString m_bindPolicy;
+ int m_ldapBindTimeout;
+ TQString m_passwordHash;
+ TQString m_ignoredUsers;
+
+ systemconfig = new KSimpleConfig( TQString::fromLatin1( KDE_CONFDIR "/ldap/ldapconfigrc" ));
+ systemconfig->setGroup(NULL);
+ m_defaultRealm = systemconfig->readEntry("DefaultRealm", TQString::null);
+ m_ticketLifetime = systemconfig->readNumEntry("TicketLifetime", 86400);
+
+ m_ldapVersion = systemconfig->readNumEntry("ConnectionLDAPVersion", 3);
+ m_ldapTimeout = systemconfig->readNumEntry("ConnectionLDAPTimeout", 2);
+ m_bindPolicy = systemconfig->readEntry("ConnectionBindPolicy", "soft");
+ m_ldapBindTimeout = systemconfig->readNumEntry("ConnectionBindTimeout", 2);
+ m_passwordHash = systemconfig->readEntry("ConnectionPasswordHash", "exop");
+ m_ignoredUsers = systemconfig->readEntry("ConnectionIgnoredUsers", DEFAULT_IGNORED_USERS_LIST);
+
+ TQFile file(LDAP_FILE);
+ if (file.open(IO_WriteOnly)) {
+ TQTextStream stream( &file );
+
+ stream << "# This file was automatically generated by TDE\n";
+ stream << "# All changes will be lost!\n";
+ stream << "\n";
+
+ if (realmcfg.bonded) {
+ stream << "host " << realmcfg.admin_server << "\n";
+ TQStringList domainChunks = TQStringList::split(".", realmcfg.name.lower());
+ stream << "base dc=" << domainChunks.join(",dc=") << "\n";
+ stream << "ldap_version " << m_ldapVersion << "\n";
+ stream << "timelimit " << m_ldapTimeout << "\n";
+ stream << "bind_timelimit " << m_ldapBindTimeout << "\n";
+ stream << "bind_policy " << m_bindPolicy.lower() << "\n";
+ stream << "pam_password " << m_passwordHash.lower() << "\n";
+ stream << "nss_initgroups_ignoreusers " << m_ignoredUsers << "\n";
+ }
+
+ file.close();
+ }
+
+ delete systemconfig;
+}
+
+void LDAPManager::writeTDERealmList(LDAPRealmConfigList realms, KSimpleConfig* config) {
+ LDAPRealmConfigList::Iterator it;
+ for (it = realms.begin(); it != realms.end(); ++it) {
+ LDAPRealmConfig realmcfg = it.data();
+ TQString configRealmName = realmcfg.name;
+ configRealmName.prepend("LDAPRealm-");
+ config->setGroup(configRealmName);
+ // Save realm settings
+ config->writeEntry("bonded", realmcfg.bonded);
+ config->writeEntry("uid_offset", realmcfg.uid_offset);
+ config->writeEntry("gid_offset", realmcfg.gid_offset);
+ config->writeEntry("domain_mappings", realmcfg.domain_mappings);
+ config->writeEntry("kdc", realmcfg.kdc);
+ config->writeEntry("kdc_port", realmcfg.kdc_port);
+ config->writeEntry("admin_server", realmcfg.admin_server);
+ config->writeEntry("admin_server_port", realmcfg.admin_server_port);
+ config->writeEntry("pkinit_require_eku", realmcfg.pkinit_require_eku);
+ config->writeEntry("pkinit_require_krbtgt_otherName", realmcfg.pkinit_require_krbtgt_otherName);
+ config->writeEntry("win2k_pkinit", realmcfg.win2k_pkinit);
+ config->writeEntry("win2k_pkinit_require_binding", realmcfg.win2k_pkinit_require_binding);
+ }
+
+ // Delete any realms that do not exist in the realms database
+ TQStringList cfgRealms = config->groupList();
+ for (TQStringList::Iterator it(cfgRealms.begin()); it != cfgRealms.end(); ++it) {
+ if ((*it).startsWith("LDAPRealm-")) {
+ config->setGroup(*it);
+ TQString realmName=*it;
+ realmName.remove(0,strlen("LDAPRealm-"));
+ if (!realms.contains(realmName)) {
+ config->deleteGroup(*it);
+ }
+ }
+ }
+}
+
// ===============================================================================================================
//
// DATA CLASS CONSTRUCTORS AND DESTRUCTORS