
    Vh                         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mZ d dlmZmZmZ dZ	 d dlZdZ G d
 de      Zd Zedk(  r e        yy# e$ r  e	j*                         Zd	ZY 6w xY w)    )absolute_importdivisionprint_functionam  
module: ldap_passwd
short_description: Set passwords in LDAP
description:
  - Set a password for an LDAP entry. This module only asserts that a given password is valid for a given entry. To assert
    the existence of an entry, see M(community.general.ldap_entry).
author:
  - Keller Fuchs (@KellerFuchs)
requirements:
  - python-ldap
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  passwd:
    description:
      - The (plaintext) password to be set for O(dn).
    type: str
extends_documentation_fragment:
  - community.general.ldap.documentation
  - community.general.attributes
aa  
- name: Set a password for the admin user
  community.general.ldap_passwd:
    dn: cn=admin,dc=example,dc=com
    passwd: "{{ vault_secret }}"

- name: Setting passwords in bulk
  community.general.ldap_passwd:
    dn: "{{ item.key }}"
    passwd: "{{ item.value }}"
  with_dict:
    alice: alice123123
    bob: "|30b!"
    admin: "{{ vault_secret }}"
z
modlist:
  description: List of modified parameters.
  returned: success
  type: list
  sample:
    - [2, "olcRootDN", ["cn=root,dc=example,dc=com"]]
N)AnsibleModulemissing_required_lib)LdapGeneric	gen_specsldap_required_togetherTFc                       e Zd Zd Zd Zd Zy)
LdapPasswdc                 l    t        j                  | |       | j                  j                  d   | _        y )Npasswd)r   __init__moduleparamsr   )selfr   s     q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/ldap_passwd.pyr   zLdapPasswd.__init__N   s*    T6* kk((2    c                    	 t        j                  | j                        }| j
                  r	 j                          	 j                  | j                  | j                         	 |j                          y# t         j                  $ r}| j	                  d|       Y d }~d }~ww xY w# t         j                  $ r}| j	                  d|       Y d }~d }~ww xY w# t         j                  $ r Y j                          yt         j                  $ r}| j	                  d|       Y d }~nd }~ww xY w	 j                          y # j                          w xY w)Nz!Cannot initialize LDAP connectionzCannot start TLS.FTzCannot bind to the server.)ldap
initialize
server_uri	LDAPErrorfail	start_tlsstart_tls_ssimple_bind_sdnr   unbindINVALID_CREDENTIALS)r   tmp_cones      r   passwd_checkzLdapPasswd.passwd_checkT   s   	>oodoo6G >>2##%		!!$''4;;7 NN% ~~ 	>II91==	> >> 2		-q112
 '' 	 NN ~~ 	7II2A66	76 NNGNNsc   A7 B) &C 7B&
B!!B&)C<CCD..E  D.D)$E )D..E Ec                     | j                         sy	 | j                  j                  | j                  d | j                         y# t
        j                  $ r}| j                  d|       Y d }~yd }~ww xY w)NFzUnable to set passwordT)r#   
connectionpasswd_sr   r   r   r   r   )r   r"   s     r   
passwd_setzLdapPasswd.passwd_setk   sf      "	3OO$$TWWdDKK@
 	 ~~ 	3II.22 		3s   1A A4A//A4N)__name__
__module____qualname__r   r#   r'    r   r   r   r   M   s    3.r   r   c                  V   t        t        t        d            dt                     } t        s | j                  t        d      t               t        |       }| j                  r!| j                   |j                                | j                   |j                                y )NT)no_log)r   )argument_specsupports_check_moderequired_togetherzpython-ldap)msg	exception)changed)r   r	   dictr
   HAS_LDAP	fail_jsonr   LDAP_IMP_ERRr   
check_mode	exit_jsonr#   r'   )r   r   s     r   mainr:   z   s    t4'89 02F 1-@#/ 	 	1 fD!2!2!2!45
_T__./r   __main__)
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESRETURN	tracebackansible.module_utils.basicr   r   ?ansible_collections.community.general.plugins.module_utils.ldapr   r	   r
   r7   r   r5   ImportError
format_excr   r:   r(   r+   r   r   <module>rG      s    A @2 
  J z zH* *Z0& zF K  '9'')LHs   A A)(A)