kern: sort groups in cred only if necesary
crsetgroups_locked() now only copy the groups. The caller
can either provide already sorted groups or must sort the
groups after the set. To sort the groups the crsortgroups()
should be used.
kern_setgroups() now expliciet sorts the groups. crcopy() now uses
crsetgroups_locked() and does the crextend() manual. crsetgroups()
enshoure that the groups are sorted.
kern: remove unnecesary allocation and copy on setgroups
For setgroups(2) it is necesary to copy the struct ucred, but it's not
necesary to copy the groups vector. This creates a function with allows
to copy a struct ucred without copy the groups. This avoids an allocation
if the old groups array is larger then the new one.
Now the unlock; alloc; lock loop of crcopysafe() isn't necesary anymore.
Because the groups array is allocated before the process is locked.