Add permission checks on the passwords directory.

Also added a couple functional tests and a dirname() wrapper that checks
the return and allocates memory accordingly. This hasn't been tested on
Linux, I'm not 100% sure libgen.h exists there.