#!/usr/bin/perl -w use Net::LDAP; use strict; my $ldap; my $result; my $opt_uri = "ldap://localhost"; my $opt_user = $ENV{'username'}; my $opt_passwd = $ENV{'password'}; my $opt_common = $ENV{'common_name'}; my $opt_group = "cn=vpnusers,ou=Groups,dc=mycompany,dc=com"; my $opt_binddn = "uid=".$opt_user.",ou=People,dc=mycompany,dc=com"; $ldap = Net::LDAP->new($opt_uri) or die("connect $opt_uri failed!"); $result = $ldap->bind($opt_binddn, password=>$opt_passwd); $result->code and $result = $ldap->bind("uid=".$opt_user.",ou=Interns,dc=mycompany,dc=com", password=>$opt_passwd); $result->code and die($result->error); $result = $ldap->search(base=>$opt_group, filter=>"(&(memberUid=$opt_user))"); $result->code(); if ($result->count == 1) { exit 0; } unless($result->count){ exit 1; }