[Pkg-ocaml-maint-commits] r2647 - in /trunk/projects/approx/trunk: Makefile approx.ml debian/NEWS debian/approx.init debian/changelog default_config.ml default_config.mli doc/approx.conf.5 etc/approx.conf ifaddr.c netif.mli server.ml server.ml.parallel server.ml.serial server.mli

ecc-guest at users.alioth.debian.org ecc-guest at users.alioth.debian.org
Fri Apr 28 17:19:28 UTC 2006


Author: ecc-guest
Date: Fri Apr 28 17:19:27 2006
New Revision: 2647

URL: http://svn.debian.org/wsvn/?sc=1&rev=2647
Log:
added "interface" configuration variable to allow listening only
on a specific network interface

added simple-minded support for file URIs, using the same logic as FTP

The server is now started as root by the init script, and then drops
privileges to user approx after binding its socket. This allows approx
to listen on port 80, for example.

Added:
    trunk/projects/approx/trunk/ifaddr.c
    trunk/projects/approx/trunk/netif.mli
Removed:
    trunk/projects/approx/trunk/server.ml.parallel
    trunk/projects/approx/trunk/server.ml.serial
Modified:
    trunk/projects/approx/trunk/Makefile
    trunk/projects/approx/trunk/approx.ml
    trunk/projects/approx/trunk/debian/NEWS
    trunk/projects/approx/trunk/debian/approx.init
    trunk/projects/approx/trunk/debian/changelog
    trunk/projects/approx/trunk/default_config.ml
    trunk/projects/approx/trunk/default_config.mli
    trunk/projects/approx/trunk/doc/approx.conf.5
    trunk/projects/approx/trunk/etc/approx.conf
    trunk/projects/approx/trunk/server.ml
    trunk/projects/approx/trunk/server.mli

Modified: trunk/projects/approx/trunk/Makefile
URL: http://svn.debian.org/wsvn/trunk/projects/approx/trunk/Makefile?rev=2647&op=diff
==============================================================================
--- trunk/projects/approx/trunk/Makefile (original)
+++ trunk/projects/approx/trunk/Makefile Fri Apr 28 17:19:27 2006
@@ -7,7 +7,7 @@
 export OCAMLFLAGS = -warn-error A
 
 define PROJ_server
-    SOURCES = util.ml config.ml default_config.ml log.ml url.ml control_file.ml release.ml server.ml version.ml approx.ml
+    SOURCES = util.ml config.ml default_config.ml log.ml url.ml control_file.ml release.ml ifaddr.c netif.mli server.ml version.ml approx.ml
     INCDIRS = +pcre +syslog +netstring +cgi +nethttpd
     LIBS = unix pcre syslog netstring cgi nethttpd
     RESULT = approx

Modified: trunk/projects/approx/trunk/approx.ml
URL: http://svn.debian.org/wsvn/trunk/projects/approx/trunk/approx.ml?rev=2647&op=diff
==============================================================================
--- trunk/projects/approx/trunk/approx.ml (original)
+++ trunk/projects/approx/trunk/approx.ml Fri Apr 28 17:19:27 2006
@@ -57,6 +57,7 @@
   in
   info_message "Version: %s %s" Version.name Version.number;
   info_message "Config file: %s" config_file;
+  info_message "Interface: %s" interface;
   info_message "Port: %d" port;
   info_message "Cache: %s" cache_dir;
   info_message "Interval:%s%s"
@@ -377,7 +378,7 @@
   in
   match meth with
   | "http" -> download_http url
-  | "ftp" -> download_ftp url
+  | "ftp" | "file" -> download_ftp url
   | _ -> invalid_arg "unsupported URL method"
 
 (* Remove any files from the cache that have been invalidated
@@ -503,7 +504,7 @@
   try
     Sys.chdir cache_dir;
     print_config ();
-    Server.main port proxy_service
+    Server.main ~user: "approx" ~interface port proxy_service
   with e ->
     exception_message e;
     exit 1

Modified: trunk/projects/approx/trunk/debian/NEWS
URL: http://svn.debian.org/wsvn/trunk/projects/approx/trunk/debian/NEWS?rev=2647&op=diff
==============================================================================
--- trunk/projects/approx/trunk/debian/NEWS (original)
+++ trunk/projects/approx/trunk/debian/NEWS Fri Apr 28 17:19:27 2006
@@ -1,3 +1,12 @@
+approx (2.06) unstable; urgency=low
+
+A new configuration variable, interface, forces approx to listen for
+connections on a specific network interface only.
+
+The approx server can now listen on privileged ports such as port 80.
+
+File: URIs are now supported in the approx.conf file.
+
 approx (2.00) unstable; urgency=low
 
 Approx now uses curl subprocesses to download files from remote

Modified: trunk/projects/approx/trunk/debian/approx.init
URL: http://svn.debian.org/wsvn/trunk/projects/approx/trunk/debian/approx.init?rev=2647&op=diff
==============================================================================
--- trunk/projects/approx/trunk/debian/approx.init (original)
+++ trunk/projects/approx/trunk/debian/approx.init Fri Apr 28 17:19:27 2006
@@ -24,7 +24,7 @@
 #	Function that starts the daemon/service.
 #
 d_start() {
-	start-stop-daemon --start --quiet --exec $DAEMON --chuid approx:approx
+	start-stop-daemon --start --quiet --exec $DAEMON
 }
 
 #

Modified: trunk/projects/approx/trunk/debian/changelog
URL: http://svn.debian.org/wsvn/trunk/projects/approx/trunk/debian/changelog?rev=2647&op=diff
==============================================================================
--- trunk/projects/approx/trunk/debian/changelog (original)
+++ trunk/projects/approx/trunk/debian/changelog Fri Apr 28 17:19:27 2006
@@ -1,3 +1,15 @@
+approx (2.06) unstable; urgency=low
+
+  * Added "interface" configuration variable to allow listening only
+    on a specific network interface, as requested by Romain Lenglet
+    <rlenglet at users.forge.objectweb.org> (closes: #352025)
+  * Added simple-minded support for file URIs, using the same logic as FTP
+  * The server is now started as root by the init script, and then drops
+    privileges to user approx after binding its socket. This allows approx
+    to listen on port 80, as requested by Andreas John <aj at net-lab.net>
+
+ -- Eric Cooper <ecc at cmu.edu>  Mon, 24 Apr 2006 16:09:22 -0400
+
 approx (2.05) unstable; urgency=low
 
   * Factor out all uses of curl command (missed one in previous fix)

Modified: trunk/projects/approx/trunk/default_config.ml
URL: http://svn.debian.org/wsvn/trunk/projects/approx/trunk/default_config.ml?rev=2647&op=diff
==============================================================================
--- trunk/projects/approx/trunk/default_config.ml (original)
+++ trunk/projects/approx/trunk/default_config.ml Fri Apr 28 17:19:27 2006
@@ -9,6 +9,7 @@
 
 let () = read config_file
 
+let interface = get "interface" ~default: "any"
 let port = get_int "port" ~default: 9999 (* for compatibility with apt-proxy *)
 let interval = get_int "interval" ~default: 720 (* minutes *)
 let max_wait = get_int "max_wait" ~default: 10 (* seconds *)

Modified: trunk/projects/approx/trunk/default_config.mli
URL: http://svn.debian.org/wsvn/trunk/projects/approx/trunk/default_config.mli?rev=2647&op=diff
==============================================================================
--- trunk/projects/approx/trunk/default_config.mli (original)
+++ trunk/projects/approx/trunk/default_config.mli Fri Apr 28 17:19:27 2006
@@ -5,6 +5,7 @@
 val config_file : string
 val cache_dir : string
 
+val interface : string
 val port : int
 val interval : int  (* minutes *)
 val max_wait : int  (* seconds *)

Modified: trunk/projects/approx/trunk/doc/approx.conf.5
URL: http://svn.debian.org/wsvn/trunk/projects/approx/trunk/doc/approx.conf.5?rev=2647&op=diff
==============================================================================
--- trunk/projects/approx/trunk/doc/approx.conf.5 (original)
+++ trunk/projects/approx/trunk/doc/approx.conf.5 Fri Apr 28 17:19:27 2006
@@ -19,6 +19,10 @@
 Comments start with a "#" character and continue to the end of the line.
 .PP
 The following names have special meaning:
+.IP interface
+Specifies the name of the network interface on which the
+.BR approx (8)
+server listens for HTTP requests (default: any)
 .IP port
 Specifies the TCP port on which the
 .BR approx (8)

Modified: trunk/projects/approx/trunk/etc/approx.conf
URL: http://svn.debian.org/wsvn/trunk/projects/approx/trunk/etc/approx.conf?rev=2647&op=diff
==============================================================================
--- trunk/projects/approx/trunk/etc/approx.conf (original)
+++ trunk/projects/approx/trunk/etc/approx.conf Fri Apr 28 17:19:27 2006
@@ -1,6 +1,7 @@
 # The following are the defaults, so there is no need
 # to uncomment them unless you want a different value.
 
+#interface	any
 #port		9999
 #interval	720
 #max_wait	10

Added: trunk/projects/approx/trunk/ifaddr.c
URL: http://svn.debian.org/wsvn/trunk/projects/approx/trunk/ifaddr.c?rev=2647&op=file
==============================================================================
--- trunk/projects/approx/trunk/ifaddr.c (added)
+++ trunk/projects/approx/trunk/ifaddr.c Fri Apr 28 17:19:27 2006
@@ -1,0 +1,47 @@
+/* approx: proxy server for Debian archive files
+   Copyright (C) 2006  Eric C. Cooper <ecc at cmu.edu>
+   Released under the GNU General Public License */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+
+static int
+ifaddr(char *name, /* OUT */ struct in_addr *addr)
+{
+    int s = socket(PF_INET, SOCK_STREAM, 0);
+    if (s == -1)
+	return 0;
+    struct ifreq r;
+    int i;
+    for (i = 0; i < sizeof(r.ifr_name); i++) {
+	if ((r.ifr_name[i] = name[i]) == '\0')
+	    break;
+    }
+    i = ioctl(s, SIOCGIFADDR, &r);
+    close(s);
+    if (i == 0 && r.ifr_addr.sa_family == AF_INET) {
+	*addr = ((struct sockaddr_in *)&r.ifr_addr)->sin_addr;
+	return 1;
+    } else {
+	return 0;
+    }
+}
+
+#include <caml/alloc.h>
+#include <caml/memory.h>
+#include <caml/mlvalues.h>
+
+value
+inet_addr_of_interface(value name)
+{
+    CAMLparam1(name);
+    struct in_addr addr;
+    if (ifaddr(String_val(name), &addr))
+	CAMLreturn(alloc_inet_addr(&addr));
+    else
+	raise_not_found();
+}

Added: trunk/projects/approx/trunk/netif.mli
URL: http://svn.debian.org/wsvn/trunk/projects/approx/trunk/netif.mli?rev=2647&op=file
==============================================================================
--- trunk/projects/approx/trunk/netif.mli (added)
+++ trunk/projects/approx/trunk/netif.mli Fri Apr 28 17:19:27 2006
@@ -1,0 +1,1 @@
+external inet_addr_of_interface : string -> Unix.inet_addr = "inet_addr_of_interface"

Modified: trunk/projects/approx/trunk/server.ml
URL: http://svn.debian.org/wsvn/trunk/projects/approx/trunk/server.ml?rev=2647&op=diff
==============================================================================
--- trunk/projects/approx/trunk/server.ml (original)
+++ trunk/projects/approx/trunk/server.ml Fri Apr 28 17:19:27 2006
@@ -29,10 +29,31 @@
     method config_reactor_synch = `Write
   end
 
-let main port service =
-  let session input _output =
-    let fd = descr_of_in_channel input in
+let serial = false
+
+let main ~user ~interface port service =
+  let sock = socket PF_INET SOCK_STREAM 0 in
+  setsockopt sock SO_REUSEADDR true;
+  let addr =
+    if interface = "any" then inet_addr_any
+    else Netif.inet_addr_of_interface interface
+  in
+  bind sock (ADDR_INET (addr, port));
+  listen sock 10;
+  setuid (Unix.getpwnam user).Unix.pw_uid;  (* drop privileges *)
+  while true do
+    let fd, _ = accept sock in
     set_nonblock fd;
-    process_connection config fd service
-  in
-  establish_server session (ADDR_INET (inet_addr_any, port))
+    if serial then
+      process_connection config fd service
+    else
+      match fork () with
+      | 0 ->
+	  if fork () <> 0 then exit 0;
+	  close sock;
+	  process_connection config fd service;
+	  exit 0
+      | pid ->
+	  close fd;
+	  ignore (waitpid [] pid)
+  done

Modified: trunk/projects/approx/trunk/server.mli
URL: http://svn.debian.org/wsvn/trunk/projects/approx/trunk/server.mli?rev=2647&op=diff
==============================================================================
--- trunk/projects/approx/trunk/server.mli (original)
+++ trunk/projects/approx/trunk/server.mli Fri Apr 28 17:19:27 2006
@@ -1,1 +1,1 @@
-val main : int -> 'a Nethttpd_types.http_service -> unit
+val main : user:string -> interface:string -> int -> 'a Nethttpd_types.http_service -> unit




More information about the Pkg-ocaml-maint-commits mailing list