<?xml version="1.0" encoding="UTF-8"?>
<!-- **************************************************************************
.... For copyright and licensing terms, see the file named COPYING.
.... **************************************************************************
.-->
<?xml-stylesheet href="docbook-xml.css" type="text/css"?>

<refentry id="ucspi-socket-rules-check">

<refmeta xmlns:xi="http://www.w3.org/2001/XInclude">
<refentrytitle>ucspi-socket-rules-check</refentrytitle>
<manvolnum>1</manvolnum>
<refmiscinfo class="manual">user commands</refmiscinfo>
<refmiscinfo class="source">nosh</refmiscinfo>
<xi:include href="version.xml" />
</refmeta>

<refnamediv>
<refname>ucspi-socket-rules-check</refname>
<refpurpose>check local socket connections against access control rules</refpurpose>
</refnamediv>

<refsynopsisdiv>
<cmdsynopsis>
<command>ucspi-socket-rules-check</command>
<arg choice='opt'>--verbose</arg>
<arg choice='req'><replaceable>next-prog</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>

<refsection><title>Description</title>

<para>
<command>ucspi-socket-rules-check</command> expects a process environment that has been set up per the UCSPI conventions by <citerefentry><refentrytitle>local-stream-socket-accept</refentrytitle><manvolnum>1</manvolnum></citerefentry> or <citerefentry><refentrytitle>tcp-socket-accept</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
It checks what is contained in the environment against a database of access control rules, and (if the access checks pass) it then chain loads to <replaceable>next-prog</replaceable> with the <citerefentry><refentrytitle>execvp</refentrytitle><manvolnum>3</manvolnum></citerefentry> function.
If the access checks fail, it exits without running anything.
</para>

<para>
<replaceable>next-prog</replaceable> may contain its own command line options, which <command>ucspi-socket-rules-check</command> will ignore.
</para>

<refsection><title>Searching for access control rules</title>

<para>
Overall behaviour is guided by the value of the <envar>PROTO</envar> environment variable.
</para>

<itemizedlist>

<listitem>
<para>
If <envar>PROTO</envar> has the value <code>UNIX</code>:
</para>

<orderedlist>

<listitem>
<para>
If the value of <envar>UNIXREMOTEEUID</envar> is the same as the process's effective UID and a directory named <filename>uid/self/</filename> exists then access is granted according to the directory contents (continuing to search if access is neither granted nor denied by the directory).
</para>
</listitem>

<listitem>
<para>
If the value of <envar>UNIXREMOTEEGID</envar> is the same as the process's effective GID and a directory named <filename>gid/self/</filename> exists then access is granted according to the directory contents (continuing to search if access is neither granted nor denied by the directory).
</para>
</listitem>

<listitem>
<para>
If a directory named <filename>uid/<replaceable>$UNIXREMOTEEUID</replaceable></filename> exists then access is granted according to the directory contents (continuing to search if access is neither granted nor denied by the directory).
</para>
</listitem>

<listitem>
<para>
If a directory named <filename>gid/<replaceable>$UNIXREMOTEEGID</replaceable></filename> exists then access is granted according to the directory contents (continuing to search if access is neither granted nor denied by the directory).
</para>
</listitem>

<listitem>
<para>
If a directory named <filename>uid/default</filename> exists then access is granted according to the directory contents (continuing to search if access is neither granted nor denied by the directory).
</para>
</listitem>

<listitem>
<para>
Otherwise access is denied.
</para>
</listitem>

</orderedlist>

</listitem>

<listitem>
<para>
If <envar>PROTO</envar> has the value <code>TCP</code>:
</para>

<orderedlist>

<listitem>

<para>
A group of directories, forming progressively larger supernets of the IP address, are checked.
</para>

