Issue 414:

Response to PR ports/175249:

Perhaps the variables could be better named: euid, egid here are the
expected user and group ownership of the various files and
directories.  I've changed them to fileowner and filegroup.

In normal use both /var/db/pkg and all the .sqlite files pkg uses
within it should be owned by root:wheel and only writeable by root.
Allowing non-root to modify the pkg DB would be a security debacle
just waiting to happen.

The change as you have it would mean that an ordinary user could not
run pkg info on a standard system.

The install_as_user flag specifically changes the requirement on
ownership so that a (non-root) user can have a personally owned copy
of a pkgng database.  Implicit in that is the assumption that they're
going to set PKG_DBDIR to put their private DB in other than the
default location.

I found and fixed a different bug to do with creating repo.sqlite the
first time ever 'pkg update' was run for a new $PKG_DBDIR, and I have
shamelessly stolen your additions to the error message in
file_mode_insecure().