diff options
author | John Dennis <jdennis@redhat.com> | 2011-09-26 10:39:15 -0400 |
---|---|---|
committer | Martin Kosek <mkosek@redhat.com> | 2011-11-29 13:30:57 +0100 |
commit | e1c1fcf5430da34f95afca40c7b7860684c1445b (patch) | |
tree | 4fae593dc2585598f694c4f919bada442148da1b /ipaserver/install/ldapupdate.py | |
parent | 1b0b9645d197f512eee61051775414ca35ee7f6d (diff) | |
download | freeipa-e1c1fcf5430da34f95afca40c7b7860684c1445b.tar.gz freeipa-e1c1fcf5430da34f95afca40c7b7860684c1445b.tar.xz freeipa-e1c1fcf5430da34f95afca40c7b7860684c1445b.zip |
Ticket #1879 - IPAdmin undefined anonymous parameter lists
The IPAdmin class in ipaserver/ipaldap.py has methods with anonymous
undefined parameter lists.
For example:
def getList(self,*args):
In Python syntax this means you can call getList with any positional
parameter list you want.
This is bad because:
1) It's not true, *args gets passed to an ldap function with a well
defined parameter list, so you really do have to call it with a
defined parameter list. *args will let you pass anything, but once it
gets passed to the ldap function it will blow up if the parameters do
not match (what parameters are those you're wondering? see item 2).
2) The programmer does not know what the valid parameters are unless
they are defined in the formal parameter list.
3) Without a formal parameter list automatic documentation generators
cannot produce API documentation (see item 2)
4) The Python interpreter cannot validate the parameters being passed
because there is no formal parameter list. Note, Python does not
validate the type of parameters, but it does validate the correct
number of postitional parameters are passed and only defined keyword
parameters are passed. Bypassing the language support facilities leads
to programming errors.
5) Without a formal parameter list program checkers such as pylint
cannot validate the program which leads to progamming errors.
6) Without a formal parameter list which includes default keyword
parameters it's not possible to use keyword arguments nor to know what
their default values are (see item 2). One is forced to pass a keyword
argument as a positional argument, plus you must then pass every
keyword argument between the end of the positional argument list and
keyword arg of interest even of the other keyword arguments are not of
interest. This also demands you know what the default value of the
intermediate keyword arguments are (see item 2) and hope they don't
change.
Also the *args anonymous tuple get passed into the error handling code
so it can report what the called values were. But because the tuple is
anonymous the error handler cannot not describe what it was passed. In
addition the error handling code makes assumptions about the possible
contents of the anonymous tuple based on current practice instead of
actual defined values. Things like "if the number of items in the
tuple is 2 or less then the first tuple item must be a dn
(Distinguished Name)" or "if the number of items in the tuple is
greater than 2 then the 3rd item must be an ldap search filter". These
are constructs which are not robust and will fail at some point in the
future.
This patch also fixes the use of IPAdmin.addEntry(). It was sometimes
being called with (dn, modlist), sometimes a Entry object, or
sometimes a Entity object. Now it's always called with either a Entry
or Entity object and IPAdmin.addEntry() validates the type of the
parameter passed.
Diffstat (limited to 'ipaserver/install/ldapupdate.py')
-rw-r--r-- | ipaserver/install/ldapupdate.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/ipaserver/install/ldapupdate.py b/ipaserver/install/ldapupdate.py index 575f22421..91d3d83cf 100644 --- a/ipaserver/install/ldapupdate.py +++ b/ipaserver/install/ldapupdate.py @@ -344,7 +344,7 @@ class LDAPUpdate: root_logger.debug("Task id: %s", dn) if self.live_run: - self.conn.addEntry(e.dn, e.toTupleList()) + self.conn.addEntry(e) return dn @@ -644,7 +644,7 @@ class LDAPUpdate: # addifexist may result in an entry with only a # dn defined. In that case there is nothing to do. # It means the entry doesn't exist, so skip it. - self.conn.addEntry(entry.dn, entry.toTupleList()) + self.conn.addEntry(entry) self.modified = True except Exception, e: root_logger.error("Add failure %s", e) |