[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3master/usr/share/se3/sbin/ -> userChangePwd.pl (source)

   1  #!/usr/bin/perl
   2  
   3  use Net::LDAP;
   4  
   5  require '/etc/SeConfig.ph';
   6  
   7  die("Erreur d'argument.\n") if ($#ARGV != 1);
   8  ($uid, $password) = @ARGV;
   9  $dn = "uid=$uid,$peopleDn";
  10  # Generation du mot de passe crypte
  11  $crypt = `/usr/sbin/slappasswd -h {MD5} -s '$password'`;
  12  ($lmPassword, $ntPassword) = mkNtPasses($password);
  13  
  14  $ldap = Net::LDAP->new(
  15                 "$slapdIp",
  16                 port    => "$slapdPort",
  17                 debug   => "$slapdDebug",
  18                 timeout => "$slapdTimeout",
  19                 version => "$slapdVersion"
  20                );
  21  $ldap->bind(
  22          $adminDn,
  23          password => $adminPw
  24         );
  25  $res = $ldap->search(
  26               base   => "$baseDn",
  27               scope  => 'sub',
  28               filter => "(&(uid=$uid)(objectClass=sambaSamAccount))"
  29              );
  30  warn $res->error if $res->code;
  31  #print ($res->entries)[0];
  32  if (($res->entries)[0]) {
  33  $res = $ldap->modify(
  34               $dn,
  35               replace => {
  36                   userPassword => $crypt,
  37                   sambaNTPassword   => $ntPassword,
  38                   sambaLMPassword   => $lmPassword,
  39                   shadowLastChange  => time                 }
  40              );
  41  } else {
  42  $res = $ldap->modify(
  43               $dn,
  44               replace => {
  45                   userPassword => $crypt,
  46                   ntPassword   => $ntPassword,
  47                   lmPassword   => $lmPassword,
  48                   shadowLastChange  => time
  49                  }
  50              );
  51  }
  52  
  53  $res->code && die("Erreur LDAP : " . $res->code . " => " . $res->error . ".\n");
  54  if ($uid eq "admin") {
  55  system("htpasswd -bm /var/www/se3/setup/.htpasswd admin $password");
  56  
  57  }
  58  
  59  exit 0;
  60  
  61  sub mkNtPasses {
  62  
  63    my ($password) = shift @_;
  64  
  65    $sambaPasses = `/usr/share/se3/sbin/mkntpwd '$password'`;
  66    $sambaPasses =~ /(.*):(.*)/;
  67    $lmPassword = $1;
  68    $ntPassword = $2;
  69  
  70    @data = ($lmPassword, $ntPassword);
  71  
  72    return @data;
  73  
  74  }
  75  


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1