Running a scanner in a freeNAS jail?

keboose

Explorer
Joined
Mar 5, 2016
Messages
92
I have a USB hotplug scanner: a Canon DR-2510C. I would like to use it to automate scanning important documents and receipts to my NAS, and I'm nearly there, but have hit a wall on the last few steps.

I'm aware that Freenas allowing USB device pass through to jails is kinda sketchy, but I've gotten 90% of the way there already. I made a jail (11.2 release), and enabled these flags in the settings:
devfs_ruleset=3 mount_devfs=[checked] allow_mount=[checked] allow_mount_devfs=[checked]

Inside the jail, I installed three packages and dependents: sane, sane-backends and scanbuttond. With only those steps, the scanner is mostly functional. By running the command scanimage with the appropriate flags (as root), I can scan anything placed in the scanner input tray to file. It was trivial to write a script that batch scans documents and names them with the current date.

I would like to take it one step further. The package scanbuttond will (on a normal system) monitor attached devices, and run scripts based on button presses on the scanner itself. That sounds WAY better than having to ssh into my NAS and send an iocage command to run my script every time I want to scan something, but the service hangs when I try to run it (you can run it in the forground withscanbuttond -f). There is no helpful output that I know of except a single line in /var/log/messages:
scanbuttond: no known scanner found yet, waiting for device to be attached
That means at least part of it is that only the jail root user can see USB devices, and I'm pretty sure the package added its own user and/or group, so it is probably trying to run as those.

I think that is the first major hurdle, at least. How would I change the permissions in the jail to allow another user to see USB devices?
 

gt2416

Patron
Joined
Feb 4, 2018
Messages
262
I dont have any experience with scanbutton but when you install it asks you to attach your scanner using the file /etc/devd.conf and then restarting devd. Have you done that ? Heres the message from the installer:

If you are having trouble getting your scanner detected try uncommenting one
of the following lines in /usr/local/etc/scanbuttond/initscanner.sh:

scanimage -n
or
sane-find-scanner > /dev/null 2> /dev/null

If your scanner is connected via a hot-plug capable technology (e.g. USB)
you can conveniently enable scanbuttond every time you attach you scanner by
using devd. In order to do so you may add the following lines to your
/etc/devd.conf and restart devd after you are done.
(Make sure to replace device-name, vendor, product and back-end name to
something that matches your environment)

attach 20 {
device-name "ugen[0-9]+";
match "vendor" "0x04a9";
match "product" "0x220e";
action "/usr/local/bin/scanbuttond \
-s /usr/local/etc/scanbuttond/buttonpressed.sh \
-S /usr/local/etc/scanbuttond/initscanner.sh \
-b /usr/local/lib/libscanbtnd-backend_plustek.so";
};

detach 20 {
device-name "ugen[0-9]+";
match "vendor" "0x04a9";
match "product" "0x220e";
action "/usr/bin/killall scanbuttond";
};
 

keboose

Explorer
Joined
Mar 5, 2016
Messages
92
The example given is to automatically start the scanbuttond service when a specific device is attached. This makes sense, as it seems the service will hang if no scanner is attached.

My problem is that scanbuttond won't work even when a scanner IS attached. Considering I can use the scanner as root using scanimage, My belief is that the service is not using the proper permissions. I need to either force the service to run as root, or give the correct user permission to see USB devices.

Edit: the program scanbd is a similar package that does the same thing as scanbuttond. When I try to run it, I get the error:
Code:
scanbd: DBus connection error: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory

Is that more helpful? I don't care which one I can get working, tbh.
 
Last edited:

keboose

Explorer
Joined
Mar 5, 2016
Messages
92
As an update to this thread, I made the tiniest bit of progress by getting past one error and finding another.

I made a new jail with the flags set like in the OP. This time I installed the dependencies listed in the scanbd github README (except for 'libusb1', can't really find that one) from repository instead of building them. I found I also needed to install the packages pkgconfig, libudev-devd, and gmake, then cloned the git project and built it, first configuring with the configure script: ./configure --enable-scanbuttond --enable-udev

I found that the error from my last post is because dbus is not running. Fixed that with sysrc dbus_enable="YES" and service dbus start.

So that's cool, one error down, unknown how many to go.

Now when I try to run scanbd (scanbd -f, I'm using the default config file at /usr/local/etc/scanbd/scanbd.conf), this is the output:
Code:
scanbd: debug on: level: 7
scanbd: dropping privs to uid saned
scanbd: dropping privs to gid saned
scanbd: drop privileges to gid: 194
scanbd: Running as effective gid 194
scanbd: drop privileges to uid: 194
scanbd: Running as effective uid 194
scanbd: dbus_init
scanbd: dbus init mutex
scanbd: dbus match type='signal',interface='org.freedesktop.Hal.Manager'
scanbd: Loading /usr/local/lib/scanbd/scanbuttond/backends/meta.so
scanbd: meta-backend: init
scanbd: libusbi: initializing...
scanbd: Loading /usr/local/lib/scanbd/scanbuttond/backends/hp3500.so
scanbd: meta-backend: attaching backend: HP3500 USB
scanbd: hp3500-backend: init
scanbd: Loading /usr/local/lib/scanbd/scanbuttond/backends/snapscan.so
scanbd: meta-backend: attaching backend: Snapscan USB
scanbd: snapscan-backend: init
scanbd: Loading /usr/local/lib/scanbd/scanbuttond/backends/niash.so
scanbd: meta-backend: attaching backend: Niash USB
scanbd: niash-backend: init
scanbd: Loading /usr/local/lib/scanbd/scanbuttond/backends/epson_vphoto.so
scanbd: meta-backend: attaching backend: Epson VX00 Photo USB
scanbd: epson-vphoto-backend: init
scanbd: Scanning for local-only devices
scanbd: Can't get the scbtn device list
scanbd: device list null
scanbd: start_scbtn_threads
scanbd: start the threads (0)
scanbd: start dbus thread
scanbd: Not Primary Owner (-1)
scanbd: Name Error (Connection ":1.1" is not allowed to own the service "de.kmux.scanbd.server" due to security policies in the configuration file)
scanbd: udev init
scanbd: get udev monitor
scanbd: start udev thread
scanbd: udev thread started                # Note: this is where the program hangs. I hit CTRL+C after a while of nothing happening
scanbd: sig_term/int_handler called with signal 2
scanbd: stop_scbtn_threads
scanbd: waiting ...
scanbd: stop dbus thread
scanbd: stop udev thread
scanbd: join udev thread
scanbd: cleanup device handler
scanbd: close udev monitor
scanbd: close udev
scanbd: exiting scanbd


As a reminder, this is the output from scanimage -L:
Code:
device `canon_dr:libusb:001:005' is a CANON DR-2510C scanner
and I CAN use the scanner if I send the scanimage command manually.
 
Top