Loading ...
Sorry, an error occurred while loading the content.

Re: [soaplite] Newbie question on 'soapifying' existing modules

Expand Messages
  • Jay A. Kreibich
    ... When using dispatch_to( ) the @INC path is cleared for security/sandboxing reasons. This means the use Net::... calls inside your module will
    Message 1 of 3 , Aug 3, 2006
    • 0 Attachment
      On Thu, Aug 03, 2006 at 06:11:15AM -0000, Chris Kacoroski scratched on the wall:
      > Hi,
      >
      > I have it installed and the examples work great. I have a high level
      > module that uses Net::LDAP for account management that I want to turn
      > into a soap service. My simple soap server is:
      >
      > #!/usr/bin/perl -w
      > use lib '/usr/local/lib'; # where I have the LDAPSOAP module
      > use SOAP::Transport::HTTP;
      >
      > # the following are called from LDAPSOAP, why do I get an error
      > # unless then are here
      > use Net::LDAP;
      > use Net::LDAPS;
      > use Net::LDAP::Util qw(ldap_error_name);
      >
      >
      > SOAP::Transport::HTTP::CGI
      > -> dispatch_to('/usr/local/lib')
      > -> handle;
      >
      > ------------------------------------------
      >
      > The simple client is:
      >
      > #!/usr/bin/perl -w
      >
      > use SOAP::Lite;
      >
      > $s = SOAP::Lite
      > -> uri('http://localhost/LDAPSOAP')
      > -> proxy('http://localhost/cgi-bin/ldap.cgi');
      >
      > $r = $s->school2Server('fw');
      >
      > $server = $r->result();
      >
      > print "$server\n";
      >
      > ---------------------------------------
      >
      > The error I get is:
      >
      > p $r->faultstring
      > Denied access to method (school2Server) in class (LDAPSOAP) at
      > /usr/local/share/perl/5.8.7/SOAP/Lite.pm line 2499, <DATA> line 225.

      > Questions:
      >
      > 1. Why do I need the Net::XXXX calls in the soap server?

      When using "dispatch_to( <path> )" the @INC path is cleared for
      security/sandboxing reasons. This means the "use Net::..." calls
      inside your module will fail. The solution is to "use" them in the
      SOAP server itself. When the system loads your module through the
      "dispatch_to( <path> )" the "use" statements will be ignored because
      the modules will already be in memory.

      See the "Service dispatch" section here: http://guide.soaplite.com/
      for more information (especially the "Mixed" sub-section).

      Also, you don't need the "use lib '/usr/local/lib';" line in the
      server.

      > 2. Why am I getting method access denied.

      Not exactly sure, but for some reason the system is convinced this
      isn't a valid reference to something inside your dispatch path.
      I assume the LDAPSOAP package is defined inside
      /usr/local/lib/LDAPSOAP.pm ?

      > 3. I was not able to get the server to work with modules that were
      > linked into /usr/local/lib. I had to copy them this. Is this
      > expected behavior.

      I'm not sure what you mean by "linked". If you mean the modules were
      sym-linked in at a file system level into that directory, I'm
      surprised that's an issue. If you mean "linked" in the compile sense,
      and that there are modules (not in /usr/local/lib) "use"'d by stuff
      that is in /usr/local/lib, then the issue is the same one that was
      pointed out in the answer to your first question. You can either
      "use" *all* of these modules in your SOAP server, or you need to come
      up with a different dispatch system.

      -j

      --
      Jay A. Kreibich | CommTech, Emrg Net Tech Svcs
      jak@... | Campus IT & Edu Svcs
      <http://www.uiuc.edu/~jak> | University of Illinois at U/C
    • Ski Kacoroski
      Jay, Thanks for your reply. ... Ok, This makes sense. ... Yes. So now I have changed the server to be: #!/usr/bin/perl -w use SOAP::Transport::HTTP; use
      Message 2 of 3 , Aug 3, 2006
      • 0 Attachment
        Jay,

        Thanks for your reply.
        >>
        >> 1. Why do I need the Net::XXXX calls in the soap server?
        >
        > When using "dispatch_to( <path> )" the @INC path is cleared for
        > security/sandboxing reasons. This means the "use Net::..." calls
        > inside your module will fail. The solution is to "use" them in the
        > SOAP server itself. When the system loads your module through the
        > "dispatch_to( <path> )" the "use" statements will be ignored because
        > the modules will already be in memory.
        >
        > See the "Service dispatch" section here: http://guide.soaplite.com/
        > for more information (especially the "Mixed" sub-section).
        >
        > Also, you don't need the "use lib '/usr/local/lib';" line in the
        > server.

        Ok, This makes sense.

        >
        >> 2. Why am I getting method access denied.
        >
        > Not exactly sure, but for some reason the system is convinced this
        > isn't a valid reference to something inside your dispatch path.
        > I assume the LDAPSOAP package is defined inside
        > /usr/local/lib/LDAPSOAP.pm ?
        >

        Yes. So now I have changed the server to be:

        #!/usr/bin/perl -w

        use SOAP::Transport::HTTP;
        use Net::LDAP;
        use Net::LDAPS;
        use Net::LDAP::Util qw(ldap_error_name);

        SOAP::Transport::HTTP::CGI
        -> dispatch_to('/usr/local/lib')
        -> handle;


        /usr/local/lib/LDAPSOAP is:

        package LDAPSOAP;

        use strict;
        use vars qw($VERSION);
        require Exporter;
        our @ISA = qw(Exporter);
        our @EXPORT = qw(school2Server);
        use Net::LDAP;
        use Net::LDAPS;
        use Net::LDAP::Util qw(ldap_error_name);

        our $VERSION = 0.5;

        # evaluate the perl code from the config filei
        our %nsdconf;
        do "/tmp/nsdconf.pl" or die
        "ERROR: could not read nsd config file $!\n";

        # Function to return the server given a school code
        sub school2Server {
        my ($school_code) = @_;
        return ($nsdconf{site_server}{$school_code});
        }

        The problem I am having is that it is not reading in the nsdconf.pl file
        which is where $nsdconf{site_server} is defined. Other than that it
        works. Is there a best practice on how to handle a configuration file
        for a module with Soap.


        >> 3. I was not able to get the server to work with modules that were
        >> linked into /usr/local/lib. I had to copy them this. Is this
        >> expected behavior.
        >
        > I'm not sure what you mean by "linked". If you mean the modules were
        > sym-linked in at a file system level into that directory, I'm
        > surprised that's an issue.

        I meant softlinks in the file system. If I replace the softlinks with
        the file it works. I think it may be because the softlink points into a
        directory that the apache web server does not have access to (even
        though the file is 644).

        Thanks for your help.

        cheers,

        ski
        --
        "When we try to pick out anything by itself, we find it
        connected to the entire universe" John Muir

        Chris "Ski" Kacoroski, kacoroski@..., 206-501-9803
      Your message has been successfully submitted and would be delivered to recipients shortly.