Monday 22 June 2009

Symbolic Links in ProFTPd

A symbolic link (also referred to as a "symlink") is a file whose contents contain the name of the file to which the symbolic link points. For example:
  lrwxrwxrwx   1 root     root           11 Mar  2  2000 rmt -> /sbin/rmt

The file rmt contains the nine characters /sbin/rmt. The reason symbolic links fail when chroot(2) is used to change the position of the root (/)of the filesystem is that, once / is moved, the pointed-to file path changes. If, for example, if chroot(2) is used to change the filesystem root to /ftp, then the symlink above would be actually be pointing to /ftp/sbin/rmt. Chances that that link, if chroot(2) is used, now points to a path that does not exist. Symbolic links that point to nonexistent files are known as dangling symbolic links. Note that symbolic links to files underneath the new root, such as symlinks to a file in the same directory:
  > pwd
/var/ftp
> ls -l
-rw-r--r-- 1 root root 0 Jan 16 11:50 tmpfile
lrwxrwxrwx 1 root root 7 Jan 16 11:50 tmplink -> tmpfile

will be unaffected; only paths that point outside/above the new root will be affected.

so clearly this will not work in a ProFTPd default directory

The trick is to use re-mount the directory you want listed again

To have an exact duplicate of the /var/ftp/incoming directory available in /home/bob/incoming and /home/dave/incoming, use one of these commands:

  • Linux (as of the 2.4.0 kernel):
      mount --bind /var/ftp/incoming /home/bob/incoming
    mount --bind /var/ftp/incoming /home/dave/incoming

    or, alternatively:
      mount -o bind /var/ftp/incoming /home/bob/incoming
    mount -o bind /var/ftp/incoming /home/dave/incoming



On Kubuntu 9.x with kernel 2.6.28-11-generic the command was:
sudo mount --bind /media/disk/Sorted\ MP3/ /home/sharedftp/download/Music/

This mounted the Sorted MP3 directory under the FTPServer DefaultRoot directory.

In order to have these tricks persist, to survive a system reboot, the /etc/fstab file may need to have these mounts added

fstab

to mount a folder locally to another folder using --bind, ie. mount --bind /path1/ /path2/
/path1 /path2 bind defaults,bind 0 0

To mount a folder with spaces in fstab use "\040"

/media/disk/Sorted\040MP3/ /home/sharedftp/download/Music/ bind defaults,bind 0 0

No comments:

Post a Comment