I've run into an interesting problem and hope that the Perl monks here might be able to give me some advice. My current job at work is to alter a very successful student service site to play nicely with a portal we've just bought.

Currently we require the students to submit their PIN with every change to their details and hope that that can be avoided with the portal. The first time that the student comes in from the portal they'll hit a basic auth page and submit their username and password. From then on the portal will submit their details to my site and no further PIN or password will be needed.

Unfortunately their username will not be their student number, so I need to make an LDAP query to our LDAP server to get their student number based on their username. This is easy, I'm using perl-ldap version 0.26. (I did try perldap but had too much trouble getting it to install on our alpha machine).

The machine that our (Forte) database (with all the student's course details etc) is on is different from where we host the student service. Access for information and updates for changes are made by web requests over SSL. This is easy, I'm using the libwww-perl libraries version 5.65.

My problem is that I can very easily get the student's student number from LDAP or I can very easily access Forte, but for some reason I can't do both. Simplified code is as follows:

### Forte.pm package Forte; use LWP::UserAgent; $ENV{HTTPS_VERSION} = '3'; $ENV{HTTPS_CERT_FILE} = "some.crt"; $ENV{HTTPS_KEY_FILE} = "some.key"; sub callforte { ... my $ua = new LWP::UserAgent; my $req = new HTTP::Request("POST", "$url"); ... my $res = $ua->request($req); ... } #------------------------------------------ ### LDAP.pm package LDAP; use Net::LDAPS; sub LDAP_connect { .... my $conn = new Net::LDAPS($LDAPhost, port=>$LDAPport, clientcert=>$cert, clientkey=>$key); .... } sub get_student_number { LDAP_connect(); ... my $entry = $conn->search(filter=>"(uid=$username)", base=>$base, attrs=>[qw/studentnumber/]); if($entry->code()) { html_error("Search for student ID for [$username] fail +ed:". $entry->code() . "\n"); return 0; } ... return $entry->{attrs}{studentnumber}[0]; } #------------------------------------------ #### application use Forte; use LDAP; # test for connection to db: $return = Forte::callforte($url, $input); ... if($using_portal) { # get student number $student_number = LDAP::get_student_number($username); }
If I comment out use LDAP; and set $using_portal to false, everything works as it should, the $ua->request($req) takes some time and returns with code 200 (and any data I want). If I leave $using_portal false, but uncomment use LDAP; then when I attempt to connect to the Forte database the $ua->request($req) line returns immediately with error code 500.

If I leave use LDAP; in my application but instead comment out use Net::LDAPS; in my LDAP package it works fine again, although obviously I won't be able to connect to LDAP.

Where do I even start with trying to work out what is making these two modules not play well together?

The dependencies (that I know about) and the versions I have installed are as follows:

I suspect that the problem is between the two SSLeay libraries, although I'm not sure how or why. Short of rewriting perl-ldap to replace Net::SSLeay with LWP, I'm not sure how I'd tell. Both have been compiled to use openssl version 0.9.6d. Has anyone had any experience here before?

All suggestions are appreciated. And thanks for reading this way-too-long question. :)

jarich


In reply to Mixing modules, LWP::UserAgent and Net::LDAPS not playing well together. by jarich

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.