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