<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-18167227</id><updated>2011-04-21T22:51:10.686-06:00</updated><title type='text'>HOWTO</title><subtitle type='html'>A compendium of tips and tricks for hackers and sysadmins</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://hackershowto.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18167227/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://hackershowto.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>David Gillies</name><uri>http://www.blogger.com/profile/04351694829320255035</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-18167227.post-114332443709058535</id><published>2006-03-25T13:57:00.000-06:00</published><updated>2006-03-26T18:40:18.633-06:00</updated><title type='text'>A few useful JavaScript utility functions</title><content type='html'>Here's some useful JavaScript utility functions. Firstly, here's the modern, recommended way to add an event listener to an object:
&lt;pre&gt;
function add_event(elem,event_name,func)
{
 if(elem.addEventListener)
    {
    elem.addEventListener(event_name,func,true);
    return true;
    }
 else if(elem.attachEvent)
    return elem.attachEvent("on"+event_name,func);
 else
    return false;
}
&lt;/pre&gt;
&lt;tt&gt;elem&lt;/tt&gt; is the object that you want to be listening for the event. You would typically obtain this with &lt;tt&gt;document.getElementById()&lt;/tt&gt;. &lt;tt&gt;event_name&lt;/tt&gt; is the name of the event you are listening for, e.g. &lt;tt&gt;click&lt;/tt&gt;, &lt;tt&gt;mouseover&lt;/tt&gt;, &lt;tt&gt;load&lt;/tt&gt; etc. &lt;tt&gt;func&lt;/tt&gt; is the name of the function you wish to be called when this event occurs. An example:

say you have a button, ID &lt;tt&gt;theButton&lt;/tt&gt;, and you want the function &lt;tt&gt;handle_button&lt;/tt&gt; to be called when it is clicked. Your HTML: &lt;tt&gt;&amp;lt;input type="button" name="theButton" is="theButton" value="CLICK" /&amp;gt;&lt;/tt&gt;. And the event listener is added in your JavaScript with &lt;tt&gt;add_event(document.getElementById('theButton'),'click',handle_button);&lt;/tt&gt;. Note that the &lt;tt&gt;func&lt;/tt&gt; is just the name of the function, without arguments.

This method of adding event listeners is recommended, since you're not cluttering your code with lots of &lt;tt&gt;onclick="…";"&lt;/tt&gt; etc. A good idea is to add an &lt;tt&gt;onload&lt;/tt&gt; listener to the window, and then set up all the subsidiary listeners within the handler function:
&lt;pre&gt;
function window_init(evt)
{
  add_event(document.getElementById('element1'),'click',handle_click);
  …
}

function handle_click(evt)
{
  if(!evt &amp;amp;&amp;amp; window.event)
     evt=window.event;

  event_target=get_target(evt) // see later
  alert(event_target.getAttribute('id');
}

add_event(window,'click',window_init);
&lt;/pre&gt;
&lt;hr width="50%"&gt;
An event can potentially be handled by more than one document element. For example, a form's submit button can trigger both the button's &lt;tt&gt;click&lt;/tt&gt; handler and the form's &lt;tt&gt;submit&lt;/tt&gt; handler. Sometimes that's not what you want. You need a method to stop the event proceeding further:
&lt;pre&gt;
function kill_event(e)
{
  if(window.event)
     {
     window.event.cancelBubble=true;
     window.event.returnValue=false;
     }
  else if(e &amp;amp;&amp;amp; e.preventDefault &amp;amp;&amp;amp; e.stopPropagation)
     {
     e.preventDefault();
     e.stopPropagation();
     }
}
&lt;/pre&gt;
You might want to use this function if a form fails validation, to stop it being submitted. Under Firefox/Mozilla, all event handler functions receive the event object as an argument. For Internet Explorer, the global window.event object is set. If you pass either of these objects to &lt;tt&gt;kill_event()&lt;/tt&gt;, it will proceed no further. It's also a good idea to return &lt;tt&gt;false&lt;/tt&gt; from the event's handler function.

&lt;hr width="50%"&gt;
You frequently want to know the element that received a mouse event. Unfortunately, the two main flavours of browser store this info in different places. This function user browser object detect to select the appropriate one:
&lt;pre&gt;
function get_target(evt)
{
  if(evt.srcElement)
     targ=evt.srcElement;
  else if(evt.target)
     targ=evt.target;
  else
     targ=false;

  return targ;
}
&lt;/pre&gt;
&lt;hr width="50%"&gt;
Many DHTML effects need to know the absolute position of an element in screen coordinates. This pair of functions will work in just about any browser:
&lt;pre&gt;
function get_x_pos(elem)
{
  var curleft=0;
  if(elem.offsetParent)
     {
     while(elem.offsetParent)
        {
        curleft+=elem.offsetLeft
        elem=elem.offsetParent;
        }
     }
  else if(elem.x)
     curleft+=elem.x;

  return curleft;
}

function get_y_pos(elem)
{
  var curtop=0;
  if(elem.offsetParent)
     {
     while(elem.offsetParent)
        {
        curtop+=elem.offsetTop
        elem=elem.offsetParent;
        }
     }
  else if(elem.y)
     curtop+=elem.y;

  return curtop;
}
&lt;/pre&gt;
The &lt;tt&gt;elem&lt;/tt&gt; parameter is the object whose x- or y-position you want, as returned by (e.g.) &lt;tt&gt;document.getElementById()&lt;/tt&gt;.

&lt;hr width="50%"&gt;
Another important piece of information is how far the window has been scrolled. You need to know this, for example, if you wish to ensure an element remains positioned in the viewport. The following pair of functions reutnr the horizontal and vertical scroll for the current &lt;tt&gt;window&lt;/tt&gt; object:
&lt;pre&gt;
function get_x_offset()
{
  var x;
  if(window.pageXOffset)
     x=window.pageXOffset;
  else if(document.documentElement &amp;amp;&amp;amp; document.documentElement.scrollLeft)
     x=document.documentElement.scrollLeft;
  else if(document.body)
     x=document.body.scrollLeft;
  return x;
}

function get_y_offset()
{
  var y;
  if(window.pageYOffset)
     y=window.pageYOffset;
  else if(document.documentElement &amp;amp;&amp;amp; document.documentElement.scrollTop)
     y=document.documentElement.scrollTop;
  else if(document.body)
     y=document.body.scrollTop;
  return y;
}
&lt;/pre&gt;
&lt;hr width="50%"&gt;
Getting the mouse position is in general impossible, because the different minority browsers implement a different set of objects and can also masquerade as other browsers. The following will work in the majority of cases:
&lt;pre&gt;
var gx,gy;

function get_mouse_pos(evt)
{
  if(event.clientX)
     {
     gx=event.clientX+document.body.scrollLeft;
     gy=event.clientY+document.body.scrollTop;
     }
  else
     {
     gx=evt.pageX;
     gy=evt.pageY;
     }

  gx=max(gx,0);
  gy=max(gy,0);

  return true;
}

function max(a,b)
{
  if(a&amp;gt;b)
     return a;
  return b;
}
&lt;/pre&gt;
The &lt;tt&gt;max&lt;/tt&gt; function helps to correct for an anomaly in some versions of Mozilla where coordinates can become negative.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18167227-114332443709058535?l=hackershowto.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18167227/posts/default/114332443709058535'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18167227/posts/default/114332443709058535'/><link rel='alternate' type='text/html' href='http://hackershowto.blogspot.com/2006/03/few-useful-javascript-utility.html' title='A few useful JavaScript utility functions'/><author><name>David Gillies</name><uri>http://www.blogger.com/profile/04351694829320255035</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-18167227.post-113064165573655359</id><published>2005-10-29T20:25:00.000-06:00</published><updated>2005-10-30T16:07:44.173-06:00</updated><title type='text'>Installing a DNS cache with DJBDNS</title><content type='html'>&lt;i&gt;This post assumes you are running some form of UNIX on your machine (Linux, Solaris, BSD, OS X, …). If you're not, you have my sympathy.&lt;/i&gt;

Any Internet-connected computer needs a DNS server. Typically your ISP will provide this. You quite likely don't even need to know how to communicate with the DNS server; if you are using DHCP to get your host configuration it will be set up automatically. However, it can sometimes be advantageous to do a bit of the work yourself. The most effective method of improving your DNS performance is to install a &lt;i&gt;cache&lt;/i&gt; on your local machine. A cache stores the results of DNS queries for a certain time period (IP addresses can change) and serves them back to the name-lookup software (called the &lt;i&gt;resolver&lt;/i&gt;) in milliseconds rather than seconds. This is very handy if you visit a certain set of websites frequently.

The main DNS server package on the net is BIND, the &lt;i&gt;&lt;a href="http://www.isc.org/index.pl?/sw/bind/index.php/"&gt;Berkeley Internet Name Domain&lt;/a&gt;&lt;/i&gt; (formerly BIN &lt;i&gt;Dæmon&lt;/i&gt;). It powers everything from small corporate intranets to the massive high-availability root servers that underpin the entire Internet's operations. But there's a couple of problems with BIND: 1) it's historically been vulnerable to an amazing variety of security attacks and 2) it's an absolute &lt;i&gt;pig&lt;/i&gt; to administer. O'Reilly Publishers have one of their celebrated 'animal' books devoted to &lt;a href="http://www.oreilly.com/catalog/dns4/"&gt;DNS and BIND&lt;/a&gt;; it's 622 pages.

Enter Daniel J. Bernstein, author of the excellent DJBDNS suite of programs. DJBDNS is markedly easier to configure than BIND, and for a long time much more secure. You can also configure it to be a lightweigfht DNS cache in minutes, just what we want. So here's how to go about it:

&lt;ol&gt;
&lt;li&gt;Obtain the &lt;tt&gt;daemontools&lt;/tt&gt; package. This is a set of utilities that make running a UNIX dæmon process much easier. DJBDNS requires it. It's available &lt;a href="http://cr.yp.to/daemontools/install.html"&gt;here&lt;/a&gt;. Current latest version is 0.76.&lt;/li&gt;
&lt;li&gt;Obtain the &lt;tt&gt;ucspi-tcp&lt;/tt&gt; package. This is a set of programs for building client/server TCP/IP applications. It is available &lt;a href="http://cr.yp.to/ucspi-tcp/install.html"&gt;here&lt;/a&gt;. Current latest version is 0.88.&lt;/li&gt;
&lt;li&gt;Obtain the &lt;tt&gt;djbdns&lt;/tt&gt; package. It is available &lt;a href="http://cr.yp.to/djbdns/install.html"&gt;here&lt;/a&gt;. Current latest version is 1.05.&lt;/li&gt;
&lt;li&gt;Build and install &lt;tt&gt;daemontools&lt;/tt&gt;.
&lt;ul&gt;
&lt;li&gt;Unpack the &lt;tt&gt;daemontools&lt;/tt&gt; tarball: &lt;tt&gt;tar -zxvf daemontools-0.76.tar.gz&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;cd admin/daemontools&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;If you are using Linux, &lt;tt&gt;cd src&lt;/tt&gt;. Find the file &lt;tt&gt;conf-cc&lt;/tt&gt;. Add the text &lt;tt&gt;-include /usr/include/errno.h&lt;/tt&gt; to the first line. This is very important as otherwise gcc under Linux will fail to build the package. &lt;tt&gt;cd ..&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;./package/install&lt;/tt&gt;. This will compile and install the daemontools package, and then start the &lt;tt&gt;svscan&lt;/tt&gt; process which monitors dæmon activity (if you're running BSD, just reboot). A line to start &lt;tt&gt;svscan&lt;/tt&gt; on boot will be added to some initialisation file, typically &lt;tt&gt;/etc/inittab&lt;/tt&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;

&lt;li&gt;Build and install &lt;tt&gt;ucspi-tcp&lt;/tt&gt;.
&lt;ul&gt;
&lt;li&gt;Unpack the &lt;tt&gt;ucspi-tcp&lt;/tt&gt; tarball: &lt;tt&gt;tar -zxvf ucspi-tcp-0.88.tar.gz&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;cd ucspi-tcp-0.88&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;If you are using Linux, edit the &lt;tt&gt;conf-cc&lt;/tt&gt; file and add the text &lt;tt&gt;-include /usr/include/errno.h&lt;/tt&gt; to the first line, just as for &lt;tt&gt;daemontools&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;Run &lt;tt&gt;make&lt;/tt&gt;, then &lt;tt&gt;make setup check&lt;/tt&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;

&lt;li&gt;Build and install &lt;tt&gt;djbdns&lt;/tt&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;Unpack the &lt;tt&gt;djbdns&lt;/tt&gt; tarball: &lt;tt&gt;tar -zxvf djbdns-10.5.tar.gz&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;cd djbdns-1.05&lt;/tt&gt;. If you are using Linux, edit the &lt;tt&gt;conf-cc&lt;/tt&gt; file and add the text &lt;tt&gt;-include /usr/include/errno.h&lt;/tt&gt; to the first line, just as for &lt;tt&gt;daemontools&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;Run &lt;tt&gt;make&lt;/tt&gt;, then &lt;tt&gt;make setup check&lt;/tt&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;li&gt;Check your DNS is OK: &lt;tt&gt;dnsq a www.google.com &lt;i&gt;&amp;lt;IP of a DNS server&amp;gt;&lt;/i&gt;&lt;/tt&gt;. You need to supply the IP address of an external DNS server. If you know the IP addresses of your ISP's nameservers, then use one of them. If not, then now is a good time to get onto Tech Support and get that info. You're going to need it later. If all is well, then you should see a bunch of lines like the following: &lt;tt&gt;authority: com 172800 NS h.gtld-servers.net&lt;/tt&gt; and &lt;tt&gt;additional: j.gtld-servers.net 172800 A 192.48.79.30&lt;/tt&gt;. If this request times out, then you have a problem getting on the Internet. It could be that a firewall is blocking requests on port 53 (DNS), but that's unlikely since I assume you've had connectivity before installing DJBDNS. If it is a firewall problem then you will need to allow outgoing connections to port 53 from ports 1024–65535 on your local machine.&lt;/li&gt;
&lt;li&gt;Create dummy users for the DNS cache and log functions: &lt;tt&gt;useradd gdnscache -s /bin/false&lt;/tt&gt; and &lt;tt&gt;useradd gdnslog -s /bin/false&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;Set up the &lt;tt&gt;dnscache&lt;/tt&gt; service: &lt;tt&gt;dnscache-conf gdnscache gdnslog /etc/dnscache&lt;/tt&gt;. This will create directories called &lt;tt&gt;root&lt;/tt&gt; and &lt;tt&gt;log&lt;/tt&gt; under the &lt;tt&gt;/etc/dnscache&lt;/tt&gt; directory. DJBDNS runs in a &lt;tt&gt;chroot&lt;/tt&gt; jail in &lt;tt&gt;/etc/dnscache/root&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;Link the DNS cache directory to &lt;tt&gt;/service&lt;/tt&gt;: &lt;tt&gt;ln -s /etc/dnscahce /service&lt;/tt&gt;. Wait five seconds. &lt;tt&gt;svscan&lt;/tt&gt; will pick up the new service and start it. To check it is running, type &lt;tt&gt;svstat /service/dnscache&lt;/tt&gt;. You should see a line indicating the service is running, along with its PID.&lt;/li&gt;
&lt;li&gt;Edit your &lt;tt&gt;/etc/resolv.conf&lt;/tt&gt; file. Include the single line &lt;tt&gt;nameserver 127.0.0.1&lt;/tt&gt;, and remove or comment out any others.&lt;/li&gt;
&lt;li&gt;Check you can resolve hosts: &lt;tt&gt;dnsip www.google.com&lt;/tt&gt;. You should get Google's IP addresses. Then try accessing a website.&lt;/li&gt;
&lt;li&gt;Open the file &lt;tt&gt;/etc/dnscache/root/servers/@&lt;/tt&gt;. You will see a bunch of IP addresses. These are root servers. At the top of this file, one per line, add the addresses of your ISP's name servers.&lt;/li&gt;
&lt;li&gt;Restart &lt;tt&gt;djbdns&lt;/tt&gt;: type &lt;tt&gt;svc -t /service/dnscache&lt;/tt&gt;&lt;/li&gt;
&lt;/ol&gt;
And that's it. You should notice an improvement in DNS response times.

&lt;b&gt;ADDENDUM:&lt;/b&gt; you can alter the size of the &lt;tt&gt;dnscache&lt;/tt&gt; in-memory file. The default size is one Megabyte, but if you've got plenty of RAM there's no harm in increasing it. I have 1G of RAM so I set the cache to be 10Mb. The files to control this are in &lt;tt&gt;/etc/dnscache/env&lt;/tt&gt;. To set the cache to be 10Mb, type the following: &lt;tt&gt;echo 10000000 &gt; CACHESIZE&lt;/tt&gt; and &lt;tt&gt;echo 10485760 &gt; DATALIMIT&lt;/tt&gt;. Then restart DNS: &lt;tt&gt;svc -t /service/dnscache&lt;/tt&gt;. If you now look at the &lt;tt&gt;dnscache&lt;/tt&gt; process (I use &lt;tt&gt;ps acvxwww | grep dnsca&lt;/tt&gt;) you will see that its Resident Set Size is a little over 10Mb.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18167227-113064165573655359?l=hackershowto.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18167227/posts/default/113064165573655359'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18167227/posts/default/113064165573655359'/><link rel='alternate' type='text/html' href='http://hackershowto.blogspot.com/2005/10/installing-dns-cache-with-djbdns.html' title='Installing a DNS cache with DJBDNS'/><author><name>David Gillies</name><uri>http://www.blogger.com/profile/04351694829320255035</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-18167227.post-113003247635042935</id><published>2005-10-22T19:29:00.001-06:00</published><updated>2005-10-23T17:29:26.206-06:00</updated><title type='text'>Using CFS</title><content type='html'>Matt Blaze's Cryptographic File System (CFS) is a simple way to encrypt a directory under Unix. Unlike the loopback encryption system, you don't have to choose the size of the encrypted filesystem beforehand—it will grow as you add files to it. Here's the steps you need to take:
&lt;ol&gt;
&lt;li&gt;Obtain the CFS sources or RPM distribution. I found an RPM called &lt;tt&gt;cfs-1.4.1-5.i386.rpm.&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;Build and install the CFS programs. These include &lt;tt&gt;cmkdir&lt;/tt&gt;, &lt;tt&gt;cattach&lt;/tt&gt; and others. How to do this is left to you. I just installed the RPM with &lt;tt&gt;rpm -ivh&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;If building from source, you must create a directory in root: &lt;tt&gt;mkdir /.cfsfs&lt;/tt&gt;. Add a line to &lt;tt&gt;/etc/exports&lt;/tt&gt;: &lt;tt&gt;/.cfsfs localhost()&lt;/tt&gt;. The RPM I used did this for me.&lt;/li&gt;
&lt;li&gt;Create another directory &lt;tt&gt;mkdir /securefs&lt;/tt&gt;. This will be the root of your crypto filesystem (although more on this later). You don't have to call it &lt;tt&gt;securefs&lt;/tt&gt; and it doesn't have to be in root. It's just a starting point&amp;mdash;you won't use it in the future.&lt;/li&gt;
&lt;li&gt;Add the following to &lt;tt&gt;/etc/rc.local&lt;/tt&gt; (or some other setup file that is called at boot time):&lt;pre&gt;
# start up CFS
if [ -x /usr/sbin/cfsd ]
then
 /usr/sbin/exportfs -a
 /usr/sbin/cfsd &amp;&amp;amp; mount -o port=3049,intr
     localhost:/.cfsfs /securefs
fi
&lt;/pre&gt;
Make sure the code that starts up &lt;tt&gt;cfsd&lt;/tt&gt; and mounts the secure directory is all on one line. This will start up CFS on boot and associate the CFS directory with the exported &lt;tt&gt;.cfsfs&lt;/tt&gt; NFS mount point. Now you can either reboot, or start CFS without rebooting. Just enter the commands in the &lt;tt&gt;then...fi&lt;/tt&gt; block above. On reboot, if all is well, you will see a new directory &lt;tt&gt;/crypt&lt;/tt&gt;. This is the CFS root.&lt;/li&gt;
&lt;li&gt;Make a secure directory, anywhere you like (your home directory, for example) with &lt;tt&gt;cmkdir &lt;i&gt;&amp;lt;directory name&amp;gt;&lt;/i&gt;&lt;/tt&gt;. You can call it anything you like, let's say &lt;tt&gt;cryptodir&lt;/tt&gt;. You will be asked for a password. This must be &lt;b&gt;long&lt;/b&gt;, 20 characters or more, so make sure you can remember it.&lt;/li&gt;
&lt;li&gt;Now you can 'attach' this directory to CFS. Use &lt;tt&gt;cattach &lt;i&gt;&amp;lt;directory name&amp;gt; &amp;lt;name&amp;gt;&lt;/i&gt;&lt;/tt&gt;. &lt;tt&gt;&lt;i&gt;&amp;lt;name&amp;gt;&lt;/i&gt;&lt;/tt&gt; can be anything you want; it will be the 'directory' that will appear in CFS. So, the command might look like &lt;tt&gt;cattach ~/cryptodir secrets&lt;/tt&gt;. You will then be prompted for your password again. Enter this, and a 'directory' will appear in the CFS root: &lt;tt&gt;/crypt/secrets&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;You can then use this new directory just like any other. Note the overhead of encryption will make it seem quite slow. If you get a gigabyte an hour throughput you're doing well (by default the cipher algorithm is two-key hybrid mode triple DES).&lt;/li&gt;
&lt;li&gt;When you no longer want your secure directory to be available, detach it from CFS: &lt;tt&gt;cdetach &lt;i&gt;&amp;lt;name&amp;gt;&lt;/i&gt;&lt;/tt&gt; e.g. &lt;tt&gt;cdetach secrets&lt;/tt&gt;.&lt;/li&gt;
&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18167227-113003247635042935?l=hackershowto.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18167227/posts/default/113003247635042935'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18167227/posts/default/113003247635042935'/><link rel='alternate' type='text/html' href='http://hackershowto.blogspot.com/2005/10/using-cfs.html' title='Using CFS'/><author><name>David Gillies</name><uri>http://www.blogger.com/profile/04351694829320255035</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-18167227.post-113000907906996854</id><published>2005-10-22T13:24:00.000-06:00</published><updated>2005-10-23T22:53:27.476-06:00</updated><title type='text'>L.A.M.P.</title><content type='html'>LAMP stands for Linux/Apache/MySQL/PHP, which are four things that together can create an enterprise strength e-commerce server. Here's a cookbook approach to setting up a Web and database server using LAMP.
&lt;ol&gt;
&lt;li&gt;Get the latest tarballs of all the components you will need. At the time of writing this list comprises:
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://httpd.apache.org/download.cgi" title="Apache HTTP server"&gt;Apache 1.3.34&lt;/a&gt;. Apache rules. It's on over 60% of the webservers out there. I use 1.3 rather than 2.0 because I'm more familiar with it.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.openssl.org/source/" source="" title=""&gt;OpenSSL&lt;/a&gt;. This is the core cryptographic and transport layer library that the mod_ssl extension uses. At the time of writing, the latest version was 0.9.8a&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.blogger.com/post-create.g?blogID=18167227"&gt;mod_ssl&lt;/a&gt;. This is the extension that Apache uses to provide secure (SSL/TLS) connections with the HTTPS protocol. At the time of writing, the latest version was 2.8.25-1.3.34. Make sure the second version string matches your Apache release version (here, 1.3.34).&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.ossp.org/pkg/lib/mm/" title="The mm shared memory library"&gt;mm&lt;/a&gt;. This is a shared memory library, written by the same genius who created OpenSSL and mod_ssl, the very cool Ralf Engelschall. It allows Apache/mod_ssl to maintain a RAM-based bank of SSL session IDs which makes connection handling a lot faster than when using the disk-based version. As of the time of writing, the latest version was 1.4.0.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.php.net/downloads.php" title="The PHP Hypertext Preprocessor"&gt;PHP&lt;/a&gt;. This is the scripting engine that puts programmatic capability in your back-end. I love PHP.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dev.mysql.com/downloads/mysql/4.1.html" title="The MySQL database server"&gt;MySQL&lt;/a&gt;. This is the SQL database server engine that complements PHP to drive your website. If you are using a relatively recent Linux distro, then get the glibc2.3 dynamic &lt;b&gt;Max&lt;/b&gt; version. As of the time of writing, the latest version was 4.1.15. 4.1.x versions are recommended since they have support for subqueries. v5.0 releases were in beta as of this time so I have not tried them (I spend too much time debugging my own software to help debug MySQL).&lt;/li&gt;
&lt;li&gt;Sundry other libraries needed to support PHP extensions. I use Cracklib, Mcrypt and Mhash, among others. Usually all you need to do is grab the tarball, unpack it and do a configure/make/make install/ldconfig.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Unpack all the tarballs&lt;/li&gt;
&lt;li&gt;Build OpenSSL
&lt;ul&gt;
&lt;li&gt;&lt;tt&gt;cd&lt;/tt&gt; to the OpenSSL directory e.g. &lt;tt&gt;openssl-0.9.8a&lt;/tt&gt;. Configure the makefile: &lt;tt&gt;./config no-threads -fPIC&lt;/tt&gt;. The &lt;tt&gt;no-threads&lt;/tt&gt; prevents a threaded version of the library being built; since Apache 1.3 does not use threads this is slightly more efficient. The &lt;tt&gt;-fPIC&lt;/tt&gt; option tells the compiler to build position-independent code, which you will need in order to build mod_ssl as a dynamically-loadable module.&lt;/li&gt;
&lt;li&gt;Run &lt;tt&gt;make&lt;/tt&gt;/&lt;tt&gt;make test&lt;/tt&gt;. If all is well, proceed to the next step.
&lt;/li&gt;&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Build mm
&lt;ul&gt;
&lt;li&gt;&lt;tt&gt;cd&lt;/tt&gt; to the mm directory e.g. &lt;tt&gt;mm-1.4.0&lt;/tt&gt;. Configure the makefile: &lt;tt&gt; ./configure --disable-shared&lt;/tt&gt;. The &lt;tt&gt;--disable-shared&lt;/tt&gt; makes the compiler generate a static binary. This is important otherwise unless you explicitly set the location of the mm library in your &lt;tt&gt;LD_LIBRARY_PATH&lt;/tt&gt;, Apache will not be able to find it.&lt;/li&gt;
&lt;li&gt;Run &lt;tt&gt;make&lt;/tt&gt;. If all is well, proceed to the next step.
&lt;/li&gt;&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Configure mod_ssl
&lt;ul&gt;
&lt;li&gt;&lt;tt&gt;cd&lt;/tt&gt; to the mod_ssl directory e.g. &lt;tt&gt;mod_ssl-2.8.25-1.3.34&lt;/tt&gt;. Configure the makefile: &lt;tt&gt;./configure --with-apache=../apache_1.3.x --with-ssl=../openssl-0.9.x --with-mm=../mm-1.4.x&lt;/tt&gt;, replacing the &lt;tt&gt;x&lt;/tt&gt;'s above with the correct version numbers.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;&lt;li&gt;Build Apache
&lt;ul&gt;
&lt;li&gt;&lt;tt&gt;cd ../apache_1.3.x&lt;/tt&gt;. Configure the makefile: &lt;tt&gt;./configure --enable-shared=max --enable-module=ssl --enable-module=... --enable-module=...&lt;/tt&gt;. This makes all modules shared objects (DSO's) and enables the mod_ssl module. You should include any other modules you wish to support here as well with &lt;tt&gt;--enable-module=&lt;/tt&gt;, for example mod_rewrite, mod_unique_id or mod_expires (which would look like &lt;tt&gt;--enable-module=rewrite&lt;/tt&gt;, &lt;tt&gt;--enable-module=unique_id&lt;/tt&gt; and &lt;tt&gt;--enable-module=expires&lt;/tt&gt; respectively&amp;mdash;you get the picture).&lt;/li&gt;
&lt;li&gt;Run &lt;tt&gt;make&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;Run &lt;tt&gt;make certificate&lt;/tt&gt;. This will create a dummy self-signed SSL certificate. If you are using this server in a production environment, you will want to replace this certificate with a real one. Note the 'common name' field in the certificate generation process should be the hostname of your computer. Set the expiration date to some large value like 10000.&lt;/li&gt;
&lt;li&gt;Run &lt;tt&gt;make install&lt;/tt&gt;. This will copy all the necessary files to the installation directory, usually &lt;tt&gt;/usr/local/apache&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;Start the server: &lt;tt&gt;/usr/local/apache/bin/apachectl startssl&lt;/tt&gt;. If all goes well, you should be able to connect to your server from a browser with &lt;tt&gt;http://localhost/&lt;/tt&gt;. Then check the HTTPS connection: &lt;tt&gt;https://localhost&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;Shut down Apache: &lt;tt&gt;/usr/local/apache/bin/apachectl stop&lt;/tt&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Build PHP
&lt;ul&gt;
&lt;li&gt;&lt;tt&gt;cd&lt;/tt&gt; to the PHP directory e.g. &lt;tt&gt;php-4.4.0&lt;/tt&gt;. Configure the makefile: &lt;tt&gt;./configure --with-mysql --with-apxs=/usr/local/apache/bin/apxs --enable-sockets --enable-... --with-...&lt;/tt&gt;. This will build PHP as an Apache DSO. The &lt;tt&gt;--enable-sockets&lt;/tt&gt; call is important for several functions that can treat URLs like files. Any additional PHP extensions you want should be configured with &lt;tt&gt;--enable-...&lt;/tt&gt; or &lt;tt&gt;with-...&lt;/tt&gt; e.g. &lt;tt&gt;--enable-calendar&lt;/tt&gt; or &lt;tt&gt;--with-mcrypt&lt;/tt&gt;. Consult the PHP documentation to find out which you need to use.&lt;/li&gt;
&lt;li&gt;Run &lt;tt&gt;make&lt;/tt&gt;/&lt;tt&gt;make install&lt;/tt&gt;. This will build PHP and copy the files to their correct locations. In particular, the PHP DSO will be in &lt;tt&gt;/usr/local/apache/libexec/libphp4.so&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;Tell Apache to load the PHP dynamic module. Find the Apache configuration file in &lt;tt&gt;/usr/local/apache/conf/httpd.conf&lt;/tt&gt;. Look for a block of lines of the form &lt;tt&gt;LoadModule module_name module_path&lt;/tt&gt;. There should be a block &lt;tt&gt;&amp;lt;IfDefine SSL&amp;gt;&lt;/tt&gt;/&lt;tt&gt;&amp;lt;/IfDefine&amp;gt;&lt;/tt&gt; with the contents &lt;tt&gt;LoadModule ssl_module libexec/libssl.so&lt;/tt&gt;. Immediately after the &lt;tt&gt;&amp;lt;/IfDefine&amp;gt;&lt;/tt&gt; add the line &lt;tt&gt;LoadModule php4_module libexec/libphp4.so&lt;/tt&gt; if it is not already there. Now look for a block of lines of the form &lt;tt&gt;AddModule module.c&lt;/tt&gt;. Again there will be an entry for mod_ssl within an &lt;tt&gt;&amp;lt;IfDefine&amp;gt;&lt;/tt&gt; block. Immediately after this block, add the line &lt;tt&gt;AddModule mod_php4.c&lt;/tt&gt; if it is not already there.&lt;/li&gt;
&lt;li&gt;Enable PHP in Apache. Look for the line &lt;tt&gt;&amp;lt;IfModule mod_mime.c&amp;gt;&lt;/tt&gt;. In this section, add the lines &lt;tt&gt;AddType application/x-httpd-php .php .phtml&lt;/tt&gt; and &lt;tt&gt;AddType application/x-httpd-php-source .phps&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;Restart Apache: &lt;tt&gt;/usr/local/apache/bin/apachectl startssl&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;Create a test PHP program. The easiest is to &lt;tt&gt;cd /usr/local/apache/htdocs&lt;/tt&gt; and create a file called &lt;tt&gt;test.php&lt;/tt&gt;:
&lt;blockquote&gt;
&lt;pre&gt;
&amp;lt;?php
phpinfo();
?&amp;gt;
&lt;/pre&gt;
&lt;/blockquote&gt;
Then open your broswer and enter the URL &lt;tt&gt;http://localhost/test.php&lt;/tt&gt;. You should see a screenful of information about the PHP installation.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Install MySQL
&lt;ul&gt;
&lt;li&gt;Execute the following commands:
&lt;blockquote&gt;
&lt;pre&gt;
groupadd mysql
useradd -g mysql mysql
&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;Move the MySQL tarball to &lt;tt&gt;/usr/local&lt;/tt&gt; and unpack it e.g. &lt;tt&gt;tar -zxvf mysql-max-4.1.15-pc-linux-gnu-i686-glibc23.tar.gz&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;Create a symbolic link to the mysql directory e.g. &lt;tt&gt;ln -s mysql-max-4.1.15-pc-linux-gnu-i686-glibc23 mysql&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;cd mysql&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;Execute the following commands:
&lt;blockquote&gt;
&lt;pre&gt;
chown -R root
chown -R mysql data
chgrp -R mysql
&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;Become the mysql user: &lt;tt&gt;su mysql&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;Setup the default databases: &lt;tt&gt;scripts/mysql_install_db&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;Start the server: &lt;tt&gt;bin/mysqld_safe &amp;amp;&lt;/tt&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
And that's it! Later on I'll show how to configure the MySQL table space for InnoDB tables, which are full ACID-compliant tables with transactional capability.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18167227-113000907906996854?l=hackershowto.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18167227/posts/default/113000907906996854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18167227/posts/default/113000907906996854'/><link rel='alternate' type='text/html' href='http://hackershowto.blogspot.com/2005/10/lamp.html' title='L.A.M.P.'/><author><name>David Gillies</name><uri>http://www.blogger.com/profile/04351694829320255035</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-18167227.post-112999883529420035</id><published>2005-10-22T10:28:00.000-06:00</published><updated>2005-10-22T10:39:20.146-06:00</updated><title type='text'>HOWTO</title><content type='html'>What's the purpose of this blog? It's to act as a compendium of all the neat little tricks and tips I garner in my day-to-day life as a software engineer and Linux sysadmin&amp;mdash;the sort of silly things that can hold you up for hours while Googling for an answer. Maybe some of these will be common knowledge. All I know is that they will have been problems I have encountered. I might also throw up a few random mathematical musings (recreational mathematics is one of my hobbies, although I'm not very good at it). Where appropriate I'll be providing code listings, too. I don't know how often I'll be posting&amp;mdash;probably as and when I encounter a new handy hint. I normally blog over at the Libertarian/Conservative &lt;a href="http://www.dailypundit.com" title="Daily Pundit blog"&gt;Daily Pundit&lt;/a&gt;, whose creator, William T. Quick, was the guy who coined the term 'blogosphere'.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18167227-112999883529420035?l=hackershowto.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18167227/posts/default/112999883529420035'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18167227/posts/default/112999883529420035'/><link rel='alternate' type='text/html' href='http://hackershowto.blogspot.com/2005/10/howto.html' title='HOWTO'/><author><name>David Gillies</name><uri>http://www.blogger.com/profile/04351694829320255035</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry></feed>
