Ejemplo n.º 1
0
def create_server_obj(server_url):

    cfg = config.initUp2dateConfig()

    enable_proxy = cfg['enableProxy']
    proxy_host = None
    proxy_user = None
    proxy_password = None

    if enable_proxy:
        proxy_host = config.getProxySetting()

        if cfg['enableProxyAuth']:
            proxy_user = cfg['proxyUser']
            proxy_password = cfg['proxyPassword']

    ca = cfg['sslCACert']

    if isinstance(ca, basestring):
        ca = [ca]

    ca_certs = ca or ["/usr/share/rhn/RHNS-CA-CERT"]

    lang = None
    for env in 'LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG':
        if env in os.environ:
            lang = os.environ[env].split(':')[0]
            lang = lang.split('.')[0]
            break
        else:
            continue


    server = rpclib.Server(server_url,
                           proxy=proxy_host,
                           username=proxy_user,
                           password=proxy_password)

    if lang:
        server.setlang(lang)

    if server_url.startswith("https"):
        for ca_cert in ca_certs:
            if not os.access(ca_cert, os.R_OK):
                raise "could not find cert %s" % ca_cert

            server.add_trusted_cert(ca_cert)

    return server
Ejemplo n.º 2
0
def create_server_obj(server_url):

    cfg = config.initUp2dateConfig()

    enable_proxy = cfg['enableProxy']
    proxy_host = None
    proxy_user = None
    proxy_password = None

    if enable_proxy:
        proxy_host = config.getProxySetting()

        if cfg['enableProxyAuth']:
            proxy_user = cfg['proxyUser']
            proxy_password = cfg['proxyPassword']

    ca = cfg['sslCACert']

    if isinstance(ca, basestring):
        ca = [ca]

    ca_certs = ca or ["/usr/share/rhn/RHNS-CA-CERT"]

    lang = None
    for env in 'LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG':
        if env in os.environ:
            lang = os.environ[env].split(':')[0]
            lang = lang.split('.')[0]
            break
        else:
            continue


    server = rpclib.Server(server_url,
                           proxy=proxy_host,
                           username=proxy_user,
                           password=proxy_password)

    if lang:
        server.setlang(lang)

    if server_url.startswith("https"):
        for ca_cert in ca_certs:
            if not os.access(ca_cert, os.R_OK):
                raise "could not find cert %s" % ca_cert

            server.add_trusted_cert(ca_cert)

    return server
Ejemplo n.º 3
0
        ret['tcp_keepalive_timeout'] = int(osad_config.get('tcp_keepalive_timeout', defval=1800))
        ret['tcp_keepalive_count'] = int(osad_config.get('tcp_keepalive_count', defval=3))

        systemid = osad_config.get('systemid')
        if systemid is None:
            systemid = self.get_up2date_config()['systemIdPath']
        ret['systemid'] = systemid

        enable_proxy = self._config.get_option('enableProxy')
        if enable_proxy is None:
            enable_proxy = self.get_up2date_config()['enableProxy']

        if enable_proxy:
            ret['enable_proxy'] = 1

            ret['proxy_url'] = config.getProxySetting()

            enable_proxy_auth = self._config.get_option('enableProxyAuth')
            if enable_proxy_auth is None:
                enable_proxy_auth = self.get_up2date_config()['enableProxyAuth']

            if enable_proxy_auth:
                ret['enable_proxy_auth'] = 1
                proxy_user = self._config.get_option('proxyUser')
                if proxy_user is None:
                    proxy_user = self.get_up2date_config()['proxyUser']
                ret['proxy_user'] = proxy_user

                proxy_password = self._config.get_option('proxyPassword')
                if proxy_password is None:
                    proxy_password = self.get_up2date_config()['proxyPassword']
