
    g                     ^    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)ldb)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9\" SS\S9\" SS\S9\" SS\S9\" SS\S9/rSS/r	\
R                  \
R                  \
R                  S.r   SS jrSrg)cmd_user_add_unix_attrs   a
  Add RFC2307 attributes to a user.

This command adds Unix attributes to a user account in the Active
Directory domain.

The username specified on the command is the sAMaccountName.

You must supply a unique uidNumber.

Unix (RFC2307) attributes will be added to the user account.

If you supply a gidNumber with '--gid-number', this will be used for the
users Unix 'gidNumber' attribute.

If '--gid-number' is not supplied, the users Unix gidNumber will be set to the
one found in 'Domain Users', this means Domain Users must have a gidNumber
attribute.

if '--unix-home' is not supplied, the users Unix home directory will be
set to /home/DOMAIN/username

if '--login-shell' is not supplied, the users Unix login shell will be
set to '/bin/sh'

if ---gecos' is not supplied, the users Unix gecos field will be set to the
users 'CN'

Add 'idmap_ldb:use rfc2307 = Yes' to the smb.conf on DCs, to use these
attributes for UID/GID mapping.

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

Example1:
samba-tool user addunixattrs User1 10001

Example1 shows how to add RFC2307 attributes to a domain enabled user
account, Domain Users will be set as the users gidNumber.

The users Unix ID will be set to '10001', provided this ID isn't already
in use.

Example2:
samba-tool user addunixattrs User2 10002 --gid-number=10001 --unix-home=/home/User2

Example2 shows how to add RFC2307 attributes to a domain enabled user
account.

The users Unix ID will be set to '10002', provided this ID isn't already
in use.

The users gidNumber attribute will be set to '10001'

The users Unix home directory will be set to '/home/user2'

Example3:
samba-tool user addunixattrs User3 10003 --gid-number=10001 --login-shell=/bin/false --gecos='User3 test'

Example3 shows how to add RFC2307 attributes to a domain enabled user
account.

The users Unix ID will be set to '10003', provided this ID isn't already
in use.

The users gidNumber attribute will be set to '10001'

The users Unix login shell will be set to '/bin/false'

The users gecos field will be set to 'User3 test'

Example4:
samba-tool user addunixattrs User4 10004 --gid-number=10001 --unix-home=/home/User4 --login-shell=/bin/bash --gecos='User4 test'

Example4 shows how to add RFC2307 attributes to a domain enabled user
account.

The users Unix ID will be set to '10004', provided this ID isn't already
in use.

The users gidNumber attribute will be set to '10001'

The users Unix home directory will be set to '/home/User4'

The users Unix login shell will be set to '/bin/bash'

The users gecos field will be set to 'User4 test'

z'%prog <username> <uid-number> [options]z-Hz--URLz%LDB URL for database or target serverURLH)helptypemetavardestz--gid-numberzUser's Unix/RFC2307 GID)r   r   z--unix-homez"User's Unix/RFC2307 home directoryz--login-shellzUser's Unix/RFC2307 login shellz--gecoszUser's Unix/RFC2307 GECOS fieldz--uidzUser's Unix/RFC2307 usernameusernamez
uid-number)	sambaoptscredoptsversionoptsNc           	         UR                  5       nUR                  U5      n[        U[        5       XS9nUR	                  5       nSR                  U5      nUR                  U[        R                  US9n[        U5      S:w  a  [        SR                  U5      5      eSR                  [        R                  " U5      5      nUR                  U[        R                  US9n[        U5      S:X  a  [        SR                  U5      5      eUS   R                  nSUS   ;   a  [        S	R                  U5      5      eU
c  US   S
   S   n
Uc  US   S
   S   nUc_  SR                  [        R                  " S5      5      n UR                  U[        R                  US9nU H  nUR                  S5      nM     U	c  Sn	UcQ  UR                  5       nUc  [        S5      eUR                  S5      nUR!                  SU5      R!                  SU5      nUR                  S5      (       d  U R"                  R%                  S5        SR                  UX'XX5      nUR'                  5          UR)                  U5        UR+                  5         U R"                  R%                  SR                  U5      5        g ! [         a    [        S5      ef = f! [        R,                   a   n[        SR                  UU5      5      eS nAff = f)N)urlsession_infocredentialslpz%(&(objectClass=person)(uidNumber={})))scope
expressionr   z#uidNumber {} is already being used.z(samaccountname={})zUnable to find user '{}'	uidNumberzUser {} is already a Unix user.cnzDomain Users	gidNumberz0Domain Users does not have a gidNumber attributez/bin/shzUnable to find Unix domainztemplate homedirz%Dz%Uzidmap_ldb:use rfc2307zYou are setting a Unix/RFC2307 UID & GID. You may want to set 'idmap_ldb:use rfc2307 = Yes' in smb.conf to use the attributes for XID/SID-mapping.
z
dn: {0}
changetype: modify
add: uidNumber
uidNumber: {1}
add: gidnumber
gidNumber: {2}
add: gecos
gecos: {3}
add: uid
uid: {4}
add: loginshell
loginShell: {5}
add: unixHomeDirectory
unixHomeDirectory: {6}
z Modified User '{}' successfully
z Failed to modify user '{0}': {1})get_loadparmget_credentialsr   r   	domain_dnformatsearchr   SCOPE_SUBTREElenr   binary_encodednget
IndexErrordomain_netbios_namereplaceoutfwritetransaction_startmodify_ldiftransaction_commitLdbError)selfr   
uid_numberr   r   r   r   
gid_number	unix_homelogin_shellgecosuidr   credssamdbdomaindnfilterresuser_dnsearch_filtermsgunix_domaintmpluser_modes                            B/usr/lib/python3/dist-packages/samba/netcmd/user/add_unix_attrs.pyruncmd_user_add_unix_attrs.run   s    ##%((,!.*:"'0 ??$ :6*% 	ll8!$!2!2&,  . HMD &z 24 4 '--c.?.?.IJll8!$!2!2&,  . HM9@@JKKa&))#a& @ &x 02 2 =F4LOE;a&,q/C2$fS%6%6~%FG ;ll8),):):.; # = C!$!5J  #K335K""#?@@66,-DT;7??hOIvv-..IIOO 1 2
 F7JEO 	" 	!	/h'
 $$&IIOO?#VH-/_  ;" $: ; ;;T || 	5A &x 35 5	5s$   9J6 *K 6KL#K>>L )	NNNNNNNNN)__name__
__module____qualname____firstlineno____doc__synopsisr   strtakes_options
takes_argsoptionsSambaOptionsCredentialsOptionsVersionOptionstakes_optiongroupsrG   __static_attributes__rI       rF   r
   r
      s    [z 9H 	tW#JS	2~$=CH}#G	%F	y@sKw;#F
M l+J ))..--
 BFAE.2c/rY   r
   )samba.getoptgetoptrS   sambar   
samba.authr   samba.netcmdr   r   r   samba.samdbr   r
   rI   rY   rF   <module>r`      s'   ,   % 6 6 W/g W/rY   