Mailing List Archive

chmod/chown question
lstat, stat, and truncate can use either an EXPR or FILEHANDLE. Is there any
reason that chmod and chown can't be modified to work with FILEHANDLEs?
configure is already checking for fchmod and fchown so that isn't a problem.
Is there something else I am missing? I am just beginning to dig into perl's
guts and I know I don't understand very much (yet...).

--
Richard J. Ohnemus (Richard_Ohnemus@sterling.com) (214) 868-5411
Sterling Software Communications Software Division
5215 North O'Connor Boulevard, Suite 1500
Irving, Texas 75039-3771
Re: chmod/chown question [ In reply to ]
: lstat, stat, and truncate can use either an EXPR or FILEHANDLE. Is there any
: reason that chmod and chown can't be modified to work with FILEHANDLEs?

Historically, a lot of systems didn't have fchmod or fchown. Perhaps
that's less of an issue nowadays. On the other hand, chown and chmod
are list operators in Perl, and there's little precedent for allowing
filehandles in a list. There would be much potential for bareword
confusion. On the gripping hand, POSIX doesn't supply the functions,
so the desired functionality is simply missing from Perl at the moment.

It may be that this is something that should go in POSIXish. Or UNIXish,
or FileHandle, or something.

Larry
Re: chmod/chown question [ In reply to ]
: lstat, stat, and truncate can use either an EXPR or FILEHANDLE. Is there any
: reason that chmod and chown can't be modified to work with FILEHANDLEs?

just a nit here: lstat _can't_ possibly work on a file handle. if you
have a file open, there aren't any symlinks to worry about... :-)

Historically, a lot of systems didn't have fchmod or fchown. Perhaps
that's less of an issue nowadays. On the other hand, chown and chmod
are list operators in Perl, and there's little precedent for allowing
filehandles in a list. There would be much potential for bareword
confusion. On the gripping hand, POSIX doesn't supply the functions,
so the desired functionality is simply missing from Perl at the moment.

It may be that this is something that should go in POSIXish. Or UNIXish,
or FileHandle, or something.

i'm not sure sure .. having _some_ of the file operators work on
file handles and some of them not is a bit confusing... and, while
we say that perl is good for writing `secure' programs, not having
fchmod or fchown (or setgroups(), grr) makes it a lot harder to
write these secure programs ... kinda like the way that we don't
have a simple way to open a file with O_EXCL|O_CREAT .. not good
for secure programs.

of course, this doesn't stop them being in FileHandle (my choice).


speaking of setgroups(), it's currently impossible in perl to remove
groups from a program. if i'm writing a daemon that binds to a priv.
port and then gives up all other priviledges, the groups are parts of
what is to be given up, but, there's nothing to do it in perl. i
have to resort to a C wrapper. perhaps setgroups() belongs in POSIXish
or maybe UNIXish... the posix standard doesn't define what setgroups()
is... it's an implimentation defined operation.

hmm.

.mrg.
Re: chmod/chown question [ In reply to ]
>
>
> : lstat, stat, and truncate can use either an EXPR or FILEHANDLE. Is there any
> : reason that chmod and chown can't be modified to work with FILEHANDLEs?
>
> just a nit here: lstat _can't_ possibly work on a file handle. if you
> have a file open, there aren't any symlinks to worry about... :-)

'lstat FILEHANDLE' is just like 'stat FILEHANDLE'. In fact lstat just calls
stat. stat then calls the system lstat only if a filename (or reference to
a filename) was passed as the argument.

> Historically, a lot of systems didn't have fchmod or fchown. Perhaps
> that's less of an issue nowadays. On the other hand, chown and chmod
> are list operators in Perl, and there's little precedent for allowing
> filehandles in a list. There would be much potential for bareword
> confusion. On the gripping hand, POSIX doesn't supply the functions,
> so the desired functionality is simply missing from Perl at the moment.
>
> It may be that this is something that should go in POSIXish. Or UNIXish,
> or FileHandle, or something.
>
> i'm not sure sure .. having _some_ of the file operators work on
> file handles and some of them not is a bit confusing... and, while
> we say that perl is good for writing `secure' programs, not having
> fchmod or fchown (or setgroups(), grr) makes it a lot harder to
> write these secure programs ... kinda like the way that we don't
> have a simple way to open a file with O_EXCL|O_CREAT .. not good
> for secure programs.
>
> of course, this doesn't stop them being in FileHandle (my choice).

I agree that fchown and fchmod (any others?) need to be in either the perl
core or an extension. Currently I use syscall to do fchown/fchmod. IMHO,
syscall should be removed and replaced with extensions.

> speaking of setgroups(), it's currently impossible in perl to remove
> groups from a program. if i'm writing a daemon that binds to a priv.
> port and then gives up all other priviledges, the groups are parts of
> what is to be given up, but, there's nothing to do it in perl. i
> have to resort to a C wrapper. perhaps setgroups() belongs in POSIXish
> or maybe UNIXish... the posix standard doesn't define what setgroups()
> is... it's an implimentation defined operation.

Can't you use syscall to call setgroups?

--
Richard J. Ohnemus (Richard_Ohnemus@sterling.com) (214) 868-5411
Sterling Software CSD
5215 North O'Connor Boulevard, Suite 1500
Irving, Texas 75039-3771
Re: chmod/chown question [ In reply to ]
In <199511091740.AA24803@ns1.sterling.com>
On Thu, 9 Nov 1995 11:40:56 -0600 (CST)
Richard Ohnemus <Rick_Ohnemus@sterling.com> writes:
>
>I agree that fchown and fchmod (any others?) need to be in either the perl
>core or an extension. Currently I use syscall to do fchown/fchmod. IMHO,
>syscall should be removed and replaced with extensions.
>
You can't do fchown/fchmod if OS does not. There is even less likely
to be a way to get pathname from a filehandle!
Re: chmod/chown question [ In reply to ]
> : lstat, stat, and truncate can use either an EXPR or FILEHANDLE. Is there any
> : reason that chmod and chown can't be modified to work with FILEHANDLEs?
>
> just a nit here: lstat _can't_ possibly work on a file handle. if you
> have a file open, there aren't any symlinks to worry about... :-)

'lstat FILEHANDLE' is just like 'stat FILEHANDLE'. In fact lstat just calls
stat. stat then calls the system lstat only if a filename (or reference to
a filename) was passed as the argument.

my 'nit' was based from the UNIX perspective. there is no equivalent
to fstat(2) for symbolic links -- you've got an open fd to a file, so,
there are no symbolic links to be used...

perl may do Nice things, though. :-)

I agree that fchown and fchmod (any others?) need to be in either the perl
core or an extension. Currently I use syscall to do fchown/fchmod. IMHO,
syscall should be removed and replaced with extensions.

i think this would be a bad idea. syscall, when i remember it :-), is
very useful for exact this thing.

Can't you use syscall to call setgroups?

cuz i forgot about it.. :-)

also, it's hard to write portably cuz i don't know the size of the arg to
getgroups...even though i may know it's name from %Config...

.mrg.