git: 629de3e1aa28 - main - ftp/ftpproxy: Minor cosmetic changes

From: Zsolt Udvari <uzsolt_at_FreeBSD.org>
Date: Thu, 13 Mar 2025 11:33:00 UTC
The branch main has been updated by uzsolt:

URL: https://cgit.FreeBSD.org/ports/commit/?id=629de3e1aa28bc9a6dc19a5659c7c635304c4d39

commit 629de3e1aa28bc9a6dc19a5659c7c635304c4d39
Author:     Juraj Lutter <otis@FreeBSD.org>
AuthorDate: 2025-03-13 11:18:09 +0000
Commit:     Zsolt Udvari <uzsolt@FreeBSD.org>
CommitDate: 2025-03-13 11:18:09 +0000

    ftp/ftpproxy: Minor cosmetic changes
    
    Add rc.d script and option to use PID file.
    Switch to DISTVERSION.
    Add license information.
    
    PR:             269722
    Approved by:    maintainer timeout (3+ weeks)
---
 ftp/ftpproxy/Makefile                    | 19 +++++++--
 ftp/ftpproxy/files/ftpproxy.in           | 46 ++++++++++++++++++++
 ftp/ftpproxy/files/patch-Makefile        |  2 +-
 ftp/ftpproxy/files/patch-doc_ftp.proxy.1 | 13 ++++++
 ftp/ftpproxy/files/patch-src_daemon.c    | 72 ++++++++++++++++++++++++++++++++
 ftp/ftpproxy/files/patch-src_ftp.c       | 39 +++++++++++++++++
 ftp/ftpproxy/files/patch-src_ftp.h       | 62 +++++++++++++++++++++++++++
 ftp/ftpproxy/files/patch-src_ip-lib.c    | 11 +++++
 ftp/ftpproxy/files/patch-src_lib.c       | 70 +++++++++++++++++++++++++++++++
 ftp/ftpproxy/files/patch-src_main.c      | 45 ++++++++++++++++++++
 10 files changed, 374 insertions(+), 5 deletions(-)

diff --git a/ftp/ftpproxy/Makefile b/ftp/ftpproxy/Makefile
index 5fb5a8c87515..e27117f93510 100644
--- a/ftp/ftpproxy/Makefile
+++ b/ftp/ftpproxy/Makefile
@@ -1,5 +1,5 @@
 PORTNAME=	ftpproxy
-PORTVERSION=	1.2.3
+DISTVERSION=	1.2.3
 PORTREVISION=	2
 CATEGORIES=	ftp
 MASTER_SITES=	http://www.ftpproxy.org/download/ \
@@ -9,19 +9,30 @@ MAINTAINER=	philippe@le-berre.com
 COMMENT=	FTP proxy
 WWW=		https://www.ftpproxy.org/
 
+LICENSE=	GPLv2
+LICENSE_FILE=	${WRKSRC}/LICENSE
+
 USES=		gmake tar:tgz
+MAKE_ARGS=	CC="${CC}" \
+		OSLIB="-lutil"
 MAKE_JOBS_UNSAFE=	yes
-MAKE_ARGS=	CC="${CC}"
 
-PLIST_FILES=	sbin/ftp.proxy \
+SUB_FILES=	ftpproxy
+
+PLIST_FILES=	etc/rc.d/ftpproxy \
+		sbin/ftp.proxy \
 		share/man/man1/ftp.proxy.1.gz
 
 pre-build:
 	@${REINPLACE_CMD} -e 's|^CFLAGS.*|CFLAGS=${CFLAGS} \
 	     -DVERSION=\\"${PORTVERSION}\\"|' ${WRKSRC}/src/Makefile
 
+post-build:
+	${GZIP_CMD} ${WRKSRC}/doc/ftp.proxy.1
+
 do-install:
 	${INSTALL_PROGRAM} ${WRKSRC}/src/ftp.proxy ${STAGEDIR}${PREFIX}/sbin
