Ë
    þI¶dC6  ã                   ó  — d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZmZ d dlm	Z	 d dl
mZ d dlmZmZ d dlmZ d dlmZ dd	lmZ dd
lmZ  G d„ de«      Z G d„ dej0                  «      Z G d„ de«      Z G d„ de«      Z G d„ de«      Zy)é    N)ÚERR_INVALID_CREDENTIALSÚLdbError)Úcolour)Úsystem_session)ÚSambaOptionÚOptionError)Úget_samba_logger)ÚSamDBé   )ÚJSONEncoder)ÚValidationErrorc                   ó\   ‡ — e Zd Zej                  dgz   Zej                  Zd„ Zˆ fd„Zˆ xZ	S )ÚOptionÚ
validatorsc                 ó~   — t        | d«      xs g }|D ]  }	  |||«       Œ y# t        $ r}t        |«      ‚d}~ww xY w)z«Runs the list of validators on the current option.

        If the validator raises ValidationError, turn that into CommandError
        which gives nicer output.
        r   N)Úgetattrr   ÚCommandError)ÚselfÚoptÚvaluer   Ú	validatorÚes         ú7/usr/lib/python3/dist-packages/samba/netcmd/__init__.pyÚrun_validatorszOption.run_validators)   sO   € ô ˜T <Ó0Ò6°Bˆ
à#ò 	&ˆIð&Ù˜#˜uÕ%ñ	&øô #ò &Ü" 1“oÐ%ûð&ús   —	#£	<¬7·<c                 óL   •— t         ‰| �  ||«      }| j                  ||«       |S )z§Override convert_value to run validators just after.

        This can also be done in process() but there we would have to
        replace the entire method.
        )ÚsuperÚconvert_valuer   )r   r   r   Ú	__class__s      €r   r   zOption.convert_value7   s+   ø€ ô ‘Ñ% c¨5Ó1ˆØ×Ñ˜C Ô'Øˆó    )
Ú__name__Ú
__module__Ú__qualname__r   ÚATTRSÚoptparseÚSUPPRESS_HELPr   r   Ú__classcell__)r   s   @r   r   r   %   s/   ø„ Ø×Ñ  Ñ.€EØ×*Ñ*€Mò&÷ð r   r   c                   ó   — e Zd Zdd„Zd„ Zy)ÚPlainHelpFormatterc           	      óö   — | j                   | j                  z
  }d| j                  z  }|j                  d«      }|D �cg c]  }t        j                  ||||¬«      ‘Œ }}dj                  |«      dz   }|S c c}w )Nú ú
)Úinitial_indentÚsubsequent_indent)ÚwidthÚcurrent_indentÚsplitÚtextwrapÚfillÚjoin)r   ÚdescriptionÚ
desc_widthÚindentÚ
paragraphsÚpÚwrapped_paragraphsÚresults           r   Úformat_descriptionz%PlainHelpFormatter.format_descriptionF   sŒ   € Ø—Z‘Z $×"5Ñ"5Ñ5ˆ
Ø�t×*Ñ*Ñ*ˆØ ×&Ñ& tÓ,ˆ
ð  ö!ð
 ô	 �M‰M˜!Ø$Ø)/Ø,2ö4ð!Ðð !ð —‘Ð-Ó.°Ñ5ˆØˆùò!s   ¾ A6c                 ó   — |rd|z   dz   S y)Nr+   Ú © )r   Úepilogs     r   Úformat_epilogz PlainHelpFormatter.format_epilogS   s   € ÙØ˜&‘= 4Ñ'Ð'àr   N)r=   )r    r!   r"   r;   r@   r>   r   r   r(   r(   E   s   „ óór   r(   c                   ó  — e Zd ZdZd„ Z ee«      Zd„ Z ee«      Zd„ Z	 ee	«      Z
