glibc/nss
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
..
nss_db nss_db: Propagate ERANGE error if parse_line fails [BZ #19837] 2016-03-29 11:27:32 +02:00
nss_files Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
alias-lookup.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
bug17079.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
bug-erange.c Update. 2002-09-29 18:25:48 +00:00
databases.def Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
db-Makefile Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
Depend
digits_dots.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
ethers-lookup.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
function.def Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
getent.c Update copyright dates not handled by scripts/update-copyrights. 2016-01-04 16:26:30 +00:00
getnssent_r.c NSS: Implement group merging support. 2016-04-29 22:18:21 -04:00
getnssent.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
getXXbyYY_r.c NSS: Implement group merging support. 2016-04-29 22:18:21 -04:00
getXXbyYY.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
getXXent_r.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
getXXent.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
grp-lookup.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
hosts-lookup.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
key-lookup.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
makedb.c Update copyright dates not handled by scripts/update-copyrights. 2016-01-04 16:26:30 +00:00
Makefile Register extra test objects 2016-04-13 17:07:13 +02:00
netgrp-lookup.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
network-lookup.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
nss_test1.c Add self-contained test for NSS. 2010-08-11 07:25:02 -07:00
nss.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
nsswitch.c NSS: Implement group merging support. 2016-04-29 22:18:21 -04:00
nsswitch.conf More configurability for secondary group lookup 2011-05-10 00:36:29 -04:00
nsswitch.h NSS: Implement group merging support. 2016-04-29 22:18:21 -04:00
proto-lookup.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
pwd-lookup.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
rewrite_field.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
rpc-lookup.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
service-lookup.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
sgrp-lookup.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
spwd-lookup.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
test-digits-dots.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
test-netdb.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
tst-field.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
tst-nss-getpwent.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
tst-nss-static.c 2012-04-06 Paul Pluzhnikov <ppluzhnikov@google.com> 2012-04-06 13:49:35 -07:00
tst-nss-test1.c Fix nss/tst-nss-test1.c format warning. 2014-11-27 03:24:18 +00:00
valid_field.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
valid_list_field.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
Versions Get canonical name in getaddrinfo from hosts file for AF_INET (fixes 16077) 2013-11-28 17:18:12 +05:30
XXX-lookup.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00