aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-12-23 00:54:27 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2012-12-23 00:54:27 +0200
commit0077bc419d34a0341f978fc0e2d5cba8d35d4b28 (patch)
treef5cb831a306e99dce9a8c5af1b4be55cf7dbb658 /src
parent67a64a6a7809c183516740696e15ab88f82d7ef0 (diff)
downloadwydawca-0077bc419d34a0341f978fc0e2d5cba8d35d4b28.tar.gz
wydawca-0077bc419d34a0341f978fc0e2d5cba8d35d4b28.tar.bz2
Fix memory leaks, provide config statements for disabling inotify.
* src/config.c: New statement "inotify" (global and spool-specific). * src/gpg.c (gpg_verify_signature): Free key when no longer needed. (verify_directive_signature): Fix memory leak. * src/job.c (job_queue_runner): Free the unlinked job. * src/triplet.c (triplet_lookup): Free key.name. * src/verify.c (fill_project_name): Return immediately if trp->blurb is not null. * src/watcher.c (create_watcher): Ignore spool if its inotify_enable is false. (watcher_init): Return immediately if inotify_enable is false. * src/wydawca.c (inotify_enable): New global. * src/wydawca.h: Likewise.
Diffstat (limited to 'src')
-rw-r--r--src/config.c10
-rw-r--r--src/gpg.c107
-rw-r--r--src/job.c7
-rw-r--r--src/triplet.c3
-rw-r--r--src/verify.c3
-rw-r--r--src/watcher.c16
-rw-r--r--src/wydawca.c2
-rw-r--r--src/wydawca.h3
8 files changed, 99 insertions, 52 deletions
diff --git a/src/config.c b/src/config.c
index 66d5fb7..509b0d5 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1155,12 +1155,16 @@ static struct grecs_keyword spool_kw[] = {
1155 NULL, offsetof(struct spool, dest_url), 1155 NULL, offsetof(struct spool, dest_url),
1156 cb_url }, 1156 cb_url },
1157 { "file-sweep-time", N_("interval"), N_("Define file sweep time"), 1157 { "file-sweep-time", N_("interval"), N_("Define file sweep time"),
1158 grecs_type_string, GRECS_DFLT, 1158 grecs_type_string, GRECS_DFLT,
1159 NULL, offsetof(struct spool, file_sweep_time), 1159 NULL, offsetof(struct spool, file_sweep_time),
1160 cb_interval }, 1160 cb_interval },
1161 { "inotify", NULL, N_("Enable or disable inotify for this spool"),
1162 grecs_type_bool, GRECS_DFLT,
1163 NULL, offsetof(struct spool, inotify_enable), },
1164
1161 { "dictionary", N_("ident"), N_("Define data dictionary"), 1165 { "dictionary", N_("ident"), N_("Define data dictionary"),
1162 grecs_type_section, GRECS_DFLT, 1166 grecs_type_section, GRECS_DFLT,
1163 NULL, offsetof(struct spool, dictionary), 1167 NULL, offsetof(struct spool, dictionary),
1164 cb_dictionary, NULL, dictionary_kw }, 1168 cb_dictionary, NULL, dictionary_kw },
1165 { "archive", N_("type: string"), N_("Set up archivation"), 1169 { "archive", N_("type: string"), N_("Set up archivation"),
1166 grecs_type_section, GRECS_DFLT, 1170 grecs_type_section, GRECS_DFLT,
@@ -1197,12 +1201,13 @@ cb_spool (enum grecs_callback_command cmd,
1197 _("tag must be a string")); 1201 _("tag must be a string"));
1198 return 1; 1202 return 1;
1199 } 1203 }
1200 spool = grecs_zalloc (sizeof (*spool)); 1204 spool = grecs_zalloc (sizeof (*spool));
1201 spool->tag = grecs_strdup (value->v.string); 1205 spool->tag = grecs_strdup (value->v.string);
1202 spool->file_sweep_time = file_sweep_time; 1206 spool->file_sweep_time = file_sweep_time;
1207 spool->inotify_enable = 1;
1203 for (i = 0; i < NITEMS (spool->dictionary); i++) 1208 for (i = 0; i < NITEMS (spool->dictionary); i++)
1204 spool->dictionary[i] = default_dictionary[i]; 1209 spool->dictionary[i] = default_dictionary[i];
1205 spool->archive = default_archive_descr; 1210 spool->archive = default_archive_descr;
1206 *pdata = spool; 1211 *pdata = spool;
1207 break; 1212 break;
1208 1213
@@ -1415,13 +1420,16 @@ static struct grecs_keyword wydawca_kw[] = {
1415 { "single-process", NULL, N_("Do not spawn subprocesses"), 1420 { "single-process", NULL, N_("Do not spawn subprocesses"),
1416 grecs_type_bool, GRECS_DFLT, &single_process }, 1421 grecs_type_bool, GRECS_DFLT, &single_process },
1417 { "wakeup-interval", N_("time"), N_("Set wake-up interval"), 1422 { "wakeup-interval", N_("time"), N_("Set wake-up interval"),
1418 grecs_type_string, GRECS_DFLT, &wakeup_interval, 0, cb_interval }, 1423 grecs_type_string, GRECS_DFLT, &wakeup_interval, 0, cb_interval },
1419 { "pidfile", N_("file"), N_("Set pid file name"), 1424 { "pidfile", N_("file"), N_("Set pid file name"),
1420 grecs_type_string, GRECS_DFLT, &pidfile }, 1425 grecs_type_string, GRECS_DFLT, &pidfile },
1421 1426
1427 { "inotify", NULL, N_("Enable or disable inotify support"),
1428 grecs_type_bool, GRECS_DFLT, &inotify_enable },
1429
1422 { "user", N_("name"), N_("Run with UID and GID of this user"), 1430 { "user", N_("name"), N_("Run with UID and GID of this user"),
1423 grecs_type_string, GRECS_DFLT, NULL, 0, cb_user }, 1431 grecs_type_string, GRECS_DFLT, NULL, 0, cb_user },
1424 { "group", NULL, N_("Retain these supplementary groups"), 1432 { "group", NULL, N_("Retain these supplementary groups"),
1425 grecs_type_string, GRECS_LIST, NULL, 0, cb_supp_groups }, 1433 grecs_type_string, GRECS_LIST, NULL, 0, cb_supp_groups },
1426 1434
1427 { "min-version", N_("major.minor"), 1435 { "min-version", N_("major.minor"),
diff --git a/src/gpg.c b/src/gpg.c
index 8979e9c..814be6f 100644
--- a/src/gpg.c
+++ b/src/gpg.c
@@ -144,83 +144,93 @@ create_gpg_homedir ()
144 logmsg (LOG_DEBUG, _("GNUPG home directory: %s"), temp_homedir); 144 logmsg (LOG_DEBUG, _("GNUPG home directory: %s"), temp_homedir);
145 setenv ("GNUPGHOME", temp_homedir, 1); 145 setenv ("GNUPGHOME", temp_homedir, 1);
146 return 0; 146 return 0;
147} 147}
148 148
149static int 149static int
150checksig (gpgme_signature_t sig, const char *uid, struct file_triplet *trp)
151{
152 switch (gpg_err_code (sig->status))
153 {
154 case GPG_ERR_NO_ERROR:
155 if (debug_level)
156 logmsg (LOG_NOTICE, _("Good signature from %s"), uid);
157 trp->uploader = uploader_find_frp (trp->uploader_list, sig->fpr);
158 if (!trp->uploader)
159 {
160 logmsg (LOG_ERR,
161 _("good signature from %s, "
162 "but the uploader info for %s not found"),
163 uid, sig->fpr);
164 return 1;
165 }
166 break;
167
168 case GPG_ERR_BAD_SIGNATURE:
169 UPDATE_STATS (STAT_BAD_SIGNATURE);
170 logmsg (LOG_ERR, _("BAD signature from %s"), uid);
171 return 0;
172
173 case GPG_ERR_NO_PUBKEY:
174 UPDATE_STATS (STAT_ACCESS_VIOLATIONS);
175 logmsg (LOG_ERR, _("No public key"));
176 return 0;
177
178 case GPG_ERR_NO_DATA:
179 UPDATE_STATS (STAT_BAD_TRIPLETS);
180 logmsg (LOG_ERR, _("No signature"));
181 return 0;
182
183 case GPG_ERR_SIG_EXPIRED:
184 UPDATE_STATS (STAT_BAD_SIGNATURE);
185 logmsg (LOG_ERR, _("Expired signature from %s"), uid);
186 return 0;
187
188 case GPG_ERR_KEY_EXPIRED:
189 UPDATE_STATS (STAT_BAD_SIGNATURE);
190 logmsg (LOG_ERR, _("Key expired (%s)"), uid);
191 return 0;
192
193 default:
194 logmsg (LOG_ERR, _("Unknown signature error"));
195 return 0;
196 }
197 return -1;
198}
199
200static int
150gpg_verify_signature (gpgme_ctx_t ctx, gpgme_signature_t sig, 201gpg_verify_signature (gpgme_ctx_t ctx, gpgme_signature_t sig,
151 struct file_triplet *trp) 202 struct file_triplet *trp)
152{ 203{
153 if (!sig) 204 if (!sig)
154 return 0; 205 return 0;
155 206
156 for (; sig; sig = sig->next) 207 for (; sig; sig = sig->next)
157 { 208 {
158 const char *uid; 209 const char *uid;
159 gpgme_key_t key; 210 gpgme_key_t key;
160 211 int rc;
212
161 if (gpgme_get_key (ctx, sig->fpr, &key, 0) == GPG_ERR_NO_ERROR) 213 if (gpgme_get_key (ctx, sig->fpr, &key, 0) == GPG_ERR_NO_ERROR)
162 uid = key->uids->uid; 214 uid = key->uids->uid;
163 else 215 else
164 uid = sig->fpr; 216 uid = sig->fpr;
165 217 rc = checksig (sig, uid, trp);
166 switch (gpg_err_code (sig->status)) 218 gpgme_key_unref (key);
167 { 219 if (rc != -1)
168 case GPG_ERR_NO_ERROR: 220 return rc;
169 if (debug_level)
170 logmsg (LOG_NOTICE, _("Good signature from %s"), uid);
171 trp->uploader = uploader_find_frp (trp->uploader_list, sig->fpr);
172 if (!trp->uploader)
173 {
174 logmsg (LOG_ERR,
175 _("good signature from %s, "
176 "but the uploader info for %s not found"),
177 uid, sig->fpr);
178 return 1;
179 }
180 break;
181
182 case GPG_ERR_BAD_SIGNATURE:
183 UPDATE_STATS (STAT_BAD_SIGNATURE);
184 logmsg (LOG_ERR, _("BAD signature from %s"), uid);
185 return 0;
186
187 case GPG_ERR_NO_PUBKEY:
188 UPDATE_STATS (STAT_ACCESS_VIOLATIONS);
189 logmsg (LOG_ERR, _("No public key"));
190 return 0;
191
192 case GPG_ERR_NO_DATA:
193 UPDATE_STATS (STAT_BAD_TRIPLETS);
194 logmsg (LOG_ERR, _("No signature"));
195 return 0;
196
197 case GPG_ERR_SIG_EXPIRED:
198 UPDATE_STATS (STAT_BAD_SIGNATURE);
199 logmsg (LOG_ERR, _("Expired signature from %s"), uid);
200 return 0;
201
202 case GPG_ERR_KEY_EXPIRED:
203 UPDATE_STATS (STAT_BAD_SIGNATURE);
204 logmsg (LOG_ERR, _("Key expired (%s)"), uid);
205 return 0;
206
207 default:
208 logmsg (LOG_ERR, _("Unknown signature error"));
209 return 0;
210 }
211 } 221 }
212 return 1; 222 return 1;
213} 223}
214 224
215/* Verify the directive file from TRP using public key PUBKEY */ 225/* Verify the directive file from TRP using public key PUBKEY */
216int 226int
217verify_directive_signature (struct file_triplet *trp) 227verify_directive_signature (struct file_triplet *trp)
218{ 228{
219 gpgme_ctx_t ctx; 229 gpgme_ctx_t ctx;
220 gpgme_data_t key_data, directive_data, plain; 230 gpgme_data_t key_data, directive_data, plain = NULL;
221 gpgme_error_t ec; 231 gpgme_error_t ec;
222 int rc; 232 int rc;
223 struct uploader_info *uptr; 233 struct uploader_info *uptr;
224 234
225 create_gpg_homedir (); 235 create_gpg_homedir ();
226 fail_if_err (gpgme_new (&