示例#1
0
    def __init__(self, application, config):
        self._verbose = config.get("verbose", 2)
        self._application = application
        self._user_mapping = config.get("user_mapping", {})
        self._domaincontroller = config.get("domaincontroller") or WsgiDAVDomainController(self._user_mapping)
        self._acceptbasic = config.get("acceptbasic", True)
        self._acceptdigest = config.get("acceptdigest", True)
        self._defaultdigest = config.get("defaultdigest", True)
        self._noncedict = dict([])

        self._headerparser = re.compile(r"([\w]+)=([^,]*),")
        self._headermethod = re.compile(r"^([\w]+)")
        
        wdcName = "NTDomainController"
        if self._domaincontroller.__class__.__name__ == wdcName:
            if self._authacceptdigest or self._authdefaultdigest or not self._authacceptbasic:
                util.warn("WARNING: %s requires basic authentication.\n\tSet acceptbasic=True, acceptdigest=False, defaultdigest=False" % wdcName)
示例#2
0
    def __init__(self, application, config):
        self._verbose = config.get("verbose", 2)
        self._application = application
        self._user_mapping = config.get("user_mapping", {})
        self._domaincontroller = config.get("domaincontroller") or WsgiDAVDomainController(self._user_mapping)
        self._acceptbasic = config.get("acceptbasic", True)
        self._acceptdigest = config.get("acceptdigest", True)
        self._defaultdigest = config.get("defaultdigest", True)
        self._noncedict = dict([])

        self._headerparser = re.compile(r"([\w]+)=([^,]*),")
        # Note: extra parser to handle digest auth requests from certain
        # clients, that leave commas un-encoded to interfere with the above.
        self._headerfixparser = re.compile(r'([\w]+)=("[^"]*,[^"]*"),')
        self._headermethod = re.compile(r"^([\w]+)")
        
        wdcName = "NTDomainController"
        if self._domaincontroller.__class__.__name__ == wdcName:
            if self._authacceptdigest or self._authdefaultdigest or not self._authacceptbasic:
                util.warn("WARNING: %s requires basic authentication.\n\tSet acceptbasic=True, acceptdigest=False, defaultdigest=False" % wdcName)
示例#3
0
    def __init__(self, config):
        self.config = config

        util.initLogging(config["verbose"], config.get("enable_loggers", []))

        util.log("Default encoding: %s (file system: %s)" %
                 (sys.getdefaultencoding(), sys.getfilesystemencoding()))

        # Evaluate configuration and set defaults
        _checkConfig(config)
        provider_mapping = self.config["provider_mapping"]
        #        response_trailer = config.get("response_trailer", "")
        self._verbose = config.get("verbose", 2)

        lockStorage = config.get("locksmanager")
        if lockStorage is True:
            lockStorage = LockStorageDict()

        if not lockStorage:
            locksManager = None
        else:
            locksManager = LockManager(lockStorage)

        propsManager = config.get("propsmanager")
        if not propsManager:
            # Normalize False, 0 to None
            propsManager = None
        elif propsManager is True:
            propsManager = PropertyManager()

        mount_path = config.get("mount_path")

        user_mapping = self.config.get("user_mapping", {})
        domainController = config.get(
            "domaincontroller") or WsgiDAVDomainController(user_mapping)
        isDefaultDC = isinstance(domainController, WsgiDAVDomainController)

        # authentication fields
        authacceptbasic = config.get("acceptbasic", True)
        authacceptdigest = config.get("acceptdigest", True)
        authdefaultdigest = config.get("defaultdigest", True)

        # Check configuration for NTDomainController
        # We don't use 'isinstance', because include would fail on non-windows boxes.
        wdcName = "NTDomainController"
        if domainController.__class__.__name__ == wdcName:
            if authacceptdigest or authdefaultdigest or not authacceptbasic:
                util.warn(
                    "WARNING: %s requires basic authentication.\n\tSet acceptbasic=True, acceptdigest=False, defaultdigest=False"
                    % wdcName)

        # Instantiate DAV resource provider objects for every share
        self.providerMap = {}
        for (share, provider) in provider_mapping.items():
            # Make sure share starts with, or is, '/'
            share = "/" + share.strip("/")

            # We allow a simple string as 'provider'. In this case we interpret
            # it as a file system root folder that is published.
            if isinstance(provider, basestring):
                provider = FilesystemProvider(provider)

            assert isinstance(provider, DAVProvider)

            provider.setSharePath(share)
            if mount_path:
                provider.setMountPath(mount_path)

            # TODO: someday we may want to configure different lock/prop managers per provider
            provider.setLockManager(locksManager)
            provider.setPropManager(propsManager)

            self.providerMap[share] = provider

        if self._verbose >= 2:
            print "Using lock manager: %r" % locksManager
            print "Using property manager: %r" % propsManager
            print "Using domain controller: %s" % domainController
            print "Registered DAV providers:"
            for share, provider in self.providerMap.items():
                hint = ""
                if isDefaultDC and not user_mapping.get(share):
                    hint = " (anonymous)"
                print "  Share '%s': %s%s" % (share, provider, hint)

        # If the default DC is used, emit a warning for anonymous realms
        if isDefaultDC and self._verbose >= 1:
            for share in self.providerMap:
                if not user_mapping.get(share):
                    # TODO: we should only warn here, if --no-auth is not given
                    print "WARNING: share '%s' will allow anonymous access." % share

        # Define WSGI application stack
        application = RequestResolver()

        if config.get("dir_browser") and config["dir_browser"].get(
                "enable", True):
            application = WsgiDavDirBrowser(application)

        application = HTTPAuthenticator(application, domainController,
                                        authacceptbasic, authacceptdigest,
                                        authdefaultdigest)
        application = ErrorPrinter(application, catchall=False)

        application = WsgiDavDebugFilter(application, config)

        self._application = application