Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > %USERACL Is Empty?!

Reply
Thread Tools

%USERACL Is Empty?!

 
 
William
Guest
Posts: n/a
 
      12-09-2005
basically %USERACL is a hash containing the key and values read from the
following file:
UserID=LoginID:Group:Name:Emailassword:IsAdmin:S tatus:Servers:Lists:Logs:Macros:Eod:FileMgr:MacroL istnL:EditPnL:BO
AADUBLINJORDAN=AADUBLINJORDAN:BO:AADUBLINJORDAN:AA DUBLINJORDAN:XEV5iEfluxjWM:::::::::[]:[]:[]:
CHANKN=CHANKN:SYS:Kenneth Chan::XECiTZAqeyBjE:1:1 ::1:1:1:1:1:[]:[]:[]:

now for test.pl:

1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use CGI;
6
7 require "./mxrt_auth.pl";
8
9 my $query = new CGI;
10 my %USERACL = initAuthMgr($query); (see NOTE1 for initAuthMgr)
11
12 while ( (my $key, my $value) = each %USERACL) {
13 print "$key = $value\n";
14 }
15

Question #1) The following error was generated by "use warnings;"

[mk_murex@mkmxg00 /mkapp/webapps/mxrt-cgi/upload_repo 12:45:03]$ ./test.pl
> output.txt

Can't locate warnings.pm in @INC (@INC contains:
/usr/perl5/5.00503/sun4-solaris /usr/perl5/5.00503
/usr/perl5/site_perl/5.005/sun4-solaris /usr/perl5/site_perl/5.005 .) at
../test.pl line 4.
BEGIN failed--compilation aborted at ./test.pl line 4.

NOTE1: for line 10 of test.pl:

mxrt_auth.pl::initAuthMrg is defined as follows:

sub initAuthMgr {
($AUTHQ) = @_;
%AUTH_INFO = $AUTHQ->cookie('MXRT_USERACL');
foreach (keys %AUTH_INFO) {
print ($AUTH_INFO{$_})."<br>";
}
return %AUTH_INFO;
}

Question #2) nothing is printed by line 12-14 of test.pl. (Even
without the line "use warnings;")

Why???

Expected output of the following script - test.pl:
IsAdmin=1
Status=1
Servers=1
....





 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      12-09-2005
William wrote:
> basically %USERACL is a hash containing the key and values read from the
> following file:
> UserID=LoginID:Group:Name:Emailassword:IsAdmin:S tatus:Servers:Lists:Logs:Macros:Eod:FileMgr:MacroL istnL:EditPnL:BO
> AADUBLINJORDAN=AADUBLINJORDAN:BO:AADUBLINJORDAN:AA DUBLINJORDAN:XEV5iEfluxjWM:::::::::[]:[]:[]:
> CHANKN=CHANKN:SYS:Kenneth Chan::XECiTZAqeyBjE:1:1 ::1:1:1:1:1:[]:[]:[]:
>
> now for test.pl:
>
> 1 #!/usr/bin/perl
> 2


Please stop putting line-numbers in your posting. It makes it
annoyingly difficult to copy and paste your code to try to run it. If
a certain line number is relevant, specify it with a comment.

> 3 use strict;
> 4 use warnings;
> 5 use CGI;
> 6
> 7 require "./mxrt_auth.pl";
> 8
> 9 my $query = new CGI;
> 10 my %USERACL = initAuthMgr($query); (see NOTE1 for initAuthMgr)
> 11
> 12 while ( (my $key, my $value) = each %USERACL) {
> 13 print "$key = $value\n";
> 14 }
> 15
>
> Question #1) The following error was generated by "use warnings;"
>
> [mk_murex@mkmxg00 /mkapp/webapps/mxrt-cgi/upload_repo 12:45:03]$ ./test.pl
> > output.txt

> Can't locate warnings.pm in @INC (@INC contains:
> /usr/perl5/5.00503/sun4-solaris /usr/perl5/5.00503
> /usr/perl5/site_perl/5.005/sun4-solaris /usr/perl5/site_perl/5.005 .) at
> ./test.pl line 4.
> BEGIN failed--compilation aborted at ./test.pl line 4.