Ejemplo n.º 4
0
def findHostByRoute():
    """ returns [hostname, intf, intf6]

        Where hostname is you FQDN of this machine.
        And intf is numeric IPv4 address. And intf6 is IPv6 address.
    """
    cfg = config.initUp2dateConfig()
    sl = config.getServerlURL()

    st = {'https':443, 'http':80}
    hostname = None
    intf = None
    intf6 = None
    etchostname = False
    sockethostname = None
    for serverUrl in sl:
        server = serverUrl.split('/')[2]
        servertype = serverUrl.split(':')[0]
        port = st[servertype]

        for family in (AF_INET6, AF_INET):
            try:
                s = socket.socket(family)
            except socket.error:
                continue

            if cfg['enableProxy']:
                server_port = config.getProxySetting()
                (server, port) = server_port.split(':')
                port = int(port)

            try:
                s.settimeout(5)
                s.connect((server, port))
                intf_tmp = s.getsockname()[0]
                if family == AF_INET:
                    intf = intf_tmp
                else:
                    intf6 = intf_tmp
                hostname_tmp = socket.getfqdn(intf_tmp)
                if hostname_tmp != intf_tmp:
                    hostname = hostname_tmp
                    sockethostname = hostname_tmp
            except socket.error:
                s.close()
                continue
            s.close()

    # Override hostname with the value from /etc/hostname
    if os.path.isfile("/etc/hostname") and os.access("/etc/hostname", os.R_OK):
        hostnameinfo = open("/etc/hostname", "r").readlines()

        # Warn if /etc/hostname contains more than one entry (bsc#929979)
        if len(hostnameinfo) > 1:
            log = up2dateLog.initLog()
            log.log_me("/etc/hostname contains more than one entry! Using first one.")

        if len(hostnameinfo):
            info = hostnameinfo[0]
        else:
            info = ""

        # ".site" is now an allowed TLD. Catch local installations by checking
        # for pseudo TLD ".suse" and require more than the domainname for ".site"
        # so "local.site" still can be identified as local installation (bsc#923990)
        if len(info):
            tmpval = info.strip().split('.')
            if not info.strip().endswith(".suse"):
                if not info.strip().endswith(".site") or len(tmpval) > 2:
                    hostname = info.strip()
                    etchostname = True

    # Override hostname with the one in /etc/sysconfig/network
    # for bz# 457953
    elif os.path.isfile("/etc/sysconfig/network") and os.access("/etc/sysconfig/network", os.R_OK):
        networkinfo = open("/etc/sysconfig/network", "r").readlines()

        for info in networkinfo:
            if not len(info):
                continue
            vals = info.split('=')
            if len(vals) <= 1:
                continue
            if vals[0].strip() == "HOSTNAME":
                # /etc/sysconfig/network is of shell syntax,
                # so values can be quoted
                hostname = ''.join(vals[1:]).strip('"\' \t\n')
                etchostname = False
                break

    # /etc/hostname doesn't contain a fully qualified hostname
    # try to find out the domain
    if etchostname and "." not in hostname:
        fqdn = socket.getfqdn(hostname)
        if "." in fqdn:
            domain = fqdn.split('.', 1)[1]
            aliasfqdn = "{0}.{1}".format(hostname, domain)
            try:
                socket.gethostbyname(aliasfqdn)
                hostname = aliasfqdn
            except socket.error:
                hostname = fqdn
                log = up2dateLog.initLog()
                log.log_me("Could not resolve /etc/hostname alias to {0}. Falling back to {1}".format(aliasfqdn, fqdn))
        else:
            log = up2dateLog.initLog()
            log.log_me("Got an invalid FQDN {0} for /etc/hostname. Falling back to {1}".format(fqdn, sockethostname))
            hostname = sockethostname

    if hostname == None or hostname == 'localhost.localdomain':
        hostname = "unknown"
    return hostname, intf, intf6
Ejemplo n.º 5
0
 def testHttpUnSpecified(self):
     "Verify that proxies with no http:// work correctly"
     self.cfg['httpProxy'] = self.proxy2
     res = config.getProxySetting()
     assert res == "proxy.company.com:8080"
Ejemplo n.º 6
0
 def testHttpSpecified(self):
     "Verify that http:// gets stripped from proxy settings"
     self.cfg['httpProxy'] = self.proxy1
     res = config.getProxySetting()
     assert res == "proxy.company.com:8080"
