
    g&                     V    S SK r S SKJr  S SKJrJr  SSKJrJ	r	J
r
Jr   " S S\5      rg)    N)CommandErrorOption   )GetPasswordCommandgpg_decryptdecrypt_samba_gpg_helpvirtual_attributes_helpc            
           \ rS rSrSrSr\R                  \R                  \R                  \R                  S.r\" SS\S9\" S\\S	S
S9\" S\SSSS9/rS/r    SS jrSrg)cmd_user_getpassword"   a"  Get the password fields of a user/computer account.

This command gets the logon password for a user/computer account.

The username specified on the command is the sAMAccountName.
The username may also be specified using the --filter option.

The command must be run from the root user id or another authorized user id.
The '-H' or '--URL' option normally only supports ldapi:// or [tdb://] and
can be used to adjust the local path. By default, tdb:// is used.
if the target account is a group managed service account, then in this
case the -H can point to a remote AD DC LDAP server.

The '--attributes' parameter takes a comma separated list of attributes,
which will be printed or given to the script specified by '--script'. If a
specified attribute is not available on an object it's silently omitted.
All attributes defined in the schema (e.g. the unicodePwd attribute holds
the NTHASH) and the following virtual attributes are possible (see --help
for which virtual attributes are supported in your environment):

   virtualClearTextUTF16: The raw cleartext as stored in the
                          'Primary:CLEARTEXT' (or 'Primary:SambaGPG'
                          with '--decrypt-samba-gpg') buffer inside the
                          supplementalCredentials attribute. This typically
                          contains valid UTF-16-LE, but may contain random
                          bytes, e.g. for computer and gMSA accounts.
                          When the account is a group managed service account,
                          and the user is permitted to access
                          msDS-ManagedPassword then the current and previous
                          password can be read over LDAP. Add ;previous=1
                          to read the previous password.

   virtualClearTextUTF8:  As virtualClearTextUTF16, but converted to UTF-8
                          (invalid UTF-16-LE is mapped in the same way as
                          Windows).

   virtualSSHA:           As virtualClearTextUTF8, but a salted SHA-1
                          checksum, useful for OpenLDAP's '{SSHA}' algorithm.

   virtualCryptSHA256:    As virtualClearTextUTF8, but a salted SHA256
                          checksum, useful for OpenLDAP's '{CRYPT}' algorithm,
                          with a $5$... salt, see crypt(3) on modern systems.
                          The number of rounds used to calculate the hash can
                          also be specified. By appending ";rounds=x" to the
                          attribute name i.e. virtualCryptSHA256;rounds=10000
                          will calculate a SHA256 hash with 10,000 rounds.
                          Non-numeric values for rounds are silently ignored.
                          The value is calculated as follows:
                          1) If a value exists in 'Primary:userPassword' with
                             the specified number of rounds it is returned.
                          2) If 'Primary:CLEARTEXT', or 'Primary:SambaGPG'
                             with '--decrypt-samba-gpg'. Calculate a hash with
                             the specified number of rounds.
                          3) Return the first CryptSHA256 value in
                             'Primary:userPassword'.


   virtualCryptSHA512:    As virtualClearTextUTF8, but a salted SHA512
                          checksum, useful for OpenLDAP's '{CRYPT}' algorithm,
                          with a $6$... salt, see crypt(3) on modern systems.
                          The number of rounds used to calculate the hash can
                          also be specified. By appending ";rounds=x" to the
                          attribute name i.e. virtualCryptSHA512;rounds=10000
                          will calculate a SHA512 hash with 10,000 rounds.
                          Non-numeric values for rounds are silently ignored.
                          The value is calculated as follows:
                          1) If a value exists in 'Primary:userPassword' with
                             the specified number of rounds it is returned.
                          2) If 'Primary:CLEARTEXT', or 'Primary:SambaGPG'
                             with '--decrypt-samba-gpg'. Calculate a hash with
                             the specified number of rounds.
                          3) Return the first CryptSHA512 value in
                             'Primary:userPassword'.

   virtualWDigestNN:      The individual hash values stored in
                          'Primary:WDigest' where NN is the hash number in
                          the range 01 to 29.
                          NOTE: As at 22-05-2017 the documentation:
                          3.1.1.8.11.3.1 WDIGEST_CREDENTIALS Construction
                        https://msdn.microsoft.com/en-us/library/cc245680.aspx
                          is incorrect.

   virtualKerberosSalt:   This results the salt string that is used to compute
                          Kerberos keys from a UTF-8 cleartext password.

   virtualSambaGPG:       The raw cleartext as stored in the
                          'Primary:SambaGPG' buffer inside the
                          supplementalCredentials attribute.
                          See the 'password hash gpg key ids' option in
                          smb.conf.

