summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2010-03-22 22:10:29 +0100
committerStephen Gallagher <sgallagh@redhat.com>2010-04-06 14:33:43 -0400
commit4aa841c5724f313435aeea1c0319e81bb0d14321 (patch)
treea8443c64d42b51954a130f3a38ca2750c48c0e2b /src/tools
parent7acaaa6c6563cf3b8ab20bf6431898d20d735842 (diff)
downloadsssd-4aa841c5724f313435aeea1c0319e81bb0d14321.tar.gz
sssd-4aa841c5724f313435aeea1c0319e81bb0d14321.tar.bz2
sssd-4aa841c5724f313435aeea1c0319e81bb0d14321.zip
Add userdel_cmd param
Fixes: #231
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/sss_userdel.c6
-rw-r--r--src/tools/tools_util.c75
-rw-r--r--src/tools/tools_util.h2
3 files changed, 83 insertions, 0 deletions
diff --git a/src/tools/sss_userdel.c b/src/tools/sss_userdel.c
index e84d78b1..7f17b1fb 100644
--- a/src/tools/sss_userdel.c
+++ b/src/tools/sss_userdel.c
@@ -161,6 +161,12 @@ int main(int argc, const char **argv)
end_transaction(tctx);
+ ret = run_userdel_cmd(tctx);
+ if (ret != EOK) {
+ ERROR("The post-delete command failed: %s\n", strerror(ret));
+ goto fini;
+ }
+
if (tctx->octx->remove_homedir) {
ret = remove_homedir(tctx,
tctx->octx->home,
diff --git a/src/tools/tools_util.c b/src/tools/tools_util.c
index 97945238..9f9382a6 100644
--- a/src/tools/tools_util.c
+++ b/src/tools/tools_util.c
@@ -25,6 +25,7 @@
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <fcntl.h>
#include "config.h"
@@ -518,3 +519,77 @@ done:
return ret;
}
+int run_userdel_cmd(struct tools_ctx *tctx)
+{
+ int ret, status;
+ char *userdel_cmd = NULL;
+ char *conf_path = NULL;
+ pid_t pid, child_pid;
+
+ conf_path = talloc_asprintf(tctx, CONFDB_DOMAIN_PATH_TMPL,
+ tctx->local->name);
+ if (!conf_path) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ ret = confdb_get_string(tctx->confdb, tctx,
+ conf_path, CONFDB_LOCAL_USERDEL_CMD,
+ NULL, &userdel_cmd);
+ if (ret != EOK || !userdel_cmd) {
+ goto done;
+ }
+
+ errno = 0;
+ pid = fork();
+ if (pid == 0) {
+ /* child */
+ execl(userdel_cmd, userdel_cmd,
+ tctx->octx->name, (char *) NULL);
+ exit(errno);
+ } else {
+ /* parent */
+ if (pid == -1) {
+ DEBUG(1, ("fork failed [%d]: %s\n"));
+ ret = errno;
+ goto done;
+ }
+
+ while((child_pid = waitpid(pid, &status, 0)) > 0) {
+ if (child_pid == -1) {
+ DEBUG(1, ("waitpid failed\n"));
+ ret = errno;
+ goto done;
+ }
+
+ if (WIFEXITED(status)) {
+ ret = WEXITSTATUS(status);
+ if (ret != 0) {
+ DEBUG(5, ("command [%s] returned nonzero status %d.\n",
+ userdel_cmd, ret));
+ ret = EOK; /* Ignore return code of the command */
+ goto done;
+ }
+ } else if (WIFSIGNALED(status)) {
+ DEBUG(5, ("command [%s] was terminated by signal %d.\n",
+ userdel_cmd, WTERMSIG(status)));
+ ret = EIO;
+ goto done;
+ } else if (WIFSTOPPED(status)) {
+ DEBUG(5, ("command [%s] was stopped by signal %d.\n",
+ userdel_cmd, WSTOPSIG(status)));
+ continue;
+ } else {
+ DEBUG(1, ("Unknown status from WAITPID\n"));
+ ret = EIO;
+ goto done;
+ }
+ }
+ }
+
+ ret = EOK;
+done:
+ talloc_free(userdel_cmd);
+ talloc_free(conf_path);
+ return ret;
+}
diff --git a/src/tools/tools_util.h b/src/tools/tools_util.h
index a2b5c783..fccec146 100644
--- a/src/tools/tools_util.h
+++ b/src/tools/tools_util.h
@@ -95,6 +95,8 @@ int remove_homedir(TALLOC_CTX *mem_ctx,
const char *username,
uid_t uid, bool force);
+int run_userdel_cmd(struct tools_ctx *tctx);
+
/* from files.c */
int remove_tree(const char *root);