Ejemplo n.º 7
0
def getServer(refreshCallback=None, serverOverride=None, timeout=None):
    log = up2dateLog.initLog()
    cfg = config.initUp2dateConfig()

    # Where do we keep the CA certificate for RHNS?
    # The servers we're talking to need to have their certs
    # signed by one of these CA.
    ca = cfg["sslCACert"]
    if not isinstance(ca, list):
        ca = [ca]

    rhns_ca_certs = ca or ["/usr/share/rhn/RHNS-CA-CERT"]
    if cfg["enableProxy"]:
        proxyHost = config.getProxySetting()
    else:
        proxyHost = None

    if not serverOverride:
        serverUrls = config.getServerlURL()
    else:
        serverUrls = serverOverride
    serverList = ServerList(serverUrls)

    proxyUser = None
    proxyPassword = None
    if cfg["enableProxyAuth"]:
        proxyUser = cfg["proxyUser"] or None
        proxyPassword = cfg["proxyPassword"] or None

    lang = None
    for env in 'LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG':
        if env in os.environ:
            if not os.environ[env]:
                # sometimes unset
                continue
            lang = os.environ[env].split(':')[0]
            lang = lang.split('.')[0]
            break


    s = RetryServer(serverList.server(),
                    refreshCallback=refreshCallback,
                    proxy=proxyHost,
                    username=proxyUser,
                    password=proxyPassword,
                    timeout=timeout)
    s.addServerList(serverList)

    s.add_header("X-Up2date-Version", up2dateUtils.version())

    if lang:
        s.setlang(lang)

    # require RHNS-CA-CERT file to be able to authenticate the SSL connections
    need_ca = [ True for i in s.serverList.serverList
                     if urlparse.urlparse(i)[0] == 'https']
    if need_ca:
        for rhns_ca_cert in rhns_ca_certs:
            if not os.access(rhns_ca_cert, os.R_OK):
                msg = "%s: %s" % (_("ERROR: can not find RHNS CA file"),
                                     rhns_ca_cert)
                log.log_me("%s" % msg)
                raise up2dateErrors.SSLCertificateFileNotFound(msg)

            # force the validation of the SSL cert
            s.add_trusted_cert(rhns_ca_cert)

    clientCaps.loadLocalCaps()

    # send up the capabality info
    headerlist = clientCaps.caps.headerFormat()
    for (headerName, value) in headerlist:
        s.add_header(headerName, value)
    return s
Ejemplo n.º 8
0
def findHostByRoute():
    """ returns [hostname, intf, intf6]

        Where hostname is you FQDN of this machine.
        And intf is numeric IPv4 address. And intf6 is IPv6 address.
    """
    cfg = config.initUp2dateConfig()
    sl = config.getServerlURL()

    st = {'https':443, 'http':80}
    hostname = None
    intf = None
    intf6 = None
    etchostname = False
    sockethostname = None
    for serverUrl in sl:
        server = serverUrl.split('/')[2]
        servertype = serverUrl.split(':')[0]
        port = st[servertype]

        for family in (AF_INET6, AF_INET):
            try:
                s = socket.socket(family)
            except socket.error:
                continue

            if cfg['enableProxy']:
                server_port = config.getProxySetting()
                (server, port) = server_port.split(':')
                port = int(port)

            try:
                s.settimeout(5)
                s.connect((server, port))
                intf_tmp = s.getsockname()[0]
                if family == AF_INET:
                    intf = intf_tmp
                else:
                    intf6 = intf_tmp
                hostname_tmp = socket.getfqdn(intf_tmp)
                if hostname_tmp != intf_tmp:
                    hostname = hostname_tmp
                    sockethostname = hostname_tmp
            except socket.error:
                s.close()
                continue
            s.close()

    # Override hostname with the value from /etc/hostname
    if os.path.isfile("/etc/hostname") and os.access("/etc/hostname", os.R_OK):
        hostnameinfo = open("/etc/hostname", "r").readlines()

        # Warn if /etc/hostname contains more than one entry (bsc#929979)
        if len(hostnameinfo) > 1:
            log = up2dateLog.initLog()
            log.log_me("/etc/hostname contains more than one entry! Using first one.")

        if len(hostnameinfo):
            info = hostnameinfo[0]
        else:
            info = ""

        # ".site" is now an allowed TLD. Catch local installations by checking
        # for pseudo TLD ".suse" and require more than the domainname for ".site"
        # so "local.site" still can be identified as local installation (bsc#923990)
        if len(info):
            tmpval = info.strip().split('.')
            if not info.strip().endswith(".suse"):
                if not info.strip().endswith(".site") or len(tmpval) > 2:
                    hostname = info.strip()
                    etchostname = True

    # Override hostname with the one in /etc/sysconfig/network
    # for bz# 457953
    elif os.path.isfile("/etc/sysconfig/network") and os.access("/etc/sysconfig/network", os.R_OK):
        networkinfo = open("/etc/sysconfig/network", "r").readlines()

        for info in networkinfo:
            if not len(info):
                continue
            vals = info.split('=')
            if len(vals) <= 1:
                continue
            if vals[0].strip() == "HOSTNAME":
                # /etc/sysconfig/network is of shell syntax,
                # so values can be quoted
                hostname = ''.join(vals[1:]).strip('"\' \t\n')
                etchostname = False
                break

    # /etc/hostname doesn't contain a fully qualified hostname
    # try to find out the domain
    if etchostname and "." not in hostname:
        fqdn = socket.getfqdn(hostname)
        if "." in fqdn:
            domain = fqdn.split('.', 1)[1]
            aliasfqdn = "{0}.{1}".format(hostname, domain)
            try:
                socket.gethostbyname(aliasfqdn)
                hostname = aliasfqdn
            except socket.error:
                hostname = fqdn
                log = up2dateLog.initLog()
                log.log_me("Could not resolve /etc/hostname alias to {0}. Falling back to {1}".format(aliasfqdn, fqdn))
        else:
            log = up2dateLog.initLog()
            log.log_me("Got an invalid FQDN {0} for /etc/hostname. Falling back to {1}".format(fqdn, sockethostname))
            hostname = sockethostname

    if hostname == None or hostname == 'localhost.localdomain':
        hostname = "unknown"
    return hostname, intf, intf6
