busunsl has asked for the wisdom of the Perl Monks concerning the following question:

I have to change the timestamp of a directory.
Using utime time, time, $dir works fine as long as I am the owner of the directory.

Problem is, the job that has to change the timestamp is running with a different uid,
and utime won't work, even though every permission is granted to eveybody (0777).

If I change the call of utime to system("touch $dir") it works for any user.

So, what's wrong here?

BTW: This is happening on AIX 4.3.3

Replies are listed 'Best First'.
Re: difference between utime and touch
by jeroenes (Priest) on Apr 05, 2001 at 14:09 UTC
    I don't know about AIX. But in general, perl will use the utime library call (see 'man utime'). Maybe 'touch' uses another call, or maybe it's setuid? Do an 'strace touch $dir' to see what touch actually does. 'man touch' may provide extra info about the library call, as does 'ldd `which touch`'. Alternatively, strace a perl oneliner with the utime statement, or look into the perl source code.

    Hope this helps,

    Jeroen
    "We are not alone"(FZ)
    Update: If 'touch' is setuid indeed, I would call it a security flaw to be fixed. Check if perl is set suid as well (ya know, the s appearing in 'ls -l'.

Re: difference between utime and touch
by jbert (Priest) on Apr 05, 2001 at 14:08 UTC
    Hmm. On Solaris I get:
    somebox> touch /usr/bin touch: cannot touch /usr/bin: no write permission
    So...perhaps your AIX "touch" command is set-uid root and so your perl proggie can leech off this privilege to do the job?

    I imagine that there isn't really a way around this other than using unix groups...

      I forgot to mention: with groups it won't work either.