Add RO group editor

pull/1/head
Timothy Pearson 12 years ago
parent 5948ba909d
commit 68e6750572

@ -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)

@ -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">

@ -0,0 +1,106 @@
/***************************************************************************
* Copyright (C) 2012 by Timothy Pearson *
* kb9vqf@pearsoncomputing.net *
* *
* 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"

@ -0,0 +1,53 @@
/***************************************************************************
* Copyright (C) 2012 by Timothy Pearson *
* kb9vqf@pearsoncomputing.net *
* *
* 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_

@ -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() {

@ -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);

@ -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,37 +181,13 @@ int LDAPManager::unbind(bool force) {
return retcode;
}
LDAPUserInfoList LDAPManager::users() {
int retcode;
LDAPUserInfoList users;
printf("[RAJA DEBUG 100.0] In LDAPManager::users()\n\r"); fflush(stdout);
if (bind() < 0) {
return LDAPUserInfoList();
}
else {
printf("[RAJA DEBUG 100.1] In LDAPManager::users() bind was OK\n\r"); fflush(stdout);
LDAPMessage* msg;
TQString ldap_base_dn = m_basedc;
TQString ldap_filter = "(objectClass=posixAccount)";
struct timeval timeout;
timeout.tv_sec = 10; // 10 second timeout
retcode = ldap_search_ext_s(m_ldap, ldap_base_dn.ascii(), LDAP_SCOPE_SUBTREE, ldap_filter.ascii(), 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 LDAPUserInfoList();
}
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
LDAPUserInfo LDAPManager::parseLDAPUserRecord(LDAPMessage* entry) {
int i;
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) {
@ -415,56 +393,125 @@ printf("[RAJA DEBUG 100.3] %s: %s\n\r", attr, vals[i]->bv_val);
}
ldap_memfree(attr);
}
users.append(userinfo);
if (ber != NULL) {
ber_free(ber, 0);
}
printf("\n\r");
return userinfo;
}
LDAPUserInfoList LDAPManager::users() {
int retcode;
LDAPUserInfoList users;
printf("[RAJA DEBUG 100.0] In LDAPManager::users()\n\r"); fflush(stdout);
if (bind() < 0) {
return LDAPUserInfoList();
}
else {
printf("[RAJA DEBUG 100.1] In LDAPManager::users() bind was OK\n\r"); fflush(stdout);
LDAPMessage* msg;
TQString ldap_base_dn = m_basedc;
TQString ldap_filter = "(objectClass=posixAccount)";
struct timeval timeout;
timeout.tv_sec = 10; // 10 second timeout
retcode = ldap_search_ext_s(m_ldap, ldap_base_dn.ascii(), LDAP_SCOPE_SUBTREE, ldap_filter.ascii(), 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 LDAPUserInfoList();
}
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
LDAPMessage* entry;
for(entry = ldap_first_entry(m_ldap, msg); entry != NULL; entry = ldap_next_entry(m_ldap, entry)) {
users.append(parseLDAPUserRecord(entry));
}
// clean up
ldap_msgfree(msg);
// RAJA FIXME
return users;
}
return LDAPUserInfoList();
}
LDAPGroupInfoList LDAPManager::groups() {
LDAPUserInfo LDAPManager::getUserByDistinguishedName(TQString dn) {
int retcode;
LDAPGroupInfoList groups;
printf("[RAJA DEBUG 110.0] In LDAPManager::groups()\n\r"); fflush(stdout);
LDAPUserInfo userinfo;
if (bind() < 0) {
return LDAPGroupInfoList();
return LDAPUserInfo();
}
else {
printf("[RAJA DEBUG 110.1] In LDAPManager::groups() bind was OK\n\r"); fflush(stdout);
LDAPMessage* msg;
TQString ldap_base_dn = m_basedc;
TQString ldap_filter = "(objectClass=posixGroup)";
struct timeval timeout;
timeout.tv_sec = 10; // 10 second timeout
retcode = ldap_search_ext_s(m_ldap, ldap_base_dn.ascii(), LDAP_SCOPE_SUBTREE, ldap_filter.ascii(), ldap_user_and_operational_attributes, 0, NULL, NULL, &timeout, 0, &msg);
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 LDAPGroupInfoList();
return LDAPUserInfo();
}
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
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);
return userinfo;
}
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;
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) {
@ -476,9 +523,6 @@ printf("[RAJA DEBUG 110.2] The number of entries returned was %d\n\n", ldap_coun
id = id.remove(0, 3);
groupinfo.name = id;
}
else {
continue;
}
ldap_memfree(dn);
}
@ -508,19 +552,49 @@ for(i = 0; vals[i] != NULL; i++) {
}
ldap_memfree(attr);
}
groups.append(groupinfo);
if (ber != NULL) {
ber_free(ber, 0);
}
printf("\n\r");
return groupinfo;
}
LDAPGroupInfoList LDAPManager::groups() {
int retcode;
LDAPGroupInfoList groups;
printf("[RAJA DEBUG 110.0] In LDAPManager::groups()\n\r"); fflush(stdout);
if (bind() < 0) {
return LDAPGroupInfoList();
}
else {
printf("[RAJA DEBUG 110.1] In LDAPManager::groups() bind was OK\n\r"); fflush(stdout);
LDAPMessage* msg;
TQString ldap_base_dn = m_basedc;
TQString ldap_filter = "(objectClass=posixGroup)";
struct timeval timeout;
timeout.tv_sec = 10; // 10 second timeout
retcode = ldap_search_ext_s(m_ldap, ldap_base_dn.ascii(), LDAP_SCOPE_SUBTREE, ldap_filter.ascii(), 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 LDAPGroupInfoList();
}
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
LDAPMessage* entry;
for(entry = ldap_first_entry(m_ldap, msg); entry != NULL; entry = ldap_next_entry(m_ldap, entry)) {
// RAJA
groups.append(parseLDAPGroupRecord(entry));
}
// clean up
ldap_msgfree(msg);
// RAJA FIXME
return groups;
}

@ -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;

Loading…
Cancel
Save