summaryrefslogtreecommitdiff
path: root/debian/patches/0135-saned-remotescanners.patch
blob: 19c24f478d168b36a8a1d63e6c7b96964d5da950 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
Description: saned option to report network-attached devices to clients
Author: Jens-U. Mozdzen <jmozdzen@nde.ag>
Author: Dhionel Díaz <ddiaz@cenditel.gob.ve>
Bug: https://alioth.debian.org/tracker/index.php?func=detail&aid=314768&group_id=30186&atid=410366
Last-Update: 2016-04-13
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/doc/saned.man
+++ b/doc/saned.man
@@ -10,6 +10,7 @@
 .I [ n ]
 .B | \-s
 .I [ n ]
+.B | \-r
 .B | \-h
 .B ]
 .SH DESCRIPTION
@@ -37,6 +38,14 @@
 .B saned
 will drop root privileges and run as this user (and group).
 .PP
+If the
+.B \-r
+flag is specified, saned will also report remote scanners (those that are accessed
+via saned's "net" backend) when receiving an inquiry to list all devices. As the
+remote scanner may not be available at the time of the request, enabling this
+option may cause a significant delay, experienced by the remote client.
+Default is not to report those scanners.
+.PP
 The
 .B \-d
 and
@@ -94,6 +103,14 @@
 machine, we strongly recommend using the Netfilter
 \fInf_conntrack_sane\fP module instead.
 .PP
+\fBreexport_remote_scanners\fP = \fI[ true | yes | 1 ]\fP
+Enables reporting remote scanners (those accessed via saned's "net"
+backend) to clients. As the remote scanner may not be available at
+the time of the request, enabling this option may cause a significant
+delay, experienced by the remote client.
+Any value other than "true", "yes" or "1" will keep this option disabled,
+which is the default when this option nor the command line flag "-r" is specified.
+.PP
 The access list is a list of host names, IP addresses or IP subnets
 (CIDR notation) that are permitted to use local SANE devices. IPv6
 addresses must be enclosed in brackets, and should always be specified
--- a/frontend/saned.c
+++ b/frontend/saned.c
@@ -246,6 +246,7 @@
 static int num_handles;
 static int debug;
 static int run_mode;
+static SANE_Bool reexport_remote_scanners_disabled = SANE_TRUE;
 static Handle *handle;
 static union
 {
@@ -1834,7 +1835,7 @@
 
 	reply.status =
 	  sane_get_devices ((const SANE_Device ***) &reply.device_list,
-			    SANE_TRUE);
+			    reexport_remote_scanners_disabled);
 	sanei_w_reply (w, (WireCodecFunc) sanei_w_get_devices_reply, &reply);
       }
       break;
@@ -2697,6 +2698,23 @@
                   DBG (DBG_INFO, "read_config: data port range: %d - %d\n", data_port_lo, data_port_hi);
                 }
             }
+          else if (strstr(config_line, "reexport_remote_scanners") != NULL)
+            {
+              optval = sanei_config_skip_whitespace (++optval);
+	      if ((optval != NULL) && (*optval != '\0'))
+	        {
+		  if (optval == endval)
+		    {
+                      DBG (DBG_ERR, "read_config: invalid value for data_portrange\n");
+                      continue;
+                    }
+		  else if ((strcmp( optval, "yes") == 0) || (strcmp( optval, "true") == 0) ||(strcmp( optval, "1") == 0))
+		    {
+                      reexport_remote_scanners_disabled = SANE_FALSE;
+                      DBG (DBG_INFO, "main: enabled serving remote scanner devices\n");
+		    }
+		}
+            }
         }
       fclose (fp);
       DBG (DBG_INFO, "read_config: done reading config\n");
@@ -3274,35 +3292,43 @@
   numchildren = 0;
   run_mode = SANED_RUN_INETD;
 
-  if (argc >= 2)
-    {
-      if (strncmp (argv[1], "-a", 2) == 0)
-	run_mode = SANED_RUN_ALONE;
-      else if (strncmp (argv[1], "-d", 2) == 0)
-	{
-	  run_mode = SANED_RUN_DEBUG;
-	  log_to_syslog = SANE_FALSE;
-	}
-      else if (strncmp (argv[1], "-s", 2) == 0)
-	run_mode = SANED_RUN_DEBUG;
-      else
-        {
-          printf ("Usage: saned [ -a [ username ] | -d [ n ] | -s [ n ] ] | -h\n");
-          if ((strncmp (argv[1], "-h", 2) == 0) ||
-               (strncmp (argv[1], "--help", 6) == 0))
-            exit (EXIT_SUCCESS);
-          else
-            exit (EXIT_FAILURE);
-        }
-    }
+  int optc;
 
-  if (run_mode == SANED_RUN_DEBUG)
-    {
-      if (argv[1][2])
-	debug = atoi (argv[1] + 2);
+  opterr = 0; /* wir wollen keine fremden Ausgaben */
+
+  do {
+    switch (optc = getopt(argc, argv, "ad:s:r")) {
+
+    case 'a': /* stand-alone */
+      run_mode = SANED_RUN_ALONE;
+      break;
+    case 'd': /* debug */
+      run_mode = SANED_RUN_DEBUG;
+      log_to_syslog = SANE_FALSE;
 
+      debug = atoi( optarg);
       DBG (DBG_WARN, "main: starting debug mode (level %d)\n", debug);
+      break;
+    case 's': /* debug to syslog */
+      run_mode = SANED_RUN_DEBUG;
+
+      debug = atoi( optarg);
+      DBG (DBG_WARN, "main: starting debug mode (level %d)\n", debug);
+      break;
+    case 'r': /* re-export network-attached scanners */
+      reexport_remote_scanners_disabled = SANE_FALSE;
+      DBG (DBG_INFO, "main: enabled serving remote scanner devices\n");
+      break;
+    case '?': /* unknown option */
+      printf ("Usage: saned [ -a [ username ] | -d [ n ] | -s [ n ] ] | -r | -h\n");
+      if ((strncmp (argv[1], "-h", 2) == 0) ||
+           (strncmp (argv[1], "--help", 6) == 0))
+        exit (EXIT_SUCCESS);
+      else
+        exit (EXIT_FAILURE);
+      break;
     }
+  } while (optc != -1);
 
   if (log_to_syslog)
     openlog ("saned", LOG_PID | LOG_CONS, LOG_DAEMON);