[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3master/usr/share/se3/sbin/ -> groupAddEntry.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  
   9  ($dnToAdd, $dnWhereToAdd) = @ARGV;
  10  
  11  $attribute = typeOfGroup($dnWhereToAdd);
  12  
  13  unless ($attribute eq 'member') {
  14    $dnToAdd =~ /^\w*=([0-9a-zA-Z-_\.]*),/g;
  15    $dnToAdd = $1;
  16  }
  17  
  18  $ldap = Net::LDAP->new(
  19                 "$slapdIp",
  20                 port    => "$slapdPort",
  21                 debug   => "$slapdDebug",
  22                 timeout => "$slapdTimeout",
  23                 version => "$slapdVersion"
  24                );
  25  $ldap->bind(
  26          "$adminDn",
  27          password => "$adminPw"
  28         );
  29  $res = $ldap->modify(
  30                $dnWhereToAdd,
  31                add => { $attribute => $dnToAdd }
  32               );
  33  
  34  die("Erreur LDAP : " . $res->error . ".\n") if ($res->code ne 0);
  35  
  36  exit 0;
  37  
  38  sub typeOfGroup {
  39    $dnToSearchIn = shift @_;
  40    $ldap = Net::LDAP->new(
  41               "$slapdIp",
  42               port    => "$slapdPort",
  43               debug   => "$slapdDebug",
  44               timeout => "$slapdTimeout",
  45               version => "$slapdVersion"
  46              );
  47    $ldap->bind(); # Anonymous BIND
  48    $res = $ldap->search(
  49                 base     => "$dnToSearchIn",
  50                 scope    => 'base',
  51                 attrs    => ['objectClass'],
  52                 filter   => 'objectClass=*'
  53                );
  54    die("Erreur LDAP : " . $res->error . ".\n") if ($res->code ne 0);  
  55    foreach $entry ($res->entries) {
  56      @classes  = $entry->get_value('objectClass');
  57    }
  58    foreach $classe (@classes) {
  59      $type = $classe if ($classe =~ /posixGroup/i or $classe =~ /groupOfNames/i);
  60    }
  61    die ("Erreur de recherche sur $dnToSearchIn pour $type.\n") if (!defined($type));
  62    
  63    if ($type =~ /posixGroup/i) {
  64      $attribute = 'memberUid';
  65    } elsif ($type =~ /groupOfNames/i) {
  66      $attribute = 'member'
  67    } else {
  68      die ("Erreur de recherche sur $dnToSearchIn.");
  69    }
  70    
  71    return $attribute;
  72  }


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