<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://wiki.darenet.org/skins/common/feed.css?12"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.darenet.org/index.php?action=history&amp;feed=atom&amp;title=Using_Chroot_With_IRCD</id>
		<title>Using Chroot With IRCD - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.darenet.org/index.php?action=history&amp;feed=atom&amp;title=Using_Chroot_With_IRCD"/>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/index.php?title=Using_Chroot_With_IRCD&amp;action=history"/>
		<updated>2026-04-05T20:48:55Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.15.1</generator>

	<entry>
		<id>http://wiki.darenet.org/index.php?title=Using_Chroot_With_IRCD&amp;diff=2243&amp;oldid=prev</id>
		<title>Secretagent:&amp;#32;New page: ==Introduction==  Many system administrators like to run certain daemons within a &quot;jail,&quot; a secure area of the file system that the daemon supposedly cannot break out of.  That way, if the...</title>
		<link rel="alternate" type="text/html" href="http://wiki.darenet.org/index.php?title=Using_Chroot_With_IRCD&amp;diff=2243&amp;oldid=prev"/>
				<updated>2008-04-25T03:34:44Z</updated>
		
		<summary type="html">&lt;p&gt;New page: ==Introduction==  Many system administrators like to run certain daemons within a &amp;quot;jail,&amp;quot; a secure area of the file system that the daemon supposedly cannot break out of.  That way, if the...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
Many system administrators like to run certain daemons within a&lt;br /&gt;
&amp;quot;jail,&amp;quot; a secure area of the file system that the daemon supposedly&lt;br /&gt;
cannot break out of.  That way, if the daemon is compromised somehow,&lt;br /&gt;
the attacker cannot get out and affect the rest of the system in any&lt;br /&gt;
way.  There are problems with this--the standard UNIX way of doing&lt;br /&gt;
this is with the chroot() call, which has been deprecated by the&lt;br /&gt;
UNIX98 standard.  Moreover, if an attacker has root within the jail,&lt;br /&gt;
it is trivial to get *out* of the jail in most circumstances.&lt;br /&gt;
Nevertheless, it is still often a good idea, and some systems can use&lt;br /&gt;
more secure jails than other systems.&lt;br /&gt;
&lt;br /&gt;
Older versions of ircd supported chroot() operation within the server&lt;br /&gt;
itself, but these were fraught with problems--chroot() can only be&lt;br /&gt;
called by a process running as root, so ircd had to be started as&lt;br /&gt;
root, typically by making it setuid, and would then have to drop those&lt;br /&gt;
privileges after calling chroot().  Moreover, the design of the server&lt;br /&gt;
would require that the server binary be in DPATH, or the /RESTART&lt;br /&gt;
command would not work.  In fact, /RESTART still wouldn't work,&lt;br /&gt;
because the server would then attempt to change directories to a DPATH&lt;br /&gt;
relative to the current root directory--and of course, the root&lt;br /&gt;
directory often would not contain the shared libraries necessary for&lt;br /&gt;
the ircd to even start.&lt;br /&gt;
&lt;br /&gt;
==Configuring the Server For Use With Chroot==&lt;br /&gt;
&lt;br /&gt;
In the versions of ircd starting with u2.10.11, all the setuid and&lt;br /&gt;
chroot() code has been removed from the server.  It is still possible&lt;br /&gt;
to cause the daemon to run in a chroot() jail, however, through the&lt;br /&gt;
use of a wrapper script.  This requires making all paths compiled in&lt;br /&gt;
to the server be relative to the new root directory; fortunately, this&lt;br /&gt;
can be done by giving the configure script the --with-chroot=&amp;lt;dir&amp;gt;&lt;br /&gt;
option.  The &amp;lt;dir&amp;gt; argument specifies to configure where the root&lt;br /&gt;
directory will be, and the server restart path, data path,&lt;br /&gt;
configuration file, and debug log files will all be modified to be&lt;br /&gt;
relative to this root directory.  If the data path or configuration&lt;br /&gt;
files cannot be made relative to the specified root directory,&lt;br /&gt;
configure will issue an error message and exit; if the server restart&lt;br /&gt;
path is not relative to the specified root directory, configure will&lt;br /&gt;
issue a warning.&lt;br /&gt;
&lt;br /&gt;
The various paths are made relative to the root directory through the&lt;br /&gt;
use of simple edits to their string representation.  As an example,&lt;br /&gt;
assume that we will be using the root directory &amp;quot;/home/ircd&amp;quot;; if the&lt;br /&gt;
data path is &amp;quot;/home/ircd/lib,&amp;quot; the data path that will be compiled&lt;br /&gt;
into the server will be simply &amp;quot;/lib&amp;quot;; if, on the other hand, the&lt;br /&gt;
specified data path were &amp;quot;/usr/local/lib/ircd,&amp;quot; configure would issue&lt;br /&gt;
an error, since there is no way to make the data path relative to the&lt;br /&gt;
specified root directory.&lt;br /&gt;
&lt;br /&gt;
==Preparing the Root Directory==&lt;br /&gt;
&lt;br /&gt;
Most modern operating systems use shared libraries.  When using&lt;br /&gt;
chroot(), these libraries are searched for relative to the new root&lt;br /&gt;
directory, and they must be present in order for a program to&lt;br /&gt;
execute.  The root directory must be prepared, therefore, by coping&lt;br /&gt;
these libraries into the correct place.  A script for this purpose has&lt;br /&gt;
been provided in tools/mkchroot.  This script relies on the command&lt;br /&gt;
&amp;quot;ldd,&amp;quot; which is used to report which shared libraries are used by a&lt;br /&gt;
particular program; it also relies on ldd printing out the full path&lt;br /&gt;
to those libraries.  If either of these conditions is not met, it will&lt;br /&gt;
be necessary to track down the libraries by hand and place them into&lt;br /&gt;
the appropriate locations.  The tools/mkchroot script takes as its&lt;br /&gt;
first argument the path to the directory to be prepared as a root&lt;br /&gt;
directory; following this argument should be a list of programs that&lt;br /&gt;
will be running with that directory as the root directory.&lt;br /&gt;
&lt;br /&gt;
==Using the Wrapper==&lt;br /&gt;
&lt;br /&gt;
Also provided in the tools subdirectory are the sources for a simple&lt;br /&gt;
wrapper program that can be used to start ircd.  The program can be&lt;br /&gt;
compiled by executing &amp;quot;cc -o wrapper tools/wrapper.c&amp;quot;; it must be run&lt;br /&gt;
as root, but do not install it as root, since that would be a major&lt;br /&gt;
security risk.  This tool can be used to set the hard limit on file&lt;br /&gt;
descriptors, as well as a root directory, and so may be useful to the&lt;br /&gt;
administrator even if chroot() operation is not desired.  A summary of&lt;br /&gt;
the command line options for the wrapper tool can be obtained with the&lt;br /&gt;
&amp;quot;-h&amp;quot; option.  To set the file descriptor limit, use the &amp;quot;-l&amp;quot; option&lt;br /&gt;
followed by the desired number of file descriptors; to select an&lt;br /&gt;
alternative root directory, use &amp;quot;-c&amp;quot; followed by the desired root&lt;br /&gt;
directory.  You must use the &amp;quot;-u&amp;quot; option to specify a user name (or&lt;br /&gt;
user ID) that the command should be run as; otherwise, the command&lt;br /&gt;
will be run as root, which is not what you want (and why you should&lt;br /&gt;
never install this program setuid root).  Follow the command line&lt;br /&gt;
arguments with &amp;quot;--&amp;quot; and the full path to the command that you wish to&lt;br /&gt;
run, along with arguments to that command.  The &amp;quot;--&amp;quot; tells the wrapper&lt;br /&gt;
program to stop interpreting options, and is very important if you&lt;br /&gt;
must give the command any options.&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Secretagent</name></author>	</entry>

	</feed>