From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10952f,b69d377feb5a8a2 X-Google-Attributes: gid10952f,public X-Google-Thread: 10872d,d4c1f7c0fe672a4 X-Google-Attributes: gid10872d,public X-Google-Thread: 1164f8,d4c1f7c0fe672a4 X-Google-Attributes: gid1164f8,public X-Google-Thread: 1020c6,d4c1f7c0fe672a4 X-Google-Attributes: gid1020c6,public X-Google-Thread: fcda7,d4c1f7c0fe672a4 X-Google-Attributes: gidfcda7,public X-Google-Thread: 1070f0,d4c1f7c0fe672a4 X-Google-Attributes: gid1070f0,public From: Jim Mellander Subject: Re: Secure cleaning of /tmp was Different Unixes pros & cons Date: 1998/09/21 Message-ID: <360698A2.1F42719C@llnl.gov>#1/1 X-Deja-AN: 393364762 Content-Transfer-Encoding: 7bit References: <35F71814.1E0B911C@iakom.com> <3602E82F.C8638268@llnl.gov> <6tuuep$kks@web.nmti.com> <360674DF.C1EDCEAF@llnl.gov> <6u5vcg$92r@web.nmti.com> Content-Type: text/plain; charset=us-ascii Organization: Lawrence Livermore National Laboratory Mime-Version: 1.0 Newsgroups: comp.unix.admin,comp.sys.hp.hpux,comp.sys.sgi.admin,comp.sys.sun.admin,comp.sys.dec,comp.security.unix Peter da Silva wrote: > > In article <360674DF.C1EDCEAF@llnl.gov>, > Jim Mellander wrote: > >Peter da Silva wrote: > >> W="` '"'$"' # whitespacish type stuff we want to skip > >> find /tmp -type f -mtime +7 -print | grep '^/tmp' | grep -v "$W" | > >> while read victim > >> do > >> d=`dirname "$victim"` > >> f=`basename "$victim"` > >> ( > >> cd "$d" > >> if [ "`pwd`" = "$d" ] > >> then > >> rm "$f" > >> fi > >> ) > >> done > > > No, there's no race condition there. No matter what they do back in /tmp > it won't have any effect on the subshell that's changed directory into > the target. > There is still a race condition, After the directory test, the file being deleted ($f) could be replaced with a symlink before the rm > > It's properly quoted and the 'grep -v $W' guarantees that there's no > whitespace or quoting characters in it for a belt-and-suspenders defense > (in actual fact, either of these is a sufficient protection, but it's > possible I'm missing something obscure in one or the other). > Didn't notice the grep -v in the original script. Sorry. This is good. Heads off the hackers at the pass......... My feeling is that there are too many obscure 'features' of shells in general to trust a script to do the job of cleaning /tmp or any other publically writable directory. Perhaps we've caught all the pitfalls here, but I sure wouldn't bet the farm on that.... Jim Mellander Unix Sys Admin Lawrence Livermore Natl. Lab.