CHMOD script

CHMOD script

am 09.10.2004 23:51:51 von 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

Re: CHMOD script

am 10.10.2004 01:21:44 von Gunnar Hjalmarsson

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

Re: CHMOD script

am 10.10.2004 02:12:42 von Peter Sundstrom

"siggy" wrote in message
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

Re: CHMOD script

am 10.10.2004 09:26:08 von webmaster

In message <2sra42F1mlv59U1@uni-berlin.de>
Gunnar Hjalmarsson 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

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 |
========================================================

Re: CHMOD script

am 10.10.2004 22:13:27 von Matt Garrish

"Kendall K. Down" wrote in message
news:758092fb4c.diggings@diggingsonline.com...
> In message <2sra42F1mlv59U1@uni-berlin.de>
> Gunnar Hjalmarsson 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
>
> 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

Re: CHMOD script

am 10.10.2004 22:18:49 von Justin C

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.

Re: CHMOD script

am 10.10.2004 23:02:05 von Gunnar Hjalmarsson

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

Re: CHMOD script

am 11.10.2004 08:33:57 von webmaster

In message
"Matt Garrish" wrote:

> 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 |
========================================================

Re: CHMOD script

am 11.10.2004 08:38:06 von webmaster

In message <2stmfmF1p25fcU1@uni-berlin.de>
Gunnar Hjalmarsson wrote:

> 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 |
========================================================

Re: CHMOD script

am 11.10.2004 19:52:29 von Joe Smith

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

Re: CHMOD script

am 12.10.2004 15:07:51 von Matt Garrish

"Kendall K. Down" wrote in message
news:788f11fc4c.diggings@diggingsonline.com...
> In message
> "Matt Garrish" wrote:
>
>> 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

Re: CHMOD script

am 12.10.2004 19:48:10 von webmaster

In message
"Matt Garrish" wrote:

> 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 |
========================================================

Re: CHMOD script

am 13.10.2004 11:14:05 von Tintin

"Kendall K. Down" wrote in message
news:481fd3fc4c.diggings@diggingsonline.com...
> In message
> "Matt Garrish" wrote:
>
>> 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.

Re: CHMOD script

am 13.10.2004 13:04:38 von webmaster

In message <2t49t0F1qscb5U1@uni-berlin.de>
"Tintin" wrote:

> 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 |
========================================================

Re: CHMOD script

am 14.10.2004 15:20:56 von Matt Garrish

"Kendall K. Down" wrote in message
news:af0332fd4c.diggings@diggingsonline.com...
> In message <2t49t0F1qscb5U1@uni-berlin.de>
> "Tintin" wrote:
>
>> 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

Re: CHMOD script

am 14.10.2004 21:59:49 von webmaster

In message
"Matt Garrish" wrote:

> 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 |
========================================================