[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  #!/usr/bin/perl
   2  
   3  ##### Change le shell de tous les utilisateurs #####
   4  
   5  # $Id: changeShellAllUsers.pl 6654 2011-11-27 16:35:54Z dbo $ #
   6  
   7  
   8  use Net::LDAP; 
   9  require '/etc/SeConfig.ph'; 
  10  
  11  die("Erreur d'argument.  Usage : changeShellAllUsers.pl shell_courant shell_cible.\n")
  12      if ($#ARGV != 1);
  13  ($shell_courant, $shell_cible) = @ARGV;
  14  die ("Erreur d'argument. shell : /bin/bash|/bin/false|/usr/lib/sftp-server.\n")
  15      if ((   $shell_courant ne '/bin/bash'
  16           && $shell_courant ne '/bin/false'
  17           && $shell_courant ne '/usr/lib/sftp-server') ||
  18          (   $shell_cible   ne '/bin/bash'
  19           && $shell_cible   ne '/bin/false'
  20           && $shell_cible   ne '/usr/lib/sftp-server'));
  21  
  22  
  23  $lcs_ldap = Net::LDAP->new(
  24      "$slapdIp",
  25      port    => "$slapdPort",
  26      debug   => "$slapdDebug",
  27      timeout => "$slapdTimeout",
  28      version => "$slapdVersion"
  29  );
  30  $lcs_ldap->bind(
  31      dn       => $adminDn,
  32      password => $adminPw,
  33      version  => '3'
  34  );
  35  $res = $lcs_ldap->search(
  36      base     => "$baseDn",
  37      scope    => 'sub',
  38      filter   => "loginShell=$shell_courant"
  39  );
  40  foreach $entry ($res->entries) {
  41      $dnToModify = $entry->dn;
  42      $homeDirectory = $entry->get_value('homeDirectory');
  43      $res = $lcs_ldap->modify(
  44          $dnToModify,
  45          replace => { 'loginShell' => $shell_cible }
  46      );
  47      if ($homeDirectory !~ /\/\.\// &&
  48          $shell_cible eq '/usr/lib/sftp-server') {
  49          $res = $lcs_ldap->modify(
  50              $dnToModify,
  51              replace => { 'homeDirectory' => "$homeDirectory/./" }
  52          );
  53      }
  54      if (   ($shell_cible eq '/bin/bash' || $shell_cible eq '/bin/true')
  55          && $homeDirectory =~ /(.*)\/\.\//) {
  56          $res = $lcs_ldap->modify(
  57                       $dnToModify,
  58                       replace => { 'homeDirectory' => "$1" }
  59          );
  60      }
  61  }


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