Blame SOURCES/shadow-4.6-sssd-flush.patch

9f13c6
From 4aaf05d72e9d6daf348cefb8a6ad35d2966cbe9b Mon Sep 17 00:00:00 2001
9f13c6
From: Jakub Hrozek <jakub.hrozek@posteo.se>
9f13c6
Date: Wed, 12 Sep 2018 14:22:11 +0200
9f13c6
Subject: [PATCH] Flush sssd caches in addition to nscd caches
9f13c6
9f13c6
Some distributions, notably Fedora, have the following order of nsswitch
9f13c6
modules by default:
9f13c6
    passwd: sss files
9f13c6
    group:  sss files
9f13c6
9f13c6
The advantage of serving local users through SSSD is that the nss_sss
9f13c6
module has a fast mmapped-cache that speeds up NSS lookups compared to
9f13c6
accessing the disk an opening the files on each NSS request.
9f13c6
9f13c6
Traditionally, this has been done with the help of nscd, but using nscd
9f13c6
in parallel with sssd is cumbersome, as both SSSD and nscd use their own
9f13c6
independent caching, so using nscd in setups where sssd is also serving
9f13c6
users from some remote domain (LDAP, AD, ...) can result in a bit of
9f13c6
unpredictability.
9f13c6
9f13c6
More details about why Fedora chose to use sss before files can be found
9f13c6
on e.g.:
9f13c6
    https://fedoraproject.org//wiki/Changes/SSSDCacheForLocalUsers
9f13c6
or:
9f13c6
    https://docs.pagure.org/SSSD.sssd/design_pages/files_provider.html
9f13c6
9f13c6
Now, even though sssd watches the passwd and group files with the help
9f13c6
of inotify, there can still be a small window where someone requests a
9f13c6
user or a group, finds that it doesn't exist, adds the entry and checks
9f13c6
again. Without some support in shadow-utils that would explicitly drop
9f13c6
the sssd caches, the inotify watch can fire a little late, so a
9f13c6
combination of commands like this:
9f13c6
    getent passwd user || useradd user; getent passwd user
9f13c6
can result in the second getent passwd not finding the newly added user
9f13c6
as the racy behaviour might still return the cached negative hit from
9f13c6
the first getent passwd.
9f13c6
9f13c6
This patch more or less copies the already existing support that
9f13c6
shadow-utils had for dropping nscd caches, except using the "sss_cache"
9f13c6
tool that sssd ships.
9f13c6
---
9f13c6
 configure.ac    | 10 +++++++
9f13c6
 lib/Makefile.am |  2 ++
9f13c6
 lib/commonio.c  |  2 ++
9f13c6
 lib/sssd.c      | 75 +++++++++++++++++++++++++++++++++++++++++++++++++
9f13c6
 lib/sssd.h      | 17 +++++++++++
9f13c6
 src/chfn.c      |  2 ++
9f13c6
 src/chgpasswd.c |  2 ++
9f13c6
 src/chpasswd.c  |  2 ++
9f13c6
 src/chsh.c      |  2 ++
9f13c6
 src/gpasswd.c   |  2 ++
9f13c6
 src/groupadd.c  |  2 ++
9f13c6
 src/groupdel.c  |  2 ++
9f13c6
 src/groupmod.c  |  2 ++
9f13c6
 src/grpck.c     |  2 ++
9f13c6
 src/grpconv.c   |  2 ++
9f13c6
 src/grpunconv.c |  2 ++
9f13c6
 src/newusers.c  |  2 ++
9f13c6
 src/passwd.c    |  2 ++
9f13c6
 src/pwck.c      |  2 ++
9f13c6
 src/pwconv.c    |  2 ++
9f13c6
 src/pwunconv.c  |  2 ++
9f13c6
 src/useradd.c   |  2 ++
9f13c6
 src/userdel.c   |  2 ++
9f13c6
 src/usermod.c   |  2 ++
9f13c6
 src/vipw.c      |  2 ++
9f13c6
 25 files changed, 146 insertions(+)
9f13c6
 create mode 100644 lib/sssd.c
9f13c6
 create mode 100644 lib/sssd.h
