summaryrefslogtreecommitdiffstats
path: root/ipa-python/config.py
diff options
context:
space:
mode:
authorSimo Sorce <ssorce@redhat.com>2007-12-11 10:58:39 -0500
committerSimo Sorce <ssorce@redhat.com>2007-12-11 10:58:39 -0500
commit3defaaf7bac1d48f5006713c5dc2aa226028f5b9 (patch)
treedea49a93d4686f2fb358d0dd2e3d4851bc185d86 /ipa-python/config.py
parentf796e50000e5c198a510300e2293ed460e7113aa (diff)
downloadfreeipa-3defaaf7bac1d48f5006713c5dc2aa226028f5b9.tar.gz
freeipa-3defaaf7bac1d48f5006713c5dc2aa226028f5b9.tar.xz
freeipa-3defaaf7bac1d48f5006713c5dc2aa226028f5b9.zip
Make admintools discover the domain using DNS calls to find the LDAP server.
Diffstat (limited to 'ipa-python/config.py')
-rw-r--r--ipa-python/config.py56
1 files changed, 51 insertions, 5 deletions
diff --git a/ipa-python/config.py b/ipa-python/config.py
index a17e585bc..c1a3915d0 100644
--- a/ipa-python/config.py
+++ b/ipa-python/config.py
@@ -20,6 +20,10 @@
import ConfigParser
from optparse import OptionParser
+import krbV
+import socket
+import ipa.dnsclient
+
class IPAConfigError(Exception):
def __init__(self, msg=''):
self.msg = msg
@@ -55,11 +59,51 @@ def __parse_config():
p.read("/etc/ipa/ipa.conf")
try:
- config.default_realm = p.get("defaults", "realm")
- config.default_server = p.get("defaults", "server")
+ if not config.default_realm:
+ config.default_realm = p.get("defaults", "realm")
+ if not config.default_server:
+ config.default_server = p.get("defaults", "server")
except:
pass
+def __discover_config():
+ try:
+ if not config.default_realm:
+ krbctx = krbV.default_context()
+ config.default_realm = krbctx.default_realm
+ if not config.default_realm:
+ return False
+
+ if not config.default_server:
+ #try once with REALM -> domain
+ name = "_ldap._tcp."+config.default_realm+"."
+ rs = ipa.dnsclient.query(name, ipa.dnsclient.DNS_C_IN, ipa.dnsclient.DNS_T_SRV)
+ rl = len(rs)
+
+ #try cycling on domain components of FQDN
+ if rl == 0:
+ name = socket.getfqdn()
+ while rl == 0:
+ tok = name.find(".")
+ if tok == -1:
+ return False
+ name = name[tok+1:]
+ q = "_ldap._tcp." + name + "."
+ rs = ipa.dnsclient.query(q, ipa.dnsclient.DNS_C_IN, ipa.dnsclient.DNS_T_SRV)
+ rl = len(rs)
+
+ for r in rs:
+ if r.dns_type == ipa.dnsclient.DNS_T_SRV:
+ rsrv = r.rdata.server.rstrip(".")
+ # we take only the first one returned for now
+ config.default_server = rsrv
+ return True
+
+ #if none found
+ return False
+ except:
+ return False
+
def usage():
return """ --realm\tset the IPA realm
--server\tset the IPA server
@@ -92,15 +136,17 @@ def __parse_args(args):
def init_config(args=None):
- __parse_config()
out_args = None
if args:
out_args = __parse_args(args)
+ __discover_config()
+ __parse_config()
+
if not config.default_realm:
- raise IPAConfigError("realm not specified in config file or on command line")
+ raise IPAConfigError("realm not found, nor specified in config file or on command line")
if not config.default_server:
- raise IPAConfigError("server not specified in config file or on command line")
+ raise IPAConfigError("server not found, nor specified in config file or on command line")
if out_args:
return out_args