mountd(8): Allow to pass {NGROUPS_MAX} + 1 groups
NGROUPS_MAX is just the minimum maximum of the number of allowed
supplementary groups. The actual runtime value may be greater. Allow
more groups to be specified accordingly (now that, a few commits ago,
nmount(2) has been changed similarly).
To this end, we just allocate once and for all a static array called
'tmp_groups' big enough to hold {NGROUPS_MAX} + 1 groups (the maximum
number of supplementary groups plus the effective GID, which we store in
a variable named 'tngroups_max' to avoid confusion with the kernel
variable 'ngroups_max' holding only the maximum number of
*supplementary* groups) in main() and use this temporary space in
get_exportlist_one(), do_opt() and parsecred(). Doing so in passing
fixes a (benign) memory leak in case "-maproot" and/or "-mapall" were
specified multiple times and the first option comprised more than
SMALLNGROUPS.
parsecred() does not use 'cr_smallgrps' anymore, but we have kept
'cr_smallgrps'/SMALLNGROUPS as 'struct expcred' is also included in
'struct exportlist' and 'struct grouplist', and thus this preallocated
field still results in an optimization for the common case of small
number of groups (although its real impact is probably negligible and
arguably was not worth the trouble).
While here, in do_mount(), remove some unnecessary groups array
allocation and copying.
Reviewed by: rmacklem (older version)
Approved by: markj (mentor)
MFC after: 2 weeks
Relnotes: yes
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47016