9f13c6
9f13c6
diff --git a/configure.ac b/configure.ac
9f13c6
index 41068a5d..10ad70cf 100644
9f13c6
--- a/configure.ac
9f13c6
+++ b/configure.ac
9f13c6
@@ -280,6 +280,9 @@ AC_ARG_WITH(sha-crypt,
9f13c6
 AC_ARG_WITH(nscd,
9f13c6
 	[AC_HELP_STRING([--with-nscd], [enable support for nscd @<:@default=yes@:>@])],
9f13c6
 	[with_nscd=$withval], [with_nscd=yes])
9f13c6
+AC_ARG_WITH(sssd,
9f13c6
+	[AC_HELP_STRING([--with-sssd], [enable support for flushing sssd caches @<:@default=yes@:>@])],
9f13c6
+	[with_sssd=$withval], [with_sssd=yes])
9f13c6
 AC_ARG_WITH(group-name-max-length,
9f13c6
 	[AC_HELP_STRING([--with-group-name-max-length], [set max group name length @<:@default=16@:>@])],
9f13c6
 	[with_group_name_max_length=$withval], [with_group_name_max_length=yes])
9f13c6
@@ -304,6 +307,12 @@ if test "$with_nscd" = "yes"; then
9f13c6
 	              [AC_MSG_ERROR([posix_spawn is needed for nscd support])])
9f13c6
 fi
9f13c6
 
9f13c6
+if test "$with_sssd" = "yes"; then
9f13c6
+	AC_CHECK_FUNC(posix_spawn,
9f13c6
+	              [AC_DEFINE(USE_SSSD, 1, [Define to support flushing of sssd caches])],
9f13c6
+	              [AC_MSG_ERROR([posix_spawn is needed for sssd support])])
9f13c6
+fi
9f13c6
+
9f13c6
 dnl Check for some functions in libc first, only if not found check for
9f13c6
 dnl other libraries.  This should prevent linking libnsl if not really
9f13c6
 dnl needed (Linux glibc, Irix), but still link it if needed (Solaris).
9f13c6
@@ -679,5 +688,6 @@ echo "	shadow group support:		$enable_shadowgrp"
9f13c6
 echo "	S/Key support:			$with_skey"
9f13c6
 echo "	SHA passwords encryption:	$with_sha_crypt"
9f13c6
 echo "	nscd support:			$with_nscd"
9f13c6
+echo "	sssd support:			$with_sssd"
9f13c6
 echo "	subordinate IDs support:	$enable_subids"
9f13c6
 echo
9f13c6
diff --git a/lib/Makefile.am b/lib/Makefile.am
9f13c6
index 6db86cd6..fd634542 100644
9f13c6
--- a/lib/Makefile.am
9f13c6
+++ b/lib/Makefile.am
9f13c6
@@ -30,6 +30,8 @@ libshadow_la_SOURCES = \
9f13c6
 	lockpw.c \
9f13c6
 	nscd.c \
9f13c6
 	nscd.h \
9f13c6
+	sssd.c \
9f13c6
+	sssd.h \
9f13c6
 	pam_defs.h \
9f13c6
 	port.c \
9f13c6
 	port.h \
9f13c6
diff --git a/lib/commonio.c b/lib/commonio.c
9f13c6
index d06b8e7d..96f2d5f7 100644
9f13c6
--- a/lib/commonio.c
9f13c6
+++ b/lib/commonio.c
9f13c6
@@ -45,6 +45,7 @@
9f13c6
 #include <stdio.h>
9f13c6
 #include <signal.h>
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #ifdef WITH_TCB
9f13c6
 #include <tcb.h>
9f13c6
 #endif				/* WITH_TCB */
9f13c6
@@ -485,6 +486,7 @@ static void dec_lock_count (void)
9f13c6
 			if (nscd_need_reload) {
9f13c6
 				nscd_flush_cache ("passwd");
9f13c6
 				nscd_flush_cache ("group");
9f13c6
+				sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP);
9f13c6
 				nscd_need_reload = false;
9f13c6
 			}
9f13c6
 #ifdef HAVE_LCKPWDF
9f13c6
diff --git a/lib/sssd.c b/lib/sssd.c
9f13c6
new file mode 100644
9f13c6
index 00000000..80e49e55
9f13c6
--- /dev/null
9f13c6
+++ b/lib/sssd.c
9f13c6
@@ -0,0 +1,75 @@
9f13c6
+/* Author: Peter Vrabec <pvrabec@redhat.com> */
9f13c6
+
9f13c6
+#include <config.h>
9f13c6
+#ifdef USE_SSSD
9f13c6
+
9f13c6
+#include <stdio.h>
9f13c6
+#include <sys/wait.h>
9f13c6
+#include <sys/types.h>
9f13c6
+#include "exitcodes.h"
9f13c6
+#include "defines.h"
9f13c6
+#include "prototypes.h"
9f13c6
+#include "sssd.h"
9f13c6
+
9f13c6
+#define MSG_SSSD_FLUSH_CACHE_FAILED "%s: Failed to flush the sssd cache.\n"
9f13c6
+
9f13c6
+int sssd_flush_cache (int dbflags)
9f13c6
+{
9f13c6
+	int status, code, rv;
9f13c6
+	const char *cmd = "/usr/sbin/sss_cache";
9f13c6
+	char *sss_cache_args = NULL;
9f13c6
+	const char *spawnedArgs[] = {"sss_cache", NULL, NULL};
9f13c6
+	const char *spawnedEnv[] = {NULL};
9f13c6
+	int i = 0;
9f13c6
+
9f13c6
+	sss_cache_args = malloc(4);
9f13c6
+	if (sss_cache_args == NULL) {
9f13c6
+	    return -1;
9f13c6
+	}
9f13c6
+
9f13c6
+	sss_cache_args[i++] = '-';
9f13c6
+	if (dbflags & SSSD_DB_PASSWD) {
9f13c6
+		sss_cache_args[i++] = 'U';
9f13c6
+	}
9f13c6
+	if (dbflags & SSSD_DB_GROUP) {
9f13c6
+		sss_cache_args[i++] = 'G';
9f13c6
+	}
9f13c6
+	sss_cache_args[i++] = '\0';
9f13c6
+	if (i == 2) {
9f13c6
+		/* Neither passwd nor group, nothing to do */
9f13c6
+		free(sss_cache_args);
9f13c6
+		return 0;
9f13c6
+	}
9f13c6
+	spawnedArgs[1] = sss_cache_args;
9f13c6
+
9f13c6
+	rv = run_command (cmd, spawnedArgs, spawnedEnv, &status);
9f13c6
+	free(sss_cache_args);
9f13c6
+	if (rv != 0) {
9f13c6
+		/* run_command writes its own more detailed message. */
9f13c6
+		(void) fprintf (stderr, _(MSG_SSSD_FLUSH_CACHE_FAILED), Prog);
9f13c6
+		return -1;
9f13c6
+	}
9f13c6
+
9f13c6
+	code = WEXITSTATUS (status);
9f13c6
+	if (!WIFEXITED (status)) {
9f13c6
+		(void) fprintf (stderr,
9f13c6
+		                _("%s: sss_cache did not terminate normally (signal %d)\n"),
9f13c6
+		                Prog, WTERMSIG (status));
9f13c6
+		return -1;
9f13c6
+	} else if (code == E_CMD_NOTFOUND) {
9f13c6
+		/* sss_cache is not installed, or it is installed but uses an
9f13c6
+		   interpreter that is missing.  Probably the former. */
9f13c6
+		return 0;
9f13c6
+	} else if (code != 0) {
9f13c6
+		(void) fprintf (stderr, _("%s: sss_cache exited with status %d\n"),
9f13c6
+		                Prog, code);
9f13c6
+		(void) fprintf (stderr, _(MSG_SSSD_FLUSH_CACHE_FAILED), Prog);
9f13c6
+		return -1;
9f13c6
+	}
9f13c6
+
9f13c6
+	return 0;
9f13c6
+}
9f13c6
+#else				/* USE_SSSD */
9f13c6
+extern int errno;		/* warning: ANSI C forbids an empty source file */
9f13c6
+#endif				/* USE_SSSD */
9f13c6
+
9f13c6
diff --git a/lib/sssd.h b/lib/sssd.h
9f13c6
new file mode 100644
9f13c6
index 00000000..00ff2a8a
9f13c6
--- /dev/null
9f13c6
+++ b/lib/sssd.h
9f13c6
@@ -0,0 +1,17 @@
9f13c6
+#ifndef _SSSD_H_
9f13c6
+#define _SSSD_H_
9f13c6
+
9f13c6
+#define SSSD_DB_PASSWD	0x001
9f13c6
+#define SSSD_DB_GROUP	0x002
9f13c6
+
9f13c6
+/*
9f13c6
+ * sssd_flush_cache - flush specified service buffer in sssd cache
9f13c6
+ */
9f13c6
+#ifdef	USE_SSSD
9f13c6
+extern int sssd_flush_cache (int dbflags);
9f13c6
+#else
9f13c6
+#define sssd_flush_cache(service) (0)
9f13c6
+#endif
9f13c6
+
9f13c6
+#endif
9f13c6
+
9f13c6
diff --git a/src/chfn.c b/src/chfn.c
9f13c6
index 18aa3de7..0725e1c7 100644
9f13c6
--- a/src/chfn.c
9f13c6
+++ b/src/chfn.c
9f13c6
@@ -47,6 +47,7 @@
9f13c6
 #include "defines.h"
