<?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>Random Tech Articles</title>
	<atom:link href="http://www.analogrithems.com/rant/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.analogrithems.com/rant</link>
	<description>If I have seen a little further it is by standing on the shoulders of Giants. - Newton</description>
	<lastBuildDate>Mon, 08 Mar 2010 08:38:16 +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>Protected: Accessing The Media.Analogrithems.Com</title>
		<link>http://www.analogrithems.com/rant/2010/03/07/accessing-the-media-analogrithems-com/</link>
		<comments>http://www.analogrithems.com/rant/2010/03/07/accessing-the-media-analogrithems-com/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 21:06:57 +0000</pubDate>
		<dc:creator>analogrithems</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.analogrithems.com/rant/?p=146</guid>
		<description><![CDATA[There is no excerpt because this is a protected post.]]></description>
			<content:encoded><![CDATA[<form action="http://www.analogrithems.com/rant/wp-pass.php" method="post">
<p>This post is password protected. To view it please enter your password below:</p>
<p><label for="pwbox-146">Password:<br />
<input name="post_password" id="pwbox-146" type="password" size="20" /></label><br />
<input type="submit" name="Submit" value="Submit" /></p></form>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.analogrithems.com/rant/2010/03/07/accessing-the-media-analogrithems-com/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.analogrithems.com/rant/2010/03/07/accessing-the-media-analogrithems-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Snort + Mysql on RHEL 5.4</title>
		<link>http://www.analogrithems.com/rant/2010/01/14/132/</link>
		<comments>http://www.analogrithems.com/rant/2010/01/14/132/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 00:29:08 +0000</pubDate>
		<dc:creator>analogrithems</dc:creator>
				<category><![CDATA[IDS]]></category>
		<category><![CDATA[Snort]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Redhat EL5]]></category>

		<guid isPermaLink="false">http://www.analogrithems.com/rant/?p=132</guid>
		<description><![CDATA[This document describes the steps for install and setting up Snort the opensource intrustion detection system. It also describes the process for updating the signature definitions.
Snort is an opensource IDS (Intrusion Detection System)  written and maintained by a company called sourcefire.  It is one of the best IDS available and is free (Kinda).
Downloading [...]]]></description>
			<content:encoded><![CDATA[<p>This document describes the steps for install and setting up Snort the opensource intrustion detection system. It also describes the process for updating the signature definitions.</p>
<p><a title="http://www.snort.org/" rel="nofollow" href="http://www.snort.org/">Snort</a> is an opensource IDS (Intrusion Detection System)  written and maintained by a company called <a title="http://www.sourcefire.com/" rel="nofollow" href="http://www.sourcefire.com/">sourcefire</a>.  It is one of the best IDS available and is free (Kinda).</p>
<h3>Downloading Snort</h3>
<p>Since we us Redhat Enterprise Linux 5 here go to the snort <a title="http://www.snort.org/downloads/" rel="nofollow" href="http://www.snort.org/downloads/">download</a> page and select <strong>snort-2.8.5.2-1.RH5.i386.rpm</strong>.  Since we will also be using the BASE web interface to view the alerts also download the <strong>snort-mysql-2.8.5.2-1.RH5.i386.rpm</strong> add-on that allows snort to log its alerts to a MySQL database.</p>
<h3>Installing Snort</h3>
<p>Installing Snort via the rpms is very easy.  Just use the rpm command like the following.</p>
<pre>[root@mytest src]# rpm -Uvh snort-2.8.5.2-1.RH5.i386.rpm snort-mysql-2.8.5.2-1.RH5.i386.rpm
Preparing...                ########################################### [100%]
  1:snort                    ########################################### [ 50%]
  2:snort-mysql          ########################################### [100%]
</pre>
<p>That&#8217;s it, Snort is installed and the rpm install script already configures Snort to start at boot.</p>
<pre>[root@mytest src]# chkconfig --list |grep snort
snortd          0:off   1:off   2:on    3:on    4:on    5:on    6:off
</pre>
<h3>Configuring Snort</h3>
<p>Here is where the real magic happens. He now need to configure Snort for use. Typicaly your server will have two NICs. One will be for remote administration and one will be dedicated to Snort. In our case I will use eth0 for remote administration and logging into the computer and I&#8217;ll use eth1 for Snort. We want to dedicate the whole interface to snort because we will be placing it in promiscus mode which will cause the network interface to take sniff all the traffic coming across its segment.</p>
<h4>Configure Dedicated Network Interface</h4>
<p>You don&#8217;t actually need to use a real IP for the Snort interface so when you configure the if-cfg file just leave out the actual IP info In redhat the network config files are located under <strong>/ettc/sysconfig/network-scripts/</strong> so I&#8217;ll place the following in <strong>/etc/sysconfig/network-scripts/ifcfg-eth1</strong></p>
<pre>DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
TYPE=Ethernet
</pre>
<p>Then recycle the network service with the <strong>service network restart</strong> command.</p>
<pre>[root@mytest network-scripts]# service network restart
Shutting down interface eth0:                              [  OK  ]
Shutting down interface eth1:                              [  OK  ]
Shutting down loopback interface:                        [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:                                  [  OK  ]
Bringing up interface eth1:                                 [  OK  ]
</pre>
<p>This will then turn on your network interface. You can verify that the interface is up and on with the ifconfig command.</p>
<pre>[root@mytest network-scripts]# ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:C0:F2:01:16:73
         UP BROADCAST MULTICAST  MTU:1500  Metric:1
         RX packets:0 errors:0 dropped:0 overruns:0 frame:0
         TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
         Interrupt:193 Base address:0xdde0
</pre>
<h4>Snort Sysconfig file</h4>
<p>So now that we have our network up it&#8217;s time to configure Snort to use the new network interface we just created. You can tell snorrt to either usee a certain NIC or ALL. In our case we only want it to use eth1 so edit <strong>/etc/sysconfig/snort</strong> find the line that has <strong>INTERFACE=eth0</strong> and change it to <strong>INTERFACE=eth1</strong></p>
<pre># What interface should snort listen on?  [Pick only 1 of the next 3!]
# This is -i {interface} on the command line
# This is the snort.conf config interface: {interface} directive
INTERFACE=eth1
</pre>
<p>Next since we will be logging to MySQL we need to shut off the standard flat file out by commenting out the <strong>ALERTMODE</strong> option. This step is actually really important. Without it no matter what you tell the snort config file, it will not send any logs to the MySQL database.</p>
<pre># How should Snort alert? Valid alert modes include fast, full, none, and
# unsock.  Fast writes alerts to the default "alert" file in a single-line,
# syslog style alert message.  Full writes the alert to the "alert" file
# with the full decoded header as well as the alert message.  None turns off
# alerting. Unsock is an experimental mode that sends the alert information
# out over a UNIX socket to another process that attaches to that socket.
# -A {alert-mode}
# output alert_{type}: {options}
#ALERTMODE=fast
</pre>
<h4>Create and Configure the Database</h4>
<p>We now need to create and configure our mysql database and tables where Snort&#8217;s events will be logged. The snort rpm you installed earlier placed a MySQL database scheme at <strong>/usr/share/snort-2.8.5.2/schemas/create_mysql</strong> Sso first we will need to manually create the MySQL database.</p>
<pre>[root@mytest ~]# mysql
mysql&gt; create database snort;
Query OK, 1 row affected (0.09 sec)
mysql&gt; exit
Bye
</pre>
<p>Next we will import the database scheme to the snorrt database we just created with the following command.</p>
<pre>[root@mytest ~]# mysql snort &lt; /usr/share/snort-2.8.5.2/schemas/create_mysql
</pre>
<p>Last we need to create a snort user in mysql with full access to the database and tables we just created. In the following example replace secret password with an actual password.</p>
<pre>[root@mytest ~]# mysql snort
mysql&gt; grant all on snort.* to 'snort'@'%' identified by 'secret password';
Query OK, 0 rows affected (0.04 sec)
mysql&gt; exit
Bye
</pre>
<h4>Snort Configuration File</h4>
<p>The actual Snort config file is located in <strong>/etc/snort</strong> and is called <strong>snort.conf&#8217;</strong> Really the only things we should edit in this file are the VAR options that are specific to our network and the log line that defines our snort connection.</p>
<pre>#This should reflect all the subnets we have on our network.
var HOME_NET [10.0.0.0/24,10.0.10.0/24,10.0.23.0/24]
var EXTERNAL_NET any
# Configure your server lists.  This allows snort to only look for attacks to
# systems that have a service up.  Why look for HTTP attacks if you are not
# running a web server?  This allows quick filtering based on IP addresses
# These configurations MUST follow the same configuration scheme as defined
# above for $HOME_NET.
var DNS_SERVERS [10.0.0.42,10.0.23.42]
var SMTP_SERVERS $HOME_NET
#Any computer that was a webserver running should be in this list
var HTTP_SERVERS [10.0.0.23,10.0.23.42]
#Any Machine that is running any type of SQL server should be listed here
var SQL_SERVERS [10.0.0.60,10.0.0.61]
var TELNET_SERVERS $HOME_NET
var FTP_SERVERS $HOME_NET
var SNMP_SERVERS $HOME_NET
#Now we should define our database config
output database: log, mysql, user=snort password=secretpassword dbname=snort host=localhost
</pre>
<p>That&#8217;s it after that you can start snort with a simple <strong>service snortd start</strong></p>
<h3>Configuring Switches for Snort</h3>
<p>In the old days of hubs every packet was always sent out every port. This was inefficient and a huge security risk. So Switches came along to make sure only the port that needed the data got the packet. It did this my keeping an internal list of which mac was on which port. Then it only sends out packets destine for the mac associated with each port. This is much more efficient and secure but for snort this actually causes a problem. In order to see every packet to inspect it, it needs the switch to treat it&#8217;s port like a hub. Luckily in managed Cisco switches you have the ability to mirror ports or vlans to another port or vlan.</p>
<p>On our vlan we will assume that we have two vlans. In reality we probably have many more but for our example it doesn&#8217;t matter we will also assume that our dedicated network interface is plugged in to port GigabitEtherrnet0/5.</p>
<pre>Switch&gt; conf t
Switch&gt; monitor session 1 source vlan 1 - 2 rx
Switch&gt; monitor session 1 destination interface gigabitEthernet0/5
</pre>
<p>This will tell your switch to take all traffic on vlan 1 &amp; 2 and mirror them to gigabitEthernet port 0/5</p>
<p>after that write and save your config. Now snort should be getting all the traffic from your vlans. As stated above if you have multiple Vlans then add more monitor session 1 source statements. You can combine all sorts of interfaces and vlans.</p>
<h3>Updating Scanning Signatures</h3>
<p>Unfortunately updating snort rules requires an account on the snort.org website. Their are free and paid subscriptions based accounts. The free account gets new signatures 30 days after the paid account. For our purposes we will be using the free version for now. So create your free account via the <a title="https://www.snort.org/signup" rel="nofollow" href="https://www.snort.org/signup">Signup Page</a> and after you do the whole email confirm thing login to the website at the <a title="https://www.snort.org/login" rel="nofollow" href="https://www.snort.org/login">Login Page</a> When you login Click on the <strong>Get Rules</strong> button this will take you to a download page and show you two sections one for VRT Subscription users and one for Registered users (Free 30days late). Select the <strong>snortrules-snapshot-CURRENT.tar.gz</strong> from the registered users section, this file is usually about 25-30MB so be patient. Once you download this tar archive to your snort machine create a tmp dir and unarchive all the files with the tar command again.</p>
<pre>[root@mytest src]# mkdir snort-rules-temp
[root@mytest src]# cd snort-rules-temp
[root@mytest snort-rules-temp]# tar -zxf ../snortrules-snapshot-CURRENT.tar.gz
</pre>
<p>Once you uncompressed the rules you need to copy only the normal rules. Copy the normal rules to the <strong>/etc/snort/rules</strong> directory.</p>
<pre>[root@mytest snort-rules-temp]# cp rules/* /etc/snort/rules/
</pre>
<p>Test the so rules with</p>
<pre>[root@mytest src]# snort -c /etc/snort/snort.conf -T
</pre>
<p>If everything looks good recycle snort with <strong>service snortd restart</strong> For best results you should update your snort rules every week.</p>
<h2>References</h2>
<ul>
<li> <a title="https://forums.snort.org/forums" rel="nofollow" href="https://forums.snort.org/forums">https://forums.snort.org/forums</a></li>
<li> <a title="http://snort.org/" rel="nofollow" href="http://snort.org/">http://snort.org/</a></li>
</ul>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.analogrithems.com/rant/2010/01/14/132/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.analogrithems.com/rant/2010/01/14/132/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The shuttle working on the hubble telescope</title>
		<link>http://www.analogrithems.com/rant/2009/12/23/the-shuttle-working-on-the-hubble-telescope/</link>
		<comments>http://www.analogrithems.com/rant/2009/12/23/the-shuttle-working-on-the-hubble-telescope/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 13:01:46 +0000</pubDate>
		<dc:creator>analogrithems</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.analogrithems.com/rant/?p=116</guid>
		<description><![CDATA[Here are a few small videos of the shuttle and the hubble from May of 2009 when the shuttle was doing repairs on the Hubble.   These are unclassified for public release.
STS125_2009142_VIS_RL
STS125_2009142_GEM
20580_200137_AO_RLBD
20580_2008137_AO_PCID
STS125_2009142_SSTB_Resize
20580_2008137_AO_MFBD_RL
STS125_2009142_SSTB
20580_2008137_RLBD_Knox
Share on Facebook]]></description>
			<content:encoded><![CDATA[<p>Here are a few small videos of the shuttle and the hubble from May of 2009 when the shuttle was doing repairs on the Hubble.   These are unclassified for public release.</p>
<p><a href="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/STS125_2009142_VIS_RL.mp4">STS125_2009142_VIS_RL</a></p>
<p><a href="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/STS125_2009142_GEM.mp4">STS125_2009142_GEM</a><a href="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/20580_200137_AO_RLBD.mp4"></a></p>
<p><a href="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/20580_200137_AO_RLBD.mp4">20580_200137_AO_RLBD</a><a href="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/20580_2008137_AO_PCID.mp4"></a></p>
<p><a href="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/20580_2008137_AO_PCID.mp4">20580_2008137_AO_PCID</a><a href="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/20580_2008137_AO_MFBD_RL.mp4"></a></p>
<p><a href="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/20580_2008137_AO_MFBD_RL.mp4"></a><a href="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/STS125_2009142_SSTB_Resize.mp4">STS125_2009142_SSTB_Resize</a></p>
<p><a href="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/20580_2008137_AO_MFBD_RL.mp4">20580_2008137_AO_MFBD_RL</a></p>
<p><a href="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/STS125_2009142_SSTB.mp4">STS125_2009142_SSTB</a></p>
<p><a href="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/20580_2008137_RLBD_Knox.mp4">20580_2008137_RLBD_Knox</a></p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.analogrithems.com/rant/2009/12/23/the-shuttle-working-on-the-hubble-telescope/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.analogrithems.com/rant/2009/12/23/the-shuttle-working-on-the-hubble-telescope/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/STS125_2009142_VIS_RL.mp4" length="927812" type="video/mp4" />
<enclosure url="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/STS125_2009142_GEM.mp4" length="127971" type="video/mp4" />
<enclosure url="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/20580_200137_AO_RLBD.mp4" length="263583" type="video/mp4" />
<enclosure url="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/20580_2008137_AO_PCID.mp4" length="120145" type="video/mp4" />
<enclosure url="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/20580_2008137_AO_MFBD_RL.mp4" length="1700162" type="video/mp4" />
<enclosure url="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/STS125_2009142_SSTB_Resize.mp4" length="91237" type="video/mp4" />
<enclosure url="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/STS125_2009142_SSTB.mp4" length="194381" type="video/mp4" />
<enclosure url="http://www.analogrithems.com/rant/wp-content/uploads/2009/12/20580_2008137_RLBD_Knox.mp4" length="104036" type="video/mp4" />
		</item>
		<item>
		<title>ipsec over ipsec</title>
		<link>http://www.analogrithems.com/rant/2009/12/23/ipsec-over-ipsec/</link>
		<comments>http://www.analogrithems.com/rant/2009/12/23/ipsec-over-ipsec/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 11:41:34 +0000</pubDate>
		<dc:creator>analogrithems</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.analogrithems.com/rant/?p=99</guid>
		<description><![CDATA[So it turns out that you can&#8217;t pass one vpn using ipsec through another vpn using ipsec.  Why, well i&#8217;ve spent some time trying to figure this out the last few days and have discovered that they are taking each others packets apart.
VPN that use ipsec for a site to site connection encapsulate packets into [...]]]></description>
			<content:encoded><![CDATA[<p>So it turns out that you can&#8217;t pass one vpn using ipsec through another vpn using ipsec.  Why, well i&#8217;ve spent some time trying to figure this out the last few days and have discovered that they are taking each others packets apart.</p>
<p>VPN that use ipsec for a site to site connection encapsulate packets into udp packets.  These udp packets are then sent across the network to the other side where the receiving device unpacks the udp packet and then decrypts it.  Typically the carrier media that connects your two vpn devices is the internet.  But if your media connecting your two devices is a network that also uses a VPN you run into a major problem.  The carrier network will start to unpack your packets meant for the other side and start throwing icmp type 3 (Host Unreachable) errors back to the vpn device.</p>
<p>Now if you are using cisco routers for the carrier network fiber you can actually tell it that traffic from your vpn devices should be excluded from the vpn tunnel and instead be sent in clear.  This way those packets to the other side of the vpn and never get double encrypted, fragmented or any other bad ness.  A great article explaining crypto acls for Cisco routers is http://www.thebryantadvantage.com/CCNPCertificationBCRANExamVPNCryptoAccessLists.htm</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.analogrithems.com/rant/2009/12/23/ipsec-over-ipsec/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.analogrithems.com/rant/2009/12/23/ipsec-over-ipsec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CAC cards and Mac OSX</title>
		<link>http://www.analogrithems.com/rant/2009/09/04/cac-cards-and-mac-osx/</link>
		<comments>http://www.analogrithems.com/rant/2009/09/04/cac-cards-and-mac-osx/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 00:50:54 +0000</pubDate>
		<dc:creator>analogrithems</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.analogrithems.com/rant/?p=97</guid>
		<description><![CDATA[I love using Mac, as a so called IT professional it&#8217;s the most professional improvement to come UNIX in over a decade.  I especially like to use it for work,  The problem isall of the systems they use at my company rely on CAC authentication.  More specificaly it&#8217;s all been geared towards Windows &#38; CAC.  [...]]]></description>
			<content:encoded><![CDATA[<p>I love using Mac, as a so called IT professional it&#8217;s the most professional improvement to come UNIX in over a decade.  I especially like to use it for work,  The problem isall of the systems they use at my company rely on CAC authentication.  More specificaly it&#8217;s all been geared towards Windows &amp; CAC.  Don&#8217;t get me wrong Common Access Cards are a great way to handle security.  They work off of industry standard concepts like X.509 Certificates and Public Key Encryption.  I don&#8217;t have a problem with that.  It&#8217;s the horseshit support I find for documentation on how to use cac with my Mac.</p>
<p>This is a list of links and tips I discovered to make it easier to do.  By default it shouldn&#8217;t be that card in OS X 10.5.6 or higher to get your CAC to work.  In factApple already has support for CAC readers built into the OS.  I have found though that often times you need to flash your CAC reader with the most current firmware version to make it work right.  The worst part about this is that you have to use a windows XP computer to do this.  I found the firmware for my cCAC reader and the flash tool at this site http://www.txsystems.com/cac.html  Once I installed it on a Windows XP machine and flashed it to the most current version I got my cac to start seeing it.</p>
<p>To test if your mac can see you CAC reader plug it into your computer and place you CAC in the reader. Then open terminal and type &#8217;sudo pcsctool&#8217;.  After you input your admin password if will tell you sucess or failure.  THis is the immeditae indicator of weather or not your computer can use your CAC reader.</p>
<p>Once you know your computer will see it you can start configuring certain programs to use it/.  So far I&#8217;ve gotten Safari and Firefox working with the CAC reader.  The best instructions you can find for getting Safari to use your CAC is from http://militarycac.com/apple.htm  I&#8217;ve included it here for archive puproses.</p>
<p>Step 1: Update your system.  (10.5.6 is the minimum required for Leopard, though 10.5.8 is currently available and recommended)</p>
<p>Step 2: Plug in your CAC Reader to the USB Port</p>
<p>Step 3: Click the Apple Icon in the upper left corner of your desktop and select &#8220;About This Mac&#8221;</p>
<p>Step 4: Click the &#8220;More Info&#8221; Button within the window that pops up. (This open System Profiler)</p>
<p>Step 5: Within the &#8220;Hardware&#8221; Category select the &#8220;USB&#8221; Section.  On the right hand side of the screen the window will display all hardware plugged into the USB ports on your Mac.  Within this should be a Smart Card Reader.  If the Smart Card reader is present here it is installed on your system, and no further hardware changes are required, i.e. additional drivers / Firmware upgrades.  Unplug the CAC Reader from your system.</p>
<p>Step 6: Open Keychains Access from the Utilities Folder within the Applications folder; Open the &#8220;Edit&#8221; Menu, and select &#8220;Keychain List&#8221;, click the &#8220;+&#8221; button in the lower left of the window opened, navigate to the location: System / Library / Keychains (Select the local hard drive i.e “Macintosh HD” on the left, followed by the System folder, within that the Library folder, and within that the Keychains folder), and select X509Anchors.  Check the Box to the left of the name under &#8220;Shared&#8221; as well as the System Box.  Click &#8220;Ok&#8221;.</p>
<p>Step 7: Plug in your CAC Reader and insert your CAC into the CAC Reader.  If in the upper left of the Keychain Access window, under &#8220;Keychains&#8221; your CAC should show up (CAC XXXX-XXXX-XXXX-XXXX-XXXX), select it. In the right hand side you will see the certificates that are on your CAC. (If your CAC does not appear remove it from the reader, unplug the CAC Reader, close and re-open keychains, plug in the Card Reader, and insert your CAC)</p>
<p>Step 8: Click the &#8220;Padlock&#8221; icon in the upper left corner of the program window, which will prompt you for your CAC PIN.  Enter your PIN to unlock your CAC.</p>
<p>Step 9: Select the desired certificate, which will show DOD CA-XX or DOD EMAIL CA-XX in the upper window.  Right Click (Control Click) and select &#8220;New Identity Preference&#8221;</p>
<p>Step 10: Enter the URL for the appropriate website you wish to access, select the appropriate certificate and click “Add”:</p>
<p>Step 11: Close Keychains, remove your CAC, and re-insert it.  Open Safari and begin navigating to your CAC enabled site.  (Air Force Users: remove your CAC card and re-insert it prior to opening Safari.)</p>
<p>If you want to use your CAC with firefox it&#8217;s a little more complicated.  This is because the plugin that used to be hosted on the mozilla addons page is nolonger active.  Now the project is hosted under the Department of Defensess forge.mil site.  This site requires a department of defense CAC to get in and download it.  It also has great documentation on how to setup firefox.  It&#8217;s all focused on the DOD Certs though.</p>
<p>If you are looking to get your mac to play nicely in a AD envronment then you should look at <a href="http://www.centrify.com/blogs/tomkemp/integrating_common_access_cards_with_apple_macintosh.asp" target="_blank">centrify</a>&#8217;s solution.  I have to be honest, I haven&#8217;t tried it but I have read a lot about it and it appears to be the perfect way to authenitcate to an active directory domain via CAC.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.analogrithems.com/rant/2009/09/04/cac-cards-and-mac-osx/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.analogrithems.com/rant/2009/09/04/cac-cards-and-mac-osx/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unix Drive Cloning</title>
		<link>http://www.analogrithems.com/rant/2009/06/15/66/</link>
		<comments>http://www.analogrithems.com/rant/2009/06/15/66/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 18:51:32 +0000</pubDate>
		<dc:creator>analogrithems</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.analogrithems.com/rant/?p=66</guid>
		<description><![CDATA[There are two schools of thought for how to clone drives under unix. The quick and dirty method is via the unix command dd. This is a bit for bit copy tool So it can even copy master boot records and partition tables. But it also copys empty space and kinda requires the drives be [...]]]></description>
			<content:encoded><![CDATA[<p>There are two schools of thought for how to clone drives under unix. The quick and dirty method is via the unix command dd. This is a bit for bit copy tool So it can even copy master boot records and partition tables. But it also copys empty space and kinda requires the drives be identical. Since it&#8217;s rare to actually have identical drives I&#8217;m going to show you how to use other system tools available under IRIX and Solaris to accomplish this task ask well as even make the new cloned drives better.</p>
<p><strong>We start with Solaris.</strong> Not much has changed in this OS over the years. Most of the following was stolen from http://timesync.gmu.edu/wordpress/?p=30 It was customized to account for increasing the partition sizes.</p>
<p>Note that in order to garuntee the best results use the</p>
<p>Say the original drive is c1t0d0 and the new drive is c1t4d0</p>
<p>Note that in order to guarantee the best results use the prtvtoc &#038; df commands to look at what the old partition table is. This Will let you know what partitions you need to create and the minimum sizes for each one. When formatting the partitions can be bigger but must be at least the same size.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   prtvtoc <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rdsk<span style="color: #000000; font-weight: bold;">/</span>c1t0d0s2 <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>OldPartitionTable
   <span style="color: #c20cb9; font-weight: bold;">df</span> <span style="color: #660033;">-k</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>OldPartitionTable</pre></div></div>

<p>Once you know the current partition sizes use the format command to setup your new drive.</p>
<p>Now, this script will build new file systems on the partitions of the new disk…matching those on the original. Then it will run ufsdump, copying data from the original to the new drive…then unmount the new “clone” drive. Finally it makes the new clone bootable. Note that this jazzy blog format wraps lines on the installboot line of the script…a “man installboot” will give you a clean copy of the syntax.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   <span style="color: #666666; font-style: italic;">#! /bin/ksh</span>
   <span style="color: #666666; font-style: italic;"># script assumes:</span>
   <span style="color: #666666; font-style: italic;"># c1t0d0 is original</span>
   <span style="color: #666666; font-style: italic;"># c1t4d0 is drive we’ll turn into a clone</span>
&nbsp;
   <span style="color: #007800;">partlist</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>prtvtoc <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rdsk<span style="color: #000000; font-weight: bold;">/</span>c1t4d0s2 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> ‘<span style="color: #000000; font-weight: bold;">!/</span>\<span style="color: #000000; font-weight: bold;">*/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>print $<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>’<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">for</span> p <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$partlist</span>
   <span style="color: #000000; font-weight: bold;">do</span>
   <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$p</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$p</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
   <span style="color: #000000; font-weight: bold;">then</span>
   newfs <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rdsk<span style="color: #000000; font-weight: bold;">/</span>c1t4d0s<span style="color: #007800;">$p</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
   <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>dsk<span style="color: #000000; font-weight: bold;">/</span>c1t4d0s<span style="color: #007800;">$p</span> <span style="color: #000000; font-weight: bold;">/</span>mnt
   <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>mnt
   ufsdump 0uf - <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>dsk<span style="color: #000000; font-weight: bold;">/</span>c1t0d0s<span style="color: #007800;">$p</span> <span style="color: #000000; font-weight: bold;">|</span> ufsrestore rf -
   <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>
   <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>mnt
   <span style="color: #000000; font-weight: bold;">fi</span>
   <span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
   <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>dsk<span style="color: #000000; font-weight: bold;">/</span>c1t4d0s0 <span style="color: #000000; font-weight: bold;">/</span>mnt
   installboot <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>platform<span style="color: #000000; font-weight: bold;">/`</span><span style="color: #c20cb9; font-weight: bold;">uname</span> -i<span style="color: #000000; font-weight: bold;">`/</span>lib<span style="color: #000000; font-weight: bold;">/</span>fs<span style="color: #000000; font-weight: bold;">/</span>ufs<span style="color: #000000; font-weight: bold;">/</span>bootblk \
   <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rdsk<span style="color: #000000; font-weight: bold;">/</span>c1t4d0s0
   <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>mnt
&nbsp;
   <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p><strong>How to CLONE AN IRIX SYSTEM DISK. </strong>I use IRIX-disk cloning as a backup strategy. It is a bit expensive perhaps because I have to keep 2 SCSI disks (cloned copies of my combined user/root disk) in the closet as backups. In the list below I assume you are running your IRIX system on (i.e. booted from) disk #1 and you want to clone it to spare disk #3. The first time (with an uninitialised disk) cloning takes about 10 steps. A second time (when the disk is already prepared), one may start at step 7 to make a backup-clone.</p>
<p> 1) BECOME SUPERUSER:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   <span style="color: #c20cb9; font-weight: bold;">su</span></pre></div></div>

<p>2) FIRST THOROUGHLY TEST THE DRIVE THAT HAS TO BECOME THE CLONE:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   fx <span style="color: #660033;">-x</span>
    fx: <span style="color: #ff0000;">&quot;device-name&quot;</span> = <span style="color: #7a0874; font-weight: bold;">&#40;</span>dksc<span style="color: #7a0874; font-weight: bold;">&#41;</span>                       <span style="color: #000000; font-weight: bold;">&lt;</span>enter<span style="color: #000000; font-weight: bold;">&gt;</span>
    fx: ctlr<span style="color: #666666; font-style: italic;"># = (0)                                  &lt;enter&gt;</span>
    fx: drive<span style="color: #666666; font-style: italic;"># = (1)                                 3</span>
    fx: lun<span style="color: #666666; font-style: italic;"># = (0)                                   &lt;enter&gt;</span>
     fx<span style="color: #000000; font-weight: bold;">&gt;</span>                                             exercise
     fx<span style="color: #000000; font-weight: bold;">/</span>exercise<span style="color: #000000; font-weight: bold;">&gt;</span>                                    butterfly
  	modifier = <span style="color: #7a0874; font-weight: bold;">&#40;</span>rd-only<span style="color: #7a0874; font-weight: bold;">&#41;</span>                           wr-cmp
  	starting block<span style="color: #666666; font-style: italic;"># = (0)                          &lt;enter&gt;</span>
  	nblocks = <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">143374744</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>                          <span style="color: #000000; font-weight: bold;">&lt;</span>enter<span style="color: #000000; font-weight: bold;">&gt;</span>
  	nscans = <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>                                   <span style="color: #000000; font-weight: bold;">&lt;</span>enter<span style="color: #000000; font-weight: bold;">&gt;</span>
  	about to destroy data on disk dksc<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span>,<span style="color: #000000;">3</span>,<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">!</span> ok? <span style="color: #c20cb9; font-weight: bold;">yes</span>
     ..
    ..
    label info has changed <span style="color: #000000; font-weight: bold;">for</span> disk dksc<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span>,<span style="color: #000000;">3</span>,<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>.
    <span style="color: #c20cb9; font-weight: bold;">write</span> out changes?                               <span style="color: #c20cb9; font-weight: bold;">yes</span>
   <span style="color: #7a0874; font-weight: bold;">exit</span></pre></div></div>

<p>3) ADD SGI LABEL:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   fx <span style="color: #660033;">-x</span>
   fx: <span style="color: #ff0000;">&quot;device-name&quot;</span> = <span style="color: #7a0874; font-weight: bold;">&#40;</span>dksc<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
    fx: ctlr<span style="color: #666666; font-style: italic;"># = (0) </span>
    fx: drive<span style="color: #666666; font-style: italic;"># = (1) 3</span>
    fx: lun<span style="color: #666666; font-style: italic;"># = (0)</span>
     auto
     about to destroy data on disk dksc<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span>,<span style="color: #000000;">3</span>,<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">!</span> ok? <span style="color: #c20cb9; font-weight: bold;">yes</span>
     <span style="color: #7a0874; font-weight: bold;">&#40;</span>Several tests... may take a long long <span style="color: #000000; font-weight: bold;">time</span>, you can
      abort them.<span style="color: #7a0874; font-weight: bold;">&#41;</span>
   <span style="color: #7a0874; font-weight: bold;">exit</span></pre></div></div>

<p>It is perhaps easier to do this via the Disk Manager desktop-interface: just initialise the disk. This only takes a few seconds and also puts a SGI label on the disk. </p>
<p>4) MAKE ROOTDRIVE PARTITIONING: List the disk partitioning of the system (root) disk:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   prtvtoc</pre></div></div>

<p>List the disk partitioning of the option disk that is to be the clone:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   prtvtoc <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rdsk<span style="color: #000000; font-weight: bold;">/</span>dks0d3vh</pre></div></div>

<p>Compare the disk partitioning of the two disks. They must have the same layout for the root and (if used) the usr partition. If they are not the same, repartition the option disk to match the system disk. In the easiest case:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   fx <span style="color: #ff0000;">&quot;dksc(0,3)&quot;</span>
    repartition
    rootdrive
    <span style="color: #7a0874; font-weight: bold;">type</span> of data partition = <span style="color: #7a0874; font-weight: bold;">&#40;</span>xfs<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    ..
    <span style="color: #7a0874; font-weight: bold;">exit</span></pre></div></div>

<p>Then compare the prtvtoc outputs again. 5) ADD STAND-ALONE SHELL (AND OTHER PROGRAMS) TO VOLUME HEADER: If necessary, first copy the appropriate sash (on your systemdisk, SCSI ID=1) to the /stand directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   dvhtool <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rdsk<span style="color: #000000; font-weight: bold;">/</span>dks0d1vh                          <span style="color: #7a0874; font-weight: bold;">&#40;</span>CAREFUL<span style="color: #000000; font-weight: bold;">!</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
   vd                                                  <span style="color: #7a0874; font-weight: bold;">&#40;</span>volume directory<span style="color: #7a0874; font-weight: bold;">&#41;</span>
   l                                                   <span style="color: #7a0874; font-weight: bold;">&#40;</span>list<span style="color: #7a0874; font-weight: bold;">&#41;</span>
   g <span style="color: #c20cb9; font-weight: bold;">sash</span> <span style="color: #000000; font-weight: bold;">/</span>stand<span style="color: #000000; font-weight: bold;">/</span>sash_Octane
   g ide <span style="color: #000000; font-weight: bold;">/</span>stand<span style="color: #000000; font-weight: bold;">/</span>ide_Octane
   g IP30prom <span style="color: #000000; font-weight: bold;">/</span>stand<span style="color: #000000; font-weight: bold;">/</span>IP30prom_Octane
   quit</pre></div></div>

<p>Then add the required programs to a volume header:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   dvhtool <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rdsk<span style="color: #000000; font-weight: bold;">/</span>dks0d3vh                      <span style="color: #7a0874; font-weight: bold;">&#40;</span>SCSI <span style="color: #007800;">ID</span>=<span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
   vd                                              <span style="color: #7a0874; font-weight: bold;">&#40;</span>volume directory<span style="color: #7a0874; font-weight: bold;">&#41;</span>
   l                                               <span style="color: #7a0874; font-weight: bold;">&#40;</span>list<span style="color: #7a0874; font-weight: bold;">&#41;</span>
   a <span style="color: #000000; font-weight: bold;">/</span>stand<span style="color: #000000; font-weight: bold;">/</span>sash_Octane <span style="color: #c20cb9; font-weight: bold;">sash</span>                       <span style="color: #7a0874; font-weight: bold;">&#40;</span>add to volume header<span style="color: #7a0874; font-weight: bold;">&#41;</span>
   a <span style="color: #000000; font-weight: bold;">/</span>stand<span style="color: #000000; font-weight: bold;">/</span>ide_Octane ide
   a <span style="color: #000000; font-weight: bold;">/</span>stand<span style="color: #000000; font-weight: bold;">/</span>IP30prom_Octane IP30prom
   l
   quit
   <span style="color: #c20cb9; font-weight: bold;">write</span>
   quit</pre></div></div>

<p>6) MAKE FILESYSTEM: To make an XFS root filesystem with a 4 KB block size and a 1000 block internal log (the default values), give this command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   mkfs <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>dsk<span style="color: #000000; font-weight: bold;">/</span>dks0d3s0</pre></div></div>

<p>7) SWITCH TO SINGLE USER MODE AND MOUNT:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   single
&nbsp;
   <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>clone
   <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>dsk<span style="color: #000000; font-weight: bold;">/</span>dks0d3s0 <span style="color: #000000; font-weight: bold;">/</span>clone
   <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>clone</pre></div></div>

<p> <img src='http://www.analogrithems.com/rant/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> XFSDUMP:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   xfsdump <span style="color: #660033;">-l</span> <span style="color: #000000;">0</span> - <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">|</span> xfsrestore - .</pre></div></div>

<p>Notice the 0, it is a NULL character, not an O! </p>
<p>9) UNMOUNT AND SHUTDOWN:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   <span style="color: #7a0874; font-weight: bold;">cd</span> ..
   <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>clone 
   <span style="color: #c20cb9; font-weight: bold;">rmdir</span> <span style="color: #000000; font-weight: bold;">/</span>clone 
   shutdown</pre></div></div>

<p>10) TEST Swap drives (in an Octane) and try if your clone is really bootable. </p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.analogrithems.com/rant/2009/06/15/66/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.analogrithems.com/rant/2009/06/15/66/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging Unix</title>
		<link>http://www.analogrithems.com/rant/2009/06/14/debugging-unix/</link>
		<comments>http://www.analogrithems.com/rant/2009/06/14/debugging-unix/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 23:15:44 +0000</pubDate>
		<dc:creator>analogrithems</dc:creator>
				<category><![CDATA[Irix]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.analogrithems.com/rant/?p=56</guid>
		<description><![CDATA[When ever I come across a command or service in Unix that crashes or fails to run properly I quickly go to the trace tools to trace the system commands.  I often find that If I just follow the system trace i can usually see what was supposed to happen and didn&#8217;t.  Unfortunatley not every [...]]]></description>
			<content:encoded><![CDATA[<p>When ever I come across a command or service in Unix that crashes or fails to run properly I quickly go to the trace tools to trace the system commands.  I often find that If I just follow the system trace i can usually see what was supposed to happen and didn&#8217;t.  Unfortunatley not every unix flavor uses the same tracing commands.</p>
<p>In linux it is very simple prefix any command with <strong>strace</strong> and it will give you lots of system trace info.</p>
<p>In Solaris use the <strong>truss</strong> command.</p>
<p>In Irix use the <strong>par</strong> command.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.analogrithems.com/rant/2009/06/14/debugging-unix/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.analogrithems.com/rant/2009/06/14/debugging-unix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LdapAuth component for CakePHP</title>
		<link>http://www.analogrithems.com/rant/2009/06/13/ldapauth-component-for-cakephp/</link>
		<comments>http://www.analogrithems.com/rant/2009/06/13/ldapauth-component-for-cakephp/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 22:08:52 +0000</pubDate>
		<dc:creator>analogrithems</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[centralized authentication]]></category>

		<guid isPermaLink="false">http://www.analogrithems.com/rant/?p=40</guid>
		<description><![CDATA[So I was looking for a way to authenticate against LDAP with cake but I&#8217;ve found that it doesn&#8217;t support it by default.  I found one that checks the auth against ldap then creates a local mysql account.  This also didn&#8217;t use a actual ldap data sourc e either, it just handeled it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>So I was looking for a way to authenticate against LDAP with cake but I&#8217;ve found that it doesn&#8217;t support it by default.  I found one that checks the auth against ldap then creates a local mysql account.  This also didn&#8217;t use a actual ldap data sourc e either, it just handeled it&#8217;s own ldap connection.  After I read through the standard cakphp auth component I saw that it wouldn&#8217;t be that hard to write an LDAP based auth component.</p>
<p>First you need to download this file <a href="http://www.analogrithems.com/rant/wp-content/uploads/2009/06/ldap_auth.phps">ldap_auth.php</a> to your <strong>&#8216;app/controllers/components/&#8217;</strong> directory.</p>
<p>Then just like the original auth component you add that component to a model.  I followed the usual auth example and created a model called Users.php like so</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000000; font-weight: bold;">class</span> User <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'User'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$useDbConfig</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ldap'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$primaryKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'uid'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$useTable</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ou=people'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>If some of these options are odd looking please have a look at my <a href="http://www.analogrithems.com/rant/?p=3">ldap data source </a> post.  </p>
<p>Next you are going to need your controller.  Here is the one I used  It defines the required functions like login, logout &#038; authorize.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> UsersController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Users'</span><span style="color: #339933;">;</span>    
        <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$components</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'RequestHandler'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'LdapAuth'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$helpers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Form'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Html'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Javascript'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Ajax'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> login<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> logout<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LdapAuth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">logout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> isAuthorized<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>7</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.analogrithems.com/rant/2009/06/13/ldapauth-component-for-cakephp/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.analogrithems.com/rant/2009/06/13/ldapauth-component-for-cakephp/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>CakePHP with full CRUD, a living example!</title>
		<link>http://www.analogrithems.com/rant/2009/06/12/cakephp-with-full-crud-a-living-example/</link>
		<comments>http://www.analogrithems.com/rant/2009/06/12/cakephp-with-full-crud-a-living-example/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 22:14:35 +0000</pubDate>
		<dc:creator>analogrithems</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[ldap]]></category>

		<guid isPermaLink="false">http://www.analogrithems.com/rant/?p=13</guid>
		<description><![CDATA[I&#8217;ve been using CakePHP for a while now and I&#8217;ve been thinking for a while it was time to see if I could give something back.  As an IT leader I&#8217;m in love with LDAP.  It makes life so simple for me and my team.  The big downside to LDAP is it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using CakePHP for a while now and I&#8217;ve been thinking for a while it was time to see if I could give something back.  As an IT leader I&#8217;m in love with LDAP.  It makes life so simple for me and my team.  The big downside to LDAP is it&#8217;s not very easy to learn how all the objectClasses and attributes work with various applications.  Microsoft has eliminated this with the <em>Microsoft Management Console</em> (<em>MMC</em>).   It amazes me that no open source project has developed a tools such as this before.  I&#8217;ve worked on a open source tool in the past that was a web interface wrapper around ldap to do account management, so I&#8217;m familiar with the requirements such an application should have. Being that CakePHP is so powerful, I wanted to see if I could do this with that.</p>
<p>When I first started, I realized that CakePHP didn&#8217;t have an LDAP data source officially supported yet.  I did find two articles about some good attempts.  One by <a href="http://bakery.cakephp.org/articles/view/ldap-datasource-for-cakephp" target="_blank"><span>euphrate</span></a>, unfortunately this one was only for reading from ldap.  The second one was by <a href="http://memdump.wordpress.com/2008/04/26/ldap-data-source-now-with-full-crud/">Gservat</a>, this one was a bit more complete, but was not really working for me and  as i read from his comments many others.  I think we wrote his for CakePHP 1.1.  Since I wanted to use Current cake 1.2.8xxx  I set out to use this as my start and fix/extend it.</p>
<p>Before we get started I want to state the environment I was using to do my work was Redhat Enterprise 5.2 &amp; Fedora 10 (Work requirement) with redhat directory server 8.1 and Fedora directory server 1.2.  Now while LDAP is a standard protocol, some of the driver may have become centric to those platforms, so if this is the case, please leave me a comment and I will try to correct the ldap data source I&#8217;m working on.  My hope is to get ldap as an offical CakePHP data source.  With that said the reason i call this a living example is because I&#8217;ve continued to upgrade and improve this data source as well as this article.  Some of the next features I want to implement is data associations.  Basically has and belongs to many relations.  This way when you look up an user account it also shows you all the groups that user is in.  This will take some time but I&#8217;ll get there.  This work is all being done in the hopes that I can use this data source and CakePHP to build a really user friendly web interface for managing enterprise LDAP infrastructures without a whole lot of LDAP knowledge.</p>
<p><b>8/20/2009 &#8211; New Home for the source.  I&#8217;ve got this datasource in my github tree now <a href="http://github.com/analogrithems/idbroker/tree/master/models/datasources">http://github.com/analogrithems/idbroker/tree/master/models/datasources</a>  enjoy, and feel free to submit bugs or request there.</p>
<p>7/13/2009 &#8211; updated ldap_source.php to make better use of the debug describe code.  Also fixed the way things update.  Only update what has changed instead of whole record.  This will help with LDAP aci rules when logging in as non-admin users and trying to do things like update your userpassword or email.</p>
<p>6/20/2009 &#8211; Updated ldap_source.php to work with OpenLDAP 2.3 schema system.  First it will try &#8216;cn=schema&#8217;, if that doesn&#8217;t return any results then it looks for schemas in &#8216;cn=subschema&#8217;  this make sure the code will work with OpenLDAP as well as the Netscape based versions like iPlanet, Redhat Directory Server, Fedora Directory Server etc.</B></p>
<p>First things first, here is my ldap data source for CakePHP.  You will need to download this <a href="http://www.analogrithems.com/rant/wp-content/uploads/2009/07/ldap_source.phps" target="_blank">ldap_source.php</a> to your &#8216;app/models/datasources/&#8217; directory.</p>
<p>So lets dive right in below is the database config we will use.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> DATABASE_CONFIG <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// if using ssl set 'host' =&gt; ldaps://hostname and 'port' =&gt; 636</span>
        <span style="color: #666666; font-style: italic;">// If using tls set 'tls' =&gt; true and 'port' =&gt; 389</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$ldap</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'datasource'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ldap'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'host'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span>                
		<span style="color: #0000ff;">'port'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">389</span><span style="color: #339933;">,</span>                        
		<span style="color: #0000ff;">'basedn'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dc=examnple,dc=com'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'login'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> 
		<span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>                
		<span style="color: #0000ff;">'database'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'tls'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'version'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span>                    
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>You notice that the variables database, login and password are blank.  Keep at least database this way.  You can populate login and password if don&#8217;t want your ldap connections to be anonymous.  I keep mine blank because I have written my own auth component that uses ldap,   So once I&#8217;m authed that gets passed to the datasource instead.  This is a ugly hack that I&#8217;ve written another <a href="http://www.analogrithems.com/rant/2009/06/13/ldapauth-component-for-cakephp/">post about</a>.</p>
<p>Here is our people model for accessing the users in your LDAP tree.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000000; font-weight: bold;">class</span> People <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'People'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$useDbConfig</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ldap'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// This would be the ldap equivalent to a primary key if your dn is </span>
	<span style="color: #666666; font-style: italic;">// in the format of uid=username, ou=people, dc=example, dc=com</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$primaryKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'uid'</span><span style="color: #339933;">;</span>     
&nbsp;
	<span style="color: #666666; font-style: italic;">// The table would be the branch of your basedn that you defined in </span>
	<span style="color: #666666; font-style: italic;">// the database config</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$useTable</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ou=people'</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$validate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'cn'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'alphaNumeric'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
				<span style="color: #0000ff;">'rule'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'custom'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;/^[a-zA-Z]*$/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'on'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'create'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Only Letters and Numbers can be used for Display Name.'</span>
			<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'between'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
				<span style="color: #0000ff;">'rule'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'between'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'on'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'create'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Between 5 to 15 characters'</span>
			<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'sn'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'rule'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'custom'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;/^[a-zA-Z]*$/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'on'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'create'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Only Letters and Numbers can be used for Last Name.'</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'userpassword'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'rule'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'minLength'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Mimimum 8 characters long.'</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'email'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'rule'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'email'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'on'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'create'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Must Contain a Valid Email Address.'</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'uid'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'rule'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'alphaNumeric'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'on'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'create'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Only Letters and Numbers can be used for Username.'</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Here is a very basic controller to accompany our people model.  It demonstrates the important core functions and should get you started on using this data source with your own application.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> PeoplesController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Peoples'</span><span style="color: #339933;">;</span>    
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$components</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'RequestHandler'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$helpers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Form'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Html'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Javascript'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Ajax'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> add<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'objectclass'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'top'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'organizationalperson'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'inetorgperson'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'person'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'posixaccount'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'shadowaccount'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password_confirm'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'userpassword'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password_confirm'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'homedirectory'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uid'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'homedirectory'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/home/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uid'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">People</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFlash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'People Was Successfully Created.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">People</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'view'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'id'</span><span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFlash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;People couldn't be created.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFlash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Passwords don't match.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">layout</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'people'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> view<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$id</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$filter</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">People</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">primaryKey</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$people</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">People</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'first'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'conditions'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$filter</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">compact</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'people'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">layout</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'people'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> delete<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">People</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">People</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">del</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>So lets talk about somethings here,  in our model we define <strong>$primaryKey</strong> &amp; <strong>$useTable</strong> variables.  The <strong>$useTable</strong> is the branch of the ldap server.  For this models purpose we define our table as <b>&#8216;ou=people&#8217;</b>.  This makes sure that objects we create (I.E. Users/people)  will be added under the organization unit people.  It also makes sure that when you pass something like &#8216;jdoe&#8217; to the delete action it will search that branch for the user object to delete.  The <strong>$primaryKey</strong> also helps in the creation and deleting of users.  It makes sure that the dn is created as uid, this is helpful to make sure that a user doesn&#8217;t already have that user name.  Also since ldap is case insensitive you don&#8217;t have to worry about the possible variations of the object names when checking the existence.</p>
<p>Now your model isn&#8217;t limited to one branch or object type.  If you wanted to create a browser for example your could define a model like the following.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000000; font-weight: bold;">class</span> Browser <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Browser'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$useDbConfig</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ldap'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$primaryKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'dn'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$useTable</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>You&#8217;ll notice here we set our <strong>$useTable</strong> to nothing (important, you get errors about no db defined from CakePHP if this missing).  The really interesting part here is that we set <strong>$primaryKey</strong> to dn.  This is the ultimate primary key for our type or data source.  The difference here is that when we create/delete an object we have to pass it the full dn.</p>
<p>Our new data source also adds some new options to the find function.<br />
<strong>$options['targetDN'] :</strong> This is more like the point in the tree we want to start our search.  If you don&#8217;t define it it defaults to the $useTable.$config[$useDbConfig]['basedn']  if your $useTable variable is empty it defaults to the basedn configured in your database config.</p>
<p><strong>$options['scope'] :</strong> If you&#8217;ve worked with ldap before then you are familiar with the concept of search scopes.  You have three search scopes, &#8217;sub&#8217;, &#8216;one, &amp; &#8216;base&#8217;.  Basically <strong>sub</strong> means search from this point down the tree.  <strong>one</strong> means search one level below this point and <strong>base</strong> means search just this point.  For example if you wanted to see if a user already existed you could set the targetDn to uid=jdoe,ou=people,dc=example,dc=com and it will check if this object already exists.   The default scope is <strong>sub</strong></p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.analogrithems.com/rant/2009/06/12/cakephp-with-full-crud-a-living-example/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.analogrithems.com/rant/2009/06/12/cakephp-with-full-crud-a-living-example/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>Why nscd sucks&#8230;.</title>
		<link>http://www.analogrithems.com/rant/2008/09/16/why-nscd-sucks/</link>
		<comments>http://www.analogrithems.com/rant/2008/09/16/why-nscd-sucks/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 01:27:53 +0000</pubDate>
		<dc:creator>analogrithems</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nscd]]></category>

		<guid isPermaLink="false">http://www.analogrithems.com/rant/?p=5</guid>
		<description><![CDATA[The name service cache daemon has some serious flaws.  One that I notice pretty often in Linux arises when you are using LDAP.  It seems that nscd will crash and burn when/if ldap is unavailable.  Unfortunately when nscd bombs, it usually takes the entire system with it.  Actually what will happen [...]]]></description>
			<content:encoded><![CDATA[<p>The name service cache daemon has some serious flaws.  One that I notice pretty often in Linux arises when you are using LDAP.  It seems that nscd will crash and burn when/if ldap is unavailable.  Unfortunately when nscd bombs, it usually takes the entire system with it.  Actually what will happen is nscd sockets will start getting broken pipe&#8217;s and becoming stale until you have several nscd.  Eventually your system will slow to a halt.  Mind you the box hasn&#8217;t crashed, but the box is in a dos state.  If you do an &#8216;<em>$# netstat -an</em>&#8216; you&#8217;ll notice several entries in reference to &#8216;/var/run/nscd/socket&#8217;.  This bug has been listed by several distros, I&#8217;ve yet to see any of them address it properly.</p>
<p>From what I&#8217;ve discovered about nscd this issue is a design flaw in nscd.  Several people have just recommended disabling nscd.  While this is a solution, it isn&#8217;t an acceptable solution in an enterprise environment. Especially if you are using oracle.  Several oracle tools and apps will freeze or crash if they can&#8217;t talk to the nscd socket.  Lame I know, but I&#8217;ve observed this in at least Oracle 10i.</p>
<p><strong>Solutions</strong></p>
<p>Now there are tow ways to get around this.  One is to make your LDAP service load balanced and highly available.  You can do replication in OpenLDAP with slurpd and then use something like balance to make the service highly available.  Another option though is to fix nscd so it doesn&#8217;t bomb your machine when it dies.</p>
<p>In this article we are going to go over the fix nscd solution.  nscd comes with a config file located in &#8216;<em>/etc/nscd.conf&#8217;</em> This file tells the nscd daemon how long to cache which name service.  See the man page to understand what each option means. The quick way to fix nscd is to tell the service here not to cache passwd and group info.  This will make nscd not go to LDAP and freak out if LDAP is not available.  Randomly I also came across a drop in replacement for nscd that dosen&#8217;t suffer from this issue. <a href="http://www.analogrithems.com/rant/wp-content/uploads/2008/09/nscd-033.c">unscd-033.c</a> The compile instructions are in the file. I can&#8217;t guarantee this safe, but I&#8217;ve used it for a while in an enterprise environment and seem haven&#8217;t had any nscd issues since<a href="http://www.analogrithems.com/rant/wp-content/uploads/2008/09/nscd-033.c"><br />
</a></p>
<p><strong>Refferences:</strong></p>
<ul>
<li>http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=248271</li>
</ul>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.analogrithems.com/rant/2008/09/16/why-nscd-sucks/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.analogrithems.com/rant/2008/09/16/why-nscd-sucks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