You have a very old version of Perl. I would suggest upgrading. If
that is not an option, remove 'use warnings;' and add ' -w' to the end
of your shebang line.

>
> NOTE1: for line 10 of test.pl:
>
> mxrt_auth.pl::initAuthMrg is defined as follows:
>
> sub initAuthMgr {
> ($AUTHQ) = @_;
> %AUTH_INFO = $AUTHQ->cookie('MXRT_USERACL');


It looks like you're not using strict in this file. Why not?

> foreach (keys %AUTH_INFO) {
> print ($AUTH_INFO{$_})."<br>";


Is this printing out what you expect it to? I'm betting not. I'm
betting you're not getting the <br> tags at all.

> }
> return %AUTH_INFO;
> }
>
> Question #2) nothing is printed by line 12-14 of test.pl. (Even
> without the line "use warnings;")
>
> Why???


Witout knowing the exact contents of %AUTH_INFO, there is no way to be
sure of the answer to that. What is the output of that function? Is
it actually printing the values of %AUTH_INFO that you expect it to?


Paul Lalli

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      12-09-2005
William <> wrote:
> basically %USERACL is a hash containing the key and values read from the
> following file:


No, it is not. Nowhere in your program do you read from the following
file and put it into that hash.

> UserID=LoginID:Group:Name:Emailassword:IsAdmin:S tatus:Servers:Lists:Log
> s:Macros:Eod:FileMgr:MacroListnL:EditPnL:BO
> AADUBLINJORDAN=AADUBLINJORDAN:BO:AADUBLINJORDAN:AA DUBLINJORDAN:XEV5iEflux
> jWM:::::::::[]:[]:[]: CHANKN=CHANKN:SYS:Kenneth
> Chan::XECiTZAqeyBjE:1:1 ::1:1:1:1:1:[]:[]:[]:
>
> Question #1) The following error was generated by "use warnings;"
>
> [mk_murex@mkmxg00 /mkapp/webapps/mxrt-cgi/upload_repo 12:45:03]$
> ./test.pl
> > output.txt

> Can't locate warnings.pm in @INC (@INC contains:
> /usr/perl5/5.00503/sun4-solaris /usr/perl5/5.00503
> /usr/perl5/site_perl/5.005/sun4-solaris /usr/perl5/site_perl/5.005 .) at
> ./test.pl line 4.
> BEGIN failed--compilation aborted at ./test.pl line 4.


You have an ancient version of perl. It does not come with the warnings.pm
module. Either upgrade perl or don't "use warnings". (Use the -w switch
instead.)

>
> NOTE1: for line 10 of test.pl:
>
> mxrt_auth.pl::initAuthMrg is defined as follows:
>
> sub initAuthMgr {
> ($AUTHQ) = @_;
> %AUTH_INFO = $AUTHQ->cookie('MXRT_USERACL');


Does $AUTHQ have a cookie named MXRT_USERACL?

> foreach (keys %AUTH_INFO) {
> print ($AUTH_INFO{$_})."<br>";
> }
> return %AUTH_INFO;
> }
>
> Question #2) nothing is printed by line 12-14 of test.pl. (Even
> without the line "use warnings;")
>
> Why???


Probably because there is nothing to print.

>
> Expected output of the following script - test.pl:
> IsAdmin=1
> Status=1
> Servers=1
> ...


I didn't expect that to be the outcome.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
William
Guest
Posts: n/a
 
      12-09-2005
On Fri, 9 Dec 2005, Paul Lalli wrote:
> William wrote:
> > basically %USERACL is a hash containing the key and values read from the
> > following file:
> > UserID=LoginID:Group:Name:Emailassword:IsAdmin:S tatus:Servers:Lists:Logs:Macros:Eod:FileMgr:MacroL istnL:EditPnL:BO
> > AADUBLINJORDAN=AADUBLINJORDAN:BO:AADUBLINJORDAN:AA DUBLINJORDAN:XEV5iEfluxjWM:::::::::[]:[]:[]:
> > CHANKN=CHANKN:SYS:Kenneth Chan::XECiTZAqeyBjE:1:1 ::1:1:1:1:1:[]:[]:[]:
> >
> > now for test.pl:
> >
> > 1 #!/usr/bin/perl
> > 2