9f13c6
 #include "getdef.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #ifdef USE_PAM
9f13c6
 #include "pam_defs.h"
9f13c6
 #endif
9f13c6
@@ -746,6 +747,7 @@ int main (int argc, char **argv)
9f13c6
 	SYSLOG ((LOG_INFO, "changed user '%s' information", user));
9f13c6
 
9f13c6
 	nscd_flush_cache ("passwd");
9f13c6
+	sssd_flush_cache (SSSD_DB_PASSWD);
9f13c6
 
9f13c6
 	closelog ();
9f13c6
 	exit (E_SUCCESS);
9f13c6
diff --git a/src/chgpasswd.c b/src/chgpasswd.c
9f13c6
index 13203a46..e5f2eb7e 100644
9f13c6
--- a/src/chgpasswd.c
9f13c6
+++ b/src/chgpasswd.c
9f13c6
@@ -46,6 +46,7 @@
9f13c6
 #endif				/* ACCT_TOOLS_SETUID */
9f13c6
 #include "defines.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "prototypes.h"
9f13c6
 #include "groupio.h"
9f13c6
 #ifdef	SHADOWGRP
9f13c6
@@ -581,6 +582,7 @@ int main (int argc, char **argv)
9f13c6
 	close_files ();
9f13c6
 
9f13c6
 	nscd_flush_cache ("group");
9f13c6
+	sssd_flush_cache (SSSD_DB_GROUP);
9f13c6
 
9f13c6
 	return (0);
9f13c6
 }
9f13c6
diff --git a/src/chpasswd.c b/src/chpasswd.c
9f13c6
index 918b27ee..49e79cdb 100644
9f13c6
--- a/src/chpasswd.c
9f13c6
+++ b/src/chpasswd.c
9f13c6
@@ -44,6 +44,7 @@
9f13c6
 #endif				/* USE_PAM */
9f13c6
 #include "defines.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "getdef.h"
9f13c6
 #include "prototypes.h"
9f13c6
 #include "pwio.h"
9f13c6
@@ -624,6 +625,7 @@ int main (int argc, char **argv)
9f13c6
 	}
9f13c6
 
9f13c6
 	nscd_flush_cache ("passwd");
9f13c6
+	sssd_flush_cache (SSSD_DB_PASSWD);
9f13c6
 
9f13c6
 	return (0);
9f13c6
 }
9f13c6
diff --git a/src/chsh.c b/src/chsh.c
9f13c6
index c89708b9..910e3dd4 100644
9f13c6
--- a/src/chsh.c
9f13c6
+++ b/src/chsh.c
9f13c6
@@ -46,6 +46,7 @@
9f13c6
 #include "defines.h"
9f13c6
 #include "getdef.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "prototypes.h"
9f13c6
 #include "pwauth.h"
9f13c6
 #include "pwio.h"
9f13c6
@@ -557,6 +558,7 @@ int main (int argc, char **argv)
9f13c6
 	SYSLOG ((LOG_INFO, "changed user '%s' shell to '%s'", user, loginsh));
9f13c6
 
9f13c6
 	nscd_flush_cache ("passwd");
9f13c6
+	sssd_flush_cache (SSSD_DB_PASSWD);
9f13c6
 
9f13c6
 	closelog ();
9f13c6
 	exit (E_SUCCESS);
9f13c6
diff --git a/src/gpasswd.c b/src/gpasswd.c
9f13c6
index c4a492b1..4d75af96 100644
9f13c6
--- a/src/gpasswd.c
9f13c6
+++ b/src/gpasswd.c
9f13c6
@@ -45,6 +45,7 @@
9f13c6
 #include "defines.h"
9f13c6
 #include "groupio.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "prototypes.h"
9f13c6
 #ifdef SHADOWGRP
9f13c6
 #include "sgroupio.h"
9f13c6
@@ -1201,6 +1202,7 @@ int main (int argc, char **argv)
9f13c6
 	close_files ();
