Refactor permissions system to be more reusable.

These changes are necessary to allow plugins (such as liveupdate) to
reuse core parts of the permission system.
Permissions: fix serialization of superuser permissions.

JSON serialization of a superuser permission set would return {all:
false} because of the way __getitem__ works.