diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-03-01 00:19:15 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-03-01 00:19:15 -0600 |
commit | 45bfc1dc6edcc27f67acfbebb2d0f22ea06a40c4 (patch) | |
tree | c3d9f2f09b0d991851c49ca4ce9ea16187688c12 /src | |
parent | 10386ff7f9356ceee6f3a30ed9064a09bd827eb4 (diff) | |
download | kcmldap-45bfc1dc6edcc27f67acfbebb2d0f22ea06a40c4.tar.gz kcmldap-45bfc1dc6edcc27f67acfbebb2d0f22ea06a40c4.zip |
Use bonding code in libtdeldap
Add skeleton code for tdeldapbonding
Diffstat (limited to 'src')
-rw-r--r-- | src/bondwizard.cpp | 2 | ||||
-rw-r--r-- | src/ldapbonding.cpp | 189 | ||||
-rw-r--r-- | src/ldapbonding.h | 3 |
3 files changed, 3 insertions, 191 deletions
diff --git a/src/bondwizard.cpp b/src/bondwizard.cpp index a71fdaa..db96f03 100644 --- a/src/bondwizard.cpp +++ b/src/bondwizard.cpp @@ -202,7 +202,7 @@ void BondWizard::accept(){ cancelButton()->setEnabled(false); finishpage->setEnabled(false); - if (m_ldapConfig->bondRealm(m_finalRealm, finishpage->ldapAdminUsername->text(), finishpage->ldapAdminPassword->password(), finishpage->ldapAdminRealm->text(), &errorString) == 0) { + if (LDAPManager::bondRealm(m_finalRealm, finishpage->ldapAdminUsername->text(), finishpage->ldapAdminPassword->password(), finishpage->ldapAdminRealm->text(), &errorString) == 0) { done(0); } else { diff --git a/src/ldapbonding.cpp b/src/ldapbonding.cpp index e7ce4ab..b7e1c23 100644 --- a/src/ldapbonding.cpp +++ b/src/ldapbonding.cpp @@ -339,7 +339,7 @@ void LDAPConfig::reBondToRealm() { passdlg.m_base->ldapAdminRealm->setText(realmName); if (passdlg.exec() == TQDialog::Accepted) { setEnabled(false); - if (bondRealm(m_realms[realmName], passdlg.m_base->ldapAdminUsername->text(), passdlg.m_base->ldapAdminPassword->password(), passdlg.m_base->ldapAdminRealm->text(), &errorString) == 0) { + if (LDAPManager::bondRealm(m_realms[realmName], passdlg.m_base->ldapAdminUsername->text(), passdlg.m_base->ldapAdminPassword->password(), passdlg.m_base->ldapAdminRealm->text(), &errorString) == 0) { // Success! realmcfg.bonded = true; m_realms.remove(realmName); @@ -378,7 +378,7 @@ void LDAPConfig::deactivateRealm() { passdlg.m_base->passprompt->setText(i18n("Please provide LDAP realm administrator credentials below to complete the unbonding process")); if (passdlg.exec() == TQDialog::Accepted) { setEnabled(false); - if (unbondRealm(m_realms[realmName], passdlg.m_base->ldapAdminUsername->text(), passdlg.m_base->ldapAdminPassword->password(), passdlg.m_base->ldapAdminRealm->text(), &errorString) == 0) { + if (LDAPManager::unbondRealm(m_realms[realmName], passdlg.m_base->ldapAdminUsername->text(), passdlg.m_base->ldapAdminPassword->password(), passdlg.m_base->ldapAdminRealm->text(), &errorString) == 0) { // Success! realmcfg.bonded = false; m_realms.remove(realmName); @@ -395,191 +395,6 @@ void LDAPConfig::deactivateRealm() { updateRealmList(); } -int LDAPConfig::bondRealm(LDAPRealmConfig realmcfg, TQString adminUserName, const char * adminPassword, TQString adminRealm, TQString *errstr) { - TQCString command = "kadmin"; - QCStringList args; - args << TQCString("-p") << TQCString(adminUserName+"@"+(adminRealm.upper())) << TQCString("-r") << TQCString(adminRealm.upper()); - - TQString hoststring = "host/"+m_fqdn; - - TQString prompt; - PtyProcess kadminProc; - kadminProc.exec(command, args); - prompt = LDAPManager::readFullLineFromPtyProcess(&kadminProc); - prompt = prompt.stripWhiteSpace(); - if (prompt == "kadmin>") { - command = TQCString("ext "+hoststring); - kadminProc.enableLocalEcho(false); - kadminProc.writeLine(command, true); - do { // Discard our own input - prompt = LDAPManager::readFullLineFromPtyProcess(&kadminProc); - printf("(kadmin) '%s'\n\r", prompt.ascii()); - } while (prompt == TQString(command)); - prompt = prompt.stripWhiteSpace(); - if (prompt.endsWith(" Password:")) { - kadminProc.enableLocalEcho(false); - kadminProc.writeLine(adminPassword, true); - do { // Discard our own input - prompt = LDAPManager::readFullLineFromPtyProcess(&kadminProc); - printf("(kadmin) '%s'\n\r", prompt.ascii()); - } while (prompt == ""); - prompt = prompt.stripWhiteSpace(); - } - if (prompt.contains("authentication failed")) { - if (errstr) *errstr = LDAPManager::detailedKAdminErrorMessage(prompt); - kadminProc.enableLocalEcho(false); - kadminProc.writeLine("quit", true); - return 1; - } - else if (prompt.endsWith("Principal does not exist")) { - // Wait for kadmin to be ready for the next command - if (!prompt.contains("kadmin>")) { - prompt = ""; - } - while (prompt == "") { - prompt = LDAPManager::readFullLineFromPtyProcess(&kadminProc); - printf("(kadmin) '%s'\n\r", prompt.ascii()); - } - command = TQCString("ank --random-key "+hoststring); - kadminProc.enableLocalEcho(false); - kadminProc.writeLine(command, true); - do { // Discard our own input - prompt = LDAPManager::readFullLineFromPtyProcess(&kadminProc); - printf("(kadmin) '%s'\n\r", prompt.ascii()); - } while (prompt == TQString(command)); - prompt = prompt.stripWhiteSpace(); - // Use all defaults - while (prompt != "kadmin>") { - if (prompt.endsWith(" Password:")) { - kadminProc.enableLocalEcho(false); - kadminProc.writeLine(adminPassword, true); - do { // Discard our own input - prompt = LDAPManager::readFullLineFromPtyProcess(&kadminProc); - printf("(kadmin) '%s'\n\r", prompt.ascii()); - } while (prompt == ""); - prompt = prompt.stripWhiteSpace(); - } - if (prompt.contains("authentication failed")) { - if (errstr) *errstr = LDAPManager::detailedKAdminErrorMessage(prompt); - kadminProc.enableLocalEcho(false); - kadminProc.writeLine("quit", true); - return 1; - } - else { - // Extract whatever default is in the [brackets] and feed it back to kadmin - TQString defaultParam; - int leftbracket = prompt.find("["); - int rightbracket = prompt.find("]"); - if ((leftbracket >= 0) && (rightbracket >= 0)) { - leftbracket++; - defaultParam = prompt.mid(leftbracket, rightbracket-leftbracket); - } - command = TQCString(defaultParam); - kadminProc.enableLocalEcho(false); - kadminProc.writeLine(command, true); - do { // Discard our own input - prompt = LDAPManager::readFullLineFromPtyProcess(&kadminProc); - printf("(kadmin) '%s'\n\r", prompt.ascii()); - } while (prompt == TQString(command)); - prompt = prompt.stripWhiteSpace(); - } - } - command = TQCString("ext "+hoststring); - kadminProc.enableLocalEcho(false); - kadminProc.writeLine(command, true); - do { // Discard our own input - prompt = LDAPManager::readFullLineFromPtyProcess(&kadminProc); - printf("(kadmin) '%s'\n\r", prompt.ascii()); - } while (prompt == TQString(command)); - prompt = prompt.stripWhiteSpace(); - if (prompt != "kadmin>") { - if (errstr) *errstr = LDAPManager::detailedKAdminErrorMessage(prompt); - kadminProc.enableLocalEcho(false); - kadminProc.writeLine("quit", true); - return 1; - } - - // Success! - kadminProc.enableLocalEcho(false); - kadminProc.writeLine("quit", true); - - realmcfg.bonded = true; - m_realms.remove(realmcfg.name); - m_realms.insert(realmcfg.name, realmcfg); - save(); - return 0; - } - else if (prompt == "kadmin>") { - // Success! - kadminProc.enableLocalEcho(false); - kadminProc.writeLine("quit", true); - - realmcfg.bonded = true; - m_realms.remove(realmcfg.name); - m_realms.insert(realmcfg.name, realmcfg); - save(); - return 0; - } - - // Failure - if (errstr) *errstr = LDAPManager::detailedKAdminErrorMessage(prompt); - kadminProc.enableLocalEcho(false); - kadminProc.writeLine("quit", true); - return 1; - } - - if (errstr) *errstr = "Internal error. Verify that kadmin exists and can be executed."; - return 1; // Failure -} - -int LDAPConfig::unbondRealm(LDAPRealmConfig realmcfg, TQString adminUserName, const char * adminPassword, TQString adminRealm, TQString *errstr) { - Q_UNUSED(realmcfg); - - TQCString command = "kadmin"; - QCStringList args; - args << TQCString("-p") << TQCString(adminUserName+"@"+(adminRealm.upper())); - - TQString hoststring = "host/"+m_fqdn; - - TQString prompt; - PtyProcess kadminProc; - kadminProc.exec(command, args); - prompt = LDAPManager::readFullLineFromPtyProcess(&kadminProc); - prompt = prompt.stripWhiteSpace(); - if (prompt == "kadmin>") { - command = TQCString("delete "+hoststring); - kadminProc.enableLocalEcho(false); - kadminProc.writeLine(command, true); - do { // Discard our own input - prompt = LDAPManager::readFullLineFromPtyProcess(&kadminProc); - printf("(kadmin) '%s'\n\r", prompt.ascii()); - } while (prompt == TQString(command)); - prompt = prompt.stripWhiteSpace(); - if (prompt.endsWith(" Password:")) { - kadminProc.enableLocalEcho(false); - kadminProc.writeLine(adminPassword, true); - do { // Discard our own input - prompt = LDAPManager::readFullLineFromPtyProcess(&kadminProc); - printf("(kadmin) '%s'\n\r", prompt.ascii()); - } while (prompt == ""); - prompt = prompt.stripWhiteSpace(); - } - if (prompt != "kadmin>") { - if (errstr) *errstr = LDAPManager::detailedKAdminErrorMessage(prompt); - kadminProc.enableLocalEcho(false); - kadminProc.writeLine("quit", true); - return 1; - } - - // Success! - kadminProc.enableLocalEcho(false); - kadminProc.writeLine("quit", true); - return 0; - } - - return 1; // Failure -} - void LDAPConfig::realmProperties() { TQListViewItem *selrealm = base->ldapRealmList->selectedItem(); if (selrealm) { diff --git a/src/ldapbonding.h b/src/ldapbonding.h index 7a8376c..a6686a3 100644 --- a/src/ldapbonding.h +++ b/src/ldapbonding.h @@ -55,9 +55,6 @@ class LDAPConfig: public TDECModule virtual TQString quickHelp() const; virtual const TDEAboutData *aboutData() const { return myAboutData; }; - 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); - private slots: void processLockouts(); void bondToNewRealm(); |