2 * Copyright (c) 1995, the EUROPAGATE consortium (see below).
4 * The EUROPAGATE consortium members are:
6 * University College Dublin
7 * Danmarks Teknologiske Videnscenter
8 * An Chomhairle Leabharlanna
9 * Consejo Superior de Investigaciones Cientificas
11 * Permission to use, copy, modify, distribute, and sell this software and
12 * its documentation, in whole or in part, for any purpose, is hereby granted,
15 * 1. This copyright and permission notice appear in all copies of the
16 * software and its documentation. Notices of copyright or attribution
17 * which appear at the beginning of any file must remain unchanged.
19 * 2. The names of EUROPAGATE or the project partners may not be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
23 * 3. Users of this software (implementors and gateway operators) agree to
24 * inform the EUROPAGATE consortium of their use of the software. This
25 * information will be used to evaluate the EUROPAGATE project and the
26 * software, and to plan further developments. The consortium may use
27 * the information in later publications.
29 * 4. Users of this software agree to make their best efforts, when
30 * documenting their use of the software, to acknowledge the EUROPAGATE
31 * consortium, and the role played by the software in their work.
33 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
34 * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
35 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
36 * IN NO EVENT SHALL THE EUROPAGATE CONSORTIUM OR ITS MEMBERS BE LIABLE
37 * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF
38 * ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
39 * OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND
40 * ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
41 * USE OR PERFORMANCE OF THIS SOFTWARE.
44 /* Gateway Email Transport Interface
48 * Revision 1.14 1995/05/19 13:25:59 adam
49 * Bug fixes. Better command line options.
51 * Revision 1.13 1995/05/16 09:40:41 adam
52 * LICENSE. Setting of CCL token names (and/or/not/set) in read_kernel_res.
54 * Revision 1.12 1995/05/03 07:37:35 adam
55 * CCL commands stop/continue implemented. New functions gw_res_{int,bool}
56 * are used when possible.
58 * Revision 1.11 1995/05/01 16:26:56 adam
59 * More work on resource monitor.
61 * Revision 1.10 1995/05/01 12:43:29 adam
62 * First work on resource monitor program.
64 * Revision 1.9 1995/04/21 16:37:43 adam
65 * Parent (eti) creates BOTH FIFOs. dtbsun is more happy now.
67 * Revision 1.8 1995/04/20 15:12:24 adam
70 * Revision 1.7 1995/04/19 16:01:57 adam
71 * Some hacks to get the FIFO communication work!! Isn't reliable.
72 * Resource gw.account added - default account info.
74 * Revision 1.6 1995/04/17 09:34:27 adam
75 * Timeout (idletime) adjustable. Minor changes in kernel.
77 * Revision 1.5 1995/03/31 09:43:13 adam
78 * Removed unused variable.
80 * Revision 1.4 1995/03/28 11:42:34 adam
81 * First use of string-queue utility.
83 * Revision 1.3 1995/03/28 08:01:23 adam
84 * FIFO existence is used to test for a running kernel.
86 * Revision 1.2 1995/03/27 12:51:05 adam
87 * New log level in use: GW_LOG_ERRNO.
89 * Revision 1.1 1995/03/27 08:24:00 adam
90 * First use of gip interface and gw-db.
91 * First work on eti program.
105 #include <sys/file.h>
106 #include <sys/stat.h>
112 #include <strqueue.h>
114 #define LINE_MAX 1024
116 static char *module = "eti";
117 static jmp_buf retry_jmp;
119 static void pipe_handle (int dummy)
121 longjmp (retry_jmp, 1);
124 static int email_header (struct str_queue *sq,
125 char *from_str, char *subject_str)
132 while ((msg = str_queue_get (sq, index++)))
136 if (memcmp (msg, "From ", 5) == 0)
137 sscanf (msg+4, "%s", from_str);
138 if (memcmp (msg, "Subject: ", 9) == 0 &&
139 sscanf (msg+9, "%s", subject_str+1) == 1)
140 strcpy (subject_str, msg+9);
145 static void start_kernel (int argc, char **argv, int id)
150 char userid_option[20];
152 argv_p = malloc (sizeof(*argv_p)*(argc+2));
155 gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "malloc fail");
158 argv_p[0] = "kernel";
159 for (i = 1; i<argc; i++)
161 sprintf (userid_option, "-i%d", id);
162 argv_p[i++] = userid_option;
165 gw_log (GW_LOG_DEBUG, module, "Starting kernel");
169 gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "fork");
174 execv ("kernel", argv_p);
175 gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "execvp");
180 static void deliver (struct str_queue *sq, GIP gip, const char *msg)
184 gip_wline (gip, msg);
185 while ((msg = str_queue_get (sq, index++)))
186 gip_wline (gip, msg);
187 gip_wline (gip, "\001");
190 int main (int argc, char **argv)
192 char from_str[LINE_MAX+1];
193 char subject_str[LINE_MAX+1];
194 char line_str[LINE_MAX+1];
203 char fifo_client_name[1024];
204 char fifo_server_name[1024];
205 struct str_queue *queue;
206 int monitor_flag = 1;
210 while (++argno < argc)
212 if (argv[argno][0] == '-')
214 if (argv[argno][1] == '-')
219 switch (argv[argno][1])
223 fprintf (stderr, "eti [options] -- [kernelOptions]\n");
224 fprintf (stderr, "Options:\n");
225 fprintf (stderr, " -l log Set Log file\n");
226 fprintf (stderr, " -d Enable debugging log\n");
227 fprintf (stderr, " -D Enable more debugging log\n");
228 fprintf (stderr, " -- Precedes kernel options "
229 "(kernel is invoked instead of monitor)\n");
233 gw_log_file (GW_LOG_ALL, argv[argno]+2);
234 else if (++argno < argc)
235 gw_log_file (GW_LOG_ALL, argv[argno]);
238 fprintf (stderr, "%s: missing log filename\n", *argv);
243 gw_log_level (GW_LOG_ALL & ~RES_DEBUG);
246 gw_log_level (GW_LOG_ALL);
249 fprintf (stderr, "%s: unknown option `%s'; use -H for help\n",
255 if (!(queue = str_queue_mk ()))
257 gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "str_queue_mk");
260 while (fgets (line_str, LINE_MAX, stdin))
261 str_queue_enq (queue, line_str);
263 r = email_header (queue, from_str, subject_str);
266 gw_log (GW_LOG_WARN, module, "No \"From\" in mail");
269 gw_log (GW_LOG_STAT, module, "Mail from %s", from_str);
270 user_db = gw_db_open ("user.db", 1);
272 r = gw_db_lookup (user_db, from_str, strlen(from_str),
273 &user_info, &info_length);
276 gw_log (GW_LOG_STAT, module, "New user");
277 id = gw_db_seq_no (user_db);
278 r = gw_db_insert (user_db, from_str, strlen(from_str),
280 gw_log (GW_LOG_STAT, module, "Added user with id %d", id);
284 if (sizeof(id) != info_length)
286 gw_log (GW_LOG_FATAL, module, "Bad id-size");
289 memcpy (&id, user_info, sizeof(id));
290 gw_log (GW_LOG_STAT, module, "Found with id %d", id);
294 gw_log (GW_LOG_FATAL, module, "gw_db_lookup fail");
299 sprintf (fifo_server_name, "fifo.s.m");
300 sprintf (fifo_client_name, "fifo.c.m");
304 sprintf (fifo_server_name, "fifo.s.%d", id);
305 sprintf (fifo_client_name, "fifo.c.%d", id);
308 gip = gipc_initialize (fifo_client_name);
310 signal (SIGPIPE, pipe_handle);
313 signal (SIGPIPE, pipe_handle);
314 gw_log (GW_LOG_DEBUG, module, "Pass %d", pass);
318 r = gipc_open (gip, fifo_server_name, 0);
324 gw_log (GW_LOG_FATAL, module, "Cannot contact monitor");
327 mknod (fifo_server_name, S_IFIFO|0666, 0);
328 start_kernel (argc-argno, argv+argno, id);
329 r = gipc_open (gip, fifo_server_name, 1);
333 gw_log (GW_LOG_FATAL, module, "Cannot start kernel");
339 gw_log (GW_LOG_DEBUG|GW_LOG_ERRNO, module, "r==-2");
340 longjmp (retry_jmp, 1);
344 gw_log (GW_LOG_DEBUG|GW_LOG_ERRNO, module, "r==-1");
345 longjmp (retry_jmp, 1);
349 gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "gipc_open");
352 /* deliver message ... */
353 gw_log (GW_LOG_DEBUG, module, "Delivering mail");
355 sprintf (msg, "eti %d\n", id);
357 strcpy (msg, "mail\n");
358 deliver (queue, gip, msg);
359 gw_log (GW_LOG_DEBUG, module, "Closing");
362 gw_db_close (user_db);
363 gw_log (GW_LOG_DEBUG, module, "Exiting");