HEX
Server: Apache
System: Linux dinesh8189 5.15.98-grsec-sharedvalley-2.lc.el8.x86_64 #1 SMP Thu Mar 9 09:07:30 -03 2023 x86_64
User: cgmgerenciamento1 (814285)
PHP: 8.1.26
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //usr/share/crypto-policies/python/cryptopolicies/validation/scope.py
# SPDX-License-Identifier: LGPL-2.1-or-later

# Copyright (c) 2021 Red Hat, Inc.

import fnmatch

from .general import PolicySyntaxError


class ScopeSyntaxError(PolicySyntaxError):
    pass


class ScopeUnknownError(ScopeSyntaxError):
    def __init__(self, scope_glob):
        super().__init__(f'unknown scope {scope_glob}')


class ScopeSelectorEmptyError(ScopeSyntaxError):
    def __init__(self):
        super().__init__('empty scope selector')


class ScopeSelectorIllegalCharacterError(ScopeSyntaxError):
    def __init__(self, selector):
        super().__init__(f'illegal character in scope selector `{selector}`')


class ScopeSelectorCurlyBracketsError(ScopeSyntaxError):
    def __init__(self, pattern):
        super().__init__(f'unsupported curly brackets usage in `{pattern}`')


class ScopeSelectorCommaError(ScopeSyntaxError):
    def __init__(self, pattern):
        super().__init__(f'unsupported comma usage in `{pattern}`')


class ScopeSelectorMatchedNothingError(ScopeSyntaxError):
    def __init__(self, pattern):
        super().__init__(f'scope selector `{pattern}` matches no scope')


def illegal_characters(p, original_pattern):
    if not all(c.isalnum() or c in '{,}*_-' for c in p):
        raise ScopeSelectorIllegalCharacterError(original_pattern)


def curly_brackets(p, original_pattern):
    if ((p.count('{'), p.count('}')) not in [(0, 0), (1, 1)]
            or p.startswith('{') and not p.endswith('}')
            or not p.startswith('{') and p.endswith('}')):
        raise ScopeSelectorCurlyBracketsError(original_pattern)


def resulting_globs(globs, all_scopes, original_pattern):
    if any(',' in g for g in globs):
        raise ScopeSelectorCommaError(original_pattern)
    for g in globs:
        if not g:
            raise ScopeSelectorEmptyError()
        if not fnmatch.filter(all_scopes, g):
            if '*' in g:
                raise ScopeSelectorMatchedNothingError(g)
            raise ScopeUnknownError(g)