<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>G-Loaded Journal &#187; Linux</title>
	<atom:link href="http://www.g-loaded.eu/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.g-loaded.eu</link>
	<description>An open-source software and technology related journal</description>
	<lastBuildDate>Fri, 11 May 2012 13:37:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
		<item>
		<title>Restore original configuration files from RPM packages</title>
		<link>http://www.g-loaded.eu/2012/03/26/restore-original-configuration-files-from-rpm-packages/</link>
		<comments>http://www.g-loaded.eu/2012/03/26/restore-original-configuration-files-from-rpm-packages/#comments</comments>
		<pubDate>Mon, 26 Mar 2012 20:24:27 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Maintenance]]></category>
		<category><![CDATA[RPM]]></category>
		<category><![CDATA[System]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/?p=2619</guid>
		<description><![CDATA[By default, when the user installs software through the RPM Package Manager or through YUM, usually, the software&#8217;s configuration files included in the RPM do not replace the existing configuration files on the filesystem, but, if they differ from those that currently exist, they are saved with the rpmnew extension. In case the rpm is [...]]]></description>
			<content:encoded><![CDATA[<p>By default, when the user installs software through the <em>RPM Package Manager</em> or through <em>YUM</em>, usually, the software&#8217;s configuration files included in the RPM do not replace the existing configuration files on the filesystem, but, if they differ from those that currently exist, they are saved with the <em>rpmnew</em> extension. In case the rpm is already installed and is the latest version, the quickest way to get the original configuration file back is to uninstall and install the package again. Today, while on CentOS 6.2, I needed to restore the original <code>/etc/sysctl.conf</code> file, which is part of the <em>initscripts</em> package. In this case, uninstalling initscripts was out of the question as it would also remove half of the installed packages due to dependencies. So, I grabbed the chance to figure out and document what would be the quickest and easiest way to restore <code>/etc/sysctl.conf</code>, excluding downloading the package itself and <a href="http://www.g-loaded.eu/2008/01/28/how-to-extract-rpm-or-deb-packages/" title="How to extract the files contained in an RPM package">extract the RPM contents</a>. Fortunately, as soon as I opened yum&#8217;s man page and having spotted the new <strong>reinstall</strong> command, the solution was quite obvious.<br />
<span id="more-2619"></span><br />
For completeness, I hereby document the whole procedure that involves the verification and restoration of the original <code>/etc/sysctl.conf</code> hoping that new users might find these notes helpful.</p>
<p>First of all, I needed to know whether the <code>/etc/sysctl.conf</code> I had on my box differed from the original one. But, before doing that, I had to know which RPM package had installed that file. So, I used the <strong>rpm command</strong> to query this file:</p>
<pre class="console">
# rpm -qf /etc/sysctl.conf
initscripts-9.03.27-1.el6.centos.1.i686
</pre>
<p>So, the <em>initscripts</em> package had installed <code>/etc/sysctl.conf</code>.</p>
<p>Then I verified the initscripts package:</p>
<pre class="console">
# rpm -V initscripts
S.5....T.  c /etc/sysconfig/init
S.5....T.  c /etc/sysctl.conf
</pre>
<p>According to the following table:</p>
<pre class="codesnp">
S file Size differs
M Mode differs (includes permissions and file type)
5 MD5 sum differs
D Device major/minor number mismatch
L readLink(2) path mismatch
U User ownership differs
G Group ownership differs
T mTime differs
P caPabilities differ
</pre>
<p>the attributes: size, MD5 checksum and the modification time of <code>/etc/sysctl.conf</code> that existed on my system differed from the attributes of the original file.</p>
<p>Since I had no idea the exact changes I had made to that file at some earlier time, I needed to restore the original and re-modify it from scratch. The new yum &#8220;<strong>reinstall</strong>&#8221; command could be used to to do this quite easily.</p>
<p>First, I kept a copy of the current file:</p>
<pre class="console">
# mv /etc/sysctl.conf /etc/sysctl.conf.modified
</pre>
<p>Then I reinstalled initscripts using YUM&#8217;s reinstall command:</p>
<pre class="console">
# yum reinstall initscripts
Loaded plugins: downloadonly, fastestmirror, priorities
Setting up Reinstall Process
Loading mirror speeds from cached hostfile
 * base: ftp.ntua.gr
 * epel: ftp.ntua.gr
 * extras: ftp.ntua.gr
 * ius: mirror.rackspace.co.uk
 * updates: centosr3.centos.org
6 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package initscripts.i686 0:9.03.27-1.el6.centos.1 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
 Package                              Arch                          Version                                           Repository                        Size
=============================================================================================================================================================
Reinstalling:
 initscripts                          i686                          9.03.27-1.el6.centos.1                            updates                          934 k

Transaction Summary
=============================================================================================================================================================
Reinstall     1 Package(s)

Total download size: 934 k
Installed size: 5.4 M
Is this ok [y/N]: y
Downloading Packages:
initscripts-9.03.27-1.el6.centos.1.i686.rpm                                                                                           | 934 kB     00:02
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : initscripts-9.03.27-1.el6.centos.1.i686                                                                                                   1/1

Installed:
  initscripts.i686 0:9.03.27-1.el6.centos.1

Complete!
</pre>
<p>Verify the initscripts package again:</p>
<pre class="console">
# rpm -V initscripts
S.5....T.  c /etc/sysconfig/init
</pre>
<p>No verification errors for <code>/etc/sysctl.conf</code>. Note that reinstalling the package did not touch the <code>/etc/sysconfig/init</code> file. It has been mentioned previously that rpm packages do not overwrite existing configuration files.</p>
<p>I had the original file back and I could then start customizing it from scratch.</p>
<p class="cc-block"><em><a href="http://www.g-loaded.eu/2012/03/26/restore-original-configuration-files-from-rpm-packages/">Restore original configuration files from RPM packages</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.</p>
<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2009/04/09/yum-priorities-configuration-for-a-centos-desktop/" rel="bookmark">YUM-Priorities Configuration for a CentOS Desktop</a></li>
<li><a href="http://www.g-loaded.eu/2006/04/05/how-to-build-rpm-packages-on-fedora/" rel="bookmark">How To Build RPM Packages on Fedora</a></li>
<li><a href="http://www.g-loaded.eu/2008/01/28/how-to-extract-rpm-or-deb-packages/" rel="bookmark">How to extract RPM or DEB packages</a></li>
<li><a href="http://www.g-loaded.eu/2011/05/12/running-supervisor-3-on-centos-5/" rel="bookmark">Running supervisor 3 on CentOS 5</a></li>
<li><a href="http://www.g-loaded.eu/2011/03/02/rhel-kernel-source-released-with-patches-already-applied/" rel="bookmark">RHEL kernel source released with patches already applied</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2012/03/26/restore-original-configuration-files-from-rpm-packages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Running supervisor 3 on CentOS 5</title>
		<link>http://www.g-loaded.eu/2011/05/12/running-supervisor-3-on-centos-5/</link>
		<comments>http://www.g-loaded.eu/2011/05/12/running-supervisor-3-on-centos-5/#comments</comments>
		<pubDate>Thu, 12 May 2011 04:56:52 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[RHEL]]></category>
		<category><![CDATA[RPM]]></category>
		<category><![CDATA[Servers]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/?p=2263</guid>
		<description><![CDATA[It&#8217;s been a long time since the last time I checked the available software for managing long running processes. Software in this particular area has evolved and, after some research and testing on a virtual machine, I tried to install supervisord in a CentOS 5.6 box. Unfortunately, no RPM package exists for the latest 3.X [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a long time since the last time I checked the available software for managing long running processes. Software in this particular area has evolved and, after some research and testing on a virtual machine, I tried to install <a href="http://supervisord.org/">supervisord</a> in a CentOS 5.6 box. Unfortunately, no RPM package exists for the latest 3.X version, so I decided to go through the procedure to rebuild the <em>supervisor RPM</em> from the Fedora development tree, since v3.X has some really cool features I cannot do without.<br />
<span id="more-2263"></span><br />
If you haven&#8217;t built an RPM package before, you will need to go through a simple procedure in order to <a href="http://www.g-loaded.eu/2006/04/05/how-to-build-rpm-packages-on-fedora/">prepare an RPM building environment</a>. It is highly recommended that you build your packages in a separate box, dedicated to this kind of work, and also use a typical user and not <em>root</em> for building. So, let&#8217;s get the source RPM of <strong>supervisord</strong> from a Fedora Rawhide mirror:</p>
<pre class="console">
wget ftp://ftp.cc.uoc.gr/mirrors/linux/fedora/linux/development/rawhide/source/SRPMS/supervisor-3.0-0.4.a10.fc16.src.rpm
</pre>
<p>The simplest way to build an RPM for our CentOS release is to use the <code>--rebuild</code> option of <code>rpmbuild</code>:</p>
<pre class="console">
rpmbuild --rebuild supervisor-3.0-0.4.a10.fc16.src.rpm
</pre>
<p>Wait a few seconds for it to finish and then your binary RPM package will be in <code>~/&lt;your_building_env&gt;/RPMS/...</code>. </p>
<p>To satisfy dependencies, you will also need the package <strong>python-meld3</strong>. So, download and rebuild it:</p>
<pre class="console">
wget ftp://ftp.cc.uoc.gr/mirrors/linux/fedora/linux/development/rawhide/source/SRPMS/python-meld3-0.6.7-4.fc16.src.rpm
rpmbuild --rebuild python-meld3-0.6.7-4.fc16.src.rpm
</pre>
<p>Having built RPM packages for <strong>supervisor</strong> and <strong>python-meld3</strong>, you can now transfer them to a testing box and install them:</p>
<pre class="console">
yum localinstall /path/to/supervisor.rpm /path/to/python-meld3
yum install python-elementtree
</pre>
<p>We also installed <strong>elementtree</strong> as this is a dependency missing from the supervisor spec file (note to self: file a bug report).</p>
<p>Finally, try to start supervisord:</p>
<pre class="console">
/etc/init.d/supervisord start
</pre>
<p>Surprisingly, it complains about the missing elementtree!</p>
<pre class="codesnp">
Starting supervisord: Traceback (most recent call last):
  File "/usr/bin/supervisord", line 5, in ?
    from pkg_resources import load_entry_point
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 2479, in ?
    working_set.require(__requires__)
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 585, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 483, in resolve
    raise DistributionNotFound(req)  # XXX put more info here
pkg_resources.DistributionNotFound: elementtree
</pre>
<p>Checking the requirements file at: <code>/usr/lib/python2.4/site-packages/supervisor-3.0a10-py2.4.egg-info/requires.txt</code> there are no special version requirements:</p>
<pre class="codesnp">
meld3 >= 0.6.5
elementtree

[iterparse]
cElementTree >= 1.0.2
</pre>
<p>After some investigation on the supervisor-users mailing list, I found a message that <a href="http://lists.supervisord.org/pipermail/supervisor-users/2007-October/000106.html">indicated</a> that <em>setuptools.setup()</em> should be used instead of <em>distutils.core.setup()</em> in the <strong>setup.py</strong> script.</p>
<p>So, the dependency resolution depends on the way the package has been installed! I didn&#8217;t even bother to patch setup.py&#8230; Knowing that the dependencies are correctly installed, I commented out the <code>elementtree</code> line and also the <code>meld3</code> line as this caused the same error.</p>
<p>So, my <code>/usr/lib/python2.4/site-packages/supervisor-3.0a10-py2.4.egg-info/requires.txt</code> file looks like this:</p>
<pre class="codesnp">
#meld3 >= 0.6.5
#elementtree

[iterparse]
cElementTree >= 1.0.2
</pre>
<p>Now supervisor starts without errors:</p>
<pre class="console">
# /etc/init.d/supervisord start
Starting supervisord:                                      [  OK  ]
# cat /var/log/supervisor/supervisord.log
2011-05-12 02:56:08,221 CRIT Supervisor running as root (no user in config file)
2011-05-12 02:56:08,267 INFO RPC interface 'supervisor' initialized
2011-05-12 02:56:08,267 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2011-05-12 02:56:08,271 INFO daemonizing the supervisord process
2011-05-12 02:56:08,272 INFO supervisord started with pid 21337
</pre>
<p>This is what it takes to run <strong>supervisord 3</strong> in CentOS 5 or RHEL 5. If you have any comments and suggestions, please let me know in the comments below.</p>
<p class="cc-block"><em><a href="http://www.g-loaded.eu/2011/05/12/running-supervisor-3-on-centos-5/">Running supervisor 3 on CentOS 5</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.</p>
<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2009/12/18/high-cpu-usage-centos-guest-virtualbox-vmware/" rel="bookmark">High CPU usage while running CentOS as guest on Virtualbox or VMware</a></li>
<li><a href="http://www.g-loaded.eu/2009/04/07/sticking-with-centos-rpmforge-and-yum-priorities-for-now/" rel="bookmark">Sticking with CentOS, RPMforge and yum-priorities for now</a></li>
<li><a href="http://www.g-loaded.eu/2009/04/09/yum-priorities-configuration-for-a-centos-desktop/" rel="bookmark">YUM-Priorities Configuration for a CentOS Desktop</a></li>
<li><a href="http://www.g-loaded.eu/2011/02/28/awaiting-centos-6/" rel="bookmark">Awaiting CentOS 6</a></li>
<li><a href="http://www.g-loaded.eu/2006/11/20/my-running-dog/" rel="bookmark">My running dog</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2011/05/12/running-supervisor-3-on-centos-5/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>RHEL kernel source released with patches already applied</title>
		<link>http://www.g-loaded.eu/2011/03/02/rhel-kernel-source-released-with-patches-already-applied/</link>
		<comments>http://www.g-loaded.eu/2011/03/02/rhel-kernel-source-released-with-patches-already-applied/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 14:06:00 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Kernel]]></category>
		<category><![CDATA[Red Hat]]></category>
		<category><![CDATA[RPM]]></category>
		<category><![CDATA[Scientific Linux]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/?p=2183</guid>
		<description><![CDATA[Red Hat used to release its kernel SRPM package including a tarball of the vanilla kernel sources and a set of custom patches. This made it possible to rebuild the kernel with or without patches or with a custom selection of patches. It seems that things have changed and Red Hat now releases the Red [...]]]></description>
			<content:encoded><![CDATA[<p>Red Hat used to release its kernel SRPM package including a tarball of the vanilla kernel sources and a set of custom patches. This made it possible to rebuild the kernel with or without patches or with a custom selection of patches. It seems that things have changed and Red Hat now releases the Red Hat Enterprise Linux kernel source already patched. This basically makes things less flexible for those who wish to apply a custom selection of Red Hat patches to the vanilla kernel source or build upon Red Hat&#8217;s patches and create derivative works.<br />
<span id="more-2183"></span><br />
It is quite clear why Red Hat makes this move. It doesn&#8217;t want to provide its work on the kernel free of cost to those companies that make commercial rebuilds (see Oracle Enterprise Linux). I won&#8217;t try to criticize this move because I don&#8217;t see any valid reason for criticizing this business decision. Personally, I don&#8217;t think it complicates things more for <a href="http://centos.org/">CentOS</a> and <a href="https://www.scientificlinux.org/">Scientific Linux</a>, since there is no kernel development taking place in these projects. On the other hand, it might have a negative impact on any cooperation on the kernel development among the various Linux distributions.</p>
<p>There is an <a href="http://lwn.net/Articles/430098/">ongoing discussion</a> about it at LWN you might find interesting.</p>
<p class="cc-block"><em><a href="http://www.g-loaded.eu/2011/03/02/rhel-kernel-source-released-with-patches-already-applied/">RHEL kernel source released with patches already applied</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.</p>
<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2005/12/14/the-complete-fedora-kernel-headers/" rel="bookmark">The Complete Fedora Kernel Headers</a></li>
<li><a href="http://www.g-loaded.eu/2005/12/20/build-a-single-native-kernel-module/" rel="bookmark">Build a single native kernel module</a></li>
<li><a href="http://www.g-loaded.eu/2006/09/09/kernel-2617-and-lirc_gpio-driver/" rel="bookmark">Kernel 2.6.17 and lirc_gpio driver</a></li>
<li><a href="http://www.g-loaded.eu/2005/12/15/get-my-kernel-headers-script/" rel="bookmark">Get my kernel headers script</a></li>
<li><a href="http://www.g-loaded.eu/2010/04/16/software-that-detects-violations-of-open-source-licenses/" rel="bookmark">Software that detects violations of open source licenses</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2011/03/02/rhel-kernel-source-released-with-patches-already-applied/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Awaiting CentOS 6</title>
		<link>http://www.g-loaded.eu/2011/02/28/awaiting-centos-6/</link>
		<comments>http://www.g-loaded.eu/2011/02/28/awaiting-centos-6/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 11:30:11 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/?p=2154</guid>
		<description><![CDATA[I feel that the long awaited CentOS 6 will be out soon. This is a very important release for all the things I am involved with and have to do with computers. CentOS 5 was perfect, but I had to maintain several custom builds of RPMs, mainly rebuilds of Fedora RPMs plus some private builds, [...]]]></description>
			<content:encoded><![CDATA[<p>I feel that the long awaited <strong>CentOS 6</strong> will be out soon. This is a very important release for all the things I am involved with and have to do with computers. CentOS 5 was perfect, but I had to maintain several custom builds of RPMs, mainly rebuilds of Fedora RPMs plus some private builds, and also several patches of Python applications which were not compatible with Python 2.4, which ships with CentOS 5. The 6th version of CentOS will eliminate the need to maintain so much custom software. I&#8217;ve already downloaded the RHEL 6 Server ISO image from Red Hat and checked it in Virtualbox. I am so satisfied with the quality and features of the 6.X series, that I seriously think I should stick with it for good, even after it reaches EOL. This is something I had been thinking about for the last months. Of course there are some things, like security, I want to examine thoroughly before going that way, but I will post more on this topic in a future post.</p>
<p class="cc-block"><em><a href="http://www.g-loaded.eu/2011/02/28/awaiting-centos-6/">Awaiting CentOS 6</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.</p>
<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2009/12/18/high-cpu-usage-centos-guest-virtualbox-vmware/" rel="bookmark">High CPU usage while running CentOS as guest on Virtualbox or VMware</a></li>
<li><a href="http://www.g-loaded.eu/2011/05/12/running-supervisor-3-on-centos-5/" rel="bookmark">Running supervisor 3 on CentOS 5</a></li>
<li><a href="http://www.g-loaded.eu/2009/10/05/fedora-server-vs-centos/" rel="bookmark">Fedora Server vs CentOS</a></li>
<li><a href="http://www.g-loaded.eu/2008/12/11/centos-debian-freebsd-opensolaris/" rel="bookmark">CentOS, Debian, FreeBSD, OpenSolaris</a></li>
<li><a href="http://www.g-loaded.eu/2009/04/09/yum-priorities-configuration-for-a-centos-desktop/" rel="bookmark">YUM-Priorities Configuration for a CentOS Desktop</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2011/02/28/awaiting-centos-6/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Caching Nameserver using dnsmasq</title>
		<link>http://www.g-loaded.eu/2010/09/18/caching-nameserver-using-dnsmasq/</link>
		<comments>http://www.g-loaded.eu/2010/09/18/caching-nameserver-using-dnsmasq/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 21:44:25 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Service]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/?p=1907</guid>
		<description><![CDATA[dnsmasq is a lightweight, open-source DNS forwarder and DHCP server. In this article we go through how to prepare the system in order to run dnsmasq and also how to configure the latter as a caching-only DNS server. A configuration file is also provided as a drop-in replacement for the default dnsmasq.conf that ships with [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.thekelleys.org.uk/dnsmasq/doc.html">dnsmasq</a> is a lightweight, open-source DNS forwarder and DHCP server. In this article we go through how to prepare the system in order to run <em>dnsmasq</em> and also how to configure the latter as a <strong>caching-only</strong> <abbr title="Domain Name System">DNS</abbr> server. A configuration file is also provided as a drop-in replacement for the default <code>dnsmasq.conf</code> that ships with your system. dnsmasq is available in most Linux distributions. This article was written while using CentOS, so it is safe to say that it also fully covers RHEL, Fedora and generally the whole Red Hat family of operating systems and possibly Novell&#8217;s SLES and OpenSUSE. Small modifications of the invoked commands may be needed for Debian, Ubuntu and other systems.<br />
<span id="more-1907"></span></p>
<h4>Is a caching nameserver really important?</h4>
<p>There is some controversy about the real benefits of using a caching name server in a system, either desktop or server. In this article we keep controversy out of the discussion and focus on the performance improvement the caching of DNS information can offer to a system while performing specific tasks. For instance, a caching nameserver allows a web browser to acquire DNS information from the local DNS cache, provided that this information has already been cached, without the need to access any public DNS servers, which results in faster web browsing. Similarly, in a server environment, services like spam filters often need to perform many DNS queries for the same hostnames. The latency of the communication with the remote nameserver may add up to the total time of email processing.</p>
<h4>BIND vs dnsmasq</h4>
<p><em>BIND</em> is the flagship of DNS servers with large deployments around the globe. I have used BIND for many years as  a <strong>caching nameserver</strong>, even on my desktop, until I realized it is overkill to use BIND this way. There are lighter solutions, even all-in-one software like <strong>dnsmasq</strong>, that seem to be more suitable for setting up local DNS caching.</p>
<h4>System preparation</h4>
<p>So, let&#8217;s get started with the system preparation before going into the details of the dnsmasq configuration.</p>
<p>First of all, we need to install dnsmasq:</p>
<pre class="console">yum install dnsmasq</pre>
<p>dnsmasq, when run as <code>root</code>, is designed to <em>drop privileges</em> and run as an unprivileged user. By default, this user is <code>nobody</code>. We use a dedicated system user to run dnsmasq.</p>
<p>Run the following commands as <code>root</code> to create such an unprivileged system user and group named <em>dnsmasq</em>:</p>
<pre class="console">
groupadd -r dnsmasq
useradd -r -g dnsmasq dnsmasq
</pre>
<p>The above should be enough.</p>
<h4>Configuration</h4>
<p>All dnsmasq configuration options go into <code>/etc/dnsmasq.conf</code>. Here we write this file from scratch, so if you need to keep a copy of the original that ships with your distribution, do so with:</p>
<pre class="console">
cp /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
</pre>
<p>Now, let&#8217;s get started with adding our own dnsmasq configuration in <code>/etc/dnsmasq.conf</code>.</p>
<p>First of all, we set some options regarding the <strong>basic server operation</strong> like the interface and port on which it should bind, the unprivileged user that should run the service and a <abbr title="Process ID">PID</abbr> file:</p>
<pre class="codesnp">
listen-address=127.0.0.1
port=53
bind-interfaces
user=dnsmasq
group=dnsmasq
pid-file=/var/run/dnsmasq.pid
</pre>
<p>The <strong>bind-interfaces</strong> directive instructs dnsmasq to bind only to the network interface specified in the <strong>listen-address</strong> directive.</p>
<p>Next comes <strong>logging</strong>.</p>
<p>By default, dnsmasq sends its log messages to the <em>DAEMON</em> syslog facility (<em>LOCAL0</em> when operating in debug mode). We go with the defaults here, but keep in mind that a separate log file can be set as it is shown in the configuration snippet below (currently commented out):</p>
<pre class="codesnp">
#log-facility=/var/log/dnsmasq.log
#log-queries
</pre>
<p>Logging to file requires some extra configuration for proper log rotation. For more information, please read <a href="#LoggingToFile">Appendix II</a>.</p>
<p>Finally, we set the options that configure dnsmasq&#8217;s <strong>name resolution</strong> and <strong>caching</strong> operations.</p>
<p>The following directives prevent dnsmasq from forwarding plain names (without any dots) or addresses in the non-routed address space to the parent nameservers.</p>
<pre class="codesnp">
domain-needed
bogus-priv
</pre>
<p>The <strong>no-hosts</strong> directive also instructs dnsmasq not to read any hostnames from <code>/etc/hosts</code>. In most systems, <code>/etc/hosts</code> is queried before a DNS service is used by the system for name lookups. So, all plain name to private IP mappings should normally be added in <code>/etc/hosts</code>. If this is not what you want, then take a look at the <em>expand-hosts</em> and <em>domain</em> directives.</p>
<pre class="codesnp">
no-hosts
</pre>
<p>Set the maximum number of <strong>concurrent DNS queries</strong>. The default value is 150. Adjust to your needs.</p>
<pre class="codesnp">
dns-forward-max=150
</pre>
<p>Set the <strong>size</strong> of the dnsmasq cache. The default is to keep 150 hostnames. By setting the cache size to 0 disables the feature (this is not what we really want). Again, adjust this value according to your needs.</p>
<pre class="codesnp">
cache-size=1000
</pre>
<p>The following directive controls whether negative caching should be enabled or not. Negative caching allows dnsmasq to remember &#8220;<em>no such domain</em>&#8221; answers from the parent nameservers, so it does not query for the same non-existent hostnames again and again. This is probably useful for spam filters or MTA services. By default, negative caching is enabled. To disable, un-comment the following directive.</p>
<pre class="codesnp">
#no-negcache
</pre>
<p>The <strong>neg-ttl</strong> directive sets a default <abbr title="Time-To-Live">TTL</abbr> value to add to negative replies from the parent nameservers, in case these replies do not contain TTL information. If neg-ttl is not set and a negative reply from a parent DNS server does not contain TTL information, then dnsmasq will not cache the reply. Here we set the default TTL to 3600 seconds. Again, adjust to your specific needs.</p>
<pre class="codesnp">
neg-ttl=3600
</pre>
<p>Here we use a separate file where dnsmasq reads the IPs of the parent nameservers from. The syntax is the same as in <code>/etc/resolv.conf</code>. We do this to facilitate the manipulation of the parent nameservers that should be used by dnsmasq by using, for example, an external script. The filename we use here is <code>resolv.dnsmasq</code>, but this can be changed to your liking. We also set the <strong>no-poll</strong> directive here to prevent dnsmasq from polling the &#8216;resolv&#8217; file for changes.</p>
<pre class="codesnp">
resolv-file=/etc/resolv.dnsmasq
no-poll
</pre>
<p>A full configuration file containing all the above configuration, which can can be used as a drop-in replacement of the default <code>/etc/dnsmasq.conf</code>, can be found in <a href="#FullConfigurationFile">Appendix I</a>.</p>
<h4>Upstream Nameservers</h4>
<p>We have used a separate file to store the IPs of the parent nameservers; that is <code>/etc/resolv.dnsmasq</code>. Using the same syntax as in <code>/etc/resolv.conf</code> add the nameserver IP addresses in resolv.dnsmasq. For example:</p>
<pre class="codesnp">
nameserver 192.168.0.252
nameserver 192.168.0.253
nameserver 192.168.0.254
</pre>
<p>Note that we still need to make a change in <code>/etc/resolv.conf</code> before the system starts using dnsmasq for domain name lookups. Read on&#8230;</p>
<h4>Starting dnsmasq</h4>
<p>In order to start dnsmasq, run as root:</p>
<pre class="console">
/etc/init.d/dnsmasq start
</pre>
<p>Check the syslog or the dnsmasq logfile (if used) for any error messages.</p>
<p>If everything seems to be OK, set the dnsmasq service to start on boot:</p>
<pre class="console">
chkconfig dnsmasq on
</pre>
<p>This command might be Red-Hat specific, so consult your distribution&#8217;s documentation about how to set services to start on boot.</p>
<h4>Switch name resolution to dnsmasq</h4>
<p>What we have done so far is set up the dnsmasq service. For hostnames that do not exist in <code>/etc/hosts</code> the system still uses the nameserver inside <code>/etc/resolv.conf</code> for name resolution.</p>
<p>To start using dnsmasq, edit <code>/etc/resolv.conf</code>, remove all nameservers and add only the IP of our dnsmasq service:</p>
<pre class="codesnp">
nameserver 127.0.0.1
</pre>
<p>From now on, the system will use dnsmasq for domain name resolution. You can un-comment the <strong>log-queries</strong> option in order to confirm the dnsmasq operation.</p>
<h4 id="FullConfigurationFile">Appendix I &#8211; Full configuration file</h4>
<p>This is the complete configuration file containing the configuration that has been discussed in this article. Note that it can be used as is to replace the default <code>/etc/dnsmasq.conf</code>.</p>
<pre class="codesnp">
#
# Configuration file for dnsmasq acting as a caching nameserver.
#
# Format is one option per line, legal options are the same
# as the long options legal on the command line. See
# "/usr/sbin/dnsmasq --help" or "man 8 dnsmasq" for details.
#
# Updated versions of this configuration file may be available at:
#
#   http://www.g-loaded.eu/2010/09/18/caching-nameserver-using-dnsmasq/
#

#
# Basic server configuration
#

listen-address=127.0.0.1
port=53
bind-interfaces
user=dnsmasq
group=dnsmasq
pid-file=/var/run/dnsmasq.pid

#
# Logging
#

#log-facility=/var/log/dnsmasq.log
#log-queries

#
# Name resolution options
#

domain-needed
bogus-priv
no-hosts
dns-forward-max=150
cache-size=1000
#no-negcache
neg-ttl=3600
resolv-file=/etc/resolv.dnsmasq
no-poll
</pre>
<p>This file is meant to be used both on servers and desktops.</p>
<h4 id="LoggingToFile" >Appendix II &#8211; Logging to file</h4>
<p>Before dnsmasq starts logging to file it is required to set the path to the logfile in the <strong>log-facility</strong> option inside <code>/etc/dnsmasq.conf</code>.</p>
<pre class="codesnp">
log-facility=/var/log/dnsmasq.log
</pre>
<p>To ensure proper rotation of the log file you should use the following logrotate configuration:</p>
<pre class="codesnp">
/var/log/dnsmasq.log {
    monthly
    missingok
    notifempty
    delaycompress
    sharedscripts
    postrotate
        [ ! -f /var/run/dnsmasq.pid ] || kill -USR2 `cat /var/run/dnsmasq.pid`
    endscript
    create 0640 dnsmasq dnsmasq
}
</pre>
<p>Save the above configuration in <code>/etc/logrotate.d/dnsmasq</code>. Also, adjust the log filename or the path to the PID file in case you have used custom names, but make sure you do not change the <strong>USR2</strong> signal that is sent to the dnsmasq process in the post-rotation script.</p>
<h4>Final Thoughts</h4>
<p><strong>dnsmasq</strong> is a very lightweight service. Therefore, you can run it on any system, either server or desktop without any noticeable impact on system resources. In this guide we used it as an internal system service bound to the loopback interface, without permitting direct access from the outside. This along with the fact that dnsmasq is mature software that has been around for several years makes our setup rather secure.</p>
<p>Several people might argue that the performance improvement a local caching nameserver offers in terms of name lookup speed is insignificant. This might be true in some cases, but there are times that this performance improvement is noticeable, especially when the quality of the network connectivity between the current machine and the upstream nameserver is an issue, or when the upstream name server is overloaded. On the other hand, it is almost certain that a local caching DNS server can in no way make name resolution slower, unless perhaps a huge cache is being used. Generally, I find keeping such a service operational a good idea.</p>
<p>In this article we discussed about one of the dnsmasq features: DNS caching. dnsmasq is a lot more than just that. Check the whole feature set in the <a href="http://www.thekelleys.org.uk/dnsmasq/doc.html">dnsmasq homepage</a>. Perhaps, in the future, more guides covering other features of this software are published. Until then, enjoy local DNS caching!!!</p>
<p class="cc-block"><em><a href="http://www.g-loaded.eu/2010/09/18/caching-nameserver-using-dnsmasq/">Caching Nameserver using dnsmasq</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.</p>
<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2009/10/07/how-to-change-the-timezone/" rel="bookmark">How to change the Timezone</a></li>
<li><a href="http://www.g-loaded.eu/2007/09/15/use-wget-or-curl-to-download-from-rapidshare-premium/" rel="bookmark">Use wget or curl to download from RapidShare Premium</a></li>
<li><a href="http://www.g-loaded.eu/2008/05/12/how-to-disable-ipv6-in-fedora-and-centos/" rel="bookmark">How to Disable IPv6 in Fedora and CentOS</a></li>
<li><a href="http://www.g-loaded.eu/2010/09/17/cpu-time-saved-by-wp-super-cache/" rel="bookmark">CPU Time saved by WP-Super-Cache</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2010/09/18/caching-nameserver-using-dnsmasq/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>mod_wsgi incompatible with mod_python</title>
		<link>http://www.g-loaded.eu/2010/04/07/mod_wsgi-incompatible-with-mod_python/</link>
		<comments>http://www.g-loaded.eu/2010/04/07/mod_wsgi-incompatible-with-mod_python/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 09:00:58 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[WSGI]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/?p=1676</guid>
		<description><![CDATA[This is a quick note that mod_wsgi daemon processes are now incompatible with mod_python. Upgraded mod_wsgi earlier today in CentOS and saw the following note. I guess this limitation has been around for a while before affecting CentOS/RHEL: ################################################################################# # mod_python and mod_wsgi compatibility note ################################################################################# # mod_wsgi will deadlock if run in daemon mode [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick note that <a href="http://code.google.com/p/modwsgi/">mod_wsgi</a> daemon processes are now incompatible with <a href="http://www.modpython.org/">mod_python</a>. Upgraded <strong>mod_wsgi</strong> earlier today in CentOS and saw the following note. I guess this limitation has been around for a while before affecting CentOS/RHEL:<br />
<span id="more-1676"></span></p>
<pre class="codesnp">
#################################################################################
# mod_python and mod_wsgi compatibility note
#################################################################################
# mod_wsgi will deadlock if run in daemon mode while mod_python is enabled
# do not enable both mod_python and mod_wsgi if you are going to use the
# WSGIDaemonProcess directive
# In previous version of mod_wsgi, apache would segfault when both mod_wsgi
# and mod_python were enabled.  This update does not guarantee that will not
# happen.
#################################################################################
# Do not enable mod_python and mod_wsgi in the same apache process.
#################################################################################
</pre>
<p>Keep this in mind if you plan to mix both modules under the same Apache instance.</p>
<p><strong>Update</strong>: As <a href="http://blog.dscpl.com.au/">Graham</a> pointed out in <a href="http://www.g-loaded.eu/2010/04/07/mod_wsgi-incompatible-with-mod_python/#comment-12257">this comment</a>, there is no issue if <strong>mod_python 3.3.1</strong> is used. That&#8217;s great news because I would miss the flexibility of mod_python when it comes to request processing.</p>
<p class="cc-block"><em><a href="http://www.g-loaded.eu/2010/04/07/mod_wsgi-incompatible-with-mod_python/">mod_wsgi incompatible with mod_python</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.</p>
<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2008/12/09/making-a-directory-writable-by-the-webserver/" rel="bookmark">Making a directory writable by the webserver</a></li>
<li><a href="http://www.g-loaded.eu/2006/11/20/my-running-dog/" rel="bookmark">My running dog</a></li>
<li><a href="http://www.g-loaded.eu/2008/05/10/use-mod_deflate-to-compress-web-content-delivered-by-apache/" rel="bookmark">Use mod_deflate to Compress Web Content delivered by Apache</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2010/04/07/mod_wsgi-incompatible-with-mod_python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Script for Apache Error Report</title>
		<link>http://www.g-loaded.eu/2010/03/28/script-apache-error-report/</link>
		<comments>http://www.g-loaded.eu/2010/03/28/script-apache-error-report/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 17:26:47 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Cron]]></category>
		<category><![CDATA[Report]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Snippet]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/?p=1648</guid>
		<description><![CDATA[The last incident with the php-cgi errors as a result of a bad PHP script made me re-evaluate the daily reports I receive from the server. I realized that a report about the httpd errors that have occured during the previous day, including all virtualhosts, is more important than I had initially thought. Such a [...]]]></description>
			<content:encoded><![CDATA[<p>The last incident with the <a href="http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/">php-cgi errors</a> as a result of a bad PHP script made me re-evaluate the daily reports I receive from the server. I realized that a report about the <em>httpd errors</em> that have occured during the previous day, including all virtualhosts, is more important than I had initially thought. Such a report would have brought the problem to my attention much earlier and could also point me to the right direction while I was trying to figure out what was the cause of it. Fortunately, I found a nice error report generator for this purpose.<br />
<span id="more-1648"></span><br />
The script is called <a href="http://www.librelogiciel.com/software/ScanErrLog/action_Presentation">scanerrlog</a> and has some quite nice features. I highly recommend you check it out. In order to run it you will also need an extra Python module, <a href="http://www.librelogiciel.com/software/jaxml/action_Presentation">jaxml</a>. Download both packages and extract <strong>scanerrlog.py</strong> and <strong>jaxml.py</strong> to the same directory. Then you can call <code>scanerrlog.py</code> using the following cronjob.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/env bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Error Report for httpd</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Requires:</span>
<span style="color: #666666; font-style: italic;">#   - scanerrlog - http://www.librelogiciel.com/software/ScanErrLog/action_Presentation</span>
<span style="color: #666666; font-style: italic;">#   - jaxml - http://www.librelogiciel.com/software/jaxml/action_Presentation</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>error_log \
    <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>vhosts<span style="color: #000000; font-weight: bold;">/*/</span>log<span style="color: #000000; font-weight: bold;">/</span>error_log \
    <span style="color: #000000; font-weight: bold;">|</span> python <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>scanerrlog.py <span style="color: #660033;">-f</span> text \
    <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;<span style="color: #780078;">`hostname`</span> - Apache Error Report&quot;</span> root<span style="color: #000000; font-weight: bold;">@</span>localhost
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>Some notes:</p>
<ol>
<li>Make sure that this cronjob runs before <strong>log rotation</strong> takes place.</li>
<li>The above shell script concatenates the <strong>error_log</strong> files from the main web server and all <em>virtualhosts</em>. Edit the paths to reflect your server configuration and virtualhost layout.</li>
<li>Edit the path to <code>scanerrlog.py</code>.</li>
</ol>
<p>Scanerrlog has some quite nice features that let you further customize the report. Make sure you read the help message.</p>
<p class="cc-block"><em><a href="http://www.g-loaded.eu/2010/03/28/script-apache-error-report/">Script for Apache Error Report</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.</p>
<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/" rel="bookmark">SELinux audit reports script</a></li>
<li><a href="http://www.g-loaded.eu/2009/10/05/strange-mod_dav_svn-error/" rel="bookmark">Strange mod_dav_svn error</a></li>
<li><a href="http://www.g-loaded.eu/2006/09/25/how-to-integrate-seaudit-report-in-logwatch/" rel="bookmark">How to integrate seaudit-report in logwatch</a></li>
<li><a href="http://www.g-loaded.eu/2007/08/10/ssl-enabled-name-based-apache-virtual-hosts-with-mod_gnutls/" rel="bookmark">SSL-enabled Name-based Apache Virtual Hosts with mod_gnutls</a></li>
<li><a href="http://www.g-loaded.eu/2007/07/29/when-it-comes-to-error-messages/" rel="bookmark">When it comes to error messages&#8230;</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2010/03/28/script-apache-error-report/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Issues with the feeds are now resolved</title>
		<link>http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/</link>
		<comments>http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 06:06:46 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Errors]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/?p=1634</guid>
		<description><![CDATA[This is just a quick notice that during the last five days there was a problem with the website feeds. The web server returned a 500 Internal Server Error to almost all requests for /feed/ URLs. Also, there was a big increase of the server&#8217;s CPU load behind the scenes, which was caused by php-cgi [...]]]></description>
			<content:encoded><![CDATA[<p>This is just a quick notice that during the last five days there was a problem with the website feeds. The web server returned a <em>500 Internal Server Error</em> to almost all requests for <code>/feed/</code> URLs. Also, there was a big increase of the server&#8217;s <strong>CPU load</strong> behind the scenes, which was caused by <em>php-cgi</em> processes. It turned out that a custom plugin (unpublished) I had written for WordPress in the past was the cause of all the trouble, but, before coming to that conclusion, the fact that the problems had started without me doing anything on the blog during the last weeks together with a series of other random observations led me do a thorough examination of the whole server just in case.<br />
<span id="more-1634"></span><br />
So, after spending two days in front of a Linux terminal, I came to the conclusion that the following code had been problematic from the beginning and it was like a time-bomb for which the time had come to cause issues to the web site and the server that hosted it.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> rsse_add_related_posts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$PostBody</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>rsse_verify_feed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$PostBody</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'yarpp_related'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$PostBody</span> <span style="color: #339933;">.=</span> yarpp_related<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'rss'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$PostBody</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rsse_add_related_posts'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">252</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This code used a function of another plugin to attach a &#8216;<em>related posts</em>&#8216; section at the end of the full content of each feed entry. As soon as I commented out the above filter and started attaching the related-posts section to the feed content through the <a href="http://mitcho.com/code/yarpp/">YARPP</a> plugin&#8217;s administration interface, everything was normal again. No more php-cgi processes timing-out or over-consuming the CPU cycles.</p>
<p>The following graph shows clearly the problematic period:</p>
<div id="attachment_1639" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.g-loaded.eu/wp-content/uploads/phpcgi-cpu-time.png"><img src="http://www.g-loaded.eu/wp-content/uploads/phpcgi-cpu-time.png" alt="php-cgi processes consuming the CPU" title="phpcgi-cpu-time" width="640" class="size-full wp-image-1639" /></a><p class="wp-caption-text">php-cgi processes consuming the CPU</p></div>
<p>The httpd error_log included many errors like the following:</p>
<pre class="codesnp">
[...]
Allowed memory size of 33554432 bytes exhausted (tried to allocate 18893 bytes)
[...]
mod_fcgid: process ... exit(communication error), terminated by calling exit(), return code: 1
[...]
[warn] (104)Connection reset by peer: mod_fcgid: read data from fastcgi server error.
[...]
[warn] mod_fcgid: stderr: PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 4864 bytes)
[...]
Premature end of script headers: index.php
[...]
</pre>
<p>Note that these errors might appear in several occasions.</p>
<p>In my case, finding that faulty piece of code was a huge relief, I can tell you.</p>
<p class="cc-block"><em><a href="http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/">Issues with the feeds are now resolved</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.</p>
<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2007/01/12/wordpress-206-feed-issues-resolved/" rel="bookmark">WordPress 2.0.6 &#8211; Feed Issues Resolved</a></li>
<li><a href="http://www.g-loaded.eu/2007/07/12/issue-addressed-author-feeds-deliver-full-content/" rel="bookmark">Issue addressed: Author feeds deliver full content</a></li>
<li><a href="http://www.g-loaded.eu/2008/10/17/status-of-content-availability-via-feeds/" rel="bookmark">Status of content availability via feeds</a></li>
<li><a href="http://www.g-loaded.eu/2009/11/19/g-loaded-feeds/" rel="bookmark">G-Loaded Feeds</a></li>
<li><a href="http://www.g-loaded.eu/2007/07/29/when-it-comes-to-error-messages/" rel="bookmark">When it comes to error messages&#8230;</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Python SSH Server for UNIX Systems using Twisted.conch</title>
		<link>http://www.g-loaded.eu/2010/03/26/python-ssh-server-unix-twisted-conch/</link>
		<comments>http://www.g-loaded.eu/2010/03/26/python-ssh-server-unix-twisted-conch/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 20:27:00 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Remote]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Twisted]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/?p=1572</guid>
		<description><![CDATA[I can still recall the excitement of the first time I tried to access and administer a remote system using SSH. Accessing my shell at a remote machine securely, being able to do local and remote port forwarding in order to access remote services through encrypted tunnels, X forwarding, secure file transfers using scp or [...]]]></description>
			<content:encoded><![CDATA[<p>I can still recall the excitement of the first time I tried to access and administer a remote system using <strong>SSH</strong>. Accessing my shell at a remote machine securely, being able to do local and remote port forwarding in order to access remote services through encrypted tunnels, X forwarding, secure file transfers using <em>scp</em> or <em>sftp</em>, <a href="http://www.g-loaded.eu/2005/11/10/ssh-with-keys/">authentication using public key infrastructure</a> are just a few of the features that justify the excitement of the first time. The only <em>Secure Shell</em> server implementation I had used all that time was the <a href="http://www.openssh.com/">OpenSSH</a> server. Although this is an open-source project, the fact that it is written in C makes it extremely difficult for me to have fun with it by making any modifications in order to implement even simple things like command filtering. This is because I have never programmed in <strong>C</strong> and do not intend to learn how to do it in the foreseeable future. So what I&#8217;ve been looking for today was a server implementation of the <strong>SSH2 protocol</strong> written in <a href="http://python.org">Python</a>. Unfortunately, there is no such project ready for immediate use. I had to hack my own! After several hours of trial and error, having written dozens of sample scripts for testing, I finally created a minimal project, called <strong>RapidSSH</strong>, in order to demonstrate how to create a fully functional SSH server with just a few lines of Python code by using <em>Twisted.conch</em>, part of the <a href="http://twistedmatrix.com">Twisted Framework</a>. Read on&#8230;<br />
<span id="more-1572"></span><br />
At first, I tried to experiment with the <a href="http://twistedmatrix.com/documents/current/conch/examples/sshsimpleserver.py">sshsimpleserver.py</a> example script that exists on the Twisted homepage. But, soon I realized that this script is there just to give an idea about how to use <code>Twisted.conch</code> and also provide a sensible starting point for your own implementations. That script was not even close in having the functionality I had in mind. After spending some time examining the Twisted source code, I found a fantastic, but completely undocumented, module: <a href="http://twistedmatrix.com/trac/browser/trunk/twisted/conch/unix.py">twisted.conch.unix</a>. Having gained some experience by my experimentation with <code>sshsimpleserver.py</code> I managed to easily put the pieces together and come up with the SSH server implementation as shown below.</p>
<p>But first, let&#8217;s install some <strong>dependencies</strong>. I assume that you will try the code on a machine aimed for testing, so I won&#8217;t be using the system&#8217;s package manager but instead use <strong>easy_install</strong> to install the needed Python modules. Other commands like <em>pip</em> could be used as well. If you do not want to mess with your system-wide python installation, just use <strong>virtualenv</strong> and <strong>pip</strong>, but I won&#8217;t go into the details about how to use these tools in the current document.</p>
<p>Install the needed dependencies:</p>
<pre class="console">
easy_install pycrypto
easy_install pyasn1
easy_install pam
easy_install twisted
</pre>
<p>Make sure you have <strong>gcc</strong> installed, because it will be needed to complete the installation of Twisted and PyCrypto.</p>
<p>I have created a project for this code at <strong>Bitbucket</strong>, called <a href="http://bitbucket.org/gnotaras/rapidssh/">RapidSSH</a>. This will make it easier to share code and ideas about SSH server implementations in Python using Twisted.</p>
<p>Filename: <code>scripts/rapidsshd_unix.py</code></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># This file is part of rapidssh - http://bitbucket.org/gnotaras/rapidssh/</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># rapidssh - A set of Secure Shell (SSH) server implementations in Python</span>
<span style="color: #808080; font-style: italic;">#            using Twisted.conch, part of the Twisted Framework.</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Copyright (c) 2010 George Notaras - http://www.g-loaded.eu</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<span style="color: #808080; font-style: italic;"># of this software and associated documentation files (the &quot;Software&quot;), to deal</span>
<span style="color: #808080; font-style: italic;"># in the Software without restriction, including without limitation the rights</span>
<span style="color: #808080; font-style: italic;"># to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<span style="color: #808080; font-style: italic;"># copies of the Software, and to permit persons to whom the Software is</span>
<span style="color: #808080; font-style: italic;"># furnished to do so, subject to the following conditions:</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># The above copyright notice and this permission notice shall be included in</span>
<span style="color: #808080; font-style: italic;"># all copies or substantial portions of the Software.</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<span style="color: #808080; font-style: italic;"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<span style="color: #808080; font-style: italic;"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<span style="color: #808080; font-style: italic;"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<span style="color: #808080; font-style: italic;"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<span style="color: #808080; font-style: italic;"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN</span>
<span style="color: #808080; font-style: italic;"># THE SOFTWARE.</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Initially based on the sshsimpleserver.py kindly published by:</span>
<span style="color: #808080; font-style: italic;"># Twisted Matrix Laboratories - http://twistedmatrix.com</span>
<span style="color: #808080; font-style: italic;">#</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> pam
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">conch</span>.<span style="color: black;">unix</span> <span style="color: #ff7700;font-weight:bold;">import</span> UnixSSHRealm
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">cred</span> <span style="color: #ff7700;font-weight:bold;">import</span> portal
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">cred</span>.<span style="color: black;">credentials</span> <span style="color: #ff7700;font-weight:bold;">import</span> IUsernamePassword
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">cred</span>.<span style="color: black;">checkers</span> <span style="color: #ff7700;font-weight:bold;">import</span> ICredentialsChecker
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">cred</span>.<span style="color: black;">error</span> <span style="color: #ff7700;font-weight:bold;">import</span> UnauthorizedLogin
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">conch</span>.<span style="color: black;">checkers</span> <span style="color: #ff7700;font-weight:bold;">import</span> SSHPublicKeyDatabase
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">conch</span>.<span style="color: black;">ssh</span> <span style="color: #ff7700;font-weight:bold;">import</span> factory, userauth, connection, keys, session
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">internet</span> <span style="color: #ff7700;font-weight:bold;">import</span> reactor, defer
<span style="color: #ff7700;font-weight:bold;">from</span> zope.<span style="color: black;">interface</span> <span style="color: #ff7700;font-weight:bold;">import</span> implements
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">python</span> <span style="color: #ff7700;font-weight:bold;">import</span> log
&nbsp;
<span style="color: #808080; font-style: italic;"># Logging</span>
<span style="color: #808080; font-style: italic;"># Currently logging to STDERR</span>
log.<span style="color: black;">startLogging</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">stderr</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Server-side public and private keys. These are the keys found in</span>
<span style="color: #808080; font-style: italic;"># sshsimpleserver.py. Make sure you generate your own using ssh-keygen!</span>
&nbsp;
publicKey = <span style="color: #483d8b;">'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAGEArzJx8OYOnJmzf4tfBEvLi8DVPrJ3/c9k2I/Az64fxjHf9imyRJbixtQhlH9lfNjUIx+4LmrJH5QNRsFporcHDKOTwTTYLh5KmRpslkYHRivcJSkbh/C+BR3utDS555mV'</span>
&nbsp;
privateKey = <span style="color: #483d8b;">&quot;&quot;&quot;-----BEGIN RSA PRIVATE KEY-----
MIIByAIBAAJhAK8ycfDmDpyZs3+LXwRLy4vA1T6yd/3PZNiPwM+uH8Yx3/YpskSW
4sbUIZR/ZXzY1CMfuC5qyR+UDUbBaaK3Bwyjk8E02C4eSpkabJZGB0Yr3CUpG4fw
vgUd7rQ0ueeZlQIBIwJgbh+1VZfr7WftK5lu7MHtqE1S1vPWZQYE3+VUn8yJADyb
Z4fsZaCrzW9lkIqXkE3GIY+ojdhZhkO1gbG0118sIgphwSWKRxK0mvh6ERxKqIt1
xJEJO74EykXZV4oNJ8sjAjEA3J9r2ZghVhGN6V8DnQrTk24Td0E8hU8AcP0FVP+8
PQm/g/aXf2QQkQT+omdHVEJrAjEAy0pL0EBH6EVS98evDCBtQw22OZT52qXlAwZ2
gyTriKFVoqjeEjt3SZKKqXHSApP/AjBLpF99zcJJZRq2abgYlf9lv1chkrWqDHUu
DZttmYJeEfiFBBavVYIF1dOlZT0G8jMCMBc7sOSZodFnAiryP+Qg9otSBjJ3bQML
pSTqy7c3a2AScC/YyOwkDaICHnnD3XyjMwIxALRzl0tQEKMXs6hH8ToUdlLROCrP
EhQ0wahUTCk1gKA4uPD6TMTChavbh4K63OvbKg==
-----END RSA PRIVATE KEY-----&quot;&quot;&quot;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> PamPasswordDatabase:
    <span style="color: #483d8b;">&quot;&quot;&quot;Authentication/authorization backend using the 'login' PAM service&quot;&quot;&quot;</span>
    credentialInterfaces = IUsernamePassword,
    implements<span style="color: black;">&#40;</span>ICredentialsChecker<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> requestAvatarId<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, credentials<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> pam.<span style="color: black;">authenticate</span><span style="color: black;">&#40;</span>credentials.<span style="color: black;">username</span>, credentials.<span style="color: black;">password</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> defer.<span style="color: black;">succeed</span><span style="color: black;">&#40;</span>credentials.<span style="color: black;">username</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> defer.<span style="color: black;">fail</span><span style="color: black;">&#40;</span>UnauthorizedLogin<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;invalid password&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> UnixSSHdFactory<span style="color: black;">&#40;</span>factory.<span style="color: black;">SSHFactory</span><span style="color: black;">&#41;</span>:
    publicKeys = <span style="color: black;">&#123;</span>
        <span style="color: #483d8b;">'ssh-rsa'</span>: keys.<span style="color: black;">Key</span>.<span style="color: black;">fromString</span><span style="color: black;">&#40;</span>data=publicKey<span style="color: black;">&#41;</span>
    <span style="color: black;">&#125;</span>
    privateKeys = <span style="color: black;">&#123;</span>
        <span style="color: #483d8b;">'ssh-rsa'</span>: keys.<span style="color: black;">Key</span>.<span style="color: black;">fromString</span><span style="color: black;">&#40;</span>data=privateKey<span style="color: black;">&#41;</span>
    <span style="color: black;">&#125;</span>
    services = <span style="color: black;">&#123;</span>
        <span style="color: #483d8b;">'ssh-userauth'</span>: userauth.<span style="color: black;">SSHUserAuthServer</span>,
        <span style="color: #483d8b;">'ssh-connection'</span>: connection.<span style="color: black;">SSHConnection</span>
    <span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Components have already been registered in twisted.conch.unix</span>
&nbsp;
portal = portal.<span style="color: black;">Portal</span><span style="color: black;">&#40;</span>UnixSSHRealm<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
portal.<span style="color: black;">registerChecker</span><span style="color: black;">&#40;</span>PamPasswordDatabase<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>   <span style="color: #808080; font-style: italic;"># Supports PAM</span>
portal.<span style="color: black;">registerChecker</span><span style="color: black;">&#40;</span>SSHPublicKeyDatabase<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># Supports PKI</span>
UnixSSHdFactory.<span style="color: black;">portal</span> = portal
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    reactor.<span style="color: black;">listenTCP</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5022</span>, UnixSSHdFactory<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    reactor.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Some notes:</p>
<ul>
<li>The server uses the very same public and private keys as found in the <code>sshsimpleserver.py</code> script. Make sure you generate new keys using <strong>ssh-keygen</strong> if you plan to run this on a public server (although this not recommended).</li>
<li>Twisted included a module for PAM authentication, <code>twisted.cred.pamauth</code>, but unfortunately I could not locate one of its dependencies to make it work. So, I used the excellent <a href="http://atlee.ca/software/pam/">python-pam</a> to create a custom PAM authenticator class.</li>
<li>I can guess what you might thought when you read about this code:<br />
<blockquote>Python is a cross-platform programming language. Twisted runs on Windows. So, is this a solution for running a SSH server on Win32?</p></blockquote>
<p> Well, at the moment it won&#8217;t run because internally it uses some Python modules that are available on UNIX platforms only. But, I intend to investigate the possibility of running this on <strong>Windows</strong> since I already need something like that.</li>
</ul>
<p>We can now enjoy our Python SSH server. Run as root:</p>
<pre class="console">
python scripts/rapidsshd_unix.py
</pre>
<p>From another machine, connect to the server using an <em>ssh client</em>:</p>
<pre class="console">
ssh -p 5022 rocky@arena
</pre>
<p>If you have deployed your public key in the <code>~/.ssh/authorized_keys</code> file on the remote machine (<em>arena</em>), you should be able to authenticate using the public key:</p>
<pre class="console">
ssh -p 5022 -i /path/to/private.key rocky@arena
</pre>
<p>You should get output like the following on the server:</p>
<pre class="console">
[root@arena ~]# python ssh.py
2010-03-26 21:30:05+0000 [-] Log opened.
2010-03-26 21:30:05+0000 [-] __main__.UnixSSHdFactory starting on 5022
2010-03-26 21:30:05+0000 [-] Starting factory <__main__.UnixSSHdFactory instance at 0xb7a0b0cc>
2010-03-26 21:30:13+0000 [__main__.UnixSSHdFactory] disabling diffie-hellman-group-exchange because we cannot find moduli file
2010-03-26 21:30:13+0000 [SSHServerTransport,0,192.168.0.172] kex alg, key alg: diffie-hellman-group1-sha1 ssh-rsa
2010-03-26 21:30:13+0000 [SSHServerTransport,0,192.168.0.172] outgoing: aes256-ctr hmac-sha1 none
2010-03-26 21:30:13+0000 [SSHServerTransport,0,192.168.0.172] incoming: aes256-ctr hmac-sha1 none
2010-03-26 21:30:14+0000 [SSHServerTransport,0,192.168.0.172] NEW KEYS
2010-03-26 21:30:14+0000 [SSHServerTransport,0,192.168.0.172] starting service ssh-userauth
2010-03-26 21:30:17+0000 [SSHService ssh-userauth on SSHServerTransport,0,192.168.0.172] rocky trying auth none
2010-03-26 21:30:17+0000 [SSHService ssh-userauth on SSHServerTransport,0,192.168.0.172] rocky trying auth publickey
2010-03-26 21:30:17+0000 [SSHService ssh-userauth on SSHServerTransport,0,192.168.0.172] rocky trying auth publickey
2010-03-26 21:30:17+0000 [SSHService ssh-userauth on SSHServerTransport,0,192.168.0.172] rocky authenticated with publickey
2010-03-26 21:30:17+0000 [SSHService ssh-userauth on SSHServerTransport,0,192.168.0.172] starting service ssh-connection
2010-03-26 21:30:17+0000 [SSHService ssh-connection on SSHServerTransport,0,192.168.0.172] got channel session request
2010-03-26 21:30:17+0000 [SSHChannel session (0) on SSHService ssh-connection on SSHServerTransport,0,192.168.0.172] channel open
2010-03-26 21:30:17+0000 [SSHChannel session (0) on SSHService ssh-connection on SSHServerTransport,0,192.168.0.172] pty request: xterm (24L, 80L, 0L, 0L)
2010-03-26 21:30:17+0000 [SSHChannel session (0) on SSHService ssh-connection on SSHServerTransport,0,192.168.0.172] getting shell
</pre>
<p>This first release of the <a href="http://bitbucket.org/gnotaras/rapidssh/">RapidSSH</a> project exists solely for demonstration purposes. Don&#8217;t get fooled by the small amount of code. Information about how to put the pieces together is scarce and it required a lot trial&#038;error and source code reading. The above implementation contains none of the customizations I had in mind. These will be done as soon as I find some time to do so. Until then it will be nice to hear about your experiences or implementations you have worked on.</p>
<p class="cc-block"><em><a href="http://www.g-loaded.eu/2010/03/26/python-ssh-server-unix-twisted-conch/">Python SSH Server for UNIX Systems using Twisted.conch</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.</p>
<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2006/05/17/epiphany-python-console-open-new-tab/" rel="bookmark">Epiphany Python Console &#8211; Open New Tab</a></li>
<li><a href="http://www.g-loaded.eu/2007/01/31/python-irc-bot/" rel="bookmark">Python IRC Bot</a></li>
<li><a href="http://www.g-loaded.eu/2006/04/07/python-crash-course/" rel="bookmark">Python Crash Course</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/10/configure-vnc-server-in-fedora/" rel="bookmark">Set up the VNC Server in Fedora</a></li>
<li><a href="http://www.g-loaded.eu/2009/05/07/descramble-passwords-from-gftp-bookmarks-using-python/" rel="bookmark">Descramble Passwords from gftp Bookmarks using Python</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2010/03/26/python-ssh-server-unix-twisted-conch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Spamassassin FH_DATE_PAST_20XX test buggy in 2010</title>
		<link>http://www.g-loaded.eu/2010/01/02/spamassassin-fh_date_past_20xx-test-buggy-in-2010/</link>
		<comments>http://www.g-loaded.eu/2010/01/02/spamassassin-fh_date_past_20xx-test-buggy-in-2010/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 02:11:19 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[Spamassassin]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/?p=1531</guid>
		<description><![CDATA[It seems there is an issue with the Spamassassin FH_DATE_PAST_20XX test. This test checks whether the email has a date in the future and, if this is the case, raises the message&#8217;s score. Apparently, this test is falsely triggered by all emails that have been sent in 2010, producing several false positives. Since, I do [...]]]></description>
			<content:encoded><![CDATA[<p>It seems there is an issue with the <a href="http://spamassassin.apache.org/">Spamassassin</a> <strong>FH_DATE_PAST_20XX</strong> test. This test checks whether the email has a date in the future and, if this is the case, raises the message&#8217;s score. Apparently, this test is falsely triggered by all emails that have been sent in 2010, producing several <em>false positives</em>. Since, I do not have much time to investigate this issue and to follow the news, I decided to inactivate it until I am certain it has been resolved.</p>
<p>[Update: It has been resolved. Update you SA rules]<br />
<span id="more-1531"></span><br />
To inactivate the <strong>FH_DATE_PAST_20XX</strong> test system-wide add the following line to the Spamassassin configuration file, usually located at <code>/etc/mail/spamassassin/local.cf</code>:</p>
<pre class="codesnp">
score FH_DATE_PAST_20XX 0
</pre>
<p>If you use the spamassassin server (<strong>spamd</strong>), don&#8217;t forget to <strong>restart</strong> it for the changes to take effect.</p>
<p>As I have mentioned in the update above, the issue has been resolved (Kudos). The Spamassassin developers have released updated rules for the FH_DATE_PAST_20XX test, so make sure you run sa-update:</p>
<pre class="console">
/usr/bin/sa-update
</pre>
<p>If you compile your rules, make sure you also run <code>/usr/bin/sa-compile</code> and of course restart <em>spamd</em>.</p>
<p class="cc-block"><em><a href="http://www.g-loaded.eu/2010/01/02/spamassassin-fh_date_past_20xx-test-buggy-in-2010/">Spamassassin FH_DATE_PAST_20XX test buggy in 2010</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.</p>
<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2009/04/10/windows-7-opensolaris-put-to-the-test/" rel="bookmark">Windows 7, OpenSolaris &#8211; put to the test</a></li>
<li><a href="http://www.g-loaded.eu/2006/01/17/fedora-core-5-test-2-review/" rel="bookmark">Fedora Core 5 Test 2 Review</a></li>
<li><a href="http://www.g-loaded.eu/2010/01/02/happy-2010/" rel="bookmark">Wishes for a happy 2010</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2010/01/02/spamassassin-fh_date_past_20xx-test-buggy-in-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Object Caching 2044/2200 objects using apc

Served from: www.g-loaded.eu @ 2012-05-16 18:03:53 -->
