
    g@/                         S SK r S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
JrJrJrJr   " S S\5      r " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)    N)	bitFields)system_session)SamDB)CommandCommandErrorSuperCommandOptionc            
           \ rS rSrSrSr\R                  \R                  \R                  S.r
\" SS\S9\" SS	S
\SSS9/rS/r  SS jrSrg)cmd_schema_attribute_modify    a4  Modify attribute settings in the schema partition.

This commands allows minor modifications to attributes in the schema. Active
Directory does not allow many changes to schema, but important modifications
are related to indexing. This command overwrites the value of searchflags,
so be sure to view the current content before making changes.

Example1:
samba-tool schema attribute modify uid \
    --searchflags="fATTINDEX,fPRESERVEONDELETE"

This alters the uid attribute to be indexed and to be preserved when
converted to a tombstone.

Important search flag values are:

fATTINDEX: create an equality index for this attribute.
fPDNTATTINDEX: create a container index for this attribute (ie OU).
fANR: specify that this attribute is a member of the ambiguous name
     resolution set.
fPRESERVEONDELETE: indicate that the value of this attribute should be
     preserved when the object is converted to a tombstone (deleted).
fCOPY: hint to clients that this attribute should be copied.
fTUPLEINDEX: create a tuple index for this attribute. This is used in
      substring queries.
fSUBTREEATTINDEX: create a browsing index for this attribute. VLV searches
      require this.
fCONFIDENTIAL: indicate that the attribute is confidential and requires
      special access checks.
fNEVERVALUEAUDIT: indicate that changes to this value should NOT be audited.
fRODCFILTEREDATTRIBUTE: indicate that this value should not be replicated to
      RODCs.
fEXTENDEDLINKTRACKING: indicate to the DC to perform extra link tracking.
fBASEONLY: indicate that this attribute should only be displayed when the
       search scope of the query is SCOPE_BASE or a single object result.
fPARTITIONSECRET: indicate that this attribute is a partition secret and
       requires special access checks.

