[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  #!/usr/bin/perl
   2  
   3  ### $Id: groupDelEntry.pl 8305 2014-12-07 22:13:48Z dbo $ ###
   4  
   5  use Net::LDAP;
   6  
   7  require '/etc/SeConfig.ph';
   8  
   9  die("Erreur d'argument.\n") if ($#ARGV != 1);
  10  
  11  ($dnToDel, $dnWhereToDel) = @ARGV;
  12  
  13  $attribute = typeOfGroup($dnWhereToDel);
  14  
  15  unless ($attribute eq 'member') {
  16    $dnToDel =~ /^(\w*)=([\w\-_\.\d]*),/;
  17    $dnToDel = $2;
  18  }
  19  
  20  $ldap = Net::LDAP->new(
  21                 "$slapdIp",
  22                 port    => "$slapdPort",
  23                 debug   => "$slapdDebug",
  24                 timeout => "$slapdTimeout",
  25                 version => "$slapdVersion"
  26                );
  27  
  28  $ldap->bind(
  29          $adminDn,
  30          password => $adminPw
  31         );
  32  
  33  $res = $ldap->modify(
  34                $dnWhereToDel,
  35                delete => { $attribute => $dnToDel }
  36               );
  37  
  38  die("Erreur LDAP : " . $res->error . ".\n") if ($res->code ne 0);
  39  
  40  exit 0;
  41  
  42  sub typeOfGroup {
  43    $dnToSearchIn = shift @_;
  44  
  45    $ldap = Net::LDAP->new(
  46               "$slapdIp",
  47               port    => "$slapdPort",
  48               debug   => "$slapdDebug",
  49               timeout => "$slapdTimeout",
  50               version => "$slapdVersion"
  51              );
  52    $ldap->bind(); # Anonymous BIND
  53    $res = $ldap->search(
  54                 base     => "$dnToSearchIn",
  55                 scope    => 'base',
  56                 attrs    => ['objectClass'],
  57                 filter   => 'objectClass=*'
  58                );
  59    
  60    foreach $entry ($res->entries) {
  61      @classes  = $entry->get_value('objectClass');
  62    }
  63    foreach $classe (@classes) {
  64      $type = $classe if ($classe =~ /group/i);
  65    }
  66    die ("Erreur de recherche sur $dnToSearchIn.\n") if (!defined($type));
  67    
  68    if ($type =~ /posixGroup/i) {
  69      $attribute = 'memberUid';
  70    } elsif ($type =~ /sambaGroupMapping/i) {
  71      $attribute = 'memberUid';
  72    } elsif ($type =~ /groupOfNames/i) {
  73      $attribute = 'member'
  74    } else {
  75      die ("Erreur de recherche sur $dnToSearchIn.\n");
  76    }
  77    
  78    return $attribute;
  79  }


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