
    gN                        S r SrSSKrSSKrSSKrSSKJrJr  SSKJr  SSK	J
r
JrJrJr  SSKJr  S r " S	 S
\R"                  5      r " S S\5      r " S S\S9r " S S\R,                  5      r " S S\R.                  5      r " S S\R0                  5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rS rS r " S  S!\5      r " S" S#\5      r g)$z7Support for parsing Samba-related command-line options.restructuredText    N)ABCMetaabstractmethod)copy)CredentialsAUTO_USE_KERBEROSDONT_USE_KERBEROSMUST_USE_KERBEROS)get_burnt_commandlinec                 <   SSSSS.nUR                  SS5      nSnU(       a  USS R                  5       (       d	  USS S	:X  a8  XTS   -  nUSS
 nU(       a  USS R                  5       (       a  M-  USS S	:X  a  M8   [        U5      nUR                  5       R                  SS5      n XcU   -  $ ! [         a(    SR	                  U5      n[
        R                  " U5      ef = f! [         a,  n	SR	                  X5      n[
        R                  " U5      eS
n	A	ff = f)zCustom option type to allow the input of sizes using byte, kb, mb ...

units, e.g. 2Gb, 4KiB ...
   e.g. Option("--size", type="bytes", metavar="SIZE")
   i   i   i   @)BKBMBGB  r   .NzA{0} option requires a numeric value, with an optional unit suffixIz3{0} invalid suffix '{1}', should be B, Kb, Mb or Gb)	replaceisdigitfloat
ValueErrorformatoptparseOptionValueErrorupperKeyError)
optionoptvaluemultipliersvdigitsmmsgsuffixks
             ./usr/lib/python3/dist-packages/samba/getopt.pycheck_bytesr*   %   s/    $+-K 	c2A F
!A  AaFcMA$abE !A  AaFcM-&M WWYsB'F-v&&&  -./5vc{ 	'',,-  -+,2F3N 	'',,-s$   =B0 )C% 02C"%
D/'DDc                   $    \ rS rSrSrS rS rSrg)OptionMissingErrorL   z2One or more Options with required=True is missing.c                     Xl         g)zjRaised when required Options are missing from the command line.

:param options: list of 1 or more option
Noptions)selfr0   s     r)   __init__OptionMissingError.__init__O   s	    
     c                     [        U R                  5      S:X  a  U R                  S   nSU S3$ [        U R                   Vs/ s H  n[        U5      PM     sn5      nSR	                  U5      nSU S3$ s  snf )Nr   r   z	Argument z is required.z, zThe arguments z are required.)lenr0   sortedstrjoin)r1   missingr   r0   s       r)   __str__OptionMissingError.__str__V   ss    t||!ll1oGwi}55Efc&kEFGii(G#G9N;; Fs   A5r/   N)__name__
__module____qualname____firstlineno____doc__r2   r;   __static_attributes__ r4   r)   r,   r,   L   s    <<r4   r,   c                       \ rS rSrSrSrg)ValidationError`   z}ValidationError is the exception raised by validators.

Should be raised from the __call__ method of the Validator subclass.
rC   N)r=   r>   r?   r@   rA   rB   rC   r4   r)   rE   rE   `   s     	r4   rE   c                   (    \ rS rSrSr\S 5       rSrg)	Validatorh   zpBase class for Validators used by SambaOption.

Subclass this to make custom validators and implement __call__.
c                     g NrC   )r1   fieldr!   s      r)   __call__Validator.__call__n   s    r4   rC   N)r=   r>   r?   r@   rA   r   rM   rB   rC   r4   r)   rH   rH   h   s    
  r4   rH   )	metaclassc                      ^  \ rS rSr\R
                  R                  SS/-   r\R
                  R                  S-   r\" \R
                  R                  5      r	\
\	S'   S rU 4S jrSrU =r$ )	Options   required
validators)bytesrU   c                 P    [        U S5      =(       d    / nU H  nU" X5        M     g)z2Runs the list of validators on the current option.rT   N)getattr)r1   r    r!   rT   	validators        r)   run_validatorsOption.run_validatorsy   s%    T<06B
#Ic! $r4   c                 H   > [         TU ]  X5      nU R                  X5        U$ )zOverride 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_valuerY   )r1   r    r!   	__class__s      r)   r]   Option.convert_value   s'     %c1C'r4   rC   )r=   r>   r?   r@   r   rQ   ATTRSTYPESr   TYPE_CHECKERr*   rY   r]   rB   __classcell__r^   s   @r)   rQ   rQ   s   s]    OO!!Z$>>EOO!!J.E445L'L" r4   rQ   c            
       P   ^  \ rS rSrSrSS\SSSSSSS4
U 4S jjrU 4S jrSrU =r	$ )	OptionParser   z@Samba OptionParser, adding support for required=True on Options.NerrorTc                 .   > [         TU ]  XX4XVUXU
5
        g)z5
Ensure that option_class defaults to the Samba one.
N)r\   r2   )r1   usageoption_listoption_classversionconflict_handlerdescription	formatteradd_help_optionprogepilogr^   s              r)   r2   OptionParser.__init__   s      	\)	(	8r4   c                    > / nU R                  5        HA  nUR                  (       d  M  [        XR                  5      nUb  M0  UR	                  U5        MC     U(       a  [        U5      e[        TU ]  X5      $ )zBLoop through required options if value is missing raise exception.)_get_all_optionsrS   rW   destappendr,   r\   check_values)r1   valuesargsr:   r   r!   r^   s         r)   ry   OptionParser.check_values   sc    ++-F4=NN6*	 . $W--w#F11r4   rC   )
r=   r>   r?   r@   rA   rQ   r2   ry   rB   rc   rd   s   @r)   rf   rf      s5    J !$")!!%8$2 2r4   rf   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )OptionGroup   a
  Samba OptionGroup base class.

Provides a generic set_option method to be used as Option callback,
so that one doesn't need to be created for every available Option.

Also overrides the add_option method, so it correctly initialises
the defaults on the OptionGroup.
c                    > [         TU ]  " U0 UD6nUR                  [        R                  :X  a  SOUR                  nU R                  X3R                  5       X@R                  5        U$ )z>Override add_option so it applies defaults during constructor.N)r\   
add_optiondefaultr   
NO_DEFAULT
set_optionget_opt_stringparser)r1   r{   kwargsr    r   r^   s        r)   r   OptionGroup.add_option   sS    g $1&1++)<)<<$#++//17KKH
r4   c                     UR                   =(       d"    UR                  S   SS R                  SS5      n[        XU5        g)z<Callback to set the attribute based on the Option dest name.r      N-_)rw   
_long_optsr   setattr)r1   r   opt_strargr   rw   s         r)   r   OptionGroup.set_option   s9    {{Hf//2126>>sCHC r4   rC   )	r=   r>   r?   r@   rA   r   r   rB   rc   rd   s   @r)   r~   r~      s    ! !r4   r~   c                   P   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 rS
rU =r$ )SambaOptions   z+General Samba-related command line options.c           
        > SSK Jn  U" 5         [        [        R                  5      nUb   SS KnUR                  U5        SSK
Jn  [        TU ]5  US5        U R                  SSS[        S	S
U R                   S9  U R                  SSS[        SSU R"                  S9  U R                  SS[        SSU R$                  S9  U R                  SS[        SSU R&                  S9  S U l        U" 5       U l        S U l        g ! [         aC    Sn[        R                  R                  U5        [        R                  R                  5          GNf = f)Nr   )fault_setupzWARNING: Using passwords on command line is insecure. Installing the setproctitle python module will hide these from shortly after program start.
)LoadParmzSamba Common Optionsz-sz--configfilecallbackFILEzConfiguration file)actiontypemetavarhelpr   z-dz--debuglevel
DEBUGLEVELdebug levelz--optionOPTIONz%set smb.conf option from command linez--realmREALMzset the realm name)sambar   r   sysargvsetproctitleModuleNotFoundErrorstderrwriteflushsamba.paramr   r\   r2   r   r8   _load_configfile_set_debuglevel_set_option
_set_realm_configfile_lprealm)r1   r   r   new_proctitler   r&   r   r^   s          r)   r2   SambaOptions.__init__   sB   % .chh7$	##))-8 	)!78nZ &7K!%!6!6 	 	8 	nZ ,]!%!5!5 	 	7 	
: (D!%!1!1 	 	3 		* '8L!% 	 	2  :
1 ' #C 

  %

  "#s   C< <A	E	E	c                     U R                   $ )z?Return path to the smb.conf file specified on the command line.r   r1   s    r)   get_loadparm_pathSambaOptions.get_loadparm_path   s    r4   c                     X0l         g rK   r   r1   r   r   r   r   s        r)   r   SambaOptions._load_configfile   s    r4   c                      U R                   R                  SU5        X4R
                  l        g ! [         a    [        R                  " SU S35      ef = f)Nr   zinvalid -d/--debug value: '')r   setRuntimeErrorr   r   rz   
debuglevelr   s        r)   r   SambaOptions._set_debuglevel   sU    	6HHLL, $'   	6++-cU!46 6	6s	   / %Ac                      U R                   R                  SU5        X0l        g ! [         a    [        R                  " SU S35      ef = f)Nr   zinvalid --realm value: 'r   )r   r   r   r   r   r   r   s        r)   r   SambaOptions._set_realm   sP    	3HHLL#& 
  	3++*3%q13 3	3s	   % %A
c                 $   UR                  S5      S:X  a  [        R                  " S5      eUR                  SS5      n U R                  R                  US   US   5        g ! [         a#  n[        R                  " SU< SU< 35      eS nAff = f)N=z&--option option takes a 'a=b' argumentr   r   zinvalid --option option value z: )findr   r   splitr   r   	Exception)r1   r   r   r   r   aes          r)   r   SambaOptions._set_option  s    88C=B++8: :IIc1	CHHLL1qt$ 	C++:=qAC C	Cs   "A" "
B,B

Bc                 n   U R                   b1  U R                  R                  U R                   5        U R                  $ [        R                  " S5      b;  U R                  R                  [        R                  " S5      5        U R                  $ U R                  R                  5         U R                  $ )z?Return loadparm object with data specified on the command line.SMB_CONF_PATH)r   r   loadosgetenvload_defaultr   s    r)   get_loadparmSambaOptions.get_loadparm  s    'HHMM$**+
 xx	 YY'3HHMM"))O45 xx HH!!#xxr4   )r   r   r   )r=   r>   r?   r@   rA   r2   r   r   r   r   r   r   rB   rc   rd   s   @r)   r   r      s0    5'R '	C r4   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )Samba3Optionsi  z<General Samba-related command line options with an s3 param.c                 Z   > [         TU ]  U5        SSKJn  UR	                  5       U l        g )Nr   )param)r\   r2   samba.samba3r   get_contextr   )r1   r   s3paramr^   s      r)   r2   Samba3Options.__init__!  s#     1&&(r4   )r   r=   r>   r?   r@   rA   r2   rB   rc   rd   s   @r)   r   r     s    F) )r4   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )HostOptionsi'  z?Command line options for connecting to target host or database.c                 n   > [         TU ]  US5        U R                  SSS[        SSU R                  SS9  g )	NzHost Optionsz-Hz--URLz%LDB URL for database or target serverURLr   H)r   r   r   r   r   rw   )r\   r2   r   r8   r   r1   r   r^   s     r)   r2   HostOptions.__init__*  s:    0gD %
!%s 	 	<r4   rC   r   rd   s   @r)   r   r   '  s    I< <r4   r   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )VersionOptionsi3  z/Command line option for printing Samba version.c                 `   > [         TU ]  US5        U R                  SSSU R                  SS9  g )NzVersion Optionsz-Vz	--versionr   zDisplay version number)r   r   r   )r\   r2   r   _display_versionr   s     r)   r2   VersionOptions.__init__5  s6    !23k*!%!6!65 	 	7r4   c                 b    SS K n[        UR                  5        [        R                  " S5        g )Nr   )r   printrm   r   exit)r1   r   r   r   r   r   s         r)   r   VersionOptions._display_version;  s    emmr4   rC   )	r=   r>   r?   r@   rA   r2   r   rB   rc   rd   s   @r)   r   r   3  s    97 r4   r   c                     U R                  5       S;   a  [        $ U R                  5       S;   a  [        $ U R                  5       S;   a  [        $ [        R
                  " SU< SU < 35      e)N)yestrue1)nofalse0)autoinvalid  option value: )lowerr
   r	   r   r   r   r   r   s     r)   parse_kerberos_arg_legacyr   A  s]    
