diff options
author | julian <julian@FreeBSD.org> | 1996-08-09 22:22:30 +0000 |
---|---|---|
committer | julian <julian@FreeBSD.org> | 1996-08-09 22:22:30 +0000 |
commit | 773f3eb265a5479bee5a4b1b136c34b7157adeb4 (patch) | |
tree | a2befc94ca4dfc225d642a13ab481023fafb21ca /libexec/ftpd | |
parent | 53ead71d814751405acf92b3d6587277c4137ffb (diff) | |
download | FreeBSD-src-773f3eb265a5479bee5a4b1b136c34b7157adeb4.zip FreeBSD-src-773f3eb265a5479bee5a4b1b136c34b7157adeb4.tar.gz |
Reviewed by: various
Submitted by: archie@whistle.com
allow ftpd to bind to a single address/interface
this allows easy split services.
Diffstat (limited to 'libexec/ftpd')
-rw-r--r-- | libexec/ftpd/ftpd.8 | 12 | ||||
-rw-r--r-- | libexec/ftpd/ftpd.c | 40 |
2 files changed, 49 insertions, 3 deletions
diff --git a/libexec/ftpd/ftpd.8 b/libexec/ftpd/ftpd.8 index 195a154..2017ad5 100644 --- a/libexec/ftpd/ftpd.8 +++ b/libexec/ftpd/ftpd.8 @@ -47,6 +47,8 @@ Internet File Transfer Protocol server .Op Fl U .Op Fl T Ar maxtimeout .Op Fl t Ar timeout +.Op Fl a Ar address +.Op Fl p Ar file .Sh DESCRIPTION .Nm Ftpd is the @@ -117,6 +119,16 @@ The default limit is 2 hours. The inactivity timeout period is set to .Ar timeout seconds (the default is 15 minutes). +.It Fl a +When +.Fl D +is specified, accept connections only on the specified +.Ar address . +.It Fl p +When +.Fl D +is specified, write the daemon's process ID to +.Ar file . .El .Pp The file diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c index 13a286c..58378db 100644 --- a/libexec/ftpd/ftpd.c +++ b/libexec/ftpd/ftpd.c @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: ftpd.c,v 1.22 1996/08/09 09:02:26 markm Exp $ */ #if 0 @@ -152,6 +152,9 @@ char *tty = ttyline; /* for klogin */ int klogin __P((struct passwd *, char *, char *, char *)); #endif +struct in_addr bind_address; +char *pid_file = NULL; + #if defined(KERBEROS) int notickets = 1; int noticketsdontcomplain = 1; @@ -255,7 +258,8 @@ main(argc, argv, envp) #endif /* OLD_SETPROCTITLE */ - while ((ch = getopt(argc, argv, "dlDSUt:T:u:v")) != EOF) { + bind_address.s_addr = htonl(INADDR_ANY); + while ((ch = getopt(argc, argv, "dlDSUt:T:u:va:p:")) != EOF) { switch (ch) { case 'D': daemon_mode++; @@ -293,6 +297,15 @@ main(argc, argv, envp) restricted_data_ports = 0; break; + case 'a': + if (!inet_aton(optarg, &bind_address)) + errx(1, "invalid address for -a"); + break; + + case 'p': + pid_file = optarg; + break; + case 'u': { long val = 0; @@ -356,7 +369,7 @@ main(argc, argv, envp) (char *)&on, sizeof(on)) < 0) syslog(LOG_ERR, "control setsockopt: %m");; server_addr.sin_family = AF_INET; - server_addr.sin_addr.s_addr = INADDR_ANY; + server_addr.sin_addr = bind_address; server_addr.sin_port = sv->s_port; if (bind(ctl_sock, (struct sockaddr *)&server_addr, sizeof(server_addr))) { syslog(LOG_ERR, "control bind: %m"); @@ -367,6 +380,27 @@ main(argc, argv, envp) exit(1); } /* + * Atomically write process ID + */ + if (pid_file) + { + int fd; + char buf[20]; + + fd = open(pid_file, O_CREAT | O_WRONLY | O_TRUNC + | O_NONBLOCK | O_EXLOCK, 0644); + if (fd < 0) + if (errno == EAGAIN) + errx(1, "%s: file locked", pid_file); + else + err(1, "%s", pid_file); + snprintf(buf, sizeof(buf), + "%lu\n", (unsigned long) getpid()); + if (write(fd, buf, strlen(buf)) < 0) + err(1, "%s: write", pid_file); + /* Leave the pid file open and locked */ + } + /* * Loop forever accepting connection requests and forking off * children to handle them. */ |