9f13c6
 
9f13c6
 	nscd_flush_cache ("group");
9f13c6
+	sssd_flush_cache (SSSD_DB_GROUP);
9f13c6
 
9f13c6
 	exit (E_SUCCESS);
9f13c6
 }
9f13c6
diff --git a/src/groupadd.c b/src/groupadd.c
9f13c6
index b57006c5..2dd8eec9 100644
9f13c6
--- a/src/groupadd.c
9f13c6
+++ b/src/groupadd.c
9f13c6
@@ -51,6 +51,7 @@
9f13c6
 #include "getdef.h"
9f13c6
 #include "groupio.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "prototypes.h"
9f13c6
 #ifdef	SHADOWGRP
9f13c6
 #include "sgroupio.h"
9f13c6
@@ -625,6 +626,7 @@ int main (int argc, char **argv)
9f13c6
 	close_files ();
9f13c6
 
9f13c6
 	nscd_flush_cache ("group");
9f13c6
+	sssd_flush_cache (SSSD_DB_GROUP);
9f13c6
 
9f13c6
 	return E_SUCCESS;
9f13c6
 }
9f13c6
diff --git a/src/groupdel.c b/src/groupdel.c
9f13c6
index 70bed010..f941a84a 100644
9f13c6
--- a/src/groupdel.c
9f13c6
+++ b/src/groupdel.c
9f13c6
@@ -49,6 +49,7 @@
9f13c6
 #include "defines.h"
9f13c6
 #include "groupio.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "prototypes.h"
9f13c6
 #ifdef	SHADOWGRP
9f13c6
 #include "sgroupio.h"
9f13c6
@@ -492,6 +493,7 @@ int main (int argc, char **argv)
9f13c6
 	close_files ();
9f13c6
 
9f13c6
 	nscd_flush_cache ("group");
9f13c6
+	sssd_flush_cache (SSSD_DB_GROUP);
9f13c6
 
9f13c6
 	return E_SUCCESS;
9f13c6
 }
9f13c6
diff --git a/src/groupmod.c b/src/groupmod.c
9f13c6
index b293b98f..1dca5fc9 100644
9f13c6
--- a/src/groupmod.c
9f13c6
+++ b/src/groupmod.c
9f13c6
@@ -51,6 +51,7 @@
9f13c6
 #include "groupio.h"
9f13c6
 #include "pwio.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "prototypes.h"
9f13c6
 #ifdef	SHADOWGRP
9f13c6
 #include "sgroupio.h"
9f13c6
@@ -877,6 +878,7 @@ int main (int argc, char **argv)
9f13c6
 	close_files ();
9f13c6
 
9f13c6
 	nscd_flush_cache ("group");
9f13c6
+	sssd_flush_cache (SSSD_DB_GROUP);
9f13c6
 
9f13c6
 	return E_SUCCESS;
9f13c6
 }
9f13c6
diff --git a/src/grpck.c b/src/grpck.c
9f13c6
index ea5d3b39..6140b10d 100644
9f13c6
--- a/src/grpck.c
9f13c6
+++ b/src/grpck.c
9f13c6
@@ -45,6 +45,7 @@
9f13c6
 #include "defines.h"
9f13c6
 #include "groupio.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "prototypes.h"
9f13c6
 
9f13c6
 #ifdef SHADOWGRP
9f13c6
@@ -870,6 +871,7 @@ int main (int argc, char **argv)
9f13c6
 	close_files (changed);
9f13c6
 
9f13c6
 	nscd_flush_cache ("group");
9f13c6
+	sssd_flush_cache (SSSD_DB_GROUP);
9f13c6
 
9f13c6
 	/*
9f13c6
 	 * Tell the user what we did and exit.
9f13c6
diff --git a/src/grpconv.c b/src/grpconv.c
9f13c6
index f95f4960..5e5eaaca 100644
9f13c6
--- a/src/grpconv.c
9f13c6
+++ b/src/grpconv.c
9f13c6
@@ -48,6 +48,7 @@
9f13c6
 #include <unistd.h>
9f13c6
 #include <getopt.h>
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "prototypes.h"
9f13c6
 /*@-exitarg@*/
9f13c6
 #include "exitcodes.h"
9f13c6
@@ -273,6 +274,7 @@ int main (int argc, char **argv)
9f13c6
 	}
9f13c6
 
9f13c6
 	nscd_flush_cache ("group");
9f13c6
+	sssd_flush_cache (SSSD_DB_GROUP);
9f13c6
 
9f13c6
 	return 0;
9f13c6
 }
9f13c6
diff --git a/src/grpunconv.c b/src/grpunconv.c
9f13c6
index 253f06f5..e4105c26 100644
9f13c6
--- a/src/grpunconv.c
9f13c6
+++ b/src/grpunconv.c
9f13c6
@@ -48,6 +48,7 @@
9f13c6
 #include <grp.h>
9f13c6
 #include <getopt.h>
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "prototypes.h"
9f13c6
 /*@-exitarg@*/
9f13c6
 #include "exitcodes.h"
9f13c6
@@ -236,6 +237,7 @@ int main (int argc, char **argv)
9f13c6
 	}
9f13c6
 
9f13c6
 	nscd_flush_cache ("group");
9f13c6
+	sssd_flush_cache (SSSD_DB_GROUP);
9f13c6
 
9f13c6
 	return 0;
9f13c6
 }
9f13c6
diff --git a/src/newusers.c b/src/newusers.c
9f13c6
index 8e4bef97..7c3bb1c2 100644
9f13c6
--- a/src/newusers.c
9f13c6
+++ b/src/newusers.c
9f13c6
@@ -62,6 +62,7 @@
9f13c6
 #include "getdef.h"
9f13c6
 #include "groupio.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "pwio.h"
9f13c6
 #include "sgroupio.h"
9f13c6
 #include "shadowio.h"
9f13c6
@@ -1233,6 +1234,7 @@ int main (int argc, char **argv)
9f13c6
 
9f13c6
 	nscd_flush_cache ("passwd");
9f13c6
 	nscd_flush_cache ("group");
9f13c6
+	sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP);
9f13c6
 
9f13c6
 #ifdef USE_PAM
9f13c6
 	unsigned int i;
9f13c6
diff --git a/src/passwd.c b/src/passwd.c
9f13c6
index 3af3e651..5bea2765 100644
9f13c6
--- a/src/passwd.c
9f13c6
+++ b/src/passwd.c
9f13c6
@@ -51,6 +51,7 @@
9f13c6
 #include "defines.h"
9f13c6
 #include "getdef.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "prototypes.h"
9f13c6
 #include "pwauth.h"
9f13c6
 #include "pwio.h"
9f13c6
@@ -1150,6 +1151,7 @@ int main (int argc, char **argv)
9f13c6
 
9f13c6
 	nscd_flush_cache ("passwd");
9f13c6
 	nscd_flush_cache ("group");
9f13c6
+	sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP);
9f13c6
 
9f13c6
 	SYSLOG ((LOG_INFO, "password for '%s' changed by '%s'", name, myname));
9f13c6
 	closelog ();
9f13c6
diff --git a/src/pwck.c b/src/pwck.c
9f13c6
index 05df68ec..0ffb711e 100644
9f13c6
--- a/src/pwck.c
9f13c6
+++ b/src/pwck.c
9f13c6
@@ -48,6 +48,7 @@
9f13c6
 #include "shadowio.h"
9f13c6
 #include "getdef.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #ifdef WITH_TCB
9f13c6
 #include "tcbfuncs.h"
9f13c6
 #endif				/* WITH_TCB */
9f13c6
@@ -877,6 +878,7 @@ int main (int argc, char **argv)
9f13c6
 	close_files (changed);
9f13c6
 
9f13c6
 	nscd_flush_cache ("passwd");
9f13c6
+	sssd_flush_cache (SSSD_DB_PASSWD);
9f13c6
 
9f13c6
 	/*
9f13c6
 	 * Tell the user what we did and exit.
9f13c6
diff --git a/src/pwconv.c b/src/pwconv.c
9f13c6
index d6ee31a8..9c69fa13 100644
9f13c6
--- a/src/pwconv.c
9f13c6
+++ b/src/pwconv.c
9f13c6
@@ -72,6 +72,7 @@
9f13c6
 #include "pwio.h"
9f13c6
 #include "shadowio.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 
9f13c6
 /*
9f13c6
  * exit status values
9f13c6
@@ -328,6 +329,7 @@ int main (int argc, char **argv)
9f13c6
 	}
9f13c6
 
9f13c6
 	nscd_flush_cache ("passwd");
9f13c6
+	sssd_flush_cache (SSSD_DB_PASSWD);
9f13c6
 
9f13c6
 	return E_SUCCESS;
9f13c6
 }
9f13c6
diff --git a/src/pwunconv.c b/src/pwunconv.c
9f13c6
index fabf0237..e11ea494 100644
9f13c6
--- a/src/pwunconv.c
9f13c6
+++ b/src/pwunconv.c
9f13c6
@@ -42,6 +42,7 @@
9f13c6
 #include <getopt.h>
9f13c6
 #include "defines.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "prototypes.h"
9f13c6
 #include "pwio.h"
9f13c6
 #include "shadowio.h"
9f13c6
@@ -250,6 +251,7 @@ int main (int argc, char **argv)
9f13c6
 	}
9f13c6
 
9f13c6
 	nscd_flush_cache ("passwd");
9f13c6
+	sssd_flush_cache (SSSD_DB_PASSWD);
9f13c6
 
9f13c6
 	return 0;
9f13c6
 }
9f13c6
diff --git a/src/useradd.c b/src/useradd.c
9f13c6
index ca90f076..b0c2224d 100644
9f13c6
--- a/src/useradd.c
9f13c6
+++ b/src/useradd.c
9f13c6
@@ -60,6 +60,7 @@
9f13c6
 #include "getdef.h"
9f13c6
 #include "groupio.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "prototypes.h"
9f13c6
 #include "pwauth.h"
9f13c6
 #include "pwio.h"
9f13c6
@@ -2425,6 +2426,7 @@ int main (int argc, char **argv)
9f13c6
 
9f13c6
 	nscd_flush_cache ("passwd");
9f13c6
 	nscd_flush_cache ("group");
9f13c6
+	sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP);
9f13c6
 
9f13c6
 	/*
9f13c6
 	 * tallylog_reset needs to be able to lookup
9f13c6
diff --git a/src/userdel.c b/src/userdel.c
9f13c6
index c8de1d31..0715e4fe 100644
9f13c6
--- a/src/userdel.c
9f13c6
+++ b/src/userdel.c
9f13c6
@@ -53,6 +53,7 @@
9f13c6
 #include "getdef.h"
9f13c6
 #include "groupio.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "prototypes.h"
9f13c6
 #include "pwauth.h"
9f13c6
 #include "pwio.h"
9f13c6
@@ -1328,6 +1329,7 @@ int main (int argc, char **argv)
9f13c6
 
9f13c6
 	nscd_flush_cache ("passwd");
9f13c6
 	nscd_flush_cache ("group");
9f13c6
+	sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP);
9f13c6
 
9f13c6
 	return ((0 != errors) ? E_HOMEDIR : E_SUCCESS);
9f13c6
 }
9f13c6
diff --git a/src/usermod.c b/src/usermod.c
9f13c6
index 7355ad31..fd9a98a6 100644
9f13c6
--- a/src/usermod.c
9f13c6
+++ b/src/usermod.c
9f13c6
@@ -57,6 +57,7 @@
9f13c6
 #include "getdef.h"
9f13c6
 #include "groupio.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "prototypes.h"
9f13c6
 #include "pwauth.h"
9f13c6
 #include "pwio.h"
9f13c6
@@ -2255,6 +2256,7 @@ int main (int argc, char **argv)
9f13c6
 
9f13c6
 	nscd_flush_cache ("passwd");
9f13c6
 	nscd_flush_cache ("group");
9f13c6
+	sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP);
9f13c6
 
9f13c6
 #ifdef WITH_SELINUX
9f13c6
 	if (Zflg) {
9f13c6
diff --git a/src/vipw.c b/src/vipw.c
9f13c6
index 6d730f65..2cfac6b4 100644
9f13c6
--- a/src/vipw.c
9f13c6
+++ b/src/vipw.c
9f13c6
@@ -42,6 +42,7 @@
9f13c6
 #include "defines.h"
9f13c6
 #include "groupio.h"
9f13c6
 #include "nscd.h"
9f13c6
+#include "sssd.h"
9f13c6
 #include "prototypes.h"
9f13c6
 #include "pwio.h"
9f13c6
 #include "sgroupio.h"
9f13c6
@@ -556,6 +557,7 @@ int main (int argc, char **argv)
9f13c6
 
9f13c6
 	nscd_flush_cache ("passwd");
9f13c6
 	nscd_flush_cache ("group");
9f13c6
+	sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP);
9f13c6
 
9f13c6
 	return E_SUCCESS;
9f13c6
 }