yy{**  	,	,  		   '')0#)7 8 	8r4   c                     U R                  5       S:X  a  [        $ U R                  5       S:X  a  [        $ U R                  5       S:X  a  [        $ [        R
                  " SU< SU < 35      e)NrS   desiredoffr   r   )r   r
   r   r	   r   r   r   s     r)   parse_kerberos_argr   M  s[    
yy{j   			!  		  '')0#)7 8 	8r4   c                      ^  \ rS rSrSrSU 4S jjrS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rSS jrSrU =r$ )CredentialsOptionsiY  z0Command line options for specifying credentials.c           
        > X l         Ub  SU-  U l        OSU l        SU l        S U l        SU l        [
        TU ]  XR                  5        U R                  SSSU R                  [        SS	9  U R                  S
SSS[        U R                  S9  U R                  SSSS[        SU R                  S9  U R                  SSSS[        SU R                  S9  U R                  SSSSU R                  S9  U R                  SSSS[        SU R                  S9  U R                  SS SS!U R                  S9  U R                  S"S#S[        S$U R                   S9  U R                  S%S&S[        S'U R"                  S9  U R                  S(S)S*S[        S+U R$                  S9  U R                  S,S-S.S[        S/U R&                  S9  [)        5       U l        g )0NzCredentials Options (%s)zCredentials OptionsTFz--simple-bind-dnDNr   DN to use for a simple bindr   r   r   r   r   z
--passwordPASSWORDPasswordr   r   r   r   r   z-Uz
--usernameUSERNAMEUsernamer   r   r   r   r   z-Wz--workgroup	WORKGROUP	Workgroupz-Nz	--no-passzDon't ask for a password)r   r   r   r   z--ipaddress	IPADDRESSzIP address of serverz-Pz--machine-passz#Use stored machine account passwordz--use-kerberosdesired|required|offUse Kerberos authenticationz--use-krb5-ccache
KRB5CCNAMEzKerberos Credentials cachez-Az--authentication-fileAUTHFILEzAuthentication filez-kz
--kerberosKERBEROSz%DEPRECATED: Migrate to --use-kerberos)special_namesectionask_for_password	ipaddressmachine_passr\   r2   _add_option_set_simple_bind_dnr8   _set_password_parse_username_parse_workgroup_set_no_password_set_ipaddress_set_machine_pass_set_kerberos_set_krb5_ccache_set_auth_file_set_kerberos_legacyr   creds)r1   r   r  r^   s      r)   r2   CredentialsOptions.__init__\  s)   (#5DDL0DL $!.+T*"&":":; 	 	= 	z*(sT=O=O 	 	Q|Z *(43G3G 	 	I 	}k *)D4I4I 	 	K 	{:8"&"7"7 	 	9 	]K *4"&"5"5 	 	7 	/ *C"&"8"8 	 	: 	)3I *;dFXFX 	 	Z 	,l *:"&"7"7 	 	9 	6
 *3"&"5"5 	 	7 	|Z *EPTPiPi 	 	k !]
r4   c                     U R                   c  U R                  " U0 UD6$ SnU H=  nUR                  S5      (       d  M  X4R                  SSU R                   -  5      4-  nM?     U R                  " U0 UD6  g )NrC   z--z--%s-)r  r   
startswithr   )r1   args1r   args2r   s        r)   r  CredentialsOptions._add_option  sw    $??E4V44A<<%%iig0A0A&ABDDE  	)&)r4   c                 H    U R                   R                  U5        SU l        g NF)r$  parse_stringr  r   s        r)   r  "CredentialsOptions._parse_username  s    

$!r4   c                 :    U R                   R                  U5        g rK   )r$  
set_domainr   s        r)   r  #CredentialsOptions._parse_workgroup  s    

c"r4   c                 V    U R                   R                  U5        SU l        SU l        g r,  )r$  set_passwordr  r  r   s        r)   r   CredentialsOptions._set_password  s$    

$ %!r4   c                     SU l         g r,  )r  r   s        r)   r  #CredentialsOptions._set_no_password  s
     %r4   c                     SU l         g )NT)r  r   s        r)   r  $CredentialsOptions._set_machine_pass  s
     r4   c                     X0l         g rK   )r  r   s        r)   r  !CredentialsOptions._set_ipaddress  s    r4   c                 b    [        S5        U R                  R                  [        X25      5        g )Nz0WARNING: The option -k|--kerberos is deprecated!)r   r$  set_kerberos_stater   r   s        r)   r#  'CredentialsOptions._set_kerberos_legacy  s#    @A

%%&?&MNr4   c                 L    U R                   R                  [        X25      5        g rK   )r$  r<  r   r   s        r)   r    CredentialsOptions._set_kerberos  s    

%%&8&FGr4   c                 :    U R                   R                  U5        g rK   )r$  set_bind_dnr   s        r)   r  &CredentialsOptions._set_simple_bind_dn  s    

s#r4   c                     SU l         U R                  R                  [        5        U R                  R	                  U5        g r,  )r  r$  r<  r
   set_named_ccacher   s        r)   r!  #CredentialsOptions._set_krb5_ccache  s/     %

%%&78

##C(r4   c                     [         R                  R                  U5      (       a*  U R                  R	                  U5        SU l        SU l        g g r,  )r   pathexistsr$  
parse_filer  r  r   s        r)   r"  !CredentialsOptions._set_auth_file  s<    77>>#JJ!!#&$)D! %D r4   c                    U R                   R                  U5        U R                  (       a  U R                   R                  U5        O+U R                  (       a  U R                   R                  5         U(       aG  U R                   R                  5       (       d(   U R                   R                  U5        U R                   $ U R                   $ ! [         a     U R                   $ f = f)zpObtain the credentials set on the command-line.

