Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/httpd allow the -I option to be useful in non-daemon...



details:   https://anonhg.NetBSD.org/src/rev/9e4a41dc5d1a
branches:  trunk
changeset: 771270:9e4a41dc5d1a
user:      mrg <mrg%NetBSD.org@localhost>
date:      Thu Nov 17 22:09:12 2011 +0000

description:
allow the -I option to be useful in non-daemon mode, by letting it force
the returned port number

diffstat:

 libexec/httpd/bozohttpd.8 |  14 +++++++++-----
 libexec/httpd/bozohttpd.c |  26 +++++++++++++++++++-------
 libexec/httpd/main.c      |  10 +++++-----
 3 files changed, 33 insertions(+), 17 deletions(-)

diffs (110 lines):

diff -r 271c5f2dde05 -r 9e4a41dc5d1a libexec/httpd/bozohttpd.8
--- a/libexec/httpd/bozohttpd.8 Thu Nov 17 20:04:25 2011 +0000
+++ b/libexec/httpd/bozohttpd.8 Thu Nov 17 22:09:12 2011 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: bozohttpd.8,v 1.29 2011/04/24 07:18:59 jmmv Exp $
+.\"    $NetBSD: bozohttpd.8,v 1.30 2011/11/17 22:09:12 mrg Exp $
 .\"
 .\"    $eterna: bozohttpd.8,v 1.99 2010/09/20 22:26:28 mrg Exp $
 .\"
@@ -135,14 +135,18 @@
 .Fl X .
 .It Fl I Ar port
 Causes
+.Nm
+to use
 .Ar port
-to use used as the port to bind daemon mode.
-The default is the
+instead of the default
 .Dq http
 port.
-This option is only valid with the
+When used with the
 .Fl b
-option.
+option, it changes the bound port.
+Otherwise it forces redirections to use this port instead of the
+value obtained via
+.Xr getsockname 2 .
 .It Fl i Ar address
 Causes
 .Ar address
diff -r 271c5f2dde05 -r 9e4a41dc5d1a libexec/httpd/bozohttpd.c
--- a/libexec/httpd/bozohttpd.c Thu Nov 17 20:04:25 2011 +0000
+++ b/libexec/httpd/bozohttpd.c Thu Nov 17 22:09:12 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bozohttpd.c,v 1.28 2011/08/27 15:33:59 joerg Exp $     */
+/*     $NetBSD: bozohttpd.c,v 1.29 2011/11/17 22:09:12 mrg Exp $       */
 
 /*     $eterna: bozohttpd.c,v 1.176 2010/09/20 22:26:28 mrg Exp $      */
 
@@ -563,14 +563,26 @@
        if (addr != NULL)
                request->hr_remoteaddr = bozostrdup(request->hr_httpd, addr);
        slen = sizeof(ss);
-       if (getsockname(0, (struct sockaddr *)(void *)&ss, &slen) < 0)
-               port = NULL;
-       else {
-               if (getnameinfo((struct sockaddr *)(void *)&ss, slen, NULL, 0,
-                               bufport, sizeof bufport, NI_NUMERICSERV) == 0)
-                       port = bufport;
+
+       /*
+        * Override the bound port from the request value, so it works even
+        * if passed through a proxy that doesn't rewrite the port.
+        */
+       if (httpd->bindport) {
+               if (strcmp(httpd->bindport, "80") != 0)
+                       port = httpd->bindport;
                else
                        port = NULL;
+       } else {
+               if (getsockname(0, (struct sockaddr *)(void *)&ss, &slen) < 0)
+                       port = NULL;
+               else {
+                       if (getnameinfo((struct sockaddr *)(void *)&ss, slen, NULL, 0,
+                                       bufport, sizeof bufport, NI_NUMERICSERV) == 0)
+                               port = bufport;
+                       else
+                               port = NULL;
+               }
        }
        if (port != NULL)
                request->hr_serverport = bozostrdup(request->hr_httpd, port);
diff -r 271c5f2dde05 -r 9e4a41dc5d1a libexec/httpd/main.c
--- a/libexec/httpd/main.c      Thu Nov 17 20:04:25 2011 +0000
+++ b/libexec/httpd/main.c      Thu Nov 17 22:09:12 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.3 2011/08/27 15:33:59 joerg Exp $   */
+/*     $NetBSD: main.c,v 1.4 2011/11/17 22:09:12 mrg Exp $     */
 
 /*     $eterna: main.c,v 1.4 2010/07/11 00:34:28 mrg Exp $     */
 /* from: eterna: bozohttpd.c,v 1.159 2009/05/23 02:14:30 mrg Exp       */
@@ -198,12 +198,15 @@
                        bozo_set_pref(&prefs, "index.html", optarg);
                        break;
 
+               case 'I':
+                       bozo_set_pref(&prefs, "port number", optarg);
+                       break;
+
 #ifdef NO_DAEMON_MODE
                case 'b':
                case 'e':
                case 'f':
                case 'i':
-               case 'I':
                case 'P':
                        bozo_err(&httpd, 1, "Daemon mode is not enabled");
                        /* NOTREACHED */
@@ -233,9 +236,6 @@
                        bozo_set_pref(&prefs, "bind address", optarg);
                        break;
 
-               case 'I':
-                       bozo_set_pref(&prefs, "port number", optarg);
-                       break;
                case 'P':
                        bozo_set_pref(&prefs, "pid file", optarg);
                        break;



Home | Main Index | Thread Index | Old Index