bkiahg has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Once again I seek your wise wisdom. I am trying to include a file across multiple web servers and I am having a terrible time with it. I first tried a simple open statement.
open(MENU, "\\\\servername\\sharename\\path\\tofile.inc") or die "Cann +ot open: $!"; while (<MENU>) {print} close MENU;
And regardless of the permissions I put on the 2003 box it tells me permission denied.

And then I tried a LWP::Simple script:
#! C:/perl/bin/perl.exe -w use strict; use CGI::Carp qw(fatalsToBrowser); use LWP::Simple; my $webpage = get("http://servername/global/admin_menu.inc"); die "Couldn't get it: $!" unless defined $webpage; print "Content-type: text/html\n\n"; print $webpage;
It gives me "Bad file descriptor"

Any way to send the permissions of the web browser to the other server? Either LWP::Simple or an open solution would work. Please point me in the right direction. Thanks in advance.

Update: fixed typo.

Replies are listed 'Best First'.
Re: Using a 2000 Box to Access an Include File from 2003
by NetWallah (Canon) on Jun 17, 2004 at 23:21 UTC
    It depends on how you are running the CGI script on the Web server.

    Typically, if you allow ANONYMOUS access to the CGI script, it runs under the ID IUSER_MachineName.
    This user does NOT have access to network shares.

    My suggestion is to turn OFF anonymous access, and let the user credentials come in either via integrated authentication, or basic.

    There are other ways around this, once you understand the issue. One is to specify specific user credentials to the user script.

    Note - I think this explains why the first script failed. The second one with LWP should have worked. The Event log, and IIS logs will provide more clues.

    Offense, like beauty, is in the eye of the beholder, and a fantasy.
    By guaranteeing freedom of expression, the First Amendment also guarantees offense.

      I have anon access turned off and tried both Window digest and Integrated Authentication (preferred). I would like to stay away from having user credentials in the script itself, but if theres no other way then...

      Will check the logs for more info. Thanks.

      Update: Checked the logs and event viewer and theres nothing pertinent in there.
        OK - I think I know why the second script (with LWP) fails:

        You are accessing a file with a .inc extension - by default, the web server does not associate this extension with a MIME type, so it will give you some kind of error.

        To fix this, associate .inc with text/html - however - I must warn you that this is a security hazard, since users will now be able to view your .inc scripts.

        Accessing the file via \\Server\path should work - make sure you have escaped back-slashes. Try the "-e <Filename>" test to verify file existance, and print the file name to see if it does look like it is supposed to. Remember - if you use a drive-letter like \\Server\c$ , you need to escape the dollar-sign as well.

        sweetblood and others messages above also have valid points, but I have not seen your response to them.

        Offense, like beauty, is in the eye of the beholder, and a fantasy.
        By guaranteeing freedom of expression, the First Amendment also guarantees offense.

Re: Using a 2000 Box to Access an Include File from 2003
by sweetblood (Prior) on Jun 17, 2004 at 22:47 UTC
    Aside from the missing ')' on your open line, and the fact I believe you should be using || instead of the or, due to operator precedence, your code looks ok. Can you access this file by entering the UNC into explorer or a browser? If you can't access it by any other means, then you're not going to be able to do so with Perl. It seems more likely a permmissions problem then any other.

    HTH

    Sweetblood

      Yes I can map to it and open it with a browser. But when I try and access it using the cgi it fails. It's almost as if the windows boxes aren't transferring the permissions of the user executing the cgi.

      Anything on 2003 that I may need to turn on? It has everything shut off by default.
      the fact I believe you should be using || instead of the or, due to operator precedence
      You believe wrong
      C:\>perl -MO=Deparse,-p -e"open F, $f or die $!" (open(F, $f) or die($!)); -e syntax OK C:\>perl -MO=Deparse,-p -e"open F, $f || die $!" open(F, ($f || die($!))); -e syntax OK C:\>perl -MO=Deparse,-p -e"open(F, $f) || die $!" (open(F, $f) or die($!)); -e syntax OK C:\>perl -MO=Deparse,-p -e"open(F, $f) or die $!" (open(F, $f) or die($!)); -e syntax OK