The '--decrypt-samba-gpg' option triggers decryption of the
Primary:SambaGPG buffer. Check with '--help' if this feature is available
in your environment or not (the python-gpgme package is required).  Please
note that you might need to set the GNUPGHOME environment variable.  If the
decryption key has a passphrase you have to make sure that the GPG_AGENT_INFO
environment variable has been set correctly and the passphrase is already
known by the gpg-agent.

Attributes with time values can take an additional format specifier, which
converts the time value into the requested format. The format can be specified
by adding ";format=formatSpecifier" to the requested attribute name, whereby
"formatSpecifier" must be a valid specifier. The syntax looks like:

  --attributes=attributeName;format=formatSpecifier

The following format specifiers are available:
  - GeneralizedTime (e.g. 20210224113259.0Z)
  - UnixTime        (e.g. 1614166392)
  - TimeSpec        (e.g. 161416639.267546892)

Attributes with an original NTTIME value of 0 and 9223372036854775807 are
treated as non-existing value.

Example1:
samba-tool user getpassword TestUser1 --attributes=pwdLastSet,virtualClearTextUTF8

Example2:
samba-tool user getpassword --filter=samaccountname=TestUser3 --attributes=msDS-KeyVersionNumber,unicodePwd,virtualClearTextUTF16

z.%prog (<username>|--filter <filter>) [options])	sambaoptsversionoptscredoptshostoptsz--filterz;LDAP Filter to get password for (must match single account))helptypez--attributesATTRIBUTELIST
attributes)r   r   metavardestz--decrypt-samba-gpg
store_trueFdecrypt_samba_gpg)r   actiondefaultr   z	username?Nc
           
      j   UR                  5       U l        U(       a  [        (       d  [        [        5      eUc  Uc  [        S5      eUc  S[
        R                  " U5      -  nUc  [        S5      eU R                  U5      n
U	R                  U R                  5      nU R                  UR                  SUS9nU R                  XS U[
        R                  U
US9nUR                  U[
        R                  5      nU R                  R!                  SU-  5        U R"                  R!                  S5        g )	Nz4Either the username or '--filter' must be specified!z((&(objectClass=user)(sAMAccountName=%s))zPlease specify --attributesF)urlrequire_ldapicreds)basednfilterscopeattrsdecryptz%sz#Any available password returned OK
)get_loadparmlpr   r   r   ldbbinary_encodeparse_attributesget_credentialsconnect_for_passwordsHget_account_attributesSCOPE_SUBTREE
write_ldifCHANGETYPE_NONEoutfwriteerrf)selfusernamer+   r    r   r   r   r   r   r   password_attrsr   samdbobjldifs                  M/usr/lib/python3/dist-packages/samba/netcmd/user/readpasswords/getpassword.pyruncmd_user_getpassword.run   s    ((*[[566>h.UVV>?3CTCTU]C^_F<==..z:((1**xzzV[*\))%1517030A0A0>2C * E S%8%89		t$		>?    )r%   )	NNNNNNNNN)__name__
__module____qualname____firstlineno____doc__synopsisoptionsSambaOptionsVersionOptionsCredentialsOptionsHostOptionstakes_optiongroupsr   strr	   r   takes_options
takes_argsr:   __static_attributes__ r<   r9   r   r   "   s    xt @H ))--..''	 	z ]dgh~C+&\	; 	$*"E8K	MM J04/37; @r<   r   )r&   samba.getoptgetoptrC   samba.netcmdr   r   commonr   r   r   r	   r   rM   r<   r9   <module>rR      s+   ,   - p@- p@r<   