diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-11 23:52:43 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-11 23:52:43 +0200 |
commit | 7c10eca883faa5dd5b01bf1e50b04abb792a6639 (patch) | |
tree | 51fc8746681d42bca8034f88510ff7f144215e70 | |
parent | 10a5f20232d2a57beb0a50b38b1d7196a7f5236e (diff) | |
download | wydawca-7c10eca883faa5dd5b01bf1e50b04abb792a6639.tar.gz wydawca-7c10eca883faa5dd5b01bf1e50b04abb792a6639.tar.bz2 |
Follow up to 87602f54.
Fix minor bugs. Update the testsuite. All tests pass now.
* modules/mailutils/mod_mailutils.c (cb_statistics): Remove. Use
wy_cb_statistics.
(expand_email_admin, expand_email_owner): Add missing functions.
* src/config.c (wy_cb_statistics): New function.
(wydawca_kw): Restore "statistics" statement.
* src/dictionary.c (dictionary_lookup): Fix debug levels.
* src/wydawca.h (wy_cb_statistics): New proto.
* tests/atlocal.in (wydawca_expandmeta): Expand @WD_MODDIR@
* tests/check-notify.at: Create notify.rc from notify.rcin
* tests/notify-upl.at: Likewise.
* tests/mailstats.at: Likewise.
* tests/upload-dry.at: Fix the expected output.
* tests/etc/mailstats.rc: Rename to tests/etc/mailstats.rcin.
* tests/etc/notify.rc: Rename to tests/etc/notify.rcin.
* tests/etc/Makefile.am: Update.
* tests/etc/wydawca.rcin: Update to the new syntax.
-rw-r--r-- | modules/mailutils/mod_mailutils.c | 142 | ||||
-rw-r--r-- | src/config.c | 10 | ||||
-rw-r--r-- | src/dictionary.c | 4 | ||||
-rw-r--r-- | src/wydawca.h | 3 | ||||
-rw-r--r-- | tests/atlocal.in | 6 | ||||
-rw-r--r-- | tests/check-notify.at | 3 | ||||
-rw-r--r-- | tests/etc/Makefile.am | 4 | ||||
-rw-r--r-- | tests/etc/mailstats.rcin (renamed from tests/etc/mailstats.rc) | 20 | ||||
-rw-r--r-- | tests/etc/notify.rcin (renamed from tests/etc/notify.rc) | 81 | ||||
-rw-r--r-- | tests/etc/wydawca.rcin | 6 | ||||
-rw-r--r-- | tests/mailstats.at | 3 | ||||
-rw-r--r-- | tests/notify-upl.at | 3 | ||||
-rw-r--r-- | tests/upload-dry.at | 2 |
13 files changed, 140 insertions, 147 deletions
diff --git a/modules/mailutils/mod_mailutils.c b/modules/mailutils/mod_mailutils.c index 8698537..2265a76 100644 --- a/modules/mailutils/mod_mailutils.c +++ b/modules/mailutils/mod_mailutils.c @@ -452,123 +452,20 @@ cb_email_address(enum grecs_callback_command cmd, grecs_node_t *node, } *(mu_address_t *) varptr = addr; return rc; } -static struct mu_kwd stat_tab[] = { - { "errors", STAT_ERRORS }, - { "warnings", STAT_WARNINGS }, - { "bad-signatures", STAT_BAD_SIGNATURE }, - { "access-violations", STAT_ACCESS_VIOLATIONS }, - { "complete-triplets", STAT_COMPLETE_TRIPLETS }, - { "incomplete-triplets", STAT_INCOMPLETE_TRIPLETS }, - { "bad-triplets", STAT_BAD_TRIPLETS }, - { "expired-triplets", STAT_EXPIRED_TRIPLETS }, - { "triplet-success", STAT_TRIPLET_SUCCESS }, - { "uploads", STAT_UPLOADS }, - { "archives", STAT_ARCHIVES }, - { "symlinks", STAT_SYMLINKS }, - { "rmsymlinks", STAT_RMSYMLINKS }, - { NULL }, -}; - -static int -parse_single_statmask(grecs_locus_t *locus, const grecs_value_t *val, - unsigned long *pmask, int *invert) -{ - const char *arg; - int x; - - if (val->type != GRECS_TYPE_STRING) { - grecs_error(&val->locus, 0, - _("expected scalar value but found list")); - return 1; - } - - arg = val->v.string; - - if (strcmp(arg, "all") == 0) { - *pmask = STAT_MASK_ALL; - *invert = 1; - return 0; - } else if (strcmp(arg, "none") == 0) { - *pmask = STAT_MASK_NONE; - *invert = 0; - return 0; - } - - if (mu_kwd_xlat_name(stat_tab, arg, &x)) { - grecs_error(&val->locus, 0, _("unknown statistics type: %s"), - arg); - return 1; - } - *pmask = STAT_MASK(x); - return 0; -} - -static int -parse_statmask(grecs_locus_t *loc, grecs_value_t *val, unsigned long *pmask) -{ - int err = 0; - int invert = 0; - unsigned long mask = 0; - int i; - struct grecs_list_entry *ep; - - switch (val->type) { - case GRECS_TYPE_STRING: - err = parse_single_statmask(loc, val, &mask, &invert); - break; - - case GRECS_TYPE_ARRAY: - for (i = 0; i < val->v.arg.c; i++) { - unsigned long x; - if (parse_single_statmask(loc, val->v.arg.v[i], - &x, &invert)) - err = 1; - else if (invert) - mask &= ~x; - else - mask |= x; - } - break; - - case GRECS_TYPE_LIST: - for (ep = val->v.list->head; ep; ep = ep->next) { - const grecs_value_t *vp = ep->data; - unsigned long x; - - if (parse_single_statmask(loc, vp, &x, &invert)) - err = 1; - else if (invert) - mask &= ~x; - else - mask |= x; - } - break; - } - if (!err) - *pmask = mask; - return err; -} - -static int -cb_statistics(enum grecs_callback_command cmd, grecs_node_t *node, - void *varptr, void *cb_data) -{ - return parse_statmask(&node->locus, node->v.value, varptr); -} - static struct grecs_keyword mail_statistics_kw[] = { { "message", N_("text"), N_("Message text"), grecs_type_string, GRECS_DFLT, &admin_stat_message }, { "statistics", N_("items"), N_("Send mail if one or more of these items are set"), - grecs_type_string, GRECS_DFLT, &mail_admin_mask, 0, cb_statistics }, + grecs_type_string, GRECS_DFLT, &mail_admin_mask, 0, + wy_cb_statistics }, { "gpg-sign", N_("key"), N_("Sign message with this key"), grecs_type_string, GRECS_DFLT, &admin_stat_sign_key }, { NULL } }; @@ -809,12 +706,45 @@ get_recipient(struct dictionary *dict, struct file_triplet const *trp, } dictionary_close(dict, md); return rcpt; } +const char * +expand_email_admin(struct metadef *def, void *data) +{ + if (mu_address_aget_printable(admin_address, &def->storage) == 0) + def->value = def->storage; + else + def->value = ""; + return def->value; +} + +const char * +expand_email_owner(struct metadef *def, void *data) +{ + struct file_triplet *trp = data; + mu_address_t addr; + const char *errp; + + addr = get_recipient(trp->spool->dictionary[project_owner_dict], + trp, &errp); + if (!addr) { + wy_log(LOG_ERR, _("cannot get email of the %s's owner: %s"), + trp->project, gettext(errp)); + def->value = ""; + } else { + if (mu_address_aget_printable(addr, &def->storage) == 0) + def->value = def->storage; + else + def->value = ""; + mu_address_destroy(&addr); + } + return def->value; +} + static void t_notify(struct mailevt *evt, int ev, struct file_triplet const *trp) { mu_address_t rcpt = NULL; const char *errp; char *text; @@ -932,11 +862,13 @@ mail_stats(struct mailevt *evt) } void mod_mailutils_LTX_notify(void *data, int ev, struct file_triplet const *trp) { struct mailevt *evt = data; + if (trp) t_notify(evt, ev, trp); else if (ev == ev_statistics) mail_stats(evt); } + diff --git a/src/config.c b/src/config.c index 8dbc788..b89beff 100644 --- a/src/config.c +++ b/src/config.c @@ -437,12 +437,19 @@ parse_statmask(grecs_locus_t *loc, grecs_value_t *val, unsigned long *pmask) } if (!err) *pmask = mask; return err; } +int +wy_cb_statistics(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) +{ + return parse_statmask(&node->locus, node->v.value, varptr); +} + static int cb_sql_host(enum grecs_callback_command cmd, grecs_node_t *node, void *varptr, void *cb_data) { struct sqlconn *pconn = varptr; @@ -1291,12 +1298,15 @@ static struct grecs_keyword wydawca_kw[] = { grecs_type_string, GRECS_DFLT, NULL, 0, cb_set_umask }, { "archive-signatures", NULL, N_("Control implicit signature archivation"), grecs_type_bool, GRECS_DFLT, &archive_signatures }, + { "statistics", N_("items"), N_("Print these stats at the end of run"), + grecs_type_string, GRECS_DFLT, &print_stats, 0, wy_cb_statistics }, + { "sql", N_("id: string"), N_("Define SQL database"), grecs_type_section, GRECS_DFLT, NULL, 0, cb_sql, NULL, sql_kw }, { "syslog", NULL, N_("Configure syslog logging"), grecs_type_section, GRECS_DFLT, NULL, 0, NULL, NULL, syslog_kw }, diff --git a/src/dictionary.c b/src/dictionary.c index 4f18267..0b96543 100644 --- a/src/dictionary.c +++ b/src/dictionary.c @@ -126,16 +126,16 @@ dictionary_done(struct dictionary *dict) int dictionary_lookup(struct dictionary *dict, void *handle, const char *cmd) { struct dictionary_descr *mp = dictionary_tab + dict->type; if (cmd) - wy_debug(1, (_("dictionary lookup: %s \"%s\""), + wy_debug(2, (_("dictionary lookup: %s \"%s\""), mp->name, cmd)); else - wy_debug(1, (_("dictionary lookup: %s"), + wy_debug(2, (_("dictionary lookup: %s"), mp->name)); if (!dict->init_passed) { wy_log(LOG_CRIT, _("INTERNAL ERROR: " "dictionary %s \"%s\" not initialized"), diff --git a/src/wydawca.h b/src/wydawca.h index 89d0458..08126ac 100644 --- a/src/wydawca.h +++ b/src/wydawca.h @@ -272,12 +272,15 @@ enum wydawca_stat { MAX_STAT }; #define STAT_MASK(c) (1<<(c)) #define STAT_MASK_NONE 0 #define STAT_MASK_ALL (STAT_MASK(MAX_STAT) - 1) + +int wy_cb_statistics(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data); enum notification_event { ev_success, ev_bad_ownership, ev_bad_directive_signature, ev_bad_detached_signature, diff --git a/tests/atlocal.in b/tests/atlocal.in index 50c5a60..89cfd3f 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -27,13 +27,17 @@ wydawca_init_testdirs() { wydawca_clean_testdirs() { rm -rf "$WD_SRC" "$WD_DST" } wydawca_expandmeta() { - sed "s/@USER@/$USER/g;s,@WD_SRC@,$WD_SRC,g;s,@WD_DST@,$WD_DST,g;s,@WD_CONFSRC@,$WD_CONFSRC,g" $1 > $2 + sed "s/@USER@/$USER/g; + s,@WD_SRC@,$WD_SRC,g; + s,@WD_DST@,$WD_DST,g; + s,@WD_CONFSRC@,$WD_CONFSRC,g; + s,@WD_MODDIR@,@abs_top_builddir@/modules/mailutils,g" $1 > $2 } wydawca_config() { wydawca_expandmeta $WD_CONFSRC/${1}in $1 } diff --git a/tests/check-notify.at b/tests/check-notify.at index 7be4741..bebfa4b 100644 --- a/tests/check-notify.at +++ b/tests/check-notify.at @@ -68,13 +68,14 @@ The Project Submission Robot ]) AT_CHECK([ wydawca_init_testdirs wydawca_config wydawca.rc mv wydawca.rc simple.rc -cat $WD_CONFSRC/notify.rc simple.rc > wydawca.rc +wydawca_config notify.rc +cat notify.rc simple.rc >> wydawca.rc wydawca_upload fail file wydawca_expandmeta outtmpl expout wydawca_expandmeta template experr diff --git a/tests/etc/Makefile.am b/tests/etc/Makefile.am index 4d1322b..086b659 100644 --- a/tests/etc/Makefile.am +++ b/tests/etc/Makefile.am @@ -18,15 +18,15 @@ GPGFILES = secring.gpg pubring.gpg noinst_DATA = @WYDAWCA_GPGFILES@ EXTRA_DIST = \ pubring.asc\ secring.asc\ wydawca.rcin\ - notify.rc\ + notify.rcin\ nullmail\ - mailstats.rc + mailstats.rcin GPG_FLAGS = --quiet --no-permission-warning --homedir . pubring.gpg secring.gpg: $(srcdir)/pubring.asc $(srcdir)/secring.asc $(GPG) $(GPG_FLAGS) --import < $(srcdir)/pubring.asc $(GPG) $(GPG_FLAGS) --allow-secret-key-import --import < $(srcdir)/secring.asc diff --git a/tests/etc/mailstats.rc b/tests/etc/mailstats.rcin index c85345e..b3aeab7 100644 --- a/tests/etc/mailstats.rc +++ b/tests/etc/mailstats.rcin @@ -11,15 +11,23 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Wydawca. If not, see <http://www.gnu.org/licenses/>. -mail-statistics { - statistics all; - message <<EOT +module-prepend-load-path "@WD_MODDIR@"; +module mailutils mod_mailutils.la; +module-init mailutils { + admin-address "root@localhost"; + from-address "wydawca-noreply@localhost"; + + mailer "| @WD_CONFSRC@/nullmail @WD_DST@/mail.out -F ${sender} ${rcpt}"; + + mail-statistics { + statistics all; + message <<EOT Subject: Wydawca stats This is to notify you that the recent run of wydawca caused the following results: errors ............................. ${stat:errors} @@ -36,7 +44,13 @@ files archived ..................... ${stat:archives} symlinks created ................... ${stat:symlinks} symlinks removed ................... ${stat:rmsymlinks} Regards, Wydawca EOT; + } +} + +notify-event { + event statistics; + module mailutils; } diff --git a/tests/etc/notify.rc b/tests/etc/notify.rcin index 635e275..55f9c72 100644 --- a/tests/etc/notify.rc +++ b/tests/etc/notify.rcin @@ -11,54 +11,71 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Wydawca. If not, see <http://www.gnu.org/licenses/>. +module-prepend-load-path "@WD_MODDIR@"; +module mailutils mod_mailutils.la; +module-init mailutils { + admin-address "root@localhost"; + from-address "wydawca-noreply@localhost"; + + mailer "| @WD_CONFSRC@/nullmail @WD_DST@/mail.out -F ${sender} ${rcpt}"; +} + # Notify the user about successful uploads notify-event { - event success; - recipient user; - message <<EOT + event success; + module mailutils; + module-config { + recipient user; + message <<EOT Subject: Upload of ${project} successful Upload of ${project} to ${url}/${dir} finished successfully. Files uploaded: ${triplet:ls:upload}$- Regards, Wydawca The Project Submission Robot EOT; + } } # Notify project admin about a successful upload. notify-event { - event success; - recipient owner; - message <<EOT + event success; + module mailutils; + module-config { + recipient owner; + message <<EOT Subject: Upload of ${project} successful ${user:real-name} (${user:email}) successfully uploaded files for ${project} to ${url}/${dir}. Files uploaded: ${triplet:ls:upload}$- Regards, Wydawca The Project Submission Robot EOT; + } } # Notify project admin, if someone non authorized attempted to upload some # files for the project they run. notify-event { - event bad-ownership; - recipient owner; - message <<EOT + event bad-ownership; + module mailutils; + module-config { + recipient owner; + message <<EOT Subject: Suspicious upload of ${project} Someone not authorized to make releases for ${project} has attempted to upload the following files to ${url}/${dir}: ${triplet:ls:full}$- @@ -70,23 +87,26 @@ releases for ${project}, please contact <puszcza-hackers@gnu.org.ua>. Otherwise, let us know so we could undertake appropriate measures. Regards, Wydawca The Project Submission Robot EOT; + } } # Notify the user (submitter), if the directive signature does not match # his record. # It may be a good idea not to notify users about such events, just to # stay on a safe side. Notifying project admins (see below) should be quite # enough. notify-event { - event bad-directive-signature; - recipient user; - message <<EOT + event bad-directive-signature; + module mailutils; + module-config { + recipient user; + message <<EOT Subject: Suspicious upload of ${project} Someone (apparently you), has tried to make a release for ${project}. However, the signature of the directive file was wrong, which looks suspicious. The person uploaded the following files: @@ -98,20 +118,23 @@ try again. If not, please let us know as soon as possible, so we can track down the person trying to make believe he is you. Regards, Wydawca The Project Submission Robot EOT; + } } # Notify the project admin, if submitted directive signature did not match # submitter record. notify-event { - event bad-directive-signature; - recipient owner; - message <<EOT + event bad-directive-signature; + module mailutils; + module-config { + recipient owner; + message <<EOT Subject: Suspicious upload of ${project} ${user:real-name} (${user:email}) has tried to make a release for ${project}. However, the signature of the directive file was wrong, which looks suspicious. The person uploaded the following files: @@ -120,23 +143,26 @@ ${triplet:ls:full} This upload has been ignored and the files removed. Regards, Wydawca The Project Submission Robot EOT; + } } # Notify the user (submitter), if the detached signature does not match # his record. # It may be a good idea not to notify users about such events, just to # stay on a safe side. Notifying project admins (see below) should be quite # enough. notify-event { - event bad-detached-signature; - recipient user; - message <<EOT + event bad-detached-signature; + module mailutils; + module-config { + recipient user; + message <<EOT Subject: Suspicious upload of ${project} Someone (apparently you), has tried to make a release for ${project}. However, the detached signature signature was wrong, which looks suspicious. The person uploaded the following files: @@ -148,20 +174,23 @@ try again. If not, please let us know as soon as possible, so we can track down the person trying to make believe he is you. Regards, Wydawca The Project Submission Robot EOT; + } } # Notify the project admin, if submitted detached signature did not match # submitter record. notify-event { - event bad-detached-signature; - recipient owner; - message <<EOT + event bad-detached-signature; + module mailutils; + module-config { + recipient owner; + message <<EOT Subject: Suspicious upload of ${project} ${user:real-name} (${user:email}) has tried to make a release for ${project}. However, the detached signature file was wrong, which looks suspicious. The person uploaded the following files: @@ -170,18 +199,21 @@ ${triplet:ls:full} This upload has been ignored and the files removed. Regards, Wydawca The Project Submission Robot EOT; + } } notify-event { - event check-failure; - recipient user; - message <<EOT + event check-failure; + module mailutils; + module-config { + recipient user; + message <<EOT Subject: ${triplet:dist} rejected Your upload of ${triplet:dist} has been rejected by the distribution verification procedure with the following diagnostics: ${check:diagn}$- @@ -189,9 +221,10 @@ ${check:diagn}$- Please fix the tarball and resubmit. Regards, Wydawca The Project Submission Robot EOT; + } } diff --git a/tests/etc/wydawca.rcin b/tests/etc/wydawca.rcin index ec87a7b..d020eff 100644 --- a/tests/etc/wydawca.rcin +++ b/tests/etc/wydawca.rcin @@ -92,12 +92,6 @@ spool ckok { url ftp://wydawca.ckok; source "@WD_SRC@/ok"; destination "@WD_DST@"; archive none; check-script "exit 0"; } - -admin-address "root@localhost"; -from-address "wydawca-noreply@localhost"; - -mailer "| @WD_CONFSRC@/nullmail @WD_DST@/mail.out -F ${sender} ${rcpt}"; - diff --git a/tests/mailstats.at b/tests/mailstats.at index 59f8e0c..e5c769d 100644 --- a/tests/mailstats.at +++ b/tests/mailstats.at @@ -66,13 +66,14 @@ Regards, Wydawca ]) AT_CHECK([ wydawca_init_testdirs wydawca_config wydawca.rc -cat $WD_CONFSRC/mailstats.rc >> wydawca.rc +wydawca_config mailstats.rc +cat mailstats.rc >> wydawca.rc wydawca_upload test file wydawca_expandmeta errtmpl experr ulimit -c unlimited wydawca --no-preproc -c wydawca.rc || exit $? wydawca_cmp proj file file.sig diff --git a/tests/notify-upl.at b/tests/notify-upl.at index ee35056..b6425ba 100644 --- a/tests/notify-upl.at +++ b/tests/notify-upl.at @@ -79,13 +79,14 @@ s,^-[[rwx-]]\{9\} @USER@.*file.sig$,listing of file.sig, ]) AT_CHECK([ wydawca_init_testdirs wydawca_config wydawca.rc mv wydawca.rc simple.rc -cat $WD_CONFSRC/notify.rc simple.rc > wydawca.rc +wydawca_config notify.rc +cat notify.rc simple.rc >> wydawca.rc wydawca_upload test file wydawca_expandmeta errtmpl experr wydawca_expandmeta outtmpl expout wydawca_expandmeta ls.sin ls.sed diff --git a/tests/upload-dry.at b/tests/upload-dry.at index e2e4063..56ccc67 100644 --- a/tests/upload-dry.at +++ b/tests/upload-dry.at @@ -20,13 +20,13 @@ AT_DATA([template], [wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started wydawca: [[DEBUG]] @WD_SRC@/ok -> @WD_DST@ wydawca: [[DEBUG]] @WD_SRC@/fail -> @WD_DST@ wydawca: [[DEBUG]] @WD_SRC@/test -> @WD_DST@ wydawca: [[DEBUG]] processing spool test (@WD_DST@) wydawca: [[DEBUG]] FILE file, DIST=file, SIG=file.sig, DIRECTIVE=file.directive.asc -wydawca: [[NOTICE]] Good signature from Wydawca (Testsuite) <bug-wydawca@gnu.org.ua> +wydawca: [[DEBUG]] Good signature from Wydawca (Testsuite) <bug-wydawca@gnu.org.ua> wydawca: [[DEBUG]] file: directive file signature OK wydawca: [[NOTICE]] file.directive.asc: VERSION: 1.1 wydawca: [[DEBUG]] processing triplet `file' wydawca: [[NOTICE]] file.directive.asc: COMMENT: Gnupload for Wydawca testsuite wydawca: [[DEBUG]] good detached signature for file wydawca: [[DEBUG]] installing file to @WD_DST@/proj |