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

I tried making a simple mailing list, well it's just a form that accepts data..but something is wrong. I get the error Cannot open file 'mailinglist.db': Permission denied. I don't see how the permission can be denied when I'm trying to set the permissions with the script. The mailinglist.db does NOT exist right now, it should as soon as the first piece of data gets stored.

Any suggestions?

#!/usr/bin/perl -w use strict; use warnings; use POSIX; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use DB_File; my %list; my $list = "mailinglist.db"; # location of database tie %list, "DB_File", "$list", O_CREAT|O_RDWR, 0644, or die "Cannot open file '$list': $!\n"; print header, start_html; my $name = param('name'); my $email = param('email'); ## Get the user information if (param) { if ($name) { if ($email) { if (exists $list{$email}) { print "<b> Email address was already found in the database. Action ca +ncelled.</b>"; } else { $list{$email} = $name; print "Thank you, $name. You will be notified of site news and websit +e updates."; } } } } foreach (keys %list) { print "$_ = > $list{$_}<br>"; }

Replies are listed 'Best First'.
Re: DB can't open
by Abigail-II (Bishop) on Dec 05, 2003 at 17:04 UTC
    The permissions will only be set if the file doesn't exist yet (and hence gets created). But then you still need write permission in the directory, or else you get a permission denied error. Furthermore, if the file already exists, and you don't have the appropriate permissions, you get a permission denied error as well.

    Abigail

Re: DB can't open
by traxlog (Scribe) on Dec 05, 2003 at 19:51 UTC
    Make sure you also give the full (unix) path to the db - it doesn't assume it's in the same directory.
Re: DB can't open
by Massyn (Hermit) on Dec 06, 2003 at 08:11 UTC

    I'll put my money on your web server security... My guess is you're using Apache, running as user 'nobody'. This user has less privileges than a cockroach, so it's my guess that this account can not access your data file.

    Play around with giving the nobody user access to this file. You could also in some cases log on as root and then su as nobody, to test the securities. Unix command like chown and chmod will be your friend to solve this one.

    Cheers

    #!/massyn.pl

    Don't -- me without telling me why. If you asked a stupid question, I wouldn't down vote you.