About a month ago, I sent a diff that allows ftp(1) to set its User-Agent. Based on feedback from halex@ and deraadt@, I have changed it so that the User-Agent can be set via a -U command-line option instead of an environment variable.
I have also fixed a conflict with guenther@'s recent fetch.c commit. Would anyone like to ok this latest version? Index: fetch.c =================================================================== RCS file: /cvs/src/usr.bin/ftp/fetch.c,v retrieving revision 1.123 diff -u -p -r1.123 fetch.c --- fetch.c 5 Jul 2014 09:20:54 -0000 1.123 +++ fetch.c 9 Jul 2014 03:41:16 -0000 @@ -884,10 +884,10 @@ again: ftp_printf(fin, ssl, "GET %s HTTP/1.0\r\n" "Proxy-Authorization: Basic %s%s\r\n%s\r\n\r\n", epath, credentials, buf ? buf : "", - HTTP_USER_AGENT); + httpuseragent); else ftp_printf(fin, ssl, "GET %s HTTP/1.0\r\n%s%s\r\n\r\n", - epath, buf ? buf : "", HTTP_USER_AGENT); + epath, buf ? buf : "", httpuseragent); } else { #ifndef SMALL @@ -945,7 +945,7 @@ again: ftp_printf(fin, ssl, ":%s", port); #endif /* !SMALL */ ftp_printf(fin, ssl, "\r\n%s%s\r\n\r\n", - buf ? buf : "", HTTP_USER_AGENT); + buf ? buf : "", httpuseragent); if (verbose) fprintf(ttyout, "\n"); } @@ -1284,6 +1284,9 @@ auto_fetch(int argc, char *argv[], char char *cp, *url, *host, *dir, *file, *portnum; char *username, *pass, *pathstart; char *ftpproxy, *httpproxy; +#ifndef SMALL + char *uagent = NULL; +#endif /* !SMALL */ int rval, xargc; volatile int argpos; int dirhasglob, filehasglob, oautologin; @@ -1304,6 +1307,13 @@ auto_fetch(int argc, char *argv[], char if ((httpproxy = getenv(HTTP_PROXY)) != NULL && *httpproxy == '\0') httpproxy = NULL; + if (httpuseragent == NULL) + httpuseragent = HTTP_USER_AGENT; +#ifndef SMALL + else + uagent = httpuseragent; +#endif /* !SMALL */ + /* * Loop through as long as there's files to fetch. */ @@ -1580,6 +1590,9 @@ bad_ftp_url: } if (connected && rval != -1) disconnect(0, NULL); +#ifndef SMALL + free(uagent); +#endif /* !SMALL */ return (rval); } Index: ftp.1 =================================================================== RCS file: /cvs/src/usr.bin/ftp/ftp.1,v retrieving revision 1.92 diff -u -p -r1.92 ftp.1 --- ftp.1 25 Jun 2014 06:57:42 -0000 1.92 +++ ftp.1 8 Jul 2014 22:06:04 -0000 @@ -62,6 +62,7 @@ .Op Fl o Ar output .Op Fl S Ar ssl_options .Op Fl s Ar srcaddr +.Op Fl U Ar useragent .Sm off .No http[s]:// Oo Ar user : password No @ .Oc Ar host Oo : Ar port @@ -268,6 +269,11 @@ of the connection. Only useful on systems with more than one address. .It Fl t Enables packet tracing. +.It Fl U Ar useragent +Set +.Ar useragent +as the User-Agent for HTTP(S) URL requests. +If not specified, the default User-Agent is ``OpenBSD ftp''. .It Fl V Disable verbose mode, overriding the default of enabled when input is from a terminal. Index: ftp_var.h =================================================================== RCS file: /cvs/src/usr.bin/ftp/ftp_var.h,v retrieving revision 1.33 diff -u -p -r1.33 ftp_var.h --- ftp_var.h 24 Dec 2013 13:00:59 -0000 1.33 +++ ftp_var.h 12 Jun 2014 19:32:51 -0000 @@ -181,6 +181,7 @@ char *httpport; /* port number to use #ifndef SMALL char *httpsport; /* port number to use for https connections */ #endif /* !SMALL */ +char *httpuseragent; /* user agent for http(s) connections */ char *gateport; /* port number to use for gateftp connections */ jmp_buf toplevel; /* non-local goto stuff for cmd scanner */ Index: main.c =================================================================== RCS file: /cvs/src/usr.bin/ftp/main.c,v retrieving revision 1.87 diff -u -p -r1.87 main.c --- main.c 23 Jan 2014 00:39:15 -0000 1.87 +++ main.c 9 Jul 2014 03:45:03 -0000 @@ -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