libnss-mysql and segmentation faults

Submitted by cjdmax on Mon, 12/10/2012 - 23:49

If you're using the excellent libnss-mysql (also known as libnss-mysql-bg on Ubuntu) please, please, PLEASE read the documentation provided at their documentation pages.

You'll also note the WHERE clause contains a '%1$s'. This '%1$s' is where the system will insert the username being searched for. For getpwuid, this is a '%1$u' because we're searching based on a number (%1$u) rather than a username/string (%s). It's important to keep these correct, else things will start crashing.

If you were, for instance, to write your own SQL queries for the getpwuid portion of the config, you may make a terrible mistake. I did. You will hate yourself if you don't catch it. Everything will segfault. If you were morally so inclined this could be a 'landmine' you could leave for the next sysadmin. It is truly hell. Your initramfs generation will segfault, your ls -al will segfault... Everthing turns to shit.

getpwuid SELECT username,'x',uid,gid,gecos,homedir,shell \
FROM users \
WHERE uid='%1$u' \
LIMIT 1

If you use %1$s here, everything will go to shit. Don't do it! The query needs the UID as an argument, not the username!