From 849e48c58b76b98e25be6d0ee458bd2940b186c8 Mon Sep 17 00:00:00 2001 From: Guillaume Girol Date: Sun, 25 Feb 2024 12:00:00 +0000 Subject: [PATCH] saned: add option to allow relaying network scanners My intended use case is the following: I want to compile saned backends with different libraries (for example glibc) than a specific application (as if it were a chroot of another distro version). This application cannot dlopen sane backends because of the library mismatch. The specific application will be built with a stripped down libsane that only has the net backend, and therefore very few dependencies. The net backend points to saned. saned has a full config and set of backends, and is responsible for exporting all scanners to the application. This option allows to reexport network scanners this way. I only have to make sure saned does not contact itself. --- doc/saned.man | 12 ++++++++++++ frontend/saned.c | 11 +++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/doc/saned.man b/doc/saned.man index 400ab6c62..f7f6504f7 100644 --- a/doc/saned.man +++ b/doc/saned.man @@ -92,6 +92,18 @@ will request .B saned to detach from the console and run in the background. +.TP +.BR \-n ", " \-\-allow\-network +allows +.B saned +to use network scanners. By default this is forbidden to prevent +.B saned +from contacting itself. When enabled, the configuration of the +.BR sane-net (5) +backend should not mention the address on which +.B saned +is listening. + .TP .BR \-o ", " \-\-once requests that diff --git a/frontend/saned.c b/frontend/saned.c index d71d428c5..842a74181 100644 --- a/frontend/saned.c +++ b/frontend/saned.c @@ -254,6 +254,7 @@ static int debug; static int run_mode; static int run_foreground; static int run_once; +static int allow_network; static int data_connect_timeout = 4000; static Handle *handle; static char *bind_addr; @@ -1869,7 +1870,7 @@ process_request (Wire * w) reply.status = sane_get_devices ((const SANE_Device ***) &reply.device_list, - SANE_TRUE); + !allow_network); sanei_w_reply (w, (WireCodecFunc) sanei_w_get_devices_reply, &reply); } break; @@ -3436,6 +3437,7 @@ static void usage(char *me, int err) " -a, --alone[=user] equal to `-l -D -u user'\n" " -l, --listen run in standalone mode (listen for connection)\n" " -u, --user=user run as `user'\n" + " -n, --allow-network allow saned to use network scanners\n" " -D, --daemonize run in background\n" " -o, --once exit after first client disconnects\n" " -d, --debug=level set debug level `level' (default is 2)\n" @@ -3457,6 +3459,7 @@ static struct option long_options[] = {"alone", optional_argument, 0, 'a'}, {"listen", no_argument, 0, 'l'}, {"user", required_argument, 0, 'u'}, + {"allow-network", no_argument, 0, 'n'}, {"daemonize", no_argument, 0, 'D'}, {"once", no_argument, 0, 'o'}, {"debug", required_argument, 0, 'd'}, @@ -3488,8 +3491,9 @@ main (int argc, char *argv[]) run_mode = SANED_RUN_INETD; run_foreground = SANE_TRUE; run_once = SANE_FALSE; + allow_network = SANE_FALSE; - while((c = getopt_long(argc, argv,"ha::lu:Dod:eb:p:B:", long_options, &long_index )) != -1) + while((c = getopt_long(argc, argv,"ha::lu:nDod:eb:p:B:", long_options, &long_index )) != -1) { switch(c) { case 'a': @@ -3504,6 +3508,9 @@ main (int argc, char *argv[]) case 'u': user = optarg; break; + case 'n': + allow_network = SANE_TRUE; + break; case 'D': run_foreground = SANE_FALSE; break;