dZg Zg Zi ZdZdZdZdZdZdZdd„Zej.                  ej0                  fd	„Zdd
„Zdd„Zd„ Zd„ Zd„ Zdd„Zd„ Z dddœd„Z!d„ Z"d„ Z#dd„Z$d„ Z%y)ÚCommandzA samba-tool command.c                 óZ   — | j                   j                  «       d   j                  d«      S )Nr   r+   )Ú__doc__Ú
splitlinesÚrstrip©r   s    r   Ú_get_short_descriptionzCommand._get_short_description]   s%   € Ø�|‰|×&Ñ&Ó(¨Ñ+×2Ñ2°4Ó8Ð8r   c                 ó˜   — | j                   j                  d«      }|d   dz   t        j                  dj	                  |dd  «      «      z   S )Nr+   r   r   )rD   r0   r1   Údedentr3   )r   Úliness     r   Ú_get_full_descriptionzCommand._get_full_descriptionb   sA   € Ø—‘×"Ñ" 4Ó(ˆØ�Q‰x˜$‰¤§¡°·±¸5ÀÀ¸9Ó1EÓ!FÑFÐFr   c                 ó^   — | j                   j                  }|j                  d«      r|dd  S |S )NÚcmd_é   )r   r    Ú
startswith)r   Únames     r   Ú	_get_namezCommand._get_nameh   s-   € Ø�~‰~×&Ñ&ˆØ�?‰?˜6Ô"Ø˜˜�8ˆOØˆr   NFTc                 ó*   — |�|| _         |�|| _        y y ©N©ÚoutfÚerrf©r   rV   rW   s      r   Ú
_set_fileszCommand._set_files   s!   € ØÐØˆDŒIØÐØˆD�Ið r   c                 ó(   — | j                  ||«       y rT   )rY   rX   s      r   Ú__init__zCommand.__init__…   s   € Ø�‰˜˜dÕ#r   c                 óL   — | j                  |«      \  }}|j                  «        y rT   )Ú_create_parserÚprint_usage)r   ÚprogÚparserÚ_s       r   ÚusagezCommand.usageˆ   s"   € Ø×'Ñ'¨Ó-‰	ˆ�Ø×ÑÕr   c                 óÆ   — t        j                  d«      }|€dnd|› d�}|€t        |› |› d|› �| j                  ¬«       y t        |› |› d|› d|› �| j                  ¬«       y )NÚERRORr=   ú(ú)z: ©Úfilez - )r   Ú
c_DARK_REDÚprintrW   )r   ÚmsgÚevalueÚklassÚerrs        r   Ú_print_errorzCommand._print_errorŒ   sj   € Ü×Ñ Ó(ˆØ�m‘¨1¨U¨G°1¨ˆàˆ>Ü�S�E˜%˜  3 %Ð(¨t¯y©yÖ9ä�S�E˜%˜  3 % s¨6¨(Ð3¸$¿)¹)ÖDr   c                 ót   — |j                  «       }|j                  |«      }t        ||t        |«      |¬«      S )z:Helper to connect to Ldb database using command line opts.)ÚcredentialsÚsession_infoÚlp)Úget_loadparmÚget_credentialsr
   r   )r   Úldap_urlÚ	sambaoptsÚcredoptsrs   Úcredss         r   Úldb_connectzCommand.ldb_connect•   s;   € à×#Ñ#Ó%ˆØ×(Ñ(¨Ó,ˆÜ�X¨5Ü"0°Ó"4¸ô=ð 	=r   c                 óŠ   — t        j                  || j                  t        dd¬«       | j                  j	                  d«       y)z¿Print json on the screen using consistent formatting and sorting.

        A custom JSONEncoder class is used to help with serializing unknown
        objects such as Dn for example.
        é   T)Úclsr6   Ú	sort_keysr+   N)ÚjsonÚdumprV   r   Úwrite)r   Údatas     r   Ú
