summaryrefslogtreecommitdiffstats
path: root/src/tools/tools_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/tools_util.c')
-rw-r--r--src/tools/tools_util.c69
1 files changed, 42 insertions, 27 deletions
diff --git a/src/tools/tools_util.c b/src/tools/tools_util.c
index cddd98b1f..503c6d5bd 100644
--- a/src/tools/tools_util.c
+++ b/src/tools/tools_util.c
@@ -49,14 +49,16 @@ static int setup_db(struct tools_ctx *ctx)
/* Connect to the conf db */
ret = confdb_init(ctx, &ctx->confdb, confdb_path);
if (ret != EOK) {
- DEBUG(1, "Could not initialize connection to the confdb\n");
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "Could not initialize connection to the confdb\n");
return ret;
}
ret = sssd_domain_init(ctx, ctx->confdb, "local", DB_PATH, &ctx->local);
if (ret != EOK) {
SYSDB_VERSION_ERROR(ret);
- DEBUG(1, "Could not initialize connection to the sysdb\n");
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "Could not initialize connection to the sysdb\n");
return ret;
}
ctx->sysdb = ctx->local->sysdb;
@@ -144,7 +146,8 @@ int parse_group_name_domain(struct tools_ctx *tctx,
for (i = 0; groups[i]; ++i) {
ret = sss_parse_name(tctx, tctx->snctx, groups[i], &domain, &name);
if (ret != EOK) {
- DEBUG(1, "Invalid name in group list, skipping: [%s] (%d)\n",
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "Invalid name in group list, skipping: [%s] (%d)\n",
groups[i], ret);
continue;
}
@@ -180,16 +183,17 @@ int parse_name_domain(struct tools_ctx *tctx,
ret = sss_parse_name(tctx, tctx->snctx, fullname, &domain, &tctx->octx->name);
if (ret != EOK) {
- DEBUG(0, "Cannot parse full name\n");
+ DEBUG(SSSDBG_FATAL_FAILURE, "Cannot parse full name\n");
return ret;
}
- DEBUG(5, "Parsed username: %s\n", tctx->octx->name);
+ DEBUG(SSSDBG_FUNC_DATA, "Parsed username: %s\n", tctx->octx->name);
if (domain) {
- DEBUG(5, "Parsed domain: %s\n", domain);
+ DEBUG(SSSDBG_FUNC_DATA, "Parsed domain: %s\n", domain);
/* only the local domain, whatever named is allowed in tools */
if (strcasecmp(domain, tctx->local->name) != 0) {
- DEBUG(1, "Invalid domain %s specified in FQDN\n", domain);
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "Invalid domain %s specified in FQDN\n", domain);
return EINVAL;
}
} else {
@@ -227,7 +231,8 @@ int check_group_names(struct tools_ctx *tctx,
grouplist[i],
groupinfo);
if (ret) {
- DEBUG(6, "Cannot find group %s, ret: %d\n", grouplist[i], ret);
+ DEBUG(SSSDBG_TRACE_FUNC,
+ "Cannot find group %s, ret: %d\n", grouplist[i], ret);
break;
}
}
@@ -280,26 +285,28 @@ int init_sss_tools(struct tools_ctx **_tctx)
tctx = talloc_zero(NULL, struct tools_ctx);
if (tctx == NULL) {
- DEBUG(1, "Could not allocate memory for tools context\n");
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "Could not allocate memory for tools context\n");
return ENOMEM;
}
/* Connect to the database */
ret = setup_db(tctx);
if (ret != EOK) {
- DEBUG(1, "Could not set up database\n");
+ DEBUG(SSSDBG_CRIT_FAILURE, "Could not set up database\n");
goto fini;
}
ret = sss_names_init(tctx, tctx->confdb, tctx->local->name, &tctx->snctx);
if (ret != EOK) {
- DEBUG(1, "Could not set up parsing\n");
+ DEBUG(SSSDBG_CRIT_FAILURE, "Could not set up parsing\n");
goto fini;
}
tctx->octx = talloc_zero(tctx, struct ops_ctx);
if (!tctx->octx) {
- DEBUG(1, "Could not allocate memory for data context\n");
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "Could not allocate memory for data context\n");
ERROR("Out of memory\n");
ret = ENOMEM;
goto fini;
@@ -328,7 +335,8 @@ static int is_owner(uid_t uid, const char *path)
ret = stat(path, &statres);
if (ret != 0) {
ret = errno;
- DEBUG(1, "Cannot stat %s: [%d][%s]\n", path, ret, strerror(ret));
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "Cannot stat %s: [%d][%s]\n", path, ret, strerror(ret));
return ret;
}
@@ -373,7 +381,8 @@ static int remove_mail_spool(TALLOC_CTX *mem_ctx,
ret = unlink(spool_file);
if (ret != 0) {
ret = errno;
- DEBUG(1, "Cannot remove() the spool file %s: [%d][%s]\n",
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "Cannot remove() the spool file %s: [%d][%s]\n",
spool_file, ret, strerror(ret));
goto fail;
}
@@ -393,19 +402,20 @@ int remove_homedir(TALLOC_CTX *mem_ctx,
ret = remove_mail_spool(mem_ctx, maildir, username, uid, force);
if (ret != EOK) {
- DEBUG(1, "Cannot remove user's mail spool\n");
+ DEBUG(SSSDBG_CRIT_FAILURE, "Cannot remove user's mail spool\n");
/* Should this be fatal? I don't think so. Maybe convert to ERROR? */
}
if (force == false && is_owner(uid, homedir) == -1) {
- DEBUG(1, "Not removing home dir - not owned by user\n");
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "Not removing home dir - not owned by user\n");
return EPERM;
}
/* Remove the tree */
ret = remove_tree(homedir);
if (ret != EOK) {
- DEBUG(1, "Cannot remove homedir %s: %d\n",
+ DEBUG(SSSDBG_CRIT_FAILURE, "Cannot remove homedir %s: %d\n",
homedir, ret);
return ret;
}
@@ -437,7 +447,7 @@ int create_mail_spool(TALLOC_CTX *mem_ctx,
fd = open(spool_file, O_CREAT | O_WRONLY | O_EXCL, 0);
if (fd < 0) {
ret = errno;
- DEBUG(1, "Cannot open() the spool file: [%d][%s]\n",
+ DEBUG(SSSDBG_CRIT_FAILURE, "Cannot open() the spool file: [%d][%s]\n",
ret, strerror(ret));
goto fail;
}
@@ -445,7 +455,7 @@ int create_mail_spool(TALLOC_CTX *mem_ctx,
ret = fchmod(fd, 0600);
if (ret != 0) {
ret = errno;
- DEBUG(1, "Cannot fchmod() the spool file: [%d][%s]\n",
+ DEBUG(SSSDBG_CRIT_FAILURE, "Cannot fchmod() the spool file: [%d][%s]\n",
ret, strerror(ret));
goto fail;
}
@@ -453,7 +463,7 @@ int create_mail_spool(TALLOC_CTX *mem_ctx,
ret = fchown(fd, uid, gid);
if (ret != 0) {
ret = errno;
- DEBUG(1, "Cannot fchown() the spool file: [%d][%s]\n",
+ DEBUG(SSSDBG_CRIT_FAILURE, "Cannot fchown() the spool file: [%d][%s]\n",
ret, strerror(ret));
goto fail;
}
@@ -461,7 +471,7 @@ int create_mail_spool(TALLOC_CTX *mem_ctx,
ret = fsync(fd);
if (ret != 0) {
ret = errno;
- DEBUG(1, "Cannot fsync() the spool file: [%d][%s]\n",
+ DEBUG(SSSDBG_CRIT_FAILURE, "Cannot fsync() the spool file: [%d][%s]\n",
ret, strerror(ret));
}
@@ -470,7 +480,8 @@ fail:
ret = close(fd);
if (ret != 0) {
ret = errno;
- DEBUG(1, "Cannot close() the spool file: [%d][%s]\n",
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "Cannot close() the spool file: [%d][%s]\n",
ret, strerror(ret));
}
}
@@ -492,7 +503,8 @@ int create_homedir(const char *skeldir,
ret = copy_tree(skeldir, homedir, 0777 & ~default_umask, uid, gid);
if (ret != EOK) {
- DEBUG(1, "Cannot populate user's home directory: [%d][%s].\n",
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "Cannot populate user's home directory: [%d][%s].\n",
ret, strerror(ret));
goto done;
}
@@ -543,22 +555,25 @@ int run_userdel_cmd(struct tools_ctx *tctx)
if (WIFEXITED(status)) {
ret = WEXITSTATUS(status);
if (ret != 0) {
- DEBUG(5, "command [%s] returned nonzero status %d.\n",
+ DEBUG(SSSDBG_FUNC_DATA,
+ "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",
+ DEBUG(SSSDBG_FUNC_DATA,
+ "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",
+ DEBUG(SSSDBG_FUNC_DATA,
+ "command [%s] was stopped by signal %d.\n",
userdel_cmd, WSTOPSIG(status));
continue;
} else {
- DEBUG(1, "Unknown status from WAITPID\n");
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unknown status from WAITPID\n");
ret = EIO;
goto done;
}