Fix client discovery and make sure command line options are not overwritten

with discovered options, just verified.
This commit is contained in:
Simo Sorce 2008-04-09 15:55:46 -04:00
parent 3e47b48068
commit 24a7cf3714

View File

@ -43,6 +43,9 @@ def parse_options():
options, args = parser.parse_args() options, args = parser.parse_args()
if (options.server and not options.domain):
parser.error("--server cannot be used without providing --domain")
return options return options
def ask_for_confirmation(message): def ask_for_confirmation(message):
@ -110,6 +113,11 @@ def main():
if options.uninstall: if options.uninstall:
return uninstall(options) return uninstall(options)
cli_domain = None
cli_server = None
cli_realm = None
cli_basedn = None
# Create the discovery instance # Create the discovery instance
ds = ipaclient.ipadiscovery.IPADiscovery() ds = ipaclient.ipadiscovery.IPADiscovery()
@ -121,32 +129,38 @@ def main():
if ret == -1 or not ds.getDomainName(): if ret == -1 or not ds.getDomainName():
logging.debug("Domain not found") logging.debug("Domain not found")
if options.domain: if options.domain:
dom = options.domain cli_domain = options.domain
elif options.unattended: elif options.unattended:
return ret return ret
else: else:
print "Failed to determine your DNS domain (DNS misconfigured?)" print "Failed to determine your DNS domain (DNS misconfigured?)"
dom = "" cli_domain = ""
while dom == "": while cli_domain == "":
dom = raw_input("Please provide your domain name (ex: example.com): ") cli_domain = raw_input("Please provide your domain name (ex: example.com): ")
ret = ds.search(domain=dom) ret = ds.search(domain=cli_domain, server=options.server)
dom = ds.getDomainName() if not cli_domain:
if ds.getDomainName():
cli_domain = ds.getDomainName()
if ret == -2 or not ds.getServerName(): if ret == -2 or not ds.getServerName():
dnsok = False dnsok = False
logging.debug("IPA Server not found") logging.debug("IPA Server not found")
if options.server: if options.server:
srv = options.server cli_server = options.server
elif options.unattended: elif options.unattended:
return ret return ret
else: else:
print "Failed to find the IPA Server (DNS misconfigured?)" print "Failed to find the IPA Server (DNS misconfigured?)"
srv = "" cli_server = ""
while srv == "": while cli_server == "":
srv = raw_input("Please provide your server name (ex: ipa.example.com): ") cli_server = raw_input("Please provide your server name (ex: ipa.example.com): ")
ret = ds.search(domain=dom, server=srv) ret = ds.search(domain=cli_domain, server=cli_server)
srv = ds.getServerName() if not cli_server:
if ds.getServerName():
cli_server = ds.getServerName()
if ret != 0: if ret != 0:
print "Failed to verify that "+srv+" is an IPA Server." print "Failed to verify that "+cli_server+" is an IPA Server."
print "This may mean that the remote server is not up or is not reachable" print "This may mean that the remote server is not up or is not reachable"
print "due to network or firewall settings." print "due to network or firewall settings."
return ret return ret
@ -168,10 +182,13 @@ def main():
print "ERROR: The provided realm name: ["+options.realm_name+"] does not match with the discovered one: ["+ds.getRealmName()+"]\n" print "ERROR: The provided realm name: ["+options.realm_name+"] does not match with the discovered one: ["+ds.getRealmName()+"]\n"
return -3 return -3
print "Realm: "+ds.getRealmName() cli_realm = ds.getRealmName()
print "DNS Domain: "+ds.getDomainName() cli_basedn = ds.getBaseDN()
print "IPA Server: "+ds.getServerName()
print "BaseDN: "+ds.getBaseDN() print "Realm: "+cli_realm
print "DNS Domain: "+cli_domain
print "IPA Server: "+cli_server
print "BaseDN: "+cli_basedn
print "\n" print "\n"
if not options.unattended and not ask_for_confirmation("Continue to configure the system with these values?"): if not options.unattended and not ask_for_confirmation("Continue to configure the system with these values?"):
@ -186,8 +203,8 @@ def main():
{'name':'empty', 'type':'empty'}] {'name':'empty', 'type':'empty'}]
#[defaults] #[defaults]
defopts = [{'name':'server', 'type':'option', 'value':ds.getServerName()}, defopts = [{'name':'server', 'type':'option', 'value':cli_server},
{'name':'realm', 'type':'option', 'value':ds.getRealmName()}] {'name':'realm', 'type':'option', 'value':cli_realm}]
opts.append({'name':'defaults', 'type':'section', 'value':defopts}) opts.append({'name':'defaults', 'type':'section', 'value':defopts})
opts.append({'name':'empty', 'type':'empty'}) opts.append({'name':'empty', 'type':'empty'})
@ -203,10 +220,10 @@ def main():
opts = [{'name':'comment', 'type':'comment', 'value':'File modified by ipa-client-install'}, opts = [{'name':'comment', 'type':'comment', 'value':'File modified by ipa-client-install'},
{'name':'empty', 'type':'empty'}, {'name':'empty', 'type':'empty'},
{'name':'ldap_version', 'type':'option', 'value':'3'}, {'name':'ldap_version', 'type':'option', 'value':'3'},
{'name':'base', 'type':'option', 'value':ds.getBaseDN()}, {'name':'base', 'type':'option', 'value':cli_basedn},
{'name':'empty', 'type':'empty'}, {'name':'empty', 'type':'empty'},
{'name':'nss_base_passwd', 'type':'option', 'value':ds.getBaseDN()+'?sub'}, {'name':'nss_base_passwd', 'type':'option', 'value':cli_basedn+'?sub'},
{'name':'nss_base_group', 'type':'option', 'value':ds.getBaseDN()+'?sub'}, {'name':'nss_base_group', 'type':'option', 'value':cli_basedn+'?sub'},
{'name':'nss_schema', 'type':'option', 'value':'rfc2307bis'}, {'name':'nss_schema', 'type':'option', 'value':'rfc2307bis'},
{'name':'nss_map_attribute', 'type':'option', 'value':'uniqueMember member'}, {'name':'nss_map_attribute', 'type':'option', 'value':'uniqueMember member'},
{'name':'nss_initgroups_ignoreusers', 'type':'option', 'value':'root,dirsrv'}, {'name':'nss_initgroups_ignoreusers', 'type':'option', 'value':'root,dirsrv'},
@ -217,9 +234,9 @@ def main():
{'name':'timelimit', 'type':'option', 'value':'15'}, {'name':'timelimit', 'type':'option', 'value':'15'},
{'name':'empty', 'type':'empty'}] {'name':'empty', 'type':'empty'}]
if not dnsok or options.force or options.on_master: if not dnsok or options.force or options.on_master:
opts.append({'name':'uri', 'type':'option', 'value':'ldap://'+ds.getServerName()}) opts.append({'name':'uri', 'type':'option', 'value':'ldap://'+cli_server})
else: else:
opts.append({'name':'nss_srv_domain', 'type':'option', 'value':ds.getDomainName()}) opts.append({'name':'nss_srv_domain', 'type':'option', 'value':cli_domain})
opts.append({'name':'empty', 'type':'empty'}) opts.append({'name':'empty', 'type':'empty'})
try: try:
@ -234,7 +251,7 @@ def main():
krbctx = krbV.default_context() krbctx = krbV.default_context()
# If we find our domain assume we are properly configured # If we find our domain assume we are properly configured
#(ex. we are configuring the client side of a Master) #(ex. we are configuring the client side of a Master)
if not options.on_master and (not krbctx.default_realm == ds.getRealmName() or options.force): if not options.on_master and (not krbctx.default_realm == cli_realm or options.force):
#Configure krb5.conf #Configure krb5.conf
krbconf = ipaclient.ipachangeconf.IPAChangeConf("IPA Installer") krbconf = ipaclient.ipachangeconf.IPAChangeConf("IPA Installer")
@ -247,7 +264,7 @@ def main():
{'name':'empty', 'type':'empty'}] {'name':'empty', 'type':'empty'}]
#[libdefaults] #[libdefaults]
libopts = [{'name':'default_realm', 'type':'option', 'value':ds.getRealmName()}] libopts = [{'name':'default_realm', 'type':'option', 'value':cli_realm}]
if dnsok and not options.force: if dnsok and not options.force:
libopts.append({'name':'dns_lookup_realm', 'type':'option', 'value':'true'}) libopts.append({'name':'dns_lookup_realm', 'type':'option', 'value':'true'})
libopts.append({'name':'dns_lookup_kdc', 'type':'option', 'value':'true'}) libopts.append({'name':'dns_lookup_kdc', 'type':'option', 'value':'true'})
@ -263,16 +280,16 @@ def main():
#the following are necessary only if DNS discovery does not work #the following are necessary only if DNS discovery does not work
if not dnsok or options.force: if not dnsok or options.force:
#[realms] #[realms]
kropts =[{'name':'kdc', 'type':'option', 'value':ds.getServerName()+':88'}, kropts =[{'name':'kdc', 'type':'option', 'value':cli_server+':88'},
{'name':'admin_server', 'type':'option', 'value':ds.getServerName()+':749'}, {'name':'admin_server', 'type':'option', 'value':cli_server+':749'},
{'name':'default_domain', 'type':'option', 'value':ds.getDomainName()}] {'name':'default_domain', 'type':'option', 'value':cli_domain}]
ropts = [{'name':ds.getRealmName(), 'type':'subsection', 'value':kropts}] ropts = [{'name':cli_realm, 'type':'subsection', 'value':kropts}]
opts.append({'name':'realms', 'type':'section', 'value':ropts}) opts.append({'name':'realms', 'type':'section', 'value':ropts})
opts.append({'name':'empty', 'type':'empty'}) opts.append({'name':'empty', 'type':'empty'})
#[domain_realm] #[domain_realm]
dropts = [{'name':'.'+ds.getDomainName(), 'type':'option', 'value':ds.getRealmName()}, dropts = [{'name':'.'+cli_domain, 'type':'option', 'value':cli_realm},
{'name':ds.getDomainName(), 'type':'option', 'value':ds.getRealmName()}] {'name':cli_domain, 'type':'option', 'value':cli_realm}]
opts.append({'name':'domain_realm', 'type':'section', 'value':dropts}) opts.append({'name':'domain_realm', 'type':'section', 'value':dropts})
opts.append({'name':'empty', 'type':'empty'}) opts.append({'name':'empty', 'type':'empty'})
@ -287,7 +304,7 @@ def main():
fstore.backup_file("/etc/krb5.conf") fstore.backup_file("/etc/krb5.conf")
krbconf.newConf("/etc/krb5.conf", opts); krbconf.newConf("/etc/krb5.conf", opts);
print "Configured /etc/krb5.conf for IPA realm " + ds.getRealmName() print "Configured /etc/krb5.conf for IPA realm " + cli_realm
#Modify nsswitch to add nss_ldap #Modify nsswitch to add nss_ldap
run(["/usr/sbin/authconfig", "--enableldap", "--update"]) run(["/usr/sbin/authconfig", "--enableldap", "--update"])
@ -299,9 +316,9 @@ def main():
run(["getent", "passwd", "admin"]) run(["getent", "passwd", "admin"])
except Exception, e: except Exception, e:
print "nss_ldap is not able to use DNS discovery!" print "nss_ldap is not able to use DNS discovery!"
print "Changing configuration to use hardcoded server name: " + ds.getServerName() print "Changing configuration to use hardcoded server name: " +cli_server
opts = [{'name':'uri', 'type':'option', 'action':'set', 'value':'ldap://'+ds.getServerName()}, opts = [{'name':'uri', 'type':'option', 'action':'set', 'value':'ldap://'+cli_server},
{'name':'empty', 'type':'empty'}] {'name':'empty', 'type':'empty'}]
try: try:
ldapconf.changeConf("/etc/ldap.conf", opts) ldapconf.changeConf("/etc/ldap.conf", opts)
@ -317,7 +334,7 @@ def main():
if options.ntp_server: if options.ntp_server:
ntp_server = options.ntp_server ntp_server = options.ntp_server
else: else:
ntp_server = ds.getServerName() ntp_server = cli_server
ipaclient.ntpconf.config_ntp(ntp_server, fstore) ipaclient.ntpconf.config_ntp(ntp_server, fstore)
print "NTP enabled" print "NTP enabled"