From 0077bc419d34a0341f978fc0e2d5cba8d35d4b28 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Sun, 23 Dec 2012 00:54:27 +0200 Subject: 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. --- src/config.c | 10 +++++- src/gpg.c | 107 ++++++++++++++++++++++++++++++++-------------------------- src/job.c | 7 +++- src/triplet.c | 3 +- src/verify.c | 3 ++ src/watcher.c | 16 ++++++++- src/wydawca.c | 2 ++ src/wydawca.h | 3 ++ 8 files changed, 99 insertions(+), 52 deletions(-) (limited to 'src') diff --git a/src/config.c b/src/config.c index 66d5fb7..509b0d5 100644 --- a/src/config.c +++ b/src/config.c @@ -1158,6 +1158,10 @@ static struct grecs_keyword spool_kw[] = { grecs_type_string, GRECS_DFLT, NULL, offsetof(struct spool, file_sweep_time), cb_interval }, + { "inotify", NULL, N_("Enable or disable inotify for this spool"), + grecs_type_bool, GRECS_DFLT, + NULL, offsetof(struct spool, inotify_enable), }, + { "dictionary", N_("ident"), N_("Define data dictionary"), grecs_type_section, GRECS_DFLT, NULL, offsetof(struct spool, dictionary), @@ -1200,6 +1204,7 @@ cb_spool (enum grecs_callback_command cmd, spool = grecs_zalloc (sizeof (*spool)); spool->tag = grecs_strdup (value->v.string); spool->file_sweep_time = file_sweep_time; + spool->inotify_enable = 1; for (i = 0; i < NITEMS (spool->dictionary); i++) spool->dictionary[i] = default_dictionary[i]; spool->archive = default_archive_descr; @@ -1418,7 +1423,10 @@ static struct grecs_keyword wydawca_kw[] = { grecs_type_string, GRECS_DFLT, &wakeup_interval, 0, cb_interval }, { "pidfile", N_("file"), N_("Set pid file name"), grecs_type_string, GRECS_DFLT, &pidfile }, - + + { "inotify", NULL, N_("Enable or disable inotify support"), + grecs_type_bool, GRECS_DFLT, &inotify_enable }, + { "user", N_("name"), N_("Run with UID and GID of this user"), grecs_type_string, GRECS_DFLT, NULL, 0, cb_user }, { "group", NULL, N_("Retain these supplementary groups"), diff --git a/src/gpg.c b/src/gpg.c index 8979e9c..814be6f 100644 --- a/src/gpg.c +++ b/src/gpg.c @@ -146,6 +146,57 @@ create_gpg_homedir () return 0; } +static int +checksig (gpgme_signature_t sig, const char *uid, struct file_triplet *trp) +{ + switch (gpg_err_code (sig->status)) + { + case GPG_ERR_NO_ERROR: + if (debug_level) + logmsg (LOG_NOTICE, _("Good signature from %s"), uid); + trp->uploader = uploader_find_frp (trp->uploader_list, sig->fpr); + if (!trp->uploader) + { + logmsg (LOG_ERR, + _("good signature from %s, " + "but the uploader info for %s not found"), + uid, sig->fpr); + return 1; + } + break; + + case GPG_ERR_BAD_SIGNATURE: + UPDATE_STATS (STAT_BAD_SIGNATURE); + logmsg (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")); + return 0; + + case GPG_ERR_NO_DATA: + UPDATE_STATS (STAT_BAD_TRIPLETS); + logmsg (LOG_ERR, _("No signature")); + return 0; + + case GPG_ERR_SIG_EXPIRED: + UPDATE_STATS (STAT_BAD_SIGNATURE); + logmsg (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); + return 0; + + default: + logmsg (LOG_ERR, _("Unknown signature error")); + return 0; + } + return -1; +} + static int gpg_verify_signature (gpgme_ctx_t ctx, gpgme_signature_t sig, struct file_triplet *trp) @@ -157,57 +208,16 @@ gpg_verify_signature (gpgme_ctx_t ctx, gpgme_signature_t sig, { const char *uid; gpgme_key_t key; - + int rc; + if (gpgme_get_key (ctx, sig->fpr, &key, 0) == GPG_ERR_NO_ERROR) uid = key->uids->uid; else uid = sig->fpr; - - switch (gpg_err_code (sig->status)) - { - case GPG_ERR_NO_ERROR: - if (debug_level) - logmsg (LOG_NOTICE, _("Good signature from %s"), uid); - trp->uploader = uploader_find_frp (trp->uploader_list, sig->fpr); - if (!trp->uploader) - { - logmsg (LOG_ERR, - _("good signature from %s, " - "but the uploader info for %s not found"), - uid, sig->fpr); - return 1; - } - break; - - case GPG_ERR_BAD_SIGNATURE: - UPDATE_STATS (STAT_BAD_SIGNATURE); - logmsg (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")); - return 0; - - case GPG_ERR_NO_DATA: - UPDATE_STATS (STAT_BAD_TRIPLETS); - logmsg (LOG_ERR, _("No signature")); - return 0; - - case GPG_ERR_SIG_EXPIRED: - UPDATE_STATS (STAT_BAD_SIGNATURE); - logmsg (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); - return 0; - - default: - logmsg (LOG_ERR, _("Unknown signature error")); - return 0; - } + rc = checksig (sig, uid, trp); + gpgme_key_unref (key); + if (rc != -1) + return rc; } return 1; } @@ -217,7 +227,7 @@ int verify_directive_signature (struct file_triplet *trp) { gpgme_ctx_t ctx; - gpgme_data_t key_data, directive_data, plain; + gpgme_data_t key_data, directive_data, plain = NULL; gpgme_error_t ec; int rc; struct uploader_info *uptr; @@ -269,6 +279,7 @@ verify_directive_signature (struct file_triplet *trp) trp->name, gpgme_strerror (ec)); } + gpgme_data_release (plain); gpgme_data_release (directive_data); gpgme_data_release (key_data); gpgme_release (ctx); diff --git a/src/job.c b/src/job.c index 3fae432..315303f 100644 --- a/src/job.c +++ b/src/job.c @@ -338,7 +338,12 @@ job_queue_runner () job->timestamp = now + interval; } else - job_remove (job); + { + job_remove (job); + free (job); + job = next; + continue; + } } } diff --git a/src/triplet.c b/src/triplet.c index 05b7536..aa74de0 100644 --- a/src/triplet.c +++ b/src/triplet.c @@ -127,9 +127,10 @@ triplet_lookup (struct spool *spool, const char *name) memcpy (key.name, finfo.name, finfo.root_len); key.name[finfo.root_len] = 0; key.spool = spool; + file_info_cleanup (&finfo); ret = grecs_symtab_lookup_or_install (triplet_table, &key, NULL); - file_info_cleanup (&finfo); + free (key.name); return ret; } diff --git a/src/verify.c b/src/verify.c index 4a108bc..dee160f 100644 --- a/src/verify.c +++ b/src/verify.c @@ -96,6 +96,9 @@ fill_project_name (struct file_triplet *trp) char *p; const char *directory; int rc; + + if (trp->blurb) + return 0; size = trp->file[file_directive].sb.st_size; if (size <= MSG_BEGIN_MARKER_LEN) diff --git a/src/watcher.c b/src/watcher.c index f8761ee..c52e3e6 100644 --- a/src/watcher.c +++ b/src/watcher.c @@ -83,9 +83,16 @@ create_watcher (struct spool *sp, void *data) if (!sp) return 0; + + if (!sp->inotify_enable) + { + if (debug_level > 1) + logmsg (LOG_DEBUG, "disabling inotify support for spool %s", sp->tag); + return 0; + } if (debug_level > 1) - logmsg (LOG_DEBUG, "creating watcher %s", path); + logmsg (LOG_DEBUG, "spool %s: creating watcher %s", sp->tag, path); dwp = malloc (sizeof(*dwp)); if (!dwp) { @@ -113,6 +120,13 @@ int watcher_init () { int ifd, rc; + + if (!inotify_enable) + { + if (debug_level > 1) + logmsg (LOG_DEBUG, "disabling inotify support"); + return -1; + } if (debug_level > 1) logmsg (LOG_DEBUG, "setting up inotify"); diff --git a/src/wydawca.c b/src/wydawca.c index 521d796..45a5cff 100644 --- a/src/wydawca.c +++ b/src/wydawca.c @@ -53,6 +53,8 @@ unsigned wydawca_stat[MAX_STAT]; unsigned min_directive_version = MIN_DIRECTIVE_VERSION; unsigned max_directive_version = MAX_DIRECTIVE_VERSION; +int inotify_enable = 1; + void initstats () { diff --git a/src/wydawca.h b/src/wydawca.h index 722fc9b..323d403 100644 --- a/src/wydawca.h +++ b/src/wydawca.h @@ -226,6 +226,7 @@ struct spool mu_url_t dest_url; /* Destination URL */ const char *dest_dir; /* Directory part of the above */ struct virt_tab vtab; /* Virtual method table */ + int inotify_enable; time_t file_sweep_time; /* Remove invalid/unprocessed files after this amount of time */ @@ -377,6 +378,8 @@ extern unsigned max_directive_version; extern struct spool fake_spool; extern struct spool inotify_spool; +extern int inotify_enable; + #define UPDATE_STATS(what) \ do \ { \ -- cgit v1.2.1