
    Vhw8                         d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ d dlmZmZ d dlmZ  G d	 d
e      Z	 	 	 	 	 	 	 	 ddZd Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functionaf  
module: ipa_config
author: Fran Fitzpatrick (@fxfitz)
short_description: Manage Global FreeIPA Configuration Settings
description:
  - Modify global configuration settings of a FreeIPA Server.
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  ipaconfigstring:
    description: Extra hashes to generate in password plug-in.
    aliases: ["configstring"]
    type: list
    elements: str
    choices: ["AllowNThash", "KDC:Disable Last Success", "KDC:Disable Lockout", "KDC:Disable Default Preauth for SPNs"]
    version_added: '2.5.0'
  ipadefaultloginshell:
    description: Default shell for new users.
    aliases: ["loginshell"]
    type: str
  ipadefaultemaildomain:
    description: Default e-mail domain for new users.
    aliases: ["emaildomain"]
    type: str
  ipadefaultprimarygroup:
    description: Default group for new users.
    aliases: ["primarygroup"]
    type: str
    version_added: '2.5.0'
  ipagroupobjectclasses:
    description: A list of group objectclasses.
    aliases: ["groupobjectclasses"]
    type: list
    elements: str
    version_added: '7.3.0'
  ipagroupsearchfields:
    description: A list of fields to search in when searching for groups.
    aliases: ["groupsearchfields"]
    type: list
    elements: str
    version_added: '2.5.0'
  ipahomesrootdir:
    description: Default location of home directories.
    aliases: ["homesrootdir"]
    type: str
    version_added: '2.5.0'
  ipakrbauthzdata:
    description: Default types of PAC supported for services.
    aliases: ["krbauthzdata"]
    type: list
    elements: str
    choices: ["MS-PAC", "PAD", "nfs:NONE"]
    version_added: '2.5.0'
  ipamaxusernamelength:
    description: Maximum length of usernames.
    aliases: ["maxusernamelength"]
    type: int
    version_added: '2.5.0'
  ipapwdexpadvnotify:
    description: Notice of impending password expiration, in days.
    aliases: ["pwdexpadvnotify"]
    type: int
    version_added: '2.5.0'
  ipasearchrecordslimit:
    description: Maximum number of records to search (-1 or 0 is unlimited).
    aliases: ["searchrecordslimit"]
    type: int
    version_added: '2.5.0'
  ipasearchtimelimit:
    description: Maximum amount of time (seconds) for a search (-1 or 0 is unlimited).
    aliases: ["searchtimelimit"]
    type: int
    version_added: '2.5.0'
  ipaselinuxusermaporder:
    description: The SELinux user map order (order in increasing priority of SELinux users).
    aliases: ["selinuxusermaporder"]
    type: list
    elements: str
    version_added: '3.7.0'
  ipauserauthtype:
    description:
      - The authentication type to use by default.
      - The choice V(idp) has been added in community.general 7.3.0.
      - The choice V(passkey) has been added in community.general 8.1.0.
    aliases: ["userauthtype"]
    choices: ["password", "radius", "otp", "pkinit", "hardened", "idp", "passkey", "disabled"]
    type: list
    elements: str
    version_added: '2.5.0'
  ipauserobjectclasses:
    description: A list of user objectclasses.
    aliases: ["userobjectclasses"]
    type: list
    elements: str
    version_added: '7.3.0'
  ipausersearchfields:
    description: A list of fields to search in when searching for users.
    aliases: ["usersearchfields"]
    type: list
    elements: str
    version_added: '2.5.0'
extends_documentation_fragment:
  - community.general.ipa.documentation
  - community.general.attributes
