Add new pkgdb_access() function to test if process has the right
access levels to continue.  Now takes notice of $INSTALL_AS_USER in
the environment.
Use EPKG_ENOACCESS for consistency with EPKG_ENODB
Add error code for insecure permissions on databases
Rewrite pkgdb_access to actually test what we're interested in:

  * Are the permissions on the DB too lax?

  * Do we have the level of (read,write,create) access we need.

'create' access translates into 'read,write' access on the enclosing
directory.
Instead of testing geteuid() == 0, instead, test what we really mean:
the package database (local.sqlite) has secure permissions, and the
euid of the process as appropriate read / write access (including to
create the DB)
Fix brain-o.  Copy the directory, not what we just tested to be a NULL
pointer.

Tweak error message slightly.
Fixes #414 -- pkgng should be usable as an ordinary user when
INSTALL_AS_USER is set in the environment.

It's insecure if the package DB is owned by another user when root is
doing stuff.

When INSTALL_AS_USER is set, allowed owners of the pkg DB are root or
the euid of the process.  The egid of the process can have write
access.