Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-22-2003, 12:04 AM   #1 (permalink)
saline
I am red.
 
saline's Avatar
 
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
saline is on a distinguished road
permissions

I just wrote a perl script that reads from text files and writes to text files within a directory. This script is accessed and interacted with via a webpage. So my question is what are the minimum permissions I need on the directory in order to get things to work properly. I feel uncomfortable using 777 but at the same time it makes sense, and works. Is there another set of permissions I could use that might keep things somehow more secure?

Am I misunderstanding how permissions work or am I just being paranoid?
__________________
http://home.cwru.edu/~cak19

It's my homepage with odd little bits of javascript.
saline is offline   Reply With Quote
Old 05-22-2003, 08:19 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
well either the 'world' can write to that directory or they can't.

a '6' would allow them to read/write and not execute.. i don't think they would need execute permission.

this is how i understand it anyway.
__________________
Mike
sde is offline   Reply With Quote
Old 05-22-2003, 08:49 AM   #3 (permalink)
saline
I am red.
 
saline's Avatar
 
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
saline is on a distinguished road
The script is inside the directory though and that needs to be executed. I'm fairly positive that the permissions need to be 777 thats why I made a whole seperate directory for this little project. Still it makes me uncomfortable.
__________________
http://home.cwru.edu/~cak19

It's my homepage with odd little bits of javascript.
saline is offline   Reply With Quote
Old 05-22-2003, 10:12 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
yes, if anything in the directory needs to execute then 7 is the setting.

you could always make the script run from that directory with only read and execute permissions .. then the files that you are writting can be in a directory beneath that one. that might be a little safer.
__________________
Mike
sde is offline   Reply With Quote
Old 05-22-2003, 09:41 PM   #5 (permalink)
bdl
Senior Contributor
 
Join Date: May 2002
Location: vta.ca.usa
Posts: 555
bdl is on a distinguished road
Just to clarify, a '7' is complete access: Read, Write, Execute. A directory has to have Read/Execute perms in order to function properly, at the least. Directories shared to other users in your same group will usually require all permissions, whereas 'world' permissions should almost always be Read/Execute only, or '5'. The appropriate directory perms for anything shared via the web should be either 775 or 755, almost never 777. If someone from the public is allowed to write to the directory and to your script, they could potentially gain access to the server, or change your script to do whatever it is they want it to do.

The way UNIX permissions work is like this:
4 = Read
2 = Write
1 = Execute

Add the values up to figure out what perms a certain file or directory should have. For example, your script should be 755, or

4+2+1 = 7 (ALL PERMS) / 4+1 = 5 (Read/Execute) / 4+1 = 5 (Read/Execute)

The first value is USER, second is GROUP, third is WORLD.

Regular files like html/php pages, images, etc. are usually 644, executables (like Perl CGI scripts) are 755, directories also 755.

Hope this makes things a little clearer for you.
bdl is offline   Reply With Quote
Old 05-23-2003, 11:28 PM   #6 (permalink)
Epsilon
Regular Contributor
 
Epsilon's Avatar
 
Join Date: Mar 2003
Location: Las Vegas, NV
Posts: 127
Epsilon is on a distinguished road
Couldn't you chown and chgrp the directory to the user and group your web server runs as (usually 'nobody')? I would think then it would work fine with permissions of 775. Then it's not world writable, but it's writable by the web server.

Or you could read/write files in a sub-directory under your script directory. That way you can make the script directory 755 and the files directory 666. There should be no reason why you have to have your script in the same directory you're writing files to.
__________________
--Epsilon--
Epsilon is offline   Reply With Quote
Old 05-24-2003, 08:55 AM   #7 (permalink)
bdl
Senior Contributor
 
Join Date: May 2002
Location: vta.ca.usa
Posts: 555
bdl is on a distinguished road
Quote:
Originally posted by Epsilon
Couldn't you chown and chgrp the directory to the user and group your web server runs as (usually 'nobody')? I would think then it would work fine with permissions of 775. Then it's not world writable, but it's writable by the web server.

Or you could read/write files in a sub-directory under your script directory. That way you can make the script directory 755 and the files directory 666. There should be no reason why you have to have your script in the same directory you're writing files to.
Valid point on the ownership; if the script and directory live under the DocumentRoot, it should already be owned by 'root' or 'httpd' or 'nobody'. That's something left to the web admin to figure out. That doesnt really matter though. As long as it's owned by a group that has permissions to write to the directory, 775 will work fine. It could be owned by the 'salinewebserverproject' group, as long as it has the right perms.

You should be able to have the script write to any directory you'd want, I would think, including '/tmp'. A directory with perms of '666' doesnt work, though. You can't enter the directory without Executable permissions, and again, that extra '2' is giving world write perms.
bdl is offline   Reply With Quote
Old 05-24-2003, 08:43 PM   #8 (permalink)
saline
I am red.
 
saline's Avatar
 
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
saline is on a distinguished road
Ahhhh

Now this is interesting alpha seems to have hit upon what I might need. I want to avoid world write but need to have the webserver be able to write.

Ok, I'll see how all of this works soon but for now, I don't know, I think I'm going back to bed.

Thanks everyone.
__________________
http://home.cwru.edu/~cak19

It's my homepage with odd little bits of javascript.
saline is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On


Similar Threads
Thread Thread Starter Forum Replies Last Post
yeah...i didn't fix it.....mySQL trouble (permissions?) trevor PHP 7 01-10-2003 08:29 PM
permissions in MySQL trevor PHP 3 01-10-2003 01:47 PM


All times are GMT -8. The time now is 02:30 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting