Home > Archive > PERL Programming > September 2007 > file permissions with cgi 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]
| Author |
file permissions with cgi script
|
|
|
| PTM: I wrote a script to handle my picture archives and show the
pictures thru web pages.
THe script is with permissions:
-r-xr-xr-x 1 root root 5572 2007-09-20 10:36 album.pl
My perl script creates a file to be included in a html page. It gets
permissions like this:
-rw-r--r-- 1 nobody nobody 113 2007-09-20 08:21 index.txt
Now I would like the script to give write access to group 'users' so
that the file could be edited by for example VI or JOE.
I have tried
$mode = 0666; chmod $mode, '$txt_file';
It doesn't change the permissions.
The same problem is with the directories. I don't find how to change
permissons of directories in perl running as CGI.
Do you have suggestions ?
| |
| Paul Lalli 2007-09-20, 7:00 pm |
| On Sep 20, 5:48 am, PTM <ptmu...@utu.fi> wrote:
> PTM: I wrote a script to handle my picture archives and show the
> pictures thru web pages.
> THe script is with permissions:
> -r-xr-xr-x 1 root root 5572 2007-09-20 10:36 album.pl
>
> My perl script creates a file to be included in a html page. It gets
> permissions like this:
> -rw-r--r-- 1 nobody nobody 113 2007-09-20 08:21 index.txt
>
> Now I would like the script to give write access to group 'users' so
> that the file could be edited by for example VI or JOE.
> I have tried
> $mode = 0666; chmod $mode, '$txt_file';
>
> It doesn't change the permissions.
First, always ask Perl why it's not changing permissions:
chmod $mode, '$txt_file' or die "Cannot change permissions: $!\n";
And when that error message tells you that there's "no such file or
directory", hopefully you'll realize that you asked it to change the
permissions of
'$txt_file'
rather than
$txt_file
That is, you asked it to change the permissions of a file named
dollarsign, t, x, t, underscore, f, i, l, e. What you meant to do was
specify the file whose name is contained in the variable $txt_file.
Single quotes do not interpolate. See the difference between:
print "My file is: $txt_file\n";
vs
print 'My file is $txt_file\n';
See also:
perldoc -q quoting
Paul Lalli
| |
|
| Paul Lalli wrote:
> On Sep 20, 5:48 am, PTM <ptmu...@utu.fi> wrote:
>
>
> First, always ask Perl why it's not changing permissions:
> chmod $mode, '$txt_file' or die "Cannot change permissions: $!\n";
> ...Single quotes do not interpolate. See the difference between:
> print "My file is: $txt_file\n";
> vs
> print 'My file is $txt_file\n';
>
> See also:
> perldoc -q quoting
>
> Paul Lalli
>
PTM: Oh my. I have been stupid. Thank you !
I'll go behind the corner and whip me all over.
I have copied the line of script from the net believing somebody had
tested it. My fault. Now there is only some honing left to make the
system work.
I have tried the line above in two systems with comparable results. Now
I can make them both work as they should.
Thank you !
| |
|
| >>Now I would like the script to give write access to group 'users' so[color=darkred]
PTM: OK, now the system works. Still there is another problem with this.
The script changes the permissions of those files, which it has created
itself. Still it has no permissions to change the permissions of
directories created by someone else.
Is there a way ?
| |
| all mail refused 2007-09-21, 7:01 pm |
| On 2007-09-21, PTM <ptmusta@utu.fi> wrote:
> PTM: OK, now the system works. Still there is another problem with this.
> The script changes the permissions of those files, which it has created
> itself. Still it has no permissions to change the permissions of
> directories created by someone else.
> Is there a way ?
Not just like that there isn't - and it's an OS issue rather than a Perl issue.
Maybe you can explain better what you want and why it matters. There's a very
good reason why any old process isn't allowed to go round changing anything
it gets an idea about.
Normally the webserver process and the people maintaining the web content will
have different accounts. CGI scripts normally produce output that gets sent
over the web and will only write to disk in carefully controlled circumstances
if at all.
--
Elvis Notargiacomo master AT barefaced DOT ch
http://www.notatla.org.uk/goen/
| |
|
| all mail refused wrote:
> On 2007-09-21, PTM <ptmusta@utu.fi> wrote:
>
>
>
> Not just like that there isn't - and it's an OS issue rather than a Perl issue.
>
> Maybe you can explain better what you want and why it matters. There's a very
> good reason why any old process isn't allowed to go round changing anything
> it gets an idea about.
> Normally the webserver process and the people maintaining the web content will
> have different accounts. CGI scripts normally produce output that gets sent
> over the web and will only write to disk in carefully controlled circumstances
> if at all.
PTM: All this is clear.
I have pictures in a tree of subdirectories. The new pictures are saved
to new directories either thru Samba or SFTP. Now the user got to change
the permissions for this directory to allow what comes next.
My index.shtml calls for album.pl, which copies index.shtml to new
directory as a symbolic link, makes thumbs of the pictures and creates a
file index.pic containing <img src> -tags for the thumbs.
All is fine and works as Buick, but this changing the permissions is
annoying.
Is there a way to tell the system, that THIS directory and all which are
created under THIS will have preset permissions no matter who creates
the directory ?
Or is there any other way around this ?
Here is one of my picture collections where I'm using one of my
album-programs:
http://ptm2.cc.utu.fi/~ptmusta/kuvat/
| |
| all mail refused 2007-09-22, 7:00 pm |
| On 2007-09-22, PTM <ptmusta@utu.fi> wrote:
I'm still not sure I've fully grasped what you are aiming for, and
none of this has much to do with Perl.
> Is there a way to tell the system, that THIS directory and all which are
> created under THIS will have preset permissions no matter who creates
> the directory ?
> Or is there any other way around this ?
The setgid filemode on a directory does this for the group used - but you
might have to arrange for the relevant processes to use a umask of 002 to
get what you want.
Or you could have something log what is created that doesn't fit your pattern
and either copy it as the desired user, or change it (as root if necessary) to
produce what you want. Supposing people copy into a directory structure that
looks like your webserver directory structure but isn't actually it - then you
might have rsync periodically copy that staging data into the real thing with
suitable owners, groups and modes.
--
Elvis Notargiacomo master AT barefaced DOT ch
http://www.notatla.org.uk/goen/
| |
| Pasi Mustalaht 2007-09-22, 7:00 pm |
| all mail refused wrote:
> On 2007-09-22, PTM <ptmusta@utu.fi> wrote:
>
> I'm still not sure I've fully grasped what you are aiming for, and
> none of this has much to do with Perl.
PTM: Thank you. This discussion gave me enough information to see it
that the problem lies elsewhere an it is hard to solve it thru Perl CGI.
I'll try to find some other solution.
|
|
|
|
|