Ejemplo n.º 9
0
    def read_config(self):
        ret = {}
        # Read from the global config first
        config_file = self.options.cfg
        self._config = osad_config.init('osad', config_file=config_file)
        config_keys = [
            'debug_level', 'osa_ssl_cert', 'logfile', 'run_rhn_check',
            'rhn_check_command', 'enable_failover'
        ]
        for key in config_keys:
            ret[key] = osad_config.get(key)

        try:
            server_url = osad_config.get('server_url')
        except osad_config.InterpolationError:
            e = sys.exc_info()[1]
            server_url = config.getServerlURL()
        else:
            if not server_url:
                server_url = config.getServerlURL()
            else:

                def convert_url(s):
                    s = s.strip()
                    if hasattr(config, 'convert_url_to_puny'):
                        s = config.convert_url_to_puny(s)
                    elif hasattr(config, 'convert_url_to_pune'):
                        s = config.convert_url_to_pune(s)
                    return s

                server_url = [convert_url(i) for i in server_url.split(';')]

        # Remove empty URLs
        for url in server_url:
            if not url:
                server_url.remove(url)

        # Real unusual case if there is no server URL both in up2date and osad config files
        if not server_url:
            die("Missing server URL in config file")

        ret['server_url'] = server_url

        #8/23/05 wregglej 165775 added the run_rhn_check option.
        run_rhn_check = osad_config.get('run_rhn_check')
        if run_rhn_check is None:
            log_debug(3, "Forcing run_rhn_check")
            run_rhn_check = 1
        ret['run_rhn_check'] = int(run_rhn_check)

        ret['tcp_keepalive_timeout'] = int(
            osad_config.get('tcp_keepalive_timeout', defval=1800))
        ret['tcp_keepalive_count'] = int(
            osad_config.get('tcp_keepalive_count', defval=3))

        systemid = osad_config.get('systemid')
        if systemid is None:
            systemid = self.get_up2date_config()['systemIdPath']
        ret['systemid'] = systemid

        enable_proxy = self._config.get_option('enableProxy')
        if enable_proxy is None:
            enable_proxy = self.get_up2date_config()['enableProxy']

        if enable_proxy:
            ret['enable_proxy'] = 1

            ret['proxy_url'] = self._config.get_option('httpProxy')
            if ret['proxy_url'] is None:
                ret['proxy_url'] = str(config.getProxySetting())

            ret['enable_proxy_auth'] = 0
            enable_proxy_auth = self._config.get_option('enableProxyAuth')
            if enable_proxy_auth is None:
                enable_proxy_auth = self.get_up2date_config(
                )['enableProxyAuth']

            if enable_proxy_auth:
                ret['enable_proxy_auth'] = 1
                proxy_user = self._config.get_option('proxyUser')
                if proxy_user is None:
                    proxy_user = self.get_up2date_config()['proxyUser']
                ret['proxy_user'] = proxy_user

                proxy_password = self._config.get_option('proxyPassword')
                if proxy_password is None:
                    proxy_password = self.get_up2date_config()['proxyPassword']
                ret['proxy_password'] = proxy_password

        if not server_url:
            die("Unable to retrieve server URL")

        # SSL cert for Jabber's TLS, it can potentially be different than the
        # client's
        osa_ssl_cert = self._config.get_option('osa_ssl_cert')
        # The up2date ssl cert - we get it from up2daate's config file
        client_ca_cert = self.get_up2date_config()['sslCACert']
        if isinstance(client_ca_cert, ListType):
            if client_ca_cert:
                client_ca_cert = client_ca_cert[0]
            else:
                client_ca_cert = None
        if osa_ssl_cert is None:
            # No setting, use up2date's
            osa_ssl_cert = client_ca_cert

        if client_ca_cert is not None:
            ret['ssl_ca_cert'] = client_ca_cert
        if osa_ssl_cert is not None:
            ret['osa_ssl_cert'] = osa_ssl_cert

        return ret
Ejemplo n.º 10
0
        systemid = osad_config.get('systemid')
        if systemid is None:
            systemid = self.get_up2date_config()['systemIdPath']
        ret['systemid'] = systemid

        enable_proxy = self._config.get_option('enableProxy')
        if enable_proxy is None:
            enable_proxy = self.get_up2date_config()['enableProxy']

        if enable_proxy:
            ret['enable_proxy'] = 1

            ret['proxy_url'] = self._config.get_option('httpProxy')
            if ret['proxy_url'] is None:
                ret['proxy_url'] = str(config.getProxySetting())

            ret['enable_proxy_auth'] = 0
            enable_proxy_auth = self._config.get_option('enableProxyAuth')
            if enable_proxy_auth is None:
                enable_proxy_auth = self.get_up2date_config(
                )['enableProxyAuth']

            if enable_proxy_auth:
                ret['enable_proxy_auth'] = 1
                proxy_user = self._config.get_option('proxyUser')
                if proxy_user is None:
                    proxy_user = self.get_up2date_config()['proxyUser']
                ret['proxy_user'] = proxy_user

                proxy_password = self._config.get_option('proxyPassword')
Ejemplo n.º 11
0
def getServer(refreshCallback=None, serverOverride=None, timeout=None):
    log = up2dateLog.initLog()
    cfg = config.initUp2dateConfig()

    # Where do we keep the CA certificate for RHNS?
    # The servers we're talking to need to have their certs
    # signed by one of these CA.
    ca = cfg["sslCACert"]
    if not isinstance(ca, list):
        ca = [ca]

    rhns_ca_certs = ca or ["/usr/share/rhn/RHNS-CA-CERT"]
    if cfg["enableProxy"]:
        proxyHost = config.getProxySetting()
    else:
        proxyHost = None

    if not serverOverride:
        serverUrls = config.getServerlURL()
    else:
        serverUrls = serverOverride
    serverList = ServerList(serverUrls)

    proxyUser = None
    proxyPassword = None
    if cfg["enableProxyAuth"]:
        proxyUser = cfg["proxyUser"] or None
        proxyPassword = cfg["proxyPassword"] or None

    lang = None
    for env in 'LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG':
        if env in os.environ:
            if not os.environ[env]:
                # sometimes unset
                continue
            lang = os.environ[env].split(':')[0]
            lang = lang.split('.')[0]
            break

    s = RetryServer(serverList.server(),
                    refreshCallback=refreshCallback,
                    proxy=proxyHost,
                    username=proxyUser,
                    password=proxyPassword,
                    timeout=timeout)
    s.addServerList(serverList)

    s.add_header("X-Up2date-Version", up2dateUtils.version())

    if lang:
        s.setlang(lang)

    # require RHNS-CA-CERT file to be able to authenticate the SSL connections
    need_ca = [
        True for i in s.serverList.serverList
        if urlparse.urlparse(i)[0] == 'https'
    ]
    if need_ca:
        for rhns_ca_cert in rhns_ca_certs:
            if not os.access(rhns_ca_cert, os.R_OK):
                msg = "%s: %s" % (_("ERROR: can not find RHNS CA file"),
                                  rhns_ca_cert)
                log.log_me("%s" % msg)
                raise up2dateErrors.SSLCertificateFileNotFound(msg)

            # force the validation of the SSL cert
            s.add_trusted_cert(rhns_ca_cert)

    clientCaps.loadLocalCaps()

    # send up the capabality info
    headerlist = clientCaps.caps.headerFormat()
    for (headerName, value) in headerlist:
        s.add_header(headerName, value)
    return s
