summaryrefslogtreecommitdiff
path: root/usr.bin/ftp/main.c
diff options
context:
space:
mode:
authorLawrence Teo <lteo@cvs.openbsd.org>2014-07-11 03:31:53 +0000
committerLawrence Teo <lteo@cvs.openbsd.org>2014-07-11 03:31:53 +0000
commitb744d39fcd7ed9beea429837851bf28f17e66645 (patch)
tree32e03d0d99db59c5207222c294715d2ee0c1b54d /usr.bin/ftp/main.c
parent6368818603865a9199bf2c7b4e9fec08b87b423a (diff)
Allow ftp(1) to change its User-Agent for HTTP(S) URL requests using a
-U command-line option. feedback from deraadt@, halex@, and Adam Thompson ok deraadt@ sthen@, man page changes ok jmc@
Diffstat (limited to 'usr.bin/ftp/main.c')
-rw-r--r--usr.bin/ftp/main.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c
index b39cf4c6820..5c3c2e858a3 100644
--- a/usr.bin/ftp/main.c
+++ b/usr.bin/ftp/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.87 2014/01/23 00:39:15 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.88 2014/07/11 03:31:52 lteo Exp $ */
/* $NetBSD: main.c,v 1.24 1997/08/18 10:20:26 lukem Exp $ */
/*
@@ -198,9 +198,10 @@ main(volatile int argc, char *argv[])
#ifndef SMALL
cookiefile = getenv("http_cookies");
#endif /* !SMALL */
+ httpuseragent = NULL;
while ((ch = getopt(argc, argv,
- "46AaCc:dD:Eegik:mno:pP:r:S:s:tvV")) != -1) {
+ "46AaCc:dD:Eegik:mno:pP:r:S:s:tU:vV")) != -1) {
switch (ch) {
case '4':
family = PF_INET;
@@ -361,6 +362,20 @@ main(volatile int argc, char *argv[])
trace = 1;
break;
+ case 'U':
+#ifndef SMALL
+ if (httpuseragent)
+ errx(1, "User-Agent was already defined");
+ /* Ensure that User-Agent value is in a single line. */
+ if (strcspn(optarg, "\r\n") != strlen(optarg))
+ errx(1, "Invalid User-Agent: %s.", optarg);
+ if (asprintf(&httpuseragent, "User-Agent: %s",
+ optarg) == -1)
+ errx(1, "Can't allocate memory for HTTP(S) "
+ "User-Agent");
+#endif /* !SMALL */
+ break;
+
case 'v':
verbose = 1;
break;
@@ -852,7 +867,7 @@ usage(void)
#ifndef SMALL
"[-S ssl_options] "
"[-s srcaddr]\n"
- " "
+ " [-U useragent] "
#endif /* !SMALL */
"http"
#ifndef SMALL