Samba-LDAP

 view release on metacpan or  search on metacpan

scripts/smbldap-useradd  view on Meta::CPAN


# USER ACCOUNT
# add posix account first
my $add;
# if AIX account, inetOrgPerson obectclass can't be used
if (defined($Options{'b'})) {
	$add = $ldap_master->add ("uid=$userName,$config{usersdn}",
				     attr => [
					      'objectclass' => ['top','person', 'organizationalPerson', 'posixAccount','shadowAccount'],
					      'cn'   => "$userCN",
					      'sn'   => "$userSN",
					      'uid'   => "$userName",
					      'uidNumber'   => "$userUidNumber",
					      'gidNumber'   => "$userGidNumber",
					      'homeDirectory'   => "$userHomeDirectory",
					      'loginShell'   => "$config{userLoginShell}",
					      'gecos'   => "$config{userGecos}",
					      'userPassword'   => "{crypt}x"
					     ]
			    	);
} else {
	$add = $ldap_master->add ("uid=$userName,$config{usersdn}",
				     attr => [
					      'objectclass' => ['top','person', 'organizationalPerson', 'inetOrgPerson','posixAccount','shadowAccount'],
					      'cn'   => "$userCN",
					      'sn'   => "$userSN",
					      'givenName'   => "$givenName",
					      'uid'   => "$userName",
					      'uidNumber'   => "$userUidNumber",
					      'gidNumber'   => "$userGidNumber",
					      'homeDirectory'   => "$userHomeDirectory",
					      'loginShell'   => "$config{userLoginShell}",
					      'gecos'   => "$config{userGecos}",
					      'userPassword'   => "{crypt}x"
					     ]
			    	);
}
$add->code && warn "failed to add entry: ", $add->error ;


#if ($createGroup) {
#    group_add($userName, $userGidNumber);
#}

if ($userGidNumber != $config{defaultUserGid}) {
  group_add_user($userGidNumber, $userName);
}

my $grouplist;
# adds to supplementary groups
if (defined($grouplist = $Options{'G'})) {
  add_grouplist_user($grouplist, $userName);
}

# If user was created successfully then we should create his/her home dir
if (defined($tmp = $Options{'m'})) {
  unless ( $userName =~ /\$$/ ) {
    if ( !(-e $userHomeDirectory) ) {
      system "mkdir $userHomeDirectory 2>/dev/null";
      system "cp -a $config{skeletonDir}/.[a-z,A-Z]* $config{skeletonDir}/* $userHomeDirectory 2>/dev/null";
      system "chown -R $userUidNumber:$userGidNumber $userHomeDirectory 2>/dev/null";
      if (defined $config{userHomeDirectoryMode}) {
	system "chmod $config{userHomeDirectoryMode} $userHomeDirectory 2>/dev/null"; 
      } else {
	system "chmod 700 $userHomeDirectory 2>/dev/null"; 
      }
    }
  }
}

# we start to defined mail adresses if option M or T is given in option
my @adds;
if (@userMailLocal) {
  my @mail;
  foreach my $m (@userMailLocal) {
    my $domain = $config{mailDomain};
    if ($m =~ /^(.+)@/) {
      push (@mail, $m);
      # mailLocalAddress contains only the first part
      $m= $1;
    } else {
      push(@mail, $m.($domain ? '@'.$domain : ''));
    }
  }
  push(@adds, 'mailLocalAddress' => [ @userMailLocal ]);
  push(@adds, 'mail' => [ @mail ]);
}
if (@userMailTo) {
  push(@adds, 'mailRoutingAddress' => [ @userMailTo ]);
}
if (@userMailLocal || @userMailTo) {
  push(@adds, 'objectClass' => 'inetLocalMailRecipient');
}

# Add Samba user infos
if (defined($Options{'a'})) {
  if (!$config{with_smbpasswd}) {

    my $winmagic = 2147483647;
    my $valpwdcanchange = 0;
    my $valpwdmustchange = $winmagic;
    my $valpwdlastset = 0;
    my $valacctflags = "[UX]";

    if (defined($tmp = $Options{'A'})) {
      if ($tmp != 0) {
	$valpwdcanchange = "0";
      } else {
	$valpwdcanchange = "$winmagic";
      }
    }

    if (defined($tmp = $Options{'B'})) {
      if ($tmp != 0) {
	$valpwdmustchange = "0";
	# To force a user to change his password:
	# . the attribut sambaPwdLastSet must be != 0
	# . the attribut sambaAcctFlags must not match the 'X' flag
	$valpwdlastset=$winmagic;
	$valacctflags = "[U]";
      } else {



( run in 0.534 second using v1.01-cache-2.11-cpan-5511b514fd6 )