X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=kernel%2Feti.c;h=de0634b6d013320257306a084e8b7bb8c6a85175;hb=7b58e36bc4c5a57dec46408bbfb3707638dd967a;hp=f7a1b997e111ada66181614010e3936175e83998;hpb=90577270f3555c93afd2df18c5f42dca967d57d5;p=egate.git diff --git a/kernel/eti.c b/kernel/eti.c index f7a1b99..de0634b 100644 --- a/kernel/eti.c +++ b/kernel/eti.c @@ -1,8 +1,74 @@ +/* + * Copyright (c) 1995, the EUROPAGATE consortium (see below). + * + * The EUROPAGATE consortium members are: + * + * University College Dublin + * Danmarks Teknologiske Videnscenter + * An Chomhairle Leabharlanna + * Consejo Superior de Investigaciones Cientificas + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation, in whole or in part, for any purpose, is hereby granted, + * provided that: + * + * 1. This copyright and permission notice appear in all copies of the + * software and its documentation. Notices of copyright or attribution + * which appear at the beginning of any file must remain unchanged. + * + * 2. The names of EUROPAGATE or the project partners may not be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * 3. Users of this software (implementors and gateway operators) agree to + * inform the EUROPAGATE consortium of their use of the software. This + * information will be used to evaluate the EUROPAGATE project and the + * software, and to plan further developments. The consortium may use + * the information in later publications. + * + * 4. Users of this software agree to make their best efforts, when + * documenting their use of the software, to acknowledge the EUROPAGATE + * consortium, and the role played by the software in their work. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * IN NO EVENT SHALL THE EUROPAGATE CONSORTIUM OR ITS MEMBERS BE LIABLE + * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF + * ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA + * OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND + * ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ /* Gateway Email Transport Interface * Europagate, 1995 * * $Log: eti.c,v $ - * Revision 1.11 1995/05/01 16:26:56 adam + * Revision 1.18 1996/03/01 14:25:28 adam + * Email gateway obeys 'Reply-To:' in header. + * + * Revision 1.17 1995/12/20 16:27:24 adam + * Extra parameter block to gw_db_open. + * + * Revision 1.16 1995/07/11 11:49:11 adam + * LINE_MAX renamed to STR_LINE_MAX. + * + * Revision 1.15 1995/07/03 12:59:28 adam + * New option for eti: -c dir to chdir before start. + * Setting change: gw.max.show defaults to 100. + * + * Revision 1.14 1995/05/19 13:25:59 adam + * Bug fixes. Better command line options. + * + * Revision 1.13 1995/05/16 09:40:41 adam + * LICENSE. Setting of CCL token names (and/or/not/set) in read_kernel_res. + * + * Revision 1.12 1995/05/03 07:37:35 adam + * CCL commands stop/continue implemented. New functions gw_res_{int,bool} + * are used when possible. + * + * Revision 1.11 1995/05/01 16:26:56 adam * More work on resource monitor. * * Revision 1.10 1995/05/01 12:43:29 adam @@ -54,10 +120,11 @@ #include #include +#include #include #include -#define LINE_MAX 1024 +#define STR_LINE_MAX 1024 static char *module = "eti"; static jmp_buf retry_jmp; @@ -81,6 +148,8 @@ static int email_header (struct str_queue *sq, return 0; if (memcmp (msg, "From ", 5) == 0) sscanf (msg+4, "%s", from_str); + if (memcmp (msg, "Reply-To: ", 10) == 0) + sscanf (msg+10, "%s", from_str); if (memcmp (msg, "Subject: ", 9) == 0 && sscanf (msg+9, "%s", subject_str+1) == 1) strcpy (subject_str, msg+9); @@ -88,7 +157,6 @@ static int email_header (struct str_queue *sq, return 1; } -#if !USE_MONITOR static void start_kernel (int argc, char **argv, int id) { pid_t pid; @@ -123,7 +191,6 @@ static void start_kernel (int argc, char **argv, int id) exit (1); } } -#endif static void deliver (struct str_queue *sq, GIP gip, const char *msg) { @@ -137,9 +204,9 @@ static void deliver (struct str_queue *sq, GIP gip, const char *msg) int main (int argc, char **argv) { - char from_str[LINE_MAX+1]; - char subject_str[LINE_MAX+1]; - char line_str[LINE_MAX+1]; + char from_str[STR_LINE_MAX+1]; + char subject_str[STR_LINE_MAX+1]; + char line_str[STR_LINE_MAX+1]; char msg[20]; GW_DB user_db; GIP gip; @@ -151,17 +218,79 @@ int main (int argc, char **argv) char fifo_client_name[1024]; char fifo_server_name[1024]; struct str_queue *queue; + int monitor_flag = 1; + int argno = 0; gw_log_init (*argv); - gw_log_level (GW_LOG_ALL); - gw_log_file (GW_LOG_ALL, "eti.log"); - + while (++argno < argc) + { + if (argv[argno][0] == '-') + { + if (argv[argno][1] == '-') + { + monitor_flag = 0; + break; + } + switch (argv[argno][1]) + { + case 'h': + case 'H': + fprintf (stderr, "eti [options] -- [kernelOptions]\n"); + fprintf (stderr, "Options:\n"); + fprintf (stderr, " -l log Set Log file\n"); + fprintf (stderr, " -d Enable debugging log\n"); + fprintf (stderr, " -D Enable more debugging log\n"); + fprintf (stderr, " -c dir Change to directory\n"); + fprintf (stderr, " -- Precedes kernel options " + "(kernel is invoked instead of monitor)\n"); + exit (1); + case 'l': + if (argv[argno][2]) + gw_log_file (GW_LOG_ALL, argv[argno]+2); + else if (++argno < argc) + gw_log_file (GW_LOG_ALL, argv[argno]); + else + { + fprintf (stderr, "%s: missing log filename\n", *argv); + exit (1); + } + break; + case 'd': + gw_log_level (GW_LOG_ALL & ~RES_DEBUG); + break; + case 'D': + gw_log_level (GW_LOG_ALL); + break; + case 'c': + if (argv[argno][2]) + { + if (chdir (argv[argno]+2)) + gw_log (GW_LOG_WARN|GW_LOG_ERRNO, module, "chdir"); + } + else if (++argno < argc) + { + if (chdir (argv[argno])) + gw_log (GW_LOG_WARN|GW_LOG_ERRNO, module, "chdir"); + } + else + { + fprintf (stderr, "%s: missing chdir name\n", *argv); + exit (1); + } + break; + default: + fprintf (stderr, "%s: unknown option `%s'; use -H for help\n", + *argv, argv[argno]); + exit (1); + } + } + } if (!(queue = str_queue_mk ())) { gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "str_queue_mk"); exit (1); } - while (fgets (line_str, LINE_MAX, stdin)) + while (fgets (line_str, STR_LINE_MAX, stdin)) str_queue_enq (queue, line_str); r = email_header (queue, from_str, subject_str); @@ -171,7 +300,7 @@ int main (int argc, char **argv) exit (1); } gw_log (GW_LOG_STAT, module, "Mail from %s", from_str); - user_db = gw_db_open ("user.db", 1); + user_db = gw_db_open ("user.db", 1, 1); r = gw_db_lookup (user_db, from_str, strlen(from_str), &user_info, &info_length); @@ -198,13 +327,16 @@ int main (int argc, char **argv) gw_log (GW_LOG_FATAL, module, "gw_db_lookup fail"); exit (1); } -#if USE_MONITOR - sprintf (fifo_server_name, "fifo.s"); - sprintf (fifo_client_name, "fifo.c"); -#else - sprintf (fifo_server_name, "fifo.s.%d", id); - sprintf (fifo_client_name, "fifo.c.%d", id); -#endif + if (monitor_flag) + { + sprintf (fifo_server_name, "fifo.s.m"); + sprintf (fifo_client_name, "fifo.c.m"); + } + else + { + sprintf (fifo_server_name, "fifo.s.%d", id); + sprintf (fifo_client_name, "fifo.c.%d", id); + } gip = gipc_initialize (fifo_client_name); @@ -214,30 +346,25 @@ int main (int argc, char **argv) signal (SIGPIPE, pipe_handle); gw_log (GW_LOG_DEBUG, module, "Pass %d", pass); if (pass == 1) + { + gipc_close (gip); r = gipc_open (gip, fifo_server_name, 0); + } else if (pass == 2) { -#if USE_MONITOR - gw_log (GW_LOG_FATAL, module, "Cannot contact monitor"); - exit (1); -#else -#if 0 - gipc_close (gip); - gipc_destroy (gip); - unlink (fifo_server_name); - unlink (fifo_client_name); - gip = gipc_initialize (fifo_client_name); -#endif - + if (monitor_flag) + { + gw_log (GW_LOG_FATAL, module, "Cannot contact monitor"); + exit (1); + } mknod (fifo_server_name, S_IFIFO|0666, 0); - start_kernel (argc, argv, id); + start_kernel (argc-argno, argv+argno, id); r = gipc_open (gip, fifo_server_name, 1); } else if (pass == 3) { gw_log (GW_LOG_FATAL, module, "Cannot start kernel"); exit (1); -#endif } if (r < 0) if (r == -2) @@ -257,11 +384,10 @@ int main (int argc, char **argv) } /* deliver message ... */ gw_log (GW_LOG_DEBUG, module, "Delivering mail"); -#if USE_MONITOR - sprintf (msg, "eti %d\n", id); -#else - strcpy (msg, "mail\n"); -#endif + if (monitor_flag) + sprintf (msg, "eti %d\n", id); + else + strcpy (msg, "mail\n"); deliver (queue, gip, msg); gw_log (GW_LOG_DEBUG, module, "Closing"); gipc_close (gip);