diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2010-03-22 22:10:29 +0100 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2010-04-06 14:33:43 -0400 |
commit | 4aa841c5724f313435aeea1c0319e81bb0d14321 (patch) | |
tree | a8443c64d42b51954a130f3a38ca2750c48c0e2b /src/tools/tools_util.c | |
parent | 7acaaa6c6563cf3b8ab20bf6431898d20d735842 (diff) | |
download | sssd-4aa841c5724f313435aeea1c0319e81bb0d14321.tar.gz sssd-4aa841c5724f313435aeea1c0319e81bb0d14321.tar.xz sssd-4aa841c5724f313435aeea1c0319e81bb0d14321.zip |
Add userdel_cmd param
Fixes: #231
Diffstat (limited to 'src/tools/tools_util.c')
-rw-r--r-- | src/tools/tools_util.c | 75 |
1 files changed, 75 insertions, 0 deletions
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; +} |