CHMOD script
am 09.10.2004 23:51:51 von siggyis there such a thing as a perl / cgi
script that will do a CHMOD on a
specified file - in a specified directory.....
siggy
is there such a thing as a perl / cgi
script that will do a CHMOD on a
specified file - in a specified directory.....
siggy
siggy wrote:
> is there such a thing as a perl / cgi
> script that will do a CHMOD on a
> specified file - in a specified directory.....
Don't know, but there is a Perl function that does just that.
perldoc -f chmod
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
"siggy"
news:41685d72$1@news.accesscomm.ca...
> is there such a thing as a perl / cgi
> script that will do a CHMOD on a
> specified file - in a specified directory.....
Congratulations!! You've earned an entry in the Perl SAQ.
http://www.ginini.com/perlsaq.html
In message <2sra42F1mlv59U1@uni-berlin.de>
Gunnar Hjalmarsson
> > is there such a thing as a perl / cgi
> > script that will do a CHMOD on a
> > specified file - in a specified directory.....
> Don't know, but there is a Perl function that does just that.
> perldoc -f chmod
It doesn't, you know.
I wrote a Perl script to create a directory and install a file in it which
another user could access. I was carefull to chmod appropriately. Both
directory and file are now sitting in my cgi-bin: the user can't access
them, I can't delete them.
The problem, apparently, is that I am not the "owner" of the file/directory.
If anyone has a solution to the problem, I'm eager to hear from them.
Ken Down
--
================ ARCHAEOLOGICAL DIGGINGS ===============
| Australia's premiere archaeological magazine |
| http://www.diggingsonline.com |
========================================================
"Kendall K. Down"
news:758092fb4c.diggings@diggingsonline.com...
> In message <2sra42F1mlv59U1@uni-berlin.de>
> Gunnar Hjalmarsson
>
>> > is there such a thing as a perl / cgi
>> > script that will do a CHMOD on a
>> > specified file - in a specified directory.....
>
>> Don't know, but there is a Perl function that does just that.
>> perldoc -f chmod
>
> It doesn't, you know.
>
It does. You seem to have the common problem of not understanding how
permissions work in the CGI environment, though. Just because a script was
written by you does not mean it will be run as you by the server. You need
to change the way you set the permissions accordingly.
Matt
In article <2srd1vF1iiooeU1@uni-berlin.de>, Peter Sundstrom wrote:
snipped to save someones embarassment
> Congratulations!! You've earned an entry in the Perl SAQ.
>
> http://www.ginini.com/perlsaq.html
I've had to bookmark that it's so much fun. Damn glad I didn't make the
list 'cos I know I've asked some damned dum questions!
Though the Llama is a great teacher it doesn't go far enough, it doesn't
teach us the value of perldoc - or it doesn't go far enough in showing
the path!
Maybe Randal and Tom can rectify this in the next version?!
Justin.
--
Justin C, by the sea.
Kendall K. Down wrote:
> I wrote a Perl script to create a directory and install a file in
> it which another user could access. I was carefull to chmod
> appropriately. Both directory and file are now sitting in my
> cgi-bin: the user can't access them, I can't delete them.
Then you did apparently *not* chmod them carefully.
> The problem, apparently, is that I am not the "owner" of the
> file/directory.
In that case, your Perl script is a CGI script, and CGI is run as some
other user but you.
> If anyone has a solution to the problem, I'm eager to hear from
> them.
Read up about the Unix/Linux file permissions system. You can't change
permissions of that directory and file e.g. via your FTP client, but
you can have your CGI script do it using the Perl chmod() function. If
you e.g. want anybody being able to read the file, you can set the
directory permission 755 and file permission 644. You can also have
the CGI script delete the file, since the user CGI is run as owns the
directory. The directory itself can well be deleted via your FTP
client, since *you* (I assume) own the directory in which the script
generated directory is located.
HTH
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
In message
"Matt Garrish"
> It does. You seem to have the common problem of not understanding how
> permissions work in the CGI environment, though. Just because a script was
> written by you does not mean it will be run as you by the server. You need
> to change the way you set the permissions accordingly.
That is entirely possible; I am a Perl newbie. So *please*, tell me what to
do!
Ken Down
--
================ ARCHAEOLOGICAL DIGGINGS ===============
| Australia's premiere archaeological magazine |
| http://www.diggingsonline.com |
========================================================
In message <2stmfmF1p25fcU1@uni-berlin.de>
Gunnar Hjalmarsson
> In that case, your Perl script is a CGI script, and CGI is run as some
> other user but you.
Yes, it is and yes, I have already identified that as the problem.
> Read up about the Unix/Linux file permissions system. You can't change
> permissions of that directory and file e.g. via your FTP client, but
> you can have your CGI script do it using the Perl chmod() function.
I used chmod() immediately after creating the file.
> If
> you e.g. want anybody being able to read the file, you can set the
> directory permission 755 and file permission 644.
Hmmmm. I set both to 766 (if I recall correctly - it was a couple of months
ago). I'll check up though and write another script to try and change the
permissions as you suggest.
> You can also have
> the CGI script delete the file, since the user CGI is run as owns the
> directory. The directory itself can well be deleted via your FTP
> client, since *you* (I assume) own the directory in which the script
> generated directory is located.
Yes, it is my private cgi-bin.
Thanks for your help.
Ken Down
--
================ ARCHAEOLOGICAL DIGGINGS ===============
| Australia's premiere archaeological magazine |
| http://www.diggingsonline.com |
========================================================
Kendall K. Down wrote:
>>If
>>you e.g. want anybody being able to read the file, you can set the
>>directory permission 755 and file permission 644.
>
> Hmmmm. I set both to 766 (if I recall correctly - it was a couple of months
> ago). I'll check up though and write another script to try and change the
> permissions as you suggest.
Keep in mind that 755 and 644 (as decimal numbers) do not work:
chmod 644,$filename; # Wrong
You need 0755 or 0644:
chmod 0644,$filename or warn "Can't chmod $filename: $!";
The leading zero tells perl that the literal that follows is a
number in octal notation, which is what is needed for chmod().
-Joe
"Kendall K. Down"
news:788f11fc4c.diggings@diggingsonline.com...
> In message
> "Matt Garrish"
>
>> It does. You seem to have the common problem of not understanding how
>> permissions work in the CGI environment, though. Just because a script
>> was
>> written by you does not mean it will be run as you by the server. You
>> need
>> to change the way you set the permissions accordingly.
>
> That is entirely possible; I am a Perl newbie. So *please*, tell me what
> to
> do!
>
You need to post the code you used to set the permissions the first time so
we can see what you did do. Otherwise, it'd just be speculation as to what
you've done wrong. See Joe's post for one likely cause, though.
Matt
In message
"Matt Garrish"
> You need to post the code you used to set the permissions the first time so
> we can see what you did do. Otherwise, it'd just be speculation as to what
> you've done wrong. See Joe's post for one likely cause, though.
Your wish is my command:
mkdir $temp, 0766 or die "can't mkdir $temp: $!";
chmod(0766, $outname);
There is a lot more to the script, obviously, but it all seems to work - the
directory and file are created and appear to contain all the right things.
It's just the permissions that don't work.
Ken Down
--
================ ARCHAEOLOGICAL DIGGINGS ===============
| Australia's premiere archaeological magazine |
| http://www.diggingsonline.com |
========================================================
"Kendall K. Down"
news:481fd3fc4c.diggings@diggingsonline.com...
> In message
> "Matt Garrish"
>
>> You need to post the code you used to set the permissions the first time
>> so
>> we can see what you did do. Otherwise, it'd just be speculation as to
>> what
>> you've done wrong. See Joe's post for one likely cause, though.
>
> Your wish is my command:
>
> mkdir $temp, 0766 or die "can't mkdir $temp: $!";
Either you haven't read the docs for the mkdir function, or you
misunderstand what a 'mask' is.
Suggest you do
man umask
to learn more about permissions and masks.
BTW, assuming you really did want to set permissions to 766 on a directory,
then that is not a very useful permission. A directory needs execute
permission set to be useful.
In message <2t49t0F1qscb5U1@uni-berlin.de>
"Tintin"
> Either you haven't read the docs for the mkdir function, or you
> misunderstand what a 'mask' is.
I did read them (at least, I read the documentation that came with OptiPerl,
I don't know if that is the same thing). It is entirely possible that I
misunderstood them or that I do not understand what a mask is - though I
have no problems with the Linux file permission.
> BTW, assuming you really did want to set permissions to 766 on a directory,
> then that is not a very useful permission. A directory needs execute
> permission set to be useful.
I was not aware of that. I thought Read and Write were all that was
necessary.
Ken Down
--
================ ARCHAEOLOGICAL DIGGINGS ===============
| Australia's premiere archaeological magazine |
| http://www.diggingsonline.com |
========================================================
"Kendall K. Down"
news:af0332fd4c.diggings@diggingsonline.com...
> In message <2t49t0F1qscb5U1@uni-berlin.de>
> "Tintin"
>
>> Either you haven't read the docs for the mkdir function, or you
>> misunderstand what a 'mask' is.
>
> I did read them (at least, I read the documentation that came with
> OptiPerl,
> I don't know if that is the same thing). It is entirely possible that I
> misunderstood them or that I do not understand what a mask is - though I
> have no problems with the Linux file permission.
>
The nobody user your scripts run as often has a restrictive umask of 022 in
your cgi-bin. Read the documentation on umask for why that is important.
Matt
In message
"Matt Garrish"
> The nobody user your scripts run as often has a restrictive umask of 022 in
> your cgi-bin. Read the documentation on umask for why that is important.
Ooooer! Thanks for the tip.
Ken Down
--
================ ARCHAEOLOGICAL DIGGINGS ===============
| Australia's premiere archaeological magazine |
| http://www.diggingsonline.com |
========================================================