[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  #!/usr/bin/perl
   2  # $Id: groupAdd.pl 6654 2011-11-27 16:35:54Z dbo $
   3  
   4  use Unicode::String qw(latin1 utf8);
   5  
   6  require '/etc/SeConfig.ph';
   7  
   8  ($groupType, $cn, @description) = @ARGV;
   9  
  10  die("Erreur d'argument" . ".\n") if ($#ARGV < 2 or ($groupType != 1 and $groupType != 2));
  11  
  12  $groupType = 'posixGroup' if $groupType == 1;
  13  $groupType = 'groupOfNames' if $groupType == 2;
  14  
  15  $description = join ' ', @description;
  16  $description = latin1($description)->utf8;
  17  
  18  $gid = getFirstFreeGid(1000);
  19  
  20  @args = (
  21       "/usr/share/se3/sbin/entryAdd.pl",
  22       "cn=$cn,$groupsDn",
  23       "cn=$cn",
  24       "objectClass=top",
  25       "objectClass=$groupType",
  26       "description=$description",
  27      );
  28  
  29  $optionalArg = "gidNumber=$gid";
  30  push @args, $optionalArg if $groupType eq 'posixGroup';
  31  
  32  $res = 0xffff & system @args;
  33  die("Erreur lors de l'ajout du groupe.\n") if $res != 0;
  34  
  35  system("sudo /usr/share/se3/scripts/group_mapping.sh $cn $cn \"$description\"") if $groupType eq 'posixGroup';
  36  
  37  exit 0;
  38  
  39  sub getFirstFreeGid {
  40  my $gidNumber = shift; # n° à partir duquel la recherche est lancée
  41  my $increment = 1024; # doit etre une puissance de 2
  42  if (defined(getgrgid($gidNumber))) {    
  43      do {
  44          $gidNumber += $increment;
  45      } while (defined(getgrgid($gidNumber)));
  46      
  47      $increment = int($increment / 2); 
  48      $gidNumber -= $increment;
  49      do {
  50          $increment = int($increment / 2); 
  51          if (defined(getgrgid($gidNumber))) {
  52              $gidNumber += $increment;
  53          } else {
  54              $gidNumber -= $increment;
  55          }
  56      } while $increment > 1;
  57      # la boucle suivante est normalement exécutée au plus une fois
  58      while (defined(getgrgid($gidNumber))) {
  59          $gidNumber++;
  60      }
  61  }
  62  return $gidNumber;
  63  }


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