[comp.unix.xenix] Linking directories on Xenix???

jbayer@ispi.UUCP (Jonathan Bayer) (08/19/89)

I have a need to be able to link a directory to another directory.  I
know that it normally is not possible, but I was wondering if there was
a way to fool the OS into linking a directory to another?  The problem
is here because I have a program that for safety's sake must run
chroot'ed in a directory, but also has to have access to the standard
/etc directory, and has to be able to create files in /etc that will be
there later. 


Any ideas?



Thanks


JB
-- 
Jonathan Bayer		Intelligent Software Products, Inc.
(201) 245-5922		500 Oakwood Ave.
jbayer@ispi.UUCP	Roselle Park, NJ   07204    

cpcahil@virtech.UUCP (Conor P. Cahill) (08/20/89)

In article <1114@ispi.UUCP>, jbayer@ispi.UUCP (Jonathan Bayer) writes:
> 
> I have a need to be able to link a directory to another directory.  I
> know that it normally is not possible, but I was wondering if there was
> a way to fool the OS into linking a directory to another? 

Normally the super-user can link directories (note that the .. in the current
directory is a link to the . in the parent directory), so that should solve
your problem.  (The /etc/mvdir shell that is usefull only for root uses this
feature).

A side issue is that having linked directories that are not in the 
normal child/parent relationship can wreck havoc on your backups if the 
backup utilities are not designed to handle this situation.  The find(1)
utility (which is part of lots of backup utilities) does not correctly
handle this situation because of the way it traverses the directory
structure.  As it processes sub-directories, find changes to the child
directory and when finished changes to "..".  If you link a directory 
to another place where it has a different parent directory, when find
changes to ".." it will go to the true parent.

For example:

	you link /etc to /usr/rootdir/etc

	if you cd to /usr/rootdir/etc  and cd ..
	    you will be in /

	if you cd to /usr/rootdir/etc/..
	    you will also be in /

> is here because I have a program that for safety's sake must run
> chroot'ed in a directory, but also has to have access to the standard
> /etc directory, and has to be able to create files in /etc that will be
> there later. 


Another solution would be to copy all modified /etc files into the local etc 
directory, run the chrooted program, and copy back out all modified etc
files.  Inefficient, but it works (unless, of course, you need the modified
files to be placed into /etc immediately).

davidsen@sungod.crd.ge.com (ody) (08/22/89)

  You can do this as root using the link(S) system call. Of course if
you mistrust the program to the extent of making it run chroot then *I*
wouldn't let it touch the space where my passwd and group live. I
strongly encourage doing something like copying the modified files
(perhaps after checking WHICH files they are) into the live /etc.

  Another note (I found out the hard way), most backup programs will
fail in some way trying to back up such a link. Be *very* careful, as
some of the failure modes I found involved trashing the filesystems
completely.
	bill davidsen		(davidsen@crdos1.crd.GE.COM)
  {uunet | philabs}!crdgw1!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me

clewis@eci386.uucp (Chris Lewis) (08/22/89)

In article <1114@ispi.UUCP> jbayer@ispi.UUCP (Jonathan Bayer) writes:
>I have a need to be able to link a directory to another directory.  I
>know that it normally is not possible, but I was wondering if there was
>a way to fool the OS into linking a directory to another?  The problem
>is here because I have a program that for safety's sake must run
>chroot'ed in a directory, but also has to have access to the standard
>/etc directory, and has to be able to create files in /etc that will be
>there later. 
>
>Any ideas?

