From 83bf46f4066e3d5e838a32357c201de9bd6ecdfd Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Wed, 12 Feb 2014 10:12:59 -0500 Subject: Update DEBUG* invocations to use new levels Use a script to update DEBUG* macro invocations, which use literal numbers for levels, to use bitmask macros instead: grep -rl --include '*.[hc]' DEBUG . | while read f; do mv "$f"{,.orig} perl -e 'use strict; use File::Slurp; my @map=qw" SSSDBG_FATAL_FAILURE SSSDBG_CRIT_FAILURE SSSDBG_OP_FAILURE SSSDBG_MINOR_FAILURE SSSDBG_CONF_SETTINGS SSSDBG_FUNC_DATA SSSDBG_TRACE_FUNC SSSDBG_TRACE_LIBS SSSDBG_TRACE_INTERNAL SSSDBG_TRACE_ALL "; my $text=read_file(\*STDIN); my $repl; $text=~s/ ^ ( .* \b (DEBUG|DEBUG_PAM_DATA|DEBUG_GR_MEM) \s* \(\s* )( [0-9] )( \s*, ) ( \s* ) ( .* ) $ / $repl = $1.$map[$3].$4.$5.$6, length($repl) <= 80 ? $repl : $1.$map[$3].$4."\n".(" " x length($1)).$6 /xmge; print $text; ' < "$f.orig" > "$f" rm "$f.orig" done Reviewed-by: Jakub Hrozek Reviewed-by: Stephen Gallagher Reviewed-by: Simo Sorce --- src/tools/tools_util.c | 69 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 27 deletions(-) (limited to 'src/tools/tools_util.c') diff --git a/src/tools/tools_util.c b/src/tools/tools_util.c index 42563dad4..68f6588ea 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 { @@ -226,7 +230,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; } } @@ -279,26 +284,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; @@ -327,7 +334,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; } @@ -372,7 +380,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; } @@ -392,19 +401,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; } @@ -436,7 +446,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; } @@ -444,7 +454,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; } @@ -452,7 +462,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; } @@ -460,7 +470,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)); } @@ -469,7 +479,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)); } } @@ -491,7 +502,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; } @@ -542,22 +554,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; } -- cgit