Home > Archive > PERL Programming > October 2004 > CHMOD script
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| is there such a thing as a perl / cgi
script that will do a CHMOD on a
specified file - in a specified directory.....
siggy
| |
| Gunnar Hjalmarsson 2004-10-09, 9:59 pm |
| 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
| |
| Peter Sundstrom 2004-10-09, 9:59 pm |
|
"siggy" <this_is_me_sigma@accesscomm.com> 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
| |
| Kendall K. Down 2004-10-10, 3:56 pm |
| In message <2sra42F1mlv59U1@uni-berlin.de>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
[color=darkred]
> 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 |
========================================
================
| |
| Matt Garrish 2004-10-10, 8:55 pm |
|
"Kendall K. Down" <webmaster@diggingsonline.com> wrote in message
news:758092fb4c.diggings@diggingsonline.com...
> In message <2sra42F1mlv59U1@uni-berlin.de>
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>
>
>
> 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
| |
| Gunnar Hjalmarsson 2004-10-10, 8:55 pm |
| 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
| |
| Justin C 2004-10-11, 3:55 am |
| 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 2004-10-11, 3:55 pm |
| In message <CJgad.10308$3C6.248852@news20.bellglobal.com>
"Matt Garrish" <matthew.garrish@sympatico.ca> 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 |
========================================
================
| |
| Kendall K. Down 2004-10-11, 3:55 pm |
| In message <2stmfmF1p25fcU1@uni-berlin.de>
Gunnar Hjalmarsson <noreply@gunnar.cc> 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 |
========================================
================
| |
| Joe Smith 2004-10-11, 3:55 pm |
| Kendall K. Down wrote:
>
> 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
| |
| Matt Garrish 2004-10-12, 3:56 pm |
|
"Kendall K. Down" <webmaster@diggingsonline.com> wrote in message
news:788f11fc4c.diggings@diggingsonline.com...
> In message <CJgad.10308$3C6.248852@news20.bellglobal.com>
> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote:
>
>
> 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
| |
| Kendall K. Down 2004-10-13, 3:55 am |
| In message <GGQad.25484$3C6.865093@news20.bellglobal.com>
"Matt Garrish" <matthew.garrish@sympatico.ca> 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 |
========================================
================
| |
| Tintin 2004-10-13, 9:03 am |
|
"Kendall K. Down" <webmaster@diggingsonline.com> wrote in message
news:481fd3fc4c.diggings@diggingsonline.com...
> In message <GGQad.25484$3C6.865093@news20.bellglobal.com>
> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote:
>
>
> 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.
| |
| Kendall K. Down 2004-10-13, 3:56 pm |
| In message <2t49t0F1qscb5U1@uni-berlin.de>
"Tintin" <tintin@invalid.invalid> 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 |
========================================
================
| |
| Matt Garrish 2004-10-14, 3:56 pm |
|
"Kendall K. Down" <webmaster@diggingsonline.com> wrote in message
news:af0332fd4c.diggings@diggingsonline.com...
> In message <2t49t0F1qscb5U1@uni-berlin.de>
> "Tintin" <tintin@invalid.invalid> wrote:
>
>
> 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
| |
| Kendall K. Down 2004-10-15, 3:55 am |
| In message <U2vbd.26053$hk6.972563@news20.bellglobal.com>
"Matt Garrish" <matthew.garrish@sympatico.ca> 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 |
========================================
================
|
|
|
|
|