aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-04-10 21:04:21 +0300
committerSergey Poznyakoff <gray@gnu.org>2020-04-10 21:07:52 +0300
commita9da878ff22f980cea3bf3102113d7f2e65f61e9 (patch)
treedd3e21c580b91f6ab3d64e228ccb23170f3ddac3
parentda966c314f92d17b45ede9aa77ad3d3624c36725 (diff)
downloadwydawca-a9da878ff22f980cea3bf3102113d7f2e65f61e9.tar.gz
wydawca-a9da878ff22f980cea3bf3102113d7f2e65f61e9.tar.bz2
Change indentation to improve readability.
-rw-r--r--configure.ac5
-rw-r--r--modules/logstat/mod_logstat.c140
-rw-r--r--modules/mailutils/mod_mailutils.c1320
-rw-r--r--src/backup.c232
-rw-r--r--src/builtin.c277
-rw-r--r--src/cmdline.opt134
-rw-r--r--src/config.c2730
-rw-r--r--src/dictionary.c265
-rw-r--r--src/directive.c997
-rw-r--r--src/diskio.c989
-rw-r--r--src/event.c25
-rw-r--r--src/exec.c230
-rw-r--r--src/gpg.c451
-rw-r--r--src/interval.c144
-rw-r--r--src/job.c654
-rw-r--r--src/lock.c373
-rw-r--r--src/module.c429
-rw-r--r--src/net.c375
-rw-r--r--src/null.c46
-rw-r--r--src/pidfile.c76
-rw-r--r--src/process.c370
-rw-r--r--src/pushd.c176
-rw-r--r--src/report.c36
-rw-r--r--src/sql.c240
-rw-r--r--src/sql.h29
-rw-r--r--src/tcpwrap.c94
-rw-r--r--src/timer.c189
-rw-r--r--src/triplet.c1726
-rw-r--r--src/userprivs.c137
-rw-r--r--src/verify.c275
-rw-r--r--src/vtab.c156
-rw-r--r--src/watcher.c307
-rw-r--r--src/wydawca.c552
-rw-r--r--src/wydawca.h299
-rw-r--r--tests/bkupname.c88
-rw-r--r--tests/nullmail.c103
-rw-r--r--tests/pushck.c34
37 files changed, 7289 insertions, 7414 deletions
diff --git a/configure.ac b/configure.ac
index ccce9d3..5febba2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -60,9 +60,8 @@ AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_FUNC_STAT
AC_FUNC_VPRINTF
-AC_CHECK_FUNCS([fchdir memset strchr strdup strerror strrchr setegid setregid\
- setresgid setresuid seteuid setreuid vsyslog sysconf getdtablesize\
- inotify_init])
+AC_CHECK_FUNCS([fchdir setegid setregid setresgid setresuid seteuid \
+ setreuid vsyslog sysconf getdtablesize inotify_init])
# **********************
# Mailutils
diff --git a/modules/logstat/mod_logstat.c b/modules/logstat/mod_logstat.c
index 760984f..a0ece89 100644
--- a/modules/logstat/mod_logstat.c
+++ b/modules/logstat/mod_logstat.c
@@ -28,101 +28,101 @@ static int stat_mask = WY_STAT_MASK_ALL;
static struct grecs_list *log_msg;
static struct grecs_keyword logstat_kw[] = {
- { "statistics", N_("items"),
- N_("Log these statistics items"),
- grecs_type_string, GRECS_DFLT, &stat_mask, 0,
- wy_cb_statistics },
- { "message", N_("text"),
- N_("Log additional message"),
- grecs_type_string, GRECS_LIST|GRECS_AGGR, &log_msg, 0, NULL },
- { NULL }
+ { "statistics", N_("items"),
+ N_("Log these statistics items"),
+ grecs_type_string, GRECS_DFLT, &stat_mask, 0,
+ wy_cb_statistics },
+ { "message", N_("text"),
+ N_("Log additional message"),
+ grecs_type_string, GRECS_LIST|GRECS_AGGR, &log_msg, 0, NULL },
+ { NULL }
};
void *
wy_config(grecs_node_t *node)
{
- grecs_tree_reduce(node, logstat_kw, 0);
- if (grecs_tree_process(node->down, logstat_kw))
- return NULL;
- return &stat_mask;
+ grecs_tree_reduce(node, logstat_kw, 0);
+ if (grecs_tree_process(node->down, logstat_kw))
+ return NULL;
+ return &stat_mask;
}
static void
logmsg(char *s)
{
- char *p;
-
- while ((p = strchr(s, '\n'))) {
- *p++ = 0;
- wy_log(LOG_INFO, "%s", s);
- s = p;
- }
- if (*s)
- wy_log(LOG_INFO, "%s", s);
+ char *p;
+
+ while ((p = strchr(s, '\n'))) {
+ *p++ = 0;
+ wy_log(LOG_INFO, "%s", s);
+ s = p;
+ }
+ if (*s)
+ wy_log(LOG_INFO, "%s", s);
}
static char *default_log_message[] = {
- "errors: ${stat:errors}",
- "warnings: ${stat:warnings}",
- "bad signatures: ${stat:bad_signatures}",
- "access violation attempts: ${stat:access_violations}",
- "complete triplets: ${stat:complete_triplets}",
- "incomplete triplets: ${stat:incomplete_triplets}",
- "bad triplets: ${stat:bad_triplets}",
- "expired triplets: ${stat:expired_triplets}",
- "triplet successes: ${stat:triplet_success}",
- "files uploaded: ${stat:uploads}",
- "files archived: ${stat:archives}",
- "symlinks created: ${stat:symlinks}",
- "symlinks removed: ${stat:rmsymlinks}",
- "check failures: ${stat:check_failures}",
- NULL
+ "errors: ${stat:errors}",
+ "warnings: ${stat:warnings}",
+ "bad signatures: ${stat:bad_signatures}",
+ "access violation attempts: ${stat:access_violations}",
+ "complete triplets: ${stat:complete_triplets}",
+ "incomplete triplets: ${stat:incomplete_triplets}",
+ "bad triplets: ${stat:bad_triplets}",
+ "expired triplets: ${stat:expired_triplets}",
+ "triplet successes: ${stat:triplet_success}",
+ "files uploaded: ${stat:uploads}",
+ "files archived: ${stat:archives}",
+ "symlinks created: ${stat:symlinks}",
+ "symlinks removed: ${stat:rmsymlinks}",
+ "check failures: ${stat:check_failures}",
+ NULL
};
void
wy_notify(void *data, int ev, wy_triplet_t const *trp)
{
- struct grecs_list_entry *ep;
- char *text;
-
- if (ev != wy_ev_finish || !wy_stat_mask_p(stat_mask))
- return;
-
- if (log_msg) {
- for (ep = log_msg->head; ep; ep = ep->next) {
- text = wy_expand_stats(ep->data);
- logmsg(text);
- free(text);
- }
- } else {
- int i;
- for (i = 0; default_log_message[i]; i++) {
- if (wy_stat_mask_p(WY_STAT_MASK(i))) {
- text = wy_expand_stats(default_log_message[i]);
- logmsg(text);
- free(text);
- }
- }
+ struct grecs_list_entry *ep;
+ char *text;
+
+ if (ev != wy_ev_finish || !wy_stat_mask_p(stat_mask))
+ return;
+
+ if (log_msg) {
+ for (ep = log_msg->head; ep; ep = ep->next) {
+ text = wy_expand_stats(ep->data);
+ logmsg(text);
+ free(text);
+ }
+ } else {
+ int i;
+ for (i = 0; default_log_message[i]; i++) {
+ if (wy_stat_mask_p(WY_STAT_MASK(i))) {
+ text = wy_expand_stats(default_log_message[i]);
+ logmsg(text);
+ free(text);
+ }
}
+ }
}
void
wy_help(void)
{
- static struct grecs_keyword top[] = {
- { "module-config", NULL,
- "module configuration",
- grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL,
- logstat_kw },
- { NULL }
- };
- static char const *docstring = "\n\
+ static struct grecs_keyword top[] = {
+ { "module-config", NULL,
+ "module configuration",
+ grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL,
+ logstat_kw },
+ { NULL }
+ };
+ static char const *docstring = "\n\
mod_logstat sends statistics reports to syslog\n";
- puts(docstring);
- printf("# Usage in notify-event statement:\n");
- printf("notify-event {\n event statistics;\n module logstat;");
- grecs_print_statement_array(top, 1, 1, stdout);
- printf("}\n");
+ puts(docstring);
+ printf("# Usage in notify-event statement:\n");
+ printf("notify-event {\n event statistics;\n module logstat;");
+ grecs_print_statement_array(top, 1, 1, stdout);
+ printf("}\n");
}
diff --git a/modules/mailutils/mod_mailutils.c b/modules/mailutils/mod_mailutils.c
index a0f6ec1..a924cdb 100644
--- a/modules/mailutils/mod_mailutils.c
+++ b/modules/mailutils/mod_mailutils.c
@@ -37,9 +37,9 @@ static char *admin_stat_message;
static char *admin_stat_sign_key;
struct message_template {
- char *name;
- char *text;
- /* int mime; for future use */
+ char *name;
+ char *text;
+ /* int mime; for future use */
};
static struct grecs_symtab *tmpl_table;
@@ -48,819 +48,811 @@ static struct grecs_symtab *tmpl_table;
void
register_message_template(const char *name, const char *text)
{
- struct message_template key, *tmpl;
- int install = 1;
-
- key.name = (char *)text;
-
- if (!tmpl_table) {
- tmpl_table = grecs_symtab_create_default(sizeof(key));
- if (!tmpl_table)
- grecs_alloc_die();
- }
-
- tmpl = grecs_symtab_lookup_or_install(tmpl_table, &key, &install);
- if (!tmpl)
- grecs_alloc_die();
- if (!install)
- grecs_warning(NULL, 0, "template %s already registered", text);
+ struct message_template key, *tmpl;
+ int install = 1;
+
+ key.name = (char *)text;
+
+ if (!tmpl_table) {
+ tmpl_table = grecs_symtab_create_default(sizeof(key));
+ if (!tmpl_table)
+ grecs_alloc_die();
+ }
+
+ tmpl = grecs_symtab_lookup_or_install(tmpl_table, &key, &install);
+ if (!tmpl)
+ grecs_alloc_die();
+ if (!install)
+ grecs_warning(NULL, 0, "template %s already registered", text);
}
const char *
resolve_message_template(const char *name)
{
- if (name[0] == '@') {
- if (name[1] == '@')
- return name + 1;
- else if (!tmpl_table)
- return NULL;
- else {
- struct message_template *p, key;
-
- key.name = (char *)name + 1;
- p = grecs_symtab_lookup_or_install(tmpl_table, &key,
- NULL);
- return p ? p->text : NULL;
- }
- }
- return name;
+ if (name[0] == '@') {
+ if (name[1] == '@')
+ return name + 1;
+ else if (!tmpl_table)
+ return NULL;
+ else {
+ struct message_template *p, key;
+
+ key.name = (char *)name + 1;
+ p = grecs_symtab_lookup_or_install(tmpl_table, &key, NULL);
+ return p ? p->text : NULL;
+ }
+ }
+ return name;
}
static int
cb_define_message(enum grecs_callback_command cmd, grecs_node_t *node,
void *varptr, void *cb_data)
{
- const char *ident;
- grecs_locus_t *locus = &node->locus;
- grecs_value_t *value = node->v.value;
-
- if (cmd != grecs_callback_set_value) {
- grecs_error(locus, 0, _("Unexpected block statement"));
- return 1;
- }
- if (!value || value->type != GRECS_TYPE_ARRAY || value->v.arg.c != 2) {
- grecs_error(locus, 0, _("expected two arguments"));
- return 1;
- }
-
- if (value->v.arg.v[0]->type != GRECS_TYPE_STRING) {
- grecs_error(&value->v.arg.v[0]->locus, 0,
- _("first argument not a string"));
- return 1;
- }
- ident = value->v.arg.v[0]->v.string;
-
- if (value->v.arg.v[1]->type != GRECS_TYPE_STRING) {
- grecs_error(&value->v.arg.v[1]->locus, 0,
- _("second argument not a string"));
- return 1;
- }
-
- register_message_template(ident, value->v.arg.v[1]->v.string);
- return 0;
+ const char *ident;
+ grecs_locus_t *locus = &node->locus;
+ grecs_value_t *value = node->v.value;
+
+ if (cmd != grecs_callback_set_value) {
+ grecs_error(locus, 0, _("Unexpected block statement"));
+ return 1;
+ }
+ if (!value || value->type != GRECS_TYPE_ARRAY || value->v.arg.c != 2) {
+ grecs_error(locus, 0, _("expected two arguments"));
+ return 1;
+ }
+
+ if (value->v.arg.v[0]->type != GRECS_TYPE_STRING) {
+ grecs_error(&value->v.arg.v[0]->locus, 0,
+ _("first argument not a string"));
+ return 1;
+ }
+ ident = value->v.arg.v[0]->v.string;
+
+ if (value->v.arg.v[1]->type != GRECS_TYPE_STRING) {
+ grecs_error(&value->v.arg.v[1]->locus, 0,
+ _("second argument not a string"));
+ return 1;
+ }
+
+ register_message_template(ident, value->v.arg.v[1]->v.string);
+ return 0;
}
static ssize_t
mu_stream_data_read_cb(void *handle, void *buffer, size_t size)
{
- mu_stream_t str = handle;
- size_t nread;
- int rc;
-
- rc = mu_stream_read(str, buffer, size, &nread);
- if (rc) {
- wy_log(LOG_ERR, "mu_stream_read: %s", mu_strerror(rc));
- errno = EIO;
- return -1;
- }
- return nread;
+ mu_stream_t str = handle;
+ size_t nread;
+ int rc;
+
+ rc = mu_stream_read(str, buffer, size, &nread);
+ if (rc) {
+ wy_log(LOG_ERR, "mu_stream_read: %s", mu_strerror(rc));
+ errno = EIO;
+ return -1;
+ }
+ return nread;
}
static int
check_sign_result(gpgme_sign_result_t result, gpgme_sig_mode_t type)
{
- gpgme_new_signature_t sign;
-
- if (result->invalid_signers) {
- wy_log(LOG_ERR, _("GPGME: invalid signer found: %s"),
- result->invalid_signers->fpr);
- return 1;
- }
-
- if (!result->signatures) {
- wy_log(LOG_ERR, _("GPGME: no signatures created"));
- return 1;
- }
-
- for (sign = result->signatures; sign; sign = sign->next) {
- if (sign->type != type) {
- wy_log(LOG_ERR,
- _("GPGME: wrong type of signature created"));
- return 1;
- }
- }
- /* FIXME: fingerprint? */
- return 0;
+ gpgme_new_signature_t sign;
+
+ if (result->invalid_signers) {
+ wy_log(LOG_ERR, _("GPGME: invalid signer found: %s"),
+ result->invalid_signers->fpr);
+ return 1;
+ }
+
+ if (!result->signatures) {
+ wy_log(LOG_ERR, _("GPGME: no signatures created"));
+ return 1;
+ }
+
+ for (sign = result->signatures; sign; sign = sign->next) {
+ if (sign->type != type) {
+ wy_log(LOG_ERR, _("GPGME: wrong type of signature created"));
+ return 1;
+ }
+ }
+ /* FIXME: fingerprint? */
+ return 0;
}
static int
gpg_sign(gpgme_data_t * output, gpgme_data_t input, const char *sign_keys)
{
- gpgme_ctx_t ctx;
- gpgme_error_t err = 0;
- gpgme_key_t key;
- int ret;
-
- err = gpgme_new(&ctx);
- if (err) {
- wy_log(LOG_ERR, _("GPGME: cannot create context: %s"),
- gpgme_strerror(err));
- return 1;
- }
-
- err = gpgme_op_keylist_start(ctx, sign_keys, 0);
- if (!err) {
- while ((err = gpgme_op_keylist_next(ctx, &key)) == 0) {
- err = gpgme_signers_add(ctx, key);
- gpgme_key_release(key);
- }
- }
-
- if (err && gpg_err_code(err) != GPG_ERR_EOF) {
- wy_log(LOG_ERR, _("GPGME: cannot list keys: %s"),
- gpgme_strerror(err));
- gpgme_release(ctx);
- return 1;
- }
-
- err = gpgme_data_new(output);
- if (err) {
- wy_log(LOG_ERR, _("%s: GPGME error: %s"),
- "gpgme_data_new", gpgme_strerror(err));
- gpgme_release(ctx);
- return 1;
- }
-
- /* FIXME: Passphrase */
- gpgme_set_textmode(ctx, 1);
- gpgme_set_armor(ctx, 1);
-
- err = gpgme_op_sign(ctx, input, *output, GPGME_SIG_MODE_CLEAR);
- if (err) {
- wy_log(LOG_ERR, _("%s: GPGME error: %s"),
- "gpgme_op_sign", gpgme_strerror(err));
- ret = 1;
- } else {
- ret = check_sign_result(gpgme_op_sign_result(ctx),
- GPGME_SIG_MODE_CLEAR);
+ gpgme_ctx_t ctx;
+ gpgme_error_t err = 0;
+ gpgme_key_t key;
+ int ret;
+
+ err = gpgme_new(&ctx);
+ if (err) {
+ wy_log(LOG_ERR, _("GPGME: cannot create context: %s"),
+ gpgme_strerror(err));
+ return 1;
+ }
+
+ err = gpgme_op_keylist_start(ctx, sign_keys, 0);
+ if (!err) {
+ while ((err = gpgme_op_keylist_next(ctx, &key)) == 0) {
+ err = gpgme_signers_add(ctx, key);
+ gpgme_key_release(key);
+ }
+ }
+
+ if (err && gpg_err_code(err) != GPG_ERR_EOF) {
+ wy_log(LOG_ERR, _("GPGME: cannot list keys: %s"),
+ gpgme_strerror(err));
+ gpgme_release(ctx);
+ return 1;
+ }
+
+ err = gpgme_data_new(output);
+ if (err) {
+ wy_log(LOG_ERR, _("%s: GPGME error: %s"),
+ "gpgme_data_new", gpgme_strerror(err));
+ gpgme_release(ctx);
+ return 1;
+ }
+
+ /* FIXME: Passphrase */
+ gpgme_set_textmode(ctx, 1);
+ gpgme_set_armor(ctx, 1);
+
+ err = gpgme_op_sign(ctx, input, *output, GPGME_SIG_MODE_CLEAR);
+ if (err) {
+ wy_log(LOG_ERR, _("%s: GPGME error: %s"),
+ "gpgme_op_sign", gpgme_strerror(err));
+ ret = 1;
+ } else {
+ ret = check_sign_result(gpgme_op_sign_result(ctx),
+ GPGME_SIG_MODE_CLEAR);
#if 0
- /* FIXME: */
- if (wy_debug_level > 1)
- gpgme_debug_info(ctx);
+ /* FIXME: */
+ if (wy_debug_level > 1)
+ gpgme_debug_info(ctx);
#endif
- }
-
- gpgme_release(ctx);
- return ret;
+ }
+
+ gpgme_release(ctx);
+ return ret;
}
static int
sign_message(mu_message_t *pmsg, const char *key)
{
- mu_message_t msg = *pmsg;
- mu_message_t newmsg;
- mu_body_t body;
- mu_header_t hdr;
- mu_stream_t istr, ostr, bodystr;
- int rc;
- struct gpgme_data_cbs cbs;
- gpgme_data_t input, output;
- gpgme_error_t err;
- char *buf = NULL;
- size_t size = 0;
- size_t nread;
-
- wy_debug(1, (_("signing message as %s"), key));
-
- if (wy_gpg_homedir) {
- wy_debug(2, (_("setting GNUPG home directory: %s"),
- wy_gpg_homedir));
- setenv("GNUPGHOME", wy_gpg_homedir, 1);
- }
-
- if ((rc = mu_message_get_body(msg, &body))) {
- wy_log(LOG_ERR, "mu_message_get_body: %s", mu_strerror(rc));
- return 1;
- }
-
- if ((rc = mu_body_get_streamref(body, &bodystr))) {
- wy_log(LOG_ERR, "mu_message_get_stream: %s", mu_strerror(rc));
- return 1;
- }
-
- memset(&cbs, 0, sizeof(cbs));
- cbs.read = mu_stream_data_read_cb;
-
- err = gpgme_data_new_from_cbs(&input, &cbs, &bodystr);
- if (err) {
- wy_log(LOG_ERR, "gpgme_data_new_from_cbs: %s",
- gpgme_strerror(rc));
- return 1;
- }
-
- rc = gpg_sign(&output, input, key);
- mu_stream_unref(bodystr);
- if (rc)
- return 1;
-
- if (gpgme_data_seek(output, 0, SEEK_SET) == -1) {
- wy_log(LOG_ERR, "gpgme_data_seek: %s", strerror(errno));
- return 1;
- }
-
- mu_message_create(&newmsg, NULL);
- mu_message_get_streamref(newmsg, &ostr);
-
- /* Copy headers */
- mu_message_get_header(msg, &hdr);
- mu_header_get_streamref(hdr, &istr);
-
- rc = mu_stream_copy(ostr, istr, 0, NULL);
- if (rc)
- wy_log(LOG_ERR, "mu_stream_copy: %s", mu_strerror(rc));
- else {
- while ((nread = gpgme_data_read(output, buf, size)) > 0) {
- rc = mu_stream_write(ostr, buf, nread, NULL);
- if (rc) {
- wy_log(LOG_ERR, "mu_stream_write: %s",
- mu_strerror(rc));
- break;
- }
- }
-
- if (rc == 0) {
- mu_message_destroy(&msg, mu_message_get_owner(msg));
- *pmsg = newmsg;
- }
+ mu_message_t msg = *pmsg;
+ mu_message_t newmsg;
+ mu_body_t body;
+ mu_header_t hdr;
+ mu_stream_t istr, ostr, bodystr;
+ int rc;
+ struct gpgme_data_cbs cbs;
+ gpgme_data_t input, output;
+ gpgme_error_t err;
+ char *buf = NULL;
+ size_t size = 0;
+ size_t nread;
+
+ wy_debug(1, (_("signing message as %s"), key));
+
+ if (wy_gpg_homedir) {
+ wy_debug(2, (_("setting GNUPG home directory: %s"),
+ wy_gpg_homedir));
+ setenv("GNUPGHOME", wy_gpg_homedir, 1);
+ }
+
+ if ((rc = mu_message_get_body(msg, &body))) {
+ wy_log(LOG_ERR, "mu_message_get_body: %s", mu_strerror(rc));
+ return 1;
+ }
+
+ if ((rc = mu_body_get_streamref(body, &bodystr))) {
+ wy_log(LOG_ERR, "mu_message_get_stream: %s", mu_strerror(rc));
+ return 1;
+ }
+
+ memset(&cbs, 0, sizeof(cbs));
+ cbs.read = mu_stream_data_read_cb;
+
+ err = gpgme_data_new_from_cbs(&input, &cbs, &bodystr);
+ if (err) {
+ wy_log(LOG_ERR, "gpgme_data_new_from_cbs: %s",
+ gpgme_strerror(rc));
+ return 1;
+ }
+
+ rc = gpg_sign(&output, input, key);
+ mu_stream_unref(bodystr);
+ if (rc)
+ return 1;
+
+ if (gpgme_data_seek(output, 0, SEEK_SET) == -1) {
+ wy_log(LOG_ERR, "gpgme_data_seek: %s", strerror(errno));
+ return 1;
+ }
+
+ mu_message_create(&newmsg, NULL);
+ mu_message_get_streamref(newmsg, &ostr);
+
+ /* Copy headers */
+ mu_message_get_header(msg, &hdr);
+ mu_header_get_streamref(hdr, &istr);
+
+ rc = mu_stream_copy(ostr, istr, 0, NULL);
+ if (rc)
+ wy_log(LOG_ERR, "mu_stream_copy: %s", mu_strerror(rc));
+ else {
+ while ((nread = gpgme_data_read(output, buf, size)) > 0) {
+ rc = mu_stream_write(ostr, buf, nread, NULL);
+ if (rc) {
+ wy_log(LOG_ERR, "mu_stream_write: %s",
+ mu_strerror(rc));
+ break;
+ }
}
- mu_stream_unref(istr);
- mu_stream_unref(ostr);
-
- if (rc)
- mu_message_destroy(&newmsg, mu_message_get_owner(msg));
- gpgme_data_release(output);
- free(buf);
-
- return rc;
+
+ if (rc == 0) {
+ mu_message_destroy(&msg, mu_message_get_owner(msg));
+ *pmsg = newmsg;
+ }
+ }
+ mu_stream_unref(istr);
+ mu_stream_unref(ostr);
+
+ if (rc)
+ mu_message_destroy(&newmsg, mu_message_get_owner(msg));
+ gpgme_data_release(output);
+ free(buf);
+
+ return rc;
}
static void
mail_send_message(mu_address_t rcpt, const char *text, const char *signer_key)
{
- int rc;
- mu_message_t msg;
- mu_stream_t stream = NULL;
- mu_header_t hdr;
- const char *sval;
-
- mu_static_memory_stream_create(&stream, text, strlen(text));
- rc = mu_stream_to_message(stream, &msg);
- mu_stream_unref(stream);
- if (rc) {
- wy_log(LOG_CRIT, _("cannot create message: %s"),
- mu_strerror(rc));
- return;
- }
- mu_message_get_header(msg, &hdr);
- mu_header_append(hdr, "X-Mailer", wy_version);
-
- if (rcpt) {
- const char *s;
-
- if (mu_address_sget_printable(rcpt, &s) == 0)
- mu_header_set_value(hdr, "To", s, 1);
-
- if (from_address && mu_header_sget_value(hdr, "From", &sval)) {
- if (mu_address_sget_printable(from_address, &s) == 0)
- mu_header_set_value(hdr, "From", s, 1);
- }
- }
-
- if (wy_debug_level > 1) {
- mu_debug_level_t level;
-
- mu_debug_get_category_level(MU_DEBCAT_MAILER, &level);
- level |= MU_DEBUG_LEVEL_MASK(MU_DEBUG_TRACE0) |
- MU_DEBUG_LEVEL_MASK(MU_DEBUG_PROT);
- if (wy_debug_level > 2)
- level |= MU_DEBUG_LEVEL_MASK(MU_DEBUG_TRACE7);
- mu_debug_set_category_level(MU_DEBCAT_MAILER, level);
- }
-
- if (!mailer_opened) {
- if ((rc = mu_mailer_open(mailer, 0))) {
- mu_url_t url = NULL;
- mu_mailer_get_url(mailer, &url);
- wy_log(LOG_CRIT, _("opening mailer `%s' failed: %s"),
- url ? mu_url_to_string(url) : "(unknown URL)",
- mu_strerror(rc));
- return;
- }
- mailer_opened = 1;
- }
-
- if (signer_key)
- sign_message(&msg, signer_key);
-
- if (!wy_dry_run) {
- rc = mu_mailer_send_message(mailer, msg, from_address, rcpt);
- if (rc)
- wy_log(LOG_CRIT, _("cannot send message: %s"),
- mu_strerror(rc));
- }
-
- mu_message_destroy(&msg, mu_message_get_owner(msg));
+ int rc;
+ mu_message_t msg;
+ mu_stream_t stream = NULL;
+ mu_header_t hdr;
+ const char *sval;
+
+ mu_static_memory_stream_create(&stream, text, strlen(text));
+ rc = mu_stream_to_message(stream, &msg);
+ mu_stream_unref(stream);
+ if (rc) {
+ wy_log(LOG_CRIT, _("cannot create message: %s"), mu_strerror(rc));
+ return;
+ }
+ mu_message_get_header(msg, &hdr);
+ mu_header_append(hdr, "X-Mailer", wy_version);
+
+ if (rcpt) {
+ const char *s;
+
+ if (mu_address_sget_printable(rcpt, &s) == 0)
+ mu_header_set_value(hdr, "To", s, 1);
+
+ if (from_address && mu_header_sget_value(hdr, "From", &sval)) {
+ if (mu_address_sget_printable(from_address, &s) == 0)
+ mu_header_set_value(hdr, "From", s, 1);
+ }
+ }
+
+ if (wy_debug_level > 1) {
+ mu_debug_level_t level;
+
+ mu_debug_get_category_level(MU_DEBCAT_MAILER, &level);
+ level |= MU_DEBUG_LEVEL_MASK(MU_DEBUG_TRACE0)
+ | MU_DEBUG_LEVEL_MASK(MU_DEBUG_PROT);
+ if (wy_debug_level > 2)
+ level |= MU_DEBUG_LEVEL_MASK(MU_DEBUG_TRACE7);
+ mu_debug_set_category_level(MU_DEBCAT_MAILER, level);
+ }
+
+ if (!mailer_opened) {
+ if ((rc = mu_mailer_open(mailer, 0))) {
+ mu_url_t url = NULL;
+ mu_mailer_get_url(mailer, &url);
+ wy_log(LOG_CRIT, _("opening mailer `%s' failed: %s"),
+ url ? mu_url_to_string(url) : "(unknown URL)",
+ mu_strerror(rc));
+ return;
+ }
+ mailer_opened = 1;
+ }
+
+ if (signer_key)
+ sign_message(&msg, signer_key);
+
+ if (!wy_dry_run) {
+ rc = mu_mailer_send_message(mailer, msg, from_address, rcpt);
+ if (rc)
+ wy_log(LOG_CRIT, _("cannot send message: %s"), mu_strerror(rc));
+ }
+
+ mu_message_destroy(&msg, mu_message_get_owner(msg));
}
static int
cb_mailer(enum grecs_callback_command cmd, grecs_node_t *node,
void *varptr, void *cb_data)
{
- int rc;
- grecs_locus_t *locus = &node->locus;
- grecs_value_t *value = node->v.value;
-
- if (wy_assert_string_arg(locus, cmd, value))
- return 1;
- rc = mu_mailer_create(&mailer, value->v.string);
- if (rc)
- grecs_error(&value->locus, 0,
- _("cannot create mailer `%s': %s"),
- value->v.string,
- mu_strerror(rc));
- return rc;
+ int rc;
+ grecs_locus_t *locus = &node->locus;
+ grecs_value_t *value = node->v.value;
+
+ if (wy_assert_string_arg(locus, cmd, value))
+ return 1;
+ rc = mu_mailer_create(&mailer, value->v.string);
+ if (rc)
+ grecs_error(&value->locus, 0,
+ _("cannot create mailer `%s': %s"),
+ value->v.string,
+ mu_strerror(rc));
+ return rc;
}
static int
cb_email_address(enum grecs_callback_command cmd, grecs_node_t *node,
void *varptr, void *cb_data)
{
- int rc = 1;
- mu_address_t addr = NULL;
- grecs_locus_t *locus = &node->locus;
- grecs_value_t *value = node->v.value;
- struct grecs_list_entry *ep;
-
- switch (value->type) {
- case GRECS_TYPE_STRING:
- rc = mu_address_create(&addr, value->v.string);
- if (rc) {
- grecs_error(&value->locus, 0,
- _("%s: invalid email address: %s"),
- value->v.string, mu_strerror(rc));
- return rc;
- }
- break;
-
- case GRECS_TYPE_LIST:
- for (ep = value->v.list->head; ep; ep = ep->next) {
- const grecs_value_t *vp = ep->data;
- mu_address_t a;
- if (wy_assert_string_arg(locus, cmd, vp))
- return 1;
-
- rc = mu_address_create(&a, vp->v.string);
- if (rc == 0)
- rc = mu_address_union(&addr, a);
- else {
- grecs_error(&value->locus, 0,
- _("%s: invalid email address: %s"),
- vp->v.string,
- mu_strerror(rc));
- }
- mu_address_destroy(&a);
- if (rc)
- break;
- }
- break;
-
- case GRECS_TYPE_ARRAY:
- grecs_error(locus, 0, _("too many arguments"));
+ int rc = 1;
+ mu_address_t addr = NULL;
+ grecs_locus_t *locus = &node->locus;
+ grecs_value_t *value = node->v.value;
+ struct grecs_list_entry *ep;
+
+ switch (value->type) {
+ case GRECS_TYPE_STRING:
+ rc = mu_address_create(&addr, value->v.string);
+ if (rc) {
+ grecs_error(&value->locus, 0,