glibc/include
Stephen Gallagher ced8f89336 NSS: Implement group merging support.
https://sourceware.org/glibc/wiki/Proposals/GroupMerging

== Justification ==
It is common today for users to rely on centrally-managed user stores for
handling their user accounts. However, much software existing today does
not have an innate understanding of such accounts. Instead, they commonly
rely on membership in known groups for managing access-control (for
example the "wheel" group on Fedora and RHEL systems or the "adm" group
on Debian-derived systems). In the present incarnation of nsswitch, the
only way to have such groups managed by a remote user store such as
FreeIPA or Active Directory would be to manually remove the groups from
/etc/group on the clients so that nsswitch would then move past nss_files
and into the SSSD, nss-ldap or other remote user database.

== Solution ==
With this patch, a new action is introduced for nsswitch:
NSS_ACTION_MERGE. To take advantage of it, one will add [SUCCESS=merge]
between two database entries in the nsswitch.conf file. When a group is
located in the first of the two group entries, processing will continue
on to the next one. If the group is also found in the next entry (and the
group name and GID are an exact match), the member list of the second
entry will be added to the group object to be returned.

== Implementation ==
After each DL_LOOKUP_FN() returns, the next action is checked. If the
function returned NSS_STATUS_SUCCESS and the next action is
NSS_ACTION_MERGE, a copy of the result buffer is saved for the next pass
through the loop. If on this next pass through the loop the database
returns another instance of a group matching both the group name and GID,
the member list is added to the previous list and it is returned as a
single object. If the following database does not contain the same group,
then the original is copied back into the destination buffer.

This patch implements merge functionality only for the group database.
For other databases, there is a default implementation that will return
the EINVAL errno if a merge is requested. The merge functionality can be
implemented for other databases at a later time if such is needed. Each
database must provide a unique implementation of the deep-copy and merge
functions.

If [SUCCESS=merge] is present in nsswitch.conf for a glibc version that
does not support it, glibc will process results up until that operation,
at which time it will return results if it has found them or else will
simply return an error. In practical terms, this ends up behaving like
the remainder of the nsswitch.conf line does not exist.

== Iterators ==
This feature does not modify the iterator functionality from its current
behavior. If getgrnam() or getgrgid() is called, glibc will iterate
through all entries in the `group` line in nsswitch.conf and display the
list of members without attempting to merge them. This is consistent with
the behavior of nss_files where if two separate lines are specified for
the same group in /etc/groups, getgrnam()/getgrgid() will display both.
Clients are already expected to handle this gracefully.

