scox.info - Random Thoughts

To content | To menu | To search

Tuesday, June 10 2008

Migrating from Mephisto to Dotclear 2

It's been a while since my last post. Beside the fact that I was busy, the reason preventing me from posting is that the blogging engine I was using (Mephisto) was in a bad shape. It seemed unmaintaned, managed to consume all the server memory and didn't survive a rails upgrade.

That's why I've decided to migrate to Dotclear 2, which seems to be a nice and clean blogging engine. However, in the migration process, I didn't want to lose:

  • All my previsous posts (both published and pending)
  • All the comments
  • Associated metadata (categories, tags and so on)

Dotclear has a nice builtin plugin called Import/Export which let you save and restore backups of your blog. All I did was writing a Ruby script that generates a dump of the Mephisto database using ActiveRecord in the same format as Import/Export, ready to be imported. It is available here and works in the following way:

  • Place it under the script directory of your Mephisto rails root
  • Edit the first lines (set your Dotclear 2 login and blog id)
  • Run it and redirect the output to your favorite location:

ruby script/migrate_to_dc2.rb > public/dump.dc2

  • Retrieve the dump file (e.g. dump.dc2) and import it in the "Import/Export" area, under the Import a single blog section.

That's it, you're done. It should have imported all your blog posts (and preserved publish dates as well as many other attributes), comments, metadatas etc.

I also wanted to maintain backward URL compatibility with Mephisto. A couple of mod_rewrite rules did the trick:

# Mephisto URL compatiblity
RewriteEngine On
# Feeds
RewriteRule ^/feed/atom.xml /feed/atom [L,R=301]
RewriteRule ^/feed/all_comments.xml$ /feed/atom/comments [L,R=301]
# Posts
RewriteRule (^/200\d.*) /post$1 [QSA,L,R=301]

That's all. I hope it will be useful to anyone wishing to migrate to Dotclear 2, as the process of creating that script is quite annoying :)

Saturday, August 25 2007

Using D-Bus from setuid applications

When trying to connect to the system bus from a setuid application, D-Bus throws back the following error:

Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

After some debugging, I found that the problem is a bug in the D-Bus EXTERNAL authentication method: the library sends the real UID while the daemon checks the effective UID, which of course doesn't work at all in setuid applications.

I filed a bug report in the Freedesktop Bugzilla and provideda patch which is yet to be merged.

In the meantime, if you need to use D-Bus in a setuid application, the following code might help:

DBusConnection *my_dbus_bus_get(DBusBusType type, DBusError *error)
{
DBusConnection *bus = NULL;

if (!(bus = dbus_bus_get(type, error)))
{
/* The connection to the BUS failed, we now check
* if we are running as setuid. */
uid_t ruid;
uid_t euid;

if (!(euid = geteuid()) && (ruid = getuid()))
{
/* In that case, we temporary change our
* real uid to the effective uid and try again */
dbus_error_free(error);
setreuid(euid, euid);
bus = dbus_bus_get(type, error);
setreuid(ruid, euid);
}
}
return bus;
}

This workaround is a function you'll have to call instead of the regular dbus_bus_get(). In case the connection fails and it's running on a setuid application, it will change the real UID to match the effective UID so the authentication process will succeed, make a connection to D-Bus and restore everything back.