summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2012-05-29 16:51:56 -0500
committerTimothy Pearson <[email protected]>2012-05-29 16:51:56 -0500
commit68e675057219723d6c657db4fd930c5b49ff583c (patch)
tree97024975d90d419111e9b1c3a27345ac1ac8f816 /src
parent5948ba909d1a2541865fcb2b52f76a7719f72f3e (diff)
downloadkcmldapmanager-68e675057219723d6c657db4fd930c5b49ff583c.tar.gz
kcmldapmanager-68e675057219723d6c657db4fd930c5b49ff583c.zip
Add RO group editor
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/groupconfigbase.ui9
-rw-r--r--src/groupconfigdlg.cpp106
-rw-r--r--src/groupconfigdlg.h53
-rw-r--r--src/ldapmgr.cpp25
-rw-r--r--src/ldapmgr.h2
-rw-r--r--src/libtdeldap.cpp620
-rw-r--r--src/libtdeldap.h6
8 files changed, 544 insertions, 279 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index c49b9de..f3a95af 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,7 +4,7 @@ METASOURCES = AUTO
# Install this plugin in the KDE modules directory
kde_module_LTLIBRARIES = kcm_ldapmanager.la
-kcm_ldapmanager_la_SOURCES = ldapmgr.cpp ldapconfigbase.ui userconfigbase.ui groupconfigbase.ui libtdeldap.cpp ldaplogindlgbase.ui ldaplogindlg.cpp ldappasswddlg.cpp userconfigdlg.cpp
+kcm_ldapmanager_la_SOURCES = ldapmgr.cpp ldapconfigbase.ui userconfigbase.ui groupconfigbase.ui libtdeldap.cpp ldaplogindlgbase.ui ldaplogindlg.cpp ldappasswddlg.cpp userconfigdlg.cpp groupconfigdlg.cpp
kcm_ldapmanager_la_LIBADD = -lkio $(LIB_TDEUI) -lldap
kcm_ldapmanager_la_LDFLAGS = -avoid-version -module -no-undefined \
$(all_libraries)
diff --git a/src/groupconfigbase.ui b/src/groupconfigbase.ui
index 2f7f8db..87bb1b5 100644
--- a/src/groupconfigbase.ui
+++ b/src/groupconfigbase.ui
@@ -60,12 +60,15 @@
<string>Group ID</string>
</property>
</widget>
- <widget class="KLineEdit" row="1" column="2" colspan="1">
+ <widget class="KIntNumInput" row="1" column="2" colspan="1">
<property name="name">
<cstring>groupID</cstring>
</property>
- <property name="enabled">
- <cstring>false</cstring>
+ <property name="minValue">
+ <number>1</number>
+ </property>
+ <property name="maxValue">
+ <number>99999</number>
</property>
</widget>
<widget class="TQLayoutWidget" row="2" column="0" colspan="3">
diff --git a/src/groupconfigdlg.cpp b/src/groupconfigdlg.cpp
new file mode 100644
index 0000000..8f7593e
--- /dev/null
+++ b/src/groupconfigdlg.cpp
@@ -0,0 +1,106 @@
+/***************************************************************************
+ * Copyright (C) 2012 by Timothy Pearson *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include <klocale.h>
+#include <klineedit.h>
+#include <ktextedit.h>
+#include <knuminput.h>
+#include <kactionselector.h>
+#include <tqlistbox.h>
+#include <kpushbutton.h>
+#include <tqpixmap.h>
+#include <tqiconset.h>
+#include <tqlabel.h>
+#include <kurlrequester.h>
+#include <kcombobox.h>
+#include <tqradiobutton.h>
+#include <tqcheckbox.h>
+#include <kdatetimewidget.h>
+
+#include "ldapmgr.h"
+#include "groupconfigdlg.h"
+
+GroupConfigDialog::GroupConfigDialog(LDAPGroupInfo group, LDAPConfig* parent, const char* name)
+ : KDialogBase(parent, name, true, i18n("LDAP Group Properties"), Ok|Cancel, Ok, true), m_group(group), m_ldapconfig(parent)
+{
+ m_base = new LDAPGroupConfigBase(this);
+ setMainWidget(m_base);
+
+ m_base->addToGroup->setText(i18n("-->"));
+ m_base->removeFromGroup->setText(i18n("<--"));
+ m_base->groupName->setEnabled(false);
+
+ connect(m_base->addToGroup, TQT_SIGNAL(clicked()), this, TQT_SLOT(addSelectedUserToGroup()));
+ connect(m_base->removeFromGroup, TQT_SIGNAL(clicked()), this, TQT_SLOT(removeSelectedUserFromGroup()));
+
+ // Update fields
+ m_base->groupName->setText(m_group.name);
+ m_base->groupID->setValue(m_group.gid);
+
+ LDAPUserInfoList userList = m_ldapconfig->userList();
+ LDAPUserInfoList::Iterator it;
+ for (it = userList.begin(); it != userList.end(); ++it) {
+ LDAPUserInfo user = *it;
+ if (group.userlist.contains(user.distinguishedName)) {
+ (void)new TQListBoxText(m_base->selectedAccounts, user.name);
+ }
+ else {
+ (void)new TQListBoxText(m_base->availableAccounts, user.name);
+ }
+ }
+ m_base->availableAccounts->sort(true);
+ m_base->selectedAccounts->sort(true);
+
+ processLockouts();
+}
+
+void GroupConfigDialog::slotOk() {
+ accept();
+}
+
+void GroupConfigDialog::processLockouts() {
+ //
+}
+
+void GroupConfigDialog::addSelectedUserToGroup() {
+ TQListBoxText* itm = dynamic_cast<TQListBoxText*>(m_base->availableAccounts->selectedItem());
+ if (itm) {
+ (void)new TQListBoxText(m_base->selectedAccounts, itm->text());
+ delete itm;
+ }
+ m_base->availableAccounts->sort(true);
+ m_base->selectedAccounts->sort(true);
+}
+
+void GroupConfigDialog::removeSelectedUserFromGroup() {
+ TQListBoxText* itm = dynamic_cast<TQListBoxText*>(m_base->selectedAccounts->selectedItem());
+ if (itm) {
+ (void)new TQListBoxText(m_base->availableAccounts, itm->text());
+ delete itm;
+ }
+ m_base->availableAccounts->sort(true);
+ m_base->selectedAccounts->sort(true);
+}
+
+LDAPGroupInfo GroupConfigDialog::groupProperties() {
+ return m_group;
+}
+
+#include "groupconfigdlg.moc"
diff --git a/src/groupconfigdlg.h b/src/groupconfigdlg.h
new file mode 100644
index 0000000..f85a2a2
--- /dev/null
+++ b/src/groupconfigdlg.h
@@ -0,0 +1,53 @@
+/***************************************************************************
+ * Copyright (C) 2012 by Timothy Pearson *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef _GROUPCONFIGDIALOG_H_
+#define _GROUPCONFIGDIALOG_H_
+
+#include <kdialogbase.h>
+
+#include "libtdeldap.h"
+#include "groupconfigbase.h"
+
+class GroupConfigDialog : public KDialogBase
+{
+ Q_OBJECT
+
+public:
+ GroupConfigDialog(LDAPGroupInfo group, LDAPConfig* parent = 0, const char* name = 0);
+ LDAPGroupInfo groupProperties();
+
+public slots:
+ void slotOk();
+ void processLockouts();
+
+private slots:
+ void addSelectedUserToGroup();
+ void removeSelectedUserFromGroup();
+
+public:
+ LDAPGroupConfigBase *m_base;
+
+private:
+ LDAPGroupInfo m_group;
+ LDAPConfig* m_ldapconfig;
+};
+
+#endif // _GROUPCONFIGDIALOG_H_
diff --git a/src/ldapmgr.cpp b/src/ldapmgr.cpp
index 70df49a..5f2433c 100644
--- a/src/ldapmgr.cpp
+++ b/src/ldapmgr.cpp
@@ -43,6 +43,7 @@
#include "libtdeldap.h"
#include "ldappasswddlg.h"
#include "userconfigdlg.h"
+#include "groupconfigdlg.h"
// FIXME
// Connect this to CMake/Automake
@@ -84,6 +85,7 @@ LDAPConfig::LDAPConfig(TQWidget *parent, const char *name, const TQStringList&)
connect(base->group_list, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(groupHighlighted()));
connect(base->user_buttonModify, TQT_SIGNAL(clicked()), this, TQT_SLOT(modifySelectedUser()));
+ connect(base->group_buttonModify, TQT_SIGNAL(clicked()), this, TQT_SLOT(modifySelectedGroup()));
load();
@@ -156,6 +158,10 @@ void LDAPConfig::connectToRealm(const TQString& realm) {
TQString host = m_systemconfig->readEntry("admin_server");
m_ldapmanager = new LDAPManager(realm, host);
+ updateAllInformation();
+}
+
+void LDAPConfig::updateAllInformation() {
populateUsers();
populateGroups();
// RAJA FIXME
@@ -322,11 +328,26 @@ void LDAPConfig::modifySelectedUser() {
// Launch a dialog to edit the user
LDAPUserInfo user = selectedUser();
- // RAJA FIXME
- // Reload user data from LDAP before launching dialog!!!! Otherwise people who leave the LDAP manager open for days at a time (admins) will end up inserting stale data into the LDAP database!!!
+ // Reload user data from LDAP before launching dialog
+ user = m_ldapmanager->getUserByDistinguishedName(user.distinguishedName);
UserConfigDialog userconfigdlg(user, this);
if (userconfigdlg.exec() == TQDialog::Accepted) {
+ // RAJA FIXME
+ }
+ updateAllInformation();
+}
+
+void LDAPConfig::modifySelectedGroup() {
+ // Launch a dialog to edit the user
+ LDAPGroupInfo group = selectedGroup();
+
+ // Reload group data from LDAP before launching dialog
+ group = m_ldapmanager->getGroupByDistinguishedName(group.distinguishedName);
+ GroupConfigDialog groupconfigdlg(group, this);
+ if (groupconfigdlg.exec() == TQDialog::Accepted) {
+ // RAJA FIXME
}
+ updateAllInformation();
}
int LDAPConfig::buttons() {
diff --git a/src/ldapmgr.h b/src/ldapmgr.h
index b875c3a..eed2b3e 100644
--- a/src/ldapmgr.h
+++ b/src/ldapmgr.h
@@ -60,6 +60,8 @@ class LDAPConfig: public KCModule
void userHighlighted();
void groupHighlighted();
void modifySelectedUser();
+ void modifySelectedGroup();
+ void updateAllInformation();
public:
LDAPUserInfo findUserInfoByNameAndUID(TQString name, TQString uid);
diff --git a/src/libtdeldap.cpp b/src/libtdeldap.cpp
index 80a037f..973e9ee 100644
--- a/src/libtdeldap.cpp
+++ b/src/libtdeldap.cpp
@@ -52,6 +52,7 @@ TQString LDAPManager::realm() {
}
int LDAPManager::bind() {
+printf("[RAJA DEBUG 600.0] In LDAPManager::bind()\n\r"); fflush(stdout);
if (m_ldap) {
return 0;
}
@@ -164,6 +165,7 @@ int LDAPManager::bind() {
}
int LDAPManager::unbind(bool force) {
+printf("[RAJA DEBUG 600.1] In LDAPManager::unbind()\n\r"); fflush(stdout);
if (!m_ldap) {
return 0;
}
@@ -179,6 +181,228 @@ int LDAPManager::unbind(bool force) {
return retcode;
}
+LDAPUserInfo LDAPManager::parseLDAPUserRecord(LDAPMessage* entry) {
+ int i;
+ char* dn = NULL;
+ char* attr;
+ struct berval **vals;
+ BerElement* ber;
+
+ LDAPUserInfo userinfo;
+
+ if((dn = ldap_get_dn(m_ldap, entry)) != NULL) {
+ printf("Returned dn: %s\n", dn);
+ userinfo.distinguishedName = dn;
+ TQStringList dnParts = TQStringList::split(",", dn);
+ TQString id = dnParts[0];
+ if (id.startsWith("uid=")) {
+ id = id.remove(0, 4);
+ userinfo.name = id;
+ }
+ ldap_memfree(dn);
+ }
+
+ for( attr = ldap_first_attribute(m_ldap, entry, &ber); attr != NULL; attr = ldap_next_attribute(m_ldap, entry, ber)) {
+ if ((vals = ldap_get_values_len(m_ldap, entry, attr)) != NULL) {
+printf("[RAJA DEBUG 100.3] %s: %s\n\r", attr, vals[i]->bv_val);
+ userinfo.informationValid = true;
+ TQString ldap_field = attr;
+ i=0;
+ if (ldap_field == "uidNumber") {
+ userinfo.uid = atoi(vals[i]->bv_val);
+ }
+ else if (ldap_field == "loginShell") {
+ userinfo.shell = vals[i]->bv_val;
+ }
+ else if (ldap_field == "homeDirectory") {
+ userinfo.homedir = vals[i]->bv_val;
+ }
+ else if (ldap_field == "gidNumber") {
+ userinfo.primary_gid = atoi(vals[i]->bv_val);
+ }
+ else if (ldap_field == "krb5KDCFlags") {
+ userinfo.status = (LDAPKRB5Flags)(atoi(vals[i]->bv_val));
+ }
+ else if (ldap_field == "createTimestamp") { // YYYYMMDD000000Z
+ TQString formattedDate = vals[i]->bv_val;
+ formattedDate.insert(4,"-");
+ formattedDate.insert(7,"-");
+ formattedDate.insert(10,"T");
+ formattedDate.insert(13,":");
+ formattedDate.insert(16,":");
+ formattedDate.remove(19, 1);
+ userinfo.account_created = TQDateTime::fromString(formattedDate, TQt::ISODate);
+ }
+ else if (ldap_field == "modifyTimestamp") { // YYYYMMDD000000Z
+ TQString formattedDate = vals[i]->bv_val;
+ formattedDate.insert(4,"-");
+ formattedDate.insert(7,"-");
+ formattedDate.insert(10,"T");
+ formattedDate.insert(13,":");
+ formattedDate.insert(16,":");
+ formattedDate.remove(19, 1);
+ userinfo.account_modified = TQDateTime::fromString(formattedDate, TQt::ISODate);
+ }
+ // FIXME
+ // These two attributes do not seem to be available with a Heimdal KDC
+ // userinfo.password_last_changed = vals[i]->bv_val;
+ // userinfo.password_expires = vals[i]->bv_val;
+ else if (ldap_field == "krb5PasswordEnd") { // YYYYMMDD000000Z
+ TQString formattedDate = vals[i]->bv_val;
+ formattedDate.insert(4,"-");
+ formattedDate.insert(7,"-");
+ formattedDate.insert(10,"T");
+ formattedDate.insert(13,":");
+ formattedDate.insert(16,":");
+ formattedDate.remove(19, 1);
+ userinfo.password_expiration = TQDateTime::fromString(formattedDate, TQt::ISODate);
+ }
+ // FIXME
+ // These six(!) attributes do not seem to be available with a Heimdal KDC
+ // userinfo.password_ages = vals[i]->bv_val;
+ // userinfo.new_password_interval = vals[i]->bv_val;
+ // userinfo.new_password_warn_interval = vals[i]->bv_val;
+ // userinfo.new_password_lockout_delay = vals[i]->bv_val;
+ // userinfo.password_has_minimum_age = vals[i]->bv_val;
+ // userinfo.password_minimum_age = vals[i]->bv_val;
+ else if (ldap_field == "krb5MaxLife") { // units: hours
+ userinfo.maximum_ticket_lifetime = atoi(vals[i]->bv_val);
+ }
+ else if (ldap_field == "cn") {
+ userinfo.commonName = vals[i]->bv_val;
+ }
+ else if (ldap_field == "givenName") {
+ userinfo.givenName = vals[i]->bv_val;
+ }
+ else if (ldap_field == "sn") {
+ userinfo.surName = vals[i]->bv_val;
+ }
+ else if (ldap_field == "initials") {
+ userinfo.initials = vals[i]->bv_val;
+ }
+ else if (ldap_field == "title") {
+ userinfo.title = vals[i]->bv_val;
+ }
+ else if (ldap_field == "mail") {
+ userinfo.email = vals[i]->bv_val;
+ }
+ else if (ldap_field == "description") {
+ userinfo.description = vals[i]->bv_val;
+ }
+ else if (ldap_field == "l") {
+ userinfo.locality = vals[i]->bv_val;
+ }
+ else if (ldap_field == "telephoneNumber") {
+ userinfo.telephoneNumber = vals[i]->bv_val;
+ }
+ else if (ldap_field == "facsimileTelephoneNumber") {
+ userinfo.faxNumber = vals[i]->bv_val;
+ }
+ else if (ldap_field == "homePhone") {
+ userinfo.homePhone = vals[i]->bv_val;
+ }
+ else if (ldap_field == "mobile") {
+ userinfo.mobilePhone = vals[i]->bv_val;
+ }
+ else if (ldap_field == "pager") {
+ userinfo.pagerNumber = vals[i]->bv_val;
+ }
+ // FIXME
+ // This attribute is not present in my current LDAP schema
+ // userinfo.website = vals[i]->bv_val;
+ else if (ldap_field == "postOfficeBox") {
+ userinfo.poBox = vals[i]->bv_val;
+ }
+ else if (ldap_field == "street") {
+ userinfo.street = vals[i]->bv_val;
+ }
+ else if (ldap_field == "postalAddress") {
+ userinfo.address = vals[i]->bv_val;
+ }
+ else if (ldap_field == "st") {
+ userinfo.state = vals[i]->bv_val;
+ }
+ else if (ldap_field == "postalCode") {
+ userinfo.postcode = vals[i]->bv_val;
+ }
+ else if (ldap_field == "registeredAddress") {
+ userinfo.registeredAddress = vals[i]->bv_val;
+ }
+ else if (ldap_field == "homePostalAddress") {
+ userinfo.homeAddress = vals[i]->bv_val;
+ }
+ else if (ldap_field == "seeAlso") {
+ userinfo.seeAlso = vals[i]->bv_val;
+ }
+ else if (ldap_field == "physicalDeliveryOfficeName") {
+ userinfo.deliveryOffice = vals[i]->bv_val;
+ }
+ else if (ldap_field == "departmentNumber") {
+ userinfo.department = vals[i]->bv_val;
+ }
+ else if (ldap_field == "roomNumber") {
+ userinfo.roomNumber = vals[i]->bv_val;
+ }
+ else if (ldap_field == "employeeType") {
+ userinfo.employeeType = vals[i]->bv_val;
+ }
+ else if (ldap_field == "employeeNumber") {
+ userinfo.employeeNumber = vals[i]->bv_val;
+ }
+ // FIXME
+ // These two attributes are not present in my current LDAP schema
+// userinfo.manager = vals[i]->bv_val;
+// userinfo.secretary = vals[i]->bv_val;
+ else if (ldap_field == "internationaliSDNNumber") {
+ userinfo.isdnNumber = vals[i]->bv_val;
+ }
+ // FIXME
+ // This attribute is not present in my current LDAP schema
+// userinfo.teletexID = vals[i]->bv_val;
+ else if (ldap_field == "telexNumber") {
+ userinfo.telexNumber = vals[i]->bv_val;
+ }
+ // FIXME
+ // This attribute is not present in my current LDAP schema
+// userinfo.preferredDelivery = vals[i]->bv_val;
+ else if (ldap_field == "destinationIndicator") {
+ userinfo.destinationIndicator = vals[i]->bv_val;
+ }
+ else if (ldap_field == "x121Address") {
+ userinfo.x121Address = vals[i]->bv_val;
+ }
+ else if (ldap_field == "displayName") {
+ userinfo.displayName = vals[i]->bv_val;
+ }
+ else if (ldap_field == "preferredLanguage") {
+ userinfo.preferredLanguage = vals[i]->bv_val;
+ }
+ // FIXME
+ // This attribute is not present in my current LDAP schema
+// userinfo.uniqueIdentifier = vals[i]->bv_val;
+ else if (ldap_field == "preferredLanguage") {
+ userinfo.businessCategory = vals[i]->bv_val;
+ }
+ else if (ldap_field == "carLicense") {
+ userinfo.carLicense = vals[i]->bv_val;
+ }
+ // FIXME
+ // This attribute is not present in my current LDAP schema
+// userinfo.notes = vals[i]->bv_val;
+ ldap_value_free_len(vals);
+ }
+ ldap_memfree(attr);
+ }
+
+ if (ber != NULL) {
+ ber_free(ber, 0);
+ }
+
+ printf("\n\r");
+
+ return userinfo;
+}
+
LDAPUserInfoList LDAPManager::users() {
int retcode;
LDAPUserInfoList users;
@@ -203,235 +427,139 @@ printf("[RAJA DEBUG 100.1] In LDAPManager::users() bind was OK\n\r"); fflush(std
printf("[RAJA DEBUG 100.2] The number of entries returned was %d\n\n", ldap_count_entries(m_ldap, msg));
// Iterate through the returned entries
- char* dn = NULL;
- char* attr;
- struct berval **vals;
- BerElement* ber;
LDAPMessage* entry;
- int i;
for(entry = ldap_first_entry(m_ldap, msg); entry != NULL; entry = ldap_next_entry(m_ldap, entry)) {
- LDAPUserInfo userinfo;
-
- if((dn = ldap_get_dn(m_ldap, entry)) != NULL) {
- printf("Returned dn: %s\n", dn);
- userinfo.distinguishedName = dn;
- TQStringList dnParts = TQStringList::split(",", dn);
- TQString id = dnParts[0];
- if (id.startsWith("uid=")) {
- id = id.remove(0, 4);
- userinfo.name = id;
- }
- ldap_memfree(dn);
- }
+ users.append(parseLDAPUserRecord(entry));
+ }
+
+ // clean up
+ ldap_msgfree(msg);
- for( attr = ldap_first_attribute(m_ldap, entry, &ber); attr != NULL; attr = ldap_next_attribute(m_ldap, entry, ber)) {
- if ((vals = ldap_get_values_len(m_ldap, entry, attr)) != NULL) {
-printf("[RAJA DEBUG 100.3] %s: %s\n\r", attr, vals[i]->bv_val);
- userinfo.informationValid = true;
- TQString ldap_field = attr;
- i=0;
- if (ldap_field == "uidNumber") {
- userinfo.uid = atoi(vals[i]->bv_val);
- }
- else if (ldap_field == "loginShell") {
- userinfo.shell = vals[i]->bv_val;
- }
- else if (ldap_field == "homeDirectory") {
- userinfo.homedir = vals[i]->bv_val;
- }
- else if (ldap_field == "gidNumber") {
- userinfo.primary_gid = atoi(vals[i]->bv_val);
- }
- else if (ldap_field == "krb5KDCFlags") {
- userinfo.status = (LDAPKRB5Flags)(atoi(vals[i]->bv_val));
- }
- else if (ldap_field == "createTimestamp") { // YYYYMMDD000000Z
- TQString formattedDate = vals[i]->bv_val;
- formattedDate.insert(4,"-");
- formattedDate.insert(7,"-");
- formattedDate.insert(10,"T");
- formattedDate.insert(13,":");
- formattedDate.insert(16,":");
- formattedDate.remove(19, 1);
- userinfo.account_created = TQDateTime::fromString(formattedDate, TQt::ISODate);
- }
- else if (ldap_field == "modifyTimestamp") { // YYYYMMDD000000Z
- TQString formattedDate = vals[i]->bv_val;
- formattedDate.insert(4,"-");
- formattedDate.insert(7,"-");
- formattedDate.insert(10,"T");
- formattedDate.insert(13,":");
- formattedDate.insert(16,":");
- formattedDate.remove(19, 1);
- userinfo.account_modified = TQDateTime::fromString(formattedDate, TQt::ISODate);
- }
- // FIXME
- // These two attributes do not seem to be available with a Heimdal KDC
- // userinfo.password_last_changed = vals[i]->bv_val;
- // userinfo.password_expires = vals[i]->bv_val;
- else if (ldap_field == "krb5PasswordEnd") { // YYYYMMDD000000Z
- TQString formattedDate = vals[i]->bv_val;
- formattedDate.insert(4,"-");
- formattedDate.insert(7,"-");
- formattedDate.insert(10,"T");
- formattedDate.insert(13,":");
- formattedDate.insert(16,":");
- formattedDate.remove(19, 1);
- userinfo.password_expiration = TQDateTime::fromString(formattedDate, TQt::ISODate);
- }
- // FIXME
- // These six(!) attributes do not seem to be available with a Heimdal KDC
- // userinfo.password_ages = vals[i]->bv_val;
- // userinfo.new_password_interval = vals[i]->bv_val;
- // userinfo.new_password_warn_interval = vals[i]->bv_val;
- // userinfo.new_password_lockout_delay = vals[i]->bv_val;
- // userinfo.password_has_minimum_age = vals[i]->bv_val;
- // userinfo.password_minimum_age = vals[i]->bv_val;
- else if (ldap_field == "krb5MaxLife") { // units: hours
- userinfo.maximum_ticket_lifetime = atoi(vals[i]->bv_val);
- }
- else if (ldap_field == "cn") {
- userinfo.commonName = vals[i]->bv_val;
- }
- else if (ldap_field == "givenName") {
- userinfo.givenName = vals[i]->bv_val;
- }
- else if (ldap_field == "sn") {
- userinfo.surName = vals[i]->bv_val;
- }
- else if (ldap_field == "initials") {
- userinfo.initials = vals[i]->bv_val;
- }
- else if (ldap_field == "title") {
- userinfo.title = vals[i]->bv_val;
- }
- else if (ldap_field == "mail") {
- userinfo.email = vals[i]->bv_val;
- }
- else if (ldap_field == "description") {
- userinfo.description = vals[i]->bv_val;
- }
- else if (ldap_field == "l") {
- userinfo.locality = vals[i]->bv_val;
- }
- else if (ldap_field == "telephoneNumber") {
- userinfo.telephoneNumber = vals[i]->bv_val;
- }
- else if (ldap_field == "facsimileTelephoneNumber") {
- userinfo.faxNumber = vals[i]->bv_val;
- }
- else if (ldap_field == "homePhone") {
- userinfo.homePhone = vals[i]->bv_val;
- }
- else if (ldap_field == "mobile") {
- userinfo.mobilePhone = vals[i]->bv_val;
- }
- else if (ldap_field == "pager") {
- userinfo.pagerNumber = vals[i]->bv_val;
- }
- // FIXME
- // This attribute is not present in my current LDAP schema
- // userinfo.website = vals[i]->bv_val;
- else if (ldap_field == "postOfficeBox") {
- userinfo.poBox = vals[i]->bv_val;
- }
- else if (ldap_field == "street") {
- userinfo.street = vals[i]->bv_val;
- }
- else if (ldap_field == "postalAddress") {
- userinfo.address = vals[i]->bv_val;
- }
- else if (ldap_field == "st") {
- userinfo.state = vals[i]->bv_val;
- }
- else if (ldap_field == "postalCode") {
- userinfo.postcode = vals[i]->bv_val;
- }
- else if (ldap_field == "registeredAddress") {
- userinfo.registeredAddress = vals[i]->bv_val;
- }
- else if (ldap_field == "homePostalAddress") {
- userinfo.homeAddress = vals[i]->bv_val;
- }
- else if (ldap_field == "seeAlso") {
- userinfo.seeAlso = vals[i]->bv_val;
- }
- else if (ldap_field == "physicalDeliveryOfficeName") {
- userinfo.deliveryOffice = vals[i]->bv_val;
- }
- else if (ldap_field == "departmentNumber") {
- userinfo.department = vals[i]->bv_val;
- }
- else if (ldap_field == "roomNumber") {
- userinfo.roomNumber = vals[i]->bv_val;
- }
- else if (ldap_field == "employeeType") {
- userinfo.employeeType = vals[i]->bv_val;
- }
- else if (ldap_field == "employeeNumber") {
- userinfo.employeeNumber = vals[i]->bv_val;
- }
- // FIXME
- // These two attributes are not present in my current LDAP schema
-// userinfo.manager = vals[i]->bv_val;
-// userinfo.secretary = vals[i]->bv_val;
- else if (ldap_field == "internationaliSDNNumber") {
- userinfo.isdnNumber = vals[i]->bv_val;
- }
- // FIXME
- // This attribute is not present in my current LDAP schema
-// userinfo.teletexID = vals[i]->bv_val;
- else if (ldap_field == "telexNumber") {
- userinfo.telexNumber = vals[i]->bv_val;
- }
- // FIXME
- // This attribute is not present in my current LDAP schema
-// userinfo.preferredDelivery = vals[i]->bv_val;
- else if (ldap_field == "destinationIndicator") {
- userinfo.destinationIndicator = vals[i]->bv_val;
- }
- else if (ldap_field == "x121Address") {
- userinfo.x121Address = vals[i]->bv_val;
- }
- else if (ldap_field == "displayName") {
- userinfo.displayName = vals[i]->bv_val;
- }
- else if (ldap_field == "preferredLanguage") {
- userinfo.preferredLanguage = vals[i]->bv_val;
- }
- // FIXME
- // This attribute is not present in my current LDAP schema
-// userinfo.uniqueIdentifier = vals[i]->bv_val;
- else if (ldap_field == "preferredLanguage") {
- userinfo.businessCategory = vals[i]->bv_val;
- }
- else if (ldap_field == "carLicense") {
- userinfo.carLicense = vals[i]->bv_val;
- }
- // FIXME
- // This attribute is not present in my current LDAP schema
-// userinfo.notes = vals[i]->bv_val;
- ldap_value_free_len(vals);
- }
- ldap_memfree(attr);
- }
- users.append(userinfo);
+ return users;
+ }
- if (ber != NULL) {
- ber_free(ber, 0);
- }
+ return LDAPUserInfoList();
+}
- printf("\n\r");
+LDAPUserInfo LDAPManager::getUserByDistinguishedName(TQString dn) {
+ int retcode;
+ LDAPUserInfo userinfo;
+
+ if (bind() < 0) {
+ return LDAPUserInfo();
+ }
+ else {
+ LDAPMessage* msg;
+ struct timeval timeout;
+ timeout.tv_sec = 10; // 10 second timeout
+ retcode = ldap_search_ext_s(m_ldap, dn.ascii(), LDAP_SCOPE_SUBTREE, NULL, ldap_user_and_operational_attributes, 0, NULL, NULL, &timeout, 0, &msg);
+ if (retcode != LDAP_SUCCESS) {
+ KMessageBox::error(0, i18n("<qt>LDAP search failure<p>Reason: [%3] %4</qt>").arg(retcode).arg(ldap_err2string(retcode)), i18n("LDAP Error"));
+ return LDAPUserInfo();
+ }
+
+ // Iterate through the returned entries
+ LDAPMessage* entry;
+ for(entry = ldap_first_entry(m_ldap, msg); entry != NULL; entry = ldap_next_entry(m_ldap, entry)) {
+ userinfo = parseLDAPUserRecord(entry);
}
// clean up
ldap_msgfree(msg);
- // RAJA FIXME
- return users;
+ return userinfo;
}
- return LDAPUserInfoList();
+ return LDAPUserInfo();
+}
+
+LDAPGroupInfo LDAPManager::getGroupByDistinguishedName(TQString dn) {
+ int retcode;
+ LDAPGroupInfo groupinfo;
+
+ if (bind() < 0) {
+ return LDAPGroupInfo();
+ }
+ else {
+ LDAPMessage* msg;
+ struct timeval timeout;
+ timeout.tv_sec = 10; // 10 second timeout
+ retcode = ldap_search_ext_s(m_ldap, dn.ascii(), LDAP_SCOPE_SUBTREE, NULL, ldap_user_and_operational_attributes, 0, NULL, NULL, &timeout, 0, &msg);
+ if (retcode != LDAP_SUCCESS) {
+ KMessageBox::error(0, i18n("<qt>LDAP search failure<p>Reason: [%3] %4</qt>").arg(retcode).arg(ldap_err2string(retcode)), i18n("LDAP Error"));
+ return LDAPGroupInfo();
+ }
+
+ // Iterate through the returned entries
+ LDAPMessage* entry;
+ for(entry = ldap_first_entry(m_ldap, msg); entry != NULL; entry = ldap_next_entry(m_ldap, entry)) {
+ groupinfo = parseLDAPGroupRecord(entry);
+ }
+
+ // clean up
+ ldap_msgfree(msg);
+
+ return groupinfo;
+ }
+
+ return LDAPGroupInfo();
+}
+
+LDAPGroupInfo LDAPManager::parseLDAPGroupRecord(LDAPMessage* entry) {
+ char* dn = NULL;
+ char* attr;
+ struct berval **vals;
+ BerElement* ber;
+ int i;
+
+ LDAPGroupInfo groupinfo;
+
+ if((dn = ldap_get_dn(m_ldap, entry)) != NULL) {
+ printf("Returned dn: %s\n", dn);
+ groupinfo.distinguishedName = dn;
+ TQStringList dnParts = TQStringList::split(",", dn);
+ TQString id = dnParts[0];
+ if (id.startsWith("cn=")) {
+ id = id.remove(0, 3);
+ groupinfo.name = id;
+ }
+ ldap_memfree(dn);
+ }
+
+ for( attr = ldap_first_attribute(m_ldap, entry, &ber); attr != NULL; attr = ldap_next_attribute(m_ldap, entry, ber)) {
+ if ((vals = ldap_get_values_len(m_ldap, entry, attr)) != NULL) {
+for(i = 0; vals[i] != NULL; i++) {
+ printf("[RAJA DEBUG 110.3] %s: %s\n\r", attr, vals[i]->bv_val);
+}
+ groupinfo.informationValid = true;
+ TQString ldap_field = attr;
+ i=0;
+ if (ldap_field == "member") {
+ TQStringList members;
+ for(i = 0; vals[i] != NULL; i++) {
+ TQString userdn = vals[i]->bv_val;
+ if (userdn.startsWith("cn=placeholder,dc=")) {
+ continue;
+ }
+ members.append(userdn);
+ }
+ groupinfo.userlist = members;
+ }
+ else if (ldap_field == "gidNumber") {
+ groupinfo.gid = atoi(vals[i]->bv_val);
+ }
+ ldap_value_free_len(vals);
+ }
+ ldap_memfree(attr);
+ }
+
+ if (ber != NULL) {
+ ber_free(ber, 0);
+ }
+
+ printf("\n\r");
+
+ return groupinfo;
}
LDAPGroupInfoList LDAPManager::groups() {
@@ -458,69 +586,15 @@ printf("[RAJA DEBUG 110.1] In LDAPManager::groups() bind was OK\n\r"); fflush(st
printf("[RAJA DEBUG 110.2] The number of entries returned was %d\n\n", ldap_count_entries(m_ldap, msg));
// Iterate through the returned entries
- char* dn = NULL;
- char* attr;
- struct berval **vals;
- BerElement* ber;
LDAPMessage* entry;
- int i;
for(entry = ldap_first_entry(m_ldap, msg); entry != NULL; entry = ldap_next_entry(m_ldap, entry)) {
- LDAPGroupInfo groupinfo;
-
- if((dn = ldap_get_dn(m_ldap, entry)) != NULL) {
- printf("Returned dn: %s\n", dn);
- groupinfo.distinguishedName = dn;
- TQStringList dnParts = TQStringList::split(",", dn);
- TQString id = dnParts[0];
- if (id.startsWith("cn=")) {
- id = id.remove(0, 3);
- groupinfo.name = id;
- }
- else {
- continue;
- }
- ldap_memfree(dn);
- }
-
- for( attr = ldap_first_attribute(m_ldap, entry, &ber); attr != NULL; attr = ldap_next_attribute(m_ldap, entry, ber)) {
- if ((vals = ldap_get_values_len(m_ldap, entry, attr)) != NULL) {
-for(i = 0; vals[i] != NULL; i++) {
- printf("[RAJA DEBUG 110.3] %s: %s\n\r", attr, vals[i]->bv_val);
-}
- groupinfo.informationValid = true;
- TQString ldap_field = attr;
- i=0;
- if (ldap_field == "member") {
- TQStringList members;
- for(i = 0; vals[i] != NULL; i++) {
- TQString userdn = vals[i]->bv_val;
- if (userdn.startsWith("cn=placeholder,dc=")) {
- continue;
- }
- members.append(userdn);
- }
- groupinfo.userlist = members;
- }
- else if (ldap_field == "gidNumber") {
- groupinfo.gid = atoi(vals[i]->bv_val);
- }
- ldap_value_free_len(vals);
- }
- ldap_memfree(attr);
- }
- groups.append(groupinfo);
-
- if (ber != NULL) {
- ber_free(ber, 0);
- }
-
- printf("\n\r");
+ // RAJA
+ groups.append(parseLDAPGroupRecord(entry));
}
// clean up
ldap_msgfree(msg);
- // RAJA FIXME
return groups;
}
diff --git a/src/libtdeldap.h b/src/libtdeldap.h
index 2a06ae9..ee62b0e 100644
--- a/src/libtdeldap.h
+++ b/src/libtdeldap.h
@@ -173,6 +173,12 @@ class LDAPManager : public TQObject {
int unbind(bool force);
LDAPUserInfoList users();
LDAPGroupInfoList groups();
+ LDAPUserInfo getUserByDistinguishedName(TQString dn);
+ LDAPGroupInfo getGroupByDistinguishedName(TQString dn);
+
+ private:
+ LDAPUserInfo parseLDAPUserRecord(LDAPMessage* entry);
+ LDAPGroupInfo parseLDAPGroupRecord(LDAPMessage* entry);
private:
TQString m_realm;