print_jsonzCommand.print_jsonœ   s,   € ô 	�	‰	�$˜Ÿ	™	¤{¸1ÈÕMØ�	‰	�‰˜Õr   c                 ó  — t        |t        «      r+|j                  \  }}}|j                  }|j                  }d}nt        j                  «       \  }}}|}d}d}t        |t        «      r+t        || j                  ¬«       | j                  «        d}�n=t        |t        «      rŒ|j                  \  }}	|t        k(  rt        d| j                  ¬«       d}nû|	dk(  rt        d| j                  ¬«       d}nÜ|	j                  d«      r| j                  ||	d	«       d}nµ| j                  ||	d	«       n¡t        |t         «      r| j                  |d
¬«       d}n{t        |t"        «      r| j                  ||d«       nWt%        |«      t&        u r| j                  ||d«       d}n0|€| j                  |«       n| j                  ||t)        |«      «       |st+        j,                  «       dk\  r"t/        j0                  || j                  ¬«       yy)zdisplay a command errorFzuncaught exceptionTrg   zInvalid username or passwordz9LDAP client internal error: NT_STATUS_NETWORK_UNREACHABLEzCould not reach remote serverzUnable to open tdb ÚldbÚassert)rm   ÚruntimeÚ	exceptionNé   )Ú
isinstancer   Úexception_infoÚinner_exceptionÚmessageÚsysÚexc_infor   rj   rW   rb   r   Úargsr   rP   ro   ÚAssertionErrorÚRuntimeErrorÚtypeÚ	ExceptionÚstrÚsambaÚget_debug_levelÚ	tracebackÚprint_tb)
r   r   Úetyperl   Ú
etracebackrŒ   r�   Úforce_tracebackÚ	ldb_ecodeÚldb_emsgs
             r   Úshow_command_errorzCommand.show_command_error¥   sÂ  € ä�aœÔ&Ø*+×*:Ñ*:Ñ'ˆU�F˜JØ×/Ñ/ˆOØ—i‘iˆGØ#‰Oä*-¯,©,«.Ñ'ˆU�F˜JØˆOØ*ˆGØ"ˆOä�aœÔ%Ü�&˜tŸy™yÕ)Ø�J‰JŒLØ#ŠOä˜¬Ô2Ø$3×$8Ñ$8Ñ!ˆY˜ØÔ3Ò3ÜÐ4¸4¿9¹9ÕEØ"'‘ØÐXÒXÜÐ5¸D¿I¹IÕFØ"'‘Ø×$Ñ$Ð%:Ô;Ø×!Ñ! '¨8°UÔ;Ø"'‘à×!Ñ! '¨8°UÕ;ä˜¬Ô8Ø×Ñ˜g¨XÐÔ6Ø"‰OÜ˜¬Ô6Ø×Ñ˜g v¨yÕ9Ü�/Ó"¤iÑ/Ø×Ñ˜g v¨{Ô;Ø"‰OØÐ$Ø×Ñ˜gÕ&à×Ñ˜g v¬s°5«zÔ:áœe×3Ñ3Ó5¸Ò:Ü×Ñ˜z°·	±	Ö:ð ;r   c                 óž  — t        j                  | j                  | j                  t	        «       ||¬«      }|j                  | j                  «       i }t        | j                  j                  «       «      D ]0  }| j                  |   } ||«      ||<   |j                  ||   «       Œ2 | j                  r|j                  dddd¬«       ||fS )N)rb   r4   Ú	formatterr_   r?   z--colorz'use colour if available (default: auto)zalways|never|autoÚauto)ÚhelpÚmetavarÚdefault)r$   ÚOptionParserÚsynopsisÚfull_descriptionr(   Úadd_optionsÚtakes_optionsÚsortedÚtakes_optiongroupsÚkeysÚadd_option_groupÚ
use_colourÚ
add_option)r   r_   r?   r`   ÚoptiongroupsrQ   Úoptiongroups          r   r]   zCommand._create_parserÕ   sÑ   € Ü×&Ñ&Ø—-‘-Ø×-Ñ-Ü(Ó*Ø˜fô	&ˆð
 	×Ñ˜4×-Ñ-Ô.ØˆÜ˜4×2Ñ2×7Ñ7Ó9Ó:ò 	8ˆDØ×1Ñ1°$Ñ7ˆKÙ!,¨VÓ!4ˆL˜ÑØ×#Ñ# L°Ñ$6Õ7ð	8ð �?Š?Ø×Ñ˜iØ#LØ&9Ø&,ð ô .ð
 �|Ð#Ð#r   c                 ó@   — | j                   j                  |dz   «       y )Nr+   )rV   r�   )r   Útexts     r   r�   zCommand.messageé   s   € Ø�	‰	�‰˜˜t™Õ$r   rU   c                ó<   — | j                  ||«       || _        | |fS )z8This is a leaf node, the command that will actually run.)rY   Úcommand_name)r   ÚpathrV   rW   Úargvs        r   Ú_resolvezCommand._resolveì   s"   € à�‰˜˜dÔ#Ø ˆÔØ�dˆ|Ðr   c                 óD  — | j                  | j                  «      \  }}|j                  t        |«      «      \  }}t	        |j
                  «      }|j                  D ]-  }|j                  D ]  }|j                  €Œ||j                  = Œ Œ/ |j                  |«       | j                  r!| j                  |j                  dd«      «       d}	d}
d}t        | j                  «      D ]2  \  }}|d   dk7  r|d   dk7  r|	dz  }	|d   d	k(  s|d   dk(  rd
}Œ.|
dz  }
Œ4 t        |«      |	k  s|st        |«      |
kD  r|j!                  «        yt        |«      | _        || _        || _        	  | j(                  |i |¤ŽS # t*        $ r}| j-                  |«       Y d }~yd }~ww xY w)NÚcolorr¢   r   Féÿÿÿÿú?Ú*r   ú+T)r]   r¶   Ú
parse_argsÚlistÚdictÚ__dict__Úoption_groupsÚoption_listÚdestÚupdater¯   Úapply_colour_choiceÚpopÚ	enumerateÚ
takes_argsÚlenr^   Úraw_argvÚraw_argsÚ
raw_kwargsÚrunr”   rŸ   )r   r¸   r`   r±   Úoptsr�   ÚkwargsÚoption_groupÚoptionÚmin_argsÚmax_argsÚundetermined_max_argsÚiÚargr   s                  r   Ú_runzCommand._runò   s¢  € Ø#×2Ñ2°4×3DÑ3DÓEÑˆ�Ø×&Ñ&¤t¨D£zÓ2‰
ˆˆdä�d—m‘mÓ$ˆØ"×0Ñ0ò 	,ˆLØ&×2Ñ2ò ,�Ø—;‘;Ñ*Ø˜vŸ{™{Ñ+ñ,ð	,ð 	�‰�lÔ#à�?Š?Ø×$Ñ$ V§Z¡Z°¸Ó%@ÔAð ˆØˆØ %ÐÜ §¡Ó0ò 	‰FˆAˆsØ�2‰w˜#Š~ # b¡'¨S¢.Ø˜A‘�Ø�2‰w˜#Š~  R¡¨C¢Ø(,Ñ%à˜A‘‘ð	ô �‹I˜Ò Ñ*?ÄCÈÃIÐPXÒDXØ×ÑÔ Øä˜T›
ˆŒØˆŒØ ˆŒð	Ø�4—8‘8˜TÐ, VÑ,Ð,øÜò 	Ø×#Ñ# AÔ&Üûð	ús   Å)E; Å;	FÆFÆFc                 ó4   — t        d| j                  › d�«      ‚)z=Run the command. This should be overridden by all subclasses.ú'z' run method not implemented)ÚNotImplementedErrorr¶   )r   r�   rÒ   s      r   rÐ   zCommand.run  s   € ä! A d×&7Ñ&7Ð%8Ð8TÐ"UÓVÐVr   c                 óR   — t        d|xs | j                  | j                  ||dœ|¤ŽS )zGet a logger object.)rQ   ÚstreamÚverboseÚquietr>   )r	   rQ   rW   )r   rQ   rà   rá   rÒ   s        r   Ú
get_loggerzCommand.get_logger   s5   € äð ØÒ"˜Ÿ™¨4¯9©9Ø 5ñð ñð 	r   c                 ó¬   — || _         	 t        j                  | j                  | j                  |¬«       y# t
        $ r}t        d|› d�«      ‚d}~ww xY w)zðHeuristics to work out whether the user wants colour output, from a
        --color=yes|no|auto option. This alters the ANSI 16 bit colour
        "constants" in the colour module to be either real colours or empty
        strings.
        )ÚhintzUnknown --color option: z% please choose from always|never|autoN)Úrequested_colourr   Úcolour_if_wantedrV   rW   Ú
