aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-01-03 11:44:34 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2010-01-03 11:49:20 +0200
commitc2cbf4e863a8f3a5081357d4b48f54cec2cd5d69 (patch)
tree93711f398c585fcc8ac0b19bbcfe15b79f4c6b73 /src
parenta2489ce17e9c9a03b649d5b63183d4f830c639a1 (diff)
downloadwydawca-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.c8
-rw-r--r--src/getopt.m42
-rw-r--r--src/gpg.c14
-rw-r--r--src/process.c2
-rw-r--r--src/triplet.c16
-rw-r--r--src/verify.c11
-rw-r--r--src/wydawca.h28
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
@@ -584,20 +584,22 @@ external_check (struct file_triplet *trp)
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))
{
@@ -622,13 +624,13 @@ process_directives (struct file_triplet *trp, const struct spool *spool)
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))
diff --git a/src/getopt.m4 b/src/getopt.m4
index b615ec3..fc50ff9 100644
--- a/src/getopt.m4
+++ b/src/getopt.m4
@@ -243,13 +243,13 @@ 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;
diff --git a/src/gpg.c b/src/gpg.c
index cca5048..979d0c0 100644
--- a/src/gpg.c
+++ b/src/gpg.c
@@ -212,23 +212,21 @@ gpg_verify_signature (gpgme_ctx_t ctx, gpgme_signature_t sig,
}
}
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;
@@ -256,13 +254,13 @@ verify_directive_signature (struct file_triplet *trp,
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
@@ -280,18 +278,20 @@ verify_directive_signature (struct file_triplet *trp,
}
/* 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,
diff --git a/src/process.c b/src/process.c
index 23641cd..676e565 100644
--- a/src/process.c
+++ b/src/process.c
@@ -199,13 +199,13 @@ scan_spool_unlocked (const struct spool *spool, int uc, uid_t *uv)
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)
{
diff --git a/src/triplet.c b/src/triplet.c
index 0744daa..efe4a0b 100644
--- a/src/triplet.c
+++ b/src/triplet.c
@@ -57,22 +57,23 @@ hash_triplet_free (void *data)
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))))
@@ -120,13 +121,13 @@ enum triplet_state
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))
@@ -173,15 +174,12 @@ remove_triplet (struct file_triplet *trp)
/* 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),
@@ -190,13 +188,13 @@ triplet_processor (void *data, void *proc_data)
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);
@@ -207,13 +205,13 @@ triplet_processor (void *data, void *proc_data)
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;
@@ -225,13 +223,13 @@ 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 ()
diff --git a/src/verify.c b/src/verify.c
index 7520466..01c61ea 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -190,21 +190,24 @@ uploader_find_frp (struct uploader_info *list, const char *fpr)
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;
@@ -298,13 +301,13 @@ verify_directive_file (struct file_triplet *trp, const struct spool *spool)
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;
}
diff --git a/src/wydawca.h b/src/wydawca.h
index 54ecf00..b44b5d7 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -235,12 +235,26 @@ struct spool
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,
@@ -398,13 +412,13 @@ enum exec_result wydawca_exec (int argc, const char **argv, int *retcode);
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);
@@ -425,18 +439,15 @@ 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);
@@ -447,14 +458,13 @@ 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);

Return to:

Send suggestions and report system problems to the System administrator.