1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
/*
GNU Anubis -- an SMTP message submission daemon.
Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008 The Anubis Team.
GNU Anubis is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.
GNU Anubis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with GNU Anubis. If not, see <http://www.gnu.org/licenses/>.
*/
#include "headers.h"
#include "extern.h"
ANUBIS_MODE anubis_mode = anubis_transparent;
const char version[] = "GNU Anubis v" VERSION;
struct options_struct options;
struct session_struct session;
#if defined(HAVE_TLS) || defined(HAVE_SSL)
struct secure_struct secure;
#endif /* HAVE_TLS or HAVE_SSL */
unsigned long topt;
NET_STREAM remote_client;
NET_STREAM remote_server;
char *anubis_domain; /* Local domain for EHLO in authentication mode */
char *incoming_mail_rule; /* Name of section for incoming mail processing */
char *outgoing_mail_rule; /* Name of section for outgoing mail processing */
#ifdef WITH_GUILE
void
anubis_core (void)
{
char *argv[] = { "anubis", NULL };
scm_boot_guile (1, argv, anubis_boot, NULL);
}
#else
# define anubis_core() anubis(NULL)
#endif /* WITH_GUILE */
void
xalloc_die ()
{
anubis_error (EXIT_FAILURE, 0, "%s", _("Not enough memory"));
abort ();
}
int
main (int argc, char *argv[])
{
/*
Signal handling.
*/
signal (SIGILL, sig_exit);
signal (SIGINT, sig_exit);
signal (SIGTERM, sig_exit);
signal (SIGHUP, sig_exit);
signal (SIGQUIT, sig_exit);
signal (SIGPIPE, SIG_IGN);
signal (SIGALRM, sig_timeout);
/* Native Language Support */
#ifdef ENABLE_NLS
/* Set locale via LC_ALL. */
#ifdef HAVE_SETLOCALE
setlocale (LC_ALL, "");
#endif /* HAVE_SETLOCALE */
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif /* ENABLE_NLS */
/* default values */
options.termlevel = NORMAL;
options.uloglevel = FAILS;
session.anubis_port = 24; /* private mail system */
session.mta_port = 25;
#ifdef USE_SOCKS_PROXY
session.socks_port = 1080;
#endif
/*
Process the command line options.
*/
SETVBUF (stderr, NULL, _IOLBF, 0);
get_options (argc, argv);
anubis_getlogin (&session.supervisor);
assign_string (&incoming_mail_rule, "INCOMING");
assign_string (&outgoing_mail_rule, "RULE");
/*
Initialize various database formats
*/
#ifdef WITH_GSASL
dbtext_init ();
# ifdef HAVE_LIBGDBM
gdbm_db_init ();
# endif
# ifdef WITH_MYSQL
mysql_db_init ();
# endif
# ifdef WITH_PGSQL
pgsql_db_init ();
# endif
#endif /* WITH_GSASL */
/*
Initialize the rc parsing subsystem.
Read the system configuration file (SUPERVISOR).
*/
rc_system_init ();
if (topt & T_CHECK_CONFIG)
{
open_rcfile (CF_SUPERVISOR);
exit (0);
}
if (!(topt & T_NORC))
{
open_rcfile (CF_SUPERVISOR);
process_rcfile (CF_INIT);
}
/* DEBUG */
#if defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
if (options.termlevel != DEBUG)
{
struct rlimit corelimit;
if (getrlimit (RLIMIT_CORE, &corelimit) == 0)
{
corelimit.rlim_cur = 0;
setrlimit (RLIMIT_CORE, &corelimit);
}
}
#endif /* HAVE_GETRLIMIT and HAVE_SETRLIMIT */
info (VERBOSE, _("UID:%d (%s), GID:%d, EUID:%d, EGID:%d"),
(int) getuid (), session.supervisor, (int) getgid (),
(int) geteuid (), (int) getegid ());
/*
Initialize GnuTLS and the PRNG.
*/
#ifdef USE_SSL
init_ssl_libs ();
#endif /* USE_SSL */
/*
Enter the main core...
*/
anubis_core ();
return 0;
}
void
anubis (char *arg)
{
if (anubis_mode == anubis_mda) /* Mail Delivery Agent */
mda ();
else if (topt & T_STDINOUT) /* stdin/stdout */
stdinout ();
else
{ /* daemon */
int sd_bind;
sd_bind = bind_and_listen (session.anubis, session.anubis_port);
if (topt & T_FOREGROUND_INIT)
topt |= T_FOREGROUND;
else
daemonize ();
loop (sd_bind);
}
}
/* EOF */
|