>
> Please stop putting line-numbers in your posting. It makes it
> annoyingly difficult to copy and paste your code to try to run it. If
> a certain line number is relevant, specify it with a comment.


I have removed the line numbers and added the -w switch.

# test.pl
#!/usr/bin/perl -w

use strict;
use CGI;

require "./mxrt_auth.pl";

my $query = new CGI;
my %USERACL = initAuthMgr($query); # line 10

while ( (my $key, my $value) = each %USERACL) {
print "$key = $value\n";
}


> > NOTE1: for line 10 of test.pl:
> >
> > mxrt_auth.pl::initAuthMrg is defined as follows:
> >
> > sub initAuthMgr {
> > ($AUTHQ) = @_;
> > %AUTH_INFO = $AUTHQ->cookie('MXRT_USERACL');

>
> It looks like you're not using strict in this file. Why not?


mxrt_auth.pl was written by another programmer.
I tried adding "use strict;" and -w on the shebang line, but I got the
following error/warnings:

mxrt_auth.pl: print (...) interpreted as function at ./mxrt_auth.pl line 42.
mxrt_auth.pl: Useless use of concatenation in void context at ./mxrt_auth.pl line 44.

mxrt_auth.pl: Execution of ./mxrt_auth.pl aborted due to compilation errors.

line 42, 44, and 86 are as follows:

#-------------------------------------------------------------------------------
# This function retuns the cookie for this session (hash format)
#-------------------------------------------------------------------------------
sub initAuthMgr {
($AUTHQ) = @_;
%AUTH_INFO = $AUTHQ->cookie('MXRT_USERACL'); # line 42
foreach (keys %AUTH_INFO) {
print ($AUTH_INFO{$_})."<br>"; # line 44
}
return %AUTH_INFO;
}


#-------------------------------------------------------------------------------
# Function to load the pull-down menus
#-------------------------------------------------------------------------------
sub authLog {
my ($msg, $useracl) = @_;

if ($useracl) {
%AUTH_INFO = %$useracl;
}

open (LOG, ">>my $MXRT_LOG") || return "Failed to open access log,
$!"; # line 86

flock(LOG, 2);

my $now = `date '+%m-%d-%Y %H:%M:%S'`;
chomp $now;

print LOG $now, " | ",
$AUTH_INFO{LoginID}, " | ",
$ENV{'REMOTE_HOST'}, " | ",
$ENV{'REMOTE_ADDR'}, " | ",
$ENV{'SCRIPT_NAME'} , " on ", $ENV{'HTTP_Host'} , " | ",
$msg,
"\n";

flock(LOG, 2);

close(LOG);
}

> > foreach (keys %AUTH_INFO) {
> > print ($AUTH_INFO{$_})."<br>";

>
> Is this printing out what you expect it to? I'm betting not. I'm
> betting you're not getting the <br> tags at all.


Paul, you are right. I am not getting the <br> tags at all.
In fact, I got no output when I printed %AUTH_INFO.

Related question:
How do I check if 'MXRT_USERACL' is indeed the correct cookie name? (see
line 42 of mxrt_auth.pl as above)

>
> > }
> > return %AUTH_INFO;
> > }
> >
> > Question #2) nothing is printed by line 12-14 of test.pl. (Even
> > without the line "use warnings;")
> >
> > Why???

>
> Witout knowing the exact contents of %AUTH_INFO, there is no way to be
> sure of the answer to that. What is the output of that function? Is
> it actually printing the values of %AUTH_INFO that you expect it to?


No. No output is being printed from %AUTH_INFO.

 
Reply With Quote
 
William
Guest
Posts: n/a
 
      12-09-2005
On Fri, 9 Dec 2005 wrote:

> William <> wrote:
> > basically %USERACL is a hash containing the key and values read from the
> > following file:

>
> No, it is not. Nowhere in your program do you read from the following
> file and put it into that hash.
>
> > UserID=LoginID:Group:Name:Emailassword:IsAdmin:S tatus:Servers:Lists:Log
> > s:Macros:Eod:FileMgr:MacroListnL:EditPnL:BO
> > AADUBLINJORDAN=AADUBLINJORDAN:BO:AADUBLINJORDAN:AA DUBLINJORDAN:XEV5iEflux
> > jWM:::::::::[]:[]:[]: CHANKN=CHANKN:SYS:Kenneth
> > Chan::XECiTZAqeyBjE:1:1 ::1:1:1:1:1:[]:[]:[]:
> >
> > Question #1) The following error was generated by "use warnings;"
> >
> > [mk_murex@mkmxg00 /mkapp/webapps/mxrt-cgi/upload_repo 12:45:03]$
> > ./test.pl
> > > output.txt