<itemizedlist>
<listitem>
<para>
If the value of <envar>TCPREMOTEIP</envar> is a human-readable IPv4 address, then, for each prefix length <code>N</code> from 32 down to 0 an <code>IP</code> string is constructed using the netmask <code><replaceable>$TCPREMOTEIP</replaceable>/<replaceable>$N</replaceable></code>, and if a directory named <filename>ip4/<replaceable>$IP</replaceable>_<replaceable>$N</replaceable></filename> exists then access is granted according to the directory contents (continuing to search if access is neither granted nor denied by the directory).
</para>
<para>
Thus <filename>ip4/0.0.0.0_0</filename> is a catch-all rule.
</para>
</listitem>
<listitem>
<para>
If the value of <envar>TCPREMOTEIP</envar> is a human-readable IPv6 address, then, for each prefix length <code>N</code> from 128 down to 0 an <code>IP</code> string is constructed using the netmask <code><replaceable>$TCPREMOTEIP</replaceable>/<replaceable>$N</replaceable></code>, and if a directory named <filename>ip6/<replaceable>$IP</replaceable>_<replaceable>$N</replaceable></filename> exists then access is granted according to the directory contents (continuing to search if access is neither granted nor denied by the directory).
</para>
<para>
Thus <filename>ip6/::_0</filename> is a catch-all rule.
</para>
</listitem>
</itemizedlist>

</listitem>

<listitem>
<para>
Otherwise access is denied.
</para>
</listitem>

</orderedlist>

</listitem>

<listitem>
<para>
If <envar>PROTO</envar> has the value <code>TCP6</code>:
</para>

<orderedlist>

<listitem>

<para>
A group of directories, forming progressively larger supernets of the IP address, are checked.
</para>

<itemizedlist>
<listitem>
<para>
If the value of <envar>TCP6REMOTEIP</envar> is a human-readable IPv4 address, then, for each prefix length <code>N</code> from 32 down to 0 an <code>IP</code> string is constructed using the netmask <code><replaceable>$TCP6REMOTEIP</replaceable>/<replaceable>$N</replaceable></code>, and if a directory named <filename>ip4/<replaceable>$IP</replaceable>_<replaceable>$N</replaceable></filename> exists then access is granted according to the directory contents (continuing to search if access is neither granted nor denied by the directory).
</para>
<para>
Thus <filename>ip4/0.0.0.0_0</filename> is a catch-all rule.
</para>
</listitem>
<listitem>
<para>
If the value of <envar>TCP6REMOTEIP</envar> is a human-readable IPv6 address, then, for each prefix length <code>N</code> from 128 down to 0 an <code>IP</code> string is constructed using the netmask <code><replaceable>$TCP6REMOTEIP</replaceable>/<replaceable>$N</replaceable></code>, and if a directory named <filename>ip6/<replaceable>$IP</replaceable>_<replaceable>$N</replaceable></filename> exists then access is granted according to the directory contents (continuing to search if access is neither granted nor denied by the directory).
</para>
<para>
Thus <filename>ip6/::_0</filename> is a catch-all rule.
</para>
</listitem>
</itemizedlist>

</listitem>

<listitem>
<para>
Otherwise access is denied.
</para>
</listitem>

</orderedlist>

</listitem>
<listitem>
<para>
Otherwise access is denied.
</para>
</listitem>

</itemizedlist>

</refsection>

<refsection><title>Access control rule directories</title>

<para>
In any given directory:
</para>

<itemizedlist>
<listitem>
<para>
If a file named <filename>allow</filename> exists then access is granted.
If a file named <filename>settings</filename> exists then it is read into the process's environment as if by <citerefentry><refentrytitle>read-conf</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
The <filename>settings</filename> file can be used, for example, to set the <envar>AXFR</envar> environment variable for <citerefentry><refentrytitle>axfrdns</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
</para>
</listitem>
<listitem>
<para>
If a file named <filename>deny</filename> exists then access is denied.
</para>
</listitem>
<listitem>
<para>
Otherwise access is neither granted nor denied.
</para>
</listitem>
</itemizedlist>

</refsection>

</refsection><refsection><title>Author</title>
<para><author><personname><firstname>Jonathan</firstname> <surname>de Boyne Pollard</surname></personname></author></para>
</refsection>

</refentry>
