Hello Monks,
I have a working script which is used to authenticate users for vpn using ldap for openvpn. The way script called is, in openvpn conf file ( /etc/openvpn/server.conf )
auth-user-pass-verify /etc/openvpn/ldap_authenticate.pl via-env
The script is as follows,
cat ldap_authenticate.pl
#!/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_u
+ser))");
$result->code();
if ($result->count == 1) { exit 0; }
unless($result->count){ exit 1; }
It works perfectly fine for users who are from
ou=People1). Just wondering how
$ENV{'username'} and
$ENV{'password'} work? I mean, considering if i call this script on command line by changing them to ask from user i.e <STDIN>, it says
Invalid credentialsand when i printed "$result" using Dumper, i can see that resultCode is 49. - How to enter manually , without using $ENV?
2). If i want to authenticate another CN ( in addition to CN=People, say CN=testuserforvpn, how can i do that?
Any pointers are greatly helpful.
Thanks
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.