
    g*                     r    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  S SKJr   " S S\
5      rg)	    N)getpass)generate_random_password)system_session)CommandCommandErrorOption)SamDBc            "       ,   \ rS rSrSrSr\" SSS\SSS	9\" S
SSS9\" SSSS9\" SSSS9\" SSSS9\" SS\S9\" SS\S9\" SS\S9\" SS\S9\" SS\S9\" SS \S9\" S!S"\S9\" S#S$\S9\" S%S&\S9\" S'S(\S9\" S)S*\S9\" S+S,\S9\" S-S.\S9\" S/S0\S9\" S1S2\S9\" S3S4\S9\" S5S6SS9\" S7S8\S9\" S9S:\S9\" S;S<\S9\" S=S>\S9\" S?S@\S9\" SASB\S9\" SCSD\S9/r	SESF/r
\R                  \R                  \R                  SG.r           SKSI jrSJrgH)Lcmd_user_add    a	  Add a new user.

This command adds a new user account to the Active Directory domain.  The username specified on the command is the sAMaccountName.

User accounts may represent physical entities, such as people or may be used as service accounts for applications.  User accounts are also referred to as security principals and are assigned a security identifier (SID).

A user account enables a user to logon to a computer and domain with an identity that can be authenticated.  To maximize security, each user should have their own unique user account and password.  A user's access to domain resources is based on permissions assigned to the user account.

Unix (RFC2307) attributes may be added to the user account. Attributes taken from NSS are obtained on the local machine. Explicitly given values override values obtained from NSS. Configure 'idmap_ldb:use rfc2307 = Yes' to use these attributes for UID/GID mapping.

The command may be run from the root userid or another authorized userid.  The -H or --URL= option can be used to execute the command against a remote server.

Example1:
samba-tool user add User1 passw0rd --given-name=John --surname=Smith --must-change-at-next-login -H ldap://samba.samdom.example.com -Uadministrator%passw1rd

Example1 shows how to add a new user to the domain against a remote LDAP server.  The -H parameter is used to specify the remote target server.  The -U option is used to pass the userid and password authorized to issue the command remotely.

Example2:
sudo samba-tool user add User2 passw2rd --given-name=Jane --surname=Doe --must-change-at-next-login

Example2 shows how to add a new user to the domain against the local server.   sudo is used so a user may run the command as root.  In this example, after User2 is created, he/she will be forced to change their password when they logon.

Example3:
samba-tool user add User3 passw3rd --userou='OU=OrgUnit'

Example3 shows how to add a new user in the OrgUnit organizational unit.

Example4:
samba-tool user add User4 passw4rd --rfc2307-from-nss --gecos 'some text'

Example4 shows how to add a new user with Unix UID, GID and login-shell set from the local NSS and GECOS set to 'some text'.

Example5:
samba-tool user add User5 passw5rd --nis-domain=samdom --unix-home=/home/User5 \
    --uid-number=10005 --login-shell=/bin/false --gid-number=10000

Example5 shows how to add a new RFC2307/NIS domain enabled user account. If
--nis-domain is set, then the other four parameters are mandatory.