The authoritative source of this information is the MS-ADTS.
%prog attribute [options]	sambaoptsversionoptscredoptsz--searchflagszSearch Flags for the attribute)helptype-H--URL%LDB URL for database or target serverURLHr   r   metavardest	attributeNc                 ,   Uc  [        S5      eS nUb  SnUR                  S5      nU V	s/ s H   oR                  5       R                  5       PM"     nn	U HC  n
U
[        S   R                  5       ;  a  [        SU
-  5      eS[        S   U
   -
  nUSU-  -  nME     UR                  5       nUR                  U5      n[        U[        5       XS9nUR                  5       nS	U< SU< 3n[        R                  " 5       n[        R                  " UU5      Ul        Ub2  [        R                  " [!        U5      [        R"                  S
5      US
'   UR%                  U5        UR'                  5         U R(                  R+                  SU-  5        g s  sn	f )Nz#A value to modify must be provided.r   ,searchflagsz$Unknown flag '%s', please see --help      urlsession_infocredentialslpzcn=searchFlagszmodified %s)r   split
capitalizeswapcaser   keysget_loadparmget_credentialsr   r   	schema_dnldbMessageDndnMessageElementstrFLAG_MOD_REPLACEmodifyset_schema_update_nowoutfwrite)selfr   r   r   r   r   r   searchflags_intflagsxflagbit_locr&   credssamdbr.   attr_dnms                     5/usr/lib/python3/dist-packages/samba/netcmd/schema.pyruncmd_schema_attribute_modify.runY   sy    DEE "O%%c*E 9>>1\\^,,.E>y7<<>>&'MPT'TUUy7=="1Q'\"B  ##%((,!.*:"'0 OO%	 )95KKMvveW%&"11O$c&:&:M KAm 	Q##%		/07 ?s   'F )NNNNN__name__
__module____qualname____firstlineno____doc__synopsisoptionsSambaOptionsVersionOptionsCredentialsOptionstakes_optiongroupsr	   r4   takes_options
takes_argsrE   __static_attributes__rG       rD   r   r       st    'P +H ))--.. 	%ECPtW#JS	2M J>B*.)1rW   r   c            	           \ rS rSrSrSr\R                  \R                  \R                  S.r
\" SSS\SS	S
9/rS/rSS jrSrg)cmd_schema_attribute_show   zShow details about an attribute from the schema.

Schema attribute definitions define and control the behaviour of directory
attributes on objects. This displays the details of a single attribute.
r   r   r   r   r   r   r   r   r   Nc                    UR                  5       nUR                  U5      n[        U[        5       XvS9nUR	                  5       n	SR                  U5      n
UR                  U	[        R                  U
S9n[        U5      S:X  a  [        SU-  5      e[        U5      S:  a  [        SU-  5      eSUS   R                  5       ;   a  S n [        [        US   S   5      5      n/ n[        S
   R                  5        H/  nUSS[        S
   U   -
  -  -  S:w  d  M  UR!                  U5        M1     [        U5      S:  a8  US   R#                  [        R$                  " U[        R&                  S5      5        UR)                  US   [        R*                  5      nU R,                  R/                  U5        g ! [         a    [        S	US   S   -  5      ef = f)Nr"   zJ(&(objectClass=attributeSchema)(|(lDAPDisplayName={0})(cn={0})(name={0})))basescope
expressionr   zNo schema objects matched "%s"r!   zPMultiple schema objects matched "%s": this is a serious issue you should report!r'   zJInvalid schemaFlags value "%s": this is a serious issue you should report!r   r    searchFlagsDecoded)r,   r-   r   r   r.   formatsearchr/   SCOPE_SUBTREElenr   r+   intr4   
ValueErrorr   appendaddr3   FLAG_MOD_ADD
write_ldifCHANGETYPE_NONEr8   r9   )r:   r   r   r   r   r   r&   r@   rA   r.   filtresflags_ioutr>   	user_ldifs                   rD   rE   cmd_schema_attribute_show.run   s   ##%((,!.*:"'0 OO%	[bbclmll	1B1B&*  , s8q=?)KLLs8a<qt}}~~& CFKKM)GIc#a&"789 C!-0557aB=)A$)G$GHIQNJJt$ 8 3x!|A

3--c33C3CEYZ[$$SVS-@-@A				"  I"#oruvwrx  zG  sH  $H  I  IIs   	F5 5GrG   NNNNrH   rG   rW   rD   rY   rY      s`    
 +H ))--.. 	tW#JS	2M
 J4#rW   rY   c            	           \ rS rSrSrSr\R                  \R                  \R                  S.r
\" SSS\SS	S
9/rS/rSS jrSrg)cmd_schema_attribute_show_oc   zShow what objectclasses MAY or MUST contain an attribute.

This is useful to determine "if I need uid, what objectclasses could be
applied to achieve this."
r   r   r   r   r   r   r   r   r   Nc                 t   UR                  5       nUR                  U5      n[        U[        5       XvS9nUR	                  5       n	SR                  U5      n
SR                  U5      nUR                  U	[        R                  U
S/S9nUR                  U	[        R                  US/S9nU R                  R                  S5        U H'  nU R                  R                  SUS   S   -  5        M)     U R                  R                  S	5        U H'  nU R                  R                  SUS   S   -  5        M)     g )
Nr"   zE(&(objectClass=classSchema)(|(mayContain={0})(systemMayContain={0})))zG(&(objectClass=classSchema)(|(mustContain={0})(systemMustContain={0})))cn)r]   r^   r_   attrsz--- MAY contain ---
z%s
r   z--- MUST contain ---
)r,   r-   r   r   r.   ra   rb   r/   rc   r8   r9   )r:   r   r   r   r   r   r&   r@   rA   r.   may_filt	must_filtmay_resmust_resmsgs                  rD   rE    cmd_schema_attribute_show_oc.run   s*   ##%((,!.*:"'0 OO%	99?	9J 	;;A6);L 	 ,,IS5F5F*24&  B<<Yc6G6G+4TF   D 			/0CIIOOFSYq\12  			01CIIOOFSYq\12 rW   rG   rr   rH   rG   rW   rD   rt   rt      s`    
 +H ))--.. 	tW#JS	2M
 J3rW   rt   c            	           \ rS rSrSrSr\R                  \R                  \R                  S.r
\" SSS\SS	S
9/rS/rSS jrSrg)cmd_schema_objectclass_showi  zShow details about an objectClass from the schema.

Schema objectClass definitions define and control the behaviour of directory
objects including what attributes they may contain. This displays the
details of an objectClass.
z%prog objectclass [options]r   r   r   r   r   r   r   objectclassNc                 t   UR                  5       nUR                  U5      n[        U[        5       XvS9nUR	                  5       n	SR                  U5      n
UR                  U	[        R                  U
S9nU H>  nUR                  U[        R                  5      nU R                  R                  U5        M@     g )Nr"   zF(&(objectClass=classSchema)(|(lDAPDisplayName={0})(cn={0})(name={0})))r\   )r,   r-   r   r   r.   ra   rb   r/   rc   rj   rk   r8   r9   )r:   r   r   r   r   r   r&   r@   rA   r.   rl   rm   r}   rp   s                 rD   rE   cmd_schema_objectclass_show.run  s    ##%((,!.*:"'0 OO%	==CVK=P 	 ll	1B1B&*  , C((c.A.ABIIIOOI& rW   rG   rr   rH   rG   rW   rD   r   r     s`     -H ))--.. 	tW#JS	2M
  J'rW   r   c                   X    \ rS rSrSr0 r\" 5       \S'   \" 5       \S'   \" 5       \S'   Sr	g)cmd_schema_attributei,  z4Query and manage attributes in the schema partition.r6   showshow_ocrG   N)
rI   rJ   rK   rL   rM   subcommandsr   rY   rt   rV   rG   rW   rD   r   r   ,  s1    >K79K35K9;K	rW   r   c                   0    \ rS rSrSr0 r\" 5       \S'   Srg)cmd_schema_objectclassi4  z7Query and manage objectclasses in the schema partition.r   rG   N)rI   rJ   rK   rL   rM   r   r   rV   rG   rW   rD   r   r   4  s    AK57KrW   r   c                   D    \ rS rSrSr0 r\" 5       \S'   \" 5       \S'   Srg)
cmd_schemai:  zSchema querying and management.r   r   rG   N)	rI   rJ   rK   rL   rM   r   r   r   rV   rG   rW   rD   r   r   :  s$    )K35K!7!9KrW   r   )r/   samba.getoptgetoptrO   samba.ms_schemar   
samba.authr   samba.samdbr   samba.netcmdr   r   r   r	   r   rY   rt   r   r   r   r   rG   rW   rD   <module>r      s|   &   % %  b1' b1JI# I#X.37 .3b''' ''T<< <8\ 8: :rW   