diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 10 | ||||
-rw-r--r-- | src/gpg.c | 107 | ||||
-rw-r--r-- | src/job.c | 7 | ||||
-rw-r--r-- | src/triplet.c | 3 | ||||
-rw-r--r-- | src/verify.c | 3 | ||||
-rw-r--r-- | src/watcher.c | 16 | ||||
-rw-r--r-- | src/wydawca.c | 2 | ||||
-rw-r--r-- | src/wydawca.h | 3 |
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[] = { NULL, offsetof(struct spool, dest_url), cb_url }, { "file-sweep-time", N_("interval"), N_("Define file sweep time"), 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), cb_dictionary, NULL, dictionary_kw }, { "archive", N_("type: string"), N_("Set up archivation"), grecs_type_section, GRECS_DFLT, @@ -1197,12 +1201,13 @@ cb_spool (enum grecs_callback_command cmd, _("tag must be a string")); return 1; } 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; *pdata = spool; break; @@ -1415,13 +1420,16 @@ static struct grecs_keyword wydawca_kw[] = { { "single-process", NULL, N_("Do not spawn subprocesses"), grecs_type_bool, GRECS_DFLT, &single_process }, { "wakeup-interval", N_("time"), N_("Set wake-up interval"), 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"), grecs_type_string, GRECS_LIST, NULL, 0, cb_supp_groups }, { "min-version", N_("major.minor"), @@ -144,83 +144,93 @@ create_gpg_homedir () logmsg (LOG_DEBUG, _("GNUPG home directory: %s"), temp_homedir); setenv ("GNUPGHOME", temp_homedir, 1); 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) { if (!sig) return 0; for (; sig; sig = sig->next) { 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; } /* Verify the directive file from TRP using public key PUBKEY */ 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; create_gpg_homedir (); fail_if_err (gpgme_new (&ctx)); @@ -266,12 +276,13 @@ verify_directive_signature (struct file_triplet *trp) rc = 1; UPDATE_STATS (STAT_BAD_SIGNATURE); logmsg (LOG_ERR, _("%s: directive verification failed: %s"), trp->name, gpgme_strerror (ec)); } + gpgme_data_release (plain); gpgme_data_release (directive_data); gpgme_data_release (key_data); gpgme_release (ctx); return rc; } @@ -335,13 +335,18 @@ job_queue_runner () interval = lock_expire_time; /* Re-queue the job */ job->state = STATE_QUEUED; job->timestamp = now + interval; } else - job_remove (job); + { + job_remove (job); + free (job); + job = next; + continue; + } } } if (job->state == STATE_QUEUED) { if (job->timestamp >= now) diff --git a/src/triplet.c b/src/triplet.c index 05b7536..aa74de0 100644 --- a/src/triplet.c +++ b/src/triplet.c @@ -124,15 +124,16 @@ triplet_lookup (struct spool *spool, const char *name) parse_file_name (name, &finfo); key.name = grecs_malloc (finfo.root_len + 1); 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; } /* Return true if any part of the triplet TRP was modified more than TTL seconds ago */ diff --git a/src/verify.c b/src/verify.c index 4a108bc..dee160f 100644 --- a/src/verify.c +++ b/src/verify.c @@ -93,12 +93,15 @@ fill_project_name (struct file_triplet *trp) char *blurb; size_t size; FILE *fp; 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) { logmsg (LOG_ERR, _("too small directive file %s"), trp->file[file_directive].name); diff --git a/src/watcher.c b/src/watcher.c index f8761ee..c52e3e6 100644 --- a/src/watcher.c +++ b/src/watcher.c @@ -80,15 +80,22 @@ create_watcher (struct spool *sp, void *data) struct dirwatcher *dwp; int wd; const char *path = get_path (sp); 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) { logmsg (LOG_ERR, "not enough memory"); return 1; } @@ -110,12 +117,19 @@ create_watcher (struct spool *sp, void *data) } 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"); ifd = inotify_init (); if (ifd == -1) { diff --git a/src/wydawca.c b/src/wydawca.c index 521d796..45a5cff 100644 --- a/src/wydawca.c +++ b/src/wydawca.c @@ -50,12 +50,14 @@ struct grecs_sockaddr listen_sockaddr; 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 () { memset (wydawca_stat, 0, sizeof wydawca_stat); } diff --git a/src/wydawca.h b/src/wydawca.h index 722fc9b..323d403 100644 --- a/src/wydawca.h +++ b/src/wydawca.h @@ -223,12 +223,13 @@ struct spool struct grecs_list *aliases; char *url; /* Download URL */ char *source_dir; /* Source directory */ 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 */ struct dictionary *dictionary[dictionary_count]; int dict_inited; struct archive_descr archive; /* Archivation data */ @@ -374,12 +375,14 @@ extern char *temp_homedir; extern unsigned min_directive_version; extern unsigned max_directive_version; extern struct spool fake_spool; extern struct spool inotify_spool; +extern int inotify_enable; + #define UPDATE_STATS(what) \ do \ { \ if (what >= MAX_STAT) abort(); \ wydawca_stat[what]++; \ } \ |