Ejemplo n.º 12
0
Archivo: osad.py Proyecto: m47ik/uyuni
    def read_config(self):
        ret = {}
        # Read from the global config first
        config_file = self.options.cfg
        self._config = osad_config.init('osad', config_file=config_file)
        config_keys = ['debug_level', 'osa_ssl_cert', 'logfile', 'run_rhn_check',
            'rhn_check_command', 'enable_failover']
        for key in config_keys:
            ret[key] = osad_config.get(key)

        try:
            server_url = osad_config.get('server_url')
        except osad_config.InterpolationError:
            e = sys.exc_info()[1]
            server_url = config.getServerlURL()
        else:
            if not server_url:
                server_url = config.getServerlURL()
            else:
                def convert_url(s):
                    s = s.strip()
                    if hasattr(config, 'convert_url_to_puny'):
                       s = config.convert_url_to_puny(s)
                    elif hasattr(config, 'convert_url_to_pune'):
                       s = config.convert_url_to_pune(s)
                    return s

                server_url = [convert_url(i) for i in server_url.split(';')]

        # Remove empty URLs
        for url in server_url:
            if not url:
                server_url.remove(url)

        # Real unusual case if there is no server URL both in up2date and osad config files
        if not server_url:
            die("Missing server URL in config file")

        ret['server_url'] = server_url

        #8/23/05 wregglej 165775 added the run_rhn_check option.
        run_rhn_check = osad_config.get('run_rhn_check')
        if run_rhn_check is None:
            log_debug(3, "Forcing run_rhn_check")
            run_rhn_check = 1
        ret['run_rhn_check'] = int(run_rhn_check)

        ret['tcp_keepalive_timeout'] = int(osad_config.get('tcp_keepalive_timeout', defval=1800))
        ret['tcp_keepalive_count'] = int(osad_config.get('tcp_keepalive_count', defval=3))

        systemid = osad_config.get('systemid')
        if systemid is None:
            systemid = self.get_up2date_config()['systemIdPath']
        ret['systemid'] = systemid

        enable_proxy = self._config.get_option('enableProxy')
        if enable_proxy is None:
            enable_proxy = self.get_up2date_config()['enableProxy']

        if enable_proxy:
            ret['enable_proxy'] = 1

            ret['proxy_url'] = self._config.get_option('httpProxy')
            if ret['proxy_url'] is None:
                ret['proxy_url'] = str(config.getProxySetting())

            ret['enable_proxy_auth'] = 0
            enable_proxy_auth = self._config.get_option('enableProxyAuth')
            if enable_proxy_auth is None:
                enable_proxy_auth = self.get_up2date_config()['enableProxyAuth']

            if enable_proxy_auth:
                ret['enable_proxy_auth'] = 1
                proxy_user = self._config.get_option('proxyUser')
                if proxy_user is None:
                    proxy_user = self.get_up2date_config()['proxyUser']
                ret['proxy_user'] = proxy_user

                proxy_password = self._config.get_option('proxyPassword')
                if proxy_password is None:
                    proxy_password = self.get_up2date_config()['proxyPassword']
                ret['proxy_password'] = proxy_password

        if not server_url:
            die("Unable to retrieve server URL")

        # SSL cert for Jabber's TLS, it can potentially be different than the
        # client's
        osa_ssl_cert = self._config.get_option('osa_ssl_cert')
        # The up2date ssl cert - we get it from up2daate's config file
        client_ca_cert = self.get_up2date_config()['sslCACert']
        if isinstance(client_ca_cert, ListType):
            if client_ca_cert:
                client_ca_cert = client_ca_cert[0]
            else:
                client_ca_cert = None
        if osa_ssl_cert is None:
            # No setting, use up2date's
            osa_ssl_cert = client_ca_cert

        if client_ca_cert is not None:
            ret['ssl_ca_cert'] = client_ca_cert
        if osa_ssl_cert is not None:
            ret['osa_ssl_cert'] = osa_ssl_cert

        return ret
Ejemplo n.º 13
0
 def testHttpUnSpecified(self):
     "Verify that proxies with no http:// work correctly"
     self.cfg['httpProxy'] = self.proxy2
     res = config.getProxySetting()
     assert res == "proxy.company.com:8080"
Ejemplo n.º 14
0
 def testHttpSpecified(self):
     "Verify that http:// gets stripped from proxy settings"
     self.cfg['httpProxy'] = self.proxy1
     res = config.getProxySetting()
     assert res == "proxy.company.com:8080"
