<?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>Blog of Alexander Mamchenkov &#187; Directory Service</title>
	<atom:link href="http://alex.mamchenkov.net/category/technology/software/directory-service/feed/" rel="self" type="application/rss+xml" />
	<link>http://alex.mamchenkov.net</link>
	<description>... mammoth cave ...</description>
	<lastBuildDate>Wed, 22 Jul 2009 05:30:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>RT3 ActiveDirectory User Attributes Sync</title>
		<link>http://alex.mamchenkov.net/2009/03/14/rt3-activedirectory-user-attributes-sync/</link>
		<comments>http://alex.mamchenkov.net/2009/03/14/rt3-activedirectory-user-attributes-sync/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 10:47:37 +0000</pubDate>
		<dc:creator>Alexander Mamchenkov</dc:creator>
				<category><![CDATA[Directory Service]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://alex.mamchenkov.net/?p=285</guid>
		<description><![CDATA[Ok, here is another small script to deal with RT3 and Active Directory. If you apply the apache LDAP auth described previously to your RT3 installation, you will have no problem getting people logged in, but you will still have to adjust their names and emails. Doing this manually is not the best choice, so [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, here is another small script to deal with RT3 and Active Directory. If you apply the apache <acronym title="Lightweight Directory Access Protocol">LDAP</acronym> auth described previously to your RT3 installation, you will have no problem getting people logged in, but you will still have to adjust their names and emails. Doing this manually is not the best choice, so here is a small script, which can be run from the cron (or manually) to update user info in RT3 according to user attributes in Active Directory:</p>
<pre>
#!/usr/bin/php
< ?php

# Debug flag. Set to non-zero for verbose output
$debug = 0;

# Settings to use while connecting to active directory
$ldap_host = "10.10.10.1"; # AD server
$ldap_user = "someuser@example.com"; # User in AD with read writes
$ldap_pass = "someuser_password"; # Password for the user above
$ldap_base = "dc=example,dc=com"; # AD base to search (recursivly)

# Settings to use while connecting to rt3 MySQL DB
$sql_host = "127.0.0.1"; # MySQL server
$sql_name = "rt3"; # RT3 DB name in MySQL
$sql_user = "rt3_user"; # User to connect to above DB
$sql_pass = "rt3_pass"; # Password for the user above

# Map of RT3 -> AD attributes
$attr_map = array(
	'RealName'		=> 'displayName',
	'EmailAddress'	=> 'mail'
);

# Connect to AD and authenticate
$ldap = ldap_connect($ldap_host);
if (!$ldap) {
	die ("Failed to connect to LDAP server: " . ldap_error() . "\n");
}
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
if (!ldap_bind($ldap,$ldap_user,$ldap_pass)) {
	die ("Failed to bind to LDAP server: " . ldap_error() . "\n");
}

# Connect to MySQL
$sql = mysql_connect($sql_host,$sql_user,$sql_pass);
if (!$sql) {
	die ("Failed to connect to MySQL server: " . mysql_error() . "\n");
}
if (!mysql_select_db($sql_name)) {
	die ("Failed to select MySQL database: " . mysql_error() . "\n");
}

# Get a list of RT3 users from MySQL
$users = get_rt3_users();

# Update attributes for each RT3 user according to AD attributes
foreach ($users as $user) {
	set_rt3_user_info($user,get_ldap_user_attr($user));
}

# Close the connections to MySQL and AD
mysql_close($sql);
ldap_unbind($ldap);

# Gets a list of RT3 users from MySQL
function get_rt3_users () {
	global $sql;

	# Skips the external users (the ones that look like email address)
	$result = mysql_query("SELECT Name FROM Users WHERE Name NOT LIKE '%@%'",$sql);
	$users = array();
	while ($user = mysql_fetch_array($result)) {
		array_push($users,$user[0]);
	}
	return $users;
}

# Gets AD attributes for the given user
function get_ldap_user_attr ($user) {
	global $ldap,$ldap_base,$attr_map,$debug;

	if ($debug) { print "Searching for user $user\n"; }
	$result = ldap_search($ldap,$ldap_base,"(sAMAccountName=$user)");
	$entries = array();
	if ($result) {
		$entries = ldap_get_entries($ldap,$result);
	} else {
		die("Failed to search LDAP: " . ldap_error($ldap) . "\n");
	}
	return $entries;
}

# Updates RT3 user in MySQL with given AD attributes
function set_rt3_user_info ($user,$attr) {
	global $sql,$attr_map;

	# Construct an update SQL query arguments
	$query = "";
	foreach ($attr_map as $k => $v) {

		# Update field only if it is set and non empty
		if (isset($attr[0][strtolower($v)][0]) and $attr[0][strtolower($v)][0] != "") {
			$query .= ",$k='" . mysql_escape_string($attr[0][strtolower($v)][0]) . "'";
		}
	}

	# Run the actual query
	$query = "UPDATE Users SET ".substr($query,1)." WHERE Name='".mysql_escape_string($user)."';";
	mysql_query($query);
}

?>
</pre>
<p>Now each time a new user logs in to RT3 and his username appears in RT3 database, this script will update his/her name and email. You can extend a list of mapped attributes to have more info updated if you want so.</p>]]></content:encoded>
			<wfw:commentRss>http://alex.mamchenkov.net/2009/03/14/rt3-activedirectory-user-attributes-sync/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache MS Active Directory Auth</title>
		<link>http://alex.mamchenkov.net/2009/03/13/apache-activedirectory-auth/</link>
		<comments>http://alex.mamchenkov.net/2009/03/13/apache-activedirectory-auth/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 12:19:33 +0000</pubDate>
		<dc:creator>Alexander Mamchenkov</dc:creator>
				<category><![CDATA[Directory Service]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://alex.mamchenkov.net/?p=284</guid>
		<description><![CDATA[I know there are plenty of methods to apache auth through active directory, but recently I found out that some of them didn&#8217;t work for me or didn&#8217;t do well. The more or less successfull one was perl Apache2::AuthenNTLM, but when you have a lot of users, this one blocks apache now and then and [...]]]></description>
			<content:encoded><![CDATA[<p>I know there are plenty of methods to apache auth through active directory, but recently I found out that some of them didn&#8217;t work for me or didn&#8217;t do well. The more or less successfull one was perl Apache2::AuthenNTLM, but when you have a lot of users, this one blocks apache now and then and causes some real problems.</p>
<p>Like always, found out about apache mod_authnz_external and ended up writing my own authentication script. Here is how to make things work:</p>
<p>First of all download and install mod_authnz_external (google for the package and installation instructions).</p>
<p>Then put the next script somewhere on the apache server (for example /etc/httpd/conf/ad_login.php):</p>
<pre>
< ?php

// AD server IP address
$ldap_host = "10.10.10.1";

// AD Base
$ldap_base = "dc=example,dc=com";

// AD domain
$ldap_domain = "example.com";

// Connect to AD server
$stderr = fopen("php://stderr","w");
$ldap = @ldap_connect($ldap_host);
if (!$ldap) {
	fwrite($stderr,"AD Auth: Failed to connect to $ldap_host\n");
	fclose($stderr);
	exit(1);
}
@ldap_set_option($ldap, LDAP_OPT_PROTOCOLO_VERSION, 3);
@ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);

// Try to login with the supplied username and password
// (using environment to pass the stuff)
if (!@ldap_bind($ldap,$_ENV['USER'] . '@' . $ldap_domain,$_ENV['PASS'])) {
	fwrite($stderr,"AD Auth: Failed to authenticate " . $_ENV['USER'] . "\n");
	fclose($stderr);

	// if failed - exit with 1
	exit(1);
}

ldap_unbind($ldap);
fclose($stderr);

// exit with 0 on success
exit(0);

?>
</pre>
<p>Next, add the following into VirtualHost (or similar) definition in apache config:</p>
<pre>
AddExternalAuth ad "/usr/bin/php -f /etc/httpd/conf/ad_login.php"
SetExternalAuthMethod ad environment

# This can go into Location or Directory sections
AuthType basic
AuthName "My Closed Zone"
AuthBasicProvider external
AuthExternal "ad"
require valid-user
</pre>
<p>Restart apache and you are done.</p>
<p>How does it work? Simple. Each time apache will need to authenticate a user, it will start a script (ad_login.php) and pass it username and password as environment variables. The script, in turn, will try to connect to AD and authenticate itself as given user. If that fails &#8211; login fails, otherwise &#8211; login ok. So basically, if a user has writes to connect to AD, (s)he has write to login to apache.</p>
<p>And of course you can extend the <acronym title="Hypertext PreProcessing">PHP</acronym> script with some extras, like additional checks on username, caching and so on.</p>]]></content:encoded>
			<wfw:commentRss>http://alex.mamchenkov.net/2009/03/13/apache-activedirectory-auth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FreeNX and MS Active Directory</title>
		<link>http://alex.mamchenkov.net/2006/09/14/freenx-and-ms-active-directory/</link>
		<comments>http://alex.mamchenkov.net/2006/09/14/freenx-and-ms-active-directory/#comments</comments>
		<pubDate>Thu, 14 Sep 2006 12:23:11 +0000</pubDate>
		<dc:creator>Alexander Mamchenkov</dc:creator>
				<category><![CDATA[Directory Service]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[NX]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://alex.mamchenkov.net/2006/09/14/freenx-and-ms-active-directory/</guid>
		<description><![CDATA[I have managed to set up FreeNX to work quite smoothly with MS Active Directory authentication. Here are few steps to be done (assuming Fedora Core 5 as a FreeNX server):
1. Make the linux server where FreeNX will be installed an AD member
For this we will need samba and kerberos stuff which are either installed [...]]]></description>
			<content:encoded><![CDATA[<p>I have managed to set up FreeNX to work quite smoothly with <acronym title="Microsoft">MS</acronym> Active Directory authentication. Here are few steps to be done (assuming Fedora Core 5 as a FreeNX server):</p>
<p>1. <strong>Make the linux server where FreeNX will be installed an AD member</strong></p>
<p>For this we will need samba and kerberos stuff which are either installed or easily retrieved with <em>yum.</em> So I will not bother describing on how to get packages :) If some configs mentioned below are missing, then obviously you are missing some packages<br />
In /etc/samba/smb.conf:</p>
<p><code /></p>
<p>[global]<br />
netbios name = myhost<br />
realm = mydomain.int<br />
workgroup = mydomain<br />
security = ADS<br />
password server = pdc.mydomain.int bdc.mydomain.int<br />
socket options = TCP_NODELAY SO_RCVBUF=16384 SO_SNDBUF=16384<br />
idmap uid = 10000-20000<br />
winbind enum users = yes<br />
winbind uid = 10000-20000<br />
winbind gid = 10000-20000<br />
winbind separator = +<br />
winbind use default domain = yes<br />
encrypt passwords = yes<br />
log level = 3 passdb:5 auth:10 winbind:5<br />
template shell = /bin/bash</p>
<p>In /etc/krb5.conf</p>
<p><code /></p>
<p>[libdefaults]<br />
ticket_lifetime = 600<br />
default_realm = mydomain.int<br />
default_tkt_enctypes = des3-hmac-sha1 des-cbc-crc<br />
default_tgs_enctypes = des3-hmac-sha1 des-cbc-crc<br />
dns_lookup_realm = false<br />
dns_lookup_kdc = false</p>
<p>[realms]<br />
mydomain.int = {<br />
kdc = pdc.mydomain.int:88<br />
kdc = bdc.mydomain.int:88<br />
admin_server = pdc.mydomain.int:749<br />
default_domain = mydomain.int<br />
}</p>
<p>[domain_realm]<br />
.mydomain.int = pdc.mydomain.int<br />
mydomain.int = pdc.mydomain.int</p>
<p>[kdc]<br />
profile = /etc/krb5kdc/kdc.conf</p>
<p>[logging]<br />
kdc = FILE:/var/log/krb5kdc.log<br />
admin_server = FILE:/var/log/kadmin.log<br />
default = FILE:/var/log/krb5lib.log</p>
<p>This is enough to be a member of AD. Just make sure that smbd and winbindd are running. To join the domain, use <em>net join ads </em>command with required options (see <em>net help join</em> for more info)</p>
<p>2. <strong>Make domain users be able to login to linux server with <acronym title="Secure SHell (encrypted protocol replaces telnet and FTP)">SSH</acronym></strong></p>
<p>I suppose there are many ways to do this, but I went with modifying the <em>/etc/pam.d/ssh</em> the next way</p>
<p><code /></p>
<p>#%PAM-1.0<br />
#auth       include      system-auth<br />
#account    required     pam_nologin.so<br />
#account    include      system-auth<br />
#password   include      system-auth</p>
<p>auth    required    /lib/security/pam_securetty.so<br />
auth    required          /lib/security/pam_nologin.so<br />
auth    sufficient  /lib/security/pam_winbind.so<br />
auth    required    /lib/security/pam_unix.so use_first_pass shadow nullok<br />
account sufficient /lib/security/pam_winbind.so<br />
account    required     pam_nologin.so<br />
account    include      system-auth<br />
session    include      system-auth<br />
session    required     pam_loginuid.so</p>
<p>and now make system look for AD users by modifying the <em>/etc/nsswitch.conf </em>to contain the next lines:</p>
<p><code /></p>
<p>passwd:     files winbind<br />
shadow:     files<br />
group:      files winbind</p>
<p>#hosts:     db files nisplus nis <acronym title="Domain Name System">DNS</acronym><br />
hosts:      files <acronym title="Domain Name System">DNS</acronym> winbind<br />
From now on the system will allow domain users to login with <acronym title="Secure SHell (encrypted protocol replaces telnet and FTP)">SSH</acronym>.</p>
<p>3. <strong>Make it work</strong></p>
<p>Now just install freenx:</p>
<p><em># yum install freenx</em></p>
<p>Optionally make it work with default nomachine keys (so that clients will have less configurations to do) by reconfiguring freenx: <em /></p>
<p><em># nxsetup --override --install --setup-nomachine-key --clean --purge</em>)</p>
<p>start nxserver</p>
<p># <em>nxserver --start</em></p>
<p>create home for desired domain users</p>
<p># mkdir /home/mydomain/myusername</p>
<p>and finally allow the user to use FreeNX</p>
<p># nxserver --adduser mydomain+myusername</p>
<p>4. <strong>Troubleshooting</strong><br />
All problems are seen in log files under <em>/var/log</em></p>
<p>5. <strong>Other benefits</strong></p>
<p>The way the samba is configured now, it is very easy to add SQUID with NTLM auth ;) If you are interested in this - just let me know in the comments - I will post the samples of config files.</p>]]></content:encoded>
			<wfw:commentRss>http://alex.mamchenkov.net/2006/09/14/freenx-and-ms-active-directory/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Things missing in Linux</title>
		<link>http://alex.mamchenkov.net/2005/06/21/things-missing-in-linux/</link>
		<comments>http://alex.mamchenkov.net/2005/06/21/things-missing-in-linux/#comments</comments>
		<pubDate>Tue, 21 Jun 2005 10:26:53 +0000</pubDate>
		<dc:creator>Alexander Mamchenkov</dc:creator>
				<category><![CDATA[Directory Service]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MS Exchange]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://alex.mamtchenkov.net/2005/06/21/things-missing-in-linux/</guid>
		<description><![CDATA[For the past few months I&#8217;ve been working a lot with Linux and M$ in parallels and most of the times I was migrating different things from M$ to Linux. During this months I realized why so many people are still stick to M$.
The idea is that it is true that you can replace any [...]]]></description>
			<content:encoded><![CDATA[<p>For the past few months I&#8217;ve been working a lot with Linux and M$ in parallels and most of the times I was migrating different things from M$ to Linux. During this months I realized why so many people are still stick to M$.</p>
<p>The idea is that it is true that you can replace any functionality of M$ by Linux including servers/desktops/terminals and whatever but the problem is that it is still a bit hard to set up a replacement since there is a lack of <acronym title="Graphical User Interface">GUI</acronym> (kind of easy usable configuration tools) and all the software comes from different vendors what makes it a bit hard setting it to work together.</p>
<p>For instance, let&#8217;s take the combination of Active Directory + Domain + M$ Exchange: it provides a directory server with all those easy administration, data replication and whatever else, plus the whole collaboration package from M$ Exchange. It is known that Active Directory can be replaced with OpenLDAP, Domain can be [almost fully] handled by Samba and M$ Exchange can be replaced by putting together MTA, <acronym title="Internet Message Access Protocol">IMAP</acronym>, <acronym title="Short for POP3, the Post Office Protocol for email">POP</acronym> and whatever else required. All of the applications can work with OpenLDAP to have a centralized username/passwords and other stuff and it seems that the whole combination is replaced, but not. Have you ever tried butting all of these together? If yes &#8211; how long did it take you and finally &#8211; how easy is it to administrate? I mean if there is a common place [ok - two] where you can go to do any tasks related to the package above?</p>
<p>I know, there is a major plus in Linux way &#8211; a matter of choice. You can choose an MTA you like (Sendmail, Exim, Postfix, Courier, whatever) as well as any <acronym title="Internet Message Access Protocol">IMAP</acronym>, <acronym title="Short for POP3, the Post Office Protocol for email">POP</acronym>, and even <acronym title="Lightweight Directory Access Protocol">LDAP</acronym> server can vary from OpenLDAP to Netscap Directory Server or new RedHat/Fedora Directory Server of similar SuSE product. This is what you will never get with M$. But on the other hand it still kinda difficult to set it up and even more difficult to watch it afterwards.</p>
<p>Of course there were some attempts to create some kind of centralized panels for administration [like Webmin or even linuxconf tool] but they all suck at some points. The major problem with them [from my point of view] is that they are modular and different modules are contributed by different people and most of the time there is a problem with compatibility.</p>
<p>The whole post above is not to tell that M$ is better that Linux [although in some cases it might be] but to try and figure out what is missing in Linux to make it easier for people to get used to it.</p>
<p>As an example to confirm the above I would describe the next situation: a while ago a was setting up a simple Linux firewall with a bunch of network services that I usually add to these kind of boxes like [iptables, squid, dhcp, caching <acronym title="Domain Name System">DNS</acronym> and some others] and a guy, who asked me to make this installation was very upset since he can not control this box in a comfortable way (lets say using web interface to have a centralized administration) and the only way for him to change something in the settings was to either call me to <acronym title="Secure SHell (encrypted protocol replaces telnet and FTP)">SSH</acronym> to the box and re-configure it or use a bunch of small tools that left him each for changing different settings.</p>]]></content:encoded>
			<wfw:commentRss>http://alex.mamchenkov.net/2005/06/21/things-missing-in-linux/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Fedora Directory Server (part 3)</title>
		<link>http://alex.mamchenkov.net/2005/06/06/fedora-directory-server-part-3/</link>
		<comments>http://alex.mamchenkov.net/2005/06/06/fedora-directory-server-part-3/#comments</comments>
		<pubDate>Mon, 06 Jun 2005 07:23:26 +0000</pubDate>
		<dc:creator>Alexander Mamchenkov</dc:creator>
				<category><![CDATA[Directory Service]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://alex.mamtchenkov.net/2005/06/06/fedora-directory-server-part-3/</guid>
		<description><![CDATA[Ok, lets continue with the Fedora Directory Server.
First of all I have some screenshots. They do not cover the whole GUI but instead show main windows and tabs and some dialogs.
Second: while reading the docs I found out not only that the directory feels good with import/export of LDIF (I have tried with standard OpenLDAP [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, lets continue with the Fedora Directory Server.</p>
<p>First of all I have <a href="http://alex.mamtchenkov.net/wp-images/custom/fedora_directory_server/">some screenshots</a>. They do not cover the whole <acronym title="Graphical User Interface">GUI</acronym> but instead show main windows and tabs and some dialogs.</p>
<p>Second: while reading the docs I found out not only that the directory feels good with import/export of LDIF (I have tried with standard OpenLDAP migration tools) but can also syncronize with M$ Active Directory and (EVEN) with M$ NT4 Domain PDC (for user/group information). This seems to be cool since I know that even M$ Active Directory has some problems communicating with NT4.</p>
<p>I have tried to set up <acronym title="Secure Sockets Layer (a security protocol)">SSL</acronym> with self singed certificates and found out that there is a whole chapter in the docs describing how to do it and a couple of tools/scripts are provided with the installation to help with generation of the certificates. All the management of the certificates can be easily done through <acronym title="Graphical User Interface">GUI</acronym>.</p>
<p>I would also like to note that although I ignored a message of low RAM on my machine (128MB) during the installation &#8211; everything works fast and good.</p>]]></content:encoded>
			<wfw:commentRss>http://alex.mamchenkov.net/2005/06/06/fedora-directory-server-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
