Manpage of ftpd

ftpd

ftpd

Section: Maintenance Commands (8)
BSD mandoc

NAME

ftpd - simple File Transfer Protocol server

SYNOPSIS

ftpd [-b] [-c clients] [-d [-d]] [-f facility] [-m maxload] [-s] [-p first:last] [-u uid]

DESCRIPTION

Ftpd is a small, simple server for the old and hairy File Transfer Protocol, designed to use less resources than older servers, be smaller, and to never execute any external program.

It supports only the most-used features and commands of FTP, and leaves out everything which is deprecated, meaningless, or correlates with trouble.

OPTIONS

-b
Be broken. Turns on some compatibility hacks for shoddy clients.
-c clients
Allow a maximum of clients to be connected. clients must be at least 1, and if you combine it with -p it will be forced down to half the number of ports specified by -p. If more than clients are connected, new clients are rejected at once, even clients wishing to upload, or to log in as normal users. Therefore, it is advisable to use -m as primary overload protection. The default value for -c is infinity.
-d
turns on debug logging. You can also turn this on by sending SIGUSR1 to the ftpd while it's running. Every command is logged at the LOG_DEBUG level, except that the argument to PASS is changed to "<password>". If you repeat -d (or SIGUSR1), responses too are logged. SIGUSR2 negates SIGUSR1/-d.
-f facility
makes ftpd use facility for all syslog(3) messages. facility defaults to local2. The facility names are normally listed in /usr/include/syslog.h or /usr/include/sys/syslog.h. Note that if -f is not the first option on the command line, a couple of messages may be logged to local2 before the -f option is parsed.
-m load
Do not allow anonymous users to download files if the load is above load when the user connects. Uploads and file listings are still allowed, as are downloads by real users. The user is not told about this until he/she tries to download a file.
-p first:last
Use only ports in the range first to last inclusive for passive-mode downloads. This means that clients will not try to open connections to TCP ports outside the range first-last, which makes troll-ftpd more compatible with packet filters. Note that the maximum number of clients (specified with -c) is forced down to (last+1-first)/2 if it is greater, as the default is. (The syntax for the port range is, conveniently, the same as that of ipfwadm(8)).
-s
Don't allow anonymous users to retrieve files owned by "ftp" (generally, files uploaded by other anonymous users).
-u uid
Do not allow uids below uid to log in (typically, low-numbered uids are used for administrative accounts). -u 100 is sufficient to deny access to all administrative accounts on many linux boxes, where 99 is the last administrative account. Anonymous FTP is allowed even if the uid of the ftp user is smaller than uid. -u 1 denies access only to root accounts. The default is to allow FTP access to all accounts.

AUTHENTICATION

Some of the complexities of older servers are left out.

Normal users are authenticated using USER, PASS and /etc/shells only. In particular, /etc/ftpusers is not consulted, since I think the name is misleading.

Anonymous users are authenticated in any of three ways:

1. The user logs in as "ftp" or "anonymous" and there is an account called "ftp" with an existing home directory. This server does not ask anonymous users for an email address or other password.

2. The user connects to an IP address which resolves to the name of a directory in /var/adm/ftp (or a symlink in that directory to a real directory), and there is an account called "ftp" (which does not need to have a valid home directory). See Virtual Servers below.

3. The user performs a CWD, PASV or PORT command without being authenticated by either of the previous methods, and there is an account called "ftp" with an existing home directory. This allows anonymous users to log in automatically, by simply changing directory, up- or downloading a file.

Ftpd does a chroot(2) to the relevant base directory when an anonymous user logs in.

Note that ftpd allows remote users to log in as root if the password is known and -u not used.

UNUSUAL FEATURES

The internal ls (see below) uses two files, /var/adm/ftp/users and /var/adm/ftp/groups, to look up file owner and group names quickly. These files are written by mkusers which is hopefully run nightly by cron(8).

Ftpd never switches uid and euid, it uses setfsuid(2) instead. The main reason is that uid switching has been exploited in several breakins, but the sheer ugliness of uid switching counts too. Ftpd only calls setfsuid(2) once, at login.

As noted above, this ftpd omits several features that are required by the RFC or might be considered useful at first. Here is a list of the most important omissions.

ASCII mode transfer is omitted, because it's useful so seldom and trips careless users so often. If the client tries to download a file in ASCII mode, ftpd prints a warning at the start of the download.

STRU and MODE are not supported. If a client tries to set a structure other than file (the default) or a MODE other than ASCII, L8 or I ftpd refuses to play.

