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

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