> > Can't locate warnings.pm in @INC (@INC contains:
> > /usr/perl5/5.00503/sun4-solaris /usr/perl5/5.00503
> > /usr/perl5/site_perl/5.005/sun4-solaris /usr/perl5/site_perl/5.005 .) at
> > ./test.pl line 4.
> > BEGIN failed--compilation aborted at ./test.pl line 4.

>

Xho wrote:
> You have an ancient version of perl. It does not come with the warnings.pm
> module. Either upgrade perl or don't "use warnings". (Use the -w switch
> instead.)
>


I have removed "use warnings" and put
#!/usr/bin/perl -w

on line 1 of mxrt_auth.pl instead.

> > NOTE1: for line 10 of test.pl:
> >
> > mxrt_auth.pl::initAuthMrg is defined as follows:
> >
> > sub initAuthMgr {
> > ($AUTHQ) = @_;
> > %AUTH_INFO = $AUTHQ->cookie('MXRT_USERACL');

>
> Does $AUTHQ have a cookie named MXRT_USERACL?


KEY QUESTION:
How do I obtain a list of cookies for $AUTHQ?


>
> > foreach (keys %AUTH_INFO) {
> > print ($AUTH_INFO{$_})."<br>";
> > }
> > return %AUTH_INFO;
> > }
> >
> > Question #2) nothing is printed by line 12-14 of test.pl. (Even
> > without the line "use warnings;")
> >
> > Why???

>
> Probably because there is nothing to print.


I agree. I just found out that %AUTH_INFO has 0 keys.

my check:

sub initAuthMgr {
($AUTHQ) = @_;
%AUTH_INFO = $AUTHQ->cookie('MXRT_USERACL');
my $num_keys = keys %AUTH_INFO;
print $num_keys; # problem found - %AUTH_INFO has 0 keys
foreach (keys %AUTH_INFO) {
print ($AUTH_INFO{$_})."<br>";
}
return %AUTH_INFO;
}

> > Expected output of the following script - test.pl:
> > IsAdmin=1
> > Status=1
> > Servers=1
> > ...

>
> I didn't expect that to be the outcome.

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      12-09-2005
William wrote:
> On Fri, 9 Dec 2005, Paul Lalli wrote:
> > Please stop putting line-numbers in your posting. It makes it
> > annoyingly difficult to copy and paste your code to try to run it. If
> > a certain line number is relevant, specify it with a comment.

>
> I have removed the line numbers and added the -w switch.


Thank you.