On-the-fly tar is not supported, for several reasons. I feel that users who want to get many files should use a special FTP client such as "mirror," which also supports incremental fetch. I don't want to either add several hundred lines of code to create tar files or execute an external tar. Finally, on-the-fly tar distorts log files.

On-the-fly compression is left out too. Most files on an FTP site are compressed already, and if a file isn't, there presumably is a reason why. (As for decompression: Don't FTP users waste bandwidth enough without help from on-the-fly decompression?)

ANONYMOUS FTP

This server leaves out some of the commands and features that have been used to subvert anonymous FTP servers in the past, but still you have to be a little bit careful in order to support anonymous FTP without risk to the rest of your files.

Make ~ftp and all files and directories below this directory owned by some user other than "ftp," and only the .../incoming directory/directories writable by "ftp." It is probably best if all directories are writable only by a special group such as "ftpadmin" and "ftp" is not a member of this group.

If you do not trust the local users, put ~ftp on a separate partition, so local users can't hard-link unapproved files into the anonymous FTP area.

Use of the -s option is strongly suggested. (Simply add "-s" to the end of the ftpd line in /etc/inetd.conf to enable it.)

Most other FTP servers require that a number of files such as ~ftp/bin/ls exist. This server does not require that any files or directories within ~/ftp whatsoever exist, and I recommend that all such unnecessary files are removed (for no real reason).

It may be worth considering to run the anonymous FTP service as a virtual server, to get automatic logins and to firewall off the FTP address/port to which real users can log in.

MAGIC FILES

The files <ftproot>/.banner and .message are magical.

If there is a file called .banner in the root directory of the anonymous FTP area, or in the root directory of a virtual host, and it is shorter than 1024 bytes, it is printed upon login. (If the client does not log in explicitly, and an implicit login is triggered by a CWD or CDUP command, the banner is not printed. This is regrettable but hard to avoid.)

If there is a file called .message in any directory and it is shorter than 1024 bytes, that file is printed whenever a user enters that directory using CWD or CDUP.

VIRTUAL SERVERS

You can run several different anonymous FTP servers on one host, by giving the host several IP addresses with different DNS names.

Here are the steps needed to create an extra server using an IP alias on linux 2.0.35, called "ftp.example.com" on address 10.11.12.13. on the IP alias eth0:1 (the first IP alias of eth0).

1. Create an "ftp" account if you do not have one. It it best if the account does not have a valid home directory and shell. I prefer to make /dev/null the ftp account's home directory and shell. Ftpd uses this account to set the anonymous users' uid.

2. Create a directory as described in Anonymous FTP and make a symlink called /var/adm/ftp/ftp.example.com which points to this directory.

3. Make sure your kernel has support for IP aliases.

4. Make sure that the following commands are run at boot:

/sbin/ifconfig eth0:1 10.11.12.13
/sbin/route add 10.11.12.13 dev eth0:1

5. Do the DNS setup. Add a PTR record to the 10.in-addr.arpa zone which points to ftp.example.com. (this must point to the same name as the symlink in step 2, but with a trailing dot) and an A record for ftp to the example.com zone file which points to 10.11.12.13. I prefer to add a line to the host's own /etc/hosts file, too:


   10.11.12.13          ftp.example.com

Then reload the zone files. Note that it is not enough to use CNAME records, you must use A and PTR records as in this example, otherwise ftpd cannot differentiate between the different virtual servers.

That should be all. If you have problems, here are some things to try.

First, symlink /var/adm/ftp/localhost to some directory and say "ftp localhost". If that doesn't log you in, the problem is with ftpd.

If not, "ping -v 10.11.12.13" and/or "ping -v ftp.example.com" from the same host. If this does not work, the problem is with the IP alias.

Next, try "ping -v 10.11.12.13" from a host on the local ethernet, and afterwards "/sbin/arp -a". If 10.11.12.13 is listed among the ARP entries with the correct hardware address, the problem is probably with the IP alias. If 1.2.3.4 is listed, but has hardware address 0:0:0:0:0:0, then proxy-ARP isn't working.

If none of that helps, I'm stumped. Good luck.

FILES

/etc/passwd is used via libc, to get the uid and home directory of normal users, the uid and home directory of "ftp" for normal anonymous ftp, and just the uid of "ftp" for virtual ftp hosts.

/etc/shadow is used like /etc/passwd if shadow support is enabled.