ValueErrorr   )r   Ú	requestedr   s      r   rÈ   zCommand.apply_colour_choice'  sg   € ð !*ˆÔð	GÜ×#Ñ# D§I¡IØ$(§I¡IØ)2ö4øô ò 	GÜÐ!9¸)¸ð EFð  Fó Gð Gûð	Gús   ‰,6 ¶	A¿AÁA)NNrT   )r=   FF)&r    r!   r"   rD   rH   ÚpropertyÚshort_descriptionrL   r¨   rR   rQ   r§   rË   rª   r¬   Úhiddenr¯   rå   rÍ   rÎ   rÏ   rY   rŽ   ÚstdoutÚstderrr[   rb   ro   rz   rƒ   rŸ   r]   r�   r¹   rÚ   rÐ   râ   rÈ   r>   r   r   rB   rB   Z   sÔ   „ Ùò9ñ !Ð!7Ó8ÐòGñ  Ð 5Ó6Ðòñ �IÓ€Dð €HØ€JØ€MØÐà€FØ€JØÐà€HØ€HØ€Jóð  ŸJ™J¨S¯Z©Zó $óóEò=òò.;ó`$ò(%ð *.°Dô ò(òTWóóGr   rB   c                   ó,   — e Zd ZdZdZi Zdddœd„Zd„ Zy)ÚSuperCommandz&A samba-tool command with subcommands.z%prog <subcommand>NrU   c                óº  — || _         | j                  ||«       g }t        |«      D ]•  \  }}|| j                  v rC||dz   d t	        |«      z   }|› d|› �}	| j                  |   }
 |
