
    Vh                     j    d dl mZmZmZ eZdZdZd dlm	Z	 dZ
 G d de      Zd Zed	k(  r e        y
y
)    )absolute_importdivisionprint_functiona  
module: capabilities
short_description: Manage Linux capabilities
description:
  - This module manipulates files privileges using the Linux capabilities(7) system.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  path:
    description:
      - Specifies the path to the file to be managed.
    type: str
    required: true
    aliases: [key]
  capability:
    description:
      - Desired capability to set (with operator and flags, if O(state=present)) or remove (if O(state=absent)).
    type: str
    required: true
    aliases: [cap]
  state:
    description:
      - Whether the entry should be present or absent in the file's capabilities.
    type: str
    choices: [absent, present]
    default: present
notes:
  - The capabilities system will automatically transform operators and flags into the effective set, so for example, C(cap_foo=ep)
    will probably become C(cap_foo+ep).
  - This module does not attempt to determine the final operator and flags to compare, so you will want to ensure that your
    capabilities argument matches the final capabilities.
author:
  - Nate Coraor (@natefoo)
a$  
- name: Set cap_sys_chroot+ep on /foo
  community.general.capabilities:
    path: /foo
    capability: cap_sys_chroot+ep
    state: present

- name: Remove cap_net_bind_service from /bar
  community.general.capabilities:
    path: /bar
    capability: cap_net_bind_service
    state: absent
)AnsibleModule)=-+c                   4    e Zd ZdZdZd Zd Zd Zd ZddZ	y)	CapabilitiesModuleLinuxNc                    || _         |j                  d   j                         | _        |j                  d   j                         j	                         | _        |j                  d   | _        |j                  dd      | _        |j                  dd      | _	        | j                  | j
                  | j                  dk(  	      | _        | j                          y )
Npath
capabilitystategetcapT)requiredsetcappresent)op_required)moduleparamsstripr   lowerr   r   get_bin_path
getcap_cmd
setcap_cmd
_parse_capcapability_tuprun)selfr   s     r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/capabilities.py__init__zCapabilitiesModule.__init__J   s    MM&)//1	 --5;;=CCE]]7+
 --h-F --h-F"oodoo4::YbKboc
    c           	           j                   j                        }|D cg c]  }|d   	 }} j                  dk(  r j                  |vr j                  j
                  r j                  j                  dd       nt        t         fd|            }|j                   j                          j                  j                  d j                  d j                   j                  |             n j                  dk(  r j                  d   |v r j                  j
                  r j                  j                  dd       nRt         fd	|      } j                  j                  d j                  d j                   j                  |              j                  j                  d
 j                         y c c}w )Nr   r   Tzcapabilities changed)changedmsgc                 .    | d   j                   d   k7  S Nr   r   xr    s    r!   <lambda>z(CapabilitiesModule.run.<locals>.<lambda>`   s    !8K8KA8N0N r#   )r%   r   r&   stdoutabsentc                 .    | d   j                   d   k7  S r(   r)   r*   s    r!   r,   z(CapabilitiesModule.run.<locals>.<lambda>j   s    1Q443F3Fq3I+I r#   F)r%   r   )r   r   r   r   r   
check_mode	exit_jsonlistfilterappendr   )r    currentcapcapss   `   r!   r   zCapabilitiesModule.runU   s   ++dii(")*3A**::"t':':''I{{%%%%d8N%O v&NPWXYt223%%d$**J`imitituyu~u~  AH  jI%  JZZ8#(;(;A(>$(F{{%%%%d8N%O !!I7S%%d$**J`imitituyu~u~  AH  jI%  Je4::>) +s   Gc                    g }| j                   d|}| j                  j                  |      \  }}}|dk7  s|dk7  r/| j                  j                  d|z  |j	                         |       |j	                         |k7  rd|v r1|j                  d      d   j	                         j                         }n/|j                         d   j	                         j                         }|D ]~  }|j                         }d|v rH|j                  d      }	| j                  |	d	         \  |	d	<   }
}|	D ]  }|j                  ||
|f        _|j                  | j                  |              |S )
Nz -v r    z Unable to get capabilities of %sr&   r-   stderrz =   ,)	r   r   run_command	fail_jsonr   splitr   r   r4   )r    r   rvalcmdrcr-   r;   r7   r6   	cap_groupopflagssubcaps                r!   r   zCapabilitiesModule.getcapn   sT    OOT2![[44S9FF 7flKK!!&H4&OX^XdXdXfou!v<<>T!v~||D)!,224::< ||~a(..0668 
6iik #: #		#I/3y}/M,IbM2u"+ 9VR$789 KK 45
6 r#   c                     dj                  |D cg c]  }dj                  |       c}      }| j                  d|d|}| j                  j                  |      \  }}}|dk7  r"| j                  j	                  d|z  ||       y |S c c}w )N r9   z 'z' r   z Unable to set capabilities of %sr:   )joinr   r   r?   r@   )r    r   r7   r6   rC   rD   r-   r;   s           r!   r   zCapabilitiesModule.setcap   s    xx6#67"ootT:![[44S9FF7KK!!&H4&OX^gm!nM 7s   Bc                 "   d}	 d}|dk(  r#|j                  t        |         }|dz  }|dk(  r#||   }|j                  |      \  }}|||fS # t        $ r9 |r-| j                  j	                  dt        t              z         n|d d fcY S Y _w xY w)Nr>   r   r<   z#Couldn't find operator (one of: %s))r&   )findOPS	Exceptionr   r@   strrA   )r    r6   r   opindirF   rG   s          r!   r   zCapabilitiesModule._parse_cap   s    		)A2+Q(Q 2+ ZYYr]
UR  	)%%*ORUVYRZ*Z%[T4(( \	)s   )A =BB)T)
__name__
__module____qualname__platformdistributionr"   r   r   r   r    r#   r!   r   r   F   s&    HL	?2B r#   r   c                      t        t        t        dddg      t        dddg      t        ddddg      	      d
      } t        |        y )NrP   Tkey)typer   aliasesr6   r   r.   )r[   defaultchoices)r   r   r   )argument_specsupports_check_mode)r   dictr   )r   s    r!   mainrb      sP    54%AwGE9x>ST

 !F vr#   __main__N)
__future__r   r   r   r[   __metaclass__DOCUMENTATIONEXAMPLESansible.module_utils.basicr   rN   objectr   rb   rS   rX   r#   r!   <module>rj      sT    A @&P 5`  ` L zF r#   