
    VhI                     ,   d dl mZmZmZ eZdZdZdZd dl	m
Z
mZ d dlZd dlmZmZ d dlmZmZmZmZ 	 d dlZd	ZdZ	 d dlZeseZd	ZdZd Zedk(  r e        yy# e$ r d
Z ej2                         ZY 8w xY w# e$ r d
Z ej2                         ZY Iw xY w)    )absolute_importdivisionprint_functionu  
module: udm_user
author:
  - Tobias Rüetschi (@keachi)
short_description: Manage posix users on a univention corporate server
description:
  - This module allows to manage posix users on a univention corporate server (UCS). It uses the Python API of the UCS to
    create a new object or edit it.
notes:
  - This module requires the deprecated L(crypt Python module, https://docs.python.org/3.12/library/crypt.html) library which
    was removed from Python 3.13. For Python 3.13 or newer, you need to install L(legacycrypt, https://pypi.org/project/legacycrypt/).
requirements:
  - legacycrypt (on Python 3.13 or newer)
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: partial
options:
  state:
    default: "present"
    choices: [present, absent]
    description:
      - Whether the user is present or not.
    type: str
  username:
    required: true
    description:
      - User name.
    aliases: ['name']
    type: str
  firstname:
    description:
      - First name. Required if O(state=present).
    type: str
  lastname:
    description:
      - Last name. Required if O(state=present).
    type: str
  password:
    description:
      - Password. Required if O(state=present).
    type: str
  birthday:
    description:
      - Birthday.
    type: str
  city:
    description:
      - City of users business address.
    type: str
  country:
    description:
      - Country of users business address.
    type: str
  department_number:
    description:
      - Department number of users business address.
    aliases: [departmentNumber]
    type: str
  description:
    description:
      - Description (not gecos).
    type: str
  display_name:
    description:
      - Display name (not gecos).
    aliases: [displayName]
    type: str
  email:
    default: ['']
    description:
      - A list of e-mail addresses.
    type: list
    elements: str
  employee_number:
    description:
      - Employee number.
    aliases: [employeeNumber]
    type: str
  employee_type:
    description:
      - Employee type.
    aliases: [employeeType]
    type: str
  gecos:
    description:
      - GECOS.
    type: str
  groups:
    default: []
    description:
      - 'POSIX groups, the LDAP DNs of the groups is found with the LDAP filter for each group as $GROUP: V((&(objectClass=posixGroup\)(cn=$GROUP\)\)).'
    type: list
    elements: str
  home_share:
    description:
      - Home NFS share. Must be a LDAP DN, for example V(cn=home,cn=shares,ou=school,dc=example,dc=com).
    aliases: [homeShare]
    type: str
  home_share_path:
    description:
      - Path to home NFS share, inside the homeShare.
    aliases: [homeSharePath]
    type: str
  home_telephone_number:
    default: []
    description:
      - List of private telephone numbers.
    aliases: [homeTelephoneNumber]
    type: list
    elements: str
  homedrive:
    description:
      - Windows home drive, for example V("H:").
    type: str
  mail_alternative_address:
    default: []
    description:
      - List of alternative e-mail addresses.
    aliases: [mailAlternativeAddress]
    type: list
    elements: str
  mail_home_server:
    description:
      - FQDN of mail server.
    aliases: [mailHomeServer]
    type: str
  mail_primary_address:
    description:
      - Primary e-mail address.
    aliases: [mailPrimaryAddress]
    type: str
  mobile_telephone_number:
    default: []
    description:
      - Mobile phone number.
    aliases: [mobileTelephoneNumber]
    type: list
    elements: str
  organisation:
    description:
      - Organisation.
    aliases: [organization]
    type: str
  overridePWHistory:
    type: bool
    default: false
    description:
      - Override password history.
    aliases: [override_pw_history]
  overridePWLength:
    type: bool
    default: false
    description:
      - Override password check.
    aliases: [override_pw_length]
  pager_telephonenumber:
    default: []
    description:
      - List of pager telephone numbers.
    aliases: [pagerTelephonenumber]
    type: list
    elements: str
  phone:
    description:
      - List of telephone numbers.
    type: list
    elements: str
    default: []
  postcode:
    description:
      - Postal code of users business address.
    type: str
  primary_group:
    description:
      - Primary group. This must be the group LDAP DN.
      - If not specified, it defaults to V(cn=Domain Users,cn=groups,$LDAP_BASE_DN).
    aliases: [primaryGroup]
    type: str
  profilepath:
    description:
      - Windows profile directory.
    type: str
  pwd_change_next_login:
    choices: ['0', '1']
    description:
      - Change password on next login.
    aliases: [pwdChangeNextLogin]
    type: str
  room_number:
    description:
      - Room number of users business address.
    aliases: [roomNumber]
    type: str
  samba_privileges:
    description:
      - Samba privilege, like allow printer administration, do domain join.
    aliases: [sambaPrivileges]
    type: list
    elements: str
    default: []
  samba_user_workstations:
    description:
      - Allow the authentication only on this Microsoft Windows host.
    aliases: [sambaUserWorkstations]
    type: list
    elements: str
    default: []
  sambahome:
    description:
      - Windows home path, for example V('\\\\$FQDN\\$USERNAME').
    type: str
  scriptpath:
    description:
      - Windows logon script.
    type: str
  secretary:
    default: []
    description:
      - A list of superiors as LDAP DNs.
    type: list
    elements: str
  serviceprovider:
    default: ['']
    description:
      - Enable user for the following service providers.
    type: list
    elements: str
  shell:
    default: '/bin/bash'
    description:
      - Login shell.
    type: str
  street:
    description:
      - Street of users business address.
    type: str
  title:
    description:
      - Title, for example V(Prof.).
    type: str
  unixhome:
    description:
      - Unix home directory.
      - If not specified, it defaults to C(/home/$USERNAME).
    type: str
  userexpiry:
    description:
      - Account expiry date, for example V(1999-12-31).
      - If not specified, it defaults to the current day plus one year.
    type: str
  position:
    default: ''
    description:
      - Define the whole position of users object inside the LDAP tree, for example V(cn=employee,cn=users,ou=school,dc=example,dc=com).
    type: str
  update_password:
    default: always
    choices: [always, on_create]
    description:
      - V(always) updates passwords if they differ.
      - V(on_create) only sets the password for newly created users.
    type: str
  ou:
    default: ''
    description:
      - Organizational Unit inside the LDAP Base DN, for example V(school) for LDAP OU C(ou=school,dc=example,dc=com).
    type: str
  subpath:
    default: 'cn=users'
    description:
      - LDAP subpath inside the organizational unit, for example V(cn=teachers,cn=users) for LDAP container C(cn=teachers,cn=users,dc=example,dc=com).
    type: str
a  
- name: Create a user on a UCS
  community.general.udm_user:
    name: FooBar
    password: secure_password
    firstname: Foo
    lastname: Bar

- name: Create a user with the DN uid=foo,cn=teachers,cn=users,ou=school,dc=school,dc=example,dc=com
  community.general.udm_user:
    name: foo
    password: secure_password
    firstname: Foo
    lastname: Bar
    ou: school
    subpath: 'cn=teachers,cn=users'

# or define the position
- name: Create a user with the DN uid=foo,cn=teachers,cn=users,ou=school,dc=school,dc=example,dc=com
  community.general.udm_user:
    name: foo
    password: secure_password
    firstname: Foo
    lastname: Bar
    position: 'cn=teachers,cn=users,ou=school,dc=school,dc=example,dc=com'
#)date	timedeltaN)AnsibleModulemissing_required_lib)umc_module_for_addumc_module_for_editldap_searchbase_dnTFc                     t        j                  t        j                         t        d      z   d      } t	        t        di dt        d      dt        d      dt        d      d	t        dd
g      dt        d      dt        ddg      dt        dgdd      dt        ddg      dt        ddg      dt        d      dt        d      dt        g dd      dt        ddg      dt        ddg      dt        g dddg       d!t        d      d"t        d      d#t        g ddd$g       d%t        dd&g      d't        dd(g      d)t        g ddd*g       d+t        dd,g      d-t        d.d/d0g1      d2t        d.d/d3g1      d4t        g ddd5g       d6t        dd78      d9t        g dd      d:t        d      d;t        dd<g      d=t        d      d>t        dd?d@gdAgB      dCt        ddDg      dEt        g dddFg       dGt        g dddHg       dIt        d      dJt        d      dKt        g dd      dLt        dgdd      dMt        dNdO      dPt        d      dQt        d      dRt        d      dSt        d      dTt        d7dUgdV      dWt        ddO      dXt        dYdYdZgd[      d\t        ddO      d]t        d^dO      d_t        d`d`dagd[      d7d_d`g dbfgc      }t        s&t        s |j                  t        dd      t        e       |j                  dT   }|j                  dW   }|j                  d\   }|j                  d]   }|j                  d_   }d.}d }t        t        dfj                  |      dggh            }	|dk7  r|}
nG|dk7  rdij                  |      }|dk7  rdjj                  |      }dkj                  ||t                     }
dlj                  ||
      }t!        t#        |	            }|d`k(  r	 |st%        dm|
      }nt'        dm|      }|j                  d   9dnj                  |j                  d   |j                  d"         |j                  d<   |j                  dR   +doj                  |j                  dT         |j                  dR<   |j)                         D ]E  }|d6k7  s	|dk7  s|d-k7  s||j                  v s$|j                  |   4|j                  |   ||<   G |j                  d   |dp<   dS|v r|j+                  dS      | |dS<   |j                  d6   }|d6   ||d6<   |j                  dX   dYk(  rZ|d6   j-                  dqdr      ds   }t/        j.                  ||      |k7  r)|j                  d-   |d-<   |j                  d2   |d2<   ||d6<   |j1                         }|r*|j)                         D ]  }|j3                  |      sd7} nd7}|j4                  s%|s|j7                          n|r|j9                          	 |j                  d   }|rdvj                  dwj=                  |            }t        t        |dxgh            }|D ]K  }t'        dy|dz         }||d{   vs|d{   j?                  |       |j4                  s|j9                          d7}M |dak(  r-|r+	 t'        dm|      }|j4                  s|jA                          d7}|jC                  ||||
~       y # t:        $ r& |j                  dtj                  ||
      u       Y w xY w# t:        $ r$ |j                  d|j                  |      u       Y w xY w# t:        $ r$ |j                  d}j                  |      u       Y w xY w)Nim  )daysz%Y-%m-%dbirthdaystr)typecitycountrydepartment_numberdepartmentNumber)r   aliasesdescriptiondisplay_namedisplayNameemail list)defaultr   elementsemployee_numberemployeeNumberemployee_typeemployeeType	firstnamegecosgroups
home_share	homeSharehome_share_pathhomeSharePathhome_telephone_numberhomeTelephoneNumber)r   r   r    r   	homedrivelastnamemail_alternative_addressmailAlternativeAddressmail_home_servermailHomeServermail_primary_addressmailPrimaryAddressmobile_telephone_numbermobileTelephoneNumberorganisationorganizationoverridePWHistoryFbooloverride_pw_history)r   r   r   overridePWLengthoverride_pw_lengthpager_telephonenumberpagerTelephonenumberpasswordT)r   no_logphonepostcodeprimary_groupprimaryGroupprofilepathpwd_change_next_login01pwdChangeNextLogin)r   choicesr   room_number
roomNumbersamba_privilegessambaPrivilegessamba_user_workstationssambaUserWorkstations	sambahome
scriptpath	secretaryserviceprovidershellz	/bin/bash)r   r   streettitleunixhome
userexpiryusernamename)requiredr   r   positionupdate_passwordalways	on_create)r   rL   r   ousubpathzcn=usersstatepresentabsent)r%   r/   rA   )argument_specsupports_check_moderequired_ifzHcrypt (part of standard library up to Python 3.12) or legacycrypt (PyPI))msg	exceptionz&(&(objectClass=posixAccount)(uid={0}))uid)attrzou={0},z{0},z	{0}{1}{2}zuid={0},{1}z
users/userz{0} {1}z	/home/{0}ze-mail}      z'Creating/editing user {0} in {1} failed)rk   z&(&(objectClass=posixGroup)(|(cn={0})))z)(cn=dnzgroups/groupr   usersz Adding groups to user {0} failedzRemoving user {0} failed)changedr\   diff	container )"r   strftimetodayr   r	   dict	HAS_CRYPTHAS_LEGACYCRYPT	fail_jsonr
   LEGACYCRYPT_IMPORT_ERRORparamsr   r   formatr   r;   lenr   r   keysgetsplitcryptru   