:param lp: Loadparm object to use.
:return: Credentials object
)r$  guessr  set_machine_accountr  set_cmdline_callbacksauthentication_requestedr   )r1   lpfallback_machines      r)   get_credentials"CredentialsOptions.get_credentials  s     	

JJ**2.""JJ,,. DJJ$G$G$I$I

..r2 zztzz  zzs   C 
C&%C&)r  r$  r  r  r  r  rK   )F)r=   r>   r?   r@   rA   r2   r  r  r  r  r  r  r  r#  r   r  r!  r"  rR  rB   rc   rd   s   @r)   r   r   Y  sT    :1#f	*"#"
&!OH$)
& r4   r   c                   Z   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 rSS
 jrSrU =r$ )CredentialsOptionsDoublei  z?Command line options for specifying credentials of two servers.c           	      
  > [         TU ]  U5        SU l        U R                  SSSU R                  [
        SS9  U R                  SSSS	[
        U R                  S
9  U R                  SSS[
        SU R                  S9  U R                  SSS[
        SU R                  S9  U R                  SSSS9  U R                  SSS[
        SU R                  S9  U R                  SSS[
        SU R                  S9  [        5       U l        g )NTz--simple-bind-dn2DN2r   r  r  z--password2	PASSWORD2r  r  z--username2	USERNAME2zUsername for second serverr
  z--workgroup2
WORKGROUP2zWorkgroup for second serverz
--no-pass2
store_truez.Don't ask for a password for the second server)r   r   z--use-kerberos2r  r  z--kerberos2	KERBEROS2zUse Kerberos)r\   r2   no_pass2r   _set_simple_bind_dn2r8   _set_password2_parse_username2_parse_workgroup2_set_kerberos2_set_kerberos2_legacyr   creds2r   s     r)   r2   !CredentialsOptionsDouble.__init__  s*    +U:!%!:!:: 	 	< 	{:'c!%!4!4 	 	6 	{)9!%!6!6 	 	8 	):!%!7!7 	 	9 	\M 	 	O)3I):TEXEX 	 	Z
 	{)+d6P6P 	 	R "mr4   c                 :    U R                   R                  U5        g rK   )rd  r-  r   s        r)   r`  )CredentialsOptionsDouble._parse_username2  s      %r4   c                 :    U R                   R                  U5        g rK   )rd  r0  r   s        r)   ra  *CredentialsOptionsDouble._parse_workgroup2  s    s#r4   c                 H    U R                   R                  U5        SU l        g r,  )rd  r3  r]  r   s        r)   r_  'CredentialsOptionsDouble._set_password2  s      %r4   c                 L    U R                   R                  [        X25      5        g rK   rd  r<  r   r   s        r)   rc  .CredentialsOptionsDouble._set_kerberos2_legacy      &&'9#'GHr4   c                 L    U R                   R                  [        X25      5        g rK   rm  r   s        r)   rb  'CredentialsOptionsDouble._set_kerberos2  ro  r4   c                 :    U R                   R                  U5        g rK   )rd  rA  r   s        r)   r^  -CredentialsOptionsDouble._set_simple_bind_dn2  s    $r4   c                 (   U(       a  U R                   R                  U5        O9U R                   R                  5       (       d  U R                   R                  5         U R                  (       a  U R                   R                  5         U R                   $ )zObtain the credentials set on the command-line.

:param lp: Loadparm object to use.
:param guess: Try guess Credentials from environment
:return: Credentials object
)rd  rL  get_usernameset_anonymousr]  rN  )r1   rP  rL  s      r)   get_credentials2)CredentialsOptionsDouble.get_credentials2  s]     KKb!))++KK%%'==KK--/{{r4   )rd  r]  )T)r=   r>   r?   r@   rA   r2   r`  ra  r_  rc  rb  r^  rw  rB   rc   rd   s   @r)   rU  rU    s5    I$:&$II% r4   rU  )!rA   __docformat__r   r   r   abcr   r   r   samba.credentialsr   r   r	   r
   samba._gluer   r*   r   r,   r   rE   rH   rQ   rf   r~   r   r   r   r   r   r   r   rU  rC   r4   r)   <module>r}     s   $ >"  	 
 '   .$-N<22 <(	i 	' X__ .!28(( !2H!(&& !.V; Vr)L )	<+ 	<[ 	8	8 DA1 Ar4   