-	${INSTALL_MAN} ${WRKSRC}/doc/ftp.proxy.1 ${STAGEDIR}${PREFIX}/share/man/man1
+	${INSTALL_MAN} ${WRKSRC}/doc/ftp.proxy.1.gz ${STAGEDIR}${PREFIX}/share/man/man1
+	${INSTALL_SCRIPT} ${WRKDIR}/ftpproxy ${STAGEDIR}${PREFIX}/etc/rc.d
 
 .include <bsd.port.mk>
diff --git a/ftp/ftpproxy/files/ftpproxy.in b/ftp/ftpproxy/files/ftpproxy.in
new file mode 100644
index 000000000000..c662fd15a946
--- /dev/null
+++ b/ftp/ftpproxy/files/ftpproxy.in
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+# PROVIDE: ftpproxy
+# REQUIRE: LOGIN FILESYSTEMS ftp
+# KEYWORD: shutdown
+#
+# ftpproxy_enable (bool):     Set to "YES" to enable ftpproxy.
+#                             (default: "NO")
+#
+# ftpproxy_config (str):      Name of ftpproxy config file
+#                             (default: "/usr/local/etc/ftpproxy.conf")
+#
+# ftpproxy_defaulthost (str): Name of ftp server to connect to.
+#                             (default: "localhost")
+#
+# ftpproxy_flags (str):       Additional flags for ftpproxy
+#                             (default: "")
+#
+# ftpproxy_user (str):        The user to run ftpproxy as
+#                             (default: "root")
+#
+
+. /etc/rc.subr
+
+name=ftpproxy
+rcvar=ftpproxy_enable
+pidfile="/var/run/ftpproxy.pid"
+start_cmd="${name}_start"
+command="%%PREFIX%%/sbin/ftp.proxy"
+
+load_rc_config $name
+
+: ${ftpproxy_enable="NO"}
+: ${ftpproxy_config="%%PREFIX%%/etc/ftpproxy.conf"}
+: ${ftpproxy_defaulthost="localhost"}
+: ${ftpproxy_flags=""}
+: ${ftpproxy_user="root"}
+
+ftpproxy_start()
+{
+        /usr/bin/install -o ${ftpproxy_user} /dev/null ${pidfile}
+        /usr/bin/su -m ${ftpproxy_user} -c "${command} -f ${ftpproxy_config} \
+                -P ${pidfile} ${ftpproxy_flags} ${ftpproxy_defaulthost}"
+}
+
+run_rc_command "$1"
diff --git a/ftp/ftpproxy/files/patch-Makefile b/ftp/ftpproxy/files/patch-Makefile
index d59d84749c93..04b9725bb5bd 100644
--- a/ftp/ftpproxy/files/patch-Makefile
+++ b/ftp/ftpproxy/files/patch-Makefile
@@ -1,4 +1,4 @@
---- Makefile.orig	2004-07-30 12:49:27.000000000 +0000
+--- Makefile.orig	2004-07-30 12:49:27 UTC
 +++ Makefile
 @@ -9,7 +9,7 @@ TARGETS =	ftp.proxy
  
diff --git a/ftp/ftpproxy/files/patch-doc_ftp.proxy.1 b/ftp/ftpproxy/files/patch-doc_ftp.proxy.1
new file mode 100644
index 000000000000..cf6c893c7855
--- /dev/null
+++ b/ftp/ftpproxy/files/patch-doc_ftp.proxy.1
@@ -0,0 +1,13 @@
+--- doc/ftp.proxy.1.orig	2023-02-20 12:32:45 UTC
++++ doc/ftp.proxy.1
+@@ -373,6 +373,10 @@ tell \fIftp.proxy\fR to use \fIport\fR as source port 
+ transfers (using port number 20 is FTP standard).
+ Keep in mind that port numbers below 1024 require root permissions.
+ .TP
++\fB-P\fR \fIfilename\fR
++tell \fIftp.proxy\fR to write the PID of the master process into
++the \fIfilename\fR specified.
++.TP
+ \fB-q\fR \fIsourceip\fR
+ sets the IP number for the outgoing control connection.
+ .TP
diff --git a/ftp/ftpproxy/files/patch-src_daemon.c b/ftp/ftpproxy/files/patch-src_daemon.c
new file mode 100644
index 000000000000..ec3d1c027604
--- /dev/null
+++ b/ftp/ftpproxy/files/patch-src_daemon.c
@@ -0,0 +1,72 @@
+--- src/daemon.c.orig	2003-10-26 22:10:19 UTC
++++ src/daemon.c
+@@ -33,6 +33,7 @@
+ #include <signal.h>
+ #include <sys/wait.h>
+ #include <pwd.h>
++#include <err.h>
+ 
+ #include <sys/types.h>
+ #include <sys/stat.h>
+@@ -51,20 +52,35 @@
+ 
+ int acceptloop(int sock)
+ {
+-	int	connect, pid, len;
++	int	connect, pid, otherpid;
++	socklen_t len;
+ 	struct sockaddr_in client;
+ 
+ 	/*
+ 	 * Go into background.
+ 	 */
+ 	
+-	if (debug != 0)
+-		; /* Do not fork in debug mode */
++	pfh = NULL;
+ 
+-	else if ((pid = fork()) > 0)
+-		exit (0);
++	if (debug == 0) {
++		pfh = pidfile_open(pidfile, 0600, &otherpid);
++		if (pfh == NULL) {
++			if (errno == EEXIST) {
++				errx(EXIT_FAILURE, "ftp.proxy already running, pid %jd.",
++						(intmax_t)otherpid);
++			}
++			warnx("Cannot open or create pid file %s", pidfile);
++		}
++		if (daemon(0, 0) == -1) {
++			warnx("Cannot daemonize");
++			pidfile_remove(pfh);
++			exit(EXIT_FAILURE);
++		}
++		pidfile_write(pfh);
++	}
+ 
+ 	fprintf (stderr, "\nstarting ftp.proxy %s in daemon mode ...\n", VERSION);
++
+ 	while (1) {
+ 
+ 		/*
+@@ -82,7 +98,7 @@ int acceptloop(int sock)
+ 
+ 		if ((pid = fork()) < 0) {
+ 			fprintf (stderr, "%04X: can't fork process: %s\n", getpid(), strerror(errno));
+-			exit (1);
++			exit(EXIT_FAILURE);
+ 			}
+ 		else if (pid == 0) {
+ 			int optlen;
+@@ -112,7 +128,9 @@ int acceptloop(int sock)
+ 
+ 	close (1);
+ 	fprintf (stderr, "%04X: terminating\n", getpid());
+-
+-	exit (0);
++	if (pfh != NULL) {
++		pidfile_remove(pfh);
++	}
++	exit (EXIT_SUCCESS);
+ }
+ 
diff --git a/ftp/ftpproxy/files/patch-src_ftp.c b/ftp/ftpproxy/files/patch-src_ftp.c
new file mode 100644
index 000000000000..8d5796197ba2
--- /dev/null
+++ b/ftp/ftpproxy/files/patch-src_ftp.c
@@ -0,0 +1,39 @@
+--- src/ftp.c.orig	2004-07-30 12:52:12 UTC
++++ src/ftp.c
+@@ -115,7 +115,7 @@ ftpcmd_t cmdtab[] = {
+ 
+ unsigned get_interface_info(int pfd, char *ip, int max)
+ {
+-	int	size;
++	socklen_t	size;
+ 	unsigned int port;
+ 	struct sockaddr_in saddr;
+ 
+@@ -133,7 +133,7 @@ unsigned get_interface_info(int pfd, char *ip, int max
+ 
+ int get_client_info(ftp_t *x, int pfd)
+ {
+-	int	size;
++	socklen_t	size;
+ 	struct sockaddr_in saddr;
+ 	struct in_addr *addr;
+ 	struct hostent *hostp = NULL;
+@@ -274,7 +274,8 @@ int getc_fd(ftp_t *x, int fd)
+ 				}
+ 			else if (FD_ISSET(x->ch.active, &available)) {
+ 				if (x->ch.state == PORT_LISTEN) {
+-					int	sock, adrlen;
++					int	sock;
++					socklen_t adrlen;
+ 					struct sockaddr_in adr;
+ 
+ 					earlyreported = 0;
+@@ -1823,7 +1824,7 @@ int proxy_request(config_t *config)
+ 				syslog(LOG_NOTICE, "%s %s: %ld bytes", x->ch.command, x->ch.filename, x->ch.bytes);
+ 
+ 				if (x->xlfp != NULL) {
+-					unsigned long now;
++					time_t now;
+ 					char	date[80];
+ 
+ 					/*
diff --git a/ftp/ftpproxy/files/patch-src_ftp.h b/ftp/ftpproxy/files/patch-src_ftp.h
new file mode 100644
index 000000000000..29d15f5c5ba4
--- /dev/null
+++ b/ftp/ftpproxy/files/patch-src_ftp.h
@@ -0,0 +1,62 @@
+--- src/ftp.h.orig	2023-02-20 11:42:14 UTC
++++ src/ftp.h
+@@ -29,11 +29,19 @@
+ #ifndef	_FTP_INCLUDED
+ #define	_FTP_INCLUDED
+ 
++#include <limits.h>
++#include <libutil.h>
++
+ extern char *version;
+ 
+ extern char *program;
+-extern char progname[80];
++extern char progname[PATH_MAX];
+ 
++/* PID file */
++#define PIDFILE_DEFAULT "/var/run/ftpproxy.pid"
++extern char pidfile[PATH_MAX];
++extern struct pidfh *pfh;
++
+ extern int debug;
+ extern int extralog;
+ extern int bindport;
+@@ -45,7 +53,7 @@ extern int acceptloop(int sock);
+ 
+ 
+ typedef struct _config {
+-    char	configfile[200];
++    char	configfile[PATH_MAX];
+ 
+     int		standalone;
+     int		timeout;
+@@ -53,12 +61,12 @@ typedef struct _config {
+     int		selectserver;
+     int		allow_anyremote;
+ 
+-    char	server[200];
++    char	server[NI_MAXHOST];
+     char	*serverlist;
+ 
+-    char	acp[200];
+-    char	ccp[200];
+-    char	ctp[200];
++    char	acp[PATH_MAX];
++    char	ccp[PATH_MAX];
++    char	ctp[PATH_MAX];
+     char	varname[80];
+ 
+     int		allow_blanks;
+@@ -66,10 +74,10 @@ typedef struct _config {
+     int		use_last_at;
+     int		monitor;
+     int		bsize;
+-    char	xferlog[200];
++    char	xferlog[PATH_MAX];
+ 
+     int		numeric_only;
+-    char	sourceip[200];
++    char	sourceip[NI_MAXHOST];
+     unsigned int dataport;
+     } config_t;
+ 
diff --git a/ftp/ftpproxy/files/patch-src_ip-lib.c b/ftp/ftpproxy/files/patch-src_ip-lib.c
new file mode 100644
index 000000000000..f99847a1e496
--- /dev/null
+++ b/ftp/ftpproxy/files/patch-src_ip-lib.c
@@ -0,0 +1,11 @@
+--- src/ip-lib.c.orig	2025-02-19 19:25:06 UTC
++++ src/ip-lib.c
+@@ -52,7 +52,7 @@ int openip(char *host, unsigned int port, char *srcip,
+ {
+ 	int	socketd;
+ 	struct sockaddr_in server;
+-	struct hostent *hostp, *gethostbyname();
++	struct hostent *hostp;
+ 
+ 	socketd = socket(AF_INET, SOCK_STREAM, 0);
+ 	if (socketd < 0)
diff --git a/ftp/ftpproxy/files/patch-src_lib.c b/ftp/ftpproxy/files/patch-src_lib.c
new file mode 100644
index 000000000000..feb5b280dc12
--- /dev/null
+++ b/ftp/ftpproxy/files/patch-src_lib.c
@@ -0,0 +1,70 @@
+--- src/lib.c.orig	2003-07-11 16:34:46 UTC
++++ src/lib.c
+@@ -76,9 +76,9 @@ static int _init_upper()
+ 		upper[c] = 'A' + (c - 'a');
+ 
+ 	DEBUG( fprintf (stderr, "init umlaute\n"); )
+-	upper[c = (unsigned char) 'ä'] = 'Ä';
+-	upper[c = (unsigned char) 'ö'] = 'Ö';
+-	upper[c = (unsigned char) 'ü'] = 'Ü';
++	upper[c = (unsigned char) '\xe4'] = '\xc4';
++	upper[c = (unsigned char) '\xf6'] = '\xd6';
++	upper[c = (unsigned char) '\xfc'] = '\xdc';
+ 
+ 	DEBUG( fprintf (stderr, "init upper[] complete\n"); )
+ 	return (0);
+@@ -97,9 +97,9 @@ static int _init_lower()
+ 		lower[c] = 'a' + (c - 'A');
+ 
+ 	DEBUG( fprintf (stderr, "init umlaute\n"); )
+-	lower[c = (unsigned char) 'Ä'] = 'ä';
+-	lower[c = (unsigned char) 'Ö'] = 'ö';
+-	lower[c = (unsigned char) 'Ü'] = 'ü';
++	lower[c = (unsigned char) '\xc4'] = '\xe4';
++	lower[c = (unsigned char) '\xd6'] = '\xf6';
++	lower[c = (unsigned char) '\xdc'] = '\xfc';
+ 
+ 	DEBUG( fprintf (stderr, "init upper[] complete\n"); )
+ 	return (0);
+@@ -140,8 +140,8 @@ int islowercase(unsigned int c)
+ 
+ char *strlwr(char *string)
+ {
+-	unsigned int c;
+-	unsigned char *p;
++	char c;
++	char *p;
+ 
+ 	if (lower['0'] == 0)
+ 		_init_lower();
+@@ -156,8 +156,8 @@ char *strlwr(char *string)
+ 
+ char *strupr(char *string)
+ {
+-	unsigned int c;
+-	unsigned char *p;
++	char c;
++	char *p;
+ 
+ 	if (upper['0'] == 0)
+ 		_init_upper();
+@@ -183,7 +183,7 @@ char *skip_ws(char *string)
+ char *noctrl(char *buffer)
+ {
+ 	int	len, i;
+-	unsigned char *p;
++	char *p;
+ 
+ 	if ((p = buffer) == NULL)
+ 		return (NULL);
+@@ -201,8 +201,8 @@ char *noctrl(char *buffer)
+ 
+ char *get_word(char **from, char *to, int maxlen)
+ {
+-	unsigned int c;
+-	unsigned char *p;
++	char c;
++	char *p;
+ 	int	k;
+ 
+ 	maxlen -= 2;
diff --git a/ftp/ftpproxy/files/patch-src_main.c b/ftp/ftpproxy/files/patch-src_main.c
new file mode 100644
index 000000000000..47c07d3d6613
--- /dev/null
+++ b/ftp/ftpproxy/files/patch-src_main.c
@@ -0,0 +1,45 @@
+--- src/main.c.orig	2023-02-20 11:38:18 UTC
++++ src/main.c
+@@ -41,6 +41,7 @@
+ #include <arpa/inet.h>
+ #include <syslog.h>
+ #include <sys/time.h>
++#include <limits.h>
+ 
+ #include "ftp.h"
+ #include "ip-lib.h"
+@@ -55,8 +56,11 @@
+ 
+ 
+ char	*program =		"";
+-char	progname[80] =		"";
++char	progname[PATH_MAX] =	"";
+ 
++char pidfile[PATH_MAX];
++struct pidfh *pfh;
++
+ int	debug =			0;
+ int	extralog =		0;
+ 
+@@ -88,6 +92,8 @@ int main(int argc, char *argv[], char *envp[])
+ 		program = progname;
+ 		}
+ 
++	copy_string(pidfile, PIDFILE_DEFAULT, sizeof(pidfile));
++
+ 	config = allocate(sizeof(config_t));
+ 	config->timeout = 15 * 60;
+         config->allow_passwdblanks = 0;
+@@ -146,6 +152,12 @@ int main(int argc, char *argv[], char *envp[])
+ 				config->dataport = strtoul(argv[k++], NULL, 10);
+ 				if (config->dataport == 0)
+ 					config->dataport = 20;
++				}
++			else if (c == 'P') {
++				if (k >= argc)
++					missing_arg(c, "pid file name");
++
++				copy_string(pidfile, argv[k++], sizeof(pidfile));
+ 				}
+ 			else if (c == 'q') {
+