summaryrefslogtreecommitdiffstats
path: root/ipapython
diff options
context:
space:
mode:
authorMartin Kosek <mkosek@redhat.com>2011-09-30 09:14:57 +0200
committerMartin Kosek <mkosek@redhat.com>2011-09-30 16:54:30 +0200
commit848d37c092979b3fde08f8d228b039672525c0b2 (patch)
treee05b11bf1061810d62fd9663871b90b284e8d9e3 /ipapython
parent8fb70fd24938f9106821f323ae8557a9bc814846 (diff)
downloadfreeipa.git-848d37c092979b3fde08f8d228b039672525c0b2.tar.gz
freeipa.git-848d37c092979b3fde08f8d228b039672525c0b2.tar.xz
freeipa.git-848d37c092979b3fde08f8d228b039672525c0b2.zip
ipa-client assumes a single namingcontext
When LDAP server contains more that one suffixes, the ipa client installation does not detect it as IPA server and fails to install. Fix ipa server discovery so that it correctly searches all naming contexts for the IPA one. https://fedorahosted.org/freeipa/ticket/1868
Diffstat (limited to 'ipapython')
-rw-r--r--ipapython/ipautil.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index 490981a4..cfc979ed 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -22,6 +22,8 @@ PLUGINS_SHARE_DIR = "/usr/share/ipa/plugins"
GEN_PWD_LEN = 12
+IPA_BASEDN_INFO = 'ipa v2.0'
+
import string
import tempfile
import logging
@@ -33,6 +35,7 @@ import stat
import shutil
import urllib2
import socket
+import ldap
from ipapython import ipavalidate
from types import *
@@ -1127,3 +1130,36 @@ def bind_port_responder(port, socket_stream=True, socket_timeout=None, responder
finally:
s.close()
+def get_ipa_basedn(conn):
+ """
+ Get base DN of IPA suffix in given LDAP server.
+
+ None is returned if the suffix is not found
+
+ :param conn: Bound LDAP connection that will be used for searching
+ """
+ entries = conn.search_ext_s(
+ '', scope=ldap.SCOPE_BASE, attrlist=['namingcontexts']
+ )
+
+ contexts = entries[0][1]['namingcontexts']
+ for context in contexts:
+ logging.debug("Check if naming context '%s' is for IPA" % context)
+ try:
+ entry = conn.search_s(context, ldap.SCOPE_BASE, "(info=IPA*)")
+ except ldap.NO_SUCH_OBJECT:
+ logging.debug("LDAP server did not return info attribute to check for IPA version")
+ continue
+ if len(entry) == 0:
+ logging.debug("Info attribute with IPA server version not found")
+ continue
+ info = entry[0][1]['info'][0].lower()
+ if info != IPA_BASEDN_INFO:
+ logging.debug("Detected IPA server version (%s) did not match the client (%s)" \
+ % (info, IPA_BASEDN_INFO))
+ continue
+ logging.debug("Naming context '%s' is a valid IPA context" % context)
+ return context
+
+ return None
+