2007-11-17 19:34:05 +05:30
|
|
|
/* Author: Peter Vrabec <pvrabec@redhat.com> */
|
2007-10-07 17:15:23 +05:30
|
|
|
|
2008-08-31 00:00:36 +05:30
|
|
|
#include <config.h>
|
|
|
|
#ifdef USE_NSCD
|
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
#include <stdio.h>
|
2007-11-17 19:34:05 +05:30
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/types.h>
|
2011-08-20 19:03:38 +05:30
|
|
|
#include "exitcodes.h"
|
2008-06-11 01:31:55 +05:30
|
|
|
#include "defines.h"
|
2011-09-19 02:32:43 +05:30
|
|
|
#include "prototypes.h"
|
2008-01-06 19:27:17 +05:30
|
|
|
#include "nscd.h"
|
2007-10-07 17:15:23 +05:30
|
|
|
|
2011-09-19 02:32:43 +05:30
|
|
|
#define MSG_NSCD_FLUSH_CACHE_FAILED "%s: Failed to flush the nscd cache.\n"
|
2008-06-11 01:31:55 +05:30
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
/*
|
2007-11-17 19:34:05 +05:30
|
|
|
* nscd_flush_cache - flush specified service buffer in nscd cache
|
2007-10-07 17:15:23 +05:30
|
|
|
*/
|
2008-01-06 19:27:17 +05:30
|
|
|
int nscd_flush_cache (const char *service)
|
2007-10-07 17:15:23 +05:30
|
|
|
{
|
2011-09-19 02:32:43 +05:30
|
|
|
int status, code;
|
|
|
|
const char *cmd = "/usr/sbin/nscd";
|
|
|
|
const char *spawnedArgs[] = {"nscd", "-i", service, NULL};
|
2011-08-20 19:03:38 +05:30
|
|
|
const char *spawnedEnv[] = {NULL};
|
2007-11-17 19:34:05 +05:30
|
|
|
|
2011-09-19 02:32:43 +05:30
|
|
|
if (run_command (cmd, spawnedArgs, spawnedEnv, &status) != 0) {
|
2011-08-20 19:03:38 +05:30
|
|
|
/* run_command writes its own more detailed message. */
|
2021-05-09 04:12:14 +05:30
|
|
|
(void) fprintf (shadow_logfd, _(MSG_NSCD_FLUSH_CACHE_FAILED), Prog);
|
2007-10-07 17:15:23 +05:30
|
|
|
return -1;
|
2007-11-17 19:34:05 +05:30
|
|
|
}
|
2011-09-19 02:32:43 +05:30
|
|
|
|
|
|
|
code = WEXITSTATUS (status);
|
|
|
|
if (!WIFEXITED (status)) {
|
2021-05-09 04:12:14 +05:30
|
|
|
(void) fprintf (shadow_logfd,
|
2011-09-19 02:32:43 +05:30
|
|
|
_("%s: nscd did not terminate normally (signal %d)\n"),
|
|
|
|
Prog, WTERMSIG (status));
|
|
|
|
return -1;
|
|
|
|
} else if (code == E_CMD_NOTFOUND) {
|
2011-08-20 19:03:38 +05:30
|
|
|
/* nscd is not installed, or it is installed but uses an
|
|
|
|
interpreter that is missing. Probably the former. */
|
|
|
|
return 0;
|
2012-02-14 01:39:59 +05:30
|
|
|
} else if (code == 1) {
|
|
|
|
/* nscd is installed, but it isn't active. */
|
|
|
|
return 0;
|
2011-09-19 02:32:43 +05:30
|
|
|
} else if (code != 0) {
|
2021-05-09 04:12:14 +05:30
|
|
|
(void) fprintf (shadow_logfd, _("%s: nscd exited with status %d\n"),
|
2011-09-19 02:32:43 +05:30
|
|
|
Prog, code);
|
2021-05-09 04:12:14 +05:30
|
|
|
(void) fprintf (shadow_logfd, _(MSG_NSCD_FLUSH_CACHE_FAILED), Prog);
|
2007-11-17 19:34:05 +05:30
|
|
|
return -1;
|
|
|
|
}
|
2011-09-19 02:32:43 +05:30
|
|
|
|
2007-11-17 19:34:05 +05:30
|
|
|
return 0;
|
2007-10-07 17:15:23 +05:30
|
|
|
}
|
2008-08-31 00:03:13 +05:30
|
|
|
#else /* USE_NSCD */
|
|
|
|
extern int errno; /* warning: ANSI C forbids an empty source file */
|
|
|
|
#endif /* USE_NSCD */
|
2007-11-17 19:34:05 +05:30
|
|
|
|