aboutsummaryrefslogtreecommitdiff
path: root/src/gpg.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-03-10 23:25:11 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2013-03-10 23:26:52 +0200
commit39a97e438dde837ada9a99cceea93a1cf97db19e (patch)
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')
-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 @@
22#define fail_if_err(expr) do { \ 22#define fail_if_err(expr) do { \
23 int a = expr; \ 23 int a = expr; \
24 if (a) { \ 24 if (a) { \
25 logmsg(LOG_ERR, _("%s: GPGME error: %s"), #expr, \ 25 wy_log(LOG_ERR, _("%s: GPGME error: %s"), #expr, \
26 gpgme_strerror(a)); \ 26 gpgme_strerror(a)); \
27 return 1; \ 27 return 1; \
28 } \ 28 } \
@@ -42,14 +42,14 @@ recursive_rmdir(const char *name)
42 struct dirent *ent; 42 struct dirent *ent;
43 43
44 if (chdir(name)) { 44 if (chdir(name)) {
45 logmsg(LOG_ERR, _("cannot change to directory %s: %s"), 45 wy_log(LOG_ERR, _("cannot change to directory %s: %s"),
46 name, strerror(errno)); 46 name, strerror(errno));
47 return 1; 47 return 1;
48 } 48 }
49 49
50 dir = opendir("."); 50 dir = opendir(".");
51 if (!dir) { 51 if (!dir) {
52 logmsg(LOG_ERR, _("cannot open directory %s: %s"), 52 wy_log(LOG_ERR, _("cannot open directory %s: %s"),
53 name, strerror(errno)); 53 name, strerror(errno));
54 return 1; 54 return 1;
55 } 55 }
@@ -62,13 +62,13 @@ recursive_rmdir(const char *name)
62 continue; 62 continue;
63 63
64 if (stat(ent->d_name, &st) && errno != ENOENT) { 64 if (stat(ent->d_name, &st) && errno != ENOENT) {
65 logmsg(LOG_ERR, _("cannot stat file `%s': %s"), 65 wy_log(LOG_ERR, _("cannot stat file `%s': %s"),
66 name, strerror(errno)); 66 name, strerror(errno));
67 rc = 1; 67 rc = 1;
68 } else if (S_ISDIR(st.st_mode)) 68 } else if (S_ISDIR(st.st_mode))
69 rc = rmdir_r(ent->d_name); 69 rc = rmdir_r(ent->d_name);
70 else if ((rc = unlink(ent->d_name)) != 0 && errno != ENOENT) 70 else if ((rc = unlink(ent->d_name)) != 0 && errno != ENOENT)
71 logmsg(LOG_ERR, _("cannot unlink %s: %s"), 71 wy_log(LOG_ERR, _("cannot unlink %s: %s"),
72 ent->d_name, strerror(errno)); 72 ent->d_name, strerror(errno));
73 } 73 }
74 closedir(dir); 74 closedir(dir);
@@ -83,19 +83,19 @@ rmdir_r(const char *name)
83 int rc; 83 int rc;
84 84
85 if (push_dir(NULL)) { 85 if (push_dir(NULL)) {
86 logmsg(LOG_ERR, _("cannot save current directory: %s"), 86 wy_log(LOG_ERR, _("cannot save current directory: %s"),
87 strerror(errno)); 87 strerror(errno));
88 return 1; 88 return 1;
89 } 89 }
90 rc = recursive_rmdir(name); 90 rc = recursive_rmdir(name);
91 if (pop_dir()) { 91 if (pop_dir()) {
92 logmsg(LOG_ERR, _("cannot restore current directory: %s"), 92 wy_log(LOG_ERR, _("cannot restore current directory: %s"),
93 strerror(errno)); 93 strerror(errno));
94 rc = 1; 94 rc = 1;
95 } 95 }
96 96
97 if (rc == 0 && rmdir(name)) { 97 if (rc == 0 && rmdir(name)) {
98 logmsg(LOG_ERR, _("cannot remove directory %s: %s"), 98 wy_log(LOG_ERR, _("cannot remove directory %s: %s"),
99 name, strerror(errno)); 99 name, strerror(errno));
100 return 1; 100 return 1;
101 } 101 }
@@ -107,11 +107,9 @@ rmdir_r(const char *name)
107static void 107static void
108remove_homedir() 108remove_homedir()
109{ 109{
110 if (wy_debug_level > 1) 110 wy_debug(2, (_("removing GNUPG home directory: %s"), temp_homedir));
111 logmsg(LOG_DEBUG, _("removing GNUPG home directory: %s"),
112 temp_homedir);
113 if (rmdir_r(temp_homedir)) 111 if (rmdir_r(temp_homedir))
114 logmsg(LOG_CRIT, _("failed to remove GPG directory %s"), 112 wy_log(LOG_CRIT, _("failed to remove GPG directory %s"),
115 temp_homedir); 113 temp_homedir);
116} 114}
117 115
@@ -124,14 +122,13 @@ create_gpg_homedir()
124 122
125 temp_homedir = grecs_strdup("/tmp/wydawca-XXXXXX"); 123 temp_homedir = grecs_strdup("/tmp/wydawca-XXXXXX");
126 if (!mkdtemp(temp_homedir)) { 124 if (!mkdtemp(temp_homedir)) {
127 logmsg(LOG_CRIT, 125 wy_log(LOG_CRIT,
128 _("cannot create GPG home directory (%s): %s"), 126 _("cannot create GPG home directory (%s): %s"),
129 temp_homedir, strerror(errno)); 127 temp_homedir, strerror(errno));
130 return 1; 128 return 1;
131 } 129 }
132 atexit(remove_homedir); 130 atexit(remove_homedir);
133 if (wy_debug_level > 1) 131 wy_debug(2, (_("GNUPG home directory: %s"), temp_homedir));
134 logmsg(LOG_DEBUG, _("GNUPG home directory: %s"), temp_homedir);
135 setenv("GNUPGHOME", temp_homedir, 1); 132 setenv("GNUPGHOME", temp_homedir, 1);
136 return 0; 133 return 0;
137} 134}
@@ -141,12 +138,11 @@ checksig(gpgme_signature_t sig, const char *uid, struct file_triplet *trp)
141{ 138{
142 switch (gpg_err_code(sig->status)) { 139 switch (gpg_err_code(sig->status)) {
143 case GPG_ERR_NO_ERROR: 140 case GPG_ERR_NO_ERROR:
144 if (wy_debug_level) 141 wy_debug(1, (_("Good signature from %s"), uid));
145 logmsg(LOG_NOTICE, _("Good signature from %s"), uid);
146 trp->uploader = uploader_find_frp(trp->uploader_list, 142 trp->uploader = uploader_find_frp(trp->uploader_list,
147 sig->fpr); 143 sig->fpr);
148 if (!trp->uploader) { 144 if (!trp->uploader) {
149 logmsg(LOG_ERR, 145 wy_log(LOG_ERR,
150 _("good signature from %s, " 146 _("good signature from %s, "
151 "but the uploader info for %s not found"), 147 "but the uploader info for %s not found"),
152 uid, sig->fpr); 148 uid, sig->fpr);
@@ -156,31 +152,31 @@ checksig(gpgme_signature_t sig, const char *uid, struct file_triplet *trp)
156 152
157 case GPG_ERR_BAD_SIGNATURE: 153 case GPG_ERR_BAD_SIGNATURE:
158 UPDATE_STATS(STAT_BAD_SIGNATURE); 154 UPDATE_STATS(STAT_BAD_SIGNATURE);
159 logmsg(LOG_ERR, _("BAD signature from %s"), uid); 155 wy_log(LOG_ERR, _("BAD signature from %s"), uid);
160 return 0; 156 return 0;
161 157
162 case GPG_ERR_NO_PUBKEY: 158 case GPG_ERR_NO_PUBKEY:
163 UPDATE_STATS(STAT_ACCESS_VIOLATIONS); 159 UPDATE_STATS(STAT_ACCESS_VIOLATIONS);
164 logmsg(LOG_ERR, _("No public key")); 160 wy_log(LOG_ERR, _("No public key"));
165 return 0; 161 return 0;
166 162
167 case GPG_ERR_NO_DATA: 163 case GPG_ERR_NO_DATA:
168 UPDATE_STATS(STAT_BAD_TRIPLETS); 164 UPDATE_STATS(STAT_BAD_TRIPLETS);
169 logmsg(LOG_ERR, _("No signature")); 165 wy_log(LOG_ERR, _("No signature"));
170 return 0; 166 return 0;
171 167
172 case GPG_ERR_SIG_EXPIRED: 168 case GPG_ERR_SIG_EXPIRED:
173 UPDATE_STATS(STAT_BAD_SIGNATURE); 169 UPDATE_STATS(STAT_BAD_SIGNATURE);
174 logmsg(LOG_ERR, _("Expired signature from %s"), uid); 170 wy_log(LOG_ERR, _("Expired signature from %s"), uid);
175 return 0; 171 return 0;
176 172
177 case GPG_ERR_KEY_EXPIRED: 173 case GPG_ERR_KEY_EXPIRED:
178 UPDATE_STATS(STAT_BAD_SIGNATURE); 174 UPDATE_STATS(STAT_BAD_SIGNATURE);
179 logmsg(LOG_ERR, _("Key expired (%s)"), uid); 175 wy_log(LOG_ERR, _("Key expired (%s)"), uid);
180 return 0; 176 return 0;
181 177
182 default: 178 default:
183 logmsg(LOG_ERR, _("Unknown signature error")); 179 wy_log(LOG_ERR, _("Unknown signature error"));
184 return 0; 180 return 0;
185 } 181 }
186 return -1; 182 return -1;
@@ -234,10 +230,8 @@ verify_directive_signature(struct file_triplet *trp)
234 res = gpgme_op_import_result(ctx); 230 res = gpgme_op_import_result(ctx);
235 pstat = res->imports; 231 pstat = res->imports;
236 uptr->fpr = grecs_strdup(pstat->fpr); 232 uptr->fpr = grecs_strdup(pstat->fpr);
237 if (wy_debug_level > 2) 233 wy_debug(3, (_("imported key: user = %s, fingerprint = %s"),
238 logmsg(LOG_DEBUG, 234 uptr->name, uptr->fpr));
239 _("imported key: user = %s, fingerprint = %s"),
240 uptr->name, uptr->fpr);
241 } 235 }
242 236
243 fail_if_err(gpgme_data_new_from_file(&directive_data, 237 fail_if_err(gpgme_data_new_from_file(&directive_data,
@@ -259,7 +253,7 @@ verify_directive_signature(struct file_triplet *trp)
259 } else { 253 } else {
260 rc = 1; 254 rc = 1;
261 UPDATE_STATS(STAT_BAD_SIGNATURE); 255 UPDATE_STATS(STAT_BAD_SIGNATURE);
262 logmsg(LOG_ERR, _("%s: directive verification failed: %s"), 256 wy_log(LOG_ERR, _("%s: directive verification failed: %s"),
263 trp->name, gpgme_strerror(ec)); 257 trp->name, gpgme_strerror(ec));
264 } 258 }
265 259
@@ -287,7 +281,7 @@ verify_detached_signature(struct file_triplet *trp)
287 while (info && info->protocol != GPGME_PROTOCOL_OpenPGP) 281 while (info && info->protocol != GPGME_PROTOCOL_OpenPGP)
288 info = info->next; 282 info = info->next;
289 if (!info) { 283 if (!info) {
290 logmsg(LOG_CRIT, 284 wy_log(LOG_CRIT,
291 _("cannot find path to gpg binary (attempting to " 285 _("cannot find path to gpg binary (attempting to "
292 "verify the detached signature for %s"), trp->name); 286 "verify the detached signature for %s"), trp->name);
293 return 1; 287 return 1;
@@ -302,19 +296,17 @@ verify_detached_signature(struct file_triplet *trp)
302 296
303 switch (wydawca_exec(5, argv, NULL)) { 297 switch (wydawca_exec(5, argv, NULL)) {
304 case exec_success: 298 case exec_success:
305 if (wy_debug_level) 299