diff --git a/Makefile b/Makefile index dac507949..ca2ecbc75 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ SUBDIRS=ipa-server ipa-admintools ipa-python ipa-client -PRJ_PREFIX=freeipa +PRJ_PREFIX=ipa RPMBUILD ?= $(PWD)/rpmbuild @@ -8,45 +8,47 @@ RPMBUILD ?= $(PWD)/rpmbuild # updating this you should run the version-update # target. SERV_MAJOR=0 -SERV_MINOR=4 -SERV_RELEASE=1 +SERV_MINOR=5 +SERV_RELEASE=0 SERV_VERSION=$(SERV_MAJOR).$(SERV_MINOR).$(SERV_RELEASE) SERV_TARBALL_PREFIX=$(PRJ_PREFIX)-server-$(SERV_VERSION) SERV_TARBALL=$(SERV_TARBALL_PREFIX).tgz ADMIN_MAJOR=0 -ADMIN_MINOR=4 -ADMIN_RELEASE=1 +ADMIN_MINOR=5 +ADMIN_RELEASE=0 ADMIN_VERSION=$(ADMIN_MAJOR).$(ADMIN_MINOR).$(ADMIN_RELEASE) ADMIN_TARBALL_PREFIX=$(PRJ_PREFIX)-admintools-$(ADMIN_VERSION) ADMIN_TARBALL=$(ADMIN_TARBALL_PREFIX).tgz PYTHON_MAJOR=0 -PYTHON_MINOR=4 -PYTHON_RELEASE=1 +PYTHON_MINOR=5 +PYTHON_RELEASE=0 PYTHON_VERSION=$(PYTHON_MAJOR).$(PYTHON_MINOR).$(PYTHON_RELEASE) PYTHON_TARBALL_PREFIX=$(PRJ_PREFIX)-python-$(PYTHON_VERSION) PYTHON_TARBALL=$(PYTHON_TARBALL_PREFIX).tgz CLI_MAJOR=0 -CLI_MINOR=3 -CLI_RELEASE=1 +CLI_MINOR=5 +CLI_RELEASE=0 CLI_VERSION=$(CLI_MAJOR).$(CLI_MINOR).$(CLI_RELEASE) CLI_TARBALL_PREFIX=$(PRJ_PREFIX)-client-$(CLI_VERSION) CLI_TARBALL=$(CLI_TARBALL_PREFIX).tgz +LIBDIR ?= /usr/lib + all: bootstrap-autogen @for subdir in $(SUBDIRS); do \ (cd $$subdir && $(MAKE) $@) || exit 1; \ done bootstrap-autogen: - cd ipa-server; if [ ! -e Makefile ]; then ./autogen.sh --prefix=/usr --sysconfdir=/etc; fi - cd ipa-client; if [ ! -e Makefile ]; then ./autogen.sh --prefix=/usr --sysconfdir=/etc; fi + cd ipa-server; if [ ! -e Makefile ]; then ./autogen.sh --prefix=/usr --sysconfdir=/etc --libdir=$(LIBDIR); fi + cd ipa-client; if [ ! -e Makefile ]; then ./autogen.sh --prefix=/usr --sysconfdir=/etc --libdir=$(LIBDIR); fi autogen: - cd ipa-server; ./autogen.sh --prefix=/usr --sysconfdir=/etc; - cd ipa-client; ./autogen.sh --prefix=/usr --sysconfdir=/etc; + cd ipa-server; ./autogen.sh --prefix=/usr --sysconfdir=/etc --libdir=$(LIBDIR) + cd ipa-client; ./autogen.sh --prefix=/usr --sysconfdir=/etc --libdir=$(LIBDIR) configure: cd ipa-server; ./configure --prefix=/usr --sysconfdir=/etc @@ -63,56 +65,56 @@ test: done version-update: - sed s/VERSION/$(SERV_VERSION)/ ipa-server/freeipa-server.spec.in \ - > ipa-server/freeipa-server.spec + sed s/VERSION/$(SERV_VERSION)/ ipa-server/ipa-server.spec.in \ + > ipa-server/ipa-server.spec - sed s/VERSION/$(ADMIN_VERSION)/ ipa-admintools/freeipa-admintools.spec.in \ - > ipa-admintools/freeipa-admintools.spec + sed s/VERSION/$(ADMIN_VERSION)/ ipa-admintools/ipa-admintools.spec.in \ + > ipa-admintools/ipa-admintools.spec - sed s/VERSION/$(PYTHON_VERSION)/ ipa-python/freeipa-python.spec.in \ - > ipa-python/freeipa-python.spec + sed s/VERSION/$(PYTHON_VERSION)/ ipa-python/ipa-python.spec.in \ + > ipa-python/ipa-python.spec - sed s/VERSION/$(CLI_VERSION)/ ipa-client/freeipa-client.spec.in \ - > ipa-client/freeipa-client.spec + sed s/VERSION/$(CLI_VERSION)/ ipa-client/ipa-client.spec.in \ + > ipa-client/ipa-client.spec archive: -mkdir -p dist - hg archive -t files dist/freeipa + hg archive -t files dist/ipa local-archive: - -mkdir -p dist/freeipa + -mkdir -p dist/ipa @for subdir in $(SUBDIRS); do \ - cp -pr $$subdir dist/freeipa/.; \ + cp -pr $$subdir dist/ipa/.; \ done archive-cleanup: - rm -fr dist/freeipa + rm -fr dist/ipa tarballs: -mkdir -p dist/sources # ipa-server - mv dist/freeipa/ipa-server dist/$(SERV_TARBALL_PREFIX) + mv dist/ipa/ipa-server dist/$(SERV_TARBALL_PREFIX) rm -f dist/sources/$(SERV_TARBALL) cd dist/$(SERV_TARBALL_PREFIX); ./autogen.sh; make distclean cd dist; tar cfz sources/$(SERV_TARBALL) $(SERV_TARBALL_PREFIX) rm -fr dist/$(SERV_TARBALL_PREFIX) # ipa-admintools - mv dist/freeipa/ipa-admintools dist/$(ADMIN_TARBALL_PREFIX) + mv dist/ipa/ipa-admintools dist/$(ADMIN_TARBALL_PREFIX) rm -f dist/sources/$(ADMIN_TARBALL) cd dist; tar cfz sources/$(ADMIN_TARBALL) $(ADMIN_TARBALL_PREFIX) rm -fr dist/$(ADMIN_TARBALL_PREFIX) # ipa-python - mv dist/freeipa/ipa-python dist/$(PYTHON_TARBALL_PREFIX) + mv dist/ipa/ipa-python dist/$(PYTHON_TARBALL_PREFIX) rm -f dist/sources/$(PYTHON_TARBALL) cd dist; tar cfz sources/$(PYTHON_TARBALL) $(PYTHON_TARBALL_PREFIX) rm -fr dist/$(PYTHON_TARBALL_PREFIX) # ipa-client - mv dist/freeipa/ipa-client dist/$(CLI_TARBALL_PREFIX) + mv dist/ipa/ipa-client dist/$(CLI_TARBALL_PREFIX) rm -f dist/sources/$(CLI_TARBALL) cd dist/$(CLI_TARBALL_PREFIX); ./autogen.sh; make distclean cd dist; tar cfz sources/$(CLI_TARBALL) $(CLI_TARBALL_PREFIX) @@ -131,25 +133,25 @@ rpmdistdir: rpm-ipa-server: cp dist/sources/$(SERV_TARBALL) $(RPMBUILD)/SOURCES/. - rpmbuild --define "_topdir $(RPMBUILD)" -ba ipa-server/freeipa-server.spec + rpmbuild --define "_topdir $(RPMBUILD)" -ba ipa-server/ipa-server.spec cp rpmbuild/RPMS/*/$(PRJ_PREFIX)-server-$(SERV_VERSION)-*.rpm dist/rpms/ cp rpmbuild/SRPMS/$(PRJ_PREFIX)-server-$(SERV_VERSION)-*.src.rpm dist/srpms/ rpm-ipa-admin: cp dist/sources/$(ADMIN_TARBALL) $(RPMBUILD)/SOURCES/. - rpmbuild --define "_topdir $(RPMBUILD)" -ba ipa-admintools/freeipa-admintools.spec + rpmbuild --define "_topdir $(RPMBUILD)" -ba ipa-admintools/ipa-admintools.spec cp rpmbuild/RPMS/noarch/$(PRJ_PREFIX)-admintools-$(ADMIN_VERSION)-*.rpm dist/rpms/ cp rpmbuild/SRPMS/$(PRJ_PREFIX)-admintools-$(ADMIN_VERSION)-*.src.rpm dist/srpms/ rpm-ipa-python: cp dist/sources/$(PYTHON_TARBALL) $(RPMBUILD)/SOURCES/. - rpmbuild --define "_topdir $(RPMBUILD)" -ba ipa-python/freeipa-python.spec + rpmbuild --define "_topdir $(RPMBUILD)" -ba ipa-python/ipa-python.spec cp rpmbuild/RPMS/noarch/$(PRJ_PREFIX)-python-$(PYTHON_VERSION)-*.rpm dist/rpms/ cp rpmbuild/SRPMS/$(PRJ_PREFIX)-python-$(PYTHON_VERSION)-*.src.rpm dist/srpms/ rpm-ipa-client: cp dist/sources/$(CLI_TARBALL) $(RPMBUILD)/SOURCES/. - rpmbuild --define "_topdir $(RPMBUILD)" -ba ipa-client/freeipa-client.spec + rpmbuild --define "_topdir $(RPMBUILD)" -ba ipa-client/ipa-client.spec cp rpmbuild/RPMS/*/$(PRJ_PREFIX)-client-$(CLI_VERSION)-*.rpm dist/rpms/ cp rpmbuild/SRPMS/$(PRJ_PREFIX)-client-$(CLI_VERSION)-*.src.rpm dist/srpms/ diff --git a/ipa-admintools/Makefile b/ipa-admintools/Makefile index 5ceb42d27..6601292ed 100644 --- a/ipa-admintools/Makefile +++ b/ipa-admintools/Makefile @@ -21,6 +21,7 @@ install: install -m 755 ipa-deldelegation $(SBINDIR) install -m 755 ipa-listdelegation $(SBINDIR) install -m 755 ipa-moddelegation $(SBINDIR) + install -m 755 ipa-getkeytab $(SBINDIR) install -m 755 ipa-addradiusclient $(SBINDIR) install -m 755 ipa-radiusclientmod $(SBINDIR) install -m 755 ipa-delradiusclient $(SBINDIR) diff --git a/ipa-admintools/ipa-adddelegation b/ipa-admintools/ipa-adddelegation index 8dde908f0..53bd43ce2 100644 --- a/ipa-admintools/ipa-adddelegation +++ b/ipa-admintools/ipa-adddelegation @@ -31,6 +31,7 @@ import xmlrpclib import kerberos import krbV import ldap +import errno def usage(): print "ipa-adddelgation [-a|--attributes attr1,attr2,..,attrn] [-s|--source STRING] [-t|--target STRING] name" @@ -90,12 +91,34 @@ def main(): new_aci.dest_group = target_grp[1].dn new_aci.attrs = attr_list + aci_entry = client.get_aci_entry(['*', 'aci']) + + # Look for an existing ACI of the same name + aci_str_list = aci_entry.getValues('aci') + if aci_str_list is None: + aci_str_list = [] + if not(isinstance(aci_str_list,list) or isinstance(aci_str_list,tuple)): + aci_str_list = [aci_str_list] + + for aci_str in aci_str_list: + try: + old_aci = ipa.aci.ACI(aci_str) + if old_aci.name == new_aci.name: + print "A delegation of that name already exists" + return 2 + except SyntaxError: + # ignore aci_str's that ACI can't parse + pass + aci_entry = client.get_aci_entry(['dn']) aci_entry.setValue('aci', new_aci.export_to_string()) client.update_entry(aci_entry) - except xmlrpclib.Fault, f: - print f.faultString + except xmlrpclib.Fault, fault: + if fault.faultCode == errno.ECONNREFUSED: + print "The IPA XML-RPC service is not responding." + else: + print fault.faultString return 1 except kerberos.GSSError, e: print "Could not initialize GSSAPI: %s/%s" % (e[0][0][0], e[0][1][0]) diff --git a/ipa-admintools/ipa-addgroup b/ipa-admintools/ipa-addgroup index 97dfd5f7b..15d42a91e 100644 --- a/ipa-admintools/ipa-addgroup +++ b/ipa-admintools/ipa-addgroup @@ -30,6 +30,7 @@ import ipa.ipaerror import xmlrpclib import kerberos import ldap +import errno def usage(): print "ipa-addgroup [-d|--description STRING] group" @@ -95,8 +96,11 @@ def main(): client = ipaclient.IPAClient() client.add_group(group) print cn + " successfully added" - except xmlrpclib.Fault, f: - print f.faultString + except xmlrpclib.Fault, fault: + if fault.faultCode == errno.ECONNREFUSED: + print "The IPA XML-RPC service is not responding." + else: + print fault.faultString return 1 except kerberos.GSSError, e: print "Could not initialize GSSAPI: %s/%s" % (e[0][0][0], e[0][1][0]) diff --git a/ipa-admintools/ipa-adduser b/ipa-admintools/ipa-adduser index d82de8955..e993bee5e 100644 --- a/ipa-admintools/ipa-adduser +++ b/ipa-admintools/ipa-adduser @@ -31,6 +31,7 @@ import kerberos import krbV import ldap import getpass +import errno def usage(): print "ipa-adduser [-c|--gecos STRING] [-d|--directory STRING] [-f|--firstname STRING] [-l|--lastname STRING] user" @@ -204,14 +205,15 @@ def main(): user.setValue('homedirectory', directory) if shell: user.setValue('loginshell', shell) - else: - user.setValue('loginshell', "/bin/sh") try: client = ipaclient.IPAClient() client.add_user(user) - except xmlrpclib.Fault, f: - print f.faultString + except xmlrpclib.Fault, fault: + if fault.faultCode == errno.ECONNREFUSED: + print "The IPA XML-RPC service is not responding." + else: + print fault.faultString return 1 except kerberos.GSSError, e: print "Could not initialize GSSAPI: %s/%s" % (e[0][0][0], e[0][1][0]) diff --git a/ipa-admintools/freeipa-admintools.spec b/ipa-admintools/ipa-admintools.spec similarity index 81% rename from ipa-admintools/freeipa-admintools.spec rename to ipa-admintools/ipa-admintools.spec index 6fd423a0b..24c83e6cd 100755 --- a/ipa-admintools/freeipa-admintools.spec +++ b/ipa-admintools/ipa-admintools.spec @@ -1,7 +1,7 @@ -Name: freeipa-admintools -Version: 0.4.1 +Name: ipa-admintools +Version: 0.5.0 Release: 1%{?dist} -Summary: FreeIPA authentication server +Summary: IPA authentication server Group: System Environment/Base License: GPL @@ -10,10 +10,10 @@ Source0: %{name}-%{version}.tgz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildArch: noarch -Requires: python python-krbV freeipa-python +Requires: python python-krbV ipa-python %description -FreeIPA is a server for identity, policy, and audit. +IPA is a server for identity, policy, and audit. %prep %setup -q @@ -35,6 +35,9 @@ rm -rf %{buildroot} %{_mandir}/man1/* %changelog +* Wed Nov 21 2007 Karl MacMillan - 0.5.0-1 +- Version bump for release and rpm name change + * Thu Nov 1 2007 Karl MacMillan - 0.4.1-1 - Version bump for release diff --git a/ipa-admintools/freeipa-admintools.spec.in b/ipa-admintools/ipa-admintools.spec.in similarity index 82% rename from ipa-admintools/freeipa-admintools.spec.in rename to ipa-admintools/ipa-admintools.spec.in index ec731a645..4b444882e 100755 --- a/ipa-admintools/freeipa-admintools.spec.in +++ b/ipa-admintools/ipa-admintools.spec.in @@ -1,7 +1,7 @@ -Name: freeipa-admintools +Name: ipa-admintools Version: VERSION Release: 1%{?dist} -Summary: FreeIPA authentication server +Summary: IPA authentication server Group: System Environment/Base License: GPL @@ -10,10 +10,10 @@ Source0: %{name}-%{version}.tgz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildArch: noarch -Requires: python python-krbV freeipa-python +Requires: python python-krbV ipa-python %description -FreeIPA is a server for identity, policy, and audit. +IPA is a server for identity, policy, and audit. %prep %setup -q @@ -35,6 +35,9 @@ rm -rf %{buildroot} %{_mandir}/man1/* %changelog +* Wed Nov 21 2007 Karl MacMillan - 0.5.0-1 +- Version bump for release and rpm name change + * Thu Nov 1 2007 Karl MacMillan - 0.4.1-1 - Version bump for release diff --git a/ipa-admintools/ipa-deldelegation b/ipa-admintools/ipa-deldelegation index 93e39548a..7ad17c38b 100644 --- a/ipa-admintools/ipa-deldelegation +++ b/ipa-admintools/ipa-deldelegation @@ -26,6 +26,7 @@ import ipa.config import xmlrpclib import kerberos import copy +import errno import ipa.aci from ipa import ipaerror @@ -85,12 +86,24 @@ def main(): aci_entry.setValue('aci', new_aci_str_list) client.update_entry(aci_entry) + except xmlrpclib.Fault, fault: + if fault.faultCode == errno.ECONNREFUSED: + print "The IPA XML-RPC service is not responding." + else: + print fault.faultString + return 1 except (SyntaxError, ipaerror.IPAError), e: print "Delegation deletion failed: " + str(e) return 1 except kerberos.GSSError, e: print "Could not initialize GSSAPI: %s/%s" % (e[0][0][0], e[0][1][0]) return 1 + except xmlrpclib.ProtocolError, e: + print "Unable to connect to IPA server: %s" % (e.errmsg) + return 1 + except ipa.ipaerror.IPAError, e: + print "%s" % (e.message) + return 1 return 0 diff --git a/ipa-admintools/ipa-delgroup b/ipa-admintools/ipa-delgroup index 08ea73771..b4f946065 100644 --- a/ipa-admintools/ipa-delgroup +++ b/ipa-admintools/ipa-delgroup @@ -23,6 +23,7 @@ from optparse import OptionParser import ipa import ipa.ipaclient as ipaclient import ipa.config +import errno import xmlrpclib import kerberos @@ -54,8 +55,11 @@ def main(): print args[1] + " successfully deleted" else: print args[1] + " " + ret - except xmlrpclib.Fault, f: - print f.faultString + except xmlrpclib.Fault, fault: + if fault.faultCode == errno.ECONNREFUSED: + print "The IPA XML-RPC service is not responding." + else: + print fault.faultString return 1 except kerberos.GSSError, e: print "Could not initialize GSSAPI: %s/%s" % (e[0][0][0], e[0][1][0]) diff --git a/ipa-admintools/ipa-deluser b/ipa-admintools/ipa-deluser index 18adf75c0..02ba5f132 100644 --- a/ipa-admintools/ipa-deluser +++ b/ipa-admintools/ipa-deluser @@ -23,6 +23,7 @@ from optparse import OptionParser import ipa import ipa.ipaclient as ipaclient import ipa.config +import errno import xmlrpclib import kerberos @@ -33,6 +34,8 @@ def usage(): def parse_options(): parser = OptionParser() + parser.add_option("-d", "--delete", action="store_true", dest="deluser", + help="Delete the user, don't inactivate them.") parser.add_option("--usage", action="store_true", help="Program usage") @@ -47,15 +50,26 @@ def main(): if len(args) != 2: usage() + msg = "inactivated" try: client = ipaclient.IPAClient() - ret = client.mark_user_deleted(args[1]) - if (ret == "Success"): - print args[1] + " successfully deleted" + if options.deluser: + ret = client.delete_user(args[1]) + msg = "deleted" else: - print args[1] + " " + ret - except xmlrpclib.Fault, f: - print f.faultString + try: + ret = client.mark_user_inactive(args[1]) + except ipa.ipaerror.exception_for(ipa.ipaerror.LDAP_EMPTY_MODLIST): + print "User is already marked inactive" + return 0 + except: + raise + print args[1] + " successfully %s" % msg + except xmlrpclib.Fault, fault: + if fault.faultCode == errno.ECONNREFUSED: + print "The IPA XML-RPC service is not responding." + else: + print fault.faultString return 1 except kerberos.GSSError, e: print "Could not initialize GSSAPI: %s/%s" % (e[0][0][0], e[0][1][0]) diff --git a/ipa-admintools/ipa-findgroup b/ipa-admintools/ipa-findgroup index a876a0505..9f809aa0b 100644 --- a/ipa-admintools/ipa-findgroup +++ b/ipa-admintools/ipa-findgroup @@ -23,6 +23,7 @@ from optparse import OptionParser import ipa.ipaclient as ipaclient import ipa.config +import errno import sys import xmlrpclib import kerberos @@ -34,6 +35,12 @@ def usage(): def parse_options(): parser = OptionParser() + parser.add_option("-a", "--all", action="store_true", dest="all", + help="Show all group attributes") + parser.add_option("-n", "--notranslate", action="store_true", + dest="notranslate", + help="Don't translate LDAP attributes into readable labels") + args = ipa.config.init_config(sys.argv) options, args = parser.parse_args(args) @@ -48,7 +55,10 @@ def main(): try: client = ipaclient.IPAClient() - groups = client.find_groups(args[1], ['cn','description','gidnumber']) + if options.all is None: + groups = client.find_groups(args[1], ['cn','description','gidnumber','nsAccountLock']) + else: + groups = client.find_groups(args[1], sattrs=['*','nsAccountLock']) counter = groups[0] groups = groups[1:] @@ -64,15 +74,21 @@ def main(): print str(e) continue attr = ent.attrList() + if options.notranslate: + labels = {} + for a in attr: + labels[a] = a + else: + labels = client.attrs_to_labels(attr) print "dn: " + ent.dn for a in attr: value = ent.getValues(a) if isinstance(value,str): - print a + ": " + value + print labels[a] + ": " + value else: - print a + ": " + print labels[a] + ": " for l in value: print "\t" + l @@ -87,7 +103,10 @@ def main(): print except xmlrpclib.Fault, fault: - print fault.faultString + if fault.faultCode == errno.ECONNREFUSED: + print "The IPA XML-RPC service is not responding." + else: + print fault.faultString return 1 except kerberos.GSSError, e: print "Could not initialize GSSAPI: %s/%s" % (e[0][0][0], e[0][1][0]) diff --git a/ipa-admintools/ipa-finduser b/ipa-admintools/ipa-finduser index 3396ce45d..6dc4d56c8 100644 --- a/ipa-admintools/ipa-finduser +++ b/ipa-admintools/ipa-finduser @@ -25,6 +25,7 @@ import ipa.config import ipa.ipautil as ipautil import base64 +import errno import sys import xmlrpclib import kerberos @@ -38,6 +39,9 @@ def parse_options(): parser.add_option("-a", "--all", action="store_true", dest="all", help="Set user's e-mail address") + parser.add_option("-n", "--notranslate", action="store_true", + dest="notranslate", + help="Don't translate LDAP attributes into readable labels") parser.add_option("--usage", action="store_true", help="Program usage") @@ -90,6 +94,12 @@ def main(): for ent in users: attr = ent.attrList() attr.sort() + if options.notranslate: + labels = {} + for a in attr: + labels[a] = a + else: + labels = client.attrs_to_labels(attr) if options.all is True: print "dn: " + ent.dn @@ -97,16 +107,19 @@ def main(): for a in attr: value = ent.getValues(a) if isinstance(value,str): - print a + ": " + str(wrap_binary_data(value)).rstrip() + print labels[a] + ": " + str(wrap_binary_data(value)).rstrip() else: - print a + ": " + print labels[a] + ": " for l in value: print "\t" + wrap_binary_data(l) # blank line between results print except xmlrpclib.Fault, fault: - print fault.faultString + if fault.faultCode == errno.ECONNREFUSED: + print "The IPA XML-RPC service is not responding." + else: + print fault.faultString return 1 except kerberos.GSSError, e: print "Could not initialize GSSAPI: %s/%s" % (e[0][0][0], e[0][1][0]) diff --git a/ipa-admintools/ipa-getkeytab b/ipa-admintools/ipa-getkeytab new file mode 100644 index 000000000..5ecb7e4a6 --- /dev/null +++ b/ipa-admintools/ipa-getkeytab @@ -0,0 +1,83 @@ +#! /usr/bin/python -E +# Authors: Karl MacMillan +# +# Copyright (C) 2007 Red Hat +# see file 'COPYING' for use and warranty information +# +# 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; version 2 only +# +# 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 +# + +import sys +from optparse import OptionParser +import ipa +import ipa.user +import ipa.ipaclient as ipaclient +import ipa.ipavalidate as ipavalidate +import ipa.config + +import base64 + +import xmlrpclib +import kerberos +import krbV +import ldap +import getpass +import errno + +def usage(): + print "ipa-getkeytab [-a] principal filename" + sys.exit(1) + +def parse_options(): + parser = OptionParser() + parser.add_option("-a", "--add", dest="add_princ", action="store_true", + help="add the principal") + + args = ipa.config.init_config(sys.argv) + options, args = parser.parse_args(args) + + return options, args + +def main(): + # The following fields are required + princ_name = "" + + options, args = parse_options() + + if len(args) != 3: + usage() + princ_name = args[1] + file_name = args[2] + + client = ipaclient.IPAClient() + + try: + if options.add_princ: + client.add_service_principal(princ_name) + + princs = client.get_keytab(princ_name) + + if princs is None: + print "could not generate keytab" + sys.exit(1) + + fd = open(file_name, "w") + fd.write(princs) + + except Exception, e: + print str(e) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/ipa-admintools/ipa-groupmod b/ipa-admintools/ipa-groupmod index 4d8dd4d5e..c7e6e1fa0 100644 --- a/ipa-admintools/ipa-groupmod +++ b/ipa-admintools/ipa-groupmod @@ -29,12 +29,16 @@ import ipa.ipaerror import xmlrpclib import kerberos import ldap +import errno def usage(): - print "ipa-groupmod [-a] [-r] user group" - print "ipa-groupmod [-d|--desc description STRING] group" + print "ipa-groupmod [-a|--add] [-r|--remove] user group" + print "ipa-groupmod [-d|--desc description STRING] [--addattr attribute=value] [--delattr attribute] [--setattr attribute=value] group" sys.exit(1) +def set_add_usage(which): + print "%s option usage: --%s NAME=VALUE" % (which, which) + def parse_options(): parser = OptionParser() parser.add_option("-a", "--add", dest="add", action="store_true", @@ -43,20 +47,38 @@ def parse_options(): help="Remove a user from the group") parser.add_option("-d", "--description", dest="desc", help="Modify the description of the group") + parser.add_option("--addattr", dest="addattr", + help="Adds an attribute or values to that attribute, attr=value", + action="append") + parser.add_option("--delattr", dest="delattr", + help="Remove an attribute", action="append") + parser.add_option("--setattr", dest="setattr", + help="Set an attribute, dropping any existing values that may exist", + action="append") parser.add_option("--usage", action="store_true", help="Program usage") args = ipa.config.init_config(sys.argv) options, args = parser.parse_args(args) - if (not options.add and not options.remove) and (not options.desc): + if (not options.add and not options.remove) and (not options.desc and + not options.addattr and not options.delattr and not options.setattr): usage() return options, args -def get_group(client, group_cn): +def get_group(client, options, group_cn): try: - group = client.get_entry_by_cn(group_cn) + attrs = ['*'] + + # in case any attributes being modified are operational such as + # nsaccountlock. Any attribute to be deleted needs to be included + # in the original record so it can be seen as being removed. + if options.delattr: + for d in options.delattr: + attrs.append(d) + group = client.get_entry_by_cn(group_cn, sattrs=attrs) + except ipa.ipaerror.IPAError, e: print "%s" % e.message return None @@ -69,32 +91,69 @@ def main(): if (options.add or options.remove) and (len(args) != 3): usage() - if (options.desc and (len(args) != 2)): + elif ((options.desc or options.addattr or options.delattr or options.setattr) and (len(args) != 2)): usage() try: client = ipaclient.IPAClient() if options.add: - group = get_group(client, args[2]) + group = get_group(client, options, args[2]) if group is None: return 1 - client.add_user_to_group(args[1], group.dn) - print args[1] + " successfully added to " + args[2] + users = args[1].split(',') + for user in users: + client.add_user_to_group(user, group.dn) + print user + " successfully added to " + args[2] elif options.remove: - group = get_group(client, args[2]) + group = get_group(client, options, args[2]) if group is None: return 1 - client.remove_user_from_group(args[1], group.dn) - print args[1] + " successfully removed" - elif options.desc: - group = get_group(client, args[1]) + users = args[1].split(',') + for user in users: + client.remove_user_from_group(user, group.dn) + print user + " successfully removed" + else: + group = get_group(client, options, args[1]) if group is None: return 1 - group.setValue('description', options.desc) + + if options.desc: + group.setValue('description', options.desc) + + if options.delattr: + for d in options.delattr: + group.delValue(d) + + if options.setattr: + for s in options.setattr: + s = s.split('=') + if len(s) != 2: + set_add_usage("set") + sys.exit(1) + (attr,value) = s + group.setValue(attr, value) + + if options.addattr: + for a in options.addattr: + a = a.split('=') + if len(a) != 2: + set_add_usage("add") + sys.exit(1) + (attr,value) = a + cvalue = group.getValue(attr) + if cvalue: + if isinstance(cvalue,str): + cvalue = [cvalue] + value = cvalue + [value] + group.setValue(attr, value) + client.update_group(group) print args[1] + " successfully updated" - except xmlrpclib.Fault, f: - print f.faultString + except xmlrpclib.Fault, fault: + if fault.faultCode == errno.ECONNREFUSED: + print "The IPA XML-RPC service is not responding." + else: + print fault.faultString return 1 except kerberos.GSSError, e: print "Could not initialize GSSAPI: %s/%s" % (e[0][0][0], e[0][1][0]) diff --git a/ipa-admintools/ipa-listdelegation b/ipa-admintools/ipa-listdelegation index 54ab346b0..6999e5f83 100644 --- a/ipa-admintools/ipa-listdelegation +++ b/ipa-admintools/ipa-listdelegation @@ -23,8 +23,10 @@ from optparse import OptionParser import ipa.ipaclient as ipaclient import ipa.config +import operator import xmlrpclib import kerberos +import errno import ipa.aci from ipa import ipaerror @@ -51,12 +53,21 @@ def main(): client = ipaclient.IPAClient() try: aci_entry = client.get_aci_entry(aci_fields) - except ipaerror.IPAError, e: - print("Delegation list failed: " + str(e)) + except xmlrpclib.Fault, fault: + if fault.faultCode == errno.ECONNREFUSED: + print "The IPA XML-RPC service is not responding." + else: + print fault.faultString return 1 except kerberos.GSSError, e: print "Could not initialize GSSAPI: %s/%s" % (e[0][0][0], e[0][1][0]) return 1 + except xmlrpclib.ProtocolError, e: + print "Unable to connect to IPA server: %s" % (e.errmsg) + return 1 + except ipaerror.IPAError, e: + print("Delegation list failed: " + str(e)) + return 1 aci_str_list = aci_entry.getValues('aci') if aci_str_list is None: @@ -75,7 +86,8 @@ def main(): group_dn_to_cn = ipa.aci.extract_group_cns(aci_list, client) - for a in aci_list: + # the operator.itemgetter(0) lets us sort by the name field + for a in sorted(aci_list, key=operator.itemgetter(0)): labels = client.attrs_to_labels(a.attrs) print "Delegation Name: " + a.name print "Group " + group_dn_to_cn[a.source_group] diff --git a/ipa-admintools/ipa-moddelegation b/ipa-admintools/ipa-moddelegation index 03b0dc4a8..103c0586d 100644 --- a/ipa-admintools/ipa-moddelegation +++ b/ipa-admintools/ipa-moddelegation @@ -32,6 +32,7 @@ import kerberos import krbV import ldap import copy +import errno aci_fields = ['*', 'aci'] @@ -142,8 +143,11 @@ def main(): aci_entry.setValue('aci', new_aci_str_list) client.update_entry(aci_entry) - except xmlrpclib.Fault, f: - print f.faultString + except xmlrpclib.Fault, fault: + if fault.faultCode == errno.ECONNREFUSED: + print "The IPA XML-RPC service is not responding." + else: + print fault.faultString return 1 except kerberos.GSSError, e: print "Could not initialize GSSAPI: %s/%s" % (e[0][0][0], e[0][1][0]) diff --git a/ipa-admintools/ipa-passwd b/ipa-admintools/ipa-passwd index 59d30e2e4..93cb5f72c 100644 --- a/ipa-admintools/ipa-passwd +++ b/ipa-admintools/ipa-passwd @@ -29,6 +29,7 @@ import kerberos import krbV import ldap import getpass +import errno def usage(): print "ipa-passwd [user]" @@ -98,6 +99,18 @@ def main(): try: client = ipaclient.IPAClient() client.modifyPassword(principal, None, password) + except xmlrpclib.Fault, fault: + if fault.faultCode == errno.ECONNREFUSED: + print "The IPA XML-RPC service is not responding." + else: + print fault.faultString + return 1 + except kerberos.GSSError, e: + print "Could not initialize GSSAPI: %s/%s" % (e[0][0][0], e[0][1][0]) + return 1 + except xmlrpclib.ProtocolError, e: + print "Unable to connect to IPA server: %s" % (e.errmsg) + return 1 except ipa.ipaerror.IPAError, e: print "%s" % (e.message) return 1 diff --git a/ipa-admintools/ipa-usermod b/ipa-admintools/ipa-usermod index c220b3f7d..9d3e7794c 100644 --- a/ipa-admintools/ipa-usermod +++ b/ipa-admintools/ipa-usermod @@ -29,9 +29,10 @@ import ipa.config import xmlrpclib import kerberos import ldap +import errno def usage(): - print "ipa-usermod [-c|--gecos STRING] [-d|--directory STRING] [-f|--firstname STRING] [-l|--lastname STRING] [-s|--shell STRING] [--add attribute=value] [--del attribute] [--set attribute=value] user" + print "ipa-usermod [-a|--activate] [-c|--gecos STRING] [-d|--directory STRING] [-f|--firstname STRING] [-l|--lastname STRING] [-s|--shell STRING] [--add attribute=value] [--del attribute] [--set attribute=value] user" sys.exit(1) def set_add_usage(which): @@ -39,6 +40,8 @@ def set_add_usage(which): def parse_options(): parser = OptionParser() + parser.add_option("-a", "--activate", dest="activate", action="store_true", + help="Activate the user") parser.add_option("-c", "--gecos", dest="gecos", help="Set the GECOS field") parser.add_option("-d", "--directory", dest="directory", @@ -49,12 +52,12 @@ def parse_options(): help="User's last name") parser.add_option("-s", "--shell", dest="shell", help="Set user's login shell to shell") - parser.add_option("--add", dest="addattr", + parser.add_option("--addattr", dest="addattr", help="Adds an attribute or values to that attribute, attr=value", action="append") - parser.add_option("--del", dest="delattr", + parser.add_option("--delattr", dest="delattr", help="Remove an attribute", action="append") - parser.add_option("--set", dest="setattr", + parser.add_option("--setattr", dest="setattr", help="Set an attribute, dropping any existing values that may exist", action="append") parser.add_option("-M", "--mailAddress", dest="mail", @@ -90,7 +93,15 @@ def main(): client = ipaclient.IPAClient() try: - user = client.get_user_by_uid(username) + attrs = ['*'] + + # in case any attributes being modified are operational such as + # nsaccountlock. Any attribute to be deleted needs to be included + # in the original record so it can be seen as being removed. + if options.delattr: + for d in options.delattr: + attrs.append(d) + user = client.get_user_by_uid(username, sattrs=attrs) except ipa.ipaerror.exception_for(ipa.ipaerror.LDAP_NOT_FOUND): print "User %s not found" % username return 1 @@ -102,7 +113,7 @@ def main(): return 1 # If any options are set we use just those. Otherwise ask for all of them. - if options.gn or options.sn or options.directory or options.gecos or options.mail or options.shell or options.addattr or options.delattr or options.setattr: + if options.gn or options.sn or options.directory or options.gecos or options.mail or options.shell or options.addattr or options.delattr or options.setattr or options.activate: givenname = options.gn lastname = options.sn gecos = options.gecos @@ -202,8 +213,7 @@ def main(): if options.delattr: for d in options.delattr: - # doesn't truly delete the attribute but does null out the value - user.setValue(d, '') + user.delValue(d) if options.setattr: for s in options.setattr: @@ -228,11 +238,22 @@ def main(): value = cvalue + [value] user.setValue(attr, value) - try: + if options.activate: + try: + client.mark_user_active(user.getValues('uid')) + print "User activated successfully." + except ipa.ipaerror.exception_for(ipa.ipaerror.LDAP_EMPTY_MODLIST): + print "User is already marked active" + return 0 + except: + raise client.update_user(user) - except xmlrpclib.Fault, f: - print f.faultString + except xmlrpclib.Fault, fault: + if fault.faultCode == errno.ECONNREFUSED: + print "The IPA XML-RPC service is not responding." + else: + print fault.faultString return 1 except kerberos.GSSError, e: print "Could not initialize GSSAPI: %s/%s" % (e[0][0][0], e[0][1][0]) diff --git a/ipa-admintools/man/ipa-deluser.1 b/ipa-admintools/man/ipa-deluser.1 index ab0303d75..8d82dcebe 100644 --- a/ipa-admintools/man/ipa-deluser.1 +++ b/ipa-admintools/man/ipa-deluser.1 @@ -19,14 +19,20 @@ .\" .TH "ipa-deluser" "1" "Oct 10 2007" "freeipa" "" .SH "NAME" -ipa\-deluser \- Delete a user +ipa\-deluser \- Delete or inactivate a user .SH "SYNOPSIS" -ipa\-deluser \fIuser\fR +ipa\-deluser [\fIOPTION\fR]... \fIuser\fR .SH "DESCRIPTION" -Deletes a user with name \fIname\fR. +Inactivates a user with login name \fIname\fR. -Users are not completely removed with the command, just marked as inactive. +By default users are not completely removed. They are marked as inactive. Use the [\-d|\-\-delete] option to completely remove them. + +Users are automatically removed from groups when they are deleted. The are not when inactivated. +.SH "OPTIONS" +.TP +\fB\-d\fR, \fB\-\-delete +Completely remove the user from the database. The default is to mark the user inactive. .SH "EXIT STATUS" The exit status is 0 on success, nonzero on error. diff --git a/ipa-admintools/man/ipa-groupmod.1 b/ipa-admintools/man/ipa-groupmod.1 index 5b9925468..5d107de2f 100644 --- a/ipa-admintools/man/ipa-groupmod.1 +++ b/ipa-admintools/man/ipa-groupmod.1 @@ -37,5 +37,17 @@ Modify the description of the group .TP \fB\-r\fR, \fB\-\-remove\fR=\fIuser1,user2,...usern\fR Remove one or more users from the group + +.TP +\fB\-\-addattr\fR=\fIattr=value\fR +Add a new attribute, or value to an existing attribute + +.TP +\fB\-\-delattr\fR=\fIattr=value\fR +Remove an attribute and all values + +.TP +\fB\-\-setattr\fR=\fIattr=value\fR +Set an attribute to a new value, removing all old ones .SH "EXIT STATUS" The exit status is 0 on success, nonzero on error. diff --git a/ipa-admintools/man/ipa-usermod.1 b/ipa-admintools/man/ipa-usermod.1 index 760e6d057..43c74e450 100644 --- a/ipa-admintools/man/ipa-usermod.1 +++ b/ipa-admintools/man/ipa-usermod.1 @@ -21,10 +21,10 @@ .SH "NAME" ipa\-usermod \- Modify a user .SH "SYNOPSIS" -ipa\-usermod [\fIOPTION\fR]... \fIgroup\fR +ipa\-usermod [\fIOPTION\fR]... \fIname\fR .SH "DESCRIPTION" -Updates the members or description of \fIgroup\fR. +Updates the user \fIname\fR. .SH "OPTIONS" .TP \fB\-a\fR, \fB\-\-add\fR=\fIuser1,user2,...usern\fR @@ -37,5 +37,17 @@ Modify the description of the group .TP \fB\-r\fR, \fB\-\-remove\fR=\fIuser1,user2,...usern\fR Remove one or more users from the group + +.TP +\fB\-\-addattr\fR=\fIattr=value\fR +Add a new attribute, or value to an existing attribute + +.TP +\fB\-\-delattr\fR=\fIattr=value\fR +Remove an attribute and all values + +.TP +\fB\-\-setattr\fR=\fIattr=value\fR +Set an attribute to a new value, removing all old ones .SH "EXIT STATUS" The exit status is 0 on success, nonzero on error. diff --git a/ipa-client/configure.ac b/ipa-client/configure.ac index 5cd416da7..9d060d9a8 100644 --- a/ipa-client/configure.ac +++ b/ipa-client/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ(2.59c) -AC_INIT([freeipa-client], - [0.3.1], +AC_INIT([ipa-client], + [0.5.0], [https://hosted.fedoraproject.org/projects/freeipa/newticket]) AC_CONFIG_SRCDIR([ipaclient/__init__.py]) @@ -47,7 +47,7 @@ AC_CONFIG_FILES([ AC_OUTPUT echo " - FreeIPA client $VERSION + IPA client $VERSION ======================== prefix: ${prefix} diff --git a/ipa-client/freeipa-client.spec b/ipa-client/ipa-client.spec similarity index 76% rename from ipa-client/freeipa-client.spec rename to ipa-client/ipa-client.spec index f4a51f47a..c184600bb 100755 --- a/ipa-client/freeipa-client.spec +++ b/ipa-client/ipa-client.spec @@ -1,7 +1,7 @@ -Name: freeipa-client -Version: 0.3.1 +Name: ipa-client +Version: 0.5.0 Release: 1%{?dist} -Summary: FreeIPA client +Summary: IPA client Group: System Environment/Base License: GPL @@ -9,10 +9,10 @@ URL: http://www.freeipa.org Source0: %{name}-%{version}.tgz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) -Requires: python python-ldap python-krbV freeipa-python +Requires: python python-ldap python-krbV ipa-python %description -FreeIPA is a server for identity, policy, and audit. +IPA is a server for identity, policy, and audit. The client package provide install and configuration scripts for clients. %prep @@ -41,6 +41,9 @@ rm -rf %{buildroot} %{_usr}/share/ipa/* %changelog +* Wed Nov 21 2007 Karl MacMillan - 0.5.0-1 +- Version bump for release and rpm name change + * Thu Nov 1 2007 Karl MacMillan - 0.3.1-1 - Version bump for release diff --git a/ipa-client/freeipa-client.spec.in b/ipa-client/ipa-client.spec.in similarity index 78% rename from ipa-client/freeipa-client.spec.in rename to ipa-client/ipa-client.spec.in index f4a7997f8..5dbd90f3f 100644 --- a/ipa-client/freeipa-client.spec.in +++ b/ipa-client/ipa-client.spec.in @@ -1,7 +1,7 @@ -Name: freeipa-client +Name: ipa-client Version: VERSION Release: 1%{?dist} -Summary: FreeIPA client +Summary: IPA client Group: System Environment/Base License: GPL @@ -9,10 +9,10 @@ URL: http://www.freeipa.org Source0: %{name}-%{version}.tgz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) -Requires: python python-ldap python-krbV freeipa-python +Requires: python python-ldap python-krbV ipa-python %description -FreeIPA is a server for identity, policy, and audit. +IPA is a server for identity, policy, and audit. The client package provide install and configuration scripts for clients. %prep @@ -41,6 +41,9 @@ rm -rf %{buildroot} %{_usr}/share/ipa/* %changelog +* Wed Nov 21 2007 Karl MacMillan - 0.5.0-1 +- Version bump for release and rpm name change + * Thu Nov 1 2007 Karl MacMillan - 0.3.1-1 - Version bump for release diff --git a/ipa-client/ipa-install/ipa-client-install b/ipa-client/ipa-install/ipa-client-install index 3e3597dca..fccdac3bd 100644 --- a/ipa-client/ipa-install/ipa-client-install +++ b/ipa-client/ipa-install/ipa-client-install @@ -124,6 +124,21 @@ def main(): print "IPA Server: "+ds.getServerName() print "BaseDN: "+ds.getBaseDN() + # Configure ipa.conf + ipaconf = ipaclient.ipachangeconf.IPAChangeConf("IPA Installer") + ipaconf.setOptionAssignment(" = ") + ipaconf.setSectionNameDelimiters(("[","]")) + + opts = [{'name':'comment', 'type':'comment', 'value':'File modified by ipa-client-install'}, + {'name':'empty', 'type':'empty'}] + defopts.append({'name':'server', 'type':'option', 'value':ds.getServerName()}) + defopts.append({'name':'realm', 'type':'option', 'value':ds.getRealmName()}) + + opts.append({'name':'defaults', 'type':'section', 'value':defopts}) + opts.append({'name':'empty', 'type':'empty'}) + + ipaconf.newConf("/etc/ipa/ipa.conf", opts) + # Configure ldap.conf ldapconf = ipaclient.ipachangeconf.IPAChangeConf("IPA Installer") ldapconf.setOptionAssignment(" ") diff --git a/ipa-python/aci.py b/ipa-python/aci.py index 60e19075a..d35da8dab 100644 --- a/ipa-python/aci.py +++ b/ipa-python/aci.py @@ -37,6 +37,16 @@ class ACI: if acistr is not None: self.parse_acistr(acistr) + def __getitem__(self,key): + """Fake getting attributes by key for sorting""" + if key == 0: + return self.name + if key == 1: + return self.source_group + if key == 2: + return self.dest_group + raise TypeError("Unknown key value %s" % key) + def export_to_string(self): """Converts the ACI to a string suitable for an LDAP aci attribute.""" attrs_str = ' || '.join(self.attrs) diff --git a/ipa-python/freeipa-python.spec b/ipa-python/ipa-python.spec similarity index 86% rename from ipa-python/freeipa-python.spec rename to ipa-python/ipa-python.spec index a84fb0fe2..2837a2832 100755 --- a/ipa-python/freeipa-python.spec +++ b/ipa-python/ipa-python.spec @@ -1,7 +1,7 @@ -Name: freeipa-python -Version: 0.4.1 +Name: ipa-python +Version: 0.5.0 Release: 1%{?dist} -Summary: FreeIPA authentication server +Summary: Ipa authentication server Group: System Environment/Base License: GPL @@ -17,7 +17,7 @@ Requires: PyKerberos %define pkgpythondir %{python_sitelib}/ipa %description -FreeIPA is a server for identity, policy, and audit. +Ipa is a server for identity, policy, and audit. %prep %setup -q @@ -38,6 +38,9 @@ rm -rf %{buildroot} %config(noreplace) %{_sysconfdir}/ipa/ipa.conf %changelog +* Wed Nov 21 2007 Karl MacMillan - 0.5.0-1 +- Version bump for release and rename of rpm + * Thu Nov 1 2007 Karl MacMillan - 0.4.1-1 - Version bump for release diff --git a/ipa-python/freeipa-python.spec.in b/ipa-python/ipa-python.spec.in similarity index 87% rename from ipa-python/freeipa-python.spec.in rename to ipa-python/ipa-python.spec.in index 0c46098ce..bd8ac0da6 100755 --- a/ipa-python/freeipa-python.spec.in +++ b/ipa-python/ipa-python.spec.in @@ -1,7 +1,7 @@ -Name: freeipa-python +Name: ipa-python Version: VERSION Release: 1%{?dist} -Summary: FreeIPA authentication server +Summary: Ipa authentication server Group: System Environment/Base License: GPL @@ -17,7 +17,7 @@ Requires: PyKerberos %define pkgpythondir %{python_sitelib}/ipa %description -FreeIPA is a server for identity, policy, and audit. +Ipa is a server for identity, policy, and audit. %prep %setup -q @@ -38,6 +38,9 @@ rm -rf %{buildroot} %config(noreplace) %{_sysconfdir}/ipa/ipa.conf %changelog +* Wed Nov 21 2007 Karl MacMillan - 0.5.0-1 +- Version bump for release and rename of rpm + * Thu Nov 1 2007 Karl MacMillan - 0.4.1-1 - Version bump for release diff --git a/ipa-python/ipaclient.py b/ipa-python/ipaclient.py index 7a140308a..168f01d38 100644 --- a/ipa-python/ipaclient.py +++ b/ipa-python/ipaclient.py @@ -135,10 +135,14 @@ class IPAClient: return all_users - def get_add_schema(self): - """Prototype for the GUI. Specify in the directory fields to - be displayed and what data to get for new users.""" - result = self.transport.get_add_schema() + def get_custom_fields(self): + """Get custom user fields""" + result = self.transport.get_custom_fields() + return result + + def set_custom_fields(self, schema): + """Set custom user fields""" + result = self.transport.set_custom_fields(schema) return result def find_users(self, criteria, sattrs=None, searchlimit=0, timelimit=-1): @@ -174,10 +178,16 @@ class IPAClient: return result - def mark_user_deleted(self,uid): + def mark_user_active(self,uid): + """Set a user as active by uid.""" + + result = self.transport.mark_user_active(uid) + return result + + def mark_user_inactive(self,uid): """Set a user as inactive by uid.""" - result = self.transport.mark_user_deleted(uid) + result = self.transport.mark_user_inactive(uid) return result # Groups support @@ -332,6 +342,52 @@ class IPAClient: entries.append(user.User(e)) return entries + + def mark_group_active(self,cn): + """Set a group as active by cn.""" + + result = self.transport.mark_group_active(cn) + return result + + def mark_group_inactive(self,cn): + """Set a group as inactive by cn.""" + + result = self.transport.mark_group_inactive(cn) + return result + +# Configuration + + def get_ipa_config(self): + """Get the IPA configuration""" + result = self.transport.get_ipa_config() + return entity.Entity(result) + + def update_ipa_config(self, config): + """Updates the IPA configuration. + + config is an Entity object. + """ + result = self.transport.update_ipa_config(config.origDataDict(), config.toDict()) + return result + + def get_password_policy(self): + """Get the IPA password policy""" + result = self.transport.get_password_policy() + return entity.Entity(result) + + def update_password_policy(self, policy): + """Updates the IPA password policy. + + policy is an Entity object. + """ + result = self.transport.update_password_policy(policy.origDataDict(), policy.toDict()) + return result + + def add_service_principal(self, princ_name): + return self.transport.add_service_principal(princ_name) + + def get_keytab(self, princ_name): + return self.transport.get_keytab(princ_name) # radius support def get_radius_client_by_ip_addr(self, ip_addr, container=None, sattrs=None): diff --git a/ipa-python/ipaerror.py b/ipa-python/ipaerror.py index 0106132ca..5391b3fd4 100644 --- a/ipa-python/ipaerror.py +++ b/ipa-python/ipaerror.py @@ -28,6 +28,11 @@ class IPAError(exceptions.Exception): error.""" self.code = code self.message = message + # Fill this in as an empty LDAP error message so we don't have a lot + # of "if e.detail ..." everywhere + if detail is None: + detail = [] + detail.append({'desc':'','info':''}) self.detail = detail def __str__(self): @@ -118,6 +123,11 @@ LDAP_EMPTY_MODLIST = gen_error_code( 0x0006, "No modifications to be performed") +LDAP_NO_CONFIG = gen_error_code( + LDAP_CATEGORY, + 0x0007, + "IPA configuration not found") + # # Input errors (sample - replace me) # @@ -147,3 +157,8 @@ CONNECTION_GSSAPI_CREDENTIALS = gen_error_code( CONNECTION_CATEGORY, 0x0003, "GSSAPI Authorization error") + +CONNECTION_UNWILLING = gen_error_code( + CONNECTION_CATEGORY, + 0x0004, + "Account inactivated. Server is unwilling to perform.") diff --git a/ipa-python/ipautil.py b/ipa-python/ipautil.py index 9584f9289..5f7d396aa 100644 --- a/ipa-python/ipautil.py +++ b/ipa-python/ipautil.py @@ -23,8 +23,11 @@ import string import tempfile import logging import subprocess +from random import Random +from time import gmtime import os import stat +import socket import readline import traceback from types import * @@ -39,7 +42,6 @@ def realm_to_suffix(realm_name): terms = ["dc=" + x.lower() for x in s] return ",".join(terms) - def template_str(txt, vars): return string.Template(txt).substitute(vars) @@ -334,6 +336,15 @@ def parse_generalized_time(timestr): except ValueError: return None +def ipa_generate_password(): + rndpwd = '' + r = Random() + r.seed(gmtime()) + for x in range(12): +# rndpwd += chr(r.randint(32,126)) + rndpwd += chr(r.randint(65,90)) #stricter set for testing + return rndpwd + def format_list(items, quote=None, page_width=80): '''Format a list of items formatting them so they wrap to fit the diff --git a/ipa-python/rpcclient.py b/ipa-python/rpcclient.py index ed23015e1..6f039f9fa 100644 --- a/ipa-python/rpcclient.py +++ b/ipa-python/rpcclient.py @@ -218,23 +218,32 @@ class RPCClient: return ipautil.unwrap_binary_data(result) - def get_add_schema(self): - """Get the list of attributes we need to ask when adding a new - user. - """ + def get_custom_fields(self): + """Get custom user fields.""" server = self.setup_server() - # FIXME: Hardcoded and designed for the TurboGears GUI. Do we want - # this for the CLI as well? try: - result = server.get_add_schema() + result = server.get_custom_fields() except xmlrpclib.Fault, fault: raise ipaerror.gen_exception(fault.faultCode, fault.faultString) except socket.error, (value, msg): raise xmlrpclib.Fault(value, msg) return ipautil.unwrap_binary_data(result) - + + def set_custom_fields(self, schema): + """Set custom user fields.""" + server = self.setup_server() + + try: + result = server.set_custom_fields(schema) + except xmlrpclib.Fault, fault: + raise ipaerror.gen_exception(fault.faultCode, fault.faultString) + except socket.error, (value, msg): + raise xmlrpclib.Fault(value, msg) + + return ipautil.unwrap_binary_data(result) + def get_all_users (self): """Return a list containing a User object for each existing user.""" @@ -309,12 +318,12 @@ class RPCClient: return result - def mark_user_deleted(self,uid): - """Mark a user as deleted/inactive""" + def mark_user_active(self,uid): + """Mark a user as active""" server = self.setup_server() try: - result = server.mark_user_deleted(uid) + result = server.mark_user_active(uid) except xmlrpclib.Fault, fault: raise ipaerror.gen_exception(fault.faultCode, fault.faultString) except socket.error, (value, msg): @@ -322,6 +331,20 @@ class RPCClient: return ipautil.unwrap_binary_data(result) + def mark_user_inactive(self,uid): + """Mark a user as inactive""" + server = self.setup_server() + + try: + result = server.mark_user_inactive(uid) + except xmlrpclib.Fault, fault: + raise ipaerror.gen_exception(fault.faultCode, fault.faultString) + except socket.error, (value, msg): + raise xmlrpclib.Fault(value, msg) + + return ipautil.unwrap_binary_data(result) + + # Group support def get_groups_by_member(self,member_dn,sattrs=None): @@ -592,6 +615,106 @@ class RPCClient: return ipautil.unwrap_binary_data(result) + def mark_group_active(self,cn): + """Mark a group as active""" + server = self.setup_server() + + try: + result = server.mark_group_active(cn) + except xmlrpclib.Fault, fault: + raise ipaerror.gen_exception(fault.faultCode, fault.faultString) + except socket.error, (value, msg): + raise xmlrpclib.Fault(value, msg) + + return ipautil.unwrap_binary_data(result) + + def mark_group_inactive(self,cn): + """Mark a group as inactive""" + server = self.setup_server() + + try: + result = server.mark_group_inactive(cn) + except xmlrpclib.Fault, fault: + raise ipaerror.gen_exception(fault.faultCode, fault.faultString) + except socket.error, (value, msg): + raise xmlrpclib.Fault(value, msg) + + return ipautil.unwrap_binary_data(result) + +# Configuration support + + def get_ipa_config(self): + """Get the IPA configuration""" + server = self.setup_server() + try: + result = server.get_ipa_config() + except xmlrpclib.Fault, fault: + raise ipaerror.gen_exception(fault.faultCode, fault.faultString) + except socket.error, (value, msg): + raise xmlrpclib.Fault(value, msg) + + return ipautil.unwrap_binary_data(result) + + def update_ipa_config(self, oldconfig, newconfig): + """Update the IPA configuration""" + server = self.setup_server() + try: + result = server.update_ipa_config(oldconfig, newconfig) + except xmlrpclib.Fault, fault: + raise ipaerror.gen_exception(fault.faultCode, fault.faultString) + except socket.error, (value, msg): + raise xmlrpclib.Fault(value, msg) + + return ipautil.unwrap_binary_data(result) + + def get_password_policy(self): + """Get the IPA password policy""" + server = self.setup_server() + try: + result = server.get_password_policy() + except xmlrpclib.Fault, fault: + raise ipaerror.gen_exception(fault.faultCode, fault.faultString) + except socket.error, (value, msg): + raise xmlrpclib.Fault(value, msg) + + return ipautil.unwrap_binary_data(result) + + def update_password_policy(self, oldpolicy, newpolicy): + """Update the IPA password policy""" + server = self.setup_server() + try: + result = server.update_password_policy(oldpolicy, newpolicy) + except xmlrpclib.Fault, fault: + raise ipaerror.gen_exception(fault.faultCode, fault.faultString) + except socket.error, (value, msg): + raise xmlrpclib.Fault(value, msg) + + return ipautil.unwrap_binary_data(result) + + def add_service_principal(self, princ_name): + server = self.setup_server() + + try: + result = server.add_service_principal(princ_name) + except xmlrpclib.Fault, fault: + raise ipaerror.gen_exception(fault.faultCode, fault.faultString) + except socket.error, (value, msg): + raise xmlrpclib.Fault(value, msg) + + return ipautil.unwrap_binary_data(result) + + def get_keytab(self, princ_name): + server = self.setup_server() + + try: + result = server.get_keytab(princ_name) + except xmlrpclib.Fault, fault: + raise ipaerror.gen_exception(fault.faultCode, fault.faultString) + except socket.error, (value, msg): + raise xmlrpclib.Fault(value, msg) + + return ipautil.unwrap_binary_data(result) + # radius support def get_radius_client_by_ip_addr(self, ip_addr, container, sattrs=None): diff --git a/ipa-python/setup.py b/ipa-python/setup.py index defd49cbd..3a5a6f4eb 100644 --- a/ipa-python/setup.py +++ b/ipa-python/setup.py @@ -35,7 +35,7 @@ def setup_package(): try: setup( name = "freeipa-python", - version = "0.4.1", + version = "0.5.0", license = "GPL", author = "Karl MacMillan, et.al.", author_email = "kmacmillan@redhat.com", diff --git a/ipa-server/Makefile.am b/ipa-server/Makefile.am index b5da3f566..9638cdab6 100644 --- a/ipa-server/Makefile.am +++ b/ipa-server/Makefile.am @@ -11,6 +11,7 @@ SUBDIRS = \ ipaserver \ ipa-slapi-plugins \ xmlrpc-server \ + ipa-keytab-util \ $(NULL) EXTRA_DIST = \ diff --git a/ipa-server/configure.ac b/ipa-server/configure.ac index e07c04c85..1e62a2f82 100644 --- a/ipa-server/configure.ac +++ b/ipa-server/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ(2.59c) -AC_INIT([freeipa-server], - [0.4], +AC_INIT([ipa-server], + [0.5], [https://hosted.fedoraproject.org/projects/freeipa/newticket]) AC_CONFIG_SRCDIR([ipaserver/ipaldap.py]) @@ -229,12 +229,13 @@ AC_CONFIG_FILES([ ipa-slapi-plugins/ipa-pwd-extop/Makefile xmlrpc-server/Makefile xmlrpc-server/test/Makefile + ipa-keytab-util/Makefile ]) AC_OUTPUT echo " - FreeIPA Server $VERSION + IPA Server $VERSION ======================== prefix: ${prefix} diff --git a/ipa-server/ipa-gui/README.multivalue b/ipa-server/ipa-gui/README.multivalue new file mode 100644 index 000000000..ba315181d --- /dev/null +++ b/ipa-server/ipa-gui/README.multivalue @@ -0,0 +1,27 @@ +The way multi-valued fields work is this: + - A new widget is added to the form. I name it as the attribute + s. + For example, I use cns for the cn attribute. + - If you need a new validator use a ForEach() so that each value is + checked. + - This attribute is populated from the incoming attribute from the + user or group record. The widget can support multiple fields at once + but I'm using it for just one field. In fact, I don't know if it + will work with more the way I'm using it. + - In the GUI an operator can add/remove values to each multi-valued field. + - Naming is very important in the widget. TurboGears automatically + re-assembles the data into a list of dict entries if you name things + properly. For example, the cns (multiple CN entries) looks like: + cns-0.cn=Rob+Crittenden&cns-1.cn=Robert+Crittenden&cns-2.cn=rcrit + - This gets converted to: + [{'cn': u'Rob Crittenden'}, {'cn': u'Robert Crittenden'}, {'cn': u'rcrit'}] + - I take this list of dicts and pull out each value and append it to a new + list that represents the original multi-valued field + - Then the list/dict version is removed (in this case, kw['cns']). + +When adding a new field you have to update: + +1. The form to add the new ExpandingForm() field and perhaps a validator +2. The edit template to add the boilerplate to display the field +3. The show template to be able to display all the fields separately +4. The new template if you want to be able to enter these on new entries +5. The subcontroller so you can do the input and output conversions diff --git a/ipa-server/ipa-gui/ipagui/controllers.py b/ipa-server/ipa-gui/ipagui/controllers.py index 5d0bfee03..d1ee22e01 100644 --- a/ipa-server/ipa-gui/ipagui/controllers.py +++ b/ipa-server/ipa-gui/ipagui/controllers.py @@ -17,6 +17,8 @@ import ipa.ipaclient from subcontrollers.user import UserController from subcontrollers.group import GroupController from subcontrollers.delegation import DelegationController +from subcontrollers.policy import PolicyController +from subcontrollers.ipapolicy import IPAPolicyController ipa.config.init_config() @@ -27,6 +29,8 @@ class Root(controllers.RootController): user = UserController() group = GroupController() delegate = DelegationController() + policy = PolicyController() + ipapolicy = IPAPolicyController() @expose(template="ipagui.templates.welcome") @identity.require(identity.not_anonymous()) diff --git a/ipa-server/ipa-gui/ipagui/forms/Makefile.am b/ipa-server/ipa-gui/ipagui/forms/Makefile.am index 5f07e4cb0..c075b9f47 100644 --- a/ipa-server/ipa-gui/ipagui/forms/Makefile.am +++ b/ipa-server/ipa-gui/ipagui/forms/Makefile.am @@ -4,8 +4,9 @@ appdir = $(IPA_DATA_DIR)/ipagui/forms app_PYTHON = \ __init__.py \ group.py \ + ipapolicy.py \ user.py \ - delegate.py \ + delegate.py \ $(NULL) EXTRA_DIST = \ diff --git a/ipa-server/ipa-gui/ipagui/forms/delegate.py b/ipa-server/ipa-gui/ipagui/forms/delegate.py index 89011f4a2..419df4fc7 100644 --- a/ipa-server/ipa-gui/ipagui/forms/delegate.py +++ b/ipa-server/ipa-gui/ipagui/forms/delegate.py @@ -44,7 +44,7 @@ aci_checkbox_attrs = [(field.name, field.label) for field in aci_attrs] aci_name_to_label = dict(aci_checkbox_attrs) class DelegateFields(): - name = widgets.TextField(name="name", label="Name") + name = widgets.TextField(name="name", label="Delegation Name") source_group_dn = widgets.HiddenField(name="source_group_dn") dest_group_dn = widgets.HiddenField(name="dest_group_dn") diff --git a/ipa-server/ipa-gui/ipagui/forms/group.py b/ipa-server/ipa-gui/ipagui/forms/group.py index 380c904a4..b67156641 100644 --- a/ipa-server/ipa-gui/ipagui/forms/group.py +++ b/ipa-server/ipa-gui/ipagui/forms/group.py @@ -1,14 +1,18 @@ import turbogears from turbogears import validators, widgets +from tg_expanding_form_widget.tg_expanding_form_widget import ExpandingForm class GroupFields(): cn = widgets.TextField(name="cn", label="Name") gidnumber = widgets.TextField(name="gidnumber", label="GID") description = widgets.TextField(name="description", label="Description") - cn_hidden = widgets.HiddenField(name="cn") editprotected_hidden = widgets.HiddenField(name="editprotected") + nsAccountLock = widgets.SingleSelectField(name="nsAccountLock", + label="Group Status", + options = [("", "active"), ("true", "inactive")]) + group_orig = widgets.HiddenField(name="group_orig") member_data = widgets.HiddenField(name="member_data") dn_to_info_json = widgets.HiddenField(name="dn_to_info_json") @@ -37,6 +41,7 @@ class GroupNewForm(widgets.Form): class GroupEditValidator(validators.Schema): + cn = validators.String(not_empty=True) gidnumber = validators.Int(not_empty=False) description = validators.String(not_empty=False) @@ -48,7 +53,7 @@ class GroupEditForm(widgets.Form): params = ['members', 'group_fields'] hidden_fields = [ - GroupFields.cn_hidden, GroupFields.editprotected_hidden, + GroupFields.editprotected_hidden, GroupFields.group_orig, GroupFields.member_data, GroupFields.dn_to_info_json ] diff --git a/ipa-server/ipa-gui/ipagui/forms/ipapolicy.py b/ipa-server/ipa-gui/ipagui/forms/ipapolicy.py new file mode 100644 index 000000000..ec0e8c6f8 --- /dev/null +++ b/ipa-server/ipa-gui/ipagui/forms/ipapolicy.py @@ -0,0 +1,59 @@ +import turbogears +from turbogears import validators, widgets + +class IPAPolicyFields(): + # From cn=ipaConfig + ipausersearchfields = widgets.TextField(name="ipausersearchfields", label="User Search Fields") + ipagroupsearchfields = widgets.TextField(name="ipagroupsearchfields", label="Group Search Fields") + ipasearchtimelimit = widgets.TextField(name="ipasearchtimelimit", label="Search Time Limit (sec.)", attrs=dict(size=6,maxlength=6)) + ipasearchrecordslimit = widgets.TextField(name="ipasearchrecordslimit", label="Search Records Limit", attrs=dict(size=6,maxlength=6)) + ipahomesrootdir = widgets.TextField(name="ipahomesrootdir", label="Root for Home Directories") + ipadefaultloginshell = widgets.TextField(name="ipadefaultloginshell", label="Default shell") + ipadefaultprimarygroup = widgets.TextField(name="ipadefaultprimarygroup", label="Default Users group") + ipamaxusernamelength = widgets.TextField(name="ipamaxusernamelength", label="Max. Username Length", attrs=dict(size=3,maxlength=3)) + ipapwdexpadvnotify = widgets.TextField(name="ipapwdexpadvnotify", label="Password Expiration Notification (days)", attrs=dict(size=3,maxlength=3)) + + ipapolicy_orig = widgets.HiddenField(name="ipapolicy_orig") + + # From cn=accounts + krbmaxpwdlife = widgets.TextField(name="krbmaxpwdlife", label="Max. Password Lifetime", attrs=dict(size=3,maxlength=3)) + krbminpwdlife = widgets.TextField(name="krbminpwdlife", label="Min. Password Lifetime", attrs=dict(size=3,maxlength=3)) + krbpwdmindiffchars = widgets.TextField(name="krbpwdmindiffchars", label="Min. number of character classes", attrs=dict(size=3,maxlength=3)) + krbpwdminlength = widgets.TextField(name="krbpwdminlength", label="Min. Length of password", attrs=dict(size=3,maxlength=3)) + krbpwdhistorylength = widgets.TextField(name="krbpwdhistorylength", label="Password History size", attrs=dict(size=3,maxlength=3)) + + password_orig = widgets.HiddenField(name="password_orig") + +class IPAPolicyValidator(validators.Schema): + ipausersearchfields = validators.String(not_empty=True) + ipagroupsearchfields = validators.String(not_empty=True) + ipasearchtimelimit = validators.Number(not_empty=True) + ipasearchrecordslimit = validators.Number(not_empty=True) + ipamaxusernamelength = validators.Number(not_empty=True) + ipapwdexpadvnotify = validators.Number(not_empty=True) + ipahomesrootdir = validators.String(not_empty=True) + ipadefaultloginshell = validators.String(not_empty=True) + ipadefaultprimarygroup = validators.String(not_empty=True) + krbmaxpwdlife = validators.Number(not_empty=True) + krbminpwdlife = validators.Number(not_empty=True) + krbpwdmindiffchars = validators.Number(not_empty=True) + krbpwdminlength = validators.Number(not_empty=True) + krbpwdhistorylength = validators.Number(not_empty=True) + +class IPAPolicyForm(widgets.Form): + params = ['ipapolicy_fields'] + + hidden_fields = [ + IPAPolicyFields.ipapolicy_orig, IPAPolicyFields.password_orig + ] + + validator = IPAPolicyValidator() + + def __init__(self, *args, **kw): + super(IPAPolicyForm,self).__init__(*args, **kw) + (self.template_c, self.template) = widgets.meta.load_kid_template( + "ipagui.templates.ipapolicyeditform") + self.ipapolicy_fields = IPAPolicyFields + + def update_params(self, params): + super(IPAPolicyForm,self).update_params(params) diff --git a/ipa-server/ipa-gui/ipagui/forms/user.py b/ipa-server/ipa-gui/ipagui/forms/user.py index 1a35b4e07..7d3d37193 100644 --- a/ipa-server/ipa-gui/ipagui/forms/user.py +++ b/ipa-server/ipa-gui/ipagui/forms/user.py @@ -1,10 +1,12 @@ import turbogears from turbogears import validators, widgets +from tg_expanding_form_widget.tg_expanding_form_widget import ExpandingForm class UserFields(): givenname = widgets.TextField(name="givenname", label="Given Name") sn = widgets.TextField(name="sn", label="Family Name") cn = widgets.TextField(name="cn", label="Common Names") + cns = ExpandingForm(name="cns", label="Common Names", fields=[cn]) title = widgets.TextField(name="title", label="Title") displayname = widgets.TextField(name="displayname", label="Display Name") initials = widgets.TextField(name="initials", label="Initials") @@ -21,11 +23,16 @@ class UserFields(): mail = widgets.TextField(name="mail", label="E-mail Address") telephonenumber = widgets.TextField(name="telephonenumber", label="Work Number") + telephonenumbers = ExpandingForm(name="telephonenumbers", label="Work Numbers", fields=[telephonenumber]) facsimiletelephonenumber = widgets.TextField(name="facsimiletelephonenumber", label="Fax Number") + facsimiletelephonenumbers = ExpandingForm(name="facsimiletelephonenumbers", label="Fax Numbers", fields=[facsimiletelephonenumber]) mobile = widgets.TextField(name="mobile", label="Cell Number") + mobiles = ExpandingForm(name="mobiles", label="Cell Numbers", fields=[mobile]) pager = widgets.TextField(name="pager", label="Pager Number") + pagers = ExpandingForm(name="pagers", label="Pager Numbers", fields=[pager]) homephone = widgets.TextField(name="homephone", label="Home Number") + homephones = ExpandingForm(name="homephones", label="Home Numbers", fields=[homephone]) street = widgets.TextField(name="street", label="Street Address") l = widgets.TextField(name="l", label="City") @@ -67,7 +74,8 @@ class UserNewValidator(validators.Schema): userpassword_confirm = validators.String(not_empty=False) givenname = validators.String(not_empty=True) sn = validators.String(not_empty=True) - mail = validators.Email(not_empty=True) + cn = validators.ForEach(validators.String(not_empty=True)) + mail = validators.Email(not_empty=False) chained_validators = [ validators.FieldsMatch('userpassword', 'userpassword_confirm') @@ -102,6 +110,7 @@ class UserEditValidator(validators.Schema): userpassword_confirm = validators.String(not_empty=False) givenname = validators.String(not_empty=True) sn = validators.String(not_empty=True) + cn = validators.ForEach(validators.String(not_empty=True)) mail = validators.Email(not_empty=True) uidnumber = validators.Int(not_empty=False) gidnumber = validators.Int(not_empty=False) diff --git a/ipa-server/ipa-gui/ipagui/helpers/userhelper.py b/ipa-server/ipa-gui/ipagui/helpers/userhelper.py index e1ade3a2c..52d37c9e4 100644 --- a/ipa-server/ipa-gui/ipagui/helpers/userhelper.py +++ b/ipa-server/ipa-gui/ipagui/helpers/userhelper.py @@ -13,7 +13,7 @@ def password_expires_in(datestr): if not expdate: return sys.maxint - delta = expdate - datetime.datetime.now() + delta = expdate - datetime.datetime.now(ipautil.GeneralizedTimeZone()) return delta.days def password_is_expired(days): diff --git a/ipa-server/ipa-gui/ipagui/proxyprovider.py b/ipa-server/ipa-gui/ipagui/proxyprovider.py index e8ef69830..bd9cf87a8 100644 --- a/ipa-server/ipa-gui/ipagui/proxyprovider.py +++ b/ipa-server/ipa-gui/ipagui/proxyprovider.py @@ -2,6 +2,11 @@ from turbogears.identity.soprovider import * from turbogears.identity.visitor import * import logging import os +import ipa.ipaclient +from ipaserver import funcs +import ipa.config +import ipa.group +import ipa.user log = logging.getLogger("turbogears.identity") @@ -15,7 +20,25 @@ class IPA_User(object): (principal, realm) = user_name.split('@') self.display_name = principal self.permissions = None - self.groups = None + transport = funcs.IPAServer() + client = ipa.ipaclient.IPAClient(transport) + client.set_krbccache(os.environ["KRB5CCNAME"]) + try: + user = client.get_user_by_principal(user_name, ['dn']) + self.groups = [] + groups = client.get_groups_by_member(user.dn, ['dn', 'cn']) + if isinstance(groups, str): + groups = [groups] + for ginfo in groups: + # cn may be multi-valued, add them all just in case + cn = ginfo.getValue('cn') + if isinstance(cn, str): + cn = [cn] + for c in cn: + self.groups.append(c) + except: + raise + return class ProxyIdentity(object): @@ -57,7 +80,7 @@ class ProxyIdentity(object): def _get_groups(self): try: - return self._groups + return self._user.groups except AttributeError: # Groups haven't been computed yet return None @@ -87,10 +110,14 @@ class ProxyIdentityProvider(SqlObjectIdentityProvider): pass def validate_identity(self, user_name, password, visit_key): - user = IPA_User(user_name) - log.debug( "validate_identity %s" % user_name) - - return ProxyIdentity(visit_key, user) + try: + user = IPA_User(user_name) + log.debug( "validate_identity %s" % user_name) + return ProxyIdentity(visit_key, user) + except: + # Something went wrong in fetching the user. Set to + # anonymous which will deny access. + return ProxyIdentity( None ) def validate_password(self, user, user_name, password): '''Validation has already occurred in the proxy''' diff --git a/ipa-server/ipa-gui/ipagui/static/css/style.css b/ipa-server/ipa-gui/ipagui/static/css/style.css index 28f501352..1a7cbb1fb 100644 --- a/ipa-server/ipa-gui/ipagui/static/css/style.css +++ b/ipa-server/ipa-gui/ipagui/static/css/style.css @@ -383,3 +383,22 @@ ul.checkboxlist li input { #inactive { background-color: silver; } + +/* + * * TableKit css + * + */ + +.sortcol { + cursor: pointer; + padding-right: 20px !important; + background-repeat: no-repeat !important; + background-position: right center !important; + text-decoration: underline; +} +.sortasc { + background-image: url(/static/images/up.gif) !important; +} +.sortdesc { + background-image: url(/static/images/down.gif) !important; +} diff --git a/ipa-server/ipa-gui/ipagui/subcontrollers/Makefile.am b/ipa-server/ipa-gui/ipagui/subcontrollers/Makefile.am index d409bac7d..2f596f2ef 100644 --- a/ipa-server/ipa-gui/ipagui/subcontrollers/Makefile.am +++ b/ipa-server/ipa-gui/ipagui/subcontrollers/Makefile.am @@ -5,6 +5,8 @@ app_PYTHON = \ __init__.py \ group.py \ ipacontroller.py \ + ipapolicy.py \ + policy.py \ user.py \ delegation.py \ $(NULL) diff --git a/ipa-server/ipa-gui/ipagui/subcontrollers/delegation.py b/ipa-server/ipa-gui/ipagui/subcontrollers/delegation.py index 1515b04c1..142d34430 100644 --- a/ipa-server/ipa-gui/ipagui/subcontrollers/delegation.py +++ b/ipa-server/ipa-gui/ipagui/subcontrollers/delegation.py @@ -19,6 +19,7 @@ import ipagui.forms.delegate import ipa.aci import ldap.dn +import operator log = logging.getLogger(__name__) @@ -34,7 +35,7 @@ class DelegationController(IPAController): raise turbogears.redirect("/delegate/list") @expose("ipagui.templates.delegatenew") - @identity.require(identity.not_anonymous()) + @identity.require(identity.in_group("admins")) def new(self): """Display delegate page""" client = self.get_ipaclient() @@ -45,7 +46,7 @@ class DelegationController(IPAController): return dict(form=delegate_form, delegate=delegate) @expose() - @identity.require(identity.not_anonymous()) + @identity.require(identity.in_group("admins")) def create(self, **kw): """Creates a new delegation""" self.restrict_post() @@ -63,11 +64,34 @@ class DelegationController(IPAController): tg_template='ipagui.templates.delegatenew') try: + aci_entry = client.get_aci_entry(aci_fields) + new_aci = ipa.aci.ACI() new_aci.name = kw.get('name') new_aci.source_group = kw.get('source_group_dn') new_aci.dest_group = kw.get('dest_group_dn') new_aci.attrs = kw.get('attrs') + if (new_aci.attrs, str): + new_aci.attrs = [new_aci.attrs] + + # Look for an existing ACI of the same name + aci_str_list = aci_entry.getValues('aci') + if aci_str_list is None: + aci_str_list = [] + if not(isinstance(aci_str_list,list) or isinstance(aci_str_list,tuple)): + aci_str_list = [aci_str_list] + + for aci_str in aci_str_list: + try: + old_aci = ipa.aci.ACI(aci_str) + if old_aci.name == new_aci.name: + turbogears.flash("Delgate add failed: a delegation of that name already exists") + return dict(form=delegate_form, delegate=kw, + tg_template='ipagui.templates.delegatenew') + except SyntaxError: + # ignore aci_str's that ACI can't parse + pass + # not pulling down existing aci attributes aci_entry = client.get_aci_entry(['dn']) @@ -75,7 +99,7 @@ class DelegationController(IPAController): client.update_entry(aci_entry) except ipaerror.IPAError, e: - turbogears.flash("Delgate add failed: " + str(e)) + turbogears.flash("Delgate add failed: " + str(e) + "
" + e.detail[0]['desc']) return dict(form=delegate_form, delegate=kw, tg_template='ipagui.templates.delegatenew') @@ -83,7 +107,7 @@ class DelegationController(IPAController): raise turbogears.redirect('/delegate/list') @expose("ipagui.templates.delegateedit") - @identity.require(identity.not_anonymous()) + @identity.require(identity.in_group("admins")) def edit(self, acistr, tg_errors=None): """Display delegate page""" if tg_errors: @@ -105,12 +129,12 @@ class DelegationController(IPAController): return dict(form=delegate_form, delegate=delegate) except (SyntaxError, ipaerror.IPAError), e: - turbogears.flash("Delegation edit failed: " + str(e)) + turbogears.flash("Delegation edit failed: " + str(e) + "
" + e.detail[0]['desc']) raise turbogears.redirect('/delegate/list') @expose() - @identity.require(identity.not_anonymous()) + @identity.require(identity.in_group("admins")) def update(self, **kw): """Display delegate page""" self.restrict_post() @@ -162,7 +186,7 @@ class DelegationController(IPAController): turbogears.flash("delegate updated") raise turbogears.redirect('/delegate/list') except (SyntaxError, ipaerror.IPAError), e: - turbogears.flash("Delegation update failed: " + str(e)) + turbogears.flash("Delegation update failed: " + str(e) + "
" + e.detail[0]['desc']) return dict(form=delegate_form, delegate=kw, tg_template='ipagui.templates.delegateedit') @@ -175,7 +199,7 @@ class DelegationController(IPAController): try: aci_entry = client.get_aci_entry(aci_fields) except ipaerror.IPAError, e: - turbogears.flash("Delegation list failed: " + str(e)) + turbogears.flash("Delegation list failed: " + str(e) + "
" + e.detail[0]['desc']) raise turbogears.redirect('/') aci_str_list = aci_entry.getValues('aci') @@ -194,6 +218,7 @@ class DelegationController(IPAController): pass group_dn_to_cn = ipa.aci.extract_group_cns(aci_list, client) + aci_list = sorted(aci_list, key=operator.itemgetter(0)) # The list page needs to display field labels, not raw # LDAP attributes for aci in aci_list: @@ -205,7 +230,7 @@ class DelegationController(IPAController): fields=ipagui.forms.delegate.DelegateFields()) @expose() - @identity.require(identity.not_anonymous()) + @identity.require(identity.in_group("admins")) def delete(self, acistr): """Display delegate page""" self.restrict_post() @@ -237,7 +262,7 @@ class DelegationController(IPAController): turbogears.flash("delegate deleted") raise turbogears.redirect('/delegate/list') except (SyntaxError, ipaerror.IPAError), e: - turbogears.flash("Delegation deletion failed: " + str(e)) + turbogears.flash("Delegation deletion failed: " + str(e) + "
" + e.detail[0]['desc']) raise turbogears.redirect('/delegate/list') @expose("ipagui.templates.delegategroupsearch") diff --git a/ipa-server/ipa-gui/ipagui/subcontrollers/group.py b/ipa-server/ipa-gui/ipagui/subcontrollers/group.py index f0574a21c..dbcc77b9a 100644 --- a/ipa-server/ipa-gui/ipagui/subcontrollers/group.py +++ b/ipa-server/ipa-gui/ipagui/subcontrollers/group.py @@ -22,7 +22,7 @@ log = logging.getLogger(__name__) group_new_form = ipagui.forms.group.GroupNewForm() group_edit_form = ipagui.forms.group.GroupEditForm() -group_fields = ['*'] +group_fields = ['*', 'nsAccountLock'] class GroupController(IPAController): @@ -37,7 +37,7 @@ class GroupController(IPAController): raise turbogears.redirect("/group/list") @expose("ipagui.templates.groupnew") - @identity.require(identity.not_anonymous()) + @identity.require(identity.in_group("admins")) def new(self, tg_errors=None): """Displays the new group form""" if tg_errors: @@ -49,7 +49,7 @@ class GroupController(IPAController): return dict(form=group_new_form, group={}) @expose() - @identity.require(identity.not_anonymous()) + @identity.require(identity.in_group("admins")) def create(self, **kw): """Creates a new group""" self.restrict_post() @@ -75,13 +75,16 @@ class GroupController(IPAController): new_group.setValue('description', kw.get('description')) rv = client.add_group(new_group) + + if kw.get('nsAccountLock'): + client.mark_group_inactive(kw.get('cn')) except ipaerror.exception_for(ipaerror.LDAP_DUPLICATE): turbogears.flash("Group with name '%s' already exists" % kw.get('cn')) return dict(form=group_new_form, group=kw, tg_template='ipagui.templates.groupnew') except ipaerror.IPAError, e: - turbogears.flash("Group add failed: " + str(e) + "
" + str(e.detail)) + turbogears.flash("Group add failed: " + str(e) + "
" + e.detail[0]['desc']) return dict(form=group_new_form, group=kw, tg_template='ipagui.templates.groupnew') @@ -90,7 +93,11 @@ class GroupController(IPAController): # on any error, we redirect to the _edit_ group page. # this code does data setup, similar to groupedit() # - group = client.get_entry_by_cn(kw['cn'], group_fields) + if isinstance(kw['cn'], list): + cn0 = kw['cn'][0] + else: + cn0 = kw['cn'] + group = client.get_entry_by_cn(cn0, group_fields) group_dict = group.toDict() member_dicts = [] @@ -166,7 +173,7 @@ class GroupController(IPAController): @expose("ipagui.templates.groupedit") - @identity.require(identity.not_anonymous()) + @identity.require(identity.in_group("admins")) def edit(self, cn, tg_errors=None): """Displays the edit group form""" if tg_errors: @@ -204,20 +211,31 @@ class GroupController(IPAController): raise turbogears.redirect('/group/show', uid=cn) @expose() - @identity.require(identity.not_anonymous()) + @identity.require(identity.in_group("admins")) def update(self, **kw): """Updates an existing group""" self.restrict_post() client = self.get_ipaclient() if kw.get('submit') == 'Cancel Edit': + orig_group_dict = loads(b64decode(kw.get('group_orig'))) + # if cancelling need to use the original group because the one + # in kw may not exist yet. + cn = orig_group_dict.get('cn') + if (isinstance(cn,str)): + cn = [cn] turbogears.flash("Edit group cancelled") - raise turbogears.redirect('/group/show', cn=kw.get('cn')) + raise turbogears.redirect('/group/show', cn=cn[0]) + + if kw.get('editprotected') == '': + # if editprotected set these don't get sent in kw + orig_group_dict = loads(b64decode(kw.get('group_orig'))) + kw['cn'] = orig_group_dict['cn'] + kw['gidnumber'] = orig_group_dict['gidnumber'] # Decode the member data, in case we need to round trip member_dicts = loads(b64decode(kw.get('member_data'))) - tg_errors, kw = self.groupupdatevalidate(**kw) if tg_errors: turbogears.flash("There were validation errors.
" + @@ -242,6 +260,20 @@ class GroupController(IPAController): if new_group.gidnumber != new_gid: group_modified = True new_group.setValue('gidnumber', new_gid) + else: + new_group.setValue('gidnumber', orig_group_dict.get('gidnumber')) + new_group.setValue('cn', orig_group_dict.get('cn')) + if new_group.cn != kw.get('cn'): + group_modified = True + new_group.setValue('cn', kw['cn']) + + if group_modified: + rv = client.update_group(new_group) + # + # If the group update succeeds, but below operations fail, we + if new_group.cn != kw.get('cn'): + group_modified = True + new_group.setValue('cn', kw['cn']) if group_modified: rv = client.update_group(new_group) @@ -252,10 +284,21 @@ class GroupController(IPAController): # kw['group_orig'] = b64encode(dumps(new_group.toDict())) except ipaerror.IPAError, e: - turbogears.flash("Group update failed: " + str(e)) + turbogears.flash("Group update failed: " + str(e) + "
" + e.detail[0]['desc']) return dict(form=group_edit_form, group=kw, members=member_dicts, tg_template='ipagui.templates.groupedit') + if kw.get('nsAccountLock') == '': + kw['nsAccountLock'] = "false" + + modify_no_update = False + if kw.get('nsAccountLock') == "false" and new_group.getValues('nsaccountlock') == "true": + client.mark_group_active(kw.get('cn')) + modify_no_update = True + elif kw.get('nsAccountLock') == "true" and new_group.nsaccountlock != "true": + client.mark_group_inactive(kw.get('cn')) + modify_no_update = True + # # Add members # @@ -268,8 +311,9 @@ class GroupController(IPAController): failed_adds = client.add_members_to_group( utf8_encode_values(dnadds), new_group.dn) kw['dnadd'] = failed_adds + group_modified = True except ipaerror.IPAError, e: - turbogears.flash("Group update failed: " + str(e)) + turbogears.flash("Group update failed: " + str(e) + "
" + e.detail[0]['desc']) return dict(form=group_edit_form, group=kw, members=member_dicts, tg_template='ipagui.templates.groupedit') @@ -285,8 +329,9 @@ class GroupController(IPAController): failed_dels = client.remove_members_from_group( utf8_encode_values(dndels), new_group.dn) kw['dndel'] = failed_dels + group_modified = True except ipaerror.IPAError, e: - turbogears.flash("Group update failed: " + str(e)) + turbogears.flash("Group update failed: " + str(e) + "
" + e.detail[0]['desc']) return dict(form=group_edit_form, group=kw, members=member_dicts, tg_template='ipagui.templates.groupedit') @@ -308,8 +353,15 @@ class GroupController(IPAController): return dict(form=group_edit_form, group=kw, members=member_dicts, tg_template='ipagui.templates.groupedit') - turbogears.flash("%s updated!" % kw['cn']) - raise turbogears.redirect('/group/show', cn=kw['cn']) + if isinstance(kw['cn'], list): + cn0 = kw['cn'][0] + else: + cn0 = kw['cn'] + if group_modified == True or modify_no_update == True: + turbogears.flash("%s updated!" % cn0) + else: + turbogears.flash("No modifications requested.") + raise turbogears.redirect('/group/show', cn=cn0) @expose("ipagui.templates.grouplist") @@ -330,7 +382,7 @@ class GroupController(IPAController): turbogears.flash("These results are truncated.
" + "Please refine your search and try again.") except ipaerror.IPAError, e: - turbogears.flash("Find groups failed: " + str(e)) + turbogears.flash("Find groups failed: " + str(e) + "
" + e.detail[0]['desc']) raise turbogears.redirect("/group/list") return dict(groups=groups, criteria=criteria, @@ -374,7 +426,7 @@ class GroupController(IPAController): turbogears.flash("group deleted") raise turbogears.redirect('/group/list') except (SyntaxError, ipaerror.IPAError), e: - turbogears.flash("Group deletion failed: " + str(e) + "
" + str(e.detail)) + turbogears.flash("Group deletion failed: " + str(e) + "
" + e.detail[0]['desc']) raise turbogears.redirect('/group/list') @validate(form=group_new_form) diff --git a/ipa-server/ipa-gui/ipagui/subcontrollers/ipapolicy.py b/ipa-server/ipa-gui/ipagui/subcontrollers/ipapolicy.py new file mode 100644 index 000000000..781ca35d4 --- /dev/null +++ b/ipa-server/ipa-gui/ipagui/subcontrollers/ipapolicy.py @@ -0,0 +1,168 @@ +import os +from pickle import dumps, loads +from base64 import b64encode, b64decode +import copy +import logging + +import cherrypy +import turbogears +from turbogears import controllers, expose, flash +from turbogears import validators, validate +from turbogears import widgets, paginate +from turbogears import error_handler +from turbogears import identity + +from ipacontroller import IPAController +from ipa.entity import utf8_encode_values +from ipa import ipaerror +import ipa.entity +import ipagui.forms.ipapolicy + +import ldap.dn + +log = logging.getLogger(__name__) + +ipapolicy_edit_form = ipagui.forms.ipapolicy.IPAPolicyForm() + +class IPAPolicyController(IPAController): + + @expose() + @identity.require(identity.in_group("admins")) + def index(self): + raise turbogears.redirect("/ipapolicy/show") + + @expose("ipagui.templates.ipapolicyshow") + @identity.require(identity.in_group("admins")) + def show(self, tg_errors=None): + """Displays the one policy page""" + client = self.get_ipaclient() + config = client.get_ipa_config() + ipapolicy = config.toDict() + + ppolicy = client.get_password_policy() + password = ppolicy.toDict() + + return dict(ipapolicy=ipapolicy,password=password,fields=ipagui.forms.ipapolicy.IPAPolicyFields()) + + @expose("ipagui.templates.ipapolicyedit") + @identity.require(identity.in_group("admins")) + def edit(self, tg_errors=None): + """Displays the edit IPA policy form""" + if tg_errors: + turbogears.flash("There were validation errors.
" + + "Please see the messages below for details.") + + try: + client = self.get_ipaclient() + config = client.get_ipa_config() + ipapolicy_dict = config.toDict() + + ppolicy = client.get_password_policy() + password_dict = ppolicy.toDict() + + # store a copy of the original policy for the update later + ipapolicy_data = b64encode(dumps(ipapolicy_dict)) + ipapolicy_dict['ipapolicy_orig'] = ipapolicy_data + + # store a copy of the original policy for the update later + password_data = b64encode(dumps(password_dict)) + password_dict['password_orig'] = password_data + + # Combine the 2 dicts to make the form easier + ipapolicy_dict.update(password_dict) + + return dict(form=ipapolicy_edit_form, ipapolicy=ipapolicy_dict) + except ipaerror.IPAError, e: + turbogears.flash("IPA Policy edit failed: " + str(e) + "
" + str(e.detail)) + raise turbogears.redirect('/ipapolicy/show') + + + @expose() + @identity.require(identity.in_group("admins")) + def update(self, **kw): + """Display delegate page""" + self.restrict_post() + client = self.get_ipaclient() + + if kw.get('submit', '').startswith('Cancel'): + turbogears.flash("Edit policy cancelled") + raise turbogears.redirect('/ipapolicy/show') + + tg_errors, kw = self.ipapolicyupdatevalidate(**kw) + if tg_errors: + turbogears.flash("There were validation errors.
" + + "Please see the messages below for details.") + return dict(form=ipapolicy_edit_form, ipapolicy=kw, + tg_template='ipagui.templates.ipapolicyedit') + + policy_modified = False + password_modified = False + + try: + orig_ipapolicy_dict = loads(b64decode(kw.get('ipapolicy_orig'))) + orig_password_dict = loads(b64decode(kw.get('password_orig'))) + + new_ipapolicy = ipa.entity.Entity(orig_ipapolicy_dict) + new_password = ipa.entity.Entity(orig_password_dict) + + if str(new_ipapolicy.ipasearchtimelimit) != str(kw.get('ipasearchtimelimit')): + policy_modified = True + new_ipapolicy.setValue('ipasearchtimelimit', kw.get('ipasearchtimelimit')) + if str(new_ipapolicy.ipasearchrecordslimit) != str(kw.get('ipasearchrecordslimit')): + policy_modified = True + new_ipapolicy.setValue('ipasearchrecordslimit', kw.get('ipasearchrecordslimit')) + if new_ipapolicy.ipausersearchfields != kw.get('ipausersearchfields'): + policy_modified = True + new_ipapolicy.setValue('ipausersearchfields', kw.get('ipausersearchfields')) + if new_ipapolicy.ipagroupsearchfields != kw.get('ipagroupsearchfields'): + policy_modified = True + new_ipapolicy.setValue('ipagroupsearchfields', kw.get('ipagroupsearchfields')) + if str(new_ipapolicy.ipapwdexpadvnotify) != str(kw.get('ipapwdexpadvnotify')): + policy_modified = True + new_ipapolicy.setValue('ipapwdexpadvnotify', kw.get('ipapwdexpadvnotify')) + if str(new_ipapolicy.ipamaxusernamelength) != str(kw.get('ipamaxusernamelength')): + policy_modified = True + new_ipapolicy.setValue('ipamaxusernamelength', kw.get('ipamaxusernamelength')) + if new_ipapolicy.ipahomesrootdir != kw.get('ipahomesrootdir'): + policy_modified = True + new_ipapolicy.setValue('ipahomesrootdir', kw.get('ipahomesrootdir')) + if new_ipapolicy.ipadefaultloginshell != kw.get('ipadefaultloginshell'): + policy_modified = True + new_ipapolicy.setValue('ipadefaultloginshell', kw.get('ipadefaultloginshell')) + if new_ipapolicy.ipadefaultprimarygroup != kw.get('ipadefaultprimarygroup'): + policy_modified = True + new_ipapolicy.setValue('ipadefaultprimarygroup', kw.get('ipadefaultprimarygroup')) + + if policy_modified: + rv = client.update_ipa_config(new_ipapolicy) + + # Now check the password policy for updates + if str(new_password.krbmaxpwdlife) != str(kw.get('krbmaxpwdlife')): + password_modified = True + new_password.setValue('krbmaxpwdlife', str(kw.get('krbmaxpwdlife'))) + if str(new_password.krbminpwdlife) != str(kw.get('krbminpwdlife')): + password_modified = True + new_password.setValue('krbminpwdlife', str(kw.get('krbminpwdlife'))) + if str(new_password.krbpwdhistorylength) != str(kw.get('krbpwdhistorylength')): + password_modified = True + new_password.setValue('krbpwdhistorylength', str(kw.get('krbpwdhistorylength'))) + if str(new_password.krbpwdmindiffchars) != str(kw.get('krbpwdmindiffchars')): + password_modified = True + new_password.setValue('krbpwdmindiffchars', str(kw.get('krbpwdmindiffchars'))) + if str(new_password.krbpwdminlength) != str(kw.get('krbpwdminlength')): + password_modified = True + new_password.setValue('krbpwdminlength', str(kw.get('krbpwdminlength'))) + if password_modified: + rv = client.update_password_policy(new_password) + + turbogears.flash("IPA Policy updated") + raise turbogears.redirect('/ipapolicy/show') + except ipaerror.IPAError, e: + turbogears.flash("Policy update failed: " + str(e) + e.detail[0]['desc']) + return dict(form=ipapolicy_edit_form, ipapolicy=kw, + tg_template='ipagui.templates.ipapolicyedit') + + @validate(form=ipapolicy_edit_form) + @identity.require(identity.not_anonymous()) + def ipapolicyupdatevalidate(self, tg_errors=None, **kw): + return tg_errors, kw diff --git a/ipa-server/ipa-gui/ipagui/subcontrollers/policy.py b/ipa-server/ipa-gui/ipagui/subcontrollers/policy.py new file mode 100644 index 000000000..1f2e45876 --- /dev/null +++ b/ipa-server/ipa-gui/ipagui/subcontrollers/policy.py @@ -0,0 +1,32 @@ +import os +from pickle import dumps, loads +from base64 import b64encode, b64decode +import copy +import logging + +import cherrypy +import turbogears +from turbogears import controllers, expose, flash +from turbogears import validators, validate +from turbogears import widgets, paginate +from turbogears import error_handler +from turbogears import identity + +from ipacontroller import IPAController +from ipa.entity import utf8_encode_values +from ipa import ipaerror + +import ldap.dn + +log = logging.getLogger(__name__) + +class PolicyController(IPAController): + + @expose("ipagui.templates.policyindex") + @identity.require(identity.in_group("admins")) + def index(self, tg_errors=None): + """Displays the one policy page""" + + # TODO: return a dict of the items and URLs to display on + # Manage Policy + return dict() diff --git a/ipa-server/ipa-gui/ipagui/subcontrollers/user.py b/ipa-server/ipa-gui/ipagui/subcontrollers/user.py index d328052b1..39343b595 100644 --- a/ipa-server/ipa-gui/ipagui/subcontrollers/user.py +++ b/ipa-server/ipa-gui/ipagui/subcontrollers/user.py @@ -34,26 +34,48 @@ class UserController(IPAController): def __init__(self, *args, **kw): super(UserController,self).__init__(*args, **kw) - self.load_custom_fields() +# self.load_custom_fields() def load_custom_fields(self): - # client = self.get_ipaclient() - # schema = client.get_user_custom_schema() - schema = [ - { 'label': 'See Also', - 'field': 'seeAlso', - 'required': 'true', } , - { 'label': 'O O O', - 'field': 'o', - 'required': 'false', } , - ] + + client = self.get_ipaclient() + schema = client.get_custom_fields() + + # FIXME: Don't load from LDAP every single time it is called + + # FIXME: Is removing the attributes on the fly thread-safe? Do we + # need to lock here? for s in schema: required=False - if (s['required'] == "true"): + if (s['required'].lower() == "true"): required=True field = widgets.TextField(name=s['field'],label=s['label']) validator = validators.String(not_empty=required) + # Don't allow dupes on the new form + try: + for i in range(len(user_new_form.custom_fields)): + if user_new_form.custom_fields[i].name == s['field']: + user_new_form.custom_fields.pop(i) + except: + pass + + # Don't allow dupes on the edit form + try: + for i in range(len(user_edit_form.custom_fields)): + if user_edit_form.custom_fields[i].name == s['field']: + user_edit_form.custom_fields.pop(i) + except: + pass + + # Don't allow dupes in the list of user fields + try: + for i in range(len(ipagui.forms.user.UserFields.custom_fields)): + if ipagui.forms.user.UserFields.custom_fields[i].name == s['field']: + ipagui.forms.user.UserFields.custom_fields.pop(i) + except: + pass + ipagui.forms.user.UserFields.custom_fields.append(field) user_new_form.custom_fields.append(field) user_edit_form.custom_fields.append(field) @@ -61,15 +83,45 @@ class UserController(IPAController): user_new_form.validator.add_field(s['field'], validator) user_edit_form.validator.add_field(s['field'], validator) + def setup_mv_fields(self, field, fieldname): + """Given a field (must be a list) and field name, convert that + field into a list of dictionaries of the form: + [ { fieldname : v1}, { fieldname : v2 }, .. ] + + This is how we pre-fill values for multi-valued fields. + """ + mvlist = [] + if field is not None: + for v in field: + mvlist.append({ fieldname : v } ) + else: + # We need to return an empty value so something can be + # displayed on the edit page. Otherwise only an Add link + # will show, not an empty field. + mvlist.append({ fieldname : '' } ) + return mvlist + + def fix_incoming_fields(self, fields, fieldname, multifieldname): + """This is called by the update() function. It takes the incoming + list of dictionaries and converts it into back into the original + field, then removes the multiple field. + """ + fields[fieldname] = [] + for i in range(len(fields[multifieldname])): + fields[fieldname].append(fields[multifieldname][i][fieldname]) + del(fields[multifieldname]) + + return fields @expose() def index(self): raise turbogears.redirect("/user/list") @expose("ipagui.templates.usernew") - @identity.require(identity.not_anonymous()) + @identity.require(identity.in_any_group("admins","editors")) def new(self, tg_errors=None): """Displays the new user form""" + self.load_custom_fields() if tg_errors: turbogears.flash("There were validation errors.
" + "Please see the messages below for details.") @@ -77,7 +129,7 @@ class UserController(IPAController): return dict(form=user_new_form, user={}) @expose() - @identity.require(identity.not_anonymous()) + @identity.require(identity.in_any_group("admins","editors")) def create(self, **kw): """Creates a new user""" self.restrict_post() @@ -88,6 +140,15 @@ class UserController(IPAController): raise turbogears.redirect('/user/list') tg_errors, kw = self.usercreatevalidate(**kw) + + # Fix incoming multi-valued fields we created for the form + kw = self.fix_incoming_fields(kw, 'cn', 'cns') + kw = self.fix_incoming_fields(kw, 'telephonenumber', 'telephonenumbers') + kw = self.fix_incoming_fields(kw, 'facsimiletelephonenumber', 'facsimiletelephonenumbers') + kw = self.fix_incoming_fields(kw, 'mobile', 'mobiles') + kw = self.fix_incoming_fields(kw, 'pager', 'pagers') + kw = self.fix_incoming_fields(kw, 'homephone', 'homephones') + if tg_errors: turbogears.flash("There were validation errors.
" + "Please see the messages below for details.") @@ -136,21 +197,21 @@ class UserController(IPAController): new_user.setValue('carlicense', kw.get('carlicense')) new_user.setValue('labeleduri', kw.get('labeleduri')) - if kw.get('nsAccountLock'): - new_user.setValue('nsAccountLock', 'true') - for custom_field in user_new_form.custom_fields: new_user.setValue(custom_field.name, kw.get(custom_field.name, '')) rv = client.add_user(new_user) + + if kw.get('nsAccountLock'): + client.mark_user_inactive(kw.get('uid')) except ipaerror.exception_for(ipaerror.LDAP_DUPLICATE): - turbogears.flash("Person with login '%s' already exists" % + turbogears.flash("User with login '%s' already exists" % kw.get('uid')) return dict(form=user_new_form, user=kw, tg_template='ipagui.templates.usernew') except ipaerror.IPAError, e: - turbogears.flash("User add failed: " + str(e)) + turbogears.flash("User add failed: " + str(e) + "
" + e.detail[0]['desc']) return dict(form=user_new_form, user=kw, tg_template='ipagui.templates.usernew') @@ -181,7 +242,7 @@ class UserController(IPAController): try: client.modifyPassword(user_dict['krbprincipalname'], "", kw.get('userpassword')) except ipaerror.IPAError, e: - message = "Person successfully created.
" + message = "User successfully created.
" message += "There was an error setting the password.
" turbogears.flash(message) return dict(form=user_edit_form, user=user_dict, @@ -204,7 +265,7 @@ class UserController(IPAController): failed_adds = dnadds if len(failed_adds) > 0: - message = "Person successfully created.
" + message = "User successfully created.
" message += "There was an error adding groups.
" message += "Failures have been preserved in the add/remove lists." turbogears.flash(message) @@ -243,6 +304,7 @@ class UserController(IPAController): @identity.require(identity.not_anonymous()) def edit(self, uid=None, principal=None, tg_errors=None): """Displays the edit user form""" + self.load_custom_fields() if tg_errors: turbogears.flash("There were validation errors.
" + "Please see the messages below for details.") @@ -259,6 +321,32 @@ class UserController(IPAController): turbogears.flash("User edit failed: No uid or principal provided") raise turbogears.redirect('/') user_dict = user.toDict() + + # Load potential multi-valued fields + if isinstance(user_dict['cn'], str): + user_dict['cn'] = [user_dict['cn']] + user_dict['cns'] = self.setup_mv_fields(user_dict['cn'], 'cn') + + if isinstance(user_dict.get('telephonenumber',''), str): + user_dict['telephonenumber'] = [user_dict.get('telephonenumber'),''] + user_dict['telephonenumbers'] = self.setup_mv_fields(user_dict.get('telephonenumber'), 'telephonenumber') + + if isinstance(user_dict.get('facsimiletelephonenumber',''), str): + user_dict['facsimiletelephonenumber'] = [user_dict.get('facsimiletelephonenumber'),''] + user_dict['facsimiletelephonenumbers'] = self.setup_mv_fields(user_dict.get('facsimiletelephonenumber'), 'facsimiletelephonenumber') + + if isinstance(user_dict.get('mobile',''), str): + user_dict['mobile'] = [user_dict.get('mobile'),''] + user_dict['mobiles'] = self.setup_mv_fields(user_dict.get('mobile'), 'mobile') + + if isinstance(user_dict.get('pager',''), str): + user_dict['pager'] = [user_dict.get('pager'),''] + user_dict['pagers'] = self.setup_mv_fields(user_dict.get('pager'), 'pager') + + if isinstance(user_dict.get('homephone',''), str): + user_dict['homephone'] = [user_dict.get('homephone'),''] + user_dict['homephones'] = self.setup_mv_fields(user_dict.get('homephone'), 'homephone') + # Edit shouldn't fill in the password field. if user_dict.has_key('userpassword'): del(user_dict['userpassword']) @@ -300,7 +388,7 @@ class UserController(IPAController): except ipaerror.IPAError, e: if uid is None: uid = principal - turbogears.flash("User edit failed: " + str(e)) + turbogears.flash("User edit failed: " + str(e) + "
" + e.detail[0]['desc']) raise turbogears.redirect('/user/show', uid=uid) @expose() @@ -314,6 +402,23 @@ class UserController(IPAController): turbogears.flash("Edit user cancelled") raise turbogears.redirect('/user/show', uid=kw.get('uid')) + # Fix incoming multi-valued fields we created for the form + kw = self.fix_incoming_fields(kw, 'cn', 'cns') + kw = self.fix_incoming_fields(kw, 'telephonenumber', 'telephonenumbers') + kw = self.fix_incoming_fields(kw, 'facsimiletelephonenumber', 'facsimiletelephonenumbers') + kw = self.fix_incoming_fields(kw, 'mobile', 'mobiles') + kw = self.fix_incoming_fields(kw, 'pager', 'pagers') + kw = self.fix_incoming_fields(kw, 'homephone', 'homephones') + + # admins and editors can update anybody. A user can only update + # themselves. We need this check because it is very easy to guess + # the edit URI. + if ((not 'admins' in turbogears.identity.current.groups and + not 'editors' in turbogears.identity.current.groups) and + (kw.get('uid') != turbogears.identity.current.display_name)): + turbogears.flash("You do not have permission to update this user.") + raise turbogears.redirect('/user/show', uid=kw.get('uid')) + # Decode the group data, in case we need to round trip user_groups_dicts = loads(b64decode(kw.get('user_groups_data'))) @@ -334,6 +439,14 @@ class UserController(IPAController): try: orig_user_dict = loads(b64decode(kw.get('user_orig'))) + # remove multi-valued fields we created for the form + del(orig_user_dict['cns']) + del(orig_user_dict['telephonenumbers']) + del(orig_user_dict['facsimiletelephonenumbers']) + del(orig_user_dict['mobiles']) + del(orig_user_dict['pagers']) + del(orig_user_dict['homephones']) + new_user = ipa.user.User(orig_user_dict) new_user.setValue('title', kw.get('title')) new_user.setValue('givenname', kw.get('givenname')) @@ -369,12 +482,6 @@ class UserController(IPAController): new_user.setValue('carlicense', kw.get('carlicense')) new_user.setValue('labeleduri', kw.get('labeleduri')) - - if kw.get('nsAccountLock'): - new_user.setValue('nsAccountLock', 'true') - else: - new_user.setValue('nsAccountLock', None) - if kw.get('editprotected') == 'true': if kw.get('userpassword'): password_change = True @@ -400,7 +507,7 @@ class UserController(IPAController): # too much work to figure out unless someone really screams pass except ipaerror.IPAError, e: - turbogears.flash("User update failed: " + str(e)) + turbogears.flash("User update failed: " + str(e) + "
" + e.detail[0]['desc']) return dict(form=user_edit_form, user=kw, user_groups=user_groups_dicts, tg_template='ipagui.templates.useredit') @@ -412,7 +519,7 @@ class UserController(IPAController): if password_change: rv = client.modifyPassword(kw['krbprincipalname'], "", kw.get('userpassword')) except ipaerror.IPAError, e: - turbogears.flash("User password change failed: " + str(e)) + turbogears.flash("User password change failed: " + str(e) + "
" + e.detail[0]['desc']) return dict(form=user_edit_form, user=kw, user_groups=user_groups_dicts, tg_template='ipagui.templates.useredit') @@ -459,6 +566,20 @@ class UserController(IPAController): user_groups=user_groups_dicts, tg_template='ipagui.templates.useredit') + if kw.get('nsAccountLock') == '': + kw['nsAccountLock'] = "false" + + try: + if kw.get('nsAccountLock') == "false" and new_user.getValues('nsaccountlock') == "true": + client.mark_user_active(kw.get('uid')) + elif kw.get('nsAccountLock') == "true" and new_user.nsaccountlock != "true": + client.mark_user_inactive(kw.get('uid')) + except ipaerror.IPAError, e: + turbogears.flash("User status change failed: " + str(e) + "
" + e.detail[0]['desc']) + return dict(form=user_edit_form, user=kw, + user_groups=user_groups_dicts, + tg_template='ipagui.templates.useredit') + turbogears.flash("%s updated!" % kw['uid']) raise turbogears.redirect('/user/show', uid=kw['uid']) @@ -481,7 +602,7 @@ class UserController(IPAController): turbogears.flash("These results are truncated.
" + "Please refine your search and try again.") except ipaerror.IPAError, e: - turbogears.flash("User list failed: " + str(e)) + turbogears.flash("User list failed: " + str(e) + "
" + e.detail[0]['desc']) raise turbogears.redirect("/user/list") return dict(users=users, uid=uid, fields=ipagui.forms.user.UserFields()) @@ -492,6 +613,7 @@ class UserController(IPAController): def show(self, uid): """Retrieve a single user for display""" client = self.get_ipaclient() + self.load_custom_fields() try: user = client.get_user_by_uid(uid, user_fields) @@ -523,7 +645,7 @@ class UserController(IPAController): user_groups=user_groups, user_reports=user_reports, user_manager=user_manager, user_secretary=user_secretary) except ipaerror.IPAError, e: - turbogears.flash("User show failed: " + str(e)) + turbogears.flash("User show failed: " + str(e) + "
" + e.detail[0]['desc']) raise turbogears.redirect("/") @expose() @@ -539,7 +661,7 @@ class UserController(IPAController): turbogears.flash("user deleted") raise turbogears.redirect('/user/list') except (SyntaxError, ipaerror.IPAError), e: - turbogears.flash("User deletion failed: " + str(e)) + turbogears.flash("User deletion failed: " + str(e) + "
" + e.detail[0]['desc']) raise turbogears.redirect('/user/list') @validate(form=user_new_form) @@ -661,7 +783,7 @@ class UserController(IPAController): users_counter = users[0] users = users[1:] except ipaerror.IPAError, e: - turbogears.flash("search failed: " + str(e)) + turbogears.flash("search failed: " + str(e) + "
" + e.detail[0]['desc']) return dict(users=users, criteria=criteria, which_select=kw.get('which_select'), diff --git a/ipa-server/ipa-gui/ipagui/templates/Makefile.am b/ipa-server/ipa-gui/ipagui/templates/Makefile.am index 18db5fffc..6626ad8c2 100644 --- a/ipa-server/ipa-gui/ipagui/templates/Makefile.am +++ b/ipa-server/ipa-gui/ipagui/templates/Makefile.am @@ -20,8 +20,13 @@ app_DATA = \ groupnewform.kid \ groupnew.kid \ groupshow.kid \ + ipapolicyeditform.kid \ + ipapolicyedit.kid \ + ipapolicyshow.kid \ loginfailed.kid \ master.kid \ + policyindex.kid \ + policylayout.kid \ usereditform.kid \ useredit.kid \ userlayout.kid \ diff --git a/ipa-server/ipa-gui/ipagui/templates/groupeditform.kid b/ipa-server/ipa-gui/ipagui/templates/groupeditform.kid index cab585fcc..6a5c5adb8 100644 --- a/ipa-server/ipa-gui/ipagui/templates/groupeditform.kid +++ b/ipa-server/ipa-gui/ipagui/templates/groupeditform.kid @@ -25,17 +25,22 @@ from ipagui.helpers import ipahelper + @@ -106,6 +112,16 @@ from ipagui.helpers import ipahelper + + +