Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

umask

by chorg (Monk)
on Jul 24, 2001 at 18:51 UTC ( [id://99352]=perlquestion: print w/replies, xml ) Need Help??

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

I'm creating dbm files using DB_File -- I keep on having to change the permissions on them because the web server can't modify them. I'd like to set the umask in the program, so that it will just work .... How do I do this ? I am kinda confused about the bitwise operators....
_______________________________________________
"Intelligence is a tool used achieve goals, however goals are not always chosen wisely..."

Replies are listed 'Best First'.
Re: umask
by nardo (Friar) on Jul 24, 2001 at 19:06 UTC
    You can set the permissions with your fifth argument to tie when creating the database:
    tie(%database, 'DB_File', $path_to_db, O_RDWR | O_CREAT, $permissions); Alternately, if you really wanted to use umask, here's a brief explanation. Umask is basically the bits not to set when a file or directory is created, files will be 666 and directories 777 with the umask bits removed, thus a umask of 002 will make files 664 and directories 775 and a umask of 010 will make files 666 (because the group x bit isn't set, it isn't modified) and directories 767 (a umask of 010 isn't really useful, it was just used as an example). And always remember to begin your permissions with a 0 to get them in octal (0644, 0777, etc.)
Re: umask
by maverick (Curate) on Jul 24, 2001 at 19:08 UTC
    The third parameter to dbmopen is the permission mask for the file. (from 'man perlfunc')
    use DB_File; dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db",0666) or die "Can't open netscape history file: $!";
    This is the mode bits that are not set if it is created by the dbmopen. ie. All the mode bits are set to 1 except those listed here. Once set, either by the create or by you chmod-ing them, the permissions shouldn't change.Update nardo's bit mask explination is better than mine.

    What you should probably consider doing is making the files owned by the user that the webserver runs as, which is usually nobody or httpd. That way you could make the files only readable / writable by the webserver (mode 0600).

    If your code is creating the empty dbm files, then the directory that they are being created in must also be writable by the webserver. Personally, I'd make a directory somewhere (not under the CGI, or HTML tree) that was owned and only accessable by the webserver to put your dbms in.

    /\/\averick

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://99352]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-24 16:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found