<?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>Monty Program Group Blog</title>
	<atom:link href="http://blog.montyprogram.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.montyprogram.com</link>
	<description></description>
	<lastBuildDate>Thu, 02 Feb 2012 16:21:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Screencast: Installing MariaDB</title>
		<link>http://blog.montyprogram.com/screencast-installing-mariadb/</link>
		<comments>http://blog.montyprogram.com/screencast-installing-mariadb/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 22:17:38 +0000</pubDate>
		<dc:creator>Daniel Bartholomew</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[screencast]]></category>

		<guid isPermaLink="false">http://blog.montyprogram.com/?p=851</guid>
		<description><![CDATA[Instead of the usual text-heavy blog posts that appear here, I thought it would be fun to mix things up and do a screencast showing exactly how easy it is to upgrade MySQL to MariaDB: Some notes: The laptop I&#8217;m &#8230; <a href="http://blog.montyprogram.com/screencast-installing-mariadb/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Instead of the usual text-heavy blog posts that appear here, I thought it would be fun to mix things up and do a screencast showing exactly how easy it is to upgrade MySQL to MariaDB:</p>
<iframe width="640" height="385" src="http://www.youtube.com/embed/rF7wChx0uzQ" frameborder="0" type="text/html"></iframe>
<h3>Some notes:</h3>
<ul>
<li>The laptop I&#8217;m using had MySQL 5.1.55 installed with one database (apart from the system database). Installing MariaDB does not impact existing data in any way and once the install completed I had instant access to my data.</li>
<li>As part of the install you are given the option to set a new password for the root user. I choose to do it in the video, but you don&#8217;t need to. If you leave the password field blank the root password will not be changed. Other database users are preserved, of course.</li>
<li>As with any database upgrade, before doing this to a production system you should have backups and test.</li>
</ul>
<h3>Links:</h3>
<p>Links shown or mentioned in the video:</p>
<ul>
<li><a href="http://kb.askmonty.org/en/installing-mariadb-deb-files">http://kb.askmonty.org/en/installing-mariadb-deb-files</a></li>
<li><a href="http://downloads.askmonty.org/mariadb/">http://downloads.askmonty.org/mariadb/</a></li>
<li><a href="http://downloads.askmonty.org/mariadb/repositories/">http://downloads.askmonty.org/mariadb/repositories/</a></li>
<li>and of course: <a href="http://mariadb.org/">http://mariadb.org/</a></li>
</ul>
<h3>Comments?</h3>
<p>What do you think? Should we make more screencasts? If so, what would you like to see demonstrated?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.montyprogram.com/screencast-installing-mariadb/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Oracle’s 27 MySQL security fixes and MariaDB</title>
		<link>http://blog.montyprogram.com/oracles-27-mysql-security-fixes-and-mariadb/</link>
		<comments>http://blog.montyprogram.com/oracles-27-mysql-security-fixes-and-mariadb/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 21:24:08 +0000</pubDate>
		<dc:creator>rasmus</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.montyprogram.com/?p=809</guid>
		<description><![CDATA[The MySQL community has something new on their radar. First up, it looks like MySQL is now part of Oracle Software Security Assurance, and this is something all MySQL users should be happy about. Next, it is worth noting that &#8230; <a href="http://blog.montyprogram.com/oracles-27-mysql-security-fixes-and-mariadb/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The MySQL community has something new on their radar. First up, it looks like MySQL is now part of <a href="http://www.oracle.com/us/support/assurance/index.html" title="Oracle Software Security Assurance" target="_blank">Oracle Software Security Assurance</a>, and this is something all MySQL users should be happy about. Next, it is worth noting that MySQL is now part of the Oracle Critical Patch Update (Oracle CPU), as the MySQL product line has made it into its first <a href="http://www.oracle.com/technetwork/topics/security/cpujan2012-366304.html" title="Oracle CPU advisory for January 2012" target="_blank">Oracle CPU advisory for January 2012</a>.</p>
<p>As part of the MySQL community, CPU’s are new to us &mdash; they are released on the Tuesday closest to the 17th day of January, April, July and October. This kind of reminds us of <a href="http://en.wikipedia.org/wiki/Patch_Tuesday" title="Patch Tuesday" target="_blank">Patch Tuesday</a>, but let’s not digress.</p>
<p>This is the first time MySQL is part of the Critical Patch Update, and the advisory suggests that there are 27 new security fixes for Oracle MySQL, with one of the vulnerabilities having the possibility of remote exploitation without authentication. As developers of a MySQL branch we are naturally concerned towards the nature of these CPU’s.</p>
<p>For starters, it’s good to note that MariaDB is always based from a branch of MySQL (MySQL 5.1 for MariaDB 5.1, 5.2 &amp; 5.3, and MySQL 5.5 for MariaDB 5.5).  So whenever there are security fixes which Oracle makes into MySQL 5.1 or MySQL 5.5, we inherit them. This is one of the benefits of being a branch as opposed to being a fork.</p>
<p>“Oracle advisories include all issues that appeared since the last advisory. But this is the first advisory for MySQL. So either Oracle found 27 new problems since October 2011 or this includes everything that’s been outstanding,” said Sergei Golubchik, VP of Architecture for MariaDB and former MySQL security contact when I asked him about the 27 security fixes.</p>
<p>Upon looking up all the CVE numbers, the reports were vague, like “Unspecified vulnerability in the MySQL Server component in Oracle MySQL 5.1.x and 5.5.x allows remote attackers to affect availability via unknown vectors.” Additionally, the reports do not reference bug numbers, so from a bit of guesswork, we might assume that <a href="http://bazaar.launchpad.net/~mysql/mysql-server/5.1/revision/3560.1.3">this commit</a> is possibly the fix for the most serious vulnerability &mdash; the one that can be remotely exploited without authentication. That bug, incidentally, was fixed in May 2011, and has long been present in both MySQL and MariaDB (though our implementation varies from upstream).</p>
<p>We notice most CVEs being reported in January 2012, but have no idea when they were reported to the Oracle bug database (or to bugs.mysql.com), or when they were fixed. We believe that this is perhaps Oracle including MySQL into their Software Security Assurance program, which is what triggered all security bugs to be reported on cve.mitre.org, all on the same day.</p>
<p>Whether these 27 fixes are new or existing ones now being bundled up and reported in a Critical Patch Update remains open until more accurate information on what bugs they address is provided. We’re actively working on finding out the answer.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.montyprogram.com/oracles-27-mysql-security-fixes-and-mariadb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MariaDB: Improve Security with Two-Step Verification</title>
		<link>http://blog.montyprogram.com/security-with-two-step-verification/</link>
		<comments>http://blog.montyprogram.com/security-with-two-step-verification/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 14:07:17 +0000</pubDate>
		<dc:creator>Sergei</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Stories]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[two step verification]]></category>

		<guid isPermaLink="false">http://blog.montyprogram.com/?p=754</guid>
		<description><![CDATA[In this primer I will show how to improve the security of your MariaDB installation by using two-step verification and how to use it from your Windows GUI client. Let&#8217;s suppose you have your data in MariaDB, installed, say, on &#8230; <a href="http://blog.montyprogram.com/security-with-two-step-verification/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In this primer I will show how to improve the security of your MariaDB installation by using <strong>two-step verification</strong> and how to use it from your Windows GUI client.</p>
<p>Let&#8217;s suppose you have your data in MariaDB, installed, say, on Ubuntu. And your users connect to it to run ad hoc queries, using some sort of a Windows GUI client. You don&#8217;t want them to write the access password on post-it notes or have it auto-entered by the client. And you don&#8217;t want anyone see the password when one of the salespersons connects to the mother ship from his laptop in the Internet café. So you decide to use the two-step verification, just like Google does, to secure the access to the data.</p>
<p><span id="more-754"></span></p>
<p>If you don&#8217;t know what a &#8220;two-step verification&#8221; is, see, for example, this introductory <a href="http://www.youtube.com/watch?v=zMabEyrtPRg">video</a> by Google.</p>
<p>So, 2-step verification looks great, but how can we implement it? Luckily, there is a PAM module in the <a href="http://code.google.com/p/google-authenticator/">Google Authenticator</a> project, and we can use it with a MariaDB <a title="Writing a MariaDB PAM Authentication Plugin" href="http://blog.montyprogram.com/writing-a-mariadb-pam-authentication-plugin/">PAM authentication plugin</a>.</p>
<p>Let me digress for a second. Below we will implement a 2-step verification based on Google Authenticator. But you may want to evaluate other similar solutions before putting this primer in production. There are quite a few PAM modules implementing one-time password approach (and <em>pam_google_authenticator</em> is just one of them). In particular, OPIE (and S/Key) look interesting, because they don&#8217;t require a valid Unix account and a home directory for every user. There are also hardware based solutions, where a user is required to have a small password generating device (like, for example, RSA SecurID).</p>
<p>But back to Google Authenticator. First, we need to install the PAM module. On Ubuntu 11.10 it is very simple: <a href="http://tombuntu.com/index.php/2011/10/16/google-authenticator-pam-available-in-ubuntu-11-10/">one apt-get</a>. On distributions that don&#8217;t include it (and older Ubuntu versions), you can use <a href="http://guides.webbynode.com/articles/security/ubuntu-google-authenticator.html">manual installation instructions</a>.</p>
<p>Either way, we install <code>/lib/security/pam_google_authenticator.so</code> (I don&#8217;t have Ubuntu 11.10, so I had to do it manually). For a 2-step verification we need to require both the <strong></strong>normal account password and the one-time code. This can be achieved with the following PAM configuration file:</p>
<pre>auth            required        pam_unix.so
auth            required        pam_google_authenticator.so
account         required        pam_unix.so</pre>
<p>I had to put it in <code>/etc/pam.d/mysql</code> file, on your system the location may be different. Having done that, let&#8217;s install the MariaDB PAM plugin and create the user account:</p>
<p><img class="size-full wp-image-737 alignnone" style="border: 0pt none;" title="MariaDB PAM setup" src="http://blog.montyprogram.com/wp-content/uploads/2012/01/xterm-1.png" alt="" width="520" height="329" /></p>
<p>Now we need to configure Google Authenticator for an account:</p>
<p><img class="alignnone  wp-image-771" style="border: 0pt none;" title="Google Authenticator Setup" src="http://blog.montyprogram.com/wp-content/uploads/2012/01/xterm-21.png" alt="" width="520" height="686" /></p>
<p>Time to install a password generator application. There are versions for <a href="http://market.android.com/details?id=com.google.android.apps.authenticator">Android</a>, <a href="http://itunes.apple.com/us/app/google-authenticator/id388497605?mt=8">iOS</a>, and Blackberry. Google explains <a title="Installing Google Authenticator " href="http://support.google.com/accounts/bin/answer.py?hl=en&amp;answer=1066447">the details</a>. When the installation is finished, start the application and enter the secret key into it — manually or using the QR-code. And we&#8217;re done and can use two-step verification when connecting to MariaDB. But our users use Windows! How will it play along?</p>
<p>The answer depends on the Windows MariaDB client that that your users have. At the moment of writing this article, only <a title="HeidiSQL in KB" href="http://kb.askmonty.org/en/heidisql">HeidiSQL</a> has full support for pluggable authentication. You may already have it installed — HeidiSQL is part of <a title="Dowload MariaDB 5.3 for Windows" href="http://downloads.askmonty.org/mariadb/5.3/#os_group=windows">MariaDB Windows distribution</a>. Alternatively, you can download it directly from the <a title="Download HeidiSQL" href="http://www.heidisql.com/download.php">official site</a>.</p>
<p>First, we use HeidiSQL session manager to configure the connection parameters. Here, we will connect as the user &#8220;serg&#8221; — the  user, that we have created above to use the PAM authentication plugin. Note that there is no special configuration for pluggable authentication on the client, it is enabled automatically when necessary.</p>
<p><a href="http://blog.montyprogram.com/wp-content/uploads/2012/01/win-1.png"><img class="alignnone size-full wp-image-786" style="border: 0pt none;" title="HeidiSQL Session Manager" src="http://blog.montyprogram.com/wp-content/uploads/2012/01/win-1.png" alt="" width="503" height="378" /></a></p>
<p>Now we can connect to the server. It uses PAM authentication plugin, that loads Google Authenticator, that asks for a verification code. And we see HeidiSQL asking:</p>
<p><img class="alignnone size-full wp-image-734" style="border: 0pt none;" title="Google Authenticator Input Dialog" src="http://blog.montyprogram.com/wp-content/uploads/2012/01/win-2.png" alt="" width="504" height="377" /></p>
<p>We start the Authenticator application, it generates the verification code:</p>
<p><img class="alignnone size-full wp-image-732" style="border: 0pt none;" title="Android Authenticator App" src="http://blog.montyprogram.com/wp-content/uploads/2012/01/handy-2.png" alt="" width="512" height="272" /></p>
<p>And we use it to login! Next time the verification code will be different, and nobody looking over the shoulder will be able to steal our precious connection password.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.montyprogram.com/security-with-two-step-verification/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wrapping up MariaDB 2011</title>
		<link>http://blog.montyprogram.com/wrapping-up-mariadb-2011/</link>
		<comments>http://blog.montyprogram.com/wrapping-up-mariadb-2011/#comments</comments>
		<pubDate>Sat, 24 Dec 2011 15:42:41 +0000</pubDate>
		<dc:creator>rasmus</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[GIS]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[subqueries]]></category>

		<guid isPermaLink="false">https://blog.montyprogram.com/?p=727</guid>
		<description><![CDATA[Parts of the world are already celebrating Christmas Eve and it&#8217;s time to relax and spend time with family and friends. Even if you don&#8217;t celebrate Christmas this is when there is time for less work. Here are a few &#8230; <a href="http://blog.montyprogram.com/wrapping-up-mariadb-2011/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Parts of the world are already celebrating Christmas Eve and it&#8217;s time to relax and spend time with family and friends. Even if you don&#8217;t celebrate Christmas this is when there is time for less work. Here are a few words to round off MariaDB&#8217;s current state and where it&#8217;s heading.</p>
<p>This year culminated in MariaDB 5.3.3, the release candidate of 5.3. This is a significant release that makes years of work available by default in the database server. Earlier releases still required features to be explicitly switched on, but thanks to thorough testing assuring the quality of the new functionality we have now enabled them. It&#8217;s still called a release candidate which means it&#8217;s ready for general usage, but we want more user feedback before calling it stable. Make yourself familiar with the <a href="http://kb.askmonty.org/en/mariadb-533-release-notes">MariaDB 5.3.3 release notes</a>. </p>
<p>Most of the new features and functionality of 5.3.3 are performance related making it possible to suddenly e.g. make use of subqueries, which previously has been a rare sight in MySQL® based applications due to the limitations that has existed. This is now addressed in MariaDB and we encourage you to start using subqueries. You will actually get a result to your query in a reasonable time.</p>
<p>Another nice addition in 5.3.3 is the new GIS (Geographic Information System) functionality. MariaDB introduces spatial functionality in accordance with the OpenGIS specification. If you have the need for <a href="http://kb.askmonty.org/en/gis-features-in-533">GIS functionality</a> in your application try MariaDB. </p>
<p>We had some challenges with the packaging of the authentication plugins and our release schedule was affected. Watch out for MariaDB 5.2.11 and MariaDB 5.5 in early 2012.</p>
<p>During 2011 we saw a huge increase in MariaDB popularity. We saw MariaDB being selected as the database for really critical systems (stay tuned for case studies of some of these systems). We saw some of the biggest IT companies making initial bets on MariaDB. A better basis for MariaDB&#8217;s 2012 couldn&#8217;t exist!</p>
<p>Thank You and Happy Holidays!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.montyprogram.com/wrapping-up-mariadb-2011/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Announcing new features in MariaDB</title>
		<link>http://blog.montyprogram.com/announcing-new-features-in-mariadb/</link>
		<comments>http://blog.montyprogram.com/announcing-new-features-in-mariadb/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 19:45:00 +0000</pubDate>
		<dc:creator>rasmus</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PAM]]></category>
		<category><![CDATA[thread pool]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://askmonty.org/blog/?p=721</guid>
		<description><![CDATA[We have lately been talking about some upcoming features that we feel are important to MariaDB users, because the corresponding ones that will be provided with MySQL will be incompatible with MariaDB and closed source. We&#8217;re happy to announce the following: The &#8230; <a href="http://blog.montyprogram.com/announcing-new-features-in-mariadb/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We have lately been talking about some upcoming features that we feel are important to MariaDB users, because the corresponding ones that will be provided with MySQL will be incompatible with MariaDB and closed source.</p>
<p>We&#8217;re happy to announce the following:</p>
<ul>
<li>The next version of MariaDB, version 5.2.10 will include an open source <a href="http://kb.askmonty.org/en/pam-authentication-plugin">PAM Authentication Plugin</a>. MariaDB 5.2.10 is scheduled for release next week.</li>
<li>A Windows Authentication Plugin is in development and QA currently and will be part of MariaDB 5.2.11, which is scheduled for release before Christmas.</li>
<li>MariaDB 5.5 will include both of the above plugins and an open source thread pool implementation. The soon-to-be-launched first version however will not include the thread pool.</li>
</ul>
<p>Stay tuned for more information as soon as we start launching the above features.</p>
<p>Mission critical services relying on MariaDB should be aware that <a title="SkySQL" href="http://www.skysql.com/">SkySQL</a> has familiarized themselves with the new features and are ready to support all of the above options.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.montyprogram.com/announcing-new-features-in-mariadb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Writing a MariaDB PAM Authentication Plugin</title>
		<link>http://blog.montyprogram.com/writing-a-mariadb-pam-authentication-plugin/</link>
		<comments>http://blog.montyprogram.com/writing-a-mariadb-pam-authentication-plugin/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 22:39:35 +0000</pubDate>
		<dc:creator>Sergei</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PAM]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://askmonty.org/blog/?p=617</guid>
		<description><![CDATA[As you may know, since version 5.2.0 (released in April 2010) we support Pluggable Authentication. Using this feature one can implement an arbitrary user authentication and account management policy, completely replacing built-in MariaDB authentication with its username/password combination and mysql.user &#8230; <a href="http://blog.montyprogram.com/writing-a-mariadb-pam-authentication-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As you may know, since version 5.2.0 (released in April 2010) we support <a title="Pluggable Authentication in the KnowledgeBase" href="http://kb.askmonty.org/en/pluggable-authentication">Pluggable Authentication</a>. Using this feature one can implement an arbitrary user authentication and account management policy, completely replacing built-in MariaDB authentication with its username/password combination and <code>mysql.user</code> table.</p>
<p>Also, as you might have heard, Oracle has recently released a <em>PAM authentication plugin</em> for MySQL. Alas, this plugin will not run on MariaDB — although the MySQL implementation of pluggable authentication is based on ours, the API is incompatible. And, being closed source, this plugin cannot be fixed to run in MariaDB. And — I&#8217;m not making it up — this plugin does not support communication between the client and the server, so even with this plugin and all the power of PAM the only possible authentication method remains a simple username/password combination.</p>
<p>But writing authentication plugins is easy, I said to myself. I will do my own authentication plugin! With blackjack and hookers.</p>
<p><span id="more-617"></span></p>
<p>I started by installing the development headers:</p>
<blockquote><p><code> $ <strong>sudo rpm -ivh MariaDB-devel-5.2.9-102.el5.x86_64.rpm</strong></code></p></blockquote>
<p>On Debian or Ubuntu you would&#8217;ve needed to install <code>libmariadbclient-dev</code>. By the way, a disclaimer — I&#8217;m doing it for MariaDB-5.2, but with minimal changes this plugin can work with MySQL-5.5 too.</p>
<p>Now I create a working directory and, being a lazy guy, copy the <strong>auth_socket</strong> plugin  sources — one of the authentication plugins that come with MariaDB — from Launchpad (only <a href="http://bazaar.launchpad.net/~maria-captains/maria/5.2/files/head:/plugin/auth/">auth_socket.c</a>). Stripped down, with the old code removed, it becomes my <code>pam.c</code>:</p>
<style type="text/css">
<!--
.Special { color: #6a5acd; }
.Comment { color: #0000ff; }
.Statement { color: #a52a2a; font-weight: bold; }
.Type { color: #2e8b57; font-weight: bold; }
.Constant { color: #ff00ff; }
.PreProc { color: #a020f0; }
-->
</style>
<pre style="border: 1px solid black; padding:2px">
<span class="PreProc">#define MYSQL_DYNAMIC_PLUGIN</span>
<span class="PreProc">#include </span><span class="Constant">&lt;mysql/plugin_auth.h&gt;</span>

<span class="Type">static</span> <span class="Type">int</span> pam_auth(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
{
}

<span class="Type">static</span> <span class="Type">struct</span> st_mysql_auth pam_info =
{
  MYSQL_AUTHENTICATION_INTERFACE_VERSION,
  <span class="Constant">"dialog"</span>,
  pam_auth
};

mysql_declare_plugin(pam)
{
  MYSQL_AUTHENTICATION_PLUGIN,
  &amp;pam_info,
  <span class="Constant">&quot;pam&quot;</span>,
  <span class="Constant">&quot;Sergei Golubchik&quot;</span>,
  <span class="Constant">&quot;PAM based authentication&quot;</span>,
  PLUGIN_LICENSE_GPL,
  <span class="Constant">NULL</span>,
  <span class="Constant">NULL</span>,
  <span class="Constant">0x0100</span>,
  <span class="Constant">NULL</span>,
  <span class="Constant">NULL</span>,
  <span class="Constant">NULL</span>
}
mysql_declare_plugin_end;
</pre>
<p>At the end of the file we have the plugin descriptor — it always has the same structure for all plugin types. Above it — authentication plugin descriptor, it tells MariaDB which function performs the actual authentication, and what plugin the client should use.</p>
<p>Let me repeat — what plugin the <em>client</em> should use. Indeed, an authentication process is always a dialog. The server asks questions (&#8220;username?&#8221;, &#8220;password?&#8221;), the client answers them. Because a loadable plugin may cause the server to ask the most unexpected questions (&#8220;the fingerprint of the left index finger?&#8221;), the client should support plugins too — which know how to answer them. And it does support them — or, more precisely, <strong>libmysqlclient</strong> does, automatically and transparently for the client applications.</p>
<p>In this particular case, though, the questions aren&#8217;t very exotic. PAM may only ask the end user to enter some text, so the client plugin needs to be able to print prompt text, read the user&#8217;s input, and send it back to the server. And repeat until the server is satisfied. Luckily, MariaDB already has a plugin to perform such a dialog with the user. The plugin is called, not surprisingly, <strong>dialog</strong>, and in my plugin descriptor, I specify that the <strong>pam</strong> server plugin needs the client to load the <strong>dialog</strong> plugin to be able to continue the authentication.</p>
<p>Now, let&#8217;s see if this plugin skeleton works:</p>
<blockquote><p><code> $ <strong>gcc -o pam.so pam.c `mysql_config --cflags` -shared -fPIC -lpam</strong></code></p></blockquote>
<p>It compiles and even loads into the server. Looks good so far, and I open <strong>man pam</strong>.</p>
<p>According to the man pages, to perform a PAM authentication one needs to do the following:</p>
<ol>
<li>initialize the PAM subsystem with the <code>pam_start()</code> function.</li>
<li>invoke <code>pam_authenticate()</code> which performs the actual authentication</li>
<li>verify the user&#8217;s account with the <code>pam_acct_mgmt()</code></li>
<li>in the process of authentication, PAM can change the user name. Retrieve the new name with <code>pam_get_item(PAM_USER)</code></li>
<li>at the end one should always call <code>pam_end()</code></li>
</ol>
<p>To talk to the client, PAM allows one to specify a <em>conversation function</em> — the function that PAM will invoke as necessary.</p>
<p>I then put the above logic into the main <code>pam_auth()</code> function:</p>
<pre style="border: 1px solid black; padding:2px">
<span class="PreProc">#include </span><span class="Constant">&lt;string.h&gt;</span>
<span class="PreProc">#include </span><span class="Constant">&lt;security/pam_modules.h&gt;</span>
<span class="PreProc">#include </span><span class="Constant">&lt;security/pam_appl.h&gt;</span>

<span class="Type">static</span> <span class="Type">int</span> conv(<span class="Type">int</span> n, <span class="Type">const</span> <span class="Type">struct</span> pam_message **msg,
                <span class="Type">struct</span> pam_response **resp, <span class="Type">void</span> *data)
{
}

<span class="PreProc">#define DO(X) </span><span class="Statement">if</span><span class="PreProc"> ((status = (X)) != PAM_SUCCESS) </span><span class="Statement">goto</span><span class="PreProc"> end</span>

<span class="Type">static</span> <span class="Type">int</span> pam_auth(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
{
  pam_handle_t *pamh = <span class="Constant">NULL</span>;
  <span class="Type">int</span> status;
  <span class="Type">const</span> <span class="Type">char</span> *new_username;
  <span class="Type">struct</span> param param;
  <span class="Type">struct</span> pam_conv c = { &amp;conv, &amp;param };

  <span class="Comment">/*</span><span class="Comment"> get the service name, as specified in</span>

<span class="Comment">     CREATE USER ... IDENTIFIED WITH pam_auth AS  &quot;service&quot;</span>

<span class="Comment">  </span><span class="Comment">*/</span>
  <span class="Type">const</span> <span class="Type">char</span> *service = info-&gt;auth_string ? info-&gt;auth_string : <span class="Constant">&quot;mysql&quot;</span>;

  param.ptr = param.buf + <span class="Constant">1</span>;
  param.vio = vio;

  DO( pam_start(service, info-&gt;user_name, &amp;c, &amp;pamh) );
  DO( pam_authenticate (pamh, <span class="Constant">0</span>) );
  DO( pam_acct_mgmt(pamh, <span class="Constant">0</span>) );
  DO( pam_get_item(pamh, PAM_USER, (<span class="Type">const</span> <span class="Type">void</span>**)&amp;new_username) );

  <span class="Statement">if</span> (new_username)
    strncpy(info-&gt;authenticated_as, new_username,
            <span class="Statement">sizeof</span>(info-&gt;authenticated_as));

<span class="Statement">end</span>:
  pam_end(pamh, status);
  <span class="Statement">return</span> status == PAM_SUCCESS ? CR_OK : CR_ERROR;
}
</pre>
<p>The plugin is almost done. The only missing bit is the conversation function <code>conv()</code>. According to the PAM documentation, it will be invoked with an array of &#8220;questions&#8221;, which should be shown to the user, and it must return the user&#8217;s answers. Additionally, it will get one opaque pointer argument — callback functions almost always have it in almost all the APIs in the world. From this function I will send the &#8220;questions&#8221; to the client, and receive the answers. The <strong>dialog</strong> plugin on the client side will do the actual communication with the user.</p>
<p>Sending and receiving is easy in the Pluggable Authentication API. One of the arguments of the main authentication function — <code>pam_auth()</code> in our case — is a so called <strong>vio</strong> handle. This handle provides <code>read_packet()</code> and <code>write_packet()</code> functions, which the client and server plugins can use to communicate with each other. The server will take care of everything else — delivering packets, splitting and reassembling them, encrypting (if SSL is used), using unix sockets, tcp/ip, named pipes, shared memory, making sure that the server plugin talks to the right client plugin, maintaining backward compatible protocol on the wire, and so on. That&#8217;s, by the way, where the name <strong>vio</strong> comes from — it means Virtual I/O.</p>
<p>There is one last difficulty to overcome. PAM can send four different types of messages, two of them being purely informational, with the meaning &#8220;print this to the user&#8221;, and two being input messages, with the meaning &#8220;print this and read the reply&#8221;. The <strong>dialog</strong> plugin, however, supports only &#8220;print this and read the reply&#8221; kinds of actions. To solve this API mismatch, our conversation function will accumulate PAM informational messages until it sees the first input message. Then it&#8217;ll send all accumulated and concatenated messages to the <strong>dialog</strong> plugin as one big prompt string, in one packet. This is what I mean:</p>
<pre style="border: 1px solid black; padding:2px">
<span class="Type">struct</span> param {
  <span class="Type">unsigned</span> <span class="Type">char</span> buf[<span class="Constant">10240</span>], *ptr;
  MYSQL_PLUGIN_VIO *vio;
};

<span class="Type">static</span> <span class="Type">int</span> conv(<span class="Type">int</span> n, <span class="Type">const</span> <span class="Type">struct</span> pam_message **msg,
                <span class="Type">struct</span> pam_response **resp, <span class="Type">void</span> *data)
{
  <span class="Type">struct</span> param *param = (<span class="Type">struct</span> param *)data;
  <span class="Type">unsigned</span> <span class="Type">char</span> *end = param-&gt;buf + <span class="Statement">sizeof</span>(param-&gt;buf) - <span class="Constant">1</span>;
  <span class="Type">int</span> i;

  <span class="Statement">for</span> (i = <span class="Constant">0</span>; i &lt; n; i++) {
    <span class="Comment">/*</span><span class="Comment"> if there's a message - append it to the buffer </span><span class="Comment">*/</span>
    <span class="Statement">if</span> (msg[i]-&gt;msg) {
      <span class="Type">int</span> len = strlen(msg[i]-&gt;msg);
      <span class="Statement">if</span> (len &gt; end - param-&gt;ptr)
        len = end - param-&gt;ptr;
      memcpy(param-&gt;ptr, msg[i]-&gt;msg, len);
      param-&gt;ptr+= len;
      *(param-&gt;ptr)++ = <span class="Special">'n'</span>;
    }
    <span class="Comment">/*</span><span class="Comment"> if the message style is *_PROMPT_*, meaning PAM asks a question,</span>
<span class="Comment">       send the accumulated text to the client, read the reply </span><span class="Comment">*/</span>
    <span class="Statement">if</span> (msg[i]-&gt;msg_style == PAM_PROMPT_ECHO_OFF ||
        msg[i]-&gt;msg_style == PAM_PROMPT_ECHO_ON) {
      <span class="Type">int</span> pkt_len;
      <span class="Type">unsigned</span> <span class="Type">char</span> *pkt;

      <span class="Comment">/*</span><span class="Comment"> allocate the response array.</span>
<span class="Comment">         freeing it is the responsibility of the caller </span><span class="Comment">*/</span>
      <span class="Statement">if</span> (*resp == <span class="Constant">0</span>) {
        *resp = calloc(<span class="Statement">sizeof</span>(<span class="Type">struct</span> pam_response), n);
        <span class="Statement">if</span> (*resp == <span class="Constant">0</span>)
          <span class="Statement">return</span> PAM_BUF_ERR;
      }

      <span class="Comment">/*</span><span class="Comment"> dialog plugin interprets the first byte of the packet</span>
<span class="Comment">         as the magic number.</span>
<span class="Comment">           2 means &quot;read the input with the echo enabled&quot;</span>
<span class="Comment">           4 means &quot;password-like input, echo disabled&quot;</span>
<span class="Comment">         C'est la vie. </span><span class="Comment">*/</span>
      param-&gt;buf[<span class="Constant">0</span>] = msg[i]-&gt;msg_style == PAM_PROMPT_ECHO_ON ? <span class="Constant">2</span> : <span class="Constant">4</span>;
      <span class="Statement">if</span> (param-&gt;vio-&gt;write_packet(param-&gt;vio, param-&gt;buf, param-&gt;ptr - param-&gt;buf - <span class="Constant">1</span>))
        <span class="Statement">return</span> PAM_CONV_ERR;

      pkt_len = param-&gt;vio-&gt;read_packet(param-&gt;vio, &amp;pkt);
      <span class="Statement">if</span> (pkt_len &lt; <span class="Constant">0</span>)
        <span class="Statement">return</span> PAM_CONV_ERR;
      <span class="Comment">/*</span><span class="Comment"> allocate and copy the reply to the response array </span><span class="Comment">*/</span>
      (*resp)[i].resp = strndup((<span class="Type">char</span>*)pkt, pkt_len);
      param-&gt;ptr = param-&gt;buf + <span class="Constant">1</span>;
    }
  }
  <span class="Statement">return</span> PAM_SUCCESS;
}
</pre>
<p>That&#8217;s all. Now I can compile it as above (repeating the process twice, because I forgot <strong>-lpam</strong> the first time), load it, configure PAM to use <strong>pam_skey</strong> for the &#8220;mysql&#8221; service, create the user and, finally, login:</p>
<blockquote><p><code> $ <strong>mysql -u root</strong><br />
Welcome to the MariaDB monitor.  Commands end with ; or g.<br />
Your MariaDB connection id is 1<br />
Server version: 5.2.9-MariaDB-debug Source distribution</p>
<p>MariaDB []> <strong>CREATE USER serg IDENTIFIED VIA pam USING 'mysql';</strong><br />
Query OK, 0 rows affected (0.00 sec)</p>
<p>MariaDB []> <strong>^D</strong>Bye<br />
$ <strong>mysql -u serg</strong><br />
challenge otp-md5 99 th91334<br />
password: <em>&lt;Enter&gt;</em><br />
(turning echo on)<br />
pasword: <strong>OMEN US HORN OMIT BACK AHOY</strong><br />
Welcome to the MariaDB monitor.  Commands end with ; or g.<br />
Your MariaDB connection id is 2<br />
Server version: 5.2.9-MariaDB-debug Source distribution</p>
<p>MariaDB []> <strong>SELECT "Hey-ho! It works!!!";</strong><br />
</code>
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.montyprogram.com/writing-a-mariadb-pam-authentication-plugin/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>MariaDB Developer Meeting, Athens – 2011-11-13 Schedule</title>
		<link>http://blog.montyprogram.com/mariadb-developer-meeting-athens-%e2%80%93-2011-11-13-schedule/</link>
		<comments>http://blog.montyprogram.com/mariadb-developer-meeting-athens-%e2%80%93-2011-11-13-schedule/#comments</comments>
		<pubDate>Sun, 13 Nov 2011 07:55:57 +0000</pubDate>
		<dc:creator>Daniel Bartholomew</dc:creator>
				<category><![CDATA[Conferences/Events]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Athens]]></category>
		<category><![CDATA[MariaDB]]></category>

		<guid isPermaLink="false">http://askmonty.org/blog/?p=618</guid>
		<description><![CDATA[Here is the printed schedule for 2011-11-13: MariaDB-εφημερίδα-13-Nov-2011.pdf]]></description>
			<content:encoded><![CDATA[<p>Here is the printed schedule for 2011-11-13: <strong><a href='https://blog.montyprogram.com/wp-content/uploads/2011/11/MariaDB-εφημερίδα-13-Nov-2011.pdf'>MariaDB-εφημερίδα-13-Nov-2011.pdf</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.montyprogram.com/mariadb-developer-meeting-athens-%e2%80%93-2011-11-13-schedule/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MariaDB Developer Meeting, Athens – 2011-11-12 Schedule</title>
		<link>http://blog.montyprogram.com/mariadb-developer-meeting-athens-%e2%80%93-2011-11-12-schedule/</link>
		<comments>http://blog.montyprogram.com/mariadb-developer-meeting-athens-%e2%80%93-2011-11-12-schedule/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 08:13:31 +0000</pubDate>
		<dc:creator>Daniel Bartholomew</dc:creator>
				<category><![CDATA[Conferences/Events]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Athens]]></category>
		<category><![CDATA[MariaDB]]></category>

		<guid isPermaLink="false">http://askmonty.org/blog/?p=611</guid>
		<description><![CDATA[Here is the printed schedule for 2011-11-12: MariaDB εφημερίδα &#8211; 12 Nov 2011]]></description>
			<content:encoded><![CDATA[<p>Here is the printed schedule for 2011-11-12: <strong><a href='https://blog.montyprogram.com/wp-content/uploads/2011/11/MariaDB-εφημερίδα-12-Nov-2011.pdf'>MariaDB εφημερίδα &#8211; 12 Nov 2011</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.montyprogram.com/mariadb-developer-meeting-athens-%e2%80%93-2011-11-12-schedule/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MariaDB Developer Meeting, Athens &#8211; 2011-11-11 Schedule</title>
		<link>http://blog.montyprogram.com/mariadb-developer-meeting-athens-2011-11-11-schedule/</link>
		<comments>http://blog.montyprogram.com/mariadb-developer-meeting-athens-2011-11-11-schedule/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 13:45:28 +0000</pubDate>
		<dc:creator>Daniel Bartholomew</dc:creator>
				<category><![CDATA[Conferences/Events]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Athens]]></category>
		<category><![CDATA[MariaDB]]></category>

		<guid isPermaLink="false">http://askmonty.org/blog/?p=601</guid>
		<description><![CDATA[Here is the printed schedule for 2011-11-11: MariaDB-εφημερίδα-11-Nov-2011.pdf (εφημερίδα = newspaper)]]></description>
			<content:encoded><![CDATA[<p>Here is the printed schedule for 2011-11-11: <strong><a href='https://blog.montyprogram.com/wp-content/uploads/2011/11/MariaDB-εφημερίδα-11-Nov-2011.pdf'>MariaDB-εφημερίδα-11-Nov-2011.pdf</a></strong></p>
<p>(<a href="http://translate.google.com/#el|en|εφημερίδα" title="Google translate">εφημερίδα = newspaper</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.montyprogram.com/mariadb-developer-meeting-athens-2011-11-11-schedule/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bzr and launchpad tricks: firefox plugin</title>
		<link>http://blog.montyprogram.com/bzr-and-launchpad-tricks-firefox-plugin/</link>
		<comments>http://blog.montyprogram.com/bzr-and-launchpad-tricks-firefox-plugin/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 09:00:57 +0000</pubDate>
		<dc:creator>Sergei</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bzr]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[launchpad]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://askmonty.org/blog/?p=364</guid>
		<description><![CDATA[If you work with bazaar, you have seen its URIs. You can find the complete list is in the bzr help urlspec. Although I commonly use only a subset of that, like bzr+ssh://bazaar.launchpad.net/~maria-captains/maria/5.2-serg/ and http://bazaar.launchpad.net/%2Bbranch/mysql-server/5.5/. In addition I often use &#8230; <a href="http://blog.montyprogram.com/bzr-and-launchpad-tricks-firefox-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you work with <strong>bazaar</strong>, you have seen its URIs. You can find the complete list is in the <strong>bzr help urlspec</strong>. Although I commonly use only a subset of that, like <strong>bzr+ssh://bazaar.launchpad.net/~maria-captains/maria/5.2-serg/</strong> and <strong>http://bazaar.launchpad.net/%2Bbranch/mysql-server/5.5/</strong>.</p>
<p>In addition I often use <a href="https://launchpad.net/">Launchpad</a> aliases, such as <strong>lp:~maria-captains/maria/5.3-serg/</strong>, <strong>lp:maria/5.3</strong>, and <strong>lp:869001</strong>.</p>
<p>And finally, there are common abbreviations that we have used in MySQL, and others that we use in MariaDB, for example <strong>bug#12345</strong> and  <strong>wl#90</strong>.</p>
<p>What&#8217;s annoying, I need to remember that <strong>wl#90</strong> corresponds to <strong>http://askmonty.org/worklog/?tid=90</strong> and type the latter in the location bar of the browser, when I want to look this task up. And <strong>lp:869001</strong> is, for my browser, <strong>https://bugs.launchpad.net/bugs/869001</strong>. Similarly, every other URL above, has its browser-friendly evil twin. It&#8217;s evil, because I have to remember it!</p>
<p>Now, Firefox tries to help, to a certain extent. It supports so-called <em>keywords</em> — short aliases for bookmarks. Create a bookmark for <strong>https://bugs.launchpad.net/bugs/%s</strong> and in the <em>Keyword</em> field enter <strong>lp</strong>. Now you can type in the location bar <strong>lp 869001</strong> (with a space) and Firefox will expand it into a complete url <strong>https://bugs.launchpad.net/bugs/869001</strong>. Quite handy. And I&#8217;ve used it for a few years. Still it annoyed me, that I had to rewrite the abbreviations manually, put spaces, remove colons, and so on. And at last it annoyed me to a degree where I wrote a Firefox plugin!<br />
<span id="more-364"></span></p>
<p>Let me introduce a <strong><a href="https://addons.mozilla.org/ru/firefox/addon/locationmorph/">LocationMorph</a></strong> — a plugin that can arbitrarily rewrite the text in the location bar, according to the user specified regular expression. I have configured it (via a Preference dialog) to use the following set of rules</p>
<blockquote>
<table>
<tr>
<td><strong>^bzr+ssh://bazaar.launchpad.net/</strong></td>
<td>→</td>
<td><strong>http://code.launchpad.net/</strong></td>
</tr>
<tr>
<td><strong>^lp:(d+)$</strong></td>
<td>→</td>
<td><strong>https://bugs.launchpad.net/bugs/$1</strong></td>
</tr>
<tr>
<td><strong>^lp:</strong></td>
<td>→</td>
<td><strong>http://code.launchpad.net/</strong></td>
</tr>
<tr>
<td><strong>^wl#(d+)$</strong></td>
<td>→</td>
<td><strong>http://askmonty.org/worklog/?tid=$1</strong></td>
</tr>
<tr>
<td><strong>^bug#(d+)$</strong></td>
<td>→</td>
<td><strong>http://bugs.mysql.com/bug.php?id=$1</strong></td>
</tr>
</table>
</blockquote>
<p>And now I can simply copy and paste a <strong>bzr</strong> URI, or a launchpad alias, or our internal abbreviation from the email (or <strong>bzr info</strong>) directly into the browser, and it understands it directly and shows me the page that I want. Ahh, perfection&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.montyprogram.com/bzr-and-launchpad-tricks-firefox-plugin/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

