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

A program to identify the players:

$obj->{'q'} isa CGI
$obj->{'cfg'} isa Config::Simple

This is from a test script in my current project:

$obj->{'q'}->param('username','admin'); $obj->{'q'}->param('password','secret'); diag('The value starts as: ' . $obj->{'cfg'}->param("paths.sessions")) +; $obj->{'cfg'}->param("paths.sessions",'/home/hesco/sandbox/My-Project/ +t/sessions'); diag('The value ends as: ' . $obj->{'cfg'}->param("paths.sessions")); $obj->_Authenticate(); is($obj->{'s'}->param("~logged-in"),1,'We have successfully logged in. +');
When run as root, it works fine, except that it puts the session file in /tmp/sessions, as my /etc/MyProject/config.ini file tells it to. However, when I run this as an unprivileged user, I get the error which follows:

# The value starts as: /tmp/sessions # The value ends as: /home/hesco/sandbox/My-Project/t/sessions Died attempting to flush session parameters to the file store: Permiss +ion denied at lib/My/Project.pm line 380.
But it would seem that my hesco user ought to be able to write to the session file store, anyway.

$ sudo ls /tmp -lht drw-rw-r-- 2 hesco www-data 104 2009-08-20 01:09 sessions
The whole point of the $obj->{'cfg'}->param() call above is to redirect that session creation back into my home directory when this is run from a command line by me, instead of by the apache server.

Why would my Test::More::diag() tell me I have successfully reset my sessions folder, but that new value becomes unavailable to my $obj->_Authenticate() call?

How can I test this?

-- Hugh

if( $lal && $lol ) { $life++; }

Replies are listed 'Best First'.
Re: Config::Simple value lost on method call, huh???
by jethro (Monsignor) on Aug 20, 2009 at 08:14 UTC
    You showed us /tmp/sessions, but what about /home/hesco/sandbox/My-Project/t/sessions? Does this path exist at all (check by copy-pasting the path from your script output, don't try to type in what you think it should be)? Does hesco have write permissions in there?
Re: Config::Simple value lost on method call, huh???
by Anonymous Monk on Aug 20, 2009 at 06:31 UTC
    How can I test this?

    Write code :) you know, a complete self-contained example that demonstrates the problem... and use ->errstr() not $!

Re: Config::Simple value lost on method call, huh???
by james2vegas (Chaplain) on Aug 20, 2009 at 08:39 UTC
    are those really the permissions for sessions? A directory needs 'x' to allow searching in it. Also, yeah, I think a little more detail (running code) would be more helpful for us to help you.

      > A directory needs 'x' to allow searching in it.

      Nope. A directory needs 'r' to allow searching in it. A directory needs 'x' to allow chdir into it, and 'w' to create an entry in it.

      It helps to think of a directory as a structured file (which in <update type="add"> classical </update> unix semantics, it is). Searching a directory is reading it ('r' permissions); changing directories, <update type="add">and accessing or changing the files pointed to by the directory entries</update> is executing it ('x' permissions); and modifying the directory (adding or removing entries in the structured file) is writing it ('w' permissions).

      Update: So, if you want to add a new file, you need 'wx' permissions, reading the file names needs 'r', reading the file names and getting to the file itself (done by ls -l - it reads the inode) needs 'rx'. Directories act funny unless you understand what part is managed by each permission bit. Even then it can still be kindof funny.

      Updates: Slight modifications after validation

      --MidLifeXis

      The tomes, scrolls etc are dusty because they reside in a dusty old house, not because they're unused. --hangon in this post

        you don't need 'rx' to list the files in a directory, just 'r', but you do need 'x' to read into the files (contents, inodes, mtime, etc) if you know the names (which doesn't require 'r' if you know the file name by some other means). There was an example here, but the parent of this note made it redundant.