<?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>Tadek's Blog &#187; Tips&amp;Tricks</title>
	<atom:link href="http://tadek.pietraszek.org/blog/category/tipstricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://tadek.pietraszek.org/blog</link>
	<description>Some random notes about computers, security, cool links and others.</description>
	<lastBuildDate>Fri, 12 Dec 2008 22:49:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Talking TLS to SMTP</title>
		<link>http://tadek.pietraszek.org/blog/2008/12/02/talking-tls-to-smtp/</link>
		<comments>http://tadek.pietraszek.org/blog/2008/12/02/talking-tls-to-smtp/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 13:06:48 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/?p=375</guid>
		<description><![CDATA[I recently wanted to test TLS with SMTP. I followed instructions on  http://qmail.jms1.net/test-auth.shtml and got it to work in less than 30s  

In short:

perl -MMIME::Base64 -e 'print encode_base64("\000user\000password")'
openssl s_client -starttls smtp -crlf -connect &#60;ip&#62;:&#60;port&#62;
auth &#60;auth_command&#62;
mail from:&#60;tadek@pietraszek.org&#62;
rcpt to:&#60;tadek@pietraszek.org&#62;
data
...
.


Interestingly, when I tried typing RCPT s_client would interpret it as &#8220;renegotiate&#8221;, which confused me a bit, [...]]]></description>
			<content:encoded><![CDATA[<p>I recently wanted to test TLS with SMTP. I followed instructions on  <a href="http://qmail.jms1.net/test-auth.shtml">http://qmail.jms1.net/test-auth.shtml</a> and got it to work in less than 30s <img src='http://tadek.pietraszek.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<p>In short:
<pre>
perl -MMIME::Base64 -e 'print encode_base64("\000user\000password")'
openssl s_client -starttls smtp -crlf -connect &lt;ip&gt;:&lt;port&gt;
auth &lt;auth_command&gt;
mail from:&lt;tadek@pietraszek.org&gt;
rcpt to:&lt;tadek@pietraszek.org&gt;
data
...
.
</pre></p>

<p>Interestingly, when I tried typing <code>RCPT</code> s_client would interpret it as &#8220;renegotiate&#8221;, which confused me a bit, but you can inhibit it with <code>--quiet</code> or type it in lowercase like I did <img src='http://tadek.pietraszek.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<p>T.</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2008/12/02/talking-tls-to-smtp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>xdu: analyzing disk-space usage</title>
		<link>http://tadek.pietraszek.org/blog/2008/11/27/xdu-analyzing-disk-space-usage/</link>
		<comments>http://tadek.pietraszek.org/blog/2008/11/27/xdu-analyzing-disk-space-usage/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 16:05:50 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips&Tricks]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/?p=371</guid>
		<description><![CDATA[I recently started getting nagmails about running out of quota on my home directory. Being a very messy user, I had no idea where the space went. I tried playing with du manually, but it&#8217;s much easier with xdu:

sudo apt-get install xdu
du &#62; /tmp/blah
xdu -n /tmp/blah
]]></description>
			<content:encoded><![CDATA[<p>I recently started getting nagmails about running out of quota on my home directory. Being a very messy user, I had no idea where the space went. I tried playing with <code>du</code> manually, but it&#8217;s much easier with <code>xdu</code>:</p>

<p><pre>sudo apt-get install xdu
du &gt; /tmp/blah
xdu -n /tmp/blah</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2008/11/27/xdu-analyzing-disk-space-usage/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Importing trusted CA certificate in OSX</title>
		<link>http://tadek.pietraszek.org/blog/2008/04/28/importing-trusted-ca-certificate-in-osx/</link>
		<comments>http://tadek.pietraszek.org/blog/2008/04/28/importing-trusted-ca-certificate-in-osx/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 08:50:14 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Links]]></category>
		<category><![CDATA[Tips&Tricks]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/?p=359</guid>
		<description><![CDATA[http://net.its.hawaii.edu/advanced/make_work/IPSec/MacOSXTiger/mactigercert.html &#8211; how to import a trusted CA certificate in OSX.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://net.its.hawaii.edu/advanced/make_work/IPSec/MacOSXTiger/mactigercert.html">http://net.its.hawaii.edu/advanced/make_work/IPSec/MacOSXTiger/mactigercert.html</a> &#8211; how to import a trusted CA certificate in OSX.</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2008/04/28/importing-trusted-ca-certificate-in-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing all files older than X days</title>
		<link>http://tadek.pietraszek.org/blog/2008/03/19/removing-all-files-older-than-x-days/</link>
		<comments>http://tadek.pietraszek.org/blog/2008/03/19/removing-all-files-older-than-x-days/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 15:39:50 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Tips&Tricks]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2008/03/19/removing-all-files-older-than-x-days/</guid>
		<description><![CDATA[I know it&#8217;s easy, but every time I write it I have to study the man page of find to figure out the correct parameters:

File only deletion:

find &#60;dir&#62; -atime +7 -type f -print &#124; xargs rm -f


Recursive deletion (be careful):

find &#60;dir&#62; -atime +7 -print &#124; xargs rm -rf

]]></description>
			<content:encoded><![CDATA[<p>I know it&#8217;s easy, but every time I write it I have to study the man page of <code>find</code> to figure out the correct parameters:</p>

<p>File only deletion:</p>

<pre><code>find &lt;dir&gt; -atime +7 -type f -print | xargs rm -f
</code></pre>

<p>Recursive deletion (be careful):</p>

<pre><code>find &lt;dir&gt; -atime +7 -print | xargs rm -rf
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2008/03/19/removing-all-files-older-than-x-days/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Installing SVN with Apache2 support on my server.</title>
		<link>http://tadek.pietraszek.org/blog/2008/03/06/installing-svn-with-apache2-support-on-my-server/</link>
		<comments>http://tadek.pietraszek.org/blog/2008/03/06/installing-svn-with-apache2-support-on-my-server/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 22:11:09 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2008/03/06/installing-svn-with-apache2-support-on-my-server/</guid>
		<description><![CDATA[I just enabled SVN access on my server through the web interface. It was quite easy and, since we have a Postgres DB authentication, there&#8217;s no need to edit inconvenient password files  

All I had to do was to enable the SVN module: link dav_svn.{load&#124;conf} in mods-enabled and add the following line to the [...]]]></description>
			<content:encoded><![CDATA[<p>I just enabled SVN access on my server through the web interface. It was quite easy and, since we have a Postgres DB authentication, there&#8217;s no need to edit inconvenient password files <img src='http://tadek.pietraszek.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<p>All I had to do was to enable the SVN module: link <code>dav_svn.{load|conf}</code> in <code>mods-enabled</code> and add the following line to the SSL-ed vhost.</p>

<pre><code>&lt;Location "/svn/foo"&gt;
   SVNPath /var/lib/svn/foo
   Dav svn
  &lt;LimitExcept OPTIONS GET&gt;
    Require user user@example.com user2@example.com
  &lt;/LimitExcept&gt;
&lt;/Location&gt;
</code></pre>

<p>Since the SSL-ed vhost already requires authentication, I didn&#8217;t have to change anything. I also had to create an SVN repository <code>svnadmin create --fs-type fsfs /var/lib/svn/foo</code> and change the permissions to <code>www-data</code>.</p>

<p>The checkout command is:</p>

<p>svn &#8211;username user@example.com &#8211;password my_secret_password co https://my.example.com/svn/foo</p>

<p>SVN caches the username and password, so any further operations are done without prompting you for it. If you don&#8217;t like it, you can disable it with <code>--no-auth-cache</code>.</p>

<p>Finally, one annoying thing. Initially, I would just try to connect without &#8211;username and SVN would first try my Unix user name and then ask for it. Unfortunately, some (but not all) users I tried in this way would get a mysterious:</p>

<pre><code>svn: PROPFIND request failed on '/svn/foo'
svn: PROPFIND of '/svn/foo': authorization failed (https://example.com)
</code></pre>

<p>WTH?</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2008/03/06/installing-svn-with-apache2-support-on-my-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache2.0 -&gt; Apache 2.2 upgrade issues</title>
		<link>http://tadek.pietraszek.org/blog/2008/03/04/apache20-apache-22-upgrade-issues/</link>
		<comments>http://tadek.pietraszek.org/blog/2008/03/04/apache20-apache-22-upgrade-issues/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 10:00:37 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2008/03/04/apache20-apache-22-upgrade-issues/</guid>
		<description><![CDATA[While upgrading apache 2.0 -> 2.2 I found that two configuration options have changed:


AuthAutoritative -> AuthBasicAuthoritative (needs to be set to Off for mod_auth_pgsql to work).
AuthDigestFile -> AuthUserFile


Plus there has been a log of changes in apache2.conf. I looked at the changes we made (keeping /etc/ in SVN comes in handy, in spite of occasional [...]]]></description>
			<content:encoded><![CDATA[<p>While upgrading apache 2.0 -> 2.2 I found that two configuration options have changed:</p>

<ul>
<li><code>AuthAutoritative</code> -> <code>AuthBasicAuthoritative</code> (needs to be set to Off for mod_auth_pgsql to work).</li>
<li><code>AuthDigestFile</code> -> <code>AuthUserFile</code></li>
</ul>

<p>Plus there has been a log of changes in <code>apache2.conf</code>. I looked at the changes we made (keeping /etc/ in SVN comes in handy, in spite of occasional pain) and pasted them to the vanilla apache2.conf that came with 2.2.</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2008/03/04/apache20-apache-22-upgrade-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WTH: eth0 got renamed to eth2 after an upgrade</title>
		<link>http://tadek.pietraszek.org/blog/2008/03/04/wth-eth0-got-renamed-to-eth2-after-an-upgrade/</link>
		<comments>http://tadek.pietraszek.org/blog/2008/03/04/wth-eth0-got-renamed-to-eth2-after-an-upgrade/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 09:49:14 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2008/03/04/wth-eth0-got-renamed-to-eth2-after-an-upgrade/</guid>
		<description><![CDATA[While upgrading a remote server from sarge to etch including the new kernel, the server did not come up. After attaching a console (thanks Hetzner!) I found out that the network interface got mysteriously renamed to eth2!

After snooping around a bit, I found out that the culprit was udev, more specifically /etc/udev/rules.d/z25_persistent-net.rules which says:


 # [...]]]></description>
			<content:encoded><![CDATA[<p>While upgrading a <strong>remote server</strong> from sarge to etch including the new kernel, the server did not come up. After attaching a console (thanks Hetzner!) I found out that the network interface got mysteriously renamed to eth2!</p>

<p>After snooping around a bit, I found out that the culprit was udev, more specifically <code>/etc/udev/rules.d/z25_persistent-net.rules</code> which says:</p>

<p><pre>
 # This file was automatically generated by the /lib/udev/write_net_rules
 # program, probably run by the persistent-net-generator.rules rules file. 
 #
 # You can modify it, as long as you keep each rule on a single line.
 # MAC addresses must be written in lowercase.
 # PCI device 0x1106:0x3065 (via-rhine)
 SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:0c:76:af:2f:9d", NAME="eth0"
</pre></p>

<p>It also contained two entries for bogus eth0 and eth1 (usb dongle got identified as a network card?). After removing the and relabeling interfaces everything is back to normal now.</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2008/03/04/wth-eth0-got-renamed-to-eth2-after-an-upgrade/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Patching debian packages</title>
		<link>http://tadek.pietraszek.org/blog/2008/03/04/patching-debian-packages/</link>
		<comments>http://tadek.pietraszek.org/blog/2008/03/04/patching-debian-packages/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 09:42:43 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2008/03/04/patching-debian-packages/</guid>
		<description><![CDATA[While upgrading my server, I had to create a new version of Cyrus-SASL packages with the crypt patch. This turned out to be more difficult as I thought as just patching the raw source would conflict with debian patches applied after that and the package building would fail. Fortunately, I learned about (dpatch)[http://www.tuxmaniac.com/blog/2008/01/25/dpatch-just-superb-a-short-how-to/], which is [...]]]></description>
			<content:encoded><![CDATA[<p>While upgrading my server, I had to create a new version of Cyrus-SASL packages with the <a href="http://frost.ath.cx/software/cyrus-sasl-patches/">crypt patch</a>. This turned out to be more difficult as I thought as just patching the raw source would conflict with debian patches applied after that and the package building would fail. Fortunately, I learned about (dpatch)[http://www.tuxmaniac.com/blog/2008/01/25/dpatch-just-superb-a-short-how-to/], which is a standard mechanism for patching stuff in Debian.</p>

<p>Once I figured out how to do it, it tunred out to be very simple:</p>

<ol>
<li>Unpack the original orig.tar.gz</li>
<li>Apply the Debian diff (this would create a debian subdirectory)</li>
<li>Edit changelog file to add a new release (so that we can keep track of it).</li>
<li>Run <code>dpatch-edit-patch fixing_foo</code> to create a patch. This will create a shell with mounted source package and any changes you make there will be included in the diff.</li>
<li><strong>Exit the shell without changing anything</strong>. You will change things after making sure that the patch is applied in the correct order.</li>
<li>Edit <code>00list</code> to set the patch ordering.</li>
<li>Run <code>dpatch-edit-patch</code> again now, with all the previous patches applied.</li>
<li>Make the necessary changes.</li>
<li>Build the target package with <code>debuild-pbuilder</code> (this will download all the dependencies too).</li>
<li>Install the pakcages with <code>dpkg -i</code> (I could also create my private apt-repository for this. I wrote about in in a blog entry about pbuilder).</li>
<li>Pin the packages so that they will not get upgraded <code>echo "package hold" | dpkg --set-selection</code></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2008/03/04/patching-debian-packages/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>sed and awk &#8211; my two old friends</title>
		<link>http://tadek.pietraszek.org/blog/2007/09/30/sed-and-awk-my-two-old-friends/</link>
		<comments>http://tadek.pietraszek.org/blog/2007/09/30/sed-and-awk-my-two-old-friends/#comments</comments>
		<pubDate>Sun, 30 Sep 2007 21:35:48 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Tips&Tricks]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2007/09/30/sed-and-awk-my-two-old-friends/</guid>
		<description><![CDATA[Writing some shell scripts I needed to do some a little fancier variable substitution than the standard shell offers. The heavyweight solution would be to write a perl one-liner, but this is, well&#8230;, heavyweight?  

Here&#8217;s a couple of patterns I used:

--parameter=$(sed -re 's/ /,/g' -e 's/(^&#124;,)/\1file:/g' ]]></description>
			<content:encoded><![CDATA[<p>Writing some shell scripts I needed to do some a little fancier variable substitution than the standard shell offers. The heavyweight solution would be to write a perl one-liner, but this is, well&#8230;, heavyweight? <img src='http://tadek.pietraszek.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<p>Here&#8217;s a couple of patterns I used:</p>

<ul><li><code>--parameter=$(sed -re 's/ /,/g' -e 's/(^|,)/\1file:/g' <<<$INPUT)</code> - replaces spaces with commas and prepends <code>file</code> to every file.</li>
<li><code>--parameter=$(awk '{split($0, a, /@/); printf "%s-?????-of-%05d", a[1], a[2]} <<<$INPUT)'<code></li> - replaces <code>file@5</code> with <code>file-?????-of-00005</code></li>
<li><code>--parameter=$(awk '{sub(/.*:/, ""); print $0}' <<<$INPUT) </code> - removes everything before the colon.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2007/09/30/sed-and-awk-my-two-old-friends/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing parameters in bash &#8211; a getopt template</title>
		<link>http://tadek.pietraszek.org/blog/2007/08/16/parsing-parameters-in-bash-a-getopt-template/</link>
		<comments>http://tadek.pietraszek.org/blog/2007/08/16/parsing-parameters-in-bash-a-getopt-template/#comments</comments>
		<pubDate>Thu, 16 Aug 2007 13:48:28 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[Tips&Tricks]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2007/08/16/parsing-parameters-in-bash-a-getopt-template/</guid>
		<description><![CDATA[Writing some bash scripts that parse command lines, I wrote this handy template with getopt. It is easy to apply even for simplest scripts.


OPTION_SPEC="help,flag1,flag2_params:"
PARSED_OPTIONS=$(getopt -n "$0" -a -o h --long $OPTION_SPEC -- "$@")
OPTIONS_RET=$?
eval set -- "$PARSED_OPTIONS"

Parsing error or no flags

if [ $OPTIONS_RET -ne 0 ] &#124;&#124; [ $# -le 0 ]; then
  usage;
  [...]]]></description>
			<content:encoded><![CDATA[<p>Writing some bash scripts that parse command lines, I wrote this handy template with <code>getopt</code>. It is easy to apply even for simplest scripts.</p>

<p><pre>
OPTION_SPEC="help,flag1,flag2_params:"
PARSED_OPTIONS=$(getopt -n "$0" -a -o h --long $OPTION_SPEC -- "$@")
OPTIONS_RET=$?
eval set -- "$PARSED_OPTIONS"</p>

<h1>Parsing error or no flags</h1>

<p>if [ $OPTIONS_RET -ne 0 ] || [ $# -le 0 ]; then
  usage;
  die;
fi</p>

<p>while [ $# -ge 1 ]; do
  case $1 in
    --help | -h )  usage; die;;
    --flag1 )  FLAG1=1;;
    --flag2_params )  shift; FLAG2_PARAMS="$1";;
    -- ) shift;;
    * ) echo "ERROR: unknown flag $1"; usage; die;;
  esac
  shift
done
</pre></p>

<p>No more unannotated <code>$n</code>s in my scripts!</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2007/08/16/parsing-parameters-in-bash-a-getopt-template/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
