Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Authors: Karl MacMillan <kmacmill@redhat.com> # # Copyright (C) 2007 Red Hat # see file 'COPYING' for use and warranty information # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. #
self.msg = msg Exception.__init__(self, msg)
return self.msg
"""Our own optparse formatter that indents multiple lined usage string.""" usage_string = "Usage:" spacing = " " * len(usage_string) lines = usage.split("\n") ret = "%s %s\n" % (usage_string, lines[0]) for line in lines[1:]: ret += "%s %s\n" % (spacing, line) return ret
from ipapython.ipautil import CheckedIPAddress
ip_local = option.ip_local is True ip_netmask = option.ip_netmask is True try: return CheckedIPAddress(value, parse_netmask=ip_netmask, match_local=ip_local) except Exception as e: raise OptionValueError("option %s: invalid IP address %s: %s" % (opt, value, e))
""" optparse.Option subclass with support of options labeled as security-sensitive such as passwords. """
""" optparse.OptionParser subclass that uses IPAOption by default for storing options. """ usage=None, option_list=None, option_class=IPAOption, version=None, conflict_handler="error", description=None, formatter=None, add_help_option=True, prog=None): OptionParser.__init__(self, usage, option_list, option_class, version, conflict_handler, description, formatter, add_help_option, prog)
""" Returns all options except those with sensitive=True in the same fashion as parse_args would """ all_opts_dict = dict([ (o.dest, o) for o in self._get_all_options() if hasattr(o, 'sensitive') ]) safe_opts_dict = {}
for option, value in opts.__dict__.iteritems(): if all_opts_dict[option].sensitive != True: safe_opts_dict[option] = value
return Values(safe_opts_dict)
"""Verify that we have all positional arguments we need, if not, exit.""" if needed_args: needed_list = needed_args.split(" ") else: needed_list = [] len_need = len(needed_list) len_have = len(args) if len_have > len_need: parser.error("too many arguments") elif len_have < len_need: parser.error("no %s specified" % needed_list[len_have])
if self.default_realm: return self.default_realm else: raise IPAConfigError("no default realm")
if len(self.default_server): return self.default_server else: raise IPAConfigError("no default server")
else: raise IPAConfigError("no default domain")
# Global library config
except: pass except: pass except: pass
try: # only import krbV when we need it import krbV krbctx = krbV.default_context() config.default_realm = krbctx.default_realm except ImportError: pass if not config.default_realm: return False
#try once with REALM -> domain dom_name = str(config.default_realm).lower() name = "_ldap._tcp."+dom_name+"." rs = ipapython.dnsclient.query(name, ipapython.dnsclient.DNS_C_IN, ipapython.dnsclient.DNS_T_SRV) rl = len(rs) if rl == 0: #try cycling on domain components of FQDN dom_name = socket.getfqdn() while rl == 0: tok = dom_name.find(".") if tok == -1: return False dom_name = dom_name[tok+1:] name = "_ldap._tcp." + dom_name + "." rs = ipapython.dnsclient.query(name, ipapython.dnsclient.DNS_C_IN, ipapython.dnsclient.DNS_T_SRV) rl = len(rs)
config.default_domain = dom_name
if r.dns_type == ipapython.dnsclient.DNS_T_SRV: rsrv = r.rdata.server.rstrip(".") config.default_server.append(rsrv)
except: pass
parser.add_option("--realm", dest="realm", help="Override default IPA realm") parser.add_option("--server", dest="server", help="Override default IPA server") parser.add_option("--domain", dest="domain", help="Override default IPA DNS domain")
config.default_realm = options.realm config.default_domain = options.domain if options.server: config.default_server.extend(options.server.split(","))
else:
# make sure the server list only contains unique items
raise IPAConfigError("IPA realm not found in DNS, in the config file (/etc/ipa/default.conf) or on the command line.") raise IPAConfigError("IPA server not found in DNS, in the config file (/etc/ipa/default.conf) or on the command line.") raise IPAConfigError("IPA domain not found in the config file (/etc/ipa/default.conf) or on the command line.") |