[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-inetutils] [PATCH] ftpd
From: |
oli |
Subject: |
[bug-inetutils] [PATCH] ftpd |
Date: |
Thu, 8 Oct 2009 23:56:28 +1100 |
Hi,
I saw the developer wanted advert and would like to help out. I have
not contributed to an open source project previously.
The patch is to allow ftpd to take a port number. It was mentioned in
the TODO file.
diff --git a/ftpd/extern.h b/ftpd/extern.h
index ce1ac8c..dbd5455 100644
--- a/ftpd/extern.h
+++ b/ftpd/extern.h
@@ -112,7 +112,7 @@ extern char tmpline[];
extern off_t restart_point;
/* Exported from server_mode.c. */
-extern int server_mode (const char *pidfile, struct sockaddr_in *phis_addr);
+extern int server_mode (const char *pidfile, int port_no, struct
sockaddr_in *phis_addr);
/* Credential for the request. */
struct credentials
diff --git a/ftpd/ftpd.c b/ftpd/ftpd.c
index 8a951cf..f2ecf4a 100644
--- a/ftpd/ftpd.c
+++ b/ftpd/ftpd.c
@@ -1,4 +1,4 @@
-/* - Ftp Server
+ /* - Ftp Server
* Copyright (c) 1985, 1988, 1990, 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
@@ -166,6 +166,7 @@ static off_t file_size;
static off_t byte_count;
static sig_atomic_t transflag; /* Flag where in a middle of transfer. */
static const char *pid_file = PATH_FTPDPID;
+static int port_no=-1; /* Listen on non standard port */
#if !defined(CMASK) || CMASK == 0
# undef CMASK
# define CMASK 027
@@ -294,6 +295,9 @@ static struct argp_option options[] = {
{ " default", 0, NULL, OPTION_DOC|OPTION_NO_TRANS,
"passwd authentication",
GRID+3 },
+ { "port", 'P', "PORT", 0,
+ "listen on non standard port",
+ GRID+1 },
#ifdef WITH_PAM
{ " pam", 0, NULL, OPTION_DOC|OPTION_NO_TRANS,
"using pam 'ftp' module",
@@ -335,7 +339,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
cred.auth_type = AUTH_TYPE_PAM;
#endif
#ifdef WITH_KERBEROS
- else if (strcasecmp (arg, "kerberos") == 0)
+ else if (strcasecmp (arg, "kerberos") == 0)
cred.auth_type = AUTH_TYPE_KERBEROS;
#endif
#ifdef WITH_KERBEROS5
@@ -397,6 +401,12 @@ parse_opt (int key, char *arg, struct argp_state *state)
defumask = val;
break;
}
+
+ case 'P':
+ {
+ port_no = atoi (arg);
+ break;
+ }
default:
return ARGP_ERR_UNKNOWN;
@@ -450,7 +460,7 @@ main (int argc, char *argv[], char **envp)
fd = accept(). tcpd is check if compile with the support */
if (daemon_mode)
{
- if (server_mode (pid_file, &his_addr) < 0)
+ if (server_mode (pid_file, port_no, &his_addr) < 0)
exit (1);
}
else
diff --git a/ftpd/server_mode.c b/ftpd/server_mode.c
index bc122dc..d354c64 100644
--- a/ftpd/server_mode.c
+++ b/ftpd/server_mode.c
@@ -75,13 +75,15 @@ reapchild (int signo ARG_UNUSED)
}
int
-server_mode (const char *pidfile, struct sockaddr_in *phis_addr)
+server_mode (const char *pidfile, int port_no, struct sockaddr_in *phis_addr)
{
int ctl_sock, fd;
struct servent *sv;
int port;
static struct sockaddr_in server_addr; /* Our address. */
+ port = port_no;
+
/* Become a daemon. */
if (daemon (1, 1) < 0)
{
@@ -91,8 +93,11 @@ server_mode (const char *pidfile, struct
sockaddr_in *phis_addr)
signal (SIGCHLD, reapchild);
/* Get port for ftp/tcp. */
- sv = getservbyname ("ftp", "tcp");
- port = (sv == NULL) ? DEFPORT : ntohs (sv->s_port);
+ if (port == -1)
+ {
+ sv = getservbyname ("ftp", "tcp");
+ port = (sv == NULL) ? DEFPORT : ntohs (sv->s_port);
+ }
/* Open socket, bind and start listen. */
ctl_sock = socket (AF_INET, SOCK_STREAM, 0);
--
oli
"During times of universal deceit, telling the truth becomes a
revolutionary act."
- George Orwell
- [bug-inetutils] [PATCH] ftpd,
oli <=