How does 'mv' rename directories?

Conor P. Cahill cpcahil at virtech.UUCP
Sun Sep 17 02:13:32 AEST 1989


In article <4195 at buengc.BU.EDU>, bph at buengc.BU.EDU (Blair P. Houghton) writes:
> In article <1160 at virtech.UUCP> cpcahil at virtech.UUCP (Conor P. Cahill) writes:
> >In article <4158 at buengc.BU.EDU>, bph at buengc.BU.EDU (Blair P. Houghton) writes:
	[ much deleted junk... ]
> 
> You only want mv(1) to be able to seteuid(2) to you, so you can move
> your own files.  If mv(1) was setuid-root, you could move files all
> over the place, without a care.  Hence, mv(1) is most definitely
> not setuid-root.

mv doesn't need to seteuid() since it is not a setuid program.  The reason
for the discussion about setuid was due to the fact that the original poster
wanted to know how a directory could be moved.  For BSD, this is simple
because the rename(2) syscall allows this, but for SYSV, there is no
rename syscall and the old link/unlink pair won't work for directories
unless the effective user is root.  The solution under sysV is to have
a second program mv_dir (in /usr/lib) that is setuid root and is called
by mv whenever a directory is to be moved.  However the mv_dir program
will only allow mv's within the same direcory.

> I've been told that mv(1) may call mv_dir(?) (which doesn't exist
> on this machine... Encore's Umax is a vanilla BSD...) which is
> setuid-root (it is claimed).  If this is how it's done, then the
> reason for the setuid-root could be to allow the moving of a
> directory across partition boundaries when the directory may
> contain files with an owner different from the directory-owner.

Nope.  See above.

> Linking to a file is a thing done on the directory containing that
> file, and so requires only the permission of the directory.  Copying

It requires search permission to the source file directory and 
write permission to the target file direcory.

> the file, however, requires permission to read from that file.
> 
> But, basically, there's no need to become uid 0 when you're just moving
> files around in a partition.

The discussion was not about moving files, it was about moving directories
and on a SYSV system you need to be euid root to accomplish it.


-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.unix.wizards mailing list