Commit 5ffc0bd2 authored by Andreas Jung's avatar Andreas Jung

- the 'trusted-proxy' directive in zope.conf now also accepts

        hostnames instead of IP addresses only (patch by Dieter Maurer)
parent a409af63
...@@ -46,6 +46,9 @@ Zope Changes ...@@ -46,6 +46,9 @@ Zope Changes
Bugs fixed Bugs fixed
- the 'trusted-proxy' directive in zope.conf now also accepts
hostnames instead of IP addresses only (patch by Dieter Maurer)
- Fixed test.py to not over-resolve symbolic links. Needed to run - Fixed test.py to not over-resolve symbolic links. Needed to run
tests when the Products directory and a product are symlinks. tests when the Products directory and a product are symlinks.
......
...@@ -16,9 +16,10 @@ ...@@ -16,9 +16,10 @@
import logging import logging
import os import os
import re
import sys import sys
import socket import socket
from re import compile
from socket import gethostbyaddr
import ZConfig import ZConfig
...@@ -138,8 +139,10 @@ class ZopeStarter: ...@@ -138,8 +139,10 @@ class ZopeStarter:
filename = self.cfg.publisher_profile_file filename = self.cfg.publisher_profile_file
ZPublisher.Publish.install_profiling(filename) ZPublisher.Publish.install_profiling(filename)
if self.cfg.trusted_proxies: if self.cfg.trusted_proxies:
proxies = tuple(self.cfg.trusted_proxies) # DM 2004-11-24: added host name mapping (such that examples in conf file really have a chance to work
ZPublisher.HTTPRequest.trusted_proxies = proxies mapped = []
for name in self.cfg.trusted_proxies: mapped.extend(_name2Ips(name))
ZPublisher.HTTPRequest.trusted_proxies = tuple(mapped)
def setupSecurityOptions(self): def setupSecurityOptions(self):
import AccessControl import AccessControl
...@@ -403,3 +406,14 @@ def dropPrivileges(cfg): ...@@ -403,3 +406,14 @@ def dropPrivileges(cfg):
os.setuid(uid) os.setuid(uid)
logger.info('Set effective user to "%s"' % effective_user) logger.info('Set effective user to "%s"' % effective_user)
return 1 # for unit testing purposes return 1 # for unit testing purposes
# DM 2004-11-24: added
def _name2Ips(host, isIp_=compile(r'(\d+\.){3}').match):
'''map a name *host* to the sequence of its ip addresses;
use *host* itself (as sequence) if it already is an ip address.
Thus, if only a specific interface on a host is trusted,
identify it by its ip (and not the host name).
'''
if isIp_(host): return [host]
return gethostbyaddr(host)[2]
...@@ -153,3 +153,4 @@ def handleConfig(config, multihandler): ...@@ -153,3 +153,4 @@ def handleConfig(config, multihandler):
if not name.startswith('_'): if not name.startswith('_'):
handlers[name] = value handlers[name] = value
return multihandler(handlers) return multihandler(handlers)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment