Module Name:    src
Committed By:   christos
Date:           Wed Sep 25 16:55:40 UTC 2024

Modified Files:
        src/usr.bin/ftp: fetch.c ftp.1 ftp_var.h main.c

Log Message:
PR/58581: Sunil Nimmagadda: Add flag to allow specifying extra http header
fields.


To generate a diff of this commit:
cvs rdiff -u -r1.240 -r1.241 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.155 -r1.156 src/usr.bin/ftp/ftp.1
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/ftp/ftp_var.h
cvs rdiff -u -r1.131 -r1.132 src/usr.bin/ftp/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.240 src/usr.bin/ftp/fetch.c:1.241
--- src/usr.bin/ftp/fetch.c:1.240	Wed Sep 25 12:53:58 2024
+++ src/usr.bin/ftp/fetch.c	Wed Sep 25 12:55:39 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.240 2024/09/25 16:53:58 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.241 2024/09/25 16:55:39 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.240 2024/09/25 16:53:58 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.241 2024/09/25 16:55:39 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -865,6 +865,7 @@ print_get(FETCH *fin, int hasleading, in
     const struct urlinfo *ui)
 {
 	const char *leading = hasleading ? ", " : "  (";
+	struct entry *np;
 
 	if (isproxy) {
 		if (verbose) {
@@ -882,6 +883,10 @@ print_get(FETCH *fin, int hasleading, in
 	print_host(fin, ui);
 	fetch_printf(fin, "Accept: */*\r\n");
 	fetch_printf(fin, "Connection: close\r\n");
+	SLIST_FOREACH(np, &custom_headers, entries) {
+		fetch_printf(fin, "%s\r\n", np->header);
+	}
+
 	if (restart_point) {
 		fputs(leading, ttyout);
 		fetch_printf(fin, "Range: bytes=" LLF "-\r\n",

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.155 src/usr.bin/ftp/ftp.1:1.156
--- src/usr.bin/ftp/ftp.1:1.155	Thu Jul 18 23:51:21 2024
+++ src/usr.bin/ftp/ftp.1	Wed Sep 25 12:55:39 2024
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.155 2024/07/19 03:51:21 lukem Exp $
+.\" 	$NetBSD: ftp.1,v 1.156 2024/09/25 16:55:39 christos Exp $
 .\"
 .\" Copyright (c) 1996-2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -57,7 +57,7 @@
 .\"
 .\"	@(#)ftp.1	8.3 (Berkeley) 10/9/94
 .\"
-.Dd July 19, 2024
+.Dd September 25, 2024
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -67,6 +67,7 @@
 .Nm
 .Op Fl 46AadefginpRtVv\&?
 .Op Fl b Ar bufsize
+.Op Fl h Ar header
 .Op Fl N Ar netrc
 .Op Fl o Ar output
 .Op Fl P Ar port
@@ -223,6 +224,14 @@ or
 proxies.
 .It Fl g
 Disables file name globbing.
+It Fl H Ar header
+Include the provided
+.Ar header
+string as a custom 
+.Tn HTTP
+header for an
+.Th HTTP
+request.
 .It Fl i
 Turns off interactive prompting during
 multiple file transfers.

Index: src/usr.bin/ftp/ftp_var.h
diff -u src/usr.bin/ftp/ftp_var.h:1.88 src/usr.bin/ftp/ftp_var.h:1.89
--- src/usr.bin/ftp/ftp_var.h:1.88	Sun Feb 18 17:33:15 2024
+++ src/usr.bin/ftp/ftp_var.h	Wed Sep 25 12:55:39 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp_var.h,v 1.88 2024/02/18 22:33:15 wiz Exp $	*/
+/*	$NetBSD: ftp_var.h,v 1.89 2024/09/25 16:55:39 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -101,6 +101,7 @@
 #endif
 
 #include <sys/param.h>
+#include <sys/queue.h>
 
 #include <netinet/in.h>
 #include <arpa/inet.h>
@@ -165,6 +166,14 @@ enum {
 	FEAT_max
 };
 
+/*
+ * Custom HTTP headers
+ */
+struct entry {
+	SLIST_ENTRY(entry)	entries;
+	const char		*header;
+};
+SLIST_HEAD(http_headers, entry);
 
 /*
  * Global defines
@@ -320,8 +329,9 @@ GLOBAL	FILE	*cin;
 GLOBAL	FILE	*cout;
 GLOBAL	int	 data;
 
-extern	struct cmd	cmdtab[];
-extern	struct option	optiontab[];
+extern	struct cmd		cmdtab[];
+extern	struct option		optiontab[];
+extern	struct http_headers	custom_headers;
 
 extern	size_t ftp_buflen;
 

Index: src/usr.bin/ftp/main.c
diff -u src/usr.bin/ftp/main.c:1.131 src/usr.bin/ftp/main.c:1.132
--- src/usr.bin/ftp/main.c:1.131	Wed Sep 25 12:53:58 2024
+++ src/usr.bin/ftp/main.c	Wed Sep 25 12:55:39 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.131 2024/09/25 16:53:58 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.132 2024/09/25 16:55:39 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996-2023 The NetBSD Foundation, Inc.
@@ -98,7 +98,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.131 2024/09/25 16:53:58 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.132 2024/09/25 16:55:39 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -134,11 +134,14 @@ static int	usage(void);
 static int	usage_help(void);
 static void	setupoption(const char *, const char *, const char *);
 
+struct http_headers custom_headers;
+
 int
 main(int volatile argc, char **volatile argv)
 {
 	int ch, rval;
 	struct passwd *pw;
+	struct entry *p;
 	char *cp, *ep, *anonpass, *upload_path, *src_addr;
 	const char *anonuser;
 	int dumbterm, isupload;
@@ -267,7 +270,8 @@ main(int volatile argc, char **volatile 
 		}
 	}
 
-	while ((ch = getopt(argc, argv, ":46Aab:defginN:o:pP:q:r:Rs:tT:u:vVx:")) != -1) {
+	SLIST_INIT(&custom_headers);
+	while ((ch = getopt(argc, argv, ":46Aab:defgH:inN:o:pP:q:r:Rs:tT:u:vVx:")) != -1) {
 		switch (ch) {
 		case '4':
 			family = AF_INET;
@@ -315,6 +319,12 @@ main(int volatile argc, char **volatile 
 			doglob = 0;
 			break;
 
+		case 'H':
+			p = ftp_malloc(sizeof(*p));
+			p->header = ftp_strdup(optarg);
+			SLIST_INSERT_HEAD(&custom_headers, p, entries);
+			break;
+
 		case 'i':
 			interactive = 0;
 			break;

Reply via email to