[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  #!/usr/bin/perl
   2  
   3  use Net::LDAP;
   4  use Net::LDAP::Entry;
   5  
   6  require '/etc/SeConfig.ph';
   7  
   8  if ($#ARGV < 2) {
   9    print
  10      "Usage :\n",
  11      "\tentryAdd.pl distinguishedName (",
  12      "liste d'arguments 'attribut=valeurs')",
  13      "\n";
  14    die("Erreur d'argument\n");
  15  }
  16  
  17  ($dn, @reste) = @ARGV;
  18  $entryToAdd = Net::LDAP::Entry->new;
  19  $entryToAdd->dn($dn);
  20  
  21  $attrs = join ' ', @reste;
  22  
  23  while (1) {
  24    $n=0;
  25    while ($attrs =~ /\=/g) {
  26      $n++;
  27    }
  28    last if $n == 1;
  29    $attrs =~ /^(.*)\s+(\w*)=(.*)$/;
  30    $attrs = $1;
  31    $entryToAdd->add($2 => $3);
  32  }
  33  
  34  ($lastAttribute, $lastValue) = split /=/, $attrs;
  35  $entryToAdd->add($lastAttribute => $lastValue);
  36  
  37  # DEBUG INFO
  38  #############
  39  #print "\ndn : $dn\n";
  40  #foreach my $attr ($entryToAdd->attributes) {
  41  #  foreach my $value ($entryToAdd->get_value($attr)) {
  42  #    print "$attr : $value\n";
  43  #  }
  44  #}
  45  
  46  $ldap = Net::LDAP->new(
  47                  "$slapdIp",
  48                  port    => "$slapdPort",
  49                  debug   => "$slapdDebug",
  50                  timeout => "$slapdTimeout",
  51                  version => "$slapdVersion"
  52                 );
  53  $ldap->bind(
  54           $adminDn,
  55           password => $adminPw
  56          );
  57  $res = $ldap->add($entryToAdd);
  58  
  59  die("Erreur LDAP : " . $res->error . ".\n") if ($res->code ne 0);
  60  
  61  exit 0;


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