<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>My Open Source Software Exploits</title>
	<atom:link href="http://allopen.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://allopen.wordpress.com</link>
	<description>Open Solutions</description>
	<lastBuildDate>Fri, 09 Oct 2009 20:48:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='allopen.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/18c6084a821c26e573d99b18dcf2bfa9?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>My Open Source Software Exploits</title>
		<link>http://allopen.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://allopen.wordpress.com/osd.xml" title="My Open Source Software Exploits" />
	<atom:link rel='hub' href='http://allopen.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Running Drupal 6.5 on PHP 5.3.x</title>
		<link>http://allopen.wordpress.com/2009/10/09/running-drupal-6-5-on-php-5-3-x/</link>
		<comments>http://allopen.wordpress.com/2009/10/09/running-drupal-6-5-on-php-5-3-x/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 18:26:59 +0000</pubDate>
		<dc:creator>bryanallo</dc:creator>
				<category><![CDATA[CMS]]></category>

		<guid isPermaLink="false">http://allopen.wordpress.com/?p=23</guid>
		<description><![CDATA[How do you move forward with PHP 5.3 while still supporting your Drupal 6.5 CMS deployments? This post is about my solution to that challenge.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=allopen.wordpress.com&amp;blog=9829394&amp;post=23&amp;subd=allopen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am sure there are many other folks out there with Drupal CMS deployed who really need PHP 5.3 . Not too long ago I decided it was time to extend my web aplication framework to authenticate against the network active directory via LDAP. As I fine-tuned my solution over the course of several days I quickly realized that I needed PHP 5.3 to be running on all web application servers because of a very recently released method inthe PHP LDAP module. Authenticating against LDAP was a cruicial step in the process of consolidating a growing range of internal business applications so PHP a 5.3 upgrade was unavoidable.</p>
<p>At the same time several business units were in the process of implementing the Drupal 6.5 CMS solution. The problem as we quickly realized was that Drupal 6.5 will only work with PHP 5.2 or older. From an organizational standpoint we absolutely needed PHP 5.3 . We also did not want to run more than one version of PHP on our webservers, just to host Drupal. Also, the various business units could not wait for Drupal 7 to be released (whenever that may be). And even if Drupal 7 were released, I am less inclined to do an immediate upgrade without a complete evaluation of the entire CMS.</p>
<p><strong>So How do I get Drupal 6.5 to work on PHP 5.3?<br />
</strong>I decided to just dive into the Drupal 6.5 source code and figure out what was broken and start fixing it all. I found four (4) core issues at the heart of the Drupal 6.5 / PHP 5.3 incompatibility.</p>
<p><strong><span style="color:#993300;">1 ) Function ereg() is deprecated<br />
</span></strong>Once you run Drupal 6.5 on PHP 5.3, the first error you will get is this one. Yes the ereg() function is deprecated (discontinued) but it still runs fine and the warning/notice can be silenced for now until you upgrade to Drupal 7. To silence the function warning, simply add a <strong><em>&#8220;@&#8221;</em></strong> before the <strong><em>&#8220;ereg()&#8221;</em></strong>  function call so <strong>&#8220;ereg()&#8221;</strong> becomes <strong>&#8220;@ereg()&#8221; </strong>. There were several instances of this. I decided to only change those that showed up on the Dripal site, instead of doing a global search and replace. The ones I found and changed are listed below:</p>
<blockquote><p><span style="color:#333399;">- The &#8220;ereg()&#8221; call should be silenced as such &#8220;@ereg()&#8221;<br />
- Line 895 &#8211; /includes/file.inc<br />
- Line 385 &#8211; /modules/user/user.module  (yes that is the &#8220;.module&#8221; extension)<br />
- Line 553 &#8211; /includes/file.inc<br />
&#8211; Silence the &#8220;array_merge()&#8221; within the &#8220;ereg()&#8221; function call as well</span></p></blockquote>
<p><span style="color:#993300;"><strong> 2 ) Function split() is deprecated</strong><br />
</span>Not sure why such a symbolic function is deprecated, but I&#8217;m sure it&#8217;s all for a good cause. Like the <strong>&#8220;ereg()&#8221;</strong> call, it must be silenced as well. Below are (not all) the instanced I changed:</p>
<blockquote><p><span style="color:#333399;">- Line 895 &#8211; /modules/filter/filter.module</span></p></blockquote>
<p><span style="color:#993300;"><strong>3 ) warning: call_user_func_array() expects parameter 2 to be array</strong><br />
<span style="color:#000000;">It appears PHP 5.3 is less forgiving as far as whether or not you specify explicitly that you are passing an arguement to a function by value or my reference. In most classical languages such as C/C++ this is very important. Is seems PHP 5.2 was okay with it either way. I think this change is a good thing and will go a long way to forcing programmers to think about how they write code and give more creative room as far as optimizing your applications to use memory more efficiently. However the solution to this problem is quite simple actually; you jsut have to add an ampersand <strong>&#8220;&amp;&#8221;</strong> infront of any relevant arguments that are causing this error. The &#8220;&amp;&#8221; simply states that you are passing a the argument by reference and not by value. Initially I found 27 instances of these calls in the Drupal 6.5 source. I am sure there are more instances in the <em>&#8220;.module&#8221;</em> code but I&#8217;m only making the changes as needed. I try to avoid global changes I don&#8217;t have to.</span></span></p>
<blockquote><p><span style="color:#993300;"><span style="color:#333399;">Example: The call call_user_func_array($function, $args) should change to call_user_func_array($function, &amp;$args) <br />
- Line 436 &#8211; /includes/menu.inc<br />
- Line 617 &#8211; /includes/theme.inc<br />
- Line 553 &#8211; /includes/file.inc</span></span></p></blockquote>
<p><strong> <span style="color:#993300;">4 ) PHP Warning: Call-time pass-by-reference has been deprecated</span></strong><br />
Once I made all the above changes and my Drupal 6.5 instance was up and running I was now getting a warning from PHP. The fix of arguement references caused PHP to issue a warning of it&#8217;s own. You can fix this by making sure the value for &#8220;<em>allow_call_time_pass_reference</em>&#8221; is set to &#8220;<em>On</em>&#8221; in your &#8220;<em>php.ini</em>&#8221; file. This is a good practice anyways and highly recommended for any production environment as your PHP intance should not report any errors or warnings to the browser, but to the server log file.</p>
<p>Please let me know if you find any more instances where the Drupal 6.5 code needs patching, so I may add them to my notes here. So far the Drupal 6.5 instances have been running successfully. Thanks and all the best.</p>
<p><strong>DISCLAIMER:<br />
</strong>I have only been working with Drupal for several days so far. Please bear with me as I dive deeper into the source code and architecture. You may see several new messages in your log files. In my case I&#8217;m running Apache. Most of the new log errors are the &#8220;deprecated function&#8221; warnings so it&#8217;s not a big deal for now, until I upgrade to Drupal 7. I am still investigating any other effects these fixes may have had on the servers.</p>
<br />Posted in CMS  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/allopen.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/allopen.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/allopen.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/allopen.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/allopen.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/allopen.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/allopen.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/allopen.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/allopen.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/allopen.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/allopen.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/allopen.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/allopen.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/allopen.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=allopen.wordpress.com&amp;blog=9829394&amp;post=23&amp;subd=allopen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://allopen.wordpress.com/2009/10/09/running-drupal-6-5-on-php-5-3-x/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d2573e17761960096520044acc730988?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bryanallo</media:title>
		</media:content>
	</item>
		<item>
		<title>LDAP and PHP</title>
		<link>http://allopen.wordpress.com/2009/10/07/ldap-and-php/</link>
		<comments>http://allopen.wordpress.com/2009/10/07/ldap-and-php/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 17:44:21 +0000</pubDate>
		<dc:creator>bryanallo</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://allopen.wordpress.com/?p=3</guid>
		<description><![CDATA[I build a lot of custom corporate and business applications and I got tired of having to build user management for every application. This post is about what I leaned about integrating PHP and LDAP.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=allopen.wordpress.com&amp;blog=9829394&amp;post=3&amp;subd=allopen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Most organizations, even those taking advantage of the benefits of open source software are running on Microsoft Windows based network services. I have spent most of my carreer building custom business applications (with PHP/MySQL whenever I have a choice). One of the critical aspects of a custom application is user management and security. It&#8217;s a real drag . I decided to integrate Active Directory into my PHP application framework so I can focus on implementing critical features instead of security models.</p>
<p>The greatest benefits of such an integration are that you can quickly and easily setup a Web Single Sign-On (WSSO) for all your corporate applications. Your same Windows user name gets you onto all the different web applications that you use in your organization. No more need to remember numerous username/password combinations. When a new employee is hired, the Systems Administrator sets up their network user and assigns them to the appropriate user groups in Active Directory and they&#8217;re good to go. Voila!</p>
<p><strong>You will need PHP 5.3+</strong><br />
PHP for the most part has what you need to do an LDAP integration. I did run into one little but crucial issue and that was with PHP5.2 . There was one crucial method not yet implemented. The &#8220;<em>ldap_set_option</em>&#8221; . Everything worked fine as long as my routines were given a correct user name and password combination. We all know this is hardly always the case. If the username/password was incorrect, the PHP LDAP module would lock-up while waiting for a response from the LDAP server that failed to authenticate the wrong username/password combination. The module tied-up the PHP server process untill the script timed-out. To remedy this I needed to be able to set a timeout on my PHP-to-LDAP connection. It turned out the PHP community was working on a solution around the same time to be released in PHP 5.3 . One simple line made all the difference:<br />
<pre class="brush: php;">
ldap_set_option($ldap_handle, LDAP_OPT_NETWORK_TIMEOUT, 10);
</pre></p>
<p>You will also need some kind of LDAP browsing tool. I used <em>LDAP Browser 2.6 </em>by <em>Softerra. </em>Thanks Mark. It also shows you what queries are being sent back to your LDAP service. From this you will very quickly be  able to decypher your active directory and determine what you need to look for in your LDAP search queries. Just playing around with the LDAP browser told me way more about active directory than I learned after endless nights realy manuals and protocol spec sheets.</p>
<p> Below is a function I put together to authenticate users against an LDAP service. I have inserted comments at every step and simplified a lot of my original code to present my solution is a very straight-forward, step-by-step process. I have not tested the resulting code below and as a result it may be missing a semi-colon here or there. I expect anyone who finds this interesting is self-sufficient enough to make this solution work for themselves as needed.</p>
<p><pre class="brush: php;">
function LDAP_UserLogin($Portal) {
	// $Portal is my applciation framework which resides in my session at all times.
	
	// Set user and password to Administrator for testing
	$USR_Name = $Portal-&gt;Web['UserName'];
	$PWD = $Portal-&gt;Web['Password'];
	
	// LDAP Windows server name
	$HOST = &quot;LDAP_ServerName&quot;;
	// Fully qualified network user name
	$USER_DN = &quot;NETWORK_DOMAIN\\&quot;.$USR_Name; 
	
	// This value is determined by your active directory structure
	$BASE_DN = &quot;DC=NETWORK_DOMAIN,DC=local&quot;;
	
	/*
	Specify what user (node) you wish to have returned.	If you use 
	the wildcard, LDAP will return every single node accessible to 
	the authenticated user. So a wildcard query from */
	$SEARCH_OBJECT=&quot;(mailnickname=$USR_Name)&quot;;
	// To show everything accessible to $USER_DN use $SEARCH_OBJECT=&quot;(objectClass=*)&quot;; 
	
	// Specify what fields (nodes) you wish returned for the authenticated user.
	$FILTER = array(&quot;*&quot;);
	// OR select only specific tree nodes/values to return.
	//$FILTER = array(&quot;sn&quot;, &quot;mailnickname&quot;, &quot;displayname&quot;, &quot;memberof&quot;);
	
	// LDAP authentication process updates
	$Message = '';
	
	// Step 1 - connect to LDAP Server
	if($ldap_handle=ldap_connect($HOST)) {
		$Message .= 'LDAP Connect Successful&lt;br&gt;';
	} else {
		$Message .= 'LDAP Connect Failed&lt;br&gt;';
		return $Message;
	}
	
	/* 
	Step 2 - Set a timeout for the PHP-to-LDAP connection, or it will tie-up 
	the server process until the script times-out, whenever someone 
	provides a wrong user/password combination. 5-10 seconds is long 
	enough to wait for an LDAP server response. */
	ldap_set_option($ldap_handle, LDAP_OPT_NETWORK_TIMEOUT, 10);
	
	// Step 3 - Bind to LDAP Server using user credentials
	if(@$bind_result=ldap_bind($ldap_handle,$USER_DN,$PWD)) {
		$Portal-&gt;User-&gt;Profile['LoginStatus'] = 1;
		$Message .= 'LDAP Bind Successful&lt;br&gt;';
	} else {
		$Message .= 'LDAP Bind Failed for '.$USER_DN.'&lt;br&gt;';
		return $Message;
	}
	
	/* 
	Step 4 - Search Active Directory for specified object - user record.
	User authentication happens in Step 3 when you bind the user to your 
	LDAP connection. you will only be able to search any nodes that user 
	has access to within the active directory tree. Therefore system 
	Administrator will be able to search the entire network directory so 
	be careful. Active directories can be very, very big! */
	if($search_result=ldap_search($ldap_handle,$BASE_DN,$SEARCH_OBJECT,$FILTER)) {
		$Message .= 'LDAP Seach Successful&lt;br&gt;';
		//Print out search result tree as array
		//print_r($search_result);
	} else {
		$Message .= 'LDAP Search Failed&lt;br&gt;';
		return $Message;
	}
	
	/* 
	Step 5 - Get first entry of LDAP record search result. This is not 
	really neccessary. It's a left over from my testing of the PHP LDAP 
	module. It helps sometimes when debuging to see if what is being 
	returned. See the commented-out line below. */
	if($result=ldap_first_entry($ldap_handle,$search_result)) {
		$Message .= 'LDAP Get First Entry Successful&lt;br&gt;';
		//Print out tree as array.
		//print_r($result);
	} else {
		$Message .= 'LDAP Get First Entry Failed&lt;br&gt;';
		return $Message;
	}
	
	
	/*
	Step 6 - Get all returned LDAP entries that met your search criteria. 
	This is important. You can uncomment the line below to see the entire 
	tree. Again be careful when querrying the entire tree with a user who 
	has full network administrative previlleges. */
	if($result=ldap_get_entries($ldap_handle,$search_result)) {
		$Message .= 'LDAP Get Entries Successful&lt;br&gt;';
		// Print out all entries as array
		//echo &quot;&lt;pre&gt;&quot;; print_r($result);
	} else {
		$Message .= 'LDAP Get Entries Failed&lt;br&gt;'; 
		return $Message;
	}
	
	
	/*
	Step 7 - Extract groups to which user is assigned. This is once you 
	have all the previous steps running successfully. You can extract 
	any relevant groups from the 'memberof' values. */
	if($result[0]['memberof']) {
		$Message .= 'LDAP Get Group Entries Successful&lt;br&gt;';
	} else {
		$Message .= 'LDAP Get Group Entries Failed&lt;br&gt;'; 
	}
	
	/*
	I chose to setup a separate &quot;Organizational Unit&quot; (OU) called &quot;Intranet&quot; 
	on the windows domain server. Within that OU I have groups setup for every 
	biz application I've deployed. Based on what business unit an employee is 
	under, they will be assigned to the appropriate groups and gain access to 
	any neccessary applicaitons. OU=Intranet helps sys admin manage and organize 
	all permissions related to web access and it helps me identify within the 
	active directory tree, what groups/permission items I should be looking for.*/
	foreach($result[0]['memberof'] as $key =&gt; $value) {
		if(strpos($value,'OU=Intranet')) {
			//This pattern may vary from one active directory to another.
			$group = preg_replace('/CN=(.*?),OU=Intranet.*?$/i','$1',$value);
			
			/*
			Push user group into application framework. $Portal-&gt;User-&gt;Groups is 
			an array I can lookup at anytime, anywhere in my application to make 
			sure the user has access to any particular group. */
			array_push($Portal-&gt;User-&gt;Groups, $group);
		}
	}
	
	//Once all user groups have been extracted, save framework object to session.
	$_SESSION['Portal'] = serialize($Portal);
	
	//Debug view, another way to dump user's entire directory tree to screen
	//print_r(ldap_explode_dn($BASE_DN,'')); 
	
	/* Step 8 - Close LDAP connection. 
	Just good practice to keep your code clean. */
	if(ldap_close($ldap_handle)) {
		$Message .= 'LDAP Connection Closed';
	} else {
		$Message .= 'LDAP Connection Failed to Close&lt;br&gt;';
	}
	
	// Return all status messages, for debuging and confirmation.
	return $Message;
}
</pre></p>
<p>If you have any questions about my application framework let me know and I can prepare a post about a basic application framework. I hope you found this post helpful. I am open to and welcome all <span style="text-decoration:underline;"><em>constructive</em></span> feedback, comments and suggestions.</p>
<p>Happy coding <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<br />Posted in Security  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/allopen.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/allopen.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/allopen.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/allopen.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/allopen.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/allopen.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/allopen.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/allopen.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/allopen.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/allopen.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/allopen.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/allopen.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/allopen.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/allopen.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=allopen.wordpress.com&amp;blog=9829394&amp;post=3&amp;subd=allopen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://allopen.wordpress.com/2009/10/07/ldap-and-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d2573e17761960096520044acc730988?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bryanallo</media:title>
		</media:content>
	</item>
	</channel>
</rss>