hasChanged
check_modecreatemodify	Exceptionjoinappendremove	exit_json)expirymoduler\   r_   rc   rd   re   rt   ru   rs   rv   user_dnexistsobjkrA   old_passwordr'   filter	group_dnsrr   grps                         n/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/udm_user.pymainr   b  s	   ]]4::<)*==zJF j
u%j
5!j
 e$j
 #,>+?A	j
 %(j
 5'4o7j
 t" %'j
 !e*:);=j
 E(6'79j
  &!j
" E"#j
$ #!&(%j
* %0M3+j
. !e*9):</j
2 #'r,2050E/F#H3j
: &;j
< u%=j
> &*"/5383K2L&N?j
F "u+;*<>Gj
J "&5/C.D"FKj
N %).4272I1J%LOj
V 5'5&68Wj
Z #5(.,A+BD[j
` "%'-+?*@Baj
f #'r,2050F/G#Igj
n u!%'oj
r r" %'sj
x u%yj
z E(6'79{j
~ %(j
@ #'E03Sz0D/E#GAj
F %&2^5Gj
J ""'-+0+<*=?Kj
R %).4272I1J%LSj
Z &[j
\ ']j
^ 2 &$)+_j
d !"&,*/1ej
j {!#kj
n U#oj
p E"qj
r u%sj
t 'uj
v 4#)($&wj
| "$&}j
@ !*2K)@&+-Aj
F B Gj
J #%Kj
N y )84!#Oj
V !i!FG
[pFd _$%op. 	 	

 }}Z(H}}Z(H	t	BmmI&GMM'"EGD077AW E 2~	8!!"%Bb=mmG,G&&wGI>	""8Y7G#e*F	6	(yA),@}}]+3/8/?/?MM+.MM*-0m, }}Z(0,7,>,>MM*--j) XXZ .OX00V]]*a(4#]]1-CF. #MM'2CMs"sww|'<'D$*L!}}Z0H:&"*J}}./8;":44S!<Q?;;x6,F/5}}=P/QC+,.4mm<N.OC*+&.C
O88:D 'A~~a("&' $$JJLJJL	]]8,FAHHLL( !V4&!AB	# 'B-nbeDCc'l2G++G4%00JJL"&' V	%lG<C$$

G 	  K  	=DD  	*  	6==hG  	  	.55h?  	sc    B5\6 6\6 <\6 \6 \6 !C;\6 8\6 A#]( :4]( 6*^ 6+]%$]%(*^^*____main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNdatetimer   r   	tracebackansible.module_utils.basicr	   r
   Iansible_collections.community.general.plugins.module_utils.univention_umcr   r   r   r   r   r{   CRYPT_IMPORT_ERRORImportError
format_exclegacycryptr|   r~   r   __name__rw       r   <module>r      s    A @Tn8 
 $  J 
 I	$
 O#m` zF G  0I---/0  6O3y3356s"   A A8 A54A58BB