/etc/group is used via libc, to get the group membership of normal users.

/proc/net/tcp is used to count existing FTP connections, if the -c or -p options are used

/var/adm/ftp/users and /var/adm/ftp/groups are used to list the names of users and groups by the LIST command, and are updated by mkusers(8). "ls -l" will tell you that these file are enormous, but actually they are mostly unallocated space. Use "ls -s" to find the true size of the files (in kbytes).

/var/adm/ftp/[hostname] is the base directory for the [hostname] virtual ftp server, or a symbolic link to its base directory. Ftpd does a chroot(2) into this directory when a user logs in to [hostname], thus symlinks outside this directory will not work.

~ftp is the base directory for "normal" anonymous FTP. Ftpd does a chroot(2) into this directory when an anonymous user logs in, thus symlinks outside this directory will not work.

LS

The behaviour of LIST and NLST is a tricky issue. Few servers send RFC-compliant responses to LIST, and some clients depend on non-compliant responses.

This server uses glob(3) to do filename globbing.

The response to NLST is by default similar to that of ls(1), and that to LIST is by default similar to that of ls -l or ls -lg on most Unix systems, except that the "total" count is meaningless. Only regular files, directories and symlinks are shown. Only a few of the many ls options are supported:

-1
Undoes -l and -C.
-a
lists even files/directories whose names begin with ".".
-C
lists files in as many colums as will fit on the screen. Undoes -1 and -l.
-d
lists argument directories' names rather their contents.
-F
appends '*' to executable regular files, '@' to symlinks and '/' to directories.
-l
shows various details about the file, including file group. See ls(1) for details. Undoes -1 and -C.
-r
reverses the sorting order (modifies -S and -t and the default alphabetical ordering).
-R
recursively descends into subdirectories of the argument directories.
-S
Sorts by file size instead of by name. Undoes -t.
-t
Sorts by file modification time instead of by name. Undoes -S.

PROTOCOL

Here are the FTP commands supported by this server.

ABOR
Abort the file transfer. Incompletely supported.
CDUP
Change to the parent directory.
CWD
Change directory.
DELE
Delete one or more files. This is not available to anonymous users. Only one argument is allowed, but that argument may contain wildcards. Ftpd returns success if at least one file is successfully deleted.
LIST
Transfer a verbose file/directory listing via a data connection.
MDTM
Return the modification time of the indicated file in YYYYMMDDHHMMSS format.
MODE
Some values are accepted, all values are disregarded. This server always uses 8-bit binary for transfers and ASCII for directory listings, on the theory that ASCII-mode transfers are more often mistakes than intentional.
NLST
Transfer a simple file listing via a data connection.
NOOP
Do nothing, but the connection timeout counter is reset.
PASS
Specify password. Ignored once the user has logged in.
PASV
Specify and open data connection; client does active open.
PORT
Specify and open data connection; server does active open.
PWD
Print the current directory.
QUIT
Close the connection.
RETR
Transmit file to client.
RNFR
Rename stage 1. Set the file name to rename
RNTO
Rename stage 2. Rename f the file from RNFR to the argument name.
SIZE
Return the size of the argument file in bytes.
SITE
Only SITE IDLE is accepted. The maximum idle period is 7200 seconds.
STOR
Receive file from client.
STRU
As for MODE.
TYPE
As for MODE.
USER
Specify user name. Ignored once the user has logged in.

The rest of the commands given in the FTP RFC or added in other servers are left out in order to keep the server simple, bug-free and secure.

This ftpd does not support the STAT command during data transfers. ABOR requests during data transfers appear not to work.

BUGS

ABOR doesn't work.

HOME PAGE

http://www.troll.no/freebies/ftpd.html

NEW VERSIONS

Send a message containing just subscribe in the subject or body to ftpd-announce-request@troll.no to be added to the announcement mailing list.

AUTHOR AND LICENCE

Written by Arnt Gulbrandsen <agulbra@troll.no> and copyright 1995-1999 Troll Tech AS, Waldemar Thranes gate 98B, N-0175 Oslo, Norway, fax +47 22806380.

Use, modification and distribution is allowed without limitation, warranty, or liability of any kind.

Janos Farkas, cmj@localnet.com, August Fullford and Ximenes Zalteca (and probably others that I've forgotten - write me and I'll add you) have made substantial contributions.

SEE ALSO

ftp(1), ncftp(1), mkusers(8), mrtginfo(8), RFC 959, RFC 2228 and RFC 2428
KDE Logo