== No Premature Optimizations ==
The following is a list of places that might be eligible for
optimization, but were not overengineered for this initial contribution:
 * Any situation where a merge may occur will result in one malloc() of
   the same size as the input buffer.
 * Any situation where a merge does occur will result in a second
   malloc() to hold the list of pointers to member name strings.
 * The list of members is simply concatenated together and is not tested
   for uniqueness (which is identical to the behavior for nss_files,
   which will simply return identical values if they both exist on the
   line in the file. This could potentially be optimized to reduce space
   usage in the buffer, but it is both complex and computationally
   expensive to do so.

== Testing ==
I performed testing by running the getent utility against my newly-built
glibc and configuring /etc/nsswitch.conf with the following entry:
group: group:      files [SUCCESS=merge] sss

In /etc/group I included the line:
wheel10:sgallagh

I then configured my local SSSD using the id_provider=local to respond
with:
wheel:*:10:localuser,localuser2

I then ran `getent group wheel` against the newly-built glibc in
multiple situations and received the expected output as described
above:
 * When SSSD was running.
 * When SSSD was configured in nsswitch.conf but the daemon was not
   running.
 * When SSSD was configured in nsswitch.conf but nss_sss.so.2 was not
   installed on the system.
 * When the order of 'sss' and 'files' was reversed.
 * All of the above with the [SUCCESS=merge] removed (to ensure no
   regressions).
 * All of the above with `getent group 10`.
 * All of the above with `getent group` with and without
   `enumerate=true` set in SSSD.
 * All of the above with and without nscd enabled on the system.
2016-04-29 22:18:21 -04:00
..
arpa Fix resolver inet_* namespace (bug 17722). 2014-12-17 18:09:11 +00:00
bits Fix limits.h NL_NMAX namespace (bug 19929). 2016-04-08 22:52:51 +00:00
gnu Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
net Fix resolver if_* namespace (bug 17717). 2014-12-16 18:18:49 +00:00
netinet Fix gethostbyaddr in6addr_any, in6addr_loopback namespace (bug 18532). 2015-06-17 20:08:22 +00:00
programs Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
protocols
rpc Rename bits/libc-tsd.h to libc-tsd.h (bug 14912). 2015-09-03 20:33:46 +00:00
rpcsvc * nis/nis_domain_of.c (__nis_domain_of): New function. 2007-04-19 14:28:01 +00:00
sys Remove union wait [BZ #19613] 2016-04-14 08:54:57 +02:00
aio.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
aliases.h Remove pre-ISO C support 2012-01-07 23:57:22 -05:00
alloca.h alloca: fix buf interaction 2015-02-24 13:29:40 -05:00
argp.h
argz.h Remove use of INTDEF/INTUSE in intl 2012-05-24 23:08:18 +02:00
assert.h Remove NOT_IN_libc 2014-11-24 15:03:45 +05:30
atomic.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
byteswap.h
caller.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
complex.h conformtest: Fix namespace testing. 2013-09-04 20:47:21 +00:00
cpio.h Add more headers to include/ for conform tests. 2014-12-11 21:41:30 +00:00
ctype.h Rename bits/libc-tsd.h to libc-tsd.h (bug 14912). 2015-09-03 20:33:46 +00:00
des.h
dirent.h Mark internal dirent functions hidden 2015-10-15 14:15:41 -07:00
dlfcn.h Mark _dl_catch_error hidden 2015-10-15 14:13:50 -07:00
elf.h Check supported DF_1_XXX bits 2012-11-21 06:33:19 -08:00
endian.h
envz.h
err.h
errno.h Remove NOT_IN_libc 2014-11-24 15:03:45 +05:30
error.h
execinfo.h Remove pre-ISO C support 2012-01-07 23:57:22 -05:00
fcntl.h hurd: Do not hide rtld symbols which need to be preempted 2016-03-20 19:51:42 +01:00
features.h Update version.h and include/features.h for 2.23 release 2016-02-18 15:54:00 -02:00
fenv.h Mark fegetround pure (bug 16296). 2015-09-15 20:36:50 +00:00
fmtmsg.h Add more headers to include/ for conform tests. 2014-12-11 21:41:30 +00:00
fnmatch.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
fpu_control.h
ftw.h
gconv.h
getopt.h Update. 2004-03-09 10:36:53 +00:00
getopt_int.h Update. 2004-03-09 10:36:53 +00:00
glob.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
gmp.h * include/gmp.h: Include/gmp-mparam.h. * stdlib/strtod.c: Include gmp-mparam.h before gmp.h and gmp-impl.h. 2003-03-14 05:48:18 +00:00
gnu-versions.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
grp-merge.h NSS: Implement group merging support. 2016-04-29 22:18:21 -04:00
grp.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
gshadow.h [BZ #9955] 2009-04-23 18:29:30 +00:00
iconv.h
ifaddrs.h Remove IS_IN_nscd 2014-11-24 11:41:44 +05:30
ifunc-impl-list.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
inline-hashtab.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
langinfo.h Add first fixes for conformtest for POSIX2008 2012-02-26 21:32:56 -05:00
libc-internal.h Use max_align_t from <stddef.h>. 2015-10-29 12:46:22 +00:00
libc-symbols.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
libgen.h
libintl.h Remove use of INTDEF/INTUSE in intl 2012-05-24 23:08:18 +02:00
libio.h Rename bits/stdio-lock.h to stdio-lock.h (bug 14912). 2015-09-04 16:21:14 +00:00
limits.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
link.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
list.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
locale.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
malloc.h * malloc/malloc.c (_int_free): Second argument is now mchunkptr. 2009-02-07 22:01:49 +00:00
math.h Fix lgamma setting signgam for ISO C (bug 15421). 2015-11-20 22:49:59 +00:00
mcheck.h
memory.h
mntent.h Remove use of INTUSE/INTDEF in misc. 2012-05-31 13:10:02 +02:00
monetary.h Add first fixes for conformtest for POSIX2008 2012-02-26 21:32:56 -05:00
mqueue.h Fix mq_receive, mq_send mq_timed* namespace (bug 18545). 2015-06-17 20:19:04 +00:00
netdb.h Fix h_errno namespace (bug 18520). 2015-06-12 10:10:18 +00:00
netgroup.h
nl_types.h
nss.h Harden putpwent, putgrent, putspent, putspent against injection [BZ #18724] 2015-10-02 11:34:13 +02:00
nsswitch.h
obstack.h
poll.h
printf.h strfmon_l: Use specified locale for number formatting [BZ #19633] 2016-04-04 15:18:13 +02:00
pthread.h Fix mq_notify pthread_barrier_* namespace (bug 18544). 2015-06-17 20:16:56 +00:00
pty.h Update. 2004-10-24 21:29:41 +00:00
pwd.h Harden putpwent, putgrent, putspent, putspent against injection [BZ #18724] 2015-10-02 11:34:13 +02:00
regex.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
resolv.h Remove NOT_IN_libc 2014-11-24 15:03:45 +05:30
rounding-mode.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
sched.h posix: New Linux posix_spawn{p} implementation 2016-03-07 11:53:47 +07:00
scratch_buffer.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
search.h Fix sem_* tdelete, tfind, tsearch, twalk namespace (bug 18536). 2015-06-17 20:11:58 +00:00
set-hooks.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
setjmp.h Mark internal setjmp functions hidden 2015-10-15 14:22:25 -07:00
sgtty.h
shadow.h Remove pre-ISO C support 2012-01-07 23:57:22 -05:00
shlib-compat.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
signal.h Mark ld.so internel sigaction functions hidden 2015-10-15 14:23:31 -07:00
spawn.h
stab.h
stackinfo.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
stap-probe.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
stdc-predef.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
stdio.h Provide __libc_fatal for rtld. 2015-07-09 15:32:32 -07:00
stdio_ext.h Remove use of INTDEF/INTUSE in libio 2012-05-24 23:06:20 +02:00
stdlib.h Refactor strtod parsing of NaN payloads. 2015-11-24 22:24:52 +00:00
string.h Add _STRING_INLINE_unaligned and string_private.h 2016-02-18 14:55:29 -02:00
strings.h
stropts.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
stubs-prologue.h
syscall.h
sysexits.h
syslog.h
tar.h
termios.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
tgmath.h
time.h Fix symbol definitions for __clock_* functions 2013-06-11 11:11:11 +05:30
ttyent.h Fix ttyslot namespace (bug 18547). 2015-06-17 20:21:19 +00:00
uchar.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
ucontext.h
ulimit.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
unistd.h posix: New Linux posix_spawn{p} implementation 2016-03-07 11:53:47 +07:00
utime.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
utmp.h Remove pre-ISO C support 2012-01-07 23:57:22 -05:00
values.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
wchar.h Refactor strtod parsing of NaN payloads. 2015-11-24 22:24:52 +00:00
wctype.h Fix regex wctype namespace (bug 18495). 2015-06-05 20:04:47 +00:00
wordexp.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
xlocale.h