<?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>Ananth Deodhar - My rambles &#187; Code</title>
	<atom:link href="http://www.ananthdeodhar.com/category/code/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ananthdeodhar.com</link>
	<description>My thoughts on things, birds, trees, and whatever else catches me fancy.</description>
	<lastBuildDate>Mon, 12 Jul 2010 07:50:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP Active Directory Integration: get userAccountControl attributes</title>
		<link>http://www.ananthdeodhar.com/2009/08/28/php-active-directory-integration-get-useraccountcontrol-attributes</link>
		<comments>http://www.ananthdeodhar.com/2009/08/28/php-active-directory-integration-get-useraccountcontrol-attributes#comments</comments>
		<pubDate>Fri, 28 Aug 2009 12:07:26 +0000</pubDate>
		<dc:creator>zooperman</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.ananthdeodhar.com/?p=25</guid>
		<description><![CDATA[While trying to integrate an AD based login in my php application, I came across the problem of checking which user accounts were not disabled. After going through some forums I did the following to see accounts which were not disabled: $result = ldap_search($ad, "OU=Users,OU=Office1,DC=country,DC=company,DC=com", "(&#38;(objectCategory=user)(!(userAccountControl=514)))"); Microsoft returns the flags set for any user in [...]]]></description>
			<content:encoded><![CDATA[<p>While trying to integrate an AD based login in my php application, I came across the problem of checking which user accounts were not disabled.</p>
<p>After going through some forums I did the following to see accounts which were not disabled:<br />
<code>$result = ldap_search($ad, "OU=Users,OU=Office1,DC=country,DC=company,DC=com", "(&amp;(objectCategory=user)(!(userAccountControl=514)))");</code></p>
<p>Microsoft returns the flags set for any user in the userAccountControl attribute in a cumulative manner. The flag values used by Active Directory are mentioned <a title="Active Directory userAccountControl Flag Values" href="http://support.microsoft.com/kb/305144" target="_blank">here</a>.</p>
<p>So e.g.<br />
John has a Normal Account [Flag 512]<br />
Alex had a Normal Account [Flag 512] but now has been disabled [Flag 2] so the status on his account now is [512+2 = 514].</p>
<p>This works fine in most cases but as the flags can be summed up in any order, ldap_search returned 66050 for some users.  Seeing the table what that means is:</p>
<p>[Flag 65536 ]+ [Flag 512] + [Flag 2] which translates to</p>
<p>[Password Doesn't Expire] + [was a Normal Account] + [but has been disabled now.]</p>
<p>So checking for 66050 in my php script was the next dirty fix to exclude such people as well like so:</p>
<p><code>$result = ldap_search($ad, "OU=Users,OU=Office1,DC=country,DC=company,DC=com", "(&amp;(objectCategory=user)(!(userAccountControl=514))(!(userAccountControl=66050)))");</code></p>
<p>While making the admin section to manage these users I had to show the users for our different offices (located in different countries) and also what settings they had.</p>
<p>The userAccountControl just gives back the sum of all the flags set when we do an ldap_search and get all entries for any user object.</p>
<p>To solve this problem of mine, I made the following function to breakdown the codes returned in the useraccountcontrol field into their corresponding flags which have been set in the userAccountControl attribute.</p>
<p><code>function getUserAccountControlAttributes($inputCode)<br />
{<br />
/**<br />
*  http://support.microsoft.com/kb/305144<br />
*<br />
*  You cannot set some of the values on a user or computer object because<br />
*  these values can be set or reset only by the directory service.<br />
*<br />
*/<br />
$userAccountControlFlags = array(16777216 =&gt; "TRUSTED_TO_AUTH_FOR_DELEGATION",<br />
8388608 =&gt; "PASSWORD_EXPIRED",<br />
4194304 =&gt; "DONT_REQ_PREAUTH",<br />
2097152 =&gt; "USE_DES_KEY_ONLY",<br />
1048576 =&gt; "NOT_DELEGATED",<br />
524288 =&gt; "TRUSTED_FOR_DELEGATION",<br />
262144 =&gt; "SMARTCARD_REQUIRED",<br />
131072 =&gt; "MNS_LOGON_ACCOUNT",<br />
65536 =&gt; "DONT_EXPIRE_PASSWORD",<br />
8192 =&gt; "SERVER_TRUST_ACCOUNT",<br />
4096 =&gt; "WORKSTATION_TRUST_ACCOUNT",<br />
2048 =&gt; "INTERDOMAIN_TRUST_ACCOUNT",<br />
512 =&gt; "NORMAL_ACCOUNT",<br />
256 =&gt; "TEMP_DUPLICATE_ACCOUNT",<br />
128 =&gt; "ENCRYPTED_TEXT_PWD_ALLOWED",<br />
64 =&gt; "PASSWD_CANT_CHANGE",<br />
32 =&gt; "PASSWD_NOTREQD",<br />
16 =&gt; "LOCKOUT",<br />
8 =&gt; "HOMEDIR_REQUIRED",<br />
2 =&gt; "ACCOUNTDISABLE",<br />
1 =&gt; "SCRIPT"<br />
);<br />
</code><br />
<code><br />
$attributes = NULL;<br />
while($inputCode &gt; 0)<br />
{<br />
foreach($userAccountControlFlags as $flag =&gt; $flagName)<br />
{<br />
$temp = $inputCode-$flag;<br />
if($temp&gt;0)<br />
{<br />
$attributes[$userAccountControlFlags[$flag]] = $flag;<br />
$inputCode = $temp;<br />
}<br />
if($temp==0)<br />
{<br />
if(isset($userAccountControlFlags[$inputCode]))<br />
{<br />
$attributes[$userAccountControlFlags[$inputCode]] = $inputCode;<br />
}<br />
$inputCode = $temp;<br />
}<br />
}<br />
}<br />
return $attributes;<br />
}</code></p>
<p><code><br />
$userAccountControlAttributes = getUserAccountControlAttributes(66048);<br />
var_dump($userAccountControlAttributes);</code></p>
<p>On doing a var_dump this function returns this:<br />
<code>array(2) { ["DONT_EXPIRE_PASSWORD"]=&gt;  int(65536) ["NORMAL_ACCOUNT"]=&gt;  int(512) }</code></p>
<p>This made it easier for me to display the attributes set on each user in my admin panel and I also removed the checks for Flag 514, and Flag 66050 in my ldap_search filter and instead checked if the ACCOUNTDISABLE was set and showed only those users in my list like so:<br />
<code>if(!isset($userAccountControlAttributes["ACCOUNTDISABLE"]))<br />
{<br />
// do something<br />
}</code></p>
<p>Hope this helps someone trying to show account attributes using php.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ananthdeodhar.com/2009/08/28/php-active-directory-integration-get-useraccountcontrol-attributes/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Some of the tools I use</title>
		<link>http://www.ananthdeodhar.com/2009/08/28/some-of-the-tools-i-use</link>
		<comments>http://www.ananthdeodhar.com/2009/08/28/some-of-the-tools-i-use#comments</comments>
		<pubDate>Fri, 28 Aug 2009 11:06:31 +0000</pubDate>
		<dc:creator>zooperman</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.ananthdeodhar.com/?p=19</guid>
		<description><![CDATA[I  was going to write about Notepad2 but just didn&#8217;t get around doing it. So here I am just listing out a few tools I use : Notepad2 (Windows notepad is dead, this one has truly replaced all my windows systems) WinMerge (diff tool) Softerra LDAP Administrator (amazing ldap manager) Easy Eclipse (eclipse installation for [...]]]></description>
			<content:encoded><![CDATA[<p>I  was going to write about Notepad2 but just didn&#8217;t get around doing it. So here I am just listing out a <em>few</em> tools I use :</p>
<p><a title="Advanced notepad with syntax highlighting" href="http://www.flos-freeware.ch/notepad2.html" target="_blank">Notepad2</a> (Windows notepad is dead, this one has truly replaced all my windows systems)</p>
<p><a title="Differencing and Merging Tool" href="http://winmerge.org" target="_blank">WinMerge</a> (diff tool)<a title="Differencing and Merging Tool" href="http://winmerge.org" target="_blank"><br />
</a></p>
<p><a title="LDAP Administrator and Browser" href="http://www.ldapadministrator.com/" target="_blank">Softerra LDAP Administrator</a> (amazing ldap manager)</p>
<p><a title="Easy Eclipse IDE" href="http://easyeclipse.org/" target="_blank">Easy Eclipse</a> (eclipse installation for the truly lazy people)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ananthdeodhar.com/2009/08/28/some-of-the-tools-i-use/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TAR to the rescue</title>
		<link>http://www.ananthdeodhar.com/2008/08/05/tar-to-the-rescue</link>
		<comments>http://www.ananthdeodhar.com/2008/08/05/tar-to-the-rescue#comments</comments>
		<pubDate>Tue, 05 Aug 2008 07:41:57 +0000</pubDate>
		<dc:creator>zooperman</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.ananthdeodhar.com/2008/08/05/tar-to-the-rescue</guid>
		<description><![CDATA[Recently I had to automate a few very VERY redundant tasks on Mac. We have been using PowerGlot &#8211; an application used to localize nib and string resources. The following were the steps which are used to localize any application: Choose the English Resource Folder (which contains nib and string resources) Choose the Target Resource [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I had to automate a few very VERY redundant tasks on Mac. We have been using PowerGlot &#8211; an application used to localize <a title="NIB File" href="http://developer.apple.com/documentation/Carbon/Conceptual/UnarchivingIOwithIBS/ibs_concepts/chapter_2_section_3.html" target="_blank">nib</a> and string resources. The following were the steps which are used to localize any application:</p>
<ul>
<li>Choose the English Resource Folder (which contains nib and string resources)</li>
<li>Choose the Target Resource Folder (where the localized files would be placed)</li>
<li>Give the glossary which has the translations stored in it.</li>
</ul>
<p>I checked out the source code from the CVS repository on my system, and ran the script which finished off the work in a few minutes.</p>
<p>Little did I realize that when the script was placing the nibs in the target folders it overwrote any previous CVS entries inside the nib.</p>
<p>A nib is basically a <a title="Bundle - A directory to group related resources." href="http://en.wikipedia.org/wiki/Bundle_(NEXTSTEP)" target="_blank">Bundle</a> which CVS treats as a simple directory, so when you check in a nib into the repository, CVS will insert its entries inside the nib bundle.</p>
<p>I read many forums to figure out a way to open the bundle using applescript but without any luck. Then on one of the forums I read someone who had faced a similar problem and tar might help.</p>
<p>A few more searches on how to use TAR and sure enough it be my saviour! Just posting the code snippet here for future reference:</p>
<pre>-- tempPath had the localized resources
-- targetPath was the folder inside the CVS repository

do shell script "(cd \"" &amp; tempPath &amp; "\"; tar cf -
* --exclude CVS) | (cd \"" &amp; targetPath &amp; "\"; tar xfp -)"</pre>
<p>&#8220;&#8211;exclude CVS&#8221; option ensures that if any CVS folder exists inside the localized nib data it doesn&#8217;t get copied into the new target folder (which in my case was the actual repository)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ananthdeodhar.com/2008/08/05/tar-to-the-rescue/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
