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

Maintaining of config file

by Eureka_sg (Monk)
on Feb 27, 2001 at 08:39 UTC ( [id://61033]=perlquestion: print w/replies, xml ) Need Help??

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

I have a web based interface used to access resources from the web server. I am using a config. file to store certain parameters such as target IP.The config. file is something like this:

212.232.434 21323 434.434.545

The parameters will be read from and used in another web page. However, writing of the file from web causes its access to change to 644(from original 666), and so subsequent writing of the file is no longer permitted.

Is there any way around this problem? I can't use chmod since the web user is anonymous.

Thanks

Replies are listed 'Best First'.
Re: Maintaining of config file
by unixwzrd (Beadle) on Feb 27, 2001 at 08:47 UTC
    Your web server is probably starting up with a umask of 022. The simplest solution is to set the correct umask in the web server startup script if you have access to it. This may have other security implications at your site, so be careful.

    Update: I did say something about using "chmod" in your script, but you say it doesn't work. That doesn't make sense. If you can create the file, you should be able to change the permissions on it since you own it.

    Mike - mps@discomsys.com

    "The two most common elements in the universe are hydrogen... and stupidity."
    Harlan Ellison

Re: Maintaining of config file
by dws (Chancellor) on Feb 27, 2001 at 10:12 UTC
    Are you sure you can't use chmod()?

    Who ends up owning the files that your CGI writes? If it's the anonymous user, then you certainly can use chmod(). Several of my CGIs do.

      If changing permissions from 666 to 644 stops the script from writing to the file a second time then it has been created with the wrong user name. This can give you all sorts of implementation headaches down the line, as you are starting to see now. The normal user, for apache, is user nobody. I would suggest you use that user id to create all CGI record files that are to be written to or, a more robust idea, do not create these files at all. Instead allow the script to create the files it writes to if they go missing. This allows for fun things like files wandering off (it can happen) and makes your script more portable.

      $japh->{'Caillte'} = $me;

Re: Maintaining of config file
by wardk (Deacon) on Feb 27, 2001 at 19:27 UTC

    If the file is "permanent" and you own it, change ownership (chown) of this file to the web user...("nobody", "netscape"), then as owner, the web user should have no problems. I would also have yourself added to the group the webuser resides in so that you can manipulate the file if need be.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-25 19:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found