diff options
-rw-r--r-- | ipa_server/servercore.py | 46 | ||||
-rw-r--r-- | ipalib/plugins/b_xmlrpc.py | 8 | ||||
-rw-r--r-- | ipalib/plugins/f_group.py | 3 | ||||
-rw-r--r-- | ipalib/plugins/f_user.py | 14 |
4 files changed, 61 insertions, 10 deletions
diff --git a/ipa_server/servercore.py b/ipa_server/servercore.py index 34008abe3..551c84e9a 100644 --- a/ipa_server/servercore.py +++ b/ipa_server/servercore.py @@ -17,9 +17,6 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -import sys -sys.path.insert(0, ".") -sys.path.insert(0, "..") import ldap from ipa_server.context import context import ipautil @@ -109,6 +106,43 @@ def get_entry_by_dn (dn, sattrs=None): # logging.info("IPA: get_entry_by_dn '%s'" % dn) return get_base_entry(dn, searchfilter, sattrs) +# User support + +def is_user_unique(uid): + """Return True if the uid is unique in the tree, False otherwise.""" + # FIXME +# uid = self.__safe_filter(uid) + searchfilter = "(&(uid=%s)(objectclass=posixAccount))" % uid + + try: + entry = get_sub_entry("cn=accounts," + basedn, searchfilter, ['dn','uid']) + return False +# except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND): + except Exception: + return True + +def uid_too_long(uid): + """Verify that the new uid is within the limits we set. This is a + very narrow test. + + Returns True if it is longer than allowed + False otherwise + """ + if not isinstance(uid,basestring) or len(uid) == 0: + # It is bad, but not too long + return False +# logging.debug("IPA: __uid_too_long(%s)" % uid) + try: + config = get_ipa_config() + maxlen = int(config.get('ipamaxusernamelength', 0)) + if maxlen > 0 and len(uid) > maxlen: + return True + except Exception, e: +# logging.debug("There was a problem " + str(e)) + pass + + return False + def update_entry (oldentry, newentry): """Update an LDAP entry @@ -130,10 +164,14 @@ def update_entry (oldentry, newentry): res = context.conn.getConn().updateEntry(moddn, oldentry, newentry) return res +def add_entry(entry): + """Add a new entry""" + return context.conn.getConn().addEntry(entry) + def uniq_list(x): """Return a unique list, preserving order and ignoring case""" myset = {} - return [set.setdefault(e.lower(),e) for e in x if e.lower() not in myset] + return [myset.setdefault(e.lower(),e) for e in x if e.lower() not in myset] def get_schema(): """Retrieves the current LDAP schema from the LDAP server.""" diff --git a/ipalib/plugins/b_xmlrpc.py b/ipalib/plugins/b_xmlrpc.py index f8dacf5d7..d7cbd8560 100644 --- a/ipalib/plugins/b_xmlrpc.py +++ b/ipalib/plugins/b_xmlrpc.py @@ -24,6 +24,7 @@ Lightwieght XML-RPC client using Python standard library xmlrpclib. """ import xmlrpclib +import socket from ipalib.backend import Backend from ipalib.util import xmlrpc_marshal from ipalib import api @@ -44,7 +45,10 @@ class xmlrpc(Backend): client = self.get_client() command = getattr(client, name) params = xmlrpc_marshal(*args, **kw) - return command(*params) -# return command(*args, **kw) + try: + return command(*params) + except socket.error, e: + print e[1] + return False api.register(xmlrpc) diff --git a/ipalib/plugins/f_group.py b/ipalib/plugins/f_group.py index 36cecc332..c5a37e725 100644 --- a/ipalib/plugins/f_group.py +++ b/ipalib/plugins/f_group.py @@ -28,7 +28,6 @@ from ipalib import api from ipa_server import servercore from ipa_server import ipaldap import ldap -from ipa_server.context import context class group(frontend.Object): @@ -82,7 +81,7 @@ class group_add(crud.Add): for g in group: entry.setValues(g, group[g]) - result = context.conn.getConn().addEntry(entry) + result = servercore.add_entry(entry) return result diff --git a/ipalib/plugins/f_user.py b/ipalib/plugins/f_user.py index 0e62b8336..49b6a3704 100644 --- a/ipalib/plugins/f_user.py +++ b/ipalib/plugins/f_user.py @@ -28,7 +28,6 @@ from ipalib import api from ipa_server import servercore from ipa_server import ipaldap import ldap -from ipa_server.context import context # Command to get the idea how plugins will interact with api.env class envtest(frontend.Command): @@ -94,6 +93,13 @@ class user_add(crud.Add): user['uid'] = args[0] + if not servercore.is_user_unique(user['uid']): + # FIXME, specific error + raise SyntaxError("user already exists") + if servercore.uid_too_long(user['uid']): + # FIXME, specific error + raise SyntaxError("uid is too long") + # dn is set here, not by the user try: del user['dn'] @@ -159,8 +165,12 @@ class user_add(crud.Add): for u in user: entry.setValues(u, user[u]) - result = context.conn.getConn().addEntry(entry) + result = servercore.add_entry(entry) return result + def forward(self, *args, **kw): + result = super(crud.Add, self).forward(*args, **kw) + if result != False: + print result api.register(user_add) |