Sindbad~EG File Manager

Current Path : /proc/self/root/usr/lib/python3.6/site-packages/SSSDConfig/__pycache__/
Upload File :
Current File : //proc/self/root/usr/lib/python3.6/site-packages/SSSDConfig/__pycache__/__init__.cpython-36.pyc

3

t�ag5��@s�dZddlZddlZddlZddlmZddlmZGdd�de�Z	Gdd	�d	e�Z
Gd
d�de	�ZGdd
�d
e	�ZGdd�de	�Z
Gdd�de	�ZGdd�de	�ZGdd�de	�ZGdd�de	�ZGdd�de	�ZGdd�de	�ZGdd�de	�ZGdd�de	�ZGd d!�d!e	�ZGd"d#�d#e	�ZGd$d%�d%e	�Zd&d'�Zd(d)�ZGd*d+�d+e�ZGd,d-�d-e�ZGd.d/�d/e�ZGd0d1�d1e�ZGd2d3�d3e�Z dS)4z,
Created on Sep 18, 2009

@author: sgallagh
�N�)�SSSDOptions)�SSSDChangeConfc@seZdZdS)�SSSDConfigExceptionN)�__name__�
__module__�__qualname__�r	r	�/usr/lib/python3.6/__init__.pyrsrc@seZdZdS)�ParsingErrorN)rrrr	r	r	r
rsrc@seZdZdS)�AlreadyInitializedErrorN)rrrr	r	r	r
rsrc@seZdZdS)�NotInitializedErrorN)rrrr	r	r	r
r
sr
c@seZdZdS)�NoOutputFileErrorN)rrrr	r	r	r
rsrc@seZdZdS)�NoServiceErrorN)rrrr	r	r	r
rsrc@seZdZdS)�NoSectionErrorN)rrrr	r	r	r
rsrc@seZdZdS)�
NoOptionErrorN)rrrr	r	r	r
rsrc@seZdZdS)�ServiceNotRecognizedErrorN)rrrr	r	r	r
rsrc@seZdZdS)�ServiceAlreadyExistsN)rrrr	r	r	r
rsrc@seZdZdS)�
NoDomainErrorN)rrrr	r	r	r
rsrc@seZdZdS)�DomainNotRecognizedN)rrrr	r	r	r
rsrc@seZdZdS)�DomainAlreadyExistsErrorN)rrrr	r	r	r
rsrc@seZdZdS)�NoSuchProviderErrorN)rrrr	r	r	r
rsrc@seZdZdS)�NoSuchProviderSubtypeErrorN)rrrr	r	r	r
rsrc@seZdZdS)�ProviderSubtypeInUseN)rrrr	r	r	r
rsrcCsdd�|D�S)NcSsg|]}|j��qSr	)�strip)�.0�xr	r	r
�
<listcomp> szstriplist.<locals>.<listcomp>r	)�lr	r	r
�	striplistsrcCs(g}x|D]}||kr
|j|�q
W|S)N)�append)Zoptions1Zoptions2�overlap�optionr	r	r
�options_overlap"s

r#c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�SSSDConfigSchemacCs�tj|�|sd}|sd}yht|d��}|j|�WdQRXxBtdd�tj|��D]*}t|d|��}|j|�WdQRXqRWWn,tk
r��Yntk
r�t	�YnXt
ttj
ddkr�tnttttdd	�|_d
dd�|_dS)
Nz/usr/share/sssd/sssd.api.confz/usr/share/sssd/sssd.api.d�rcSstjd|�S)Nz^sssd-.*\.conf$)�re�search)�fr	r	r
�<lambda>7sz+SSSDConfigSchema.__init__.<locals>.<lambda>�/r�)�bool�int�long�float�str�list�NoneFT)�false�true)r�__init__�open�readfp�filter�os�listdir�IOError�SyntaxErrorrr,r-�sys�version_infor.r/r0r1�type_lookup�bool_lookup)�self�
schemafile�schemaplugindir�fd�filer	r	r
r5*s2



zSSSDConfigSchema.__init__cCs|j|�st�|j|�}d}d}d}d}i}�x�|j|�D�]�}|d}	t|	jd��}
t|
�}|j|
|}|j|
|}
|j|
|}|dt	j
kr�t	j
|d}nd}|dkr�||
||df||d<q:|dk�rFt|
|�|k�r||
|||
|f||d<�q|tk�r�t|
|�|
k�r>||
|||
|gf||d<n�yh|
t
k�r�t|
|�tk�r�||
|||j|
|j�gf||d<n ||
|||
|
|�gf||d<Wntk
�r�t�YnXn�yd|t
k�rt|
|�tk�r||
|||j|
|j�f||d<n||
||||
|�f||d<Wntk
�rBt�YnXq:|dk�r
|tk�r^t�g}x�|
|d�D]~}t|�|
k�r�y@|
t
k�r�t|�tk�r�|j|j�}n|
|�}|j|g�Wntk
�r�t�YnXn|j|g��qpW||
|||f||d<q:t�q:W|S)	Nrrr+��value�,�name�)�has_sectionr�options�strip_comments_emptyr�split�lenr?r@rZoption_strings�typer1r,r0�lower�
ValueErrorr�extend)rA�sectionrLZPRIMARY_TYPEZSUBTYPEZ	MANDATORYZDEFAULTZparsed_optionsr"Zunparsed_optionZsplit_optionZ	optionlenZprimarytype�subtypeZ	mandatoryZdescZ
fixed_optionsr�newvaluer	r	r
�get_optionsQs�




 


zSSSDConfigSchema.get_optionscCs<|j|�st|��|j||�s.td||f��|j|�|S)NzSection [%s] has no option [%s])rKr�
has_optionrrW)rArTr"r	r	r
�
get_option�s
zSSSDConfigSchema.get_optioncs:|j|�st|��|j|��t�fdd��j�D��}|S)Ncs,g|]$}�|ddkr|�|df�qS)rJNr	)rr)�schema_optionsr	r
r�sz1SSSDConfigSchema.get_defaults.<locals>.<listcomp>)rKrrW�dict�keys)rArTZdefaultsr	)rZr
�get_defaults�s

zSSSDConfigSchema.get_defaultscCsdd�|j�D�}|S)NcSs@g|]8}|ddkr|djd�r|djd�r|d�qS)rI�service�domain�provider)�
startswith)rrr	r	r
r�sz1SSSDConfigSchema.get_services.<locals>.<listcomp>)�sections)rA�service_listr	r	r
�get_services�szSSSDConfigSchema.get_servicescCs�i}xf|j�D]Z}|djd�}|ddkrt|�dkr|d|krPg||d<||dj|dg�qWx |j�D]}t||�||<qvW|S)NrIr*rr`rFrr+)rbrNrOrSr\�tuple)rA�	providersrTZsplitsection�keyr	r	r
�
get_providers�szSSSDConfigSchema.get_providersN)	rrrr5rWrYr]rdrhr	r	r	r
r$)s'v	r$c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�SSSDConfigObjectcCsd|_i|_dS)N)rIrL)rAr	r	r
r5�szSSSDConfigObject.__init__cCs|jS)z�
        Return the name of the object

        === Returns ===
        The domain name

        === Errors ===
        No errors
        )rI)rAr	r	r
�get_name�s
zSSSDConfigObject.get_namecCs$||jj�kr|j|St|��dS)a
        Return the value of an service option

        optionname:
          The option to get.

        === Returns ===
        The value for the requested option.

        === Errors ===
        NoOptionError:
          The specified option was not listed in the service
        N)rLr\r)rA�
optionnamer	r	r
rYs
zSSSDConfigObject.get_optioncCs|jS)z�
        Return a dictionary of name/value pairs for this object

        === Returns ===
        A dictionary of name/value pairs currently in use for this object

        === Errors ===
        No errors
        )rL)rAr	r	r
�get_all_optionss
z SSSDConfigObject.get_all_optionscCs||jkr|j|=dS)z�
        Remove an option from the object. If the option does not exist, it is ignored.

        === Returns ===
        No return value.

        === Errors ===
        No errors
        N)rL)rArkr	r	r
�
remove_options

zSSSDConfigObject.remove_optionN)rrrr5rjrYrlrmr	r	r	r
ri�s
ric@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�SSSDServicez3
    Object to manipulate SSSD service options
    cCs~tj|�t|t�s"t|�tkr&t�|j|�s8t|��||_	||_
i|_g|_|jj
|j
jd��|jj
|j
j|j	��dS)a\
        Create a new SSSDService, setting its defaults to those found in the
        schema. This constructor should not be used directly. Use
        SSSDConfig.new_service() instead.

        name:
          The service name
        apischema:
          An SSSDConfigSchema? object created by SSSDConfig.__init__()

        === Returns ===
        The newly-created SSSDService object.

        === Errors ===
        TypeError:
          The API schema passed in was unusable or the name was not a string.
        ServiceNotRecognizedError:
          The service was not listed in the schema
        r^N)rir5�
isinstancer$rPr0�	TypeErrorrKrrI�schemarL�hidden_options�updater])rA�servicename�	apischemar	r	r
r50s

zSSSDService.__init__cCs6i}|jjd�}|j|�|jj|j�}|j|�|S)aI
        List options for the service, including the mandatory flag.

        === Returns ===
        A dictionary of configurable options. This dictionary is keyed on the
        option name with a tuple of the variable type, subtype ('None' if the
        type is not  a collection type), whether it is mandatory, the
        translated option description, and the default value (or 'None') as
        the value.

        Example:
        { 'enumerate' :
          (bool, None, False, u'Enable enumerating all users/groups', True) }

        === Errors ===
        No errors
        r^)rqrWrsrI)rArLrZr	r	r
�list_options_with_mandatory[s

z'SSSDService.list_options_with_mandatorycCsR|j�}i}x@|j�D]4}||d||d||d||df||<qW|S)a
        List all options that apply to this service

        === Returns ===
        A dictionary of configurable options. This dictionary is keyed on the
        option name with a tuple of the variable type, subtype ('None' if the
        type is not  a collection type), the translated option description, and
        the default value (or 'None') as the value.

        Example:
        { 'services' :
          (list, str, u'SSSD Services to start', ['nss', 'pam']) }

        === Errors ===
        No Errors
        rrrFrJ)rvr\)rArL�filtered_optionsrgr	r	r
�list_optionsxs
4zSSSDService.list_optionscCs^|j�}i}xL|j�D]@}||dr||d||d||d||df||<qW|S)a
        List all mandatory options that apply to this service

        === Returns ===
        A dictionary of configurable options. This dictionary is keyed on the
        option name with a tuple of the variable type, subtype ('None' if the
        type is not  a collection type), the translated option description, and
        the default value (or 'None') as the value.

        Example:
        { 'services' :
          (list, str, u'SSSD Services to start', ['nss', 'pam']) }

        === Errors ===
        No Errors
        r+rrrFrJ)rvr\)rArLrwrgr	r	r
�list_mandatory_options�s4z"SSSDService.list_mandatory_optionscCsR|jj|j|�r"|jj|j|�}nH|jjd|�r@|jjd|�}n*||jkrX||j|<dStd|j|f��|dkr�|j|�dSd}|dtkr�t	|�tkr�t	|�t
kr�t|jd��}n|g}t	|�|dk�r�yb|dt
kr�t	|�t
kr�|jj|j�}n4|dtk�r$t	|�t
k�r$t|d�}n|d|�}Wn2tk
�rLd}Yntk
�rdd}YnX|�r�td|d|t	|�f��t	|�tk�rDybg}xX|D]P}|d	t
k�r�t	|�t
k�r�|j|jj|j�g�n|j|d	|�g��q�WWn2tk
�rd}Yntk
�r(d}YnX|�r@td
|d	��|}||j|<dS)a
        Set a service option to the specified value (or values)

        optionname:
          The option to change
        value:
          The value to set. This may be a single value or a list of values. If
          it is set to None, it resets the option to its default.

        === Returns ===
        No return value

        === Errors ===
        NoOptionError:
          The specified option is not listed in the schema
        TypeError:
          The value specified was not of the expected type
        r^NzSection [%s] has no option [%s]FrrHTzExpected %s for %s, received %srzExpected %s)rqrXrIrYrrrLrrmr1rPr0rrNr,r@rQr-rR�KeyErrorrprS)rArkrG�
option_schema�raise_errorrVrr	r	r
�
set_option�s\





zSSSDService.set_optionN)	rrr�__doc__r5rvrxryr}r	r	r	r
rn+s+rnc@sjeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�
SSSDDomainz2
    Object to manipulate SSSD domain options
    cCsvtj|�t|t�s"t|�tkr&t�||_||_d|_	d|_
g|_i|_|jj
|jjd��|jj
|jjd��dS)a
        Creates a new, empty SSSDDomain. This domain is inactive by default.
        This constructor should not be used directly. Use
        SSSDConfig.new_domain() instead.

        name:
          The domain name.
        apischema:
          An SSSDConfigSchema object created by SSSDConfig.__init__()

        === Returns ===
        The newly-created SSSDDomain object.

        === Errors ===
        TypeError:
          apischema was not an SSSDConfigSchema object or domainname was not
         a string
        FNr`r_)rir5ror$rPr0rprIrq�active�oldnamerfrLrsr])rAZ
domainnamerur	r	r
r5
s
zSSSDDomain.__init__cCst|�|_dS)ad
        Enable or disable this domain

        active:
          Boolean value. If True, this domain will be added to the active
          domains list when it is saved. If False, it will be removed from the
          active domains list when it is saved.

        === Returns ===
        No return value

        === Errors ===
        No errors
        N)r,r�)rAr�r	r	r
�
set_active/szSSSDDomain.set_activecCsxi}|j|jjd��|j|jjd��xJ|jD]@\}}|jjd|�}|j|�|jjd||f�}|j|�q0W|S)ag
        List options for the currently-configured providers, including the
        mandatory flag

        === Returns ===
        A dictionary of configurable options. This dictionary is keyed on the
        option name with a tuple of the variable type, subtype ('None' if the
        type is not  a collection type), whether it is mandatory, the
        translated option description, and the default value (or 'None') as
        the value.

        Example:
        { 'enumerate' :
          (bool, None, False, u'Enable enumerating all users/groups', True) }

        === Errors ===
        No errors
        r`r_zprovider/%szprovider/%s/%s)rsrqrWrf)rArLr`ZprovidertyperZr	r	r
rv@s
z&SSSDDomain.list_options_with_mandatorycCsR|j�}i}x@|j�D]4}||d||d||d||df||<qW|S)a$
        List options available for the currently-configured providers.

        === Returns ===
        A dictionary of configurable options. This dictionary is keyed on the
        option name with a tuple of the variable type, subtype ('None' if the
        type is not  a collection type), the translated option description, and
        the default value (or 'None') as the value.

        Example:
        { 'enumerate' :
          (bool, None, u'Enable enumerating all users/groups', True) }

        === Errors ===
        No errors
        rrrFrJ)rvr\)rArLrwrgr	r	r
rxds
4zSSSDDomain.list_optionscCs^|j�}i}xL|j�D]@}||dr||d||d||d||df||<qW|S)a$
        List mandatory options for the currently-configured providers.

        === Returns ===
        A dictionary of configurable options. This dictionary is keyed on the
        option name with a tuple of the variable type, subtype ('None' if the
        type is not  a collection type), the translated option description, and
        the default value (or 'None') as the value.

        Example:
        { 'enumerate' :
          (bool, None, u'Enable enumerating all users/groups', True) }

        === Errors ===
        No errors
        r+rrrFrJ)rvr\)rArLrwrgr	r	r
rys4z!SSSDDomain.list_mandatory_optionsNcCs`|jjd|�}|r0|j|jjd||f��n,|j�}x"||D]}|j|j||��qBW|S)a�
        If provider_type is specified, list all options applicable to that
        target, otherwise list all possible options available for a provider.

        type:
            Provider backend type. (e.g. local, ldap, krb5, etc.)
        provider_type:
            Subtype of the backend type. (e.g. id, auth, access, chpass)

        === Returns ===

        A dictionary of configurable options for the specified provider type.
        This dictionary is keyed on the option name with a tuple of the
        variable type, subtype ('None' if the type is not  a collection type),
        the translated option description, and the default value (or 'None')
        as the value.

        === Errors ===

        NoSuchProviderError:
            The specified provider is not listed in the schema or plugins
        NoSuchProviderSubtypeError:
            The specified provider subtype is not listed in the schema
        zprovider/%szprovider/%s/%s)rqrWrs�list_providers�list_provider_options)rAr`�
provider_typerLZknown_providersr	r	r
r��s
z SSSDDomain.list_provider_optionscCs
|jj�S)a>
        Return a dictionary of providers.

        === Returns ===
        Returns a dictionary of providers, keyed on the primary type, with the
        value being a tuple of the subtypes it supports.

        Example:
        { 'ldap' : ('id', 'auth', 'chpass') }

        === Errors ===
        No Errors
        )rqrh)rAr	r	r
r��szSSSDDomain.list_providersc
Cs`|j�}||j�kr&td|j|f��|dkr<|j|�dS||}d}|dtkr�t|�tkr�t|�tkr|t|j	d��}n|g}t|�|dk�rFy^|dt
kr�t|�tkr�|jj|j
�}n0|dtkr�t|�tkr�t|d�}n|d|�}Wn2tk
�rd}Yntk
�r$d}YnX|�rFtd|d|t|�f��t|�tk�rybg}xX|D]P}|dt
k�r�t|�tk�r�|j|jj|j
�g�n|j|d|�g��q`WWn2tk
�r�d}Yntk
�r�d}YnX|�rtd	|d��|}|jd
�}|dk�rR|d|�}	y|j||	�Wntk
�rNt�YnXn
||j|<dS)a
        Set a domain option to the specified value (or values)

        option:
          The option to change.
        value:
          The value to set. This may be a single value or a list of values.
          If it is set to None, it resets the option to its default.

        === Returns ===
        No return value.

        === Errors ===
        NoOptionError:
            The specified option is not listed in the schema
        TypeError:
            The value specified was not of the expected type
        zSection [%s] has no option [%s]NFrrHTzExpected %s for %s, received %srzExpected %s�	_provider)rxr\rrIrmr1rPr0rrNr,rqr@rQr-rRrzrprS�rfind�add_providerrrL)
rAr"rGrLr{r|rVrZis_providerr`r	r	r
r}�sf





zSSSDDomain.set_optioncCs(t|�tkrt�|js|j|_||_dS)z�
        Change the name of the domain

        newname:
          New name for this domain

        === Returns ===
        No return value.

        === Errors ===
        TypeError:
          newname was not a string
        N)rPr0rpr�rI)rAZnewnamer	r	r
�set_name-s
zSSSDDomain.set_namecs�|j�}||j�kr*�||kr.t���nt��fdd�|jD�}t|�dkrRt�t|�dkr�|dd|kr�t|dd��n|jj|�fg�d�}||j|<|jj	|j
jd|��|jj	|j
jd|�f��dS)	aH
        Add a new provider type to the domain

        type:
          Provider backend type. (e.g. local, ldap, krb5, etc.)
        subtype:
          Subtype of the backend type. (e.g. id, auth, chpass)

        === Returns ===
        No return value.

        === Errors ===
        ProviderSubtypeInUse:
          Another backend is already providing this subtype
        NoSuchProviderError:
          The specified provider is not listed in the schema or plugins
        NoSuchProviderSubtypeError:
          The specified provider subtype is not listed in the schema
        csg|]}|d�kr|�qS)rr	)rr)r�r	r
rasz+SSSDDomain.add_provider.<locals>.<listcomp>rrz%s_providerzprovider/%szprovider/%s/%sN)r�r\rrrfrOrrSrLrsrqr])rAr`r��configured_providersZwith_this_typeZoption_namer	)r�r
r�Ds&


zSSSDDomain.add_providerc
Cs�d}x |jD]\}}||krPd}qW|s.dS|j||�}xV|jD]L\}}||f||fkr\qB|j||�}t|j�|j��}x|D]
}||=q�WqBWx|D]}	|	|jkr�|j|	=q�Wd|}	|	|jkr�|j|	=|jj||f�dS)a
        Remove a provider from the domain. If the provider is not present, it
        is ignored.

        provider_type:
          Subtype of the backend type. (e.g. id, auth, chpass)

        === Returns ===
        No return value.

        === Errors ===
        No Errors
        Nz%s_provider)rfr�r#r\rL�remove)
rAr�r`ZptyperLZprovZprovider_optionsr!�optr"r	r	r
�remove_providerus,



zSSSDDomain.remove_provider)N)rrrr~r5r�rvrxryr�r�r}r�r�r�r	r	r	r
rs%$
'[1rc@s�eZdZdZd1dd�Zd2dd�Zdd�Zd3d	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�ZdS)4�
SSSDConfigzQ
    class SSSDConfig
    Primary class for operating on SSSD configurations
    NcCs,tj|�t||�|_d|_d|_d|_dS)a+
        Initialize the SSSD config parser/editor. This constructor does not
        open or create a config file. If the schemafile and schemaplugindir
        are not passed, it will use the system defaults.

        schemafile:
          The path to the API schema config file. Usually
          /usr/share/sssd/sssd.api.conf
        schemaplugindir:
          The path the directory containing the provider schema config files.
          Usually /usr/share/sssd/sssd.api.d

        === Returns ===
        The newly-created SSSDConfig object.

        === Errors ===
        IOError:
          Exception raised when the schema file could not be opened for
          reading.
        ParsingError:
          The main schema file or one of those in the plugin directory could
          not be parsed.
        NFr+)rr5r$rq�
configfile�initialized�API_VERSION)rArBrCr	r	r
r5�s

zSSSDConfig.__init__cCs�|jr
t�|sd}t|d��.}y|j|�Wntk
rDt�YnXWdQRX||_d|_y"t|jdd��|j	kr|td��Wnt
k
r�YnXdS)a�
        Read in a config file, populating all of the service and domain
        objects with the read values.

        configfile:
          The path to the SSSD config file. If not specified, use the system
          default, usually /etc/sssd.conf

        === Returns ===
        No return value

        === Errors ===
        IOError:
          Exception raised when the file could not be opened for reading
        ParsingError:
          Exception raised when errors occur attempting to parse a file.
        AlreadyInitializedError:
          This SSSDConfig object was already initialized by a call to
          import_config() or new_config()
        z/etc/sssd/sssd.confr%NT�sssdZconfig_file_versionzWrong config_file_version)r�rr6r7�	Exceptionrr�r-�getr�rp)rAr�rDr	r	r
�
import_config�s zSSSDConfig.import_configcCs2|jr
t�d|_x|jj�D]}|j|�}qWdS)a/
        Initialize the SSSDConfig object with the defaults from the schema.

        === Returns ===
        No return value

        === Errors ===
        AlreadyInitializedError:
          This SSSDConfig object was already initialized by a call to
          import_config() or new_config()
        TN)r�rrqrd�new_service)rArtr^r	r	r
�
new_config�s
zSSSDConfig.new_configc	Csj|js
t�|dkr&|jdkr t�|j}tjd�}t|d��}|j|j�}|j	|�WdQRXtj|�dS)a�
        Write out the configuration to a file.

        outputfile:
          The path to write the new config file. If it is not specified, it
          will use the path specified by the import() call.
        === Returns ===
        No return value

        === Errors ===
        IOError:
          Exception raised when the file could not be opened for writing
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        NoOutputFileError:
          No outputfile was specified and this SSSDConfig object was not
          initialized by import()
        N��w)
r�r
r�rr9�umaskr6�dump�opts�write)rAZ
outputfileZ	old_umaskZof�outputr	r	r
r�s

zSSSDConfig.writecCs~|js
t�|jdd�rvt|jdd�jd��}tj|�}d|krD|d=|j�}xt	|�D]}||krV||=qVWt	|�}ng}|S)a
        Return a list of all active services.

        === Returns ===
        The list of active services.

        === Errors ===
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        r��servicesrH�)
r�r
rXrr�rNr[�fromkeys�
list_servicesr1)rA�active_services�service_dictZconfigured_servicesZsrvr	r	r
�list_active_services3s


zSSSDConfig.list_active_servicescsL|js
t�|jdd�r.t|jdd�jd���ng��fdd�|j�D�}|S)a
        Return a list of all disabled services.

        === Returns ===
        The list of inactive services.

        === Errors ===
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        r�r�rHcsg|]}|�kr|�qSr	r	)rr)r�r	r
risz5SSSDConfig.list_inactive_services.<locals>.<listcomp>)r�r
rXrr�rNr�)rAr�r	)r�r
�list_inactive_servicesUsz!SSSDConfig.list_inactive_servicescCs |js
t�dd�|j�D�}|S)a
        Retrieve a list of known services.

        === Returns ===
        The list of known services.

        === Errors ===
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        cSs"g|]}|djd�s|d�qS)rIr_)ra)rrr	r	r
r|sz,SSSDConfig.list_services.<locals>.<listcomp>)r�r
rb)rArcr	r	r
r�mszSSSDConfig.list_servicescCsp|js
t�|j|�st�t||j�}xF|j|j|��D]2}y|j|d|d�Wq6t	k
rfYq6Xq6W|S)a�
        Get an SSSDService object to edit a service.

        name:
          The name of the service to return.

        === Returns ===
        An SSSDService instance containing the current state of a service in
        the SSSDConfig

        === Errors ===
        NoServiceError:
          There is no such service with the specified name in the SSSDConfig.
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        rIrG)
r�r
rKrrnrqrMrLr}r)rArIr^r�r	r	r
�get_service�s

zSSSDConfig.get_servicecCs6|js
t�|j|�rt|��t||j�}|j|�|S)a�
        Create a new service from the defaults and return the SSSDService
        object for it. This function will also add this service to the list of
        active services in the [SSSD] section.

        name:
          The name of the service to create and return.

        === Returns ===
        The newly-created SSSDService object

        === Errors ===
        ServiceNotRecognizedError:
          There is no such service in the schema.
        ServiceAlreadyExistsError:
          The service being created already exists in the SSSDConfig object.
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        )r�r
rKrrnrq�save_service)rArIr^r	r	r
r��s

zSSSDConfig.new_servicecCs�|js
t�||j�krt�|jdd�d}|s@|jdd|�dStjt|dj	d���}d|krf|d=d||<|jdddj
|j���dS)	a�
        Activate a service

        name:
          The name of the service to activate

        === Returns ===
        No return value

        === Errors ===
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        NoServiceError:
          There is no such service with the specified name in the SSSDConfig.
        r�r�rNrGrHr�z, )r�r
r�r�get_option_index�setr[r�rrN�joinr\)rArI�itemr�r	r	r
�activate_service�szSSSDConfig.activate_servicecCs�|js
t�||j�krt�|jdd�d}|s@|jddd�dStjt|dj	d���}d|krf|d=||krt||=|jdddj
|j���dS)	a�
        Deactivate a service

        name:
          The name of the service to deactivate

        === Returns ===
        No return value

        === Errors ===
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        NoServiceError:
          There is no such service with the specified name in the SSSDConfig.
        r�r�rr�NrGrHz, )r�r
r�rr�r�r[r�rrNr�r\)rArIr�r�r	r	r
�deactivate_service�szSSSDConfig.deactivate_servicecCs|js
t�|jd|�dS)a�
        Remove a service from the SSSDConfig object. This function will also
        remove this service from the list of active services in the [SSSD]
        section. Has no effect if the service does not exist.

        === Returns ===
        No return value

        === Errors ===
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        rTN)r�r
�
delete_option)rArIr	r	r
�delete_serviceszSSSDConfig.delete_servicecCs�|js
t�t|t�st�|j�}|jd|�}g}xV|j�j�D]F\}}t	|�t
kr\dj|�}|dkrn|j|�}|j
d|t|�d��q>W|j|||�dS)a�
        Save the changes made to the service object back to the SSSDConfig
        object.

        service_object:
          The SSSDService object to save to the configuration.

        === Returns ===
        No return value
        === Errors ===
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        TypeError:
          service_object was not of the type SSSDService
        rTz, �debug_levelr")rPrIrGN)r�r
rornrprjr�rl�itemsrPr1r��_get_debug_level_valr r0�add_section)rAr^rI�indexZaddkwr"rGr	r	r
r�&s 


zSSSDConfig.save_servicecCs�|js
t�|jdd�rNt|jdd�jd��}tj|�}d|krD|d=t|�}ng}|j	�}xd|j	�D]X}|jd|d�r�|jd|d�dkr�|j
|�||kr�|j
|�qd||krd|j
|�qdW|S)a
        Return a list of all active domains.

        === Returns ===
        The list of configured, active domains.

        === Errors ===
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        r��domainsrHr�z	domain/%s�enabledr3)r�r
rXrr�rNr[r�r1�list_domainsr�)rA�sssd_domains�domain_dictr��domr	r	r
�list_active_domainsPs&


zSSSDConfig.list_active_domainscCs�|js
t�|jdd�rNt|jdd�jd��}tj|�}d|krD|d=t|�}ng}|j	�}xR|j	�D]F}|jd|d�r�|jd|d�dkr�|j
|�qd||krd|j
|�qdW|S)a.
        Return a list of all configured, but disabled domains.

        === Returns ===
        The list of configured, inactive domains.

        === Errors ===
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        r�r�rHr�z	domain/%sr�r4)r�r
rXrr�rNr[r�r1r�r�)rAr�r�r�r�r	r	r
�list_inactive_domainsvs"

z SSSDConfig.list_inactive_domainscCs |js
t�dd�|j�D�}|S)aL
        Return a list of all configured domains, including inactive domains.

        === Returns ===
        The list of configured domains, both active and inactive.

        === Errors ===
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        cSs*g|]"}|djd�r|ddd��qS)rIzdomain/�N)ra)rrr	r	r
r�sz+SSSDConfig.list_domains.<locals>.<listcomp>)r�r
rb)rAr�r	r	r
r��szSSSDConfig.list_domainsc
Cs�|js
t�|jd|�s t|��t||j�}dd�|j|jd|��D�}ddddddddddd�
}|j�}dd�|D�}d	|kr�|j	d�xt|j
�D]h\}}||kr�q�||kr�||j|�}	|	d|j�kr�|d|j
d��||	dkr�|j	||	df�q�Wx:|D]2\}
}y|j|
|�Wntk
�r6YnX�qWxd|j|jd|��D]L}|d
|df|k�rTy|j|d
|d�Wntk
�r�YnX�qTW|j|�|_|S)a�
        Get an SSSDDomain object to edit a domain.

        name:
          The name of the domain to return.

        === Returns ===
        An SSSDDomain instance containing the current state of a domain in the
        SSSDConfig

        === Errors ===
        NoDomainError:
          There is no such domain with the specified name in the SSSDConfig.
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        z	domain/%scSs.g|]&}|djd�dkr|d|df�qS)rIr�rrG)r�)rrr	r	r
r�sz)SSSDConfig.get_domain.<locals>.<listcomp>N�id_provider�
auth_provider)
r�Z
sudo_providerr�Zchpass_providerZautofs_providerZselinux_providerZsubdomains_providerZsession_providerZhostid_providerZresolver_providercSsg|]}|d�qS)rr	)rrr	r	r
r�s�access_provider�permitrr�rIrG)r�r�)r�r
rKrrrqrMrLr�r r�r�r\r�r}r�is_domain_activer�)
rArIr_rfZdefault_providersr�Zproviders_listr`Zdefault_providerZdefault_provider_valuer"rGr�r	r	r
�
get_domain�sR
zSSSDConfig.get_domaincCs6|js
t�|jd|�rt�t||j�}|j|�|S)a�
        Create a new, empty domain and return the SSSDDomain object for it.

        name:
          The name of the domain to create and return.

        === Returns ===
        The newly-created SSSDDomain object

        === Errors ===
        DomainAlreadyExistsError:
          The service being created already exists in the SSSDConfig object.
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        z	domain/%s)r�r
rKrrrq�save_domain)rArIr_r	r	r
�
new_domain�s
zSSSDConfig.new_domaincCs&|js
t�||j�krt�||j�kS)a�
        Is a particular domain set active

        name:
          The name of the configured domain to check

        === Returns ===
        True if the domain is active, False if it is inactive

        === Errors ===
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        NoDomainError:
          No domain by this name is configured
        )r�r
r�rr�)rArIr	r	r
r�s
zSSSDConfig.is_domain_activecCs�|js
t�||j�krt�|jdd�d}|s@|jdd|�dStjt|dj	d���}d|krf|d=d||<|jdddj
|j���dS)	a�
        Activate a configured domain

        name:
          The name of the configured domain to activate

        === Returns ===
        No return value

        === Errors ===
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        NoDomainError:
          No domain by this name is configured
        r�r�rNrGrHr�z, )r�r
r�rr�r�r[r�rrNr�r\)rArIr�r�r	r	r
�activate_domain2szSSSDConfig.activate_domaincCs�|js
t�||j�krt�|jdd�d}|s@|jddd�dStjt|dj	d���}d|krf|d=||krt||=|jdddj
|j���dS)	a�
        Deactivate a configured domain

        name:
          The name of the configured domain to deactivate

        === Returns ===
        No return value

        === Errors ===
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        NoDomainError:
          No domain by this name is configured
        r�r�rr�NrGrHz, )r�r
r�rr�r�r[r�rrNr�r\)rArIr�r�r	r	r
�deactivate_domain\szSSSDConfig.deactivate_domaincCs(|js
t�|j|�|jdd|�dS)a�
        Remove a domain from the SSSDConfig object. This function will also
        remove this domain from the list of active domains in the [SSSD]
        section, if it is there.

        === Returns ===
        No return value

        === Errors ===
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        rTz	domain/%sN)r�r
r�r�)rArIr	r	r
�
delete_domain�s
zSSSDConfig.delete_domainc
CsZ|js
t�t|t�st�|j�}d}|jrX|j|krX|j|j�|jdd|j�}d|_d|}|j	|j
d|�\}}||j�kr�|j|g�|j
|�dd�}x@|D]8}|ddkr�|d|j�kr�|j|dd|dd�q�WxV|j�j�D]F\}}	t|	�tk�rd	j|	�}	|d
k�r"|j|	�}	|j||t|	��q�W|j�rL|j|�n
|j|�dS)a9
        Save the changes made to the domain object back to the SSSDConfig
        object. If this domain is marked active, ensure it is present in the
        active domain list in the [SSSD] section

        domain_object:
          The SSSDDomain object to save to the configuration.

        === Returns ===
        No return value

        === Errors ===
        NotInitializedError:
          This SSSDConfig object has not had import_config() or new_config()
          run on it yet.
        TypeError:
          domain_object was not of type SSSDDomain
        NrTz	domain/%srPr"rIrGTz, r�)r�r
rorrprjr�r�r�ZfindOptsr�r�r�rLrlZdelete_option_subtreer�rPr1r�r�r�r0r�r�)
rAr_rIZoldindexZsectionname�noZsection_subtreeZsection_optionsr"rGr	r	r
r��s:





zSSSDConfig.save_domain)NN)N)N)rrrr~r5r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r	r	r	r
r��s0

-
$""***&$S**r�)!r~r9r&r=ZsssdoptionsrZ
ipachangeconfrr�rrrr
rrrrrrrrrrrrrr#r$�objectrirnrr�r	r	r	r
�<module>sBG<\'

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists