summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/groupconfigdlg.cpp13
-rw-r--r--src/groupconfigdlg.h2
-rw-r--r--src/ldapmgr.cpp26
-rw-r--r--src/ldapmgr.h2
-rw-r--r--src/libtdeldap.cpp89
-rw-r--r--src/libtdeldap.h1
-rw-r--r--src/userconfigdlg.cpp3
-rw-r--r--src/userconfigdlg.h2
8 files changed, 136 insertions, 2 deletions
diff --git a/src/groupconfigdlg.cpp b/src/groupconfigdlg.cpp
index 8f7593e..94b70e4 100644
--- a/src/groupconfigdlg.cpp
+++ b/src/groupconfigdlg.cpp
@@ -72,6 +72,19 @@ GroupConfigDialog::GroupConfigDialog(LDAPGroupInfo group, LDAPConfig* parent, co
}
void GroupConfigDialog::slotOk() {
+ int i;
+
+ // Update data
+ m_group.gid = m_base->groupID->value();
+ TQStringList userlist;
+ for (i=0;i<m_base->selectedAccounts->count();i++) {
+ TQListBoxText* itm = dynamic_cast<TQListBoxText*>(m_base->selectedAccounts->item(i));
+ if (itm) {
+ userlist.append(m_ldapconfig->findUserInfoByName(itm->text()).distinguishedName);
+ }
+ }
+ m_group.userlist = userlist;
+
accept();
}
diff --git a/src/groupconfigdlg.h b/src/groupconfigdlg.h
index f85a2a2..dc51337 100644
--- a/src/groupconfigdlg.h
+++ b/src/groupconfigdlg.h
@@ -44,9 +44,9 @@ private slots:
public:
LDAPGroupConfigBase *m_base;
+ LDAPGroupInfo m_group;
private:
- LDAPGroupInfo m_group;
LDAPConfig* m_ldapconfig;
};
diff --git a/src/ldapmgr.cpp b/src/ldapmgr.cpp
index 5f2433c..ba45fd1 100644
--- a/src/ldapmgr.cpp
+++ b/src/ldapmgr.cpp
@@ -201,6 +201,30 @@ void LDAPConfig::updateGroupsList() {
processLockouts();
}
+LDAPUserInfo LDAPConfig::findUserInfoByName(TQString name) {
+ // Figure out which user is selected
+ LDAPUserInfoList::Iterator it;
+ for (it = m_userInfoList.begin(); it != m_userInfoList.end(); ++it) {
+ LDAPUserInfo user = *it;
+ if (user.name == name) {
+ return user;
+ }
+ }
+ return LDAPUserInfo();
+}
+
+LDAPGroupInfo LDAPConfig::findGroupInfoByName(TQString name) {
+ // Figure out which group is selected
+ LDAPGroupInfoList::Iterator it;
+ for (it = m_groupInfoList.begin(); it != m_groupInfoList.end(); ++it) {
+ LDAPGroupInfo group = *it;
+ if (group.name == name) {
+ return group;
+ }
+ }
+ return LDAPGroupInfo();
+}
+
LDAPUserInfo LDAPConfig::findUserInfoByNameAndUID(TQString name, TQString uid) {
// Figure out which user is selected
LDAPUserInfoList::Iterator it;
@@ -345,6 +369,8 @@ void LDAPConfig::modifySelectedGroup() {
group = m_ldapmanager->getGroupByDistinguishedName(group.distinguishedName);
GroupConfigDialog groupconfigdlg(group, this);
if (groupconfigdlg.exec() == TQDialog::Accepted) {
+ group = groupconfigdlg.m_group;
+ m_ldapmanager->updateGroupInfo(group);
// RAJA FIXME
}
updateAllInformation();
diff --git a/src/ldapmgr.h b/src/ldapmgr.h
index eed2b3e..8c7e594 100644
--- a/src/ldapmgr.h
+++ b/src/ldapmgr.h
@@ -64,6 +64,8 @@ class LDAPConfig: public KCModule
void updateAllInformation();
public:
+ LDAPUserInfo findUserInfoByName(TQString name);
+ LDAPGroupInfo findGroupInfoByName(TQString name);
LDAPUserInfo findUserInfoByNameAndUID(TQString name, TQString uid);
LDAPGroupInfo findGroupInfoByNameAndGID(TQString name, TQString gid);
LDAPGroupInfo findGroupInfoByGID(TQString gid);
diff --git a/src/libtdeldap.cpp b/src/libtdeldap.cpp
index 973e9ee..b8ce094 100644
--- a/src/libtdeldap.cpp
+++ b/src/libtdeldap.cpp
@@ -505,6 +505,95 @@ LDAPGroupInfo LDAPManager::getGroupByDistinguishedName(TQString dn) {
return LDAPGroupInfo();
}
+void add_single_attribute_operation(LDAPMod **mods, int *i, TQString attr, TQString value) {
+ mods[*i]->mod_op = LDAP_MOD_DELETE;
+ mods[*i]->mod_type = strdup(attr.ascii());
+ mods[*i]->mod_values = NULL;
+ (*i)++;
+
+ char **values = (char**)malloc(2*sizeof(char*));
+ values[0] = strdup(value.ascii());
+ values[1] = NULL;
+ mods[*i]->mod_op = LDAP_MOD_ADD;
+ mods[*i]->mod_type = strdup(attr.ascii());
+ mods[*i]->mod_values = values;
+ (*i)++;
+}
+
+void add_multiple_attributes_operation(LDAPMod **mods, int *i, TQString attr, TQStringList strings) {
+ mods[*i]->mod_op = LDAP_MOD_DELETE;
+ mods[*i]->mod_type = strdup(attr.ascii());
+ mods[*i]->mod_values = NULL;
+ (*i)++;
+
+ int j=0;
+ char **values = (char**)malloc((strings.count()+1)*sizeof(char*));
+ for ( TQStringList::Iterator it = strings.begin(); it != strings.end(); ++it ) {
+ values[j] = strdup((*it).ascii());
+ j++;
+ }
+ values[j] = NULL;
+ mods[*i]->mod_op = LDAP_MOD_ADD;
+ mods[*i]->mod_type = strdup(attr.ascii());
+ mods[*i]->mod_values = values;
+ (*i)++;
+}
+
+int LDAPManager::updateGroupInfo(LDAPGroupInfo group) {
+ int retcode;
+ int i;
+ LDAPGroupInfo groupinfo;
+
+ if (bind() < 0) {
+ return -1;
+ }
+ else {
+ // Assemble the LDAPMod structure
+ // We will replace attributes by first deleting them, then adding them back with their new values
+ int number_of_parameters = 2; // 2 primary attributes
+ number_of_parameters = (number_of_parameters * 2); // MODIFY/DELETE
+ LDAPMod *mods[number_of_parameters+1];
+ for (i=0;i<number_of_parameters;i++) {
+ mods[i] = new LDAPMod;
+ mods[i]->mod_type = NULL;
+ mods[i]->mod_values = NULL;
+ }
+ mods[number_of_parameters] = NULL;
+
+ // Load LDAP modification requests from provided data structure
+ i=0;
+ add_single_attribute_operation(mods, &i, "gidNumber", TQString("%1").arg(group.gid));
+ add_multiple_attributes_operation(mods, &i, "member", group.userlist);
+
+ // Perform LDAP update
+ retcode = ldap_modify_ext_s(m_ldap, group.distinguishedName.ascii(), mods, NULL, NULL);
+
+ // Clean up
+ for (i=0;i<number_of_parameters;i++) {
+ if (mods[i]->mod_type != NULL) {
+ free(mods[i]->mod_type);
+ }
+ if (mods[i]->mod_values != NULL) {
+ int j = 0;
+ while (mods[i]->mod_values[j] != NULL) {
+ free(mods[i]->mod_values[j]);
+ j++;
+ }
+ free(mods[i]->mod_values);
+ }
+ delete mods[i];
+ }
+
+ if (retcode != LDAP_SUCCESS) {
+ KMessageBox::error(0, i18n("<qt>LDAP modification failure<p>Reason: [%3] %4</qt>").arg(retcode).arg(ldap_err2string(retcode)), i18n("LDAP Error"));
+ return -2;
+ }
+ else {
+ return 0;
+ }
+ }
+}
+
LDAPGroupInfo LDAPManager::parseLDAPGroupRecord(LDAPMessage* entry) {
char* dn = NULL;
char* attr;
diff --git a/src/libtdeldap.h b/src/libtdeldap.h
index ee62b0e..7e7ae5d 100644
--- a/src/libtdeldap.h
+++ b/src/libtdeldap.h
@@ -175,6 +175,7 @@ class LDAPManager : public TQObject {
LDAPGroupInfoList groups();
LDAPUserInfo getUserByDistinguishedName(TQString dn);
LDAPGroupInfo getGroupByDistinguishedName(TQString dn);
+ int updateGroupInfo(LDAPGroupInfo group);
private:
LDAPUserInfo parseLDAPUserRecord(LDAPMessage* entry);
diff --git a/src/userconfigdlg.cpp b/src/userconfigdlg.cpp
index 48724fa..a2ad641 100644
--- a/src/userconfigdlg.cpp
+++ b/src/userconfigdlg.cpp
@@ -110,6 +110,9 @@ UserConfigDialog::UserConfigDialog(LDAPUserInfo user, LDAPConfig* parent, const
}
void UserConfigDialog::slotOk() {
+ // Update data
+ // RAJA FIXME
+
accept();
}
diff --git a/src/userconfigdlg.h b/src/userconfigdlg.h
index 909dd16..a900c0e 100644
--- a/src/userconfigdlg.h
+++ b/src/userconfigdlg.h
@@ -42,9 +42,9 @@ public slots:
public:
LDAPUserConfigBase *m_base;
+ LDAPUserInfo m_user;
private:
- LDAPUserInfo m_user;
LDAPConfig* m_ldapconfig;
TQString m_prevPrimaryGroup;
};