fix uid/gid conversions

* use uid_t/gid_t for id's and (uid_t)-1 or (gid_t)-1 for invalid values, like here http://linux.die.net/man/3/chown
* delete strange calls endpwent() and endgrent()