<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Hi All,<br>
    <br>
    Thank you for all the help you gave me to get this working!<br>
    <br>
    Here is my tutorial:<br>
    <br>
    -T<br>
    <br>
    <br>
    <div style="text-align: center;">
      <h1 class="page-title">
        How to set up your scanner to work with<br>
        Sane and PDF Studio under Fedora 27 Linux's systemd</h1>
    </div>
    <div>
      References:<br>
         <a href="https://help.ubuntu.com/community/SaneDaemonTutorial">SaneDaemonTutorial</a><br>
         <a
href="https://www.mankier.com/8/saned#Systemd_configuration_for_saned_with_systemd_support_compiled_in">sand
        systemd manual page</a><br>
         <a
        href="https://bugzilla.redhat.com/show_bug.cgi?id=1091566#c8">RHEL:
        saned systemd support</a><br>
         <a
        href="https://wiki.debian.org/SaneOverNetwork#Client_Configuration">SaneOverNetwork</a><br>
      <br>
      <br>
    </div>
    <p><em>
        <b>Background:</b><br>
        <br>
        <b>systemd</b></em> uses "sockets" to replace the defunct <em>xinetd</em>.<br>
      <b>systemd</b> will listen on port 6566 tcp and use <em>saned.socket</em>
      to start an instance of <em><a class="moz-txt-link-abbreviated" href="mailto:saned@.service">saned@.service</a></em> for each request
      to port 6566 tcp
      <br>
      <br>
    </p>
    <p>
      <b>Prerequisites:</b><br>
      <br>
      <em>saned's</em> daemons are required to be installed.<br>
      <b>Fedora 27:</b></p>
    <div style="margin-left: 20px;">
      <pre><code>su root -c "dnf install sane-backends sane-backends-daemon"
</code></pre>
    </div>
    <p>
      <b>Redhat Enterprise Linux and Clones (CentOS, Scientific Linux):</b><br>
      Note: sane-backends is not support under Enterprise Linux due to
      Enterprise Linux's deliberate out of date nature as needed patches
      can not be installed<br>
      <br>
    </p>
    <p>
      <b>Systemd Scripts:</b><br>
      For the systemd configuration we need to add 2 configuration files
      called <em><b>saned.socket</b></em> and <em><b><a class="moz-txt-link-abbreviated" href="mailto:saned@saned.service">saned@saned.service</a></b></em>
      in
      <em><b>/etc/systemd/system</b></em> with:<br>
    </p>
    <div style="margin-left: 20px;">
      ownership of <em><b>root.root</b></em>, and<br>
      permissions of <em><b>755</b></em><br>
      <br>
    </div>
    <p><em><b>saned.socket</b></em></p>
    <div style="margin-left: 20px;">
      <pre><code>[Unit]
Description=saned incoming socket

[Socket]
ListenStream=6566
Accept=yes
MaxConnections=1
connect_timeout=60

[Install]
WantedBy=sockets.target
</code></pre>
      <br>
    </div>
    <p><em><b><a class="moz-txt-link-abbreviated" href="mailto:saned@saned.service">saned@saned.service</a></b></em></p>
    <div style="margin-left: 20px;">
      <pre><code>[Unit]
Description=Scanner Service
Requires=saned.socket

[Service]
ExecStart=/usr/sbin/saned
User=saned
Group=saned
StandardInput=null
StandardOutput=syslog
StandardError=syslog
# Environment=SANE_CONFIG_DIR=/etc/sane.d SANE_DEBUG_DLL=255
</code></pre>
      <br>
    </div>
    <p>To create the daemon's user and group accounts:</p>
    <div style="margin-left: 20px;">
      <pre><code><em>su root -c "useradd saned"
su root -c "useradd -g saned saned"</em>
</code></pre>
      <br>
    </div>
    <p>To set ownership and permissions of these two file:</p>
    <div style="margin-left: 20px;">
      <pre><code><em>su root -c "chown root.root /etc/systemd/system/saned.service /etc/systemd/system/saned.socket"
su root -c "chmod 644 /etc/systemd/system/saned.service /etc/systemd/system/saned.socket"</em>
</code></pre>
      <br>
    </div>
    <p>Add you local host name to /etc/sane.d/saned.conf.<br>
      For Example (substitute your actual network for the one shown):</p>
    <div style="margin-left: 20px;">
      <pre><code># The hostname matching is not case-sensitive. 
192.168.255.0/24
localhost
</code></pre>
      <br>
    </div>
    <p>Add your local hostname resolved in /etc/hosts (get your host
      name from the "hostname" command).<br>
      For Example:</p>
    <div style="margin-left: 20px;">
      <pre><code>127.0.0.1   foo.bar.local foo localhost localhost.localdomain localhost4 localhost4.localdomain4
</code></pre>
      <br>
    </div>
    <p>Add the following entry to /etc/services.</p>
    <div style="margin-left: 20px;">
      <pre><code>sane-port 6566/tcp # SANE network scanner daemon
</code></pre>
      <br>
    </div>
    <p>To active these services at boot:</p>
    <div style="margin-left: 20px;">
      <pre><code><em>su root -c "systemctl enable saned.socket"
su root -c "useradd -g saned saned"</em>
</code></pre>
      <br>
    </div>
    <p>To manually start the sand service:</p>
    <div style="margin-left: 20px;">
      <pre><code><em>su root -c "systemctl start saned.socket"</em></code>
</pre>
      <br>
    </div>
    <p>SELinux on Fedora 27:</p>
    <div style="margin-left: 20px;">
      <pre><code><em>
SELinux Policy must 3.13.1-283.21 or later
To check your version SELinux Policy:
   rpm -qa selinux-policy
   
To update SELinux Policy:
   su root -c "dnf upgrade selinux-policy"
   
su root -c "ausearch -c 'systemd' --raw | audit2allow -M my-systemd"
su root -c "semodule -X 300 -i my-systemd.pp"
</em></code>
</pre>
    </div>
    <p>To test the sand service ("$" means to test as a standard user):</p>
    <div style="margin-left: 20px;">
      <pre><code><em><b>$ nmap -p 6566 192.168.255.10</b>

<i>Starting Nmap 7.60 ( <a class="moz-txt-link-freetext" href="https://nmap.org">https://nmap.org</a> ) at 2018-02-03 01:26 PST
Nmap scan report for rn1.rent-a-nerd.local (192.168.255.10)
Host is up (0.00025s latency).

PORT     STATE SERVICE
6566/tcp open  sane-port

Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds</i>


<b>$ xsane net:192.168.255.10</b></em></code>
</pre>
      <br>
    </div>
    <br>
    <br>
    <br>
  </body>
</html>