j
                  |	g|¢­||dœŽc S |dv r|dk(  rd}|j                  |«       Œtt        |›d|›d	�| j                  ¬
«       | g fc S  t        d|z  | j                  ¬
«       | |fS )a  This is an internal node. We need to consume one of the args and
        find the relevant child, returning an instance of that Command.

        If there are no children, this SuperCommand will be returned
        and its _run() will do a --help like thing.
        r   Nr*   rU   )ú--helpr£   Nz-hz-Vz	--versionr£   rñ   z: no such subcommand: r+   rg   z%s: missing subcommand
)	r¶   rY   rÊ   ÚsubcommandsÚtupler¹   Úappendrj   rV   )r   r·   rV   rW   r�   Údeferred_argsrØ   ÚaÚsub_argsÚsub_pathÚsubs              r   r¹   zSuperCommand._resolve>  s  € ð !ˆÔØ�‰˜˜dÔ#ð
 ˆä˜d“Oò 	‰DˆAˆqØ�D×$Ñ$Ñ$Ø  A¡ ˜<¬%°Ó*>Ñ>�Ø"˜V 1 Q C˜=�à×&Ñ& qÑ)�Ø#�s—|‘| HÐN¨xÑN¸dÈÒNÒNàÐIÑIà˜’;Ø �AØ×$Ñ$ QÔ'Øô ²Dº!Ð<À4Ç9Á9ÕMØ˜"�:Òð#	ô( 	Ð(¨DÑ1¸¿	¹	ÕBØ�mÐ$Ð$r   c                 óÎ  — d}t        | j                  j                  «       «      }t        |D �cg c]  }t	        |«      ‘Œ c}«      }|D ]4  }| j                  |   }|j
                  rŒ|d| ||j                  fz  z  }Œ6 |d| j                  › d�z  }| j                  | j                  |¬«      \  }}	|j                  t        |«      «      \  }
}|j                  «        yc c}w )Nz
Available subcommands:
z  %*s  - %s
z5For more help on a specific subcommand, please type: z <subcommand> (-h|--help)
)r?   r¼   )r«   rò   r­   ÚmaxrÌ   rë   rê   r¶   r]   rÀ   rÁ   Ú
print_help)r   r¸   r?   ÚsubcmdsÚcÚ
max_lengthÚcmd_nameÚcmdr`   r±   rÑ   r�   s               r   rÚ   zSuperCommand._rund  sü   € Ø-ˆä˜×)Ñ)×.Ñ.Ó0Ó1ˆÜ¨'Ö2 Qœ#˜a�&Ò2Ó3ˆ
Øò 	>ˆHØ×"Ñ" 8Ñ,ˆCØ�zŠzØØ�oØ�˜X s×'<Ñ'<ð)>ñ >ñ >‰Fð		>ð 	ÐJØ×'Ñ'Ð(Ð(CðEñ 	Fˆð  $×2Ñ2°4×3DÑ3DÈVÐ2ÓTÑˆ�Ø×&Ñ&¤t¨D£zÓ2‰
ˆˆdð
 	×ÑÔØùò% 3s   ¯C")r    r!   r"   rD   r§   rò   r¹   rÚ   r>   r   r   rï   rï   7  s   „ Ù0à#€Hà€Kà)-°Dô $%óLr   rï   c                   ó   — e Zd ZdZdd„Zd„ Zy)r   z1An exception class for samba-tool Command errors.Nc                 óR   — || _         || _        t        j                  «       | _        y rT   )r�   rŒ   rŽ   r�   r‹   )r   r�   rŒ   s      r   r[   zCommandError.__init__€  s   € ØˆŒØ.ˆÔÜ!Ÿl™l›nˆÕr   c                 ó    — d| j                   z  S )NzCommandError(%s))r�   rG   s    r   Ú__repr__zCommandError.__repr__…  s   € Ø! D§L¡LÑ0Ð0r   rT   )r    r!   r"   rD   r[   r  r>   r   r   r   r   }  s   „ Ù;ó-ó
1r   r   )r   r$   rŽ   r1   r˜   r–   r…   r   r   r   Ú
samba.authr   Úsamba.getoptr   r   Úsamba.loggerr	   Úsamba.samdbr
   Úencodersr   r   r   r   ÚIndentedHelpFormatterr(   ÚobjectrB   rï   r”   r   r>   r   r   ú<module>r     s|   ðó& Û Û 
Û Û ã ß 1Ý Ý %ß 1Ý )Ý å !Ý 'ôˆ[ô ô@˜×7Ñ7ô ô*ZGˆfô ZGôzC�7ô CôL	1�9õ 	1r   