diff --git a/cmdline/main.cpp b/cmdline/main.cpp index 65364b0..0650d4c 100644 --- a/cmdline/main.cpp +++ b/cmdline/main.cpp @@ -58,10 +58,12 @@ static const TDECmdLineOptions options[] = { "givenname ", I18N_NOOP("Sets the first name of the specified account to the given value"), 0 }, { "surname ", I18N_NOOP("Sets the last name of the specified account to the given value"), 0 }, { "group ", I18N_NOOP("Sets membership of the specified account in the groups listed on the command line, and revokes membership in any groups not listed. This option may be used multiple times."), 0 }, + { "primarygroup ", I18N_NOOP("Sets membership of the specified account in the group listed on the command line, and sets that group as the user's primary group."), 0 }, { "revokeallgroups", I18N_NOOP("Revokes membership of the specified account for all groups"), 0 }, { "adminusername ", I18N_NOOP("Specifies the username of the administrative user with permissions to perform the requested task"), 0 }, { "adminpasswordfile ", I18N_NOOP("Specifies the location of a file which contains the password of the administrative user"), 0 }, - { "!+command", I18N_NOOP("The command to execute on the Kerberos realm. Valid commands are: adduser deluser"), 0 }, + { "anonymous", I18N_NOOP("Do not use authentication when contacting the realm controller"), 0 }, + { "!+command", I18N_NOOP("The command to execute on the Kerberos realm. Valid commands are: adduser deluser listusers"), 0 }, { "!+realm", I18N_NOOP("The Kerberos realm on which to execute the specified command. Example: MY.REALM"), 0 }, { "", I18N_NOOP("This utility will use GSSAPI to connect to the realm controller. You must own an active, valid Kerberos ticket in order to use this utility!"), 0 }, TDECmdLineLastOption // End of options. @@ -103,20 +105,22 @@ int main(int argc, char *argv[]) systemconfig.setGroup("LDAPRealm-" + realm); TQString host = systemconfig.readEntry("admin_server"); LDAPCredentials credentials; - if (args->isSet("adminusername") && args->isSet("adminpasswordfile")) { - TQString passFileName = args->getOption("adminpasswordfile"); - TQFile passFile(passFileName); - if (!passFile.open(IO_ReadOnly)) { - printf("[ERROR] Unable to open specified password file '%s'\n\r", passFileName.ascii()); fflush(stdout); - return -1; + if (!args->isSet("anonymous")) { + if (args->isSet("adminusername") && args->isSet("adminpasswordfile")) { + TQString passFileName = args->getOption("adminpasswordfile"); + TQFile passFile(passFileName); + if (!passFile.open(IO_ReadOnly)) { + printf("[ERROR] Unable to open specified password file '%s'\n\r", passFileName.ascii()); fflush(stdout); + return -1; + } + TQTextStream stream(&passFile); + credentials.username = args->getOption("adminusername"); + credentials.password = stream.readLine(); + passFile.close(); + } + else { + credentials.use_gssapi = true; } - TQTextStream stream(&passFile); - credentials.username = args->getOption("adminusername"); - credentials.password = stream.readLine(); - passFile.close(); - } - else { - credentials.use_gssapi = true; } credentials.realm = realm; LDAPManager ldapmanager(realm, host, &credentials); @@ -174,6 +178,10 @@ int main(int argc, char *argv[]) printf("[ERROR] You must specify a surname when adding a user\n\r"); return -1; } + if (!args->isSet("primarygroup")) { + printf("[ERROR] You must specify a primary group when adding a user\n\r"); + return -1; + } // Get user data user.name = args->getOption("username"); @@ -214,7 +222,7 @@ int main(int argc, char *argv[]) if ((groupList.count() > 0) || revoke_all) { LDAPGroupInfoList groupInfoList = ldapmanager.groups(&retcode); if (retcode != 0) { - printf("[ERROR] Unable to retrieve list of users from realm controller\n\r"); + printf("[ERROR] Unable to retrieve list of groups from realm controller\n\r"); return -1; } LDAPGroupInfoList::Iterator it; @@ -235,6 +243,20 @@ int main(int argc, char *argv[]) } } } + bool primary_gid_found = false; + TQString primaryGroupName = args->getOption("primarygroup"); + for (it = groupInfoList.begin(); it != groupInfoList.end(); ++it) { + LDAPGroupInfo group = *it; + if (primaryGroupName == group.name) { + user.primary_gid = group.gid; + primary_gid_found = true; + break; + } + } + if (!primary_gid_found) { + printf("[ERROR] Invalid primary group specified\n\r"); + return -1; + } } if (user.new_password != "") { @@ -289,6 +311,25 @@ int main(int argc, char *argv[]) } // FIXME } + else if (command == "listusers") { + TQString errorString; + if (ldapmanager.bind(&errorString) != 0) { + printf("[ERROR] Unable to bind to Kerberos realm controller\n\r[ERROR] Detailed debugging information: %s\n\r", errorString.ascii()); + return -1; + } + + LDAPUserInfoList userInfoList = ldapmanager.users(&retcode); + if (retcode != 0) { + printf("[ERROR] Unable to retrieve list of users from realm controller\n\r"); + return -1; + } + + LDAPUserInfoList::Iterator it; + for (it = userInfoList.begin(); it != userInfoList.end(); ++it) { + LDAPUserInfo user = *it; + printf("%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n\r", user.uid, user.name.ascii(), user.commonName.ascii(), user.givenName.ascii(), user.initials.ascii(), user.surName.ascii(), user.shell.ascii(), user.homedir.ascii()); fflush(stdout); + } + } else { TDECmdLineArgs::usage(i18n("An invalid command was specified")); return -1; diff --git a/src/Makefile.am b/src/Makefile.am index 6f0e15e..3dd58bb 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 serviceconfigbase.ui userconfigdlg.cpp groupconfigdlg.cpp serviceconfigdlg.cpp +kcm_ldapmanager_la_SOURCES = ldapmgr.cpp ldapconfigbase.ui userconfigbase.ui groupconfigbase.ui machineconfigbase.ui serviceconfigbase.ui userconfigdlg.cpp groupconfigdlg.cpp machineconfigdlg.cpp serviceconfigdlg.cpp kcm_ldapmanager_la_LIBADD = -ltdeio $(LIB_TDEUI) -lldap -ltdeldap kcm_ldapmanager_la_LDFLAGS = -avoid-version -module -no-undefined \ $(all_libraries) diff --git a/src/groupconfigdlg.cpp b/src/groupconfigdlg.cpp index 38e2850..6898e2a 100644 --- a/src/groupconfigdlg.cpp +++ b/src/groupconfigdlg.cpp @@ -50,7 +50,7 @@ GroupConfigDialog::GroupConfigDialog(LDAPGroupInfo group, LDAPConfig* parent, co m_base->groupName->setEnabled(false); } - m_base->detailsIcon->setPixmap(SmallIcon("kdmconfig.png")); + m_base->detailsIcon->setPixmap(SmallIcon("tdmconfig.png")); connect(m_base->addToGroup, TQT_SIGNAL(clicked()), this, TQT_SLOT(addSelectedUserToGroup())); connect(m_base->removeFromGroup, TQT_SIGNAL(clicked()), this, TQT_SLOT(removeSelectedUserFromGroup())); diff --git a/src/ldapconfigbase.ui b/src/ldapconfigbase.ui index 0214857..d6ff638 100644 --- a/src/ldapconfigbase.ui +++ b/src/ldapconfigbase.ui @@ -429,13 +429,21 @@ Refresh - + groupGroupDetails Group Members + + + 5 + 5 + 1 + 1 + + unnamed diff --git a/src/ldapmgr.cpp b/src/ldapmgr.cpp index 5da7169..3d7e581 100644 --- a/src/ldapmgr.cpp +++ b/src/ldapmgr.cpp @@ -48,6 +48,7 @@ #include "ldappasswddlg.h" #include "userconfigdlg.h" #include "groupconfigdlg.h" +#include "machineconfigdlg.h" #include "serviceconfigdlg.h" // FIXME @@ -91,7 +92,7 @@ LDAPConfig::LDAPConfig(TQWidget *parent, const char *name, const TQStringList&) base->service_author->setEnabled(false); base->user_icon->setPixmap(SmallIcon("personal.png")); - base->group_icon->setPixmap(SmallIcon("kdmconfig.png")); + base->group_icon->setPixmap(SmallIcon("tdmconfig.png")); base->machine_icon->setPixmap(SmallIcon("system.png")); base->service_icon->setPixmap(SmallIcon("kcmsystem.png")); @@ -108,6 +109,7 @@ LDAPConfig::LDAPConfig(TQWidget *parent, const char *name, const TQStringList&) connect(base->user_buttonAdd, TQT_SIGNAL(clicked()), this, TQT_SLOT(addNewUser())); connect(base->group_buttonAdd, TQT_SIGNAL(clicked()), this, TQT_SLOT(addNewGroup())); + connect(base->machine_buttonAdd, TQT_SIGNAL(clicked()), this, TQT_SLOT(addNewMachine())); connect(base->service_buttonAdd, TQT_SIGNAL(clicked()), this, TQT_SLOT(addNewService())); connect(base->user_buttonModify, TQT_SIGNAL(clicked()), this, TQT_SLOT(modifySelectedUser())); connect(base->group_buttonModify, TQT_SIGNAL(clicked()), this, TQT_SLOT(modifySelectedGroup())); @@ -235,11 +237,9 @@ void LDAPConfig::processLockouts() { else { base->machine_buttonDelete->setEnabled(false); } + base->machine_buttonAdd->setEnabled(connected); // FIXME - // Disable machine add/modify as they are not implemented - // In fact, I don't know if I CAN implement them! - // Think about it...yes you can add the 'add' feature...kadmin 'ank --random-key host/HOSTNAME.FQDN'... - base->machine_buttonAdd->setEnabled(false); + // Disable machine modify as it is not yet implemented base->machine_buttonModify->setEnabled(false); base->machine_buttonRefresh->setEnabled(connected); @@ -777,6 +777,21 @@ void LDAPConfig::addNewGroup() { updateAllInformation(); } +void LDAPConfig::addNewMachine() { + // Launch a dialog to add the machine + LDAPMachineInfo machine; + + MachineConfigDialog machineconfigdlg(machine, m_ldapmanager->realm(), this); + if (machineconfigdlg.exec() == TQDialog::Accepted) { + machine = machineconfigdlg.m_machine; + TQString errorstring; + if (m_ldapmanager->addMachineInfo(machine, &errorstring) != 0) { + KMessageBox::error(0, i18n("Unable to add new machine!