Ejemplo n.º 15
0
def findHostByRoute():
    """ returns [hostname, intf, intf6]

        Where hostname is you FQDN of this machine.
        And intf is numeric IPv4 address. And intf6 is IPv6 address.
    """
    cfg = config.initUp2dateConfig()
    sl = config.getServerlURL()

    st = {'https': 443, 'http': 80}
    hostname = None
    intf = None
    intf6 = None
    for serverUrl in sl:
        server = serverUrl.split('/')[2]
        servertype = serverUrl.split(':')[0]
        port = st[servertype]

        for family in (AF_INET6, AF_INET):
            try:
                s = socket.socket(family)
            except socket.error:
                continue

            if cfg['enableProxy']:
                server_port = config.getProxySetting()
                (server, port) = server_port.split(':')
                port = int(port)

            try:
                s.settimeout(5)
                s.connect((server, port))
                intf_tmp = s.getsockname()[0]
                if family == AF_INET:
                    intf = intf_tmp
                else:
                    intf6 = intf_tmp
                hostname_tmp = socket.getfqdn(intf_tmp)
                if hostname_tmp != intf_tmp:
                    hostname = hostname_tmp
            except socket.error:
                s.close()
                continue
            s.close()

    # Override hostname with the value from /etc/hostname
    if os.path.isfile("/etc/hostname") and os.access("/etc/hostname", os.R_OK):
        hostnameinfo = open("/etc/hostname", "r").readlines()

        for info in hostnameinfo:
            if not len(info):
                continue
            hostname = info.strip()

    # Override hostname with the one in /etc/sysconfig/network
    # for bz# 457953
    elif os.path.isfile("/etc/sysconfig/network") and os.access(
            "/etc/sysconfig/network", os.R_OK):
        networkinfo = open("/etc/sysconfig/network", "r").readlines()

        for info in networkinfo:
            if not len(info):
                continue
            vals = info.split('=')
            if len(vals) <= 1:
                continue
            if vals[0].strip() == "HOSTNAME":
                # /etc/sysconfig/network is of shell syntax,
                # so values can be quoted
                hostname = ''.join(vals[1:]).strip('"\' \t\n')
                break

    if hostname == None or hostname == 'localhost.localdomain':
        hostname = "unknown"
    return hostname, intf, intf6
Ejemplo n.º 16
0
    def get_server(self, refreshCallback=None, serverOverride=None, timeout=None):
        """
        Moved from rpcServer.
        """
        ca = self.cfg["sslCACert"]
        if isinstance(ca, basestring):
            ca = [ca]

        rhns_ca_certs = ca or ["/usr/share/rhn/RHNS-CA-CERT"]
        if self.cfg["enableProxy"]:
            proxy_host = config.getProxySetting()
        else:
            proxy_host = None

        if not serverOverride:
            server_urls = config.getServerlURL()
        else:
            server_urls = serverOverride
        server_list = rpcServer.ServerList(server_urls)

        proxy_user = None
        proxy_password = None
        if self.cfg["enableProxyAuth"]:
            proxy_user = self.cfg["proxyUser"] or None
            proxy_password = self.cfg["proxyPassword"] or None

        lang = None
        for env in 'LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG':
            if os.environ.get(env):
                lang = os.environ[env].split(':')[0].split('.')[0]
                break
            else:
                continue

        retry_server = rpcServer.RetryServer(server_list.server(),
                                             refreshCallback=refreshCallback,
                                             proxy=proxy_host,
                                             username=proxy_user,
                                             password=proxy_password)
        retry_server.addServerList(server_list)
        retry_server.add_header("X-Up2date-Version", up2dateUtils.version())

        if lang:
            retry_server.setlang(lang)

        # require RHNS-CA-CERT file to be able to authenticate the SSL connections
        need_ca = [True for i in retry_server.serverList.serverList if urlparse.urlparse(i)[0] == 'https']
        if need_ca:
            for rhns_ca_cert in rhns_ca_certs:
                if not os.access(rhns_ca_cert, os.R_OK):
                    msg = "%s: %s" % ("ERROR: can not find RHNS CA file", rhns_ca_cert)
                    log.log_me("%s" % msg)
                    raise up2dateErrors.SSLCertificateFileNotFound(msg)

                # force the validation of the SSL cert
                retry_server.add_trusted_cert(rhns_ca_cert)

        clientCaps.loadLocalCaps()

        # send up the capabality info
        header_list = clientCaps.caps.headerFormat()
        for (headerName, value) in header_list:
            retry_server.add_header(headerName, value)

        return retry_server
