HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/ipalib/__pycache__/config.cpython-39.opt-1.pyc
a

}�f�a�@s�dZddlmZddlZddlmZddlZddlmZmZddl	m
Z
mZddlZddl
mZddlmZdd	lmZdd
lmZmZmZmZmZmZmZmZddlmZejr�eZ Gdd
�d
�Z!dS)ap
Process-wide static configuration and environment.

The standard run-time instance of the `Env` class is initialized early in the
`ipalib` process and is then locked into a read-only state, after which no
further changes can be made to the environment throughout the remaining life
of the process.

For the per-request thread-local information, see `ipalib.request`.
�)�absolute_importN)�path)�urlparse�
urlunparse)�RawConfigParser�ParsingError)�tasks)�DN)�
check_name)�CONFIG_SECTION�OVERRIDE_ERROR�	SET_ERROR�	DEL_ERROR�TLS_VERSIONS�TLS_VERSION_DEFAULT_MIN�TLS_VERSION_DEFAULT_MAX�USER_CACHE_PATH)�errorsc@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)S)*�Enva�
    Store and retrieve environment variables.

    First an foremost, the `Env` class provides a handy container for
    environment variables.  These variables can be both set *and* retrieved
    either as attributes *or* as dictionary items.

    For example, you can set a variable as an attribute:

    >>> env = Env()
    >>> env.attr = 'I was set as an attribute.'
    >>> env.attr
    u'I was set as an attribute.'
    >>> env['attr']  # Also retrieve as a dictionary item
    u'I was set as an attribute.'

    Or you can set a variable as a dictionary item:

    >>> env['item'] = 'I was set as a dictionary item.'
    >>> env['item']
    u'I was set as a dictionary item.'
    >>> env.item  # Also retrieve as an attribute
    u'I was set as a dictionary item.'

    The variable names must be valid lower-case Python identifiers that neither
    start nor end with an underscore.  If your variable name doesn't meet these
    criteria, a ``ValueError`` will be raised when you try to set the variable
    (compliments of the `base.check_name()` function).  For example:

    >>> env.BadName = 'Wont work as an attribute'
    Traceback (most recent call last):
      ...
    ValueError: name must match '^[a-z][_a-z0-9]*[a-z0-9]$|^[a-z]$'; got 'BadName'
    >>> env['BadName'] = 'Also wont work as a dictionary item'
    Traceback (most recent call last):
      ...
    ValueError: name must match '^[a-z][_a-z0-9]*[a-z0-9]$|^[a-z]$'; got 'BadName'

    The variable values can be ``str``, ``int``, or ``float`` instances, or the
    ``True``, ``False``, or ``None`` constants.  When the value provided is an
    ``str`` instance, some limited automatic type conversion is performed, which
    allows values of specific types to be set easily from configuration files or
    command-line options.

    So in addition to their actual values, the ``True``, ``False``, and ``None``
    constants can be specified with an ``str`` equal to what ``repr()`` would
    return.  For example:

    >>> env.true = True
    >>> env.also_true = 'True'  # Equal to repr(True)
    >>> env.true
    True
    >>> env.also_true
    True

    Note that the automatic type conversion is case sensitive.  For example:

    >>> env.not_false = 'false'  # Not equal to repr(False)!
    >>> env.not_false
    u'false'

    If an ``str`` value looks like an integer, it's automatically converted to
    the ``int`` type.

    >>> env.lucky = '7'
    >>> env.lucky
    7

    Leading and trailing white-space is automatically stripped from ``str``
    values.  For example:

    >>> env.message = '  Hello!  '  # Surrounded by double spaces
    >>> env.message
    u'Hello!'
    >>> env.number = ' 42 '  # Still converted to an int
    >>> env.number
    42
    >>> env.false = ' False '  # Still equal to repr(False)
    >>> env.false
    False

    Also, empty ``str`` instances are converted to ``None``.  For example:

    >>> env.empty = ''
    >>> env.empty is None
    True

    `Env` variables are all set-once (first-one-wins).  Once a variable has been
    set, trying to override it will raise an ``AttributeError``.  For example:

    >>> env.date = 'First'
    >>> env.date = 'Second'
    Traceback (most recent call last):
      ...
    AttributeError: cannot override Env.date value u'First' with 'Second'

    An `Env` instance can be *locked*, after which no further variables can be
    set.  Trying to set variables on a locked `Env` instance will also raise
    an ``AttributeError``.  For example:

    >>> env = Env()
    >>> env.okay = 'This will work.'
    >>> env.__lock__()
    >>> env.nope = 'This wont work!'
    Traceback (most recent call last):
      ...
    AttributeError: locked: cannot set Env.nope to 'This wont work!'

    `Env` instances also provide standard container emulation for membership
    testing, counting, and iteration.  For example:

    >>> env = Env()
    >>> 'key1' in env  # Has key1 been set?
    False
    >>> env.key1 = 'value 1'
    >>> 'key1' in env
    True
    >>> env.key2 = 'value 2'
    >>> len(env)  # How many variables have been set?
    2
    >>> list(env)  # What variables have been set?
    ['key1', 'key2']

    Lastly, in addition to all the handy container functionality, the `Env`
    class provides high-level methods for bootstraping a fresh `Env` instance
    into one containing all the run-time and configuration information needed
    by the built-in freeIPA plugins.

    These are the `Env` bootstraping methods, in the order they must be called:

        1. `Env._bootstrap()` - initialize the run-time variables and then
           merge-in variables specified on the command-line.

        2. `Env._finalize_core()` - merge-in variables from the configuration
           files and then merge-in variables from the internal defaults, after
           which at least all the standard variables will be set.  After this
           method is called, the plugins will be loaded, during which
           third-party plugins can merge-in defaults for additional variables
           they use (likely using the `Env._merge()` method).

        3. `Env._finalize()` - one last chance to merge-in variables and then
           the instance is locked.  After this method is called, no more
           environment variables can be set during the remaining life of the
           process.

    However, normally none of these three bootstraping methods are called
    directly and instead only `plugable.API.bootstrap()` is called, which itself
    takes care of correctly calling the `Env` bootstrapping methods.
    FcKs6t�|di�t�|dt��|r2|jfi|��dS)N�_Env__d�
_Env__done)�object�__setattr__�set�_merge)�selfZ
initialize�r�1/usr/lib/python3.9/site-packages/ipalib/config.py�__init__�szEnv.__init__cCs,|jdurtd|jj��t�|dd�dS)z9
        Prevent further changes to environment.
        Tz%s.__lock__() already called�_Env__lockedN)r�	Exception�	__class__�__name__rr�rrrr�__lock__�s


�zEnv.__lock__cCs|jS)z,
        Return ``True`` if locked.
        )rr#rrr�__islocked__�szEnv.__islocked__cCs|||<dS)zn
        Set the attribute named ``name`` to ``value``.

        This just calls `Env.__setitem__()`.
        Nr)r�name�valuerrrr�szEnv.__setattr__cCs�|jrtt|jj||f��t|�||jvrLtt|jj||j||f��t|t	�r�|�
�}t|t�rr|�d�}ddddd�}||vr�||}n"|�
�r�t|�}n|dkr�t|�}t|�tttttd�tfvr�t||��t�|||�||j|<dS)z+
        Set ``key`` to ``value``.
        zutf-8TFN)�True�False�None��basedn)r�AttributeErrorr
r!r"r
rr�
isinstance�str�strip�bytes�decode�isdigit�intr	�type�unicode�float�bool�	TypeErrorrr)r�keyr'�mrrr�__setitem__�s8�
�


�


zEnv.__setitem__cCs
|j|S)z<
        Return the value corresponding to ``key``.
        �r�rr:rrr�__getitem__szEnv.__getitem__cCstt|jj|f��dS)a#
        Raise an ``AttributeError`` (deletion is never allowed).

        For example:

        >>> env = Env()
        >>> env.name = 'A value'
        >>> del env.name
        Traceback (most recent call last):
          ...
        AttributeError: locked: cannot delete Env.name
        N)r-rr!r"�rr&rrr�__delattr__s
�zEnv.__delattr__cCs
||jvS)zS
        Return True if instance contains ``key``; otherwise return False.
        r=r>rrr�__contains__-szEnv.__contains__cCs
t|j�S)z;
        Return number of variables currently set.
        )�lenrr#rrr�__len__3szEnv.__len__ccst|j�D]
}|Vq
dS)z:
        Iterate through keys in ascending order.
        N)�sortedrr>rrr�__iter__9szEnv.__iter__cKs:d}|��D] \}}||vr|||<|d7}q|t|�fS)a
        Merge variables from ``kw`` into the environment.

        Any variables in ``kw`` that have already been set will be ignored
        (meaning this method will *not* try to override them, which would raise
        an exception).

        This method returns a ``(num_set, num_total)`` tuple containing first
        the number of variables that were actually set, and second the total
        number of variables that were provided.

        For example:

        >>> env = Env()
        >>> env._merge(one=1, two=2)
        (2, 2)
        >>> env._merge(one=1, three=3)
        (1, 2)
        >>> env._merge(one=1, two=2, three=3)
        (0, 3)

        Also see `Env._merge_from_file()`.

        :param kw: Variables provides as keyword arguments.
        r�)�itemsrC)r�kw�ir:r'rrrr@s
z
Env._mergecCs�t�|�sdSt�}z|�|�Wnty6YdS0|�t�sL|�t�|�t�}t	|�dkrfdSd}|D] \}}||vrn|||<|d7}qnd|vr�d|d<|t	|�fS)a�
        Merge variables from ``config_file`` into the environment.

        Any variables in ``config_file`` that have already been set will be
        ignored (meaning this method will *not* try to override them, which
        would raise an exception).

        If ``config_file`` does not exist or is not a regular file, or if there
        is an error parsing ``config_file``, ``None`` is returned.

        Otherwise this method returns a ``(num_set, num_total)`` tuple
        containing first the number of variables that were actually set, and
        second the total number of variables found in ``config_file``.

        Also see `Env._merge()`.

        :param config_file: Path of the configuration file to load.
        Nr)rrrG�
config_loadedT)
r�isfiler�readrZhas_sectionrZadd_sectionrHrC)rZconfig_file�parserrHrJr:r'rrr�_merge_from_fileas(




zEnv._merge_from_filecGs2||vr*||dur*tj||g|�R�SdSdS)a
        Append path components in ``parts`` to base path ``self[key]``.

        For example:

        >>> env = Env()
        >>> env.home = '/people/joe'
        >>> env._join('home', 'Music', 'favourites')
        u'/people/joe/Music/favourites'
        N)r�join)rr:�partsrrr�_join�sz	Env._joincCs.||jvrtd|jj|f��|j�|�dS)Nz%s.%s() already called)rr r!r"�addr@rrrZ__doing�s

�zEnv.__doingcCs||jvrt||��dS�N)r�getattrr@rrrZ__do_if_not_done�s
zEnv.__do_if_not_donecCs
||jvSrT)rr@rrr�_isdone�szEnv._isdonecKs6|�d�t�t�t��|_t�|j�|_t�tjd�|_	t�|j	�|_
tj�d�}|�
d�sd|nd|_t��|_|jfi|��d|vr�tj�tj�|jd��|_|jr�d|vr�d|_d	|vr�|�d
d�|_d|vr�d
|_tj�d�|_d|v�r|jdu�rt�d��d|v�r||jdu�rZt�|j��r>t� |j��sPt�d�!|j���|j|_"n"|j�rl|j|_"nt�ddd�|_"d|v�r�|�dd|j�|_#d|v�r�|�dd�|_$d|v�r�|�dd�|_%d|v�r�tj�t&d�|_'d|v�r�|�dd�|_(t�|j(��st�d�!|j(���d|v�r2|jd k|_)dS)!a�
        Initialize basic environment.

        This method will perform the following steps:

            1. Initialize certain run-time variables.  These run-time variables
               are strictly determined by the external environment the process
               is running in; they cannot be specified on the command-line nor
               in the configuration files.

            2. Merge-in the variables in ``overrides`` by calling
               `Env._merge()`.  The intended use of ``overrides`` is to merge-in
               variables specified on the command-line.

            3. Intelligently fill-in the *in_tree*, *context*, *conf*, and
               *conf_default* variables if they haven't been set already.

        Also see `Env._finalize_core()`, the next method in the bootstrap
        sequence.

        :param overrides: Variables specified via command-line options.
        �
_bootstrapr�~N�in_treezipasetup.py.in�modeZ	developer�dot_ipa�homez.ipa�context�defaultZIPA_CONFDIR�confdirz>IPA_CONFDIR env cannot be set because explicit confdir is usedzPIPA_CONFDIR env var must be an absolute path to an existing directory, got '{}'.�/�etc�ipa�confz%s.conf�conf_defaultzdefault.conf�nss_dirZnssdb�	cache_dir�tls_ca_certzca.crtzDtls_ca_cert has to be an absolute path to a CA certificate, got '{}'�plugins_on_demandZcli)*�_Env__doingr�dirname�abspath�__file__�ipalibZ
site_packages�sys�argvZscript�bin�os�
expanduser�
startswithr\rZis_fips_enabledZ	fips_moderrLrPrYrZrRr[r]�environ�getZenv_confdirr�EnvironmentError�isabs�isdir�formatr_rcrdrerrfrgrh)rZ	overridesr\rrrrW�sp

��

���






��
zEnv._bootstrapcKs�|�d�|�d�|j�d�}|dkr@|�|j�|�|j�d|vrT|jdk|_d|vr�|j	sh|jsx|�
dd	�|_nt�
d
dd	d�|_d	|vr�|�
dd
|j�|_|jr�|jdkr�t|dd�s�d|vr�d|_d|vr�|j��|_d|v�rd|v�rtdd�|j�d�D��|_d|v�r6d|v�r6d�|j�|_d|v�rXd|v�rXd�|j�|_d|v�r�d|v�rt|j}n
|�d�}|�r�t|�\}}}}}}	|�ddd�}t||||||	f�|_d|v�r�d|v�r�|j}
n
|�d�}
|
�r�t|
�}|j|_|jfi|��d |v�rt |_!|j!d!u�rD|j!t"v�rDt#�$d"j|j!d#���d$|v�rTt%|_&|j&d!u�r�|j&t"v�r�t#�$d%j|j&d#���|j!d!u�r�|j&d!u�r�|j&|j!k�r�t#�$d&��d!S)'a�
        Complete initialization of standard IPA environment.

        This method will perform the following steps:

            1. Call `Env._bootstrap()` if it hasn't already been called.

            2. Merge-in variables from the configuration file ``self.conf``
               (if it exists) by calling `Env._merge_from_file()`.

            3. Merge-in variables from the defaults configuration file
               ``self.conf_default`` (if it exists) by calling
               `Env._merge_from_file()`.

            4. Intelligently fill-in the *in_server* , *logdir*, *log*, and
               *jsonrpc_uri* variables if they haven't already been set.

            5. Merge-in the variables in ``defaults`` by calling `Env._merge()`.
               In normal circumstances ``defaults`` will simply be those
               specified in `constants.DEFAULT_CONFIG`.

        After this method is called, all the environment variables used by all
        the built-in plugins will be available.  As such, this method should be
        called *before* any plugins are loaded.

        After this method has finished, the `Env` instance is still writable
        so that 3rd-party plugins can set variables they may require as the
        plugins are registered.

        Also see `Env._finalize()`, the final method in the bootstrap sequence.

        :param defaults: Internal defaults for all built-in variables.
        �_finalize_corerWrZZdummy�	in_server�server�logdirr[�logr`�varrbz%s.logZ	installerrKF�realmzUNCONFIGURED.INVALID�domainr,css|]}d|fVqdS)�dcNr)�.0r�rrr�	<genexpr>Z�z%Env._finalize_core.<locals>.<genexpr>�.�
xmlrpc_urizhttps://{}/ipa/xml�ldap_uriz	ldap://{}�jsonrpc_uriz/xmlz/jsonrG�tls_version_minNz3Unknown TLS version '{ver}' set in tls_version_min.)Zver�tls_version_maxz3Unknown TLS version '{ver}' set in tls_version_max.zDtls_version_min is set to a higher TLS version than tls_version_max.)'ri�_Env__do_if_not_donerrurOrcrdr]r{rYrRr}rrPr~rUr��lowerr�r	�splitr,ryr|r�r�r�replacerr��netlocrrr�rrrvrr�)r�defaultsrZr��schemer�Zuripath�params�query�fragmentr��parsedrrrrzs�"


�


��



����
������
��zEnv._finalize_corecKs0|�d�|�d�|jfi|��|��dS)aV
        Finalize and lock environment.

        This method will perform the following steps:

            1. Call `Env._finalize_core()` if it hasn't already been called.

            2. Merge-in the variables in ``lastchance`` by calling
               `Env._merge()`.

            3. Lock this `Env` instance, after which no more environment
               variables can be set on this instance.  Aside from unit-tests
               and example code, normally only one `Env` instance is created,
               which means that after this step, no more variables can be set
               during the remaining life of the process.

        This method should be called after all plugins have been loaded and
        after `plugable.API.finalize()` has been called.

        :param lastchance: Any final variables to merge-in before locking.
        �	_finalizerzN)rir�rr$)rZ
lastchancerrrr��s

z
Env._finalizeN)r"�
__module__�__qualname__�__doc__rrr$r%rr<r?rArBrDrFrrOrRrir�rVrWrzr�rrrrr8s.
'!(kr)"r�Z
__future__rrqrrn�urllib.parserrZconfigparserrrZsixZipaplatform.tasksrZipapython.dnr	Zipalib.baser
Zipalib.constantsrrr
rrrrrrmrZPY3r/r6rrrrr�<module>s
(