touch question

Hello,

is it correct or a bug that only the owner of a file can use "touch" to set
the modification time of a file to some arbitrary time? For testing
purposes, I've got a file with mode 666 in a mode 777 directory, owned by
another user, but I can't "touch" it. Why?

robert
Robert Latest [ Mo, 07 Januar 2008 16:50 ] [ ID #1901430 ]

Re: touch question

On Mon, 07 Jan 2008 15:50:57 +0000, Robert Latest wrote:

> Hello,
>
> is it correct or a bug that only the owner of a file can use "touch" to
> set the modification time of a file to some arbitrary time? For testing
> purposes, I've got a file with mode 666 in a mode 777 directory, owned
> by another user, but I can't "touch" it. Why?
>
> robert

From the man page for utimes

NAME utime, utimes - change access and/or modification times of an
inode

SYNOPSIS #include <sys/types.h> #include <utime.h>

int utime(const char *filename, const struct utimbuf *buf);

#include <sys/time.h>

int utimes(const char *filename, const struct timeval times[2]);

DESCRIPTION utime() changes the access and modification times of the
inode specified by filename to the actime and modtime fields of buf
respectively.

If buf is NULL, then the access and modification times of the
file are set to the current time.

Changing time stamps is permitted when: either the process has
appropriate privileges (Linux: has the CAP_FOWNER capability), or the
effective user ID equals the user ID of the file, or buf is NULL and
the process has write per- mission to the file.

So the behaviour is correct. You have to have an EUID equal to the owner
of the file to set an arbitary time. You can set it to the current time
just by having write permission.
Icarus Sparry [ Mo, 07 Januar 2008 18:26 ] [ ID #1901436 ]

Re: touch question

In article <478260ae$0$84195$742ec2ed [at] news.sonic.net>,
Icarus Sparry <usenet [at] icarus.freeuk.com> wrote:

> So the behaviour is correct. You have to have an EUID equal to the owner
> of the file to set an arbitary time. You can set it to the current time
> just by having write permission.

I presume the intent is that the owner might want to know when people
have written to his file. They shouldn't be able to write to the file
and then hide it by reverting the modification time.

--
Barry Margolin, barmar [at] alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Barry Margolin [ Di, 08 Januar 2008 04:41 ] [ ID #1902407 ]

Re: touch question

Barry Margolin wrote:
> I presume the intent is that the owner might want to know when people
> have written to his file. They shouldn't be able to write to the file
> and then hide it by reverting the modification time.

Yeah, makes sense.

robert
Robert Latest [ Di, 08 Januar 2008 09:58 ] [ ID #1902421 ]
Linux » comp.unix.shell » touch question

Vorheriges Thema: Pattern matching question
Nächstes Thema: Getting script location, trouble with spaces