Implement permission handling

Also fixes a bug in the SQLite persistence
Adds the following API functions:
getRank(id)
registerPermission(name, title, description, options)
unregisterPermission(name)
givePermission(rank, perm, option)
getPermission(rank, perm)