Reviewed by: various
Submitted by: archie@whistle.com allow ftpd to bind to a single address/interface this allows easy split services.
This commit is contained in:
@@ -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
|
||||
|
||||
+37
-3
@@ -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");
|
||||
@@ -366,6 +379,27 @@ main(argc, argv, envp)
|
||||
syslog(LOG_ERR, "control listen: %m");
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user