Rootless glftpd

Glftpd by default runs as root. It's launched as root, and it will never give up the root privilege. It uses a function named seteuid(uid); to escalate between privileges.

This is an artifact from the original way that glftpd accounted for ownership and stats by using the UNIX ACLs to see who owns a file. This also means that in order to delete some other user's file, or to write to a root owned log file, you will need to escalate to root. Glftpd will do this temporarily but seteuid(0); and when done switch back to your regular uid defined in /etc/passwd.

Even though you in ps -ef see glftpd run as a regular user, it must have privileges to escalate in order to function.

What this means for you is that anyone hacking glftpd, nomatter if this is done while your UID is currently a user or root, can most likely inject shell code which can trigger seteuid(0);, and your system is compromised.

Warning!

The binaries built with these capabilities are only a technical preview. The SQLite3 implementation is not perfect in regards to locking and transaction. The SQLite3 implementation is open sourced, and can be found here. Your contributions are welcomed!

If you are a DB junkie or have a good model for implementation for access, please contribute. If you are a script maintainer which rely on the filesystem ownership (st_uid/st_gid), please implement support for reading the .ownerdb files.

Current implementation design

As the rootless glftpd cannot rely on the filesystem ACLs for ownership, we need to implement another separate structure. We used SQLite3 for this not having to reinvent the wheel. As SQLite3 is an atomic accounting database with slim traces and open license.

We use one micro db per folder which glftpd manages. This is to reduce locking issues (one central DB would introduce longer waits for locks) and to make transparency to external tools as slim as possible. For instance, if you move a directory to your Archive disk, you would need to update a central DB in order to keep permissions. But with this approach the permissions follow the directory automaticly.

Glftpd will maintain and create/delete the owner database files as a part of the regular use. It's integrated in the MKD / DELE / RMD commands, and doing RETR/STOR will update the database accordingly.

The filename for the owner database is .ownerdb. The structure for the file is:

Activation in glftpd

Now that you have hopefully read and understood what this implies, here comes the options which enables you to use a non-rooted glftpd.

Connecting and logging

If all above is set up correctly, you should now be able to connect to your glftpd as any user, and it should run as your defined gl_user.

Debug logging for the ownerdb transactions will be put in /ftp-data/owner_update.log. Take a peak in it now and then. Reference to this can be found in owner.c.