FutureQuest, Inc. FutureQuest, Inc. FutureQuest, Inc.

FutureQuest, Inc.
Go Back   FutureQuest Community > General Site Owner Support (All may read/respond) > PHP, Perl, Python and/or MySQL
User Name
Password  Lost PW

Reply
 
Thread Tools Search this Thread Display Modes
Old 08-17-2005, 04:55 AM   Postid: 137300
Wassercrats
Site Owner
 
Wassercrats's Avatar

Forum Notability:
291 pts: An Honor To Be Around
[Post Feedback]
 
Join Date: Nov 2001
Posts: 7,100
Setting default permissions with umask

I think I've used chmod in the past to change file permission with a Perl script, but I forgot about that and the first function I found was umask. Shouldn't the following code save the file with permissions of 755? I tried "umask 022" too, but it didn't work. The file gets saved with 644 permissions.

umask 0022;
open(LOG, ">$SSI_File");
print LOG $SSI_Code;
close(LOG);
Wassercrats is offline   Reply With Quote
Old 08-17-2005, 10:38 AM   Postid: 137306
 Kevin
Systems Administrator
 
Kevin's Avatar
 
Join Date: Aug 2001
Location: Orlando, FL
Posts: 2,554
Re: Setting default permissions with umask

The umask in UNIX has to work with both files and directories so a mask of 022 would set files to 644 and directories to 755. In general you wouldn't want to make all files 755 anyways.
__________________
Kevin
Kevin is offline   Reply With Quote
Old 08-17-2005, 03:13 PM   Postid: 137323
Wassercrats
Site Owner
 
Wassercrats's Avatar

Forum Notability:
291 pts: An Honor To Be Around
[Post Feedback]
 
Join Date: Nov 2001
Posts: 7,100
Re: Setting default permissions with umask

I tried "umask 0133" just now and the file is still saved as 644. I think I'm not getting it. Are the Unix settings overriding my Perl umask settings? Do I have to create a directory along with a file in order for my Perl umask to have an affect?
Wassercrats is offline   Reply With Quote
Old 08-17-2005, 05:34 PM   Postid: 137336
 Kevin
Systems Administrator
 
Kevin's Avatar
 
Join Date: Aug 2001
Location: Orlando, FL
Posts: 2,554
Re: Setting default permissions with umask

The problem is that directories and files work a bit differently.
umask 0022 will set files to 0644 and directories to 0755 which is what you want.
umask 0133 will also set files to 0644 but it will also set directories to 0644 which makes them pretty useless.

As far as I know there is NO umask setting that will set the execute bit on a file as UNIX is automaticly adjusting the umask on the fly to support both directories with +x and files without +x.
__________________
Kevin
Kevin is offline   Reply With Quote
Old 08-17-2005, 05:46 PM   Postid: 137337
Wassercrats
Site Owner
 
Wassercrats's Avatar

Forum Notability:
291 pts: An Honor To Be Around
[Post Feedback]
 
Join Date: Nov 2001
Posts: 7,100
Re: Setting default permissions with umask

Quote:
umask 0022 will set files to 0644 and directories to 0755 which is what you want.
I'm creating a file in the cgi-bin and it needs to be 755.
Quote:
As far as I know there is NO umask setting that will set the execute bit on a file as UNIX is automaticly adjusting the umask on the fly to support both directories with +x and files without +x.
Oh. Well, chmod worked, so I'll stick with that. Thanks.
Wassercrats is offline   Reply With Quote
Old 08-17-2005, 05:50 PM   Postid: 137339
 Kevin
Systems Administrator
 
Kevin's Avatar
 
Join Date: Aug 2001
Location: Orlando, FL
Posts: 2,554
Re: Setting default permissions with umask

Right but it isn't normal to want to set ALL files to executable so the standard in UNIX is to set all files to non-executable and then you have to chmod only the ones you want to be +x.

If I designed UNIX I would have made seperate fmask and dmask settings for files and directories and if you set umask you would set both to values that would match up.
IOW umask 022 would set fmask to 133 and dmask to 022 but you could still set them independantly if needed.

Of course if I designed UNIX I would be much older
__________________
Kevin
Kevin is offline   Reply With Quote
Old 08-17-2005, 06:02 PM   Postid: 137340
Wassercrats
Site Owner
 
Wassercrats's Avatar

Forum Notability:
291 pts: An Honor To Be Around
[Post Feedback]
 
Join Date: Nov 2001
Posts: 7,100
Re: Setting default permissions with umask

I was thinking that the base value that gets masked when using umask in Perl is always 777. I don't like that I have to create a file with incorrect permissions and then chmod to fix it. It doesn't really matter though. At least it starts out overly restrictive before using chmod instead of overly permissive.
Wassercrats is offline   Reply With Quote
Old 08-17-2005, 06:08 PM   Postid: 137341
Wassercrats
Site Owner
 
Wassercrats's Avatar

Forum Notability:
291 pts: An Honor To Be Around
[Post Feedback]
 
Join Date: Nov 2001
Posts: 7,100
Re: Setting default permissions with umask

If Unix is adusting the umask on the fly, then the base value wouldn't matter anyway. Well, I know what works so I won't worry about what doesn't.
Wassercrats is offline   Reply With Quote
Old 08-17-2005, 06:16 PM   Postid: 137342
 Bruce
Developer
 
Bruce's Avatar
 
Join Date: Apr 2001
Location: Saskatoon, SK, Canada
Posts: 1,199
Re: Setting default permissions with umask

Quote:
Originally Posted by Wassercrats
I was thinking that the base value that gets masked when using umask in Perl is always 777.
Pretty near every UNIX program that I have seen (or written) all default to using 0666 for files and 0777 for directories. The reason being that setting the execute bit on any file automatically turns it into a script which, by default, would get interpreted by /bin/sh if it was ever executed. This can lead to all kinds of nasty effects.

If you really want to create an executable file, you have three choices:
1. use chmod after creating the file,
2. use sysopen, which is a somewhat more obscure interface, or
3. use fchmod on the open file handle.
I have searched, but haven't figured out how to get fchmod to work in Perl, unfortunately.
__________________
Bruce Guenter, FutureQuest http://www.FutureQuest.net/ http://untroubled.org/
Bruce is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 visitors)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 03:18 AM.


Running on vBulletin®
Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.
Hosted & Administrated by FutureQuest, Inc.
Images & content copyright © 1998-2014 FutureQuest, Inc.
FutureQuest, Inc.