> > > NOTE1: for line 10 of test.pl:
> > >
> > > mxrt_auth.pl::initAuthMrg is defined as follows:
> > >
> > > sub initAuthMgr {
> > > ($AUTHQ) = @_;
> > > %AUTH_INFO = $AUTHQ->cookie('MXRT_USERACL');

> >
> > It looks like you're not using strict in this file. Why not?

>
> mxrt_auth.pl was written by another programmer.
> I tried adding "use strict;" and -w on the shebang line, but I got the
> following error/warnings:


No, not "but you got", "*AND* you got". That's exactly why we use
strict and -w, so Perl will tell you when you do something wrong.

> mxrt_auth.pl: print (...) interpreted as function at ./mxrt_auth.pl line 42.
> mxrt_auth.pl: Useless use of concatenation in void context at ./mxrt_auth.pl line 44.
>
> mxrt_auth.pl: Execution of ./mxrt_auth.pl aborted due to compilation errors.


You skipped something. Neither of the first two outputs are errors,
they're both warnings. They wouldn't have caused the script to abort
due to compilation errors.

> line 42, 44, and 86 are as follows:
>
> #-------------------------------------------------------------------------------
> # This function retuns the cookie for this session (hash format)
> #-------------------------------------------------------------------------------
> sub initAuthMgr {
> ($AUTHQ) = @_;
> %AUTH_INFO = $AUTHQ->cookie('MXRT_USERACL'); # line 42
> foreach (keys %AUTH_INFO) {
> print ($AUTH_INFO{$_})."<br>"; # line 44


If those warnings are both correct, there's something screwy going on.
Both warnings are referring to this line. By using the parentheses,
the arguments to print stop after the first closing parenthesis. This
should be:
print "$AUTH_INFO{$_}<br>";

> }
> return %AUTH_INFO;
> }
>
>
> #-------------------------------------------------------------------------------
> # Function to load the pull-down menus
> #-------------------------------------------------------------------------------
> sub authLog {
> my ($msg, $useracl) = @_;
>
> if ($useracl) {
> %AUTH_INFO = %$useracl;
> }
>
> open (LOG, ">>my $MXRT_LOG") || return "Failed to open access log,
> $!"; # line 86


You seem to be implying this line gave you an error. It would be nice
to see what that error message was.

> > > foreach (keys %AUTH_INFO) {
> > > print ($AUTH_INFO{$_})."<br>";

> >
> > Is this printing out what you expect it to? I'm betting not. I'm
> > betting you're not getting the <br> tags at all.

>
> Paul, you are right. I am not getting the <br> tags at all.


Well, that's because of the parentheses error I mentioned above.

> In fact, I got no output when I printed %AUTH_INFO.


But that's because %AUTH_INFO is empty.

> Related question:
> How do I check if 'MXRT_USERACL' is indeed the correct cookie name? (see
> line 42 of mxrt_auth.pl as above)


By checking the return value of the cookie method. If what it returns
is not defined, you gave an invalid cookie name.


> > Witout knowing the exact contents of %AUTH_INFO, there is no way to be
> > sure of the answer to that. What is the output of that function? Is
> > it actually printing the values of %AUTH_INFO that you expect it to?

>
> No. No output is being printed from %AUTH_INFO.


So %AUTH_INFO is empty, which in turn means that the cookie was not
valid. Fix your cookie name.

Paul Lalli

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      12-09-2005
William wrote:
> KEY QUESTION:
> How do I obtain a list of cookies for $AUTHQ?


It's not documented, but looking at the source code, it looks like you
should be able to do:
my @cookies = $AUTHQ->cookie();
to get a list of all the names of the cookies being sent to this
script.

Paul Lalli

 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      12-09-2005
William <> wrote:
> >
> > Does $AUTHQ have a cookie named MXRT_USERACL?

>
> KEY QUESTION:
> How do I obtain a list of cookies for $AUTHQ?


By analogy with the param() method, I assumed that calling cookie() with
no parameters gives you a list of cookie names. An experiment showed this
to be true, but it wasn't documented in the POD for CGI.

However, cookies have to be set by something. Presumably, you have control
or at least knowledge of the thing that sets those cookies. So the best
way to figure out what a cookie is called is probably to look in the code
that sets it, rather than by introspection of the submitted request.


Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      12-09-2005
xhos...@gmail.com wrote:
> By analogy with the param() method, I assumed that calling cookie() with
> no parameters gives you a list of cookie names. An experiment showed this
> to be true, but it wasn't documented in the POD for CGI.


Xho, as you can see in my reply to William, I believed this to be true
as well. However, I did find one very small reference to this ability.
In the description of raw_cookie(), we find this tiny snippet:

"You can use the regular cookie() method to get the names"

So, I don't think it's fair to say that this ability is not documented.
Just that it's not *well* documented...

Paul Lalli

 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      12-09-2005
"Paul Lalli" <> wrote:
> xhos...@gmail.com wrote:
> > By analogy with the param() method, I assumed that calling cookie()
> > with no parameters gives you a list of cookie names. An experiment
> > showed this to be true, but it wasn't documented in the POD for CGI.

>
> Xho, as you can see in my reply to William, I believed this to be true
> as well. However, I did find one very small reference to this ability.
> In the description of raw_cookie(), we find this tiny snippet:
>
> "You can use the regular cookie() method to get the names"
>
> So, I don't think it's fair to say that this ability is not documented.
> Just that it's not *well* documented...


OK, I stand corrected.

Thanks,

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57