z'%prog <username> [<password>] [options]z-Hz--URLz%LDB URL for database or target serverURLH)helptypemetavardestz--must-change-at-next-loginz*Force password to be changed on next login
store_true)r   actionz--random-passwordzGenerate random passwordz--smartcard-requiredz*Require a smartcard for interactive logonsz--use-username-as-cnz"Force use of username as user's CNz--userouzDN of alternative location (without domainDN counterpart) to default CN=Users in which new user object will be created. E. g. 'OU=<OU name>')r   r   z	--surnamezUser's surnamez--given-namezUser's given namez
--initialszUser's initialsz--profile-pathzUser's profile pathz--script-pathzUser's logon script pathz--home-drivezUser's home drive letterz--home-directoryzUser's home directory pathz--job-titlezUser's job titlez--departmentzUser's departmentz	--companyzUser's companyz--descriptionzUser's descriptionz--mail-addresszUser's email addressz--internet-addresszUser's home pagez--telephone-numberzUser's phone numberz--physical-delivery-officezUser's office locationz--rfc2307-from-nsszWCopy Unix user attributes from NSS (will be overridden by explicit UID/GID/GECOS/shell)z--nis-domainzUser's Unix/RFC2307 NIS domainz--unix-homez"User's Unix/RFC2307 home directoryz--uidzUser's Unix/RFC2307 usernamez--uid-numberzUser's Unix/RFC2307 numeric UIDz--gid-numberz&User's Unix/RFC2307 primary GID numberz--gecoszUser's Unix/RFC2307 GECOS fieldz--login-shellzUser's Unix/RFC2307 login shellusernamez	password?)	sambaoptscredoptsversionoptsNc#                    U"(       a&  Ub  US:w  a  [        S5      eU(       a  [        S5      eU(       a  U"(       d  [        SS5      n U"(       a  OEUb  US:w  a  O;[        S5      n[        S5      n#UU#:X  d  S nU R                  R	                  S5        MM  U(       a;  [
        R                  " U5      n$Uc  UnUc  U$S	   nUc  U$S
   nU c  U$S   n U!c  U$S   n!UR                  5       n%UR                  U%5      n&U(       d  U(       a1  U%R                  S5      (       d  U R                  R	                  S5        Ub  S UU!UU4;   a  [        S5      e [        U[        5       U&U%S9n'U'R                  XUXXUUUUUUUUUUUUUUUUUUU U!U"S9  U R                  R	                  SU-  5        g ! [         a  n([        SU-  U(5      eS n(A(ff = f)N zNIt is not allowed to specify --newpassword together with --smartcard-required.z\It is not allowed to specify --must-change-at-next-login together with --smartcard-required.      zNew Password: zRetype Password: zSorry, passwords do not match.
            zidmap_ldb:use rfc2307zYou are setting a Unix/RFC2307 UID or GID. You may want to set 'idmap_ldb:use rfc2307 = Yes' to use those attributes for XID/SID-mapping.
zMissing parameters. To enable NIS features, the following options have to be given: --nis-domain=, --uid-number=, --login-shell=, --unix-home=, --gid-number= Operation cancelled.)urlsession_infocredentialslp)'force_password_change_at_next_login_requseusernameascnuserousurname	givennameinitialsprofilepath	homedrive
scriptpathhomedirectoryjobtitle
departmentcompanydescriptionmailaddressinternetaddresstelephonenumberphysicaldeliveryoffice	nisdomainunixhomeuid	uidnumber	gidnumbergecos
loginshellsmartcard_requiredzFailed to add user '%s': zUser '%s' added successfully
)r   r   r   outfwritepwdgetpwnamget_loadparmget_credentialsgetr	   r   newuser	Exception))selfr   passwordr   r   r   r   must_change_at_next_loginrandom_passworduse_username_as_cnr'   r(   
given_namer*   profile_pathscript_path
home_drivehome_directory	job_titler0   r1   r2   mail_addressinternet_addresstelephone_numberphysical_delivery_officerfc2307_from_nss
nis_domain	unix_homer9   
uid_number
gid_numberr<   login_shellr>   passwordverifypwentr$   credssamdbes)                                            7/usr/lib/python3/dist-packages/samba/netcmd/user/add.pyruncmd_user_add.run   s&    #B" $I J J )" $I J J #5/S9H!#B/0H$%89N~-		 BC  LL*E{!"1X
!"1X
}a"#Ah##%((,66122		  !n  o!
KJGG" $0 1 1	Jan.>&+4EMM(Vo*<U\  ~F&2jU`p~#,Wbm&2DT*:Sk$.$.* %+-?  	A 			88CD  	J:XEqII	Js   ;F+ +
G	5GG	 )!NNNNNFFFNNNNNNNNNNNNNNNNFNNNNNNNF)__name__
__module____qualname____firstlineno____doc__synopsisr   strinttakes_options
takes_argsoptionsSambaOptionsCredentialsOptionsVersionOptionstakes_optiongroupsrc   __static_attributes__re       rb   r   r       s+   'P 9H 	tW#JQT3	(,@"	$ 	"."	$ 	%@"	$ 	%8"	$ 	z c	 	{!1<~$7cB|"3#>&;#F%?cJ~$>SI!(D3O}#5C@~$7cB{!1<%9D&<3G#*<3G#*?cJ+2JQTU#m"	$ 	~$D3O}#G	w;#F~$ECP~$LSVWy@sK%FSQW,M\ k*J ))..-- EI@EDHGK>BGKGK<ABF59$PErv   r   )rA   r   samba.getoptgetoptrp   sambar   
samba.authr   samba.netcmdr   r   r   samba.samdbr	   r   re   rv   rb   <module>r}      s/   ,    * % 6 6 qE7 qErv   