diff options
author | José Fonseca <jrfonseca@users.sourceforge.net> | 2004-01-13 16:50:40 +0000 |
---|---|---|
committer | José Fonseca <jrfonseca@users.sourceforge.net> | 2004-01-13 16:50:40 +0000 |
commit | 566c484db7a60a0bdbfc84e9b53651b42a3e3552 (patch) | |
tree | 3562b4c30ebc8e2e46978adc26e55c305cd72146 | |
parent | 48e245a29e60eed2e2fb9dfdebf4b8c674d7c530 (diff) |
Add a 'postconnect' keyword to execute a command after closing a SMTP connection.
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | lexer.l | 1 | ||||
-rw-r--r-- | parser.y | 3 | ||||
-rw-r--r-- | smtp.c | 43 | ||||
-rw-r--r-- | smtp.h | 7 |
6 files changed, 59 insertions, 5 deletions
@@ -2,6 +2,9 @@ News ~~~~ * Version 0.5.1 (under development): + + * A 'postconnect' keyword to execute a command after closing a SMTP + connection. * Version 0.5.0 (2003-11-14): @@ -12,7 +15,7 @@ News * Detailed documentation on how to use the StartTLS extension. More verbosity on StartTLS error messages. - * New 'preconnect' keyword to execute a command prior to opening an SMTP + * New 'preconnect' keyword to execute a command prior to opening a SMTP connection (Daniel Richard G.). * Fixed a bug which prevented to send mail when libesmtp had no @@ -20,6 +23,7 @@ News * New 'default' keyword for identities (Vitezslav Batrla). + * Version 0.4.1 (2003-07-14): * Packaging fixes. @@ -71,3 +75,4 @@ News * Initial release. + @@ -10,4 +10,7 @@ To do * Include simple scripts to queue emails for dial-up connections. + * In conjunction with "preconnect", a "postconnect" configuration option + would be a good idea (example: tear down a SSH tunnel). + @@ -61,6 +61,7 @@ pass(word)? { BEGIN(NAME); return PASSWORD; } (start)?tls { return STARTTLS; } (certificate_)?passphrase { return CERTIFICATE_PASSPHRASE; } preconnect { return PRECONNECT; } +postconnect { return POSTCONNECT; } mda { return MDA; } = { return MAP; } @@ -54,7 +54,7 @@ void yyerror (const char *s); char *sval; } -%token IDENTITY DEFAULT HOSTNAME USERNAME PASSWORD STARTTLS CERTIFICATE_PASSPHRASE PRECONNECT MDA +%token IDENTITY DEFAULT HOSTNAME USERNAME PASSWORD STARTTLS CERTIFICATE_PASSPHRASE PRECONNECT POSTCONNECT MDA %token MAP @@ -101,6 +101,7 @@ statement : HOSTNAME map STRING { identity->host = xstrdup($3); SET_DEFAULT_IDEN | STARTTLS map REQUIRED { identity->starttls = Starttls_REQUIRED; SET_DEFAULT_IDENTITY; } | CERTIFICATE_PASSPHRASE map STRING { identity->certificate_passphrase = xstrdup($3); SET_DEFAULT_IDENTITY; } | PRECONNECT map STRING { identity->preconnect = xstrdup($3); SET_DEFAULT_IDENTITY; } + | PRECONNECT map STRING { identity->postconnect = xstrdup($3); SET_DEFAULT_IDENTITY; } | MDA map STRING { mda = xstrdup($3); } | DEFAULT { default_identity = identity; } ; @@ -62,6 +62,12 @@ void identity_free(identity_t *identity) if(identity->certificate_passphrase) free(identity->certificate_passphrase); + if(identity->preconnect) + free(identity->preconnect); + + if(identity->postconnect) + free(identity->postconnect); + free(identity); } @@ -563,6 +569,43 @@ void smtp_send(message_t *msg) auth_destroy_context (authctx); auth_client_exit (); + /* Execute post-connect command if one was specified. */ + if (identity->postconnect) + { + int ret, exit_status; + + if (verbose) + fprintf (stdout, "Executing post-connect command: %s\n", identity->postconnect); + + ret = system (identity->postconnect); + exit_status = WEXITSTATUS(ret); + + /* Check whether the child process caught a signal meant for us */ + if (WIFSIGNALED(ret)) + { + int sig = WTERMSIG(ret); + + if (sig == SIGINT || sig == SIGQUIT) + { + fprintf (stderr, "Post-connect command received signal %d\n", sig); + exit (EX_SOFTWARE); + } + } + + if (ret == -1) + { + fputs ("Error executing post-connect command\n", stderr); + exit (EX_OSERR); + } + + if (exit_status != 0) + { + fprintf (stderr, "Post-connect command \"%s\" exited with non-zero status %d\n", + identity->postconnect, exit_status); + exit (EX_SOFTWARE); + } + } + return; failure: @@ -27,21 +27,22 @@ typedef struct { char *host; /**< hostname and service (port) */ - /** \name Auth Extension */ + /** \name Auth extension */ /*@{*/ char *user; char *pass; /*@}*/ - /** \name StartTLS Extension */ + /** \name StartTLS extension */ /*@{*/ enum starttls_option starttls; char *certificate_passphrase; /*@}*/ - /** \name Pre-connect Command */ + /** \name Pre- and post-connect commands */ /*@{*/ char *preconnect; + char *postconnect; /*@}*/ } identity_t; |