%1").arg(errorstring), i18n("Internal Failure")); + } + } + updateAllInformation(); +} + void LDAPConfig::addNewService() { // Launch a dialog to add the service LDAPServiceInfo service; diff --git a/src/ldapmgr.h b/src/ldapmgr.h index bb3e407..48fe954 100644 --- a/src/ldapmgr.h +++ b/src/ldapmgr.h @@ -67,6 +67,7 @@ class LDAPConfig: public TDECModule void serviceHighlighted(); void addNewUser(); void addNewGroup(); + void addNewMachine(); void addNewService(); void modifySelectedUser(); void modifySelectedGroup(); diff --git a/src/machineconfigbase.ui b/src/machineconfigbase.ui new file mode 100644 index 0000000..bc05add --- /dev/null +++ b/src/machineconfigbase.ui @@ -0,0 +1,195 @@ + + LDAPMachineConfigBase + + + LDAPMachineConfigBase + + + + 0 + 0 + 519 + 356 + + + + + unnamed + + + + TabWidget2 + + + true + + + + detailsTab + + + Kerberos Machine + + + + unnamed + + + + unnamed_layoutwidget + + + + unnamed + + + + detailsIcon + + + + 4 + 5 + 1 + 0 + + + + + + unnamed + + + Machine Name + + + + + machineName + + + + + realmNameLabel + + + + + + + + + + unnamed_layoutwidget + + + + unnamed + + + + validBox + + + + 5 + 5 + 1 + 0 + + + + 0 + + + 0 + + + NoFrame + + + Plain + + + + + + true + + + true + + + + unnamed + + + + autoGeneratePassword + + + + + unnamed + + + Generate new random password + + + + + manuallySpecifyPassword + + + + + unnamed + + + Set specified password + + + + + specifiedPassword + + + true + + + + + Spacer2 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + + + + + + + + + LDAPMachineConfigBase.ui.h + + + kdialog.h + kpassdlg.h + + + + \ No newline at end of file diff --git a/src/machineconfigdlg.cpp b/src/machineconfigdlg.cpp new file mode 100644 index 0000000..37954be --- /dev/null +++ b/src/machineconfigdlg.cpp @@ -0,0 +1,99 @@ +/*************************************************************************** + * Copyright (C) 2013 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ldapmgr.h" +#include "machineconfigdlg.h" + +MachineConfigDialog::MachineConfigDialog(LDAPMachineInfo machine, TQString realmName, LDAPConfig* parent, const char* name) + : KDialogBase(parent, name, true, i18n("LDAP Machine Properties"), Ok|Cancel, Ok, true), m_machine(machine), m_ldapconfig(parent) +{ + m_base = new LDAPMachineConfigBase(this); + setMainWidget(m_base); + + m_base->detailsIcon->setPixmap(SmallIcon("system.png")); + + m_base->realmNameLabel->setText("."+realmName.lower()); + + connect(m_base->machineName, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(processLockouts())); + connect(m_base->specifiedPassword, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(processLockouts())); + connect(m_base->autoGeneratePassword, TQT_SIGNAL(clicked()), this, TQT_SLOT(processLockouts())); + connect(m_base->manuallySpecifyPassword, TQT_SIGNAL(clicked()), this, TQT_SLOT(manuallySpecifyPasswordClicked())); + + m_base->autoGeneratePassword->setChecked(true); + m_base->manuallySpecifyPassword->setChecked(false); + + m_base->machineName->setFocus(); + + processLockouts(); +} + +void MachineConfigDialog::slotOk() { + m_machine.name = m_base->machineName->text(); + if (m_base->autoGeneratePassword->isOn() == true) { + m_machine.newPassword = TQString(); + } + else if (m_base->manuallySpecifyPassword->isOn() == true) { + m_machine.newPassword = m_base->specifiedPassword->password(); + } + + accept(); +} + +void MachineConfigDialog::processLockouts() { + m_base->specifiedPassword->setEnabled(m_base->manuallySpecifyPassword->isOn()); + + if (((m_base->manuallySpecifyPassword->isOn() == true) && (strcmp(m_base->specifiedPassword->password(), "") == 0)) || (m_base->machineName->text() == "")) { + enableButton(KDialogBase::Ok, false); + } + else { + enableButton(KDialogBase::Ok, true); + } +} + +void MachineConfigDialog::manuallySpecifyPasswordClicked() { + processLockouts(); + + if (m_base->specifiedPassword->isEnabled()) { + m_base->specifiedPassword->setFocus(); + } +} + +LDAPMachineInfo MachineConfigDialog::machineProperties() { + return m_machine; +} + +#include "machineconfigdlg.moc" diff --git a/src/machineconfigdlg.h b/src/machineconfigdlg.h new file mode 100644 index 0000000..25f2554 --- /dev/null +++ b/src/machineconfigdlg.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2013 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 _MACHINECONFIGDIALOG_H_ +#define _MACHINECONFIGDIALOG_H_ + +#include + +#include "libtdeldap.h" +#include "machineconfigbase.h" + +class MachineConfigDialog : public KDialogBase +{ + Q_OBJECT + +public: + MachineConfigDialog(LDAPMachineInfo machine, TQString realmName, LDAPConfig* parent = 0, const char* name = 0); + LDAPMachineInfo machineProperties(); + +public slots: + void slotOk(); + void processLockouts(); + void manuallySpecifyPasswordClicked(); + +public: + LDAPMachineConfigBase *m_base; + LDAPMachineInfo m_machine; + +private: + LDAPConfig* m_ldapconfig; +}; + +#endif // _MACHINECONFIGDIALOG_H_ diff --git a/src/userconfigdlg.cpp b/src/userconfigdlg.cpp index 0eabcaa..8f23ed5 100644 --- a/src/userconfigdlg.cpp +++ b/src/userconfigdlg.cpp @@ -58,7 +58,7 @@ UserConfigDialog::UserConfigDialog(LDAPUserInfo user, LDAPConfig* parent, const m_base->enabledIcon->setPixmap(SmallIcon("decrypted.png")); m_base->disabledIcon->setPixmap(SmallIcon("encrypted.png")); m_base->userIcon->setPixmap(SmallIcon("personal.png")); - m_base->groupsIcon->setPixmap(SmallIcon("kdmconfig.png")); + m_base->groupsIcon->setPixmap(SmallIcon("tdmconfig.png")); m_base->passwordIcon->setPixmap(SmallIcon("password.png")); connect(m_base->loginName, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(processLockouts()));