def __init__(self): # We store the security list in the global flags. This way, we don't # have to worry about clearing it up. if rhnFlags.test(self._flag_string): self.sec = rhnFlags.get(self._flag_string) else: self.sec = [] rhnFlags.set(self._flag_string, self.sec)
def _set_proxy_info(self, req): """ Spacewalk Proxy stuff. """ proxyVersion = "X-RHN-Proxy-Version" if req.headers_in.has_key(proxyVersion): self.proxyVersion = req.headers_in[proxyVersion] # Make sure the proxy version gets set in the headers. rhnFlags.get("outputTransportOptions")[proxyVersion] = str(self.proxyVersion) # Make sure the proxy auth-token gets set in global flags. if req.headers_in.has_key("X-RHN-Proxy-Auth"): rhnFlags.set("X-RHN-Proxy-Auth", req.headers_in["X-RHN-Proxy-Auth"]) return apache.OK
def _set_proxy_info(self, req): """ RHN Proxy stuff. """ proxyVersion = 'X-RHN-Proxy-Version' if req.headers_in.has_key(proxyVersion): self.proxyVersion = req.headers_in[proxyVersion] # Make sure the proxy version gets set in the headers. rhnFlags.get('outputTransportOptions')[proxyVersion] = str( self.proxyVersion) # Make sure the proxy auth-token gets set in global flags. if req.headers_in.has_key('X-RHN-Proxy-Auth'): rhnFlags.set('X-RHN-Proxy-Auth', req.headers_in['X-RHN-Proxy-Auth']) return apache.OK
def _set_proxy_info(self, req): """ Spacewalk Proxy stuff. """ proxyVersion = 'X-RHN-Proxy-Version' if req.headers_in.has_key(proxyVersion): self.proxyVersion = req.headers_in[proxyVersion] # Make sure the proxy version gets set in the headers. rhnFlags.get('outputTransportOptions')[proxyVersion] = str( self.proxyVersion) # Make sure the proxy auth-token gets set in global flags. if req.headers_in.has_key('X-RHN-Proxy-Auth'): rhnFlags.set('X-RHN-Proxy-Auth', req.headers_in['X-RHN-Proxy-Auth']) return apache.OK
def headerParserHandler(self, req): """ after a request has been received, first thing we do is to create the input object """ # pylint: disable=R0911 log_setreq(req) log_debug(3) self.start_time = time.time() # Decline if this is a subrequest: if req.main: return apache.DECLINED log_debug(4, req.method, req.path_info, req.headers_in) # Clear the global flags. rhnFlags.reset() # Init the transport options. rhnFlags.set('outputTransportOptions', UserDictCase()) # Init the session token dictionary. rhnFlags.set("AUTH_SESSION_TOKEN", UserDictCase()) ret = self._init_request_processor(req) if ret != apache.OK: return ret ret = self._set_client_info(req) if ret != apache.OK: return ret # Check the protocol version if req.proto_num < 1001: # HTTP protocols prior to 1.1 close the connection rhnFlags.get('outputTransportOptions')["Connection"] = "close" ret = self._set_proxy_info(req) if ret != apache.OK: return ret # Need to run _set_other first, since _set_lang needs RoodDir set ret = self._set_other(req) if ret != apache.OK: return ret ret = self._set_lang(req) if ret != apache.OK: return ret return apache.OK
def _setSessionToken(headers): """ Pushes token into rhnFlags. If doesn't exist, returns None. Pull session token out of the headers and into rhnFlags. """ log_debug(3) token = UserDictCase() if headers.has_key('X-RHN-Server-Id'): token['X-RHN-Server-Id'] = headers['X-RHN-Server-Id'] else: # This has to be here, or else we blow-up. return None prefix = "x-rhn-auth" tokenKeys = [ x for x in headers.keys() if x[:len(prefix)].lower() == prefix] for k in tokenKeys: token[k] = headers[k] rhnFlags.set("AUTH_SESSION_TOKEN", token) return token
def _setSessionToken(headers): """ Pushes token into rhnFlags. If doesn't exist, returns None. Pull session token out of the headers and into rhnFlags. """ log_debug(3) token = UserDictCase() if headers.has_key('X-RHN-Server-Id'): token['X-RHN-Server-Id'] = headers['X-RHN-Server-Id'] else: # This has to be here, or else we blow-up. return None prefix = "x-rhn-auth" tokenKeys = [x for x in headers.keys() if x[:len(prefix)].lower() == prefix] for k in tokenKeys: token[k] = headers[k] rhnFlags.set("AUTH_SESSION_TOKEN", token) return token
def _getHeaderFromFile(self, filePath, stat_info=None): """ Utility function to extract a header from an rpm. If stat_info was already passed, don't re-stat the file """ log_debug(3, filePath) if stat_info: s = stat_info else: s = None try: s = os.stat(filePath) except: raise rhnFault( 17, "Unable to read package %s" % os.path.basename(filePath)), None, sys.exc_info()[2] lastModified = s[stat.ST_MTIME] del s # XXX: not neccessary? # Get the package header from the file # since we stat()ed the file, we know it's there already fd = os.open(filePath, os.O_RDONLY) h = rhn_rpm.get_package_header(fd=fd) os.close(fd) if h is None: raise rhnFault(17, "Invalid RPM %s" % os.path.basename(filePath)) stringIO = cStringIO.StringIO() # Put the result in stringIO stringIO.write(h.unload()) del h # XXX: not neccessary? pkgFilename = os.path.basename(filePath) pkg = pkgFilename.split('.') # Replace .rpm with .hdr pkg[-1] = "hdr" pkgFilename = ".".join(pkg) extra_headers = { 'X-RHN-Package-Header': pkgFilename, } self._set_last_modified(lastModified, extra_headers=extra_headers) rhnFlags.set("AlreadyEncoded", 1) return stringIO.getvalue()
def _getHeaderFromFile(self, filePath, stat_info=None): """ Utility function to extract a header from an rpm. If stat_info was already passed, don't re-stat the file """ log_debug(3, filePath) if stat_info: s = stat_info else: s = None try: s = os.stat(filePath) except: raise rhnFault(17, "Unable to read package %s" % os.path.basename(filePath)), None, sys.exc_info()[2] lastModified = s[stat.ST_MTIME] del s # XXX: not neccessary? # Get the package header from the file # since we stat()ed the file, we know it's there already fd = os.open(filePath, os.O_RDONLY) h = rhn_rpm.get_package_header(fd=fd) os.close(fd) if h is None: raise rhnFault(17, "Invalid RPM %s" % os.path.basename(filePath)) stringIO = cStringIO.StringIO() # Put the result in stringIO stringIO.write(h.unload()) del h # XXX: not neccessary? pkgFilename = os.path.basename(filePath) pkg = pkgFilename.split('.') # Replace .rpm with .hdr pkg[-1] = "hdr" pkgFilename = ".".join(pkg) extra_headers = { 'X-RHN-Package-Header' : pkgFilename, } self._set_last_modified(lastModified, extra_headers=extra_headers) rhnFlags.set("AlreadyEncoded", 1) return stringIO.getvalue()