Ejemplo n.º 17
0
def findHostByRoute():
    """ returns [hostname, intf, intf6]

        Where hostname is you FQDN of this machine.
        And intf is numeric IPv4 address. And intf6 is IPv6 address.
    """
    cfg = config.initUp2dateConfig()
    sl = config.getServerlURL()

    st = {'https':443, 'http':80}
    hostname = None
    intf = None
    intf6 = None
    for serverUrl in sl:
        server = serverUrl.split('/')[2]
        servertype = serverUrl.split(':')[0]
        port = st[servertype]

        for family in (AF_INET6, AF_INET):
            try:
                s = socket.socket(family)
            except socket.error:
                continue

            if cfg['enableProxy']:
                server_port = config.getProxySetting()
                (server, port) = server_port.split(':')
                port = int(port)

            try:
                s.settimeout(5)
                s.connect((server, port))
                intf_tmp = s.getsockname()[0]
                if family == AF_INET:
                    intf = intf_tmp
                else:
                    intf6 = intf_tmp
                hostname_tmp = socket.getfqdn(intf_tmp)
                if hostname_tmp != intf_tmp:
                    hostname = hostname_tmp
            except socket.error:
                s.close()
                continue
            s.close()

    # Override hostname with the value from /etc/hostname
    if os.path.isfile("/etc/hostname") and os.access("/etc/hostname", os.R_OK):
        hostnameinfo = open("/etc/hostname", "r").readlines()

        for info in hostnameinfo:
            if not len(info):
                continue
            hostname = info.strip()

    # Override hostname with the one in /etc/sysconfig/network
    # for bz# 457953
    elif os.path.isfile("/etc/sysconfig/network") and os.access("/etc/sysconfig/network", os.R_OK):
        networkinfo = open("/etc/sysconfig/network", "r").readlines()

        for info in networkinfo:
            if not len(info):
                continue
            vals = info.split('=')
            if len(vals) <= 1:
                continue
            strippedstring = vals[0].strip()
            vals[0] = strippedstring
            if vals[0] == "HOSTNAME":
                hostname = ''.join(vals[1:]).strip()
                break

    if hostname == None or hostname == 'localhost.localdomain':
        hostname = "unknown"
    return hostname, intf, intf6
Ejemplo n.º 18
0
        systemid = osad_config.get('systemid')
        if systemid is None:
            systemid = self.get_up2date_config()['systemIdPath']
        ret['systemid'] = systemid

        enable_proxy = self._config.get_option('enableProxy')
        if enable_proxy is None:
            enable_proxy = self.get_up2date_config()['enableProxy']

        if enable_proxy:
            ret['enable_proxy'] = 1

            ret['proxy_url'] = self._config.get_option('httpProxy')
            if ret['proxy_url'] is None:
                ret['proxy_url'] = str(config.getProxySetting())

            ret['enable_proxy_auth'] = 0
            enable_proxy_auth = self._config.get_option('enableProxyAuth')
            if enable_proxy_auth is None:
                enable_proxy_auth = self.get_up2date_config()['enableProxyAuth']

            if enable_proxy_auth:
                ret['enable_proxy_auth'] = 1
                proxy_user = self._config.get_option('proxyUser')
                if proxy_user is None:
                    proxy_user = self.get_up2date_config()['proxyUser']
                ret['proxy_user'] = proxy_user

                proxy_password = self._config.get_option('proxyPassword')
                if proxy_password is None:
Ejemplo n.º 19
0
        ret['tcp_keepalive_count'] = int(
            osad_config.get('tcp_keepalive_count', defval=3))

        systemid = osad_config.get('systemid')
        if systemid is None:
            systemid = self.get_up2date_config()['systemIdPath']
        ret['systemid'] = systemid

        enable_proxy = self._config.get_option('enableProxy')
        if enable_proxy is None:
            enable_proxy = self.get_up2date_config()['enableProxy']

        if enable_proxy:
            ret['enable_proxy'] = 1

            ret['proxy_url'] = config.getProxySetting()

            enable_proxy_auth = self._config.get_option('enableProxyAuth')
            if enable_proxy_auth is None:
                enable_proxy_auth = self.get_up2date_config(
                )['enableProxyAuth']

            if enable_proxy_auth:
                ret['enable_proxy_auth'] = 1
                proxy_user = self._config.get_option('proxyUser')
                if proxy_user is None:
                    proxy_user = self.get_up2date_config()['proxyUser']
                ret['proxy_user'] = proxy_user

                proxy_password = self._config.get_option('proxyPassword')
                if proxy_password is None: