Switch to a portable implementation of `id -gn`

The ouput of `groups` may not list the primary group first -- and while
`id -gn` works in most Unix-like platforms, it does not work on Solaris.
Re-implement it using $PERL, for portability.
Avoid a race condition in crypt testing

Test::Warn fails us here because it only captures the first line of a
multi-line warning.  Opening up the debug log and searching over it
leads to race conditions, as the error we're looking for may not have
been flushed to disk by the time we read it.

Instead, use a simple __WARN__ handler to look for the desired warning.
Merge branch '4.2/test-crypt-race-condition' into 4.2-trunk