Getting the files in is easy:

	ln /etc/* /etc/rootdir/etc

Getting them out ain't, though as long as these files aren't deleted,
you could "touch" 'em in /etc and link 'em to /etc/rootdir/etc.
Or simply copy the files back after your special application runs.

Frankly, if you don't trust the program to run without chrooting, I don't
know why you'd trust it enough to have /etc writeable.

Are you concerned about integrity or security?

You could hard "link" (rather than ln) the directory as root, but a 
hostile program might be able to break the chroot by chdir("..")'ing.
-- 
Chris Lewis, R.H. Lathwell & Associates: Elegant Communications Inc.
UUCP: {uunet!mnetor, utcsri!utzoo}!lsuc!eci386!clewis
Phone: (416)-595-5425

debra@alice.UUCP (Paul De Bra) (08/23/89)

In article <1797@crdgw1.crd.ge.com> davidsen@crdos1.UUCP (bill davidsen) writes:
>  You can do this as root using the link(S) system call...

But fsck will bark every time you run it, because it doesn't like
directories with more than one link.

Paul.
-- 
------------------------------------------------------
|debra@research.att.com   | uunet!research!debra     |
------------------------------------------------------

thurm@shorty.CS.WISC.EDU (Matthew Thurmaier) (08/24/89)

In article <1114@ispi.uucp> Jonathan Bayer writes:
> I have a need to be able to link a directory to another directory.  I
> know that it normally is not possible, but ...

Jonathan,

	This is somewhat of a KLUDGE, but see if you can get it to work.  I have
not had time to try it myself, so there are NO PROMISSES, just hunches:

1.) We know that a directory is really just a way of maping file names to
	i-nodes.

2.) We know that directories have i-node #s, just like any other file.

3.) We know that directories entries may only be made by root.

4.) We know that the structure of a directory entry is listed in <sys/dir.h>

SO,

Write a program which you execute as root, which includes <sys/dir.h>, opens the
directory that you want to link to, gets it's i-node number and other vital
information (note that if you open that directory, the "." entry represents
the directory itself), then open the directory in which you want to make the
new link entry and create an entry with the same information, only with the 
name changed to whatever you want, instead of ".".

Let me know how it turns out.

Matthew.
make sure that 
Snail Mail:                                 E Mail:
Matthew J. Thurmaier                ...!{allegra,harvard,seismo}!shorty!matt
The Computer Classroom              matt@shorty.wisc.edu
6701 Seybold Road, Ste. 122
Madison, WI 53719
(608) 271-2171
                                  "why am I ALWAYS going somewhere?" >>-matt-->

clewis@eci386.uucp (Chris Lewis) (08/26/89)

In article <8233@spool.cs.wisc.edu> thurm@shorty.cs.wisc.edu (Matthew Thurmaier) writes:
>In article <1114@ispi.uucp> Jonathan Bayer writes:
>> I have a need to be able to link a directory to another directory.  I
>> know that it normally is not possible, but ...

>	This is somewhat of a KLUDGE, but see if you can get it to work.  I have
>not had time to try it myself, so there are NO PROMISSES, just hunches:

>3.) We know that directories entries may only be made by root.

Nope.  *Only* by the kernel.  There's no way of writing into a directory
file from a user program except by openning the special file for the
file system, traversing the hierarchy yourself, and manually zapping a 
block in the directory.  And, if you have to allocate a new block?  Well,
forget it.

The "link" system call will do what you want if you're root, unfortunately, 
fsck will probably bitch.
-- 
Chris Lewis, R.H. Lathwell & Associates: Elegant Communications Inc.
UUCP: {uunet!mnetor, utcsri!utzoo}!lsuc!eci386!clewis
Phone: (416)-595-5425

marks@mgse.UUCP (Mark Seiffert) (08/28/89)

In article <9807@alice.UUCP> debra@alice.UUCP () writes:
>In article <1797@crdgw1.crd.ge.com> davidsen@crdos1.UUCP (bill davidsen) writes:
>>  You can do this as root using the link(S) system call...
>
>But fsck will bark every time you run it, because it doesn't like
>directories with more than one link.

I have not ran fsck with a directory link yet. I have noticed that
when you cd into a linked directory, and then cd .. out of it, you
are in the parent directory of the linked file (is that the way to
explain it?), it is aggravating.

I have noticed the following problem, i would call it a bug, you
decide for yourself. When the following script is ran it creates a
directory in /usr/tmp and then links the directory to a second name.
If you rm the second directory name, and then cd into the first, you
can cd back out. It looks like rmdir does not check to see if a directory
has links before it removes the . directory entry.

I also noticed there is no online manual page for link. ln will not
work with directories, as stated in the man page.

link does not give a diagnostic message if it can not find the
first directory named on the command line for the link command.

------------------ cut here ------------------
set -x
cd /usr/tmp
mkdir test1
link test1 test2
rmdir test2
cd test1
l
cd /usr/tmp
rmdir test1
------------------ cut here ------------------

Any comments? Is this a known bug, i decided to drop SCO's softcare
support.

>
>Paul.
>-- 
>------------------------------------------------------
>|debra@research.att.com   | uunet!research!debra     |
>------------------------------------------------------

-- 
Mark Seiffert,  Metairie, LA.
uucp:           rex!mgse!marks
bitnet:         marks%mgse@REX.CS.TULANE.EDU
internet:       marks%mgse@rex.cs.tulane.edu