a  
- name: Ensure password plugin features DC:Disable Last Success and KDC:Disable Lockout are enabled
  community.general.ipa_config:
    ipaconfigstring: ["KDC:Disable Last Success", "KDC:Disable Lockout"]
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the default login shell is bash
  community.general.ipa_config:
    ipadefaultloginshell: /bin/bash
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the default e-mail domain is ansible.com
  community.general.ipa_config:
    ipadefaultemaildomain: ansible.com
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the default primary group is set to ipausers
  community.general.ipa_config:
    ipadefaultprimarygroup: ipausers
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the group search fields are set to 'cn,description'
  community.general.ipa_config:
    ipagroupsearchfields: ['cn', 'description']
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the home directory location is set to /home
  community.general.ipa_config:
    ipahomesrootdir: /home
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the default types of PAC supported for services is set to MS-PAC and PAD
  community.general.ipa_config:
    ipakrbauthzdata: ["MS-PAC", "PAD"]
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the maximum user name length is set to 32
  community.general.ipa_config:
    ipamaxusernamelength: 32
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the password expiration notice is set to 4 days
  community.general.ipa_config:
    ipapwdexpadvnotify: 4
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the search record limit is set to 100
  community.general.ipa_config:
    ipasearchrecordslimit: 100
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the search time limit is set to 2 seconds
  community.general.ipa_config:
    ipasearchtimelimit: 2
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the default user auth type is password
  community.general.ipa_config:
    ipauserauthtype: ['password']
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the user search fields is set to 'uid,givenname,sn,ou,title'
  community.general.ipa_config:
    ipausersearchfields: ['uid', 'givenname', 'sn', 'ou', 'title']
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the SELinux user map order is set
  community.general.ipa_config:
    ipaselinuxusermaporder:
      - "guest_u:s0"
      - "xguest_u:s0"
      - "user_u:s0"
      - "staff_u:s0-s0:c0.c1023"
      - "unconfined_u:s0-s0:c0.c1023"
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret
z^
config:
  description: Configuration as returned by IPA API.
  returned: always
  type: dict
N)AnsibleModule)	IPAClientipa_argument_spec)	to_nativec                   *     e Zd Z fdZd Zd Z xZS )ConfigIPAClientc                 2    t         t        |   ||||       y )N)superr   __init__)selfmodulehostportprotocol	__class__s        p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/ipa_config.pyr   zConfigIPAClient.__init__   s    ot-fdD(K    c                 (    | j                  dd       S )Nconfig_show)methodname
_post_json)r   s    r   r   zConfigIPAClient.config_show   s    m$??r   c                 *    | j                  d||      S )N
config_mod)r   r   itemr   )r   r   r   s      r   r   zConfigIPAClient.config_mod   s    lDIIr   )__name__
__module____qualname__r   r   r   __classcell__)r   s   @r   r   r      s    L@Jr   r   c                    i }| | |d<   |||d<   |||d<   |||d<   |||d<   |dj                  |      |d<   |||d<   |||d	<   |t        |      |d
<   |	t        |	      |d<   |
t        |
      |d<   |t        |      |d<   |dj                  |      |d<   |||d<   |||d<   |dj                  |      |d<   |S )Nipaconfigstringipadefaultloginshellipadefaultemaildomainipadefaultprimarygroupipagroupobjectclasses,ipagroupsearchfieldsipahomesrootdiripakrbauthzdataipamaxusernamelengthipapwdexpadvnotifyipasearchrecordslimitipasearchtimelimit$ipaselinuxusermaporderipauserauthtypeipauserobjectclassesipausersearchfields)joinstr)r%   r&   r'   r(   r+   r)   r,   r-   r.   r/   r0   r1   r3   r4   r6   r5   configs                    r   get_config_dictr:      sT    F"$3 !')=%&(*?&')+A'((*?&''),2F)G%&"$3 !"$3 !'),-A)B%&%'*+='>#$(*-.C*D&'%'*+='>#$)+.884J+K'("$3 !')=%&&(+1D(E$%Mr   c                 (    | j                  ||      S )N)ipa_datamodule_data)get_diff)client
ipa_configmodule_configs      r   get_config_diffrB   &  s    ??JM?JJr   c                    t        di d| j                  j                  d      d| j                  j                  d      d| j                  j                  d      d| j                  j                  d      d| j                  j                  d      d| j                  j                  d      d| j                  j                  d      d| j                  j                  d      d	| j                  j                  d	      d
| j                  j                  d
      d| j                  j                  d      d| j                  j                  d      d| j                  j                  d      d| j                  j                  d      d| j                  j                  d      d| j                  j                  d      }|j                         }t	        |||      }d}i }|D ]K  }|j                  |      |j                  |d       k7  s(d}|j                  ||j                  |      i       M |r| j                  s|j                  d |       ||j                         fS )Nr%   r&   r'   r(   r)   r+   r,   r-   r.   r/   r0   r1   r3   r4   r6   r5   FT)r   r    )r:   paramsgetr   rB   update
check_moder   )r   r?   rA   r@   diffchanged
new_config
module_keys           r   ensurerM   *  sV   # ))*;<#]]../EF %mm//0GH  &}}001IJ	
 %mm//0GH $]]../EF ))*;< ))*;< $]]../EF "==,,-AB %mm//0GH "==,,-AB  &}}001IJ ))*;< #MM--.CD  $]]../EF!M$ ##%J6:}=DGJ K
Z(JNN:t,LLGz=+<+<Z+HIJK
 v((t*5F&&(((r   c                     t               } | j                  t        ddg ddg      t        ddg      t        ddg      t        dd	g      t        ddd
g      t        dddg      t        ddg      t        ddg ddg      t        ddg      t        ddg      t        ddg      t        ddg      t        dddg      t        dddgg d      t        dddg      t        dddg             t        | d      }t	        ||j
                  d   |j
                  d   |j
                  d    !      }	 |j                  |j
                  d"   |j
                  d#   $       t        ||      \  }}|j                  ||%       y # t        $ r8}|j                  t        |      t        j                         &       Y d }~y d }~ww xY w)'Nlistr8   )AllowNThashzKDC:Disable Last SuccesszKDC:Disable Lockoutz$KDC:Disable Default Preauth for SPNsconfigstring)typeelementschoicesaliases
loginshell)rR   rU   emaildomainprimarygroupgroupobjectclasses)rR   rS   rU   groupsearchfieldshomesrootdir)zMS-PACPADznfs:NONEkrbauthzdataintmaxusernamelengthpwdexpadvnotifysearchrecordslimitsearchtimelimitselinuxusermaporderuserauthtype)passwordradiusotppkinithardenedidppasskeydisabled)rR   rS   rU   rT   usersearchfieldsuserobjectclasses)r%   r&   r'   r(   r)   r+   r,   r-   r.   r/   r0   r1   r3   r4   r6   r5   T)argument_specsupports_check_modeipa_hostipa_portipa_prot)r   r   r   r   ipa_useripa_pass)usernamere   )rJ   user)msg	exception)r   rG   dictr   r   rE   loginrM   	exit_json	Exception	fail_jsonr	   	traceback
format_exc)ro   r   r?   rJ   rw   es         r   mainr   M  s   %'M&5&N '5%57 "u|nE"G#8HI",@+AC!v+>*?A%.1AB&5%B&4%57 "u7J6KLU5F4GH"8L7MNU5F4GH#%-B,C E&5&4%5&PQ !fu*<)=?!v+>*?A=   D # F
 ]]:&]]:&z*	FM]]:.]]:. 	 	
 vv.t4 MYq\Y5I5I5KLLMs   AF 	G.GG__main__)NNNNNNNNNNNNNNNN)
__future__r   r   r   rR   __metaclass__DOCUMENTATIONEXAMPLESRETURNr   ansible.module_utils.basicr   >ansible_collections.community.general.plugins.module_utils.ipar   r   +ansible.module_utils.common.text.convertersr	   r   r:   rB   rM   r   r    rD   r   r   <module>r      s    A @kZgR
  4 g AJi J @DGKEI:>BFCGAECG*ZK )F8Mv zF r   