summaryrefslogtreecommitdiffabout
path: root/src/gpg.c
authorSergey Poznyakoff <gray@gnu.org.ua>2013-03-10 21:25:11 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-03-10 21:26:52 (GMT)
commit39a97e438dde837ada9a99cceea93a1cf97db19e (patch) (side-by-side diff)
treeefc492dcfcdc2c21bfdec5c31692b348601cd94a /src/gpg.c
parent87602f5492b842f734dffe22f4e2f85dbc6ce713 (diff)
downloadwydawca-39a97e438dde837ada9a99cceea93a1cf97db19e.tar.gz
wydawca-39a97e438dde837ada9a99cceea93a1cf97db19e.tar.bz2
Provide a convenient debugging macro.
Rename logmsg to wy_log.
Diffstat (limited to 'src/gpg.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/gpg.c62
1 files changed, 27 insertions, 35 deletions
diff --git a/src/gpg.c b/src/gpg.c
index 1eb1db8..7b5146e 100644
--- a/src/gpg.c
+++ b/src/gpg.c
@@ -22,7 +22,7 @@
#define fail_if_err(expr) do { \
int a = expr; \
if (a) { \
- logmsg(LOG_ERR, _("%s: GPGME error: %s"), #expr, \
+ wy_log(LOG_ERR, _("%s: GPGME error: %s"), #expr, \
gpgme_strerror(a)); \
return 1; \
} \
@@ -42,14 +42,14 @@ recursive_rmdir(const char *name)
struct dirent *ent;
if (chdir(name)) {
- logmsg(LOG_ERR, _("cannot change to directory %s: %s"),
+ wy_log(LOG_ERR, _("cannot change to directory %s: %s"),
name, strerror(errno));
return 1;
}
dir = opendir(".");
if (!dir) {
- logmsg(LOG_ERR, _("cannot open directory %s: %s"),
+ wy_log(LOG_ERR, _("cannot open directory %s: %s"),
name, strerror(errno));
return 1;
}
@@ -62,13 +62,13 @@ recursive_rmdir(const char *name)
continue;
if (stat(ent->d_name, &st) && errno != ENOENT) {
- logmsg(LOG_ERR, _("cannot stat file `%s': %s"),
+ wy_log(LOG_ERR, _("cannot stat file `%s': %s"),
name, strerror(errno));
rc = 1;
} else if (S_ISDIR(st.st_mode))
rc = rmdir_r(ent->d_name);
else if ((rc = unlink(ent->d_name)) != 0 && errno != ENOENT)
- logmsg(LOG_ERR, _("cannot unlink %s: %s"),
+ wy_log(LOG_ERR, _("cannot unlink %s: %s"),
ent->d_name, strerror(errno));
}
closedir(dir);
@@ -83,19 +83,19 @@ rmdir_r(const char *name)
int rc;
if (push_dir(NULL)) {
- logmsg(LOG_ERR, _("cannot save current directory: %s"),
+ wy_log(LOG_ERR, _("cannot save current directory: %s"),
strerror(errno));
return 1;
}
rc = recursive_rmdir(name);
if (pop_dir()) {
- logmsg(LOG_ERR, _("cannot restore current directory: %s"),
+ wy_log(LOG_ERR, _("cannot restore current directory: %s"),
strerror(errno));
rc = 1;
}
if (rc == 0 && rmdir(name)) {
- logmsg(LOG_ERR, _("cannot remove directory %s: %s"),
+ wy_log(LOG_ERR, _("cannot remove directory %s: %s"),
name, strerror(errno));
return 1;
}
@@ -107,11 +107,9 @@ rmdir_r(const char *name)
static void
remove_homedir()
{
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, _("removing GNUPG home directory: %s"),
- temp_homedir);
+ wy_debug(2, (_("removing GNUPG home directory: %s"), temp_homedir));
if (rmdir_r(temp_homedir))
- logmsg(LOG_CRIT, _("failed to remove GPG directory %s"),
+ wy_log(LOG_CRIT, _("failed to remove GPG directory %s"),
temp_homedir);
}
@@ -124,14 +122,13 @@ create_gpg_homedir()
temp_homedir = grecs_strdup("/tmp/wydawca-XXXXXX");
if (!mkdtemp(temp_homedir)) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("cannot create GPG home directory (%s): %s"),
temp_homedir, strerror(errno));
return 1;
}
atexit(remove_homedir);
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, _("GNUPG home directory: %s"), temp_homedir);
+ wy_debug(2, (_("GNUPG home directory: %s"), temp_homedir));
setenv("GNUPGHOME", temp_homedir, 1);
return 0;
}
@@ -141,12 +138,11 @@ checksig(gpgme_signature_t sig, const char *uid, struct file_triplet *trp)
{
switch (gpg_err_code(sig->status)) {
case GPG_ERR_NO_ERROR:
- if (wy_debug_level)
- logmsg(LOG_NOTICE, _("Good signature from %s"), uid);
+ wy_debug(1, (_("Good signature from %s"), uid));
trp->uploader = uploader_find_frp(trp->uploader_list,
sig->fpr);
if (!trp->uploader) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("good signature from %s, "
"but the uploader info for %s not found"),
uid, sig->fpr);
@@ -156,31 +152,31 @@ checksig(gpgme_signature_t sig, const char *uid, struct file_triplet *trp)
case GPG_ERR_BAD_SIGNATURE:
UPDATE_STATS(STAT_BAD_SIGNATURE);
- logmsg(LOG_ERR, _("BAD signature from %s"), uid);
+ wy_log(LOG_ERR, _("BAD signature from %s"), uid);
return 0;
case GPG_ERR_NO_PUBKEY:
UPDATE_STATS(STAT_ACCESS_VIOLATIONS);
- logmsg(LOG_ERR, _("No public key"));
+ wy_log(LOG_ERR, _("No public key"));
return 0;
case GPG_ERR_NO_DATA:
UPDATE_STATS(STAT_BAD_TRIPLETS);
- logmsg(LOG_ERR, _("No signature"));
+ wy_log(LOG_ERR, _("No signature"));
return 0;
case GPG_ERR_SIG_EXPIRED:
UPDATE_STATS(STAT_BAD_SIGNATURE);
- logmsg(LOG_ERR, _("Expired signature from %s"), uid);
+ wy_log(LOG_ERR, _("Expired signature from %s"), uid);
return 0;
case GPG_ERR_KEY_EXPIRED:
UPDATE_STATS(STAT_BAD_SIGNATURE);
- logmsg(LOG_ERR, _("Key expired (%s)"), uid);
+ wy_log(LOG_ERR, _("Key expired (%s)"), uid);
return 0;
default:
- logmsg(LOG_ERR, _("Unknown signature error"));
+ wy_log(LOG_ERR, _("Unknown signature error"));
return 0;
}
return -1;
@@ -234,10 +230,8 @@ verify_directive_signature(struct file_triplet *trp)
res = gpgme_op_import_result(ctx);
pstat = res->imports;
uptr->fpr = grecs_strdup(pstat->fpr);
- if (wy_debug_level > 2)
- logmsg(LOG_DEBUG,
- _("imported key: user = %s, fingerprint = %s"),
- uptr->name, uptr->fpr);
+ wy_debug(3, (_("imported key: user = %s, fingerprint = %s"),
+ uptr->name, uptr->fpr));
}
fail_if_err(gpgme_data_new_from_file(&directive_data,
@@ -259,7 +253,7 @@ verify_directive_signature(struct file_triplet *trp)
} else {
rc = 1;
UPDATE_STATS(STAT_BAD_SIGNATURE);
- logmsg(LOG_ERR, _("%s: directive verification failed: %s"),
+ wy_log(LOG_ERR, _("%s: directive verification failed: %s"),
trp->name, gpgme_strerror(ec));
}
@@ -287,7 +281,7 @@ verify_detached_signature(struct file_triplet *trp)
while (info && info->protocol != GPGME_PROTOCOL_OpenPGP)
info = info->next;
if (!info) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("cannot find path to gpg binary (attempting to "
"verify the detached signature for %s"), trp->name);
return 1;
@@ -302,19 +296,17 @@ verify_detached_signature(struct file_triplet *trp)
switch (wydawca_exec(5, argv, NULL)) {
case exec_success:
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("good detached signature for %s"),
- trp->name);
+ wy_debug(1, (_("good detached signature for %s"), trp->name));
return 0;
case exec_fail:
UPDATE_STATS(STAT_BAD_SIGNATURE);
- logmsg(LOG_ERR, _("BAD detached signature for %s"), trp->name);
+ wy_log(LOG_ERR, _("BAD detached signature for %s"), trp->name);
notify(spool->notification, trp, ev_bad_detached_signature);
break;
case exec_error:
- logmsg(LOG_CRIT, _("cannot verify detached signature for %s"),
+ wy_log(LOG_CRIT, _("cannot verify detached signature for %s"),
trp->name);
break;
}

Return to:

Send suggestions and report system problems to the System administrator.