Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.04 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. # This code was developped by Jerome Tournier (jtournier@gmail.com) and
  4. # contributors (their names can be found in the CONTRIBUTORS file).
  5.  
  6. # This was first contributed by IDEALX (http://www.opentrust.com/)
  7.  
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  21. # USA.
  22.  
  23. # Purpose of smbldap-useradd : user (posix,shadow,samba) add
  24.  
  25. use strict;
  26.  
  27. use FindBin;
  28. use FindBin qw($RealBin);
  29. use lib "$RealBin/";
  30. use smbldap_tools;
  31. use Crypt::SmbHash;
  32. #####################
  33.  
  34. use Getopt::Std;
  35. my %Options;
  36.  
  37. my $ok =
  38. getopts( 'o:abnmwWiPG:u:g:d:s:c:k:t:A:B:C:D:E:F:H:L:M:N:S:T:?', \%Options );
  39.  
  40. if ( ( !$ok ) || ( @ARGV < 1 ) || ( $Options{'?'} ) ) {
  41. print_banner;
  42. print "Usage: $0 [-awmugdsckABCDEFGHMNPST?] username\n";
  43. print " -a is a Windows User (otherwise, Posix stuff only)\n";
  44. print " -b is a AIX User\n";
  45. print " -c gecos\n";
  46. print " -d home\n";
  47. print " -g gid\n";
  48. print " -i is a trust account (Windows Workstation)\n";
  49. print " -k skeleton dir (with -m)\n";
  50. print " -m creates home directory and copies /etc/skel\n";
  51. print " -n do not create a group\n";
  52. print
  53. " -o add the user in the organizational unit (relative to the user suffix. Ex: 'ou=admin,ou=all')\n";
  54. print " -u uid\n";
  55. print " -s shell\n";
  56. print
  57. " -t time. Wait 'time' seconds before exiting (when adding Windows Workstation)\n";
  58. print " -w is a Windows Workstation (otherwise, Posix stuff only)\n";
  59. print
  60. " -W is a Windows Workstation, with Samba atributes (otherwise, Posix stuff only)\n";
  61. print " -A can change password ? 0 if no, 1 if yes\n";
  62. print " -B must change password ? 0 if no, 1 if yes\n";
  63. print " -C sambaHomePath (SMB home share, like '\\\\PDC-SRV\\homes')\n";
  64. print
  65. " -D sambaHomeDrive (letter associated with home share, like 'H:')\n";
  66. print " -E sambaLogonScript (DOS script to execute on login)\n";
  67. print
  68. " -F sambaProfilePath (profile directory, like '\\\\PDC-SRV\\profiles\\foo')\n";
  69. print " -G supplementary comma-separated groups\n";
  70. print
  71. " -H sambaAcctFlags (samba account control bits like '[NDHTUMWSLKI]')\n";
  72. print " -M local mailAddress (comma seperated)\n";
  73. print " -N given name \n";
  74. print " -P ends by invoking smbldap-passwd\n";
  75. print " -S surname (Family name)\n";
  76. print " -T mailToAddress (forward address) (comma seperated)\n";
  77. print " -Z set custom LDAP attributes, name=value pairs comma separated\n";
  78. print " -? show this help message\n";
  79. exit(1);
  80. }
  81.  
  82. my $ldap_master = connect_ldap_master();
  83.  
  84. # cause problems when dealing with getpwuid because of the
  85. # negative ttl and ldap modification
  86. my $nscd_status = system "/etc/init.d/nscd status >/dev/null 2>&1";
  87.  
  88. if ( $nscd_status == 0 ) {
  89. system "/etc/init.d/nscd stop > /dev/null 2>&1";
  90. }
  91.  
  92. # Read only first @ARGV
  93. my $userName = $ARGV[0];
  94.  
  95. # For computers account, add a trailing dollar if missing
  96. if ( defined( $Options{'w'} ) or defined( $Options{'W'} ) ) {
  97. if ( $userName =~ /[^\$]$/s ) {
  98. $userName .= "\$";
  99. }
  100. }
  101.  
  102. # untaint $userName (can finish with one or two $)
  103. if ( $userName =~ /^([\w -.]+\$?)$/ ) {
  104. $userName = $1;
  105. }
  106. else {
  107. print "$0: illegal username\n";
  108. exit(1);
  109. }
  110.  
  111. # user must not exist in LDAP (should it be nss-wide ?)
  112. my ( $rc, $dn ) = get_user_dn2($userName);
  113. if ( $rc and defined($dn) ) {
  114. print "$0: user $userName exists\n";
  115. exit(9);
  116. }
  117. elsif ( !$rc ) {
  118. print "$0: error in get_user_dn2\n";
  119. exit(10);
  120. }
  121.  
  122. # Read options
  123. # we create the user in the specified ou (relative to the users suffix)
  124. my $user_ou = $Options{'o'};
  125. my $node;
  126. if ( defined $user_ou ) {
  127.  
  128. # admin can specify a organizational unit like '-o ou=admin,ou=all'. We need to check that
  129. # each ou exist
  130. my @path;
  131. while ( $user_ou =~ m/(ou=)?([^,]+),?/g ) {
  132. push( @path, $2 );
  133. }
  134. foreach $node ( reverse @path ) {
  135.  
  136. # if the ou does not exist, we create it
  137. my $mesg = $ldap_master->search(
  138. base => "$config{usersdn}",
  139. scope => "one",
  140. filter => "(&(objectClass=organizationalUnit)(ou=$node))"
  141. );
  142. $mesg->code && die $mesg->error;
  143. if ( $mesg->count eq 0 ) {
  144. print
  145. "ou=$node,$config{usersdn} does not exist. Creating it (Y/[N]) ? ";
  146. chomp( my $answ = <STDIN> );
  147. if ( $answ eq "y" || $answ eq "Y" ) {
  148.  
  149. # add organizational unit
  150. my $add = $ldap_master->add(
  151. "ou=$node,$config{usersdn}",
  152. attr => [
  153. 'objectclass' => [ 'top', 'organizationalUnit' ],
  154. 'ou' => "$node"
  155. ]
  156. );
  157. $add->code && die "failed to add entry: ", $add->error;
  158. print "$user_ou,$config{usersdn} created \n";
  159.  
  160. }
  161. else {
  162. print "exiting.\n";
  163. exit;
  164. }
  165. }
  166. $config{usersdn} = "ou=$node,$config{usersdn}";
  167. }
  168. }
  169.  
  170. my $userUidNumber = $Options{'u'};
  171. if ( !defined($userUidNumber) ) {
  172. $userUidNumber = get_next_id( $config{usersdn}, "uidNumber" );
  173. }
  174. elsif ( getpwuid($userUidNumber) ) {
  175. die "Uid already exists.\n";
  176. }
  177.  
  178. if ( $nscd_status == 0 ) {
  179. system "/etc/init.d/nscd start > /dev/null 2>&1";
  180. }
  181.  
  182. my $createGroup = 0;
  183. my $userGidNumber = $Options{'g'};
  184.  
  185. # gid not specified ?
  186. if ( !defined($userGidNumber) ) {
  187.  
  188. # windows machine => $config{defaultComputerGid}
  189. if ( defined( $Options{'w'} ) or defined( $Options{'W'} ) ) {
  190. $userGidNumber = $config{defaultComputerGid};
  191.  
  192. # } elsif (!defined($Options{'n'})) {
  193. # create new group (redhat style)
  194. # find first unused gid starting from $config{GID_START}
  195. # while (defined(getgrgid($config{GID_START}))) {
  196. # $config{GID_START}++;
  197. # }
  198. # $userGidNumber = $config{GID_START};
  199.  
  200. # $createGroup = 1;
  201.  
  202. }
  203. else {
  204.  
  205. # user will have gid = $config{defaultUserGid}
  206. $userGidNumber = $config{defaultUserGid};
  207. }
  208. }
  209. else {
  210. my $gid;
  211. if ( ( $gid = parse_group($userGidNumber) ) < 0 ) {
  212. print "$0: unknown group $userGidNumber\n";
  213. exit(6);
  214. }
  215. $userGidNumber = $gid;
  216. }
  217.  
  218. my $group_entry;
  219. my $userGroupSID;
  220. my $userRid;
  221. my $user_sid;
  222. if ( defined $Options{'a'}
  223. or defined $Options{'i'}
  224. or defined $Options{'w'}
  225. or defined( $Options{'W'} ) )
  226. {
  227.  
  228. # as grouprid we use the value of the sambaSID attribute for
  229. # group of gidNumber=$userGidNumber
  230. $group_entry = read_group_entry_gid($userGidNumber);
  231. $userGroupSID = $group_entry->get_value('sambaSID');
  232. unless ($userGroupSID) {
  233. print "Error: SID not set for unix group $userGidNumber\n";
  234. print "check if your unix group is mapped to an NT group\n";
  235. exit(7);
  236. }
  237.  
  238. # as rid we use 2 * uid + 1000
  239. $userRid = 2 * $userUidNumber + 1000;
  240.  
  241. # let's test if this SID already exist
  242. $user_sid = "$config{SID}-$userRid";
  243. my $test_exist_sid = does_sid_exist( $user_sid, $config{usersdn} );
  244. if ( $test_exist_sid->count == 1 ) {
  245. print "User SID already owned by\n";
  246.  
  247. # there should not exist more than one entry, but ...
  248. foreach my $entry ( $test_exist_sid->all_entries ) {
  249. my $dn = $entry->dn;
  250. chomp($dn);
  251. print "$dn\n";
  252. }
  253. exit(7);
  254. }
  255. }
  256.  
  257. my $userHomeDirectory;
  258. my ( $givenName, $userCN, $userSN, $displayName );
  259. my @userMailLocal;
  260. my @userMailTo;
  261. my $tmp;
  262. if ( !defined( $userHomeDirectory = $Options{'d'} ) ) {
  263. $userHomeDirectory = &subst_user( $config{userHome}, $userName );
  264. }
  265.  
  266. # RFC 2256 & RFC 2798
  267. # sn: family name (option S) # RFC 2256: family name of a person.
  268. # givenName: prenom (option N) # RFC 2256: part of a person's name which is not their surname nor middle name.
  269. # cn: person's full name # RFC 2256: person's full name.
  270. # displayName: perferably displayed name # RFC 2798: preferred name of a person to be used when displaying entries.
  271.  
  272. #givenname is the forename of a person (not famiy name) => http://en.wikipedia.org/wiki/Given_name
  273. #surname (or sn) is the familiy name => http://en.wikipedia.org/wiki/Surname
  274. # my surname (or sn): Tournier
  275. # my givenname: Jerome
  276.  
  277. $userHomeDirectory =~ s/\/\//\//;
  278. $config{userLoginShell} = $tmp if ( defined( $tmp = $Options{'s'} ) );
  279. $config{userGecos} = $tmp if ( defined( $tmp = $Options{'c'} ) );
  280. $config{skeletonDir} = $tmp if ( defined( $tmp = $Options{'k'} ) );
  281. $givenName = ( utf8Encode( $Options{'N'} ) || $userName );
  282. $userSN = ( utf8Encode( $Options{'S'} ) || $userName );
  283. if ( $Options{'N'} and $Options{'S'} ) {
  284. $displayName = $userCN = "$givenName" . " $userSN";
  285. }
  286. else {
  287. $displayName = $userCN = $userName;
  288. }
  289.  
  290. @userMailLocal = &split_arg_comma( $Options{'M'} );
  291. @userMailTo = &split_arg_comma( $Options{'T'} );
  292.  
  293. ########################
  294.  
  295. # MACHINE ACCOUNT
  296. if ( defined( $Options{'w'} )
  297. or defined( $Options{'i'} )
  298. or defined( $Options{'W'} ) )
  299. {
  300.  
  301. # if Options{'i'} and username does not end with $ caracter => we add it
  302. if ( $Options{'i'} and !( $userName =~ m/\$$/ ) ) {
  303. $userName .= "\$";
  304. }
  305.  
  306. if (
  307. !add_posix_machine(
  308. $userName, $userUidNumber, $userGidNumber, $Options{'t'}
  309. )
  310. )
  311. {
  312. die "$0: error while adding posix account\n";
  313. }
  314.  
  315. if ( defined( $Options{'i'} ) ) {
  316.  
  317. # For machine trust account
  318. # Objectclass sambaSAMAccount must be added now !
  319. my $pass;
  320. my $pass2;
  321.  
  322. system "stty -echo";
  323. print "New password : ";
  324. chomp( $pass = <STDIN> );
  325. print "\n";
  326. system "stty echo";
  327.  
  328. system "stty -echo";
  329. print "Retype new password : ";
  330. chomp( $pass2 = <STDIN> );
  331. print "\n";
  332. system "stty echo";
  333.  
  334. if ( $pass ne $pass2 ) {
  335. print "New passwords don't match!\n";
  336. exit(10);
  337. }
  338. my ( $lmpassword, $ntpassword ) = ntlmgen $pass;
  339. my $date = time;
  340. my $modify = $ldap_master->modify(
  341. "uid=$userName,$config{computersdn}",
  342. changes => [
  343. replace => [
  344. objectClass =>
  345. [ 'posixAccount', 'account', 'sambaSAMAccount' ]
  346. ],
  347. add => [ sambaLogonTime => '0' ],
  348. add => [ sambaLogoffTime => '2147483647' ],
  349. add => [ sambaKickoffTime => '2147483647' ],
  350. add => [ sambaPwdCanChange => '0' ],
  351. add => [ sambaPwdMustChange => '2147483647' ],
  352. add => [ sambaPwdLastSet => "$date" ],
  353. add => [ sambaAcctFlags => '[I ]' ],
  354. add => [ sambaLMPassword => "$lmpassword" ],
  355. add => [ sambaNTPassword => "$ntpassword" ],
  356. add => [ sambaSID => "$user_sid" ],
  357. add => [ sambaPrimaryGroupSID => "$config{SID}-515" ]
  358. ]
  359. );
  360.  
  361. $modify->code && die "failed to add entry: ", $modify->error;
  362. }
  363. elsif ( defined( $Options{'W'} ) ) {
  364. my $date = time;
  365. my $modify = $ldap_master->modify(
  366. "uid=$userName,$config{computersdn}",
  367. changes => [
  368. replace => [
  369. objectClass =>
  370. [ 'posixAccount', 'account', 'sambaSAMAccount' ]
  371. ],
  372. add => [ sambaLogonTime => '0' ],
  373. add => [ sambaLogoffTime => '2147483647' ],
  374. add => [ sambaKickoffTime => '2147483647' ],
  375. add => [ sambaPwdCanChange => '0' ],
  376. add => [ sambaPwdMustChange => '2147483647' ],
  377. add => [ sambaPwdLastSet => "$date" ],
  378. add => [ sambaAcctFlags => '[W ]' ],
  379. add => [ sambaSID => "$user_sid" ],
  380. add => [ sambaPrimaryGroupSID => "$config{SID}-515" ],
  381. add => [ displayName => "$userName" ],
  382. add => [ sambaDomainName => "$config{sambaDomain}" ]
  383. ]
  384. );
  385.  
  386. $modify->code && die "failed to add entry: ", $modify->error;
  387. }
  388.  
  389. $ldap_master->unbind;
  390. exit 0;
  391. }
  392.  
  393. # USER ACCOUNT
  394. # add posix account first
  395. my $add;
  396.  
  397. # if AIX account, inetOrgPerson obectclass can't be used
  398. if ( defined( $Options{'b'} ) ) {
  399. $add = $ldap_master->add(
  400. "uid=$userName,$config{usersdn}",
  401. attr => [
  402. 'objectclass' => [
  403. 'top', 'person',
  404. 'organizationalPerson', 'posixAccount',
  405. 'shadowAccount'
  406. ],
  407. 'cn' => "$userCN",
  408. 'sn' => "$userSN",
  409. 'uid' => "$userName",
  410. 'uidNumber' => "$userUidNumber",
  411. 'gidNumber' => "$userGidNumber",
  412. 'homeDirectory' => "$userHomeDirectory",
  413. 'loginShell' => "$config{userLoginShell}",
  414. 'gecos' => "$config{userGecos}",
  415. 'userPassword' => "{crypt}x"
  416. ]
  417. );
  418. }
  419. else {
  420. $add = $ldap_master->add(
  421. "uid=$userName,$config{usersdn}",
  422. attr => [
  423. 'objectclass' => [
  424. 'top', 'person',
  425. 'organizationalPerson', 'inetOrgPerson',
  426. 'posixAccount', 'shadowAccount'
  427. ],
  428. 'cn' => "$userCN",
  429. 'sn' => "$userSN",
  430. 'givenName' => "$givenName",
  431. 'uid' => "$userName",
  432. 'uidNumber' => "$userUidNumber",
  433. 'gidNumber' => "$userGidNumber",
  434. 'homeDirectory' => "$userHomeDirectory",
  435. 'loginShell' => "$config{userLoginShell}",
  436. 'gecos' => "$config{userGecos}",
  437. 'userPassword' => "{crypt}x"
  438. ]
  439. );
  440. }
  441. $add->code && warn "failed to add entry: ", $add->error;
  442.  
  443. #if ($createGroup) {
  444. # group_add($userName, $userGidNumber);
  445. #}
  446.  
  447. if ( $userGidNumber != $config{defaultUserGid} ) {
  448. group_add_user( $userGidNumber, $userName );
  449. }
  450.  
  451. my $grouplist;
  452.  
  453. # adds to supplementary groups
  454. if ( defined( $grouplist = $Options{'G'} ) ) {
  455. add_grouplist_user( $grouplist, $userName );
  456. }
  457.  
  458. # If user was created successfully then we should create his/her home dir
  459. if ( defined( $tmp = $Options{'m'} ) ) {
  460. unless ( $userName =~ /\$$/ ) {
  461. if ( !( -d $userHomeDirectory ) ) {
  462. if ( $config{skeletonDir} ne "" ) {
  463. system
  464. "cp -r $config{skeletonDir} $userHomeDirectory 2>/dev/null";
  465. }
  466. else {
  467. system "mkdir $userHomeDirectory 2>/dev/null";
  468. }
  469. system
  470. "chown -R $userName:$userGidNumber $userHomeDirectory 2>/dev/null";
  471. if ( defined $config{userHomeDirectoryMode} ) {
  472. system
  473. "chmod $config{userHomeDirectoryMode} $userHomeDirectory 2>/dev/null";
  474. }
  475. else {
  476. system "chmod 700 $userHomeDirectory 2>/dev/null";
  477. }
  478. }
  479. else {
  480. print
  481. "Warning: homedirectory $userHomeDirectory already exist. Check manually\n";
  482. }
  483. }
  484. }
  485.  
  486. # we start to defined mail adresses if option M or T is given in option
  487. my @adds;
  488. if (@userMailLocal) {
  489. my @mail;
  490. foreach my $m (@userMailLocal) {
  491. my $domain = $config{mailDomain};
  492. if ( $m =~ /^(.+)@/ ) {
  493. push( @mail, $m );
  494.  
  495. # mailLocalAddress contains only the first part
  496. $m = $1;
  497. }
  498. else {
  499. push( @mail, $m . ( $domain ? '@' . $domain : '' ) );
  500. }
  501. }
  502. push( @adds, 'mailLocalAddress' => [@userMailLocal] );
  503. push( @adds, 'mail' => [@mail] );
  504. }
  505. if (@userMailTo) {
  506. push( @adds, 'mailRoutingAddress' => [@userMailTo] );
  507. }
  508. if ( @userMailLocal || @userMailTo ) {
  509. push( @adds, 'objectClass' => 'inetLocalMailRecipient' );
  510. }
  511.  
  512. # Custom modification - MPK
  513. if ( $Options{'Z'} ) {
  514. my @namval = split /,/, $Options{'Z'};
  515. if (@namval) {
  516. foreach my $pair (@namval) {
  517. my ( $name, $value ) = split /=/, $pair;
  518. next if ( !$name or !$value );
  519. push( @adds, $name => $value );
  520. }
  521. }
  522. }
  523.  
  524. # Add Samba user infos
  525. if ( defined( $Options{'a'} ) ) {
  526. if ( !$config{with_smbpasswd} ) {
  527.  
  528. my $winmagic = 2147483647;
  529. my $valpwdcanchange = 0;
  530. my $valpwdmustchange = $winmagic;
  531. my $valpwdlastset = 0;
  532. my $valacctflags = "[UX]";
  533.  
  534. if ( defined( $tmp = $Options{'A'} ) ) {
  535. if ( $tmp != 0 ) {
  536. $valpwdcanchange = "0";
  537. }
  538. else {
  539. $valpwdcanchange = "$winmagic";
  540. }
  541. }
  542.  
  543. if ( defined( $tmp = $Options{'B'} ) ) {
  544. if ( $tmp != 0 ) {
  545. $valpwdmustchange = "0";
  546.  
  547. # To force a user to change his password:
  548. # . the attribut sambaAcctFlags must not match the 'X' flag
  549. $valacctflags = "[U]";
  550. }
  551. else {
  552. $valpwdmustchange = "$winmagic";
  553. }
  554. }
  555.  
  556. if ( defined( $tmp = $Options{'H'} ) ) {
  557. $valacctflags = "$tmp";
  558. }
  559.  
  560. my $modify = $ldap_master->modify(
  561. "uid=$userName,$config{usersdn}",
  562. changes => [
  563. add => [ objectClass => 'sambaSAMAccount' ],
  564. add => [ sambaPwdLastSet => "$valpwdlastset" ],
  565. add => [ sambaLogonTime => '0' ],
  566. add => [ sambaLogoffTime => '2147483647' ],
  567. add => [ sambaKickoffTime => '2147483647' ],
  568. add => [ sambaPwdCanChange => "$valpwdcanchange" ],
  569. add => [ sambaPwdMustChange => "$valpwdmustchange" ],
  570. add => [ displayName => "$displayName" ],
  571. add => [ sambaAcctFlags => "$valacctflags" ],
  572. add => [ sambaSID => "$config{SID}-$userRid" ]
  573. ]
  574. );
  575.  
  576. $modify->code && die "failed to add entry: ", $modify->error;
  577.  
  578. }
  579. else {
  580. my $FILE = "|smbpasswd -s -a $userName >/dev/null";
  581. open( FILE, $FILE ) || die "$!\n";
  582. print FILE <<EOF;
  583. x
  584. x
  585. EOF
  586. close FILE;
  587. if ($?) {
  588. print "$0: error adding samba account\n";
  589. exit(10);
  590. }
  591. } # with_smbpasswd
  592.  
  593. $tmp = defined( $Options{'E'} ) ? $Options{'E'} : $config{userScript};
  594. my $valscriptpath = &subst_user( $tmp, $userName );
  595.  
  596. $tmp = defined( $Options{'C'} ) ? $Options{'C'} : $config{userSmbHome};
  597. my $valsmbhome = &subst_user( $tmp, $userName );
  598.  
  599. my $valhomedrive =
  600. defined( $Options{'D'} ) ? $Options{'D'} : $config{userHomeDrive};
  601.  
  602. # if the letter is given without the ":" symbol, we add it
  603. $valhomedrive .= ':' if ( $valhomedrive && $valhomedrive !~ /:$/ );
  604.  
  605. $tmp = defined( $Options{'F'} ) ? $Options{'F'} : $config{userProfile};
  606. my $valprofilepath = &subst_user( $tmp, $userName );
  607.  
  608. if ($valhomedrive) {
  609. push( @adds, 'sambaHomeDrive' => $valhomedrive );
  610. }
  611. if ($valsmbhome) {
  612. push( @adds, 'sambaHomePath' => $valsmbhome );
  613. }
  614.  
  615. if ($valprofilepath) {
  616. push( @adds, 'sambaProfilePath' => $valprofilepath );
  617. }
  618. if ($valscriptpath) {
  619. push( @adds, 'sambaLogonScript' => $valscriptpath );
  620. }
  621. if ( !$config{with_smbpasswd} ) {
  622. push( @adds, 'sambaPrimaryGroupSID' => $userGroupSID );
  623. push( @adds, 'sambaLMPassword' => "XXX" );
  624. push( @adds, 'sambaNTPassword' => "XXX" );
  625. }
  626. my $modify =
  627. $ldap_master->modify( "uid=$userName,$config{usersdn}", add => {@adds} );
  628.  
  629. $modify->code && die "failed to add entry: ", $modify->error;
  630. }
  631.  
  632. # add AIX user
  633. if ( defined( $Options{'b'} ) ) {
  634. my $modify = $ldap_master->modify(
  635. "uid=$userName,$config{usersdn}",
  636. changes => [
  637. add => [ objectClass => 'aixAuxAccount' ],
  638. add => [ passwordChar => "!" ],
  639. add => [ isAdministrator => "false" ]
  640. ]
  641. );
  642.  
  643. $modify->code && die "failed to add entry: ", $modify->error;
  644. }
  645.  
  646. $ldap_master->unbind; # take down session
  647.  
  648. if ( defined( $Options{'P'} ) ) {
  649. if ( defined( $tmp = $Options{'B'} ) and $tmp != 0 ) {
  650. exec "$RealBin/smbldap-passwd -B \"$userName\"";
  651. }
  652. else {
  653. exec "$RealBin/smbldap-passwd \"$userName\"";
  654. }
  655. }
  656.  
  657. exit 0;
  658.  
  659. ########################################
  660.  
  661. =head1 NAME
  662.  
  663. smbldap-useradd - Create a new user
  664.  
  665. =head1 SYNOPSIS
  666.  
  667. smbldap-useradd [-o user_ou] [-c comment] [-d home_dir] [-g initial_group] [-G group[,...]] [-m [-k skeleton_dir]] [-s shell] [-u uid [ -o]] [-P] [-A canchange] [-B mustchange] [-C smbhome] [-D homedrive] [-E scriptpath] [-F profilepath] [-H acctflags] login
  668.  
  669. =head1 DESCRIPTION
  670.  
  671. Creating New Users
  672. The smbldap-useradd command creates a new user account using the values specified on the command line and the default values from the system and from the configuration files (in /etc/smbldap-tools directory).
  673.  
  674. For Samba users, rid is '2*uidNumber+1000', and sambaPrimaryGroupSID is '$SID-2*gidNumber+1001', where $SID is the domain SID. Thus you may want to use :
  675. $ smbldap-useradd -a -g "Domain Admins" -u 500 Administrator
  676. to create an domain administrator account (admin rid is 0x1F4 = 500 and grouprid is 0x200 = 512).
  677.  
  678. Without any option, the account created will be an Unix (Posix) account. The following options may be used to add information:
  679.  
  680. -o node
  681. The user's account will be created in the specified organazional unit. It is relative to the user suffix dn ($usersdn) defined in the configuration file.
  682. Ex: 'ou=admin,ou=all'
  683.  
  684. -a
  685. The user will have a Samba account (and Unix).
  686.  
  687. -b
  688. The usrer is an AIX acount
  689.  
  690. -w
  691. Creates an account for a Samba machine (Workstation), so that it can join a sambaDomainName.
  692.  
  693. -i
  694. Creates an interdomain trust account (machine Workstation). A password will be asked for the trust account.
  695.  
  696. -c "comment"
  697. The new user's comment field (gecos). This option is for gecos only! To set as user's full name use the -N and -S options.
  698.  
  699. -d home_dir
  700. The new user will be created using home_dir as the value for the user's login directory. The default is to append the login name to userHomePrefix (defined in the configuration file) and use that as the login directory name.
  701.  
  702. -g initial_group
  703. The group name or number of the user's initial login group. The group name must exist. A group number must refer to an already existing group. The default group number is defined in the configuration file (defaultUserGid="513").
  704.  
  705. -G group,[...]
  706. A list of supplementary groups which the user is also a member of. Each group is separated to the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g option. The default is for the user to belong only to the initial group.
  707.  
  708. -m
  709. The user's home directory will be created if it does not exist. The files contained in skeletonDir will be copied to the home directory if the -k option is used, otherwise the files contained in /etc/skel will be used instead. Any directories contained in skeletonDir or /etc/skel will be created in the user's home directory as well. The -k option is only valid in conjunction with the -m option. The default is to not create the directory and to not copy any files.
  710.  
  711. -s shell
  712. The name of the user's login shell. The default is to leave this field blank, which causes the system to select the default login shell.
  713.  
  714. -t time
  715. Wait <time> seconds before exiting script when adding computer's account. This is useful when Master/PDC and Slaves/BDCs are connected through the internet (replication is not real time)
  716.  
  717. -u uid
  718. The numerical value of the user's ID. This value must be unique, unless the -o option is used. The value must be nonnegative. The default is to use the smallest ID value greater than 1000 and greater than every other user.
  719.  
  720. -P
  721. ends by invoking smbldap-passwd
  722.  
  723. -A
  724. can change password ? 0 if no, 1 if yes
  725.  
  726. -B
  727. must change password ? 0 if no, 1 if yes
  728.  
  729. -C sambaHomePath
  730. SMB home share, like '\\\\PDC-SRV\\homes'
  731.  
  732. -D sambaHomeDrive
  733. letter associated with home share, like 'H:'
  734.  
  735. -E sambaLogonScript
  736. relative to the [netlogon] share (DOS script to execute on login, like 'foo.bat'
  737.  
  738. -F sambaProfilePath
  739. profile directory, like '\\\\PDC-SRV\\profiles\\foo'
  740.  
  741. -H sambaAcctFlags
  742. spaces and trailing bracket are ignored (samba account control bits like '[NDHTUMWSLKI]'
  743.  
  744. -M mail
  745. local mail aliases (multiple addresses are seperated by spaces)
  746.  
  747. -N givenname
  748. family name. Defaults to username
  749.  
  750. -S surname
  751. defaults to username
  752.  
  753. -T mailToAddress
  754. Forward address (multiple addresses are seperated by spaces)
  755.  
  756. -n
  757. do not print banner message
  758.  
  759. =head1 SEE ALSO
  760.  
  761. useradd(1)
  762.  
  763. =cut
  764.  
  765. #'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement