<?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/"
	>

<channel>
	<title>tech notes</title>
	<atom:link href="http://bsd.dischaos.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://bsd.dischaos.com</link>
	<description>just some random notes on BSDs, linux and web development</description>
	<lastBuildDate>Fri, 07 May 2010 10:18:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Dovecot MySQL stored procedures patch</title>
		<link>http://bsd.dischaos.com/2010/05/07/dovecot-mysql-stored-procedures-patch/</link>
		<comments>http://bsd.dischaos.com/2010/05/07/dovecot-mysql-stored-procedures-patch/#comments</comments>
		<pubDate>Fri, 07 May 2010 10:18:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[other]]></category>
		<category><![CDATA[dovecot]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=184</guid>
		<description><![CDATA[With this patch it&#8217;s possible to use stored procedure calls in dovecot&#8217;s configuration. It implements the correct logic of handling mysql multiple statements as described in this MySQL document. I&#8217;m not sure it&#8217;s the correct place to implement it in (dovecot&#8217;s design is very clean and this is a rather quick hack), but it&#8217;s been [...]]]></description>
			<content:encoded><![CDATA[<p>With <a href="http://bsd.dischaos.com/files/dovecot-driver-mysql.c.patch">this patch</a> it&#8217;s possible to use stored procedure calls in dovecot&#8217;s configuration.</p>
<p>It implements the correct logic of handling mysql multiple statements as described <a href="http://dev.mysql.com/doc/refman/5.0/en/c-api-multiple-queries.html">in this MySQL document</a>. I&#8217;m not sure it&#8217;s the correct place to implement it in (dovecot&#8217;s design is very clean and this is a rather quick hack), but it&#8217;s been working fine in production for a couple of months now.</p>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2010/05/07/dovecot-mysql-stored-procedures-patch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Munin plugin for dovecot logins</title>
		<link>http://bsd.dischaos.com/2010/05/07/munin-plugin-for-dovecot-logins/</link>
		<comments>http://bsd.dischaos.com/2010/05/07/munin-plugin-for-dovecot-logins/#comments</comments>
		<pubDate>Fri, 07 May 2010 10:03:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[other]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[munin]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=181</guid>
		<description><![CDATA[Graphs dovecot imap and pop3 logins based on entries in the log file. May require changing the location of the log file (hardcoded to /var/log/dovecot-info.log)]]></description>
			<content:encoded><![CDATA[<p><a href="http://bsd.dischaos.com/files/dovecot_logins">Graphs dovecot imap and pop3 logins</a> based on entries in the log file. May require changing the location of the log file (hardcoded to /var/log/dovecot-info.log)</p>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2010/05/07/munin-plugin-for-dovecot-logins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Munin plugin for Ironport</title>
		<link>http://bsd.dischaos.com/2010/01/31/munin-plugin-for-ironport/</link>
		<comments>http://bsd.dischaos.com/2010/01/31/munin-plugin-for-ironport/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 00:28:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[other]]></category>
		<category><![CDATA[ironport]]></category>
		<category><![CDATA[munin]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=173</guid>
		<description><![CDATA[A simple munin plugin for graphing Ironport statistics. All it graphs is CPU, memory, disk IO and queue utilisation. It requires SNMP to be enabled on the Ironport (and assumes you&#8217;re using SNMP v3) and snmpwalk to be installed on the munin server. The plugin supports the following environment variables: * snmp_community &#8211; by default [...]]]></description>
			<content:encoded><![CDATA[<p>A simple <a href="http://bsd.dischaos.com/files/ipstatus_">munin plugin for graphing Ironport statistics</a>.  All it graphs is CPU, memory, disk IO and queue utilisation. It requires SNMP to be enabled on the Ironport (and assumes you&#8217;re using SNMP v3) and snmpwalk to be installed on the munin server. The plugin supports the following environment variables:</p>
<p>* snmp_community &#8211; by default set to v3get (default Ironport setting)<br />
* snmp_password &#8211; you have to set it yourself<br />
* snmp_oidbase &#8211; set to 1.3.6.1.4.1.15497.1.1.1 which points at Ironport&#8217;s MIBS. </p>
<p>Save it as ipstatus_ and link to it via ipstatus_yourironporthostname</p>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2010/01/31/munin-plugin-for-ironport/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Portauditing jails</title>
		<link>http://bsd.dischaos.com/2010/01/07/portauditing-jails/</link>
		<comments>http://bsd.dischaos.com/2010/01/07/portauditing-jails/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 11:41:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[bsd]]></category>
		<category><![CDATA[jail]]></category>
		<category><![CDATA[portaudit]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=167</guid>
		<description><![CDATA[I run most of the services in separate jails (that&#8217;s all easy to set up and maintain with ezjail) and quite often end up having 10+ jails even on simple mail/web server installations. Installing portaudit, updating its database and running it every day in each jail seems to be a waste of space and resources. [...]]]></description>
			<content:encoded><![CDATA[<p>I run most of the services in separate jails (that&#8217;s all easy to set up and maintain with ezjail) and quite often end up having 10+ jails even on simple mail/web server installations. </p>
<p>Installing portaudit, updating its database and running it every day in each jail seems to be a waste of space and resources. Instead I decided to <a href="http://bsd.dischaos.com/files/420.jailportaudit">check all jails from the host system</a> during nightly security checks.</p>
<p><a href="http://bsd.dischaos.com/files/420.jailportaudit">This</a> should be saved as /usr/local/etc/periodic/security/420.jailportaudit (with chmod 555):</p>
<div class="codesnip-container" >#!/bin/sh</p>
<p>RET_VAL=&#8221;"</p>
<p>get_jail_name()<br />
{<br />
    jid=$1<br />
    RET_VAL=`jls | egrep &#8220;^ +$jid &#8221; | awk &#8216;{print $3}&#8217;`<br />
}</p>
<p>check_jail()<br />
{<br />
    jid=$1</p>
<p>    get_jail_name $jid<br />
    echo &#8220;==== checking jail :: &#8221; $RET_VAL &#8221; :: ====&#8221;<br />
    /usr/sbin/jexec $jid pkg_info | /usr/bin/awk &#8216;{print $1}&#8217; | /usr/bin/xargs /usr/local/sbin/portaudit<br />
    echo<br />
}</p>
<p>main()<br />
{<br />
    param=$1 </p>
<p>    for i in `jls | tail +2 | awk &#8216;{print $1}&#8217;`<br />
    do<br />
        check_jail $i<br />
    done<br />
}</p>
<p>main $@</p></div>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2010/01/07/portauditing-jails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing corrupted Ironport Queue</title>
		<link>http://bsd.dischaos.com/2010/01/05/fixing-corrupted-ironport-queue/</link>
		<comments>http://bsd.dischaos.com/2010/01/05/fixing-corrupted-ironport-queue/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 16:35:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[bsd]]></category>
		<category><![CDATA[other]]></category>
		<category><![CDATA[postgresql]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=160</guid>
		<description><![CDATA[Looks like there&#8217;s a hidden command you can use to fix queue problems similar to these: Critical: Queue: Your queue has been corrupted; UNABLE TO REPAIR: unable to mount queue: &#8216;(\&#8217;qstore/gcq.py get_time_sorted_gens&#124;919\&#8217;, &#8220;&#8220;, &#8220;[Errno 2] No such file or directory: \&#8217;/var/db/godspeed/gen/gen063.chk\&#8217;&#8221;, \&#8217;[qstore/gcq.py mount&#124;1387] [qstore/gcq.py load&#124;996] [qstore/gcq.py get_time_sorted_gens&#124;919]\&#8217;)&#8217; Critical: Error while sending alert: Unable to send [...]]]></description>
			<content:encoded><![CDATA[<p>Looks like there&#8217;s a hidden command you can use to fix queue problems similar to these:</p>
<blockquote><p>
Critical: Queue: Your queue has been corrupted; UNABLE TO REPAIR: unable to<br />
mount queue: &#8216;(\&#8217;qstore/gcq.py get_time_sorted_gens|919\&#8217;, &#8220;<type<br />
        \'exceptions.OSError\'>&#8220;, &#8220;[Errno 2] No such file or directory:<br />
        \&#8217;/var/db/godspeed/gen/gen063.chk\&#8217;&#8221;, \&#8217;[qstore/gcq.py mount|1387]<br />
        [qstore/gcq.py load|996] [qstore/gcq.py get_time_sorted_gens|919]\&#8217;)&#8217;
</p></blockquote>
<blockquote><p>Critical: Error while sending alert: Unable to send System/Critical alert to xxx@xxx.com with subject &#8220;Critical <System> ironport: Queue: Your queue has been corrupted; UNABLE TO REPAIR: unab&#8230;&#8221;.
</p></blockquote>
<p>What it means is basically that the workqueue is corrupted and the ironport is unable to accept/deliver emails. Rebooting doesn&#8217;t help (doesn&#8217;t really change anything). There&#8217;s however a way of recovering your ironport from this problem. The hidden command is:</p>
<div class="codesnip-container" >resetqueue</div>
<p>It deletes the broken queue, creates a new one, removes all messages in the system quarantines and reboots the ironport. After this clean up operation your ironport should be as new.</p>
<p>What&#8217;s interesting is that by looking at various error messages thrown by Ironports from time to time (especially when something breaks more seriously &#8211; doesn&#8217;t happen too often Ironports are quite solid) you can actually see what&#8217;s running under the hood. Other than it running on something derived from FreeBSD (can&#8217;t be that far off it as they actually contribute some code back to the OS) it looks like it&#8217;s mostly run by python scripts. That&#8217;s interesting from the performance perspective as even the queue management seems to be written in python. Also the database used internally seems to be some version of PostgreSQL. A very nice choice of software&#8230;</p>
<p>Haven&#8217;t seen anything yet that would suggest what MTA (if it&#8217;s not something created by Ironport) is used there. Sure the fact it can write qmail compatible log files doesn&#8217;t mean anything <img src='http://bsd.dischaos.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )</p>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2010/01/05/fixing-corrupted-ironport-queue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>how to create a new kvm image for eucalyptus UEC</title>
		<link>http://bsd.dischaos.com/2009/11/15/how-to-create-a-new-kvm-image-for-eucalyptus-uec/</link>
		<comments>http://bsd.dischaos.com/2009/11/15/how-to-create-a-new-kvm-image-for-eucalyptus-uec/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 13:29:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[eucalyptus]]></category>
		<category><![CDATA[kvm]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=150</guid>
		<description><![CDATA[Eucalyptus is a new cloud management software available with the latest version of ubuntu (karmic koala). It&#8217;s compatible with Amazon&#8217;s EC2 (in terms of images and CLI tools) and it&#8217;s opensource so anyone can build a EC2 like service. That is&#8230; when it becomes a little bit more stable&#8230; Eucalyptus comes with 2 images you [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.eucalpytus.com/products/ubuntu_enterprise_cloud">Eucalyptus</a> is a new cloud management software available with the latest version of ubuntu (karmic koala). It&#8217;s compatible with Amazon&#8217;s EC2 (in terms of images and CLI tools) and it&#8217;s opensource so anyone can build a EC2 like service. That is&#8230; when it becomes a little bit more stable&#8230; <img src='http://bsd.dischaos.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Eucalyptus comes with 2 images you can use to create vm instances on it &#8211; a 64 bit and 32 bit versions of ubuntu. These images are very well prepared and well integrated with EC2/Eucalyptus. But what if you want to run a different linux distro in your Eucalyptus based lab? Here&#8217;s a quick howto on creating a simple CentOS image on a ubuntu box with kvm installed:</p>
<p><strong>Creating a new disk Image</strong></p>
<p>This will be the main hdd in your virtual image, so make sure to give it as much space as you think you&#8217;ll need. Since we&#8217;re building a kvm image, we can use a qcow2 format for disk images. Qcow2 is an expandable image format, so it&#8217;ll only take as much storage space as it&#8217;s actually used withing the image.  </p>
<div class="codesnip-container" >kvm-img create -f qcow2 image.img 20G</div>
<p><strong>OS Installation</strong></p>
<p>Fetch an .iso of the distribution you want installed in the image.</p>
<div class="codesnip-container" >wget http://www.mirrorservice.org/sites/mirror.centos.org/5.4/isos/x86_64/CentOS-5.4-x86_64-netinstall.iso</div>
<p>and start the installation process:</p>
<div class="codesnip-container" >sudo kvm -m 256 -cdrom Centos-5.4-x86_64-netinstall.iso -drive file=image.img,if=scsi,index=0 -boot d -curses -net<br />
nic,vlan=0,model=e1000,macaddr=00:16:3e:de:ad:01 -net tap</div>
<p>if your installation process requires more than 256MB of RAM change the -m option, and if you need more processors available, you can use the &#8216;-c&#8217; option. </p>
<p>The command above will boot a new kvm instance, with the disk image you&#8217;ve created as the primary hdd and the iso as the first bootable device. Also the &#8216;-curses&#8217; option will make the kvm display all console output to your ssh session. (I&#8217;m assuming here, you&#8217;re creating this image over a remote connection, if you&#8217;re not you can probably skip the -curses option and kvm should use sdl drivers instead)</p>
<p>After finishing the installation you can test the new virtual machine by running:</p>
<div class="codesnip-container" >sudo kvm -m 256 -drive file=image.img,if=scsi,index=0,boot=on -boot c -curses -net nic,vlan=0,model=e1000,macaddr=00:16:e3:de:ad:01 -net tap</div>
<p>At this point you can add all the packages you want to have installed, all users, any settings that need to be present in your new UEC instances.</p>
<p>Now it&#8217;s also a good time to copy the kernel and the initrd image from your new vm image some place outside. They will be used later on to create and upload an complete virtual image to your UEC.</p>
<p>Before you shut your new shiny image down there&#8217;s one more step to be done:</p>
<p><b>Integration with UEC</b></p>
<p>Your new image needs to know what IP it has when started in UEC and also, it needs to know the public bit of the ssh key allowed to access it. The way it&#8217;s done in UEC (and EC2?) is via a restful interface provided by the cloud. The interface is available under this URL: http://169.254.169.254/latest/meta-data. You can use wget to see what information is provided:</p>
<div class="codesnip-container" >wget -q -O &#8211; http://169.254.169.254/latest/meta-data/</div>
<p>What&#8217;s interesting for us here is the public key data which is available here:</p>
<p>http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key</p>
<p>As we need to automate the whole process a bit, let&#8217;s put it all into an init.d script:</p>
<div class="codesnip-container" >#!/bin/bash<br />
#<br />
. /etc/rc.d/init.d/functions</p>
<p>RETVAL=0</p>
<p>start()<br />
{<br />
        fetch_ssh_key<br />
        regenerate_ssh_keys<br />
}</p>
<p>stop()<br />
{<br />
        echo &#8220;nothing to stop&#8230;&#8221;<br />
}</p>
<p>regenerate_ssh_keys()<br />
{<br />
        rm -f /etc/ssh/ssh_host_key /etc/ssh/ssh_host_rsa_key /etc/ssh_ssh_host_dsa_key<br />
        [ -f /etc/ssh/ssh_host_key ] || (ssh-keygen -f /etc/ssh/ssh_host_key -t rsa1 -C &#8216;host&#8217; -N &#8221; | logger -s -t &#8220;ec2&#8243;)<br />
        [ -f /etc/ssh/ssh_host_rsa_key ] || (ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa  -C &#8216;host&#8217; -N &#8221; | logger -s -t &#8220;ec2&#8243;)<br />
        [ -f /etc/ssh/ssh_host_dsa_key ] || (ssh-keygen -f /etc/ssh/ssh_host_dsa_key -t dsa  -C &#8216;host&#8217; -N &#8221; | logger -s -t &#8220;ec2&#8243;)</p>
<p>        echo &#8220;&#8212;&#8211;BEGIN SSH HOST KEY FINGERPRINTS&#8212;&#8211;&#8221; |logger -s -t &#8220;ec2&#8243;<br />
        ssh-keygen -l -f /etc/ssh/ssh_host_key.pub |logger -s -t &#8220;ec2&#8243;<br />
        ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub |logger -s -t &#8220;ec2&#8243;<br />
        ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub |logger -s -t &#8220;ec2&#8243;<br />
        echo &#8220;&#8212;&#8211;END SSH HOST KEY FINGERPRINTS&#8212;&#8211;&#8221;   |logger -s -t &#8220;ec2&#8243;<br />
}</p>
<p>fetch_ssh_key()<br />
{<br />
        if [ ! -d /root/.ssh ] ; then<br />
                mkdir -p /root/.ssh<br />
                chmod 700 /root/.ssh<br />
        fi</p>
<p>        curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/ssh-key<br />
        if [ $? -eq 0 ] ; then<br />
                cat /tmp/ssh-key >> /root/.ssh/authorized_keys<br />
                chmod 600 /root/.ssh/authorized_keys<br />
                rm /tmp/ssh-key<br />
                # disable password logging<br />
                sed -i.bkp &#8216;s/^PasswordAuthentication yes/PasswordAuthentication no/&#8217; /etc/ssh/sshd_config<br />
        fi<br />
}</p>
<p>case &#8220;$1&#8243; in<br />
        start)<br />
                start<br />
                ;;<br />
        stop)<br />
                stop<br />
                ;;<br />
        restart)<br />
                stop<br />
                start<br />
                ;;<br />
        condrestart)<br />
                echo &#8220;not implemented&#8221;<br />
                ;;<br />
        status)<br />
                echo &#8220;not implemented&#8221;<br />
                ;;</p>
<p>        *)<br />
                echo $&#8221;Usage: $0 {start|stop|restart|reload|condrestart|status}&#8221;<br />
                RETVAL=1<br />
esac</p>
<p>exit $RETVAL</p></div>
<p>Enable this script in your boot process. The script will not only download and install this key on root account. It also regenerates your instance&#8217; keys and displays their fingerprints on the console (so you can see them by doing euca-get-console-output i-instance_number)</p>
<p>This script is just a simple example, you can also take the python uec backend available in ubuntu and use it to do the same thing i a slightly better and cleaner way.</p>
<p><b>Uploading to UEC</b></p>
<p>The last step is uploading your image to UEC:</p>
<p>bundle and upload the previously copied kernel first:</p>
<div class="codesnip-container" >euca-bundle-image -i kvm-kernel/vmlinuz-2.6.28-11-generic &#8211;kernel true<br />
euca-upload-bundle -k mybucket -m /tmp/vmlinuz-2.6.28-11-generic.manifest.xml<br />
euca-register mybucket/vmlinuz-2.6.28-11-generic.manifest.xml</div>
<p>save the k-* output produced by the last command above and proceed with initrd:</p>
<div class="codesnip-container" >euca-bundle-image -i kvm-kernel/initrd.img-2.6.28-11-generic<br />
euca-upload-bundle -b mybucket  /tmp/initrd.img-2.6.28-11-generic.manifest.xml<br />
euca-register mybucket/initrd.img-2.6.28-11-generic.manifest.xml</div>
<p>as above, save the i-* output and upload the image now:</p>
<div class="codesnip-container" >euca-bundle-image -i image.img &#8211;kernel $PREVIOUSLY_SAVED_KERNELID &#8211;ramdisk $PREVIOUSLY_SAVED_IMAGERD<br />
euca-upload-bundle -b mybucket -m /tmp/image.img.manifest.xml<br />
euca-register mybucket/image.img.manifest.xml</div>
<p>All done, your new image should be visible after euca-describe-images -a.</p>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2009/11/15/how-to-create-a-new-kvm-image-for-eucalyptus-uec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ssh port knocking with pf</title>
		<link>http://bsd.dischaos.com/2009/10/24/ssh-port-knocking-with-pf/</link>
		<comments>http://bsd.dischaos.com/2009/10/24/ssh-port-knocking-with-pf/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 13:39:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[bsd]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[pf]]></category>
		<category><![CDATA[port knocking]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=143</guid>
		<description><![CDATA[The idea of port knocking is simple &#8211; a service, normally firewalled accepts connections from a given source IP if that IP address has connected to certain ports in some special sequence. This is a simplified implementation of this idea using pf to protect the ssh service. In pf.conf file: &#8230; ### pf tables table [...]]]></description>
			<content:encoded><![CDATA[<p>The idea of port knocking is simple &#8211; a service, normally firewalled accepts connections from a given source IP if that IP address has connected to certain ports in some special sequence. This is a simplified implementation of this idea using pf to protect the ssh service.</p>
<p>In pf.conf file:</p>
<div class="codesnip-container" >&#8230;<br />
### pf tables<br />
table &lt;ssh_accept&gt; persist<br />
&#8230;<br />
### pf rules<br />
block in log all<br />
&#8230;<br />
pass in quick on $if proto tcp from &lt;ssh_accept&gt; to $me port 22 flags S/SA keep state<br />
&#8230;<br />
# there&#8217;s no service listening on 31337 so we need synproxy state to complete the handshake<br />
pass in quick on $if proto tcp from any to $me port {31337} synproxy state (max-src-conn-rate 3/5, overload &lt;ssh_accept&gt;<br />
&#8230;</div>
<p>This will open port 22 on the $me host if there are 3 attempts to connect to port 31337 within 5 seconds.</p>
<p>From this moment ssh access to $me is granted. This shouldn&#8217;t probably be allowed forever, so this crontab entry will clear all entries in the ssh_accept table not used within last 5 minutes:</p>
<div class="codesnip-container" >*/5      *       *       *       *       root    /sbin/pfctl -q -t ssh_accept -T expire 300</div>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2009/10/24/ssh-port-knocking-with-pf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RPM build environment on CentOS</title>
		<link>http://bsd.dischaos.com/2009/09/02/rpm-build-environment-on-centos/</link>
		<comments>http://bsd.dischaos.com/2009/09/02/rpm-build-environment-on-centos/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 21:42:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[redhat]]></category>
		<category><![CDATA[rpm]]></category>
		<category><![CDATA[rpmbuild]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=106</guid>
		<description><![CDATA[Just a quick note on how to build RPMs setting up build environment RPMs should be built from a &#8221;&#8217;standard user&#8221;&#8217; account, &#8221;&#8217;not root&#8221;&#8217;. This saves a lot of trouble when something goes wrong during package preparation/installation and keeps the build environment clean. Here&#8217;s how to setup build environment in your home directory: mkdir -p [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick note on how to build RPMs</p>
<h3> setting up build environment </h3>
<p>RPMs should be built from a &#8221;&#8217;standard user&#8221;&#8217; account, &#8221;&#8217;not root&#8221;&#8217;. This saves a lot of trouble when something goes wrong during package preparation/installation and keeps the build environment clean.</p>
<p>Here&#8217;s how to setup build environment in your home directory:</p>
<div class="codesnip-container" >mkdir -p ~/build/{BUILD,RPMS,S{OURCES,PECS,RPMS}}</div>
<p>These directories are for:</p>
<p>BUILD &#8211; that&#8217;s the place where your source package will get untargzipped, patched and compiled<br />
RPMS &#8211; will contain your RPMS when done<br />
SOURCES &#8211; upload all source .tar.gz&#8217;s and your patches here<br />
SPECS &#8211; .spec files with instructions on how to build your packages<br />
SRPMS &#8211; source RPMS, a bit more about them below</p>
<p>Now you need to tell rpm-build where to look for these directories:</p>
<div class="codesnip-container" >echo &#8220;%_topdir $HOME/build&#8221; &gt; ~/.rpmmacros</div>
<p>and finally you need to install some software:</p>
<div class="codesnip-container" >sudo yum install rpm-build redhat-rpm-config mock</div>
<p>(Keep in mind, that the list above is not complete as it doesn&#8217;t contain any compilers, libtools, automakes etc, that might be required to actually build your source package.)</p>
<p>and create a &#8216;special&#8217; user for the mock package (this is to allow fakeroot builds):</p>
<div class="codesnip-container" >sudo useradd -M -d / -s /sbin/nologin mockbuild</div>
<h3> building from SRPMs (easy!)  </h3>
<p>SRPMS (source RPMS) contain the .spec file and all necessary source files and patches needed to build a binary package. This can be usefull if there&#8217;s no binary package available for your platform but there&#8217;s a source one available for a similar one (redhat.srpms to build packages for centos).</p>
<p>One way to build a binary package from a source one is to:</p>
<div class="codesnip-container" >rpmbuild &#8211;rebuild package-1.0.src.rpm</div>
<p>This will do all the magic and (hopefully) put a binary package in build/RPMS/$arch/</p>
<p>Other way is to install (as user, it will put all sources and patches to build/SOURCES and the spec file to build/SPECS) the source package first and then use rpmbuild:</p>
<div class="codesnip-container" >rpm -i package-1.0.src.rpm<br />
rpmbuild -ba ~/build/SPECS/package-1.0.spec</div>
<p>According to the documentation you can build RPMs from .tar.gzs if they contain a .spec file. You would do it by using -ta option for rpmbuild instead of -ba.</p>
<h3>building from source</h3>
<p>This means creating your own package from scratch. There&#8217;s how to do it:</p>
<p>First see if the package builds from source without any tweaking. Check if it (or the resulting package you want built) requires any special options to be passed to either ./configure or make. Also at this point think of any modifications to the original source code you&#8217;d like to have (changes in default config files, additional modules compiled in or removed from the package etc etc).</p>
<p>If you do need some changes done, this is a good time to make all the patches.<br />
Make a clean and untouched copy of the untargzipped package:</p>
<div class="codesnip-container" >tar xvfz moosoft-1.0.tar.gz<br />
cp -Rvp moosoft-1.0 moosoft-1.0.orig</div>
<p>now make all the required changes in the moosoft-1.0 directory and generate patch or a set of patches:</p>
<div class="codesnip-container" >diff -uNr moosoft-1.0.orig moosoft-1.0 &gt; moosoft-1.0.bigpatch.patch<br />
# or:<br />
diff -uNr moosoft-1.0.orig/etc/moo.conf moosoft-1.0/etc/moo.conf &gt;<br />
moosoft-1.0.config.patch<br />
diff -uNr moosoft-1.0.orig/doc/ moosoft-1.0/doc &gt;<br />
moosoft-1.0.documentation.patch<br />
# etc&#8230; to generate multiple patches</div>
<p>Copy these patches and the original moosoft-1.0.tar.gz file to ~/build/SOURCES.</p>
<p>The last thing to do is to prepare a recipe for rpmbuild how to build your package. Create moosoft-1.0.spec file in ~/build/SPECS:</p>
<pre>#                  _____________________________
#         (__)    /                             \
#         (oo)   ( This is an example .spec file )
#  /-------\/  --'\_____________________________/
# / |     ||
#*  ||----||
#   ^^    ^^
####
# package preamble
# one line description of the package
Summary: Very important Unix tool
Name: moo
Version: 1.0
# this marks the internal release version: moo-1.0-1.666.x86_64.rpm
Release: 1.666
License: BSD
# group you want your package in, mostly for GUI package browsers
# some example groups used by vendors:
# http://www.rpmfind.net/linux/RPM/Groups.html
Group: Networking/Daemons
# your name for example
Packager:
#
Source: http://full.url.to.the/package/%{name}-%{version}.tar.gz
Source1: moo.init
# list all your patches here:
Patch0: moo-1.0.etc.patch
Patch1: moo-1.0.documentation.patch
# list all packages required to build this package
BuildRequires: openssl-devel
Provides:
# list all packages that conflict with this one:
Conflicts: bse
BuildRoot: %{_tmppath}/%{name}-%{version}-build

####
# full length description
%description

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eros elit,
pretium eu vestibulum vel, blandit vel nisl. Fusce mattis volutpat
pellentesque. Etiam sit amet magna eget dui faucibus rutrum. Aliquam a ligula
erat. Proin metus tortor, sollicitudin et accumsan quis, hendrerit non leo.
Curabitur egestas neque sed nulla vulputate vel bibendum sapien tristique.
Vivamus malesuada, magna et semper iaculis, magna lorem adipiscing erat, vel
euismod enim nulla vel tortor. Vestibulum accumsan placerat sagittis. Sed
commodo pretium lectus et dignissim. Ut nec orci tellus.

#####
# this prepares a fresh build directory in ~/build/BUILD, useful macros here
# are:
# %setup - cleans any previous builds and untargzips the source
# %patch - applies patches
# any other commands here are executed as standard sh commands
%prep

%setup
%patch
%patch1

./configure --enable-something --with-something-else

#####
# this tells rpmbuild how to build your package, rpmbuild runs it as a sh
# script
%build
make

#####
# all the steps necessary to install your package into $RPM_BUILD_ROOT
# first step is to clear $RPM_BUILD_ROOT
%install
[ "$RPM_BUILD_ROOT" != "/" ] &amp;&amp; rm -rf $RPM_BUILD_ROOT
#install all files under RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT

# now you can remove uneeded stuff
rm -f $RPM_BUILD_ROOT{_prefix}/sbin/rc.moo

#####
# NOTE: this section is optional
# commands run just before the package is installed
%pre
/usr/sbin/useradd -c "moo user" -r -s /bin/false -u 666 -d / moo 2&gt; /dev/null
|| :

#####
# NOTE: this section is optional
# commands run before uninstalling the software
%preun
/sbin/service moo stop &gt; /dev/null 2&gt;&amp;1
/sbin/chkconfig --del moo

#####
# NOTE: this section is optional
# commands run after installing the package
%post
/sbin/chkconfig -add moo
touch /var/log/moo

#####
# NOTE: this section is optional
# commands run after unistalling the package
%postun
/sbin/service moo stop
/usr/sbin/userdel moo

#####
# list all the files that are part of the package. If a file is not in the
# list rpmbuild won't put it in the package
# see below on how to automate the process of creating this list.
# some useful macros here:
# %doc filename - installs filename into /usr/share/doc/moo-1.0/
# %doc /path/to/filename - installs filename into /path/to/filename and marks
# it as being documentation
# %config /etc/config_file - similar for configuration files
# %attr(mode, user, group) file - lets you specify file attributes applied
# during installation, use - if you want to use defaults
%files
/usr/bin/moo
/usr/sbin/moomoo
# this will package the dir and all directories inside it
/example/of/a/dir
# this will package only the 'dir' directory
%dir /example/of/a/dir

#####
# document changes between package releases
%changelog
* Wed Jul 8 2009 Your Name Here
- another version of the package

* Mon Jul 6 2009 Your Name Here
- initial version of the package</pre>
<p>To get the list of all installed files do</p>
<div class="codesnip-container" >rpmbuild -bi ~/build/SPECS/moo-1.0.spec</div>
<p>this will go through prep, build and install steps of the spec file and install all files under $RPM_BUILD_ROOT, which in this case should be /var/tmp/moo-1.0-build.</p>
<div class="codesnip-container" >ls -R1 /var/tmp/moo-1.0-build</div>
<p>and use the output to populate the %files section</p>
<p>Now the package can be build by running:</p>
<div class="codesnip-container" >rpmbuild -ba ~/build/SPECS/moo-1.0.spec</div>
<h3> building with modules </h3>
<p>Sometimes it&#8217;s helpful to split one package into multiple modules. Here&#8217;s an example .spec file for a library, it will produce two packages: libmoo (with the shared objects provided by the library) and libmoo-devel (with all headers and static libraries)</p>
<pre>#                  _____________________________
#         (__)    /                             \
#         (oo)   ( This is an example .spec file )
#  /-------\/  --'\_____________________________/
# / |     ||
#*  ||----||
#   ^^    ^^
####
# package preamble
# one line description of the package
Summary: An Example library
Name: libmoo
Version: 1.0
# this marks the internal release version: libmoo-1.0-1.666.x86_64.rpm
Release: 1.666
License: BSD
# group you want your package in, mostly for GUI package browsers
# some example groups used by vendors:
# http://www.rpmfind.net/linux/RPM/Groups.html
Group: Development/Libraries
# your name for example
Packager:
#
Source: http://full.url.to.the/package/%{name}-%{version}.tar.gz
# list all your patches here:
Patch0: moo-1.0.etc.patch
Patch1: moo-1.0.documentation.patch
# list all packages required to build this package
BuildRequires: openssl-devel
Provides:
# list all packages that conflict with this one:
Conflicts: bse
BuildRoot: %{_tmppath}/%{name}-%{version}-build

####
# changes in the preamble for libmoo-devel package
%package devel
Summary: libmoo development files and headers
Group: Development/Libraries
# -devel requires the main package
Requires: %name = %version

####
# full length description
%description

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eros elit,
pretium eu vestibulum vel, blandit vel nisl. Fusce mattis volutpat
pellentesque. Etiam sit amet magna eget dui faucibus rutrum. Aliquam a ligula
erat. Proin metus tortor, sollicitudin et accumsan quis, hendrerit non leo.
Curabitur egestas neque sed nulla vulputate vel bibendum sapien tristique.
Vivamus malesuada, magna et semper iaculis, magna lorem adipiscing erat, vel
euismod enim nulla vel tortor. Vestibulum accumsan placerat sagittis. Sed
commodo pretium lectus et dignissim. Ut nec orci tellus.

####
# full description of the -devel package
%description devel

static libraries and headers for libmoo 

#####
# this prepares a fresh build directory in ~/build/BUILD, useful macros here
# are:
# %setup - cleans any previous builds and untargzips the source
# %patch - applies patches
# any other commands here are executed as standard sh commands
%prep

%setup
%patch
%patch1

./configure --enable-something --with-something-else

#####
# this tells rpmbuild how to build your package, rpmbuild runs it as a sh
# script
%build
make

#####
# all the steps necessary to install your package into $RPM_BUILD_ROOT
# first step is to clear $RPM_BUILD_ROOT
%install
[ "$RPM_BUILD_ROOT" != "/" ] &amp;&amp; rm -rf $RPM_BUILD_ROOT
#install all files under RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT

# now you can remove uneeded stuff
rm -f $RPM_BUILD_ROOT{_prefix}/sbin/rc.moo

#####
# NOTE: this section is optional
# commands run just before the package is installed
%pre
/usr/sbin/useradd -c "moo user" -r -s /bin/false -u 666 -d / moo 2&gt; /dev/null
|| :

#####
# NOTE: this section is optional
# commands run before uninstalling the software
%preun
/sbin/service moo stop &gt; /dev/null 2&gt;&amp;1
/sbin/chkconfig --del moo

#####
# NOTE: this section is optional
# commands run after installing the package
%post
/sbin/ldconfi

#####
# NOTE: this section is optional
# commands run after unistalling the package
%postun
/sbin/ldconfig

#####
# list all the files that are part of the package. If a file is not in the
# list rpmbuild won't put it in the package
# see below on how to automate the process of creating this list.
# some useful macros here:
# %doc filename - installs filename into /usr/share/doc/moo-1.0/
# %doc /path/to/filename - installs filename into /path/to/filename and marks
# it as being documentation
# %config /etc/config_file - similar for configuration files
# %attr(mode, user, group) file - lets you specify file attributes applied
# during installation, use - if you want to use defaults
%files
%defattr(-,root,root,0755)
%attr(755,root,root) %_prefix/lib/lib*.so.*
%doc INSTALL ChangeLog

#####
# separate list of files for the -devel modules
%files devel
%defattr(-,root,root,0755)
%attr(755,root,root) %_prefix/lib/lib*.so
%attr(644,root,root) %_prefix/lib/*.a
#exclude *.la files
%exclude %_prefix/lib/*.la

#####
# document changes between package releases
%changelog
* Wed Jul 8 2009 Your Name
- another version of the package

* Mon Jul 6 2009 Your Name
- initial version of the package</pre>
<p>building the package with rpmbuild -ba libmoo-1.0.spec will produce two files:</p>
<p>libmoo-1.0-1.666.arch.rpm and libmoo-devel-1.0-1.666.arch.rpm</p>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2009/09/02/rpm-build-environment-on-centos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Graphing Alteon configuration</title>
		<link>http://bsd.dischaos.com/2009/08/31/graphing-alteon-configuration/</link>
		<comments>http://bsd.dischaos.com/2009/08/31/graphing-alteon-configuration/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 22:15:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[other]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=126</guid>
		<description><![CDATA[If you happen to use Nortel&#8217;s Alteon load balancers and need something to help you visualise your configuration here&#8217;s a script that produces graphs of connections and dependencies between groups, virtual IPs, real IPs and services in the Alteon configuration. It&#8217;s not very useful, the code is ugly, but the graphs are cool to look [...]]]></description>
			<content:encoded><![CDATA[<p>If you happen to use Nortel&#8217;s Alteon load balancers and need something to help you visualise your configuration <a href="http://bsd.dischaos.com/files/graph_gen.py">here&#8217;s a script</a> that produces graphs of connections and dependencies between groups, virtual IPs, real IPs and services in the Alteon configuration. It&#8217;s not very useful, the code is ugly, but the graphs are cool to look at <img src='http://bsd.dischaos.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Especially for huge config files with lots of services and VIPs. The script uses two great python libraries &#8211; <a href="http://code.google.com/p/python-graph/">pygraph</a> and <a href="http://www.graphviz.org/Resources.php">graphviz</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2009/08/31/graphing-alteon-configuration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting all prefixes advertised by an AS</title>
		<link>http://bsd.dischaos.com/2009/07/22/getting-all-prefixes-advertised-by-an-as/</link>
		<comments>http://bsd.dischaos.com/2009/07/22/getting-all-prefixes-advertised-by-an-as/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 21:33:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[other]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[as]]></category>
		<category><![CDATA[ripe]]></category>
		<category><![CDATA[whois]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=116</guid>
		<description><![CDATA[This simple script displays all prefixes advertised by an AS. It uses RIPE&#8217;s looking glass to get their local BGP table and parses it for the given AS number. For example, to get all the other networks advertised by the AS dischaos.com is in, first I need to get Layered tech&#8217;s AS number: whois -h [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bsd.dischaos.com/files/getprefixes.py">This simple script</a> displays all prefixes advertised by an AS. It uses RIPE&#8217;s looking glass to get their local BGP table and parses it for the given AS number.</p>
<p>For example, to get all the other networks advertised by the AS dischaos.com is in, first I need to get Layered tech&#8217;s AS number:</p>
<p>whois -h www.ris.ripe.net 216.32.74.94</p>
<blockquote><p>
% This is RIPE NCC&#8217;s Routing Information Service<br />
% whois gateway to collected BGP Routing Tables<br />
% IPv4 or IPv6 address to origin prefix match<br />
%<br />
% For more information visit http://www.ripe.net/ris/riswhois.html</p>
<p>route:        216.0.0.0/8<br />
origin:       AS3303<br />
descr:        SWISSCOM Swisscom (Switzerland) Ltd<br />
lastupd-frst: 2009-06-08 11:31Z  192.65.185.243@rrc04<br />
lastupd-last: 2009-06-08 11:31Z  192.65.185.243@rrc04<br />
seen-at:      rrc04<br />
num-rispeers: 1<br />
source:       RISWHOIS</p>
<p>route:        216.32.0.0/14<br />
origin:       AS3561<br />
descr:        SAVVIS &#8211; Savvis<br />
lastupd-frst: 2009-06-08 12:56Z  198.32.160.22@rrc11<br />
lastupd-last: 2009-07-22 12:06Z  195.69.145.49@rrc03<br />
seen-at:      rrc00,rrc01,rrc03,rrc04,rrc06,rrc07,rrc10,rrc11,rrc12,rrc13,rrc15,rrc16<br />
num-rispeers: 86<br />
source:       RISWHOIS</p>
<p>route:        216.32.64.0/19<br />
origin:       AS22576<br />
descr:        LAYER3-ASN &#8211; Layered Technologies, Inc.<br />
lastupd-frst: 2009-06-08 12:56Z  198.32.160.22@rrc11<br />
lastupd-last: 2009-07-22 14:55Z  193.232.244.147@rrc13<br />
seen-at:      rrc00,rrc01,rrc03,rrc04,rrc06,rrc07,rrc10,rrc11,rrc12,rrc13,rrc15,rrc16<br />
num-rispeers: 85<br />
source:       RISWHOIS</p>
</blockquote>
<p>Their AS number is 22576. Now lets see what other networks they advertise:</p>
<blockquote><p>
$ ./getprefixes.py 22576<br />
networks advertised by AS22576:<br />
64.92.160.0/20<br />
72.21.32.0/19<br />
72.36.128.0/17<br />
72.232.0.0/17<br />
72.232.128.0/19<br />
72.232.160.0/21<br />
72.232.168.0/22<br />
72.232.172.0/23<br />
72.232.174.0/23<br />
72.232.176.0/20<br />
72.232.192.0/18<br />
72.233.0.0/19<br />
72.233.28.0/22<br />
72.233.32.0/19<br />
72.233.64.0/18<br />
72.233.64.0/20<br />
72.233.80.0/23<br />
72.233.82.0/23<br />
72.233.84.0/23<br />
72.233.86.0/23<br />
72.233.88.0/21<br />
72.233.96.0/22<br />
72.233.100.0/22<br />
72.233.104.0/21<br />
72.233.112.0/21<br />
72.233.120.0/21<br />
72.233.127.0/24<br />
208.95.152.0/22<br />
209.67.208.0/20<br />
216.32.64.0/19
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2009/07/22/getting-all-prefixes-advertised-by-an-as/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

