diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-01-03 11:44:34 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-01-03 11:49:20 +0200 |
commit | c2cbf4e863a8f3a5081357d4b48f54cec2cd5d69 (patch) | |
tree | 93711f398c585fcc8ac0b19bbcfe15b79f4c6b73 /src | |
parent | a2489ce17e9c9a03b649d5b63183d4f830c639a1 (diff) | |
download | wydawca-c2cbf4e863a8f3a5081357d4b48f54cec2cd5d69.tar.gz wydawca-c2cbf4e863a8f3a5081357d4b48f54cec2cd5d69.tar.bz2 |
Do not pass spool as a separate parameter, register it early in the triplet.
* src/directive.c (process_directives): Remove spool parameter.
* src/gpg.c (verify_directive_signature)
(verify_detached_signature): Remove spool parameter.
* src/process.c (scan_spool_unlocked): Update call to register_file.
* src/triplet.c (register_file): Take spool ptr as second argument.
(triplet_processor): Ignore proc_data.
(enumerate_triplets): Pass NULL as proc_data.
* src/verify.c (verify_directive_file): Remove spool parameter.
* src/wydawca.h (ASGN_SPOOL): New macro.
(register_file, verify_directive_file)
(verify_directive_signature, verify_detached_signature)
(process_directives): Remove spool parameter.
* src/getopt.m4 (print_help): Minor fix.
Diffstat (limited to 'src')
-rw-r--r-- | src/directive.c | 8 | ||||
-rw-r--r-- | src/getopt.m4 | 2 | ||||
-rw-r--r-- | src/gpg.c | 14 | ||||
-rw-r--r-- | src/process.c | 2 | ||||
-rw-r--r-- | src/triplet.c | 16 | ||||
-rw-r--r-- | src/verify.c | 11 | ||||
-rw-r--r-- | src/wydawca.h | 28 |
7 files changed, 47 insertions, 34 deletions
diff --git a/src/directive.c b/src/directive.c index 401397d..93830b1 100644 --- a/src/directive.c +++ b/src/directive.c @@ -578,32 +578,34 @@ external_check (struct file_triplet *trp) free (file); if (rc) { UPDATE_STATS (STAT_CHECK_FAIL); notify (spool->notification, trp, ev_check_fail); } return rc; } -/* Process the directives from TRP, using given SPOOL */ +/* Process the directives from TRP */ int -process_directives (struct file_triplet *trp, const struct spool *spool) +process_directives (struct file_triplet *trp) { int rc, n; const char *key, *val; char *relative_dir; + const struct spool *spool; + ASGN_SPOOL (spool, trp, return 1); UPDATE_STATS (STAT_COMPLETE_TRIPLETS); timer_start ("triplet"); report_init (); for (n = directive_first (trp, &key, &val); n; n = directive_next (trp, n, &key, &val)) { enum directive d = find_directive (key); switch (d) { case unknown_dir: /* should not happen */ abort (); @@ -616,25 +618,25 @@ process_directives (struct file_triplet *trp, const struct spool *spool) case directory_dir: /* FIXME: Alloc it in triplet */ relative_dir = safe_file_name_alloc (val); if (!relative_dir || relative_dir[0] == '/') { logmsg (LOG_ERR, _("%s: invalid directory: %s"), trp->file[file_directive].name, val); return 1; } break; case filename_dir: - rc = verify_detached_signature (trp, spool); + rc = verify_detached_signature (trp); if (rc == 0) { if (external_check (trp)) return 1; if (move_file (trp, spool, file_dist, relative_dir) || move_file (trp, spool, file_signature, relative_dir)) return 1; } else { logmsg (LOG_ERR, _("invalid detached signature for %s"), trp->name); diff --git a/src/getopt.m4 b/src/getopt.m4 index b615ec3..fc50ff9 100644 --- a/src/getopt.m4 +++ b/src/getopt.m4 @@ -237,25 +237,25 @@ print_option_descr (const char *descr, size_t lmargin, size_t rmargin) descr++; } } } void print_help(void) { unsigned i; printf ("%s %s [%s]... %s\n", _("Usage:"), [<$2>], _("[<OPTION>]"), gettext (args_doc)); - if (doc && doc[0]) + if (doc[0]) print_option_descr(gettext (doc), 0, RMARGIN); putchar ('\n'); for (i = 0; i < sizeof (opthelp) / sizeof (opthelp[0]); i++) { unsigned n; if (opthelp[i].opt) { n = printf (" %s", opthelp[i].opt); if (opthelp[i].arg) { char *cb, *ce, *sep = ""; @@ -206,35 +206,33 @@ gpg_verify_signature (gpgme_ctx_t ctx, gpgme_signature_t sig, logmsg (LOG_ERR, _("Key expired (%s)"), uid); return 0; default: logmsg (LOG_ERR, _("Unknown signature error")); return 0; } } return 1; } /* Verify the directive file from TRP using public key PUBKEY */ -/* FIXME: spool currently unused */ int -verify_directive_signature (struct file_triplet *trp, - const struct spool *spool) +verify_directive_signature (struct file_triplet *trp) { gpgme_ctx_t ctx; gpgme_data_t key_data, directive_data, plain; gpgme_error_t ec; int rc; struct uploader_info *uptr; - + create_gpg_homedir (); fail_if_err (gpgme_new (&ctx)); for (uptr = trp->uploader_list; uptr; uptr = uptr->next) { gpgme_import_result_t res; gpgme_import_status_t pstat; fail_if_err (gpgme_data_new_from_mem (&key_data, uptr->gpg_key, strlen (uptr->gpg_key), 0)); @@ -250,54 +248,56 @@ verify_directive_signature (struct file_triplet *trp, fail_if_err (gpgme_data_new_from_file (&directive_data, trp->file[file_directive].name, 1)); gpgme_data_new (&plain); ec = gpgme_op_verify (ctx, directive_data, NULL, plain); if (ec == GPG_ERR_NO_ERROR) { gpgme_verify_result_t result; result = gpgme_op_verify_result (ctx); if (!gpg_verify_signature (ctx, result->signatures, trp)) { UPDATE_STATS (STAT_BAD_SIGNATURE); - notify (spool->notification, trp, ev_bad_directive_signature); + notify (trp->spool->notification, trp, ev_bad_directive_signature); rc = 1; } else rc = 0; } else { rc = 1; UPDATE_STATS (STAT_BAD_SIGNATURE); logmsg (LOG_ERR, _("%s: directive verification failed: %s"), trp->name, gpgme_strerror (ec)); } gpgme_data_release (directive_data); gpgme_data_release (key_data); return rc; } /* Verify the detached signature of TRP. NOTE: It is assumed that the public key is already registered (by a previous call to verify_directive_signature). */ int -verify_detached_signature (struct file_triplet *trp, - const struct spool *spool) +verify_detached_signature (struct file_triplet *trp) { gpgme_engine_info_t info; const char *argv[5]; + const struct spool *spool; + ASGN_SPOOL (spool, trp, return 1); + fail_if_err (gpgme_get_engine_info (&info)); while (info && info->protocol != GPGME_PROTOCOL_OpenPGP) info = info->next; if (!info) { logmsg (LOG_CRIT, _("cannot find path to gpg binary (attempting to verify " "the detached signature for %s"), trp->name); return 1; } create_gpg_homedir (); diff --git a/src/process.c b/src/process.c index 23641cd..676e565 100644 --- a/src/process.c +++ b/src/process.c @@ -193,25 +193,25 @@ scan_spool_unlocked (const struct spool *spool, int uc, uid_t *uv) logmsg (LOG_DEBUG, _("ignoring file: %s/%s"), spool->source_dir, ent->d_name); continue; } finfo.sb = st; parse_file_name (ent->d_name, &finfo); if (debug_level) logmsg (LOG_DEBUG, _("found file %s: %s, stem: %.*s"), ent->d_name, file_type_str (finfo.type), finfo.root_len, finfo.name); - register_file (&finfo); + register_file (&finfo, spool); } closedir (dir); if (count_collected_triplets () > 0) { int i; for (i = 0; i < dictionary_count; i++) { if (dictionary_init (spool->dictionary[i])) { diff --git a/src/triplet.c b/src/triplet.c index 0744daa..efe4a0b 100644 --- a/src/triplet.c +++ b/src/triplet.c @@ -51,34 +51,35 @@ hash_triplet_free (void *data) free (tp->directive); free (tp->blurb); free (tp->tmp); free (tp->check_diag); /* FIXME: free uploader list */ free (tp); } /* Register a file in the triplet table */ void -register_file (struct file_info *finfo) +register_file (struct file_info *finfo, const struct spool *spool) { struct file_triplet *tp, *ret; tp = xmalloc (sizeof(*tp) + finfo->root_len + 1); memset (tp, 0, sizeof (*tp)); tp->name = (char*)(tp + 1); memcpy (tp->name, finfo->name, finfo->root_len); tp->name[finfo->root_len] = 0; - + tp->spool = spool; + if (! ((triplet_table || (triplet_table = hash_initialize (0, 0, hash_triplet_hasher, hash_triplet_compare, hash_triplet_free))) && (ret = hash_insert (triplet_table, tp)))) xalloc_die (); if (ret != tp) free (tp); ret->file[finfo->type] = *finfo; } @@ -114,25 +115,25 @@ enum triplet_state triplet_complete, /* A complete triplet: all three files are present and have the same owner */ triplet_incomplete, /* Incomplete triplet: some files are missing */ triplet_bad, /* Bad triplet. Should be removed immediately. */ }; static enum triplet_state check_triplet_state (struct file_triplet *trp) { if (trp->file[file_directive].name) { - if (verify_directive_file (trp, trp->spool)) + if (verify_directive_file (trp)) return triplet_bad; if (trp->file[file_dist].name == 0 && trp->file[file_signature].name == 0) { if (directive_get_value (trp, "filename", NULL)) return triplet_directive; } else if (trp->file[file_dist].name && trp->file[file_signature].name) { if (trp->file[file_dist].sb.st_uid == @@ -167,77 +168,74 @@ remove_triplet (struct file_triplet *trp) if (!dry_run_mode && unlink (trp->file[i].name)) logmsg (LOG_ERR, _("cannot remove %s: %s"), trp->file[i].name, strerror (errno)); } } } /* Process a single triplet from the table */ static bool triplet_processor (void *data, void *proc_data) { struct file_triplet *trp = data; - const struct spool *spool = proc_data; - - trp->spool = spool; if (debug_level) logmsg (LOG_DEBUG, "FILE %s, DIST=%s, SIG=%s, DIRECTIVE=%s", trp->name, SP (trp->file[file_dist].name), SP (trp->file[file_signature].name), SP (trp->file[file_directive].name)); switch (check_triplet_state (trp)) { case triplet_directive: case triplet_complete: if (debug_level) logmsg (LOG_DEBUG, _("processing triplet `%s'"), trp->name); - if (process_directives (trp, spool)) + if (process_directives (trp)) remove_triplet (trp); return true; case triplet_incomplete: if (debug_level) logmsg (LOG_DEBUG, _("%s: incomplete triplet"), trp->name); /* ignore unless expired (see below); */ UPDATE_STATS (STAT_INCOMPLETE_TRIPLETS); break; case triplet_bad: UPDATE_STATS (STAT_BAD_TRIPLETS); remove_triplet (trp); return true; } - if (triplet_expired_p (trp, spool->file_sweep_time)) + if (triplet_expired_p (trp, trp->spool->file_sweep_time)) { UPDATE_STATS (STAT_EXPIRED_TRIPLETS); remove_triplet (trp); } return true; } /* Process all triplets from the table according to the SPOOL */ void enumerate_triplets (const struct spool *spool) { if (debug_level) logmsg (LOG_DEBUG, _("processing spool %s (%s)"), spool->tag, mu_url_to_string (spool->dest_url)); if (triplet_table) { - hash_do_for_each (triplet_table, triplet_processor, (void*) spool); + hash_do_for_each (triplet_table, triplet_processor, NULL); hash_clear (triplet_table); } } size_t count_collected_triplets () { return triplet_table ? hash_get_n_entries (triplet_table) : 0; } static const char * diff --git a/src/verify.c b/src/verify.c index 7520466..01c61ea 100644 --- a/src/verify.c +++ b/src/verify.c @@ -184,33 +184,36 @@ new_uploader_info (struct uploader_info *src) } struct uploader_info * uploader_find_frp (struct uploader_info *list, const char *fpr) { for (; list; list = list->next) if (list->fpr && strcmp (list->fpr, fpr) == 0) break; return list; } int -verify_directive_file (struct file_triplet *trp, const struct spool *spool) +verify_directive_file (struct file_triplet *trp) { char *command; - struct dictionary *dict = spool->dictionary[project_uploader_dict]; int rc; void *md; - size_t nrows, ncols, i; struct uploader_info *head, *tail; + const struct spool *spool; + struct dictionary *dict; + + ASGN_SPOOL (spool, trp, return 1); + dict = spool->dictionary[project_uploader_dict]; if (!trp->file[file_directive].name) return 1; if (fill_project_name (trp)) return 1; md = dictionary_open (dict); if (!md) return 1; command = triplet_expand_dictionary_query (dict, md, trp); @@ -292,25 +295,25 @@ verify_directive_file (struct file_triplet *trp, const struct spool *spool) dictionary_close (dict, md); if (!head) { logmsg (LOG_ERR, _("no valid uploaders found for %s"), trp->name); return 1; } trp->uploader_list = head; trp->uploader = NULL; - if (verify_directive_signature (trp, spool)) + if (verify_directive_signature (trp)) { /*FIXME: Update stats */ logmsg (LOG_ERR, _("invalid signature for %s"), trp->name ? trp->name : "[unknown]"); return 1; } else if (debug_level) logmsg (LOG_DEBUG, _("%s: directive file signature OK"), trp->name); if (debug_level > 1) { int i; diff --git a/src/wydawca.h b/src/wydawca.h index 54ecf00..b44b5d7 100644 --- a/src/wydawca.h +++ b/src/wydawca.h @@ -229,24 +229,38 @@ 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 */ time_t file_sweep_time; /* Remove invalid/unprocessed files after this amount of time */ struct dictionary *dictionary[dictionary_count]; struct archive_descr archive; /* Archivation data */ struct notification *notification; char *check_script; }; +#define ASGN_SPOOL(spool, trp, faction) \ + do \ + { \ + spool = (trp)->spool; \ + if (!spool) \ + { \ + logmsg (LOG_CRIT, \ + _("INTERNAL ERROR at %s:%d: spool not defined for %s"),\ + __FILE__, __LINE__, (trp)->name); \ + faction; \ + } \ + } \ + while (0) + enum wydawca_stat { STAT_ERRORS, STAT_WARNINGS, STAT_BAD_SIGNATURE, STAT_ACCESS_VIOLATIONS, STAT_COMPLETE_TRIPLETS, STAT_INCOMPLETE_TRIPLETS, STAT_BAD_TRIPLETS, STAT_EXPIRED_TRIPLETS, STAT_TRIPLET_SUCCESS, @@ -392,25 +406,25 @@ enum exec_result }; enum exec_result wydawca_exec (int argc, const char **argv, int *retcode); /* Directory scanning and registering */ int scan_spool (const struct spool *spool, int uc, uid_t *uv); int scan_all_spools (int, uid_t *); void spool_create_timers (void); void register_spool (struct spool *spool); struct spool *wydawca_find_spool (const char *name); -void register_file (struct file_info *finfo); +void register_file (struct file_info *finfo, const struct spool *spool); void enumerate_triplets (const struct spool *); size_t count_collected_triplets (void); char *triplet_expand_param (const char *tmpl, struct file_triplet *trp); char *triplet_expand_dictionary_query (struct dictionary *dict, void *handle, struct file_triplet *trp); /* General-purpose dictionary support */ struct dictionary *dictionary_new (enum dictionary_id id, enum dictionary_type type); int dictionary_init (struct dictionary *dict); int dictionary_done (struct dictionary *dict); void *dictionary_open (struct dictionary *dict); @@ -419,48 +433,44 @@ int dictionary_lookup (struct dictionary *dict, void *handle, const char *cmd); void dictionary_copy_result (struct dictionary *dict, const char *res, size_t size); const char *dictionary_result (struct dictionary *dict, void *handle, unsigned nrow, unsigned ncol); int dictionary_quote_string (struct dictionary *dict, void *handle, const char *input, char **poutput, size_t *psize); unsigned dictionary_num_rows (struct dictionary *dict); unsigned dictionary_num_cols (struct dictionary *dict); /* Verification functions */ -int verify_directive_file (struct file_triplet *trp, - const struct spool *spool); -int verify_directive_signature (struct file_triplet *trp, - const struct spool *spool); -int verify_detached_signature (struct file_triplet *trp, - const struct spool *spool); +int verify_directive_file (struct file_triplet *trp); +int verify_directive_signature (struct file_triplet *trp); +int verify_detached_signature (struct file_triplet *trp); int fill_project_name (struct file_triplet *trp); struct uploader_info *uploader_find_frp (struct uploader_info *list, const char *frp); /* Directive file support */ int directive_parse (struct file_triplet *trp); int directive_get_value (struct file_triplet *trp, const char *key, const char **pval); int directive_pack_version (const char *val, unsigned *pversion); int directive_version_in_range_p (struct file_triplet *trp, unsigned from, unsigned to); int verify_directive_format (struct file_triplet *trp); int directive_first (struct file_triplet *trp, const char **pkey, const char **pval); int directive_next (struct file_triplet *trp, int n, const char **pkey, const char **pval); -int process_directives (struct file_triplet *trp, - const struct spool *spool); +int process_directives (struct file_triplet *trp); int enabled_spool_p (const struct spool *spool); int selected_spools (void); int parse_time_interval (const char *str, time_t *pint, const char **endp); /* config.c */ void config_init (void); void config_help (void); |