1 |
/* GNU mailutils - a suite of utilities for electronic mail |
/* GNU Mailutils -- a suite of utilities for electronic mail |
2 |
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. |
Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
GNU Mailutils is free software; you can redistribute it and/or modify |
5 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
6 |
the Free Software Foundation; either version 2, or (at your option) |
the Free Software Foundation; either version 2, or (at your option) |
7 |
any later version. |
any later version. |
8 |
|
|
9 |
This program is distributed in the hope that it will be useful, |
GNU Mailutils is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU General Public License for more details. |
GNU General Public License for more details. |
13 |
|
|
14 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
15 |
along with this program; if not, write to the Free Software |
along with GNU Mailutils; if not, write to the Free Software |
16 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
17 |
|
|
18 |
#include "comsat.h" |
#include "comsat.h" |
55 |
|
|
56 |
static struct argp_option options[] = |
static struct argp_option options[] = |
57 |
{ |
{ |
58 |
{"config", 'c', "FILE", 0, "Read configuration from FILE", 0}, |
{"config", 'c', "FILE", 0, N_("Read configuration from FILE"), 0}, |
59 |
{ NULL, 0, NULL, 0, NULL, 0 } |
{ NULL, 0, NULL, 0, NULL, 0 } |
60 |
}; |
}; |
61 |
|
|
136 |
{ |
{ |
137 |
int c; |
int c; |
138 |
|
|
139 |
|
/* Native Language Support */ |
140 |
|
mu_init_nls (); |
141 |
|
|
142 |
mu_argp_parse (&argp, &argc, &argv, 0, comsat_argp_capa, |
mu_argp_parse (&argp, &argc, &argv, 0, comsat_argp_capa, |
143 |
NULL, &daemon_param); |
NULL, &daemon_param); |
144 |
|
|
145 |
if (daemon_param.timeout > 0 && daemon_param.mode == MODE_DAEMON) |
if (daemon_param.timeout > 0 && daemon_param.mode == MODE_DAEMON) |
146 |
{ |
{ |
147 |
fprintf (stderr, "--timeout and --daemon are incompatible\n"); |
fprintf (stderr, _("--timeout and --daemon are incompatible\n")); |
148 |
exit (EXIT_FAILURE); |
exit (EXIT_FAILURE); |
149 |
} |
} |
150 |
|
|
178 |
static RETSIGTYPE |
static RETSIGTYPE |
179 |
sig_hup (int sig) |
sig_hup (int sig) |
180 |
{ |
{ |
181 |
syslog (LOG_NOTICE, "restarting"); |
syslog (LOG_NOTICE, _("restarting")); |
182 |
|
|
183 |
if (xargv[0][0] != '/') |
if (xargv[0][0] != '/') |
184 |
syslog (LOG_ERR, "can't restart: not started with absolute pathname"); |
syslog (LOG_ERR, _("can't restart: not started with absolute pathname")); |
185 |
else |
else |
186 |
execvp (xargv[0], xargv); |
execvp (xargv[0], xargv); |
187 |
|
|
215 |
first three one, in, out, err. Do not do the chdir("/"). */ |
first three one, in, out, err. Do not do the chdir("/"). */ |
216 |
if (daemon (1, 0) < 0) |
if (daemon (1, 0) < 0) |
217 |
{ |
{ |
218 |
perror ("failed to become a daemon:"); |
perror (_("failed to become a daemon:")); |
219 |
exit (EXIT_FAILURE); |
exit (EXIT_FAILURE); |
220 |
} |
} |
221 |
} |
} |
259 |
exit (1); |
exit (1); |
260 |
} |
} |
261 |
|
|
262 |
syslog (LOG_NOTICE, "GNU comsat started"); |
syslog (LOG_NOTICE, _("GNU comsat started")); |
263 |
|
|
264 |
last_request_time = last_overflow_time = time (NULL); |
last_request_time = last_overflow_time = time (NULL); |
265 |
while (1) |
while (1) |
286 |
unsigned delay; |
unsigned delay; |
287 |
|
|
288 |
delay = overflow_delay_time << (overflow_count + 1); |
delay = overflow_delay_time << (overflow_count + 1); |
289 |
syslog (LOG_NOTICE, "too many requests: pausing for %u seconds", |
syslog (LOG_NOTICE, _("too many requests: pausing for %u seconds"), |
290 |
delay); |
delay); |
291 |
sleep (delay); |
sleep (delay); |
292 |
reqcount = 0; |
reqcount = 0; |
339 |
|
|
340 |
if (acl_match (&sin_from)) |
if (acl_match (&sin_from)) |
341 |
{ |
{ |
342 |
syslog (LOG_ALERT, "DENIED attempt to connect from %s", |
syslog (LOG_ALERT, _("DENIED attempt to connect from %s"), |
343 |
inet_ntoa (sin_from.sin_addr)); |
inet_ntoa (sin_from.sin_addr)); |
344 |
return 1; |
return 1; |
345 |
} |
} |
346 |
|
|
347 |
syslog (LOG_INFO, "%d bytes from %s", rdlen, inet_ntoa (sin_from.sin_addr)); |
syslog (LOG_INFO, _("%d bytes from %s"), rdlen, inet_ntoa (sin_from.sin_addr)); |
348 |
|
|
349 |
buffer[rdlen] = 0; |
buffer[rdlen] = 0; |
350 |
|
|
352 |
p = strchr (buffer, '@'); |
p = strchr (buffer, '@'); |
353 |
if (!p) |
if (!p) |
354 |
{ |
{ |
355 |
syslog (LOG_ERR, "malformed input: %s", buffer); |
syslog (LOG_ERR, _("malformed input: %s"), buffer); |
356 |
return 1; |
return 1; |
357 |
} |
} |
358 |
*p++ = 0; |
*p++ = 0; |
367 |
break; |
break; |
368 |
default: |
default: |
369 |
if (!isspace (*endp)) |
if (!isspace (*endp)) |
370 |
syslog (LOG_ERR, "malformed input: %s@%s (near %s)", buffer, p, endp); |
syslog (LOG_ERR, _("malformed input: %s@%s (near %s)"), buffer, p, endp); |
371 |
} |
} |
372 |
|
|
373 |
if (find_user (buffer, tty) != SUCCESS) |
if (find_user (buffer, tty) != SUCCESS) |
432 |
change_user (user); |
change_user (user); |
433 |
if ((fp = fopen (device, "w")) == NULL) |
if ((fp = fopen (device, "w")) == NULL) |
434 |
{ |
{ |
435 |
syslog (LOG_ERR, "can't open device %s: %m", device); |
syslog (LOG_ERR, _("can't open device %s: %m"), device); |
436 |
exit (0); |
exit (0); |
437 |
} |
} |
438 |
|
|
448 |
if ((status = mailbox_create (&mbox, path)) != 0 |
if ((status = mailbox_create (&mbox, path)) != 0 |
449 |
|| (status = mailbox_open (mbox, MU_STREAM_READ)) != 0) |
|| (status = mailbox_open (mbox, MU_STREAM_READ)) != 0) |
450 |
{ |
{ |
451 |
syslog (LOG_ERR, "can't open mailbox %s: %s", |
syslog (LOG_ERR, _("can't open mailbox %s: %s"), |
452 |
path, mu_errstring (status)); |
path, mu_errstring (status)); |
453 |
return; |
return; |
454 |
} |
} |
455 |
|
|
456 |
if ((status = mailbox_get_stream (mbox, &stream))) |
if ((status = mailbox_get_stream (mbox, &stream))) |
457 |
{ |
{ |
458 |
syslog (LOG_ERR, "can't get stream for mailbox %s: %s", |
syslog (LOG_ERR, _("can't get stream for mailbox %s: %s"), |
459 |
path, mu_errstring (status)); |
path, mu_errstring (status)); |
460 |
return; |
return; |
461 |
} |
} |
462 |
|
|
463 |
if ((status = stream_size (stream, (off_t *) &size))) |
if ((status = stream_size (stream, (off_t *) &size))) |
464 |
{ |
{ |
465 |
syslog (LOG_ERR, "can't get stream size (mailbox %s): %s", |
syslog (LOG_ERR, _("can't get stream size (mailbox %s): %s"), |
466 |
path, mu_errstring (status)); |
path, mu_errstring (status)); |
467 |
return; |
return; |
468 |
} |
} |
479 |
if ((status = mailbox_create (&tmp, "/dev/null")) != 0 |
if ((status = mailbox_create (&tmp, "/dev/null")) != 0 |
480 |
|| (status = mailbox_open (tmp, MU_STREAM_READ)) != 0) |
|| (status = mailbox_open (tmp, MU_STREAM_READ)) != 0) |
481 |
{ |
{ |
482 |
syslog (LOG_ERR, "can't create temporary mailbox: %s", |
syslog (LOG_ERR, _("can't create temporary mailbox: %s"), |
483 |
mu_errstring (status)); |
mu_errstring (status)); |
484 |
return; |
return; |
485 |
} |
} |
486 |
|
|
487 |
if ((status = memory_stream_create (&stream, 0, 0))) |
if ((status = memory_stream_create (&stream, 0, 0))) |
488 |
{ |
{ |
489 |
syslog (LOG_ERR, "can't create temporary stream: %s", |
syslog (LOG_ERR, _("can't create temporary stream: %s"), |
490 |
mu_errstring (status)); |
mu_errstring (status)); |
491 |
return; |
return; |
492 |
} |
} |
533 |
if (strncmp (ftty, PATH_TTY_PFX, strlen (PATH_TTY_PFX))) |
if (strncmp (ftty, PATH_TTY_PFX, strlen (PATH_TTY_PFX))) |
534 |
{ |
{ |
535 |
/* An attempt to break security... */ |
/* An attempt to break security... */ |
536 |
syslog (LOG_ALERT, "bad line name in utmp record: %s", ftty); |
syslog (LOG_ALERT, _("bad line name in utmp record: %s"), ftty); |
537 |
return NOT_HERE; |
return NOT_HERE; |
538 |
} |
} |
539 |
|
|
541 |
{ |
{ |
542 |
if (!S_ISCHR (statb.st_mode)) |
if (!S_ISCHR (statb.st_mode)) |
543 |
{ |
{ |
544 |
syslog (LOG_ALERT, "not a character device: %s", ftty); |
syslog (LOG_ALERT, _("not a character device: %s"), ftty); |
545 |
return NOT_HERE; |
return NOT_HERE; |
546 |
} |
} |
547 |
|
|
574 |
pw = getpwnam (user); |
pw = getpwnam (user); |
575 |
if (!pw) |
if (!pw) |
576 |
{ |
{ |
577 |
syslog (LOG_CRIT, "no such user: %s", user); |
syslog (LOG_CRIT, _("no such user: %s"), user); |
578 |
exit (1); |
exit (1); |
579 |
} |
} |
580 |
|
|
594 |
|
|
595 |
if (!auth) |
if (!auth) |
596 |
{ |
{ |
597 |
syslog (LOG_ALERT, "user nonexistent: %s", user); |
syslog (LOG_ALERT, _("user nonexistent: %s"), user); |
598 |
return NULL; |
return NULL; |
599 |
} |
} |
600 |
|
|
609 |
void |
void |
610 |
stop() |
stop() |
611 |
{ |
{ |
612 |
syslog (LOG_ALERT, "waiting for debug"); |
syslog (LOG_ALERT, _("waiting for debug")); |
613 |
while (!_st) |
while (!_st) |
614 |
_st=_st; |
_st=_st; |
615 |
} |
} |