[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 #!/usr/bin/perl 2 3 use Net::LDAP; 4 use POSIX; 5 6 require '/etc/SeConfig.ph'; 7 8 die("Erreur d'argument.\n") if ($#ARGV != 1); 9 ($valueToSearch, $dnToSearchIn) = @ARGV; 10 11 $attribute = typeOfGroup($dnToSearchIn); 12 13 $res = $ldap->search( 14 base => "$dnToSearchIn", 15 scope => 'base', 16 attrs => ['$attribute'], 17 filter => 'objectClass=*' 18 ); 19 20 foreach $entry ($res->entries) { 21 @members = $entry->get_value($attribute); 22 } 23 foreach $membre (@members) { 24 $found = 1 if ($membre =~ /(\w*=|^)$valueToSearch(,|$)/); 25 } 26 27 $ldap->unbind(); 28 29 die("$valueToSearch non trouvé dans $dnToSearchIn.\n") if (!defined($found)); 30 31 exit 0; 32 33 sub typeOfGroup { 34 $dnToSearchIn = shift @_; 35 $ldap = Net::LDAP->new( 36 "$slapdIp", 37 port => "$slapdPort", 38 debug => "$slapdDebug", 39 timeout => "$slapdTimeout", 40 version => "$slapdVersion" 41 ); 42 $ldap->bind(); # Anonymous BIND 43 44 $res = $ldap->search( 45 base => "$dnToSearchIn", 46 scope => 'base', 47 attrs => ['objectClass'], 48 filter => 'objectClass=*' 49 ); 50 51 foreach $entry ($res->entries) { 52 @classes = $entry->get_value('objectClass'); 53 } 54 foreach $classe (@classes) { 55 $type = $classe if ($classe =~ /group/i); 56 } 57 die ("Erreur de recherche sur $dnToSearchIn.\n") if (!defined($type)); 58 59 if ($type =~ /posixGroup/i) { 60 $attribute = 'memberUid'; 61 } elsif ($type =~ /groupOfNames/i) { 62 $attribute = 'member' 63 } else { 64 die ("Erreur de recherche sur $dnToSearchIn.\n"); 65 } 66 67 return $attribute; 68 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |