ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/ircd.c
(Generate patch)

Comparing:
ircd-hybrid-7.2/src/ircd.c (file contents), Revision 876 by michael, Wed Oct 24 21:51:21 2007 UTC vs.
ircd-hybrid/trunk/src/ircd.c (file contents), Revision 5486 by michael, Sun Feb 8 13:52:45 2015 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  ircd.c: Starts up and runs the ircd.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2015 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file ircd.c
23 > * \brief Starts up and runs the ircd.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28 < #include "s_user.h"
29 < #include "tools.h"
28 > #include "user.h"
29 > #include "list.h"
30   #include "ircd.h"
31   #include "channel.h"
30 #include "channel_mode.h"
32   #include "client.h"
32 #include "common.h"
33   #include "event.h"
34   #include "fdlist.h"
35   #include "hash.h"
36   #include "irc_string.h"
37 #include "sprintf_irc.h"
37   #include "ircd_signal.h"
38 < #include "list.h"
40 < #include "s_gline.h"
38 > #include "gline.h"
39   #include "motd.h"
40 < #include "ircd_handler.h"
43 < #include "msg.h"         /* msgtab */
40 > #include "conf.h"
41   #include "hostmask.h"
45 #include "numeric.h"
46 #include "packet.h"
42   #include "parse.h"
43 < #include "irc_res.h"
43 > #include "res.h"
44   #include "restart.h"
45 < #include "s_auth.h"
45 > #include "rng_mt.h"
46 > #include "auth.h"
47   #include "s_bsd.h"
48 < #include "s_conf.h"
49 < #include "s_log.h"
54 < #include "s_misc.h"
55 < #include "s_serv.h"      /* try_connections */
56 < #include "s_stats.h"
48 > #include "log.h"
49 > #include "server.h"      /* try_connections */
50   #include "send.h"
51   #include "whowas.h"
52   #include "modules.h"
53   #include "memory.h"
54 < #include "hook.h"
54 > #include "mempool.h"
55   #include "ircd_getopt.h"
63 #include "balloc.h"
64 #include "motd.h"
65 #include "supported.h"
56   #include "watch.h"
57 + #include "conf_db.h"
58 + #include "conf_class.h"
59 + #include "ipcache.h"
60  
68 /* Try and find the correct name to use with getrlimit() for setting the max.
69 * number of files allowed to be open by this process.
70 */
61  
62 < /* /quote set variables */
63 < struct SetOptions GlobalSetOptions;
62 > #ifdef HAVE_LIBGEOIP
63 > GeoIP *geoip_ctx;
64 > #endif
65  
75 /* configuration set from ircd.conf */
76 struct config_file_entry ConfigFileEntry;
77 /* server info set from ircd.conf */
78 struct server_info ServerInfo;
79 /* admin info set from ircd.conf */
80 struct admin_info AdminInfo = { NULL, NULL, NULL };
81 struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0 };
82 struct ServerState_t server_state = { 0 };
83 struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} };
66   struct timeval SystemTime;
67 < struct Client me;             /* That's me */
68 < struct LocalUser meLocalUser; /* That's also part of me */
87 < unsigned long connect_id = 0; /* unique connect ID */
67 > struct Connection meConnection; /* That's also part of me */
68 > struct Client me = { .connection = &meConnection };  /* That's me */
69  
70 < static unsigned long initialVMTop = 0;   /* top of virtual memory at init */
70 > char **myargv;
71   const char *logFileName = LPATH;
72   const char *pidFileName = PPATH;
73  
74 < char **myargv;
75 < char ircd_platform[PLATFORMLEN];
76 <
77 < int dorehash = 0;
78 < int doremotd = 0;
79 < time_t nextconnect = 1;       /* time for next try_connections call */
74 > unsigned int dorehash;
75 > unsigned int doremotd;
76 > unsigned int default_server_capabs;
77 > unsigned int splitmode;
78 > unsigned int splitchecking;
79 > unsigned int split_users;
80 > unsigned int split_servers;
81  
82 < /* Set to zero because it should be initialized later using
83 < * initialize_server_capabs
84 < */
85 < int default_server_capabs = 0;
82 > static struct event event_cleanup_glines =
83 > {
84 >  .name = "cleanup_glines",
85 >  .handler = cleanup_glines,
86 >  .when = CLEANUP_GLINES_TIME
87 > };
88  
89 < #ifdef HAVE_LIBCRYPTO
90 < int bio_spare_fd = -1;
91 < #endif
89 > static struct event event_cleanup_tklines =
90 > {
91 >  .name = "cleanup_tklines",
92 >  .handler = cleanup_tklines,
93 >  .when = CLEANUP_TKLINES_TIME
94 > };
95  
96 < int splitmode;
97 < int splitchecking;
98 < int split_users;
99 < unsigned int split_servers;
96 > static struct event event_try_connections =
97 > {
98 >  .name = "try_connections",
99 >  .handler = try_connections,
100 >  .when = STARTUP_CONNECTIONS_TIME
101 > };
102  
103 < /* Do klines the same way hybrid-6 did them, i.e. at the
104 < * top of the next io_loop instead of in the same loop as
105 < * the klines are being applied.
106 < *
107 < * This should fix strange CPU starvation as very indirectly reported.
108 < * (Why do you people not email bug reports? WHY? WHY?)
120 < *
121 < * - Dianora
122 < */
103 > static struct event event_comm_checktimeouts =
104 > {
105 >  .name = "comm_checktimeouts",
106 >  .handler = comm_checktimeouts,
107 >  .when = 1
108 > };
109  
110 < int rehashed_klines = 0;
110 > static struct event event_save_all_databases =
111 > {
112 >  .name = "save_all_databases",
113 >  .handler = save_all_databases,
114 >  .when = DATABASE_UPDATE_TIMEOUT
115 > };
116  
117 < /*
118 < * get_vm_top - get the operating systems notion of the resident set size
119 < */
120 < #ifndef _WIN32
121 < static unsigned long
131 < get_vm_top(void)
132 < {
133 <  /*
134 <   * NOTE: sbrk is not part of the ANSI C library or the POSIX.1 standard
135 <   * however it seems that everyone defines it. Calling sbrk with a 0
136 <   * argument will return a pointer to the top of the process virtual
137 <   * memory without changing the process size, so this call should be
138 <   * reasonably safe (sbrk returns the new value for the top of memory).
139 <   * This code relies on the notion that the address returned will be an
140 <   * offset from 0 (NULL), so the result of sbrk is cast to a size_t and
141 <   * returned. We really shouldn't be using it here but...
142 <   */
117 > struct event event_write_links_file =
118 > {
119 >  .name = "write_links_file",
120 >  .handler = write_links_file,
121 > };
122  
144  void *vptr = sbrk(0);
145  return((unsigned long)vptr);
146 }
123  
124   /*
125   * print_startup - print startup information
# Line 151 | Line 127 | get_vm_top(void)
127   static void
128   print_startup(int pid)
129   {
130 <  printf("ircd: version %s\n", ircd_version);
130 >  printf("ircd: version %s(%s)\n", ircd_version, serno);
131    printf("ircd: pid %d\n", pid);
132    printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
133 <         : "foreground", ConfigFileEntry.dpath);
133 >         : "foreground", ConfigGeneral.dpath);
134   }
135  
136   static void
# Line 175 | Line 151 | make_daemon(void)
151  
152    setsid();
153   }
178 #endif
179
180 /*
181 * get_maxrss - get the operating systems notion of the resident set size
182 */
183 unsigned long
184 get_maxrss(void)
185 {
186 #ifdef _WIN32
187  return (0);   /* FIXME */
188 #else
189  return (get_vm_top() - initialVMTop);
190 #endif
191 }
154  
155   static int printVersion = 0;
156  
157 < struct lgetopt myopts[] = {
158 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
159 <   STRING, "File to use for dline.conf"},
198 <  {"configfile", &ConfigFileEntry.configfile,
157 > static struct lgetopt myopts[] =
158 > {
159 >  {"configfile", &ConfigGeneral.configfile,
160     STRING, "File to use for ircd.conf"},
161 <  {"klinefile",  &ConfigFileEntry.klinefile,
162 <   STRING, "File to use for kline.conf"},
163 <  {"xlinefile",  &ConfigFileEntry.xlinefile,
164 <   STRING, "File to use for xline.conf"},
165 <  {"logfile",    &logFileName,
161 >  {"glinefile",  &ConfigGeneral.glinefile,
162 >   STRING, "File to use for gline database"},
163 >  {"klinefile",  &ConfigGeneral.klinefile,
164 >   STRING, "File to use for kline database"},
165 >  {"dlinefile",  &ConfigGeneral.dlinefile,
166 >   STRING, "File to use for dline database"},
167 >  {"xlinefile",  &ConfigGeneral.xlinefile,
168 >   STRING, "File to use for xline database"},
169 >  {"resvfile",  &ConfigGeneral.resvfile,
170 >   STRING, "File to use for resv database"},
171 >  {"logfile",    &logFileName,
172     STRING, "File to use for ircd.log"},
173    {"pidfile",    &pidFileName,
174     STRING, "File to use for process ID"},
175 <  {"foreground", &server_state.foreground,
175 >  {"foreground", &server_state.foreground,
176     YESNO, "Run in foreground (don't detach)"},
177 <  {"version",    &printVersion,
177 >  {"version",    &printVersion,
178     YESNO, "Print version and exit"},
179    {"help", NULL, USAGE, "Print this text"},
180    {NULL, NULL, STRING, NULL},
# Line 216 | Line 183 | struct lgetopt myopts[] = {
183   void
184   set_time(void)
185   {
186 <  static char to_send[200];
220 <  struct timeval newtime;
221 < #ifdef _WIN32
222 <  FILETIME ft;
223 <
224 <  GetSystemTimeAsFileTime(&ft);
225 <  if (ft.dwLowDateTime < 0xd53e8000)
226 <    ft.dwHighDateTime--;
227 <  ft.dwLowDateTime -= 0xd53e8000;
228 <  ft.dwHighDateTime -= 0x19db1de;
229 <
230 <  newtime.tv_sec  = (*(uint64_t *) &ft) / 10000000;
231 <  newtime.tv_usec = (*(uint64_t *) &ft) / 10 % 1000000;
232 < #else
233 <  newtime.tv_sec  = 0;
234 <  newtime.tv_usec = 0;
186 >  struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 };
187  
188    if (gettimeofday(&newtime, NULL) == -1)
189    {
190 <    ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted",
190 >    ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted",
191           strerror(errno));
192 <    sendto_realops_flags(UMODE_ALL, L_ALL,
192 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
193                           "Clock Failure (%s), TS can be corrupted",
194                           strerror(errno));
195 <    restart("Clock Failure");
195 >    server_die("Clock Failure", 1);
196    }
245 #endif
197  
198    if (newtime.tv_sec < CurrentTime)
199    {
200 <    ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)",
201 <               (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
202 <    report_error(L_ALL, to_send, me.name, 0);
200 >    ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)",
201 >         (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
202 >    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
203 >                         "System clock is running backwards - (%lu < %lu)",
204 >                         (unsigned long)newtime.tv_sec,
205 >                         (unsigned long)CurrentTime);
206      set_back_events(CurrentTime - newtime.tv_sec);
207    }
208  
# Line 259 | Line 213 | set_time(void)
213   static void
214   io_loop(void)
215   {
216 <  while (1 == 1)
216 >  while (1)
217    {
264    /*
265     * Maybe we want a flags word?
266     * ie. if (REHASHED_KLINES(global_flags))
267     * SET_REHASHED_KLINES(global_flags)
268     * CLEAR_REHASHED_KLINES(global_flags)
269     *
270     * - Dianora
271     */
272    if (rehashed_klines)
273    {
274      check_conf_klines();
275      rehashed_klines = 0;
276    }
277
218      if (listing_client_list.head)
219      {
220 <      dlink_node *ptr = NULL, *ptr_next = NULL;
221 <      DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head)
222 <      {
283 <        struct Client *client_p = ptr->data;
284 <        assert(client_p->localClient->list_task);
285 <        safe_list_channels(client_p, client_p->localClient->list_task, 0, 0);
286 <      }
220 >      dlink_node *node = NULL, *node_next = NULL;
221 >      DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head)
222 >        safe_list_channels(node->data, 0);
223      }
224  
225 <    /* Run pending events, then get the number of seconds to the next
226 <     * event
291 <     */
292 <    while (eventNextTime() <= CurrentTime)
293 <      eventRun();
225 >    /* Run pending events */
226 >    event_run();
227  
228      comm_select();
229      exit_aborted_clients();
230      free_exited_clients();
298    send_queued_all();
231  
232      /* Check to see whether we have to rehash the configuration .. */
233      if (dorehash)
234      {
235 <      rehash(1);
235 >      conf_rehash(1);
236        dorehash = 0;
237      }
238 +
239      if (doremotd)
240      {
241 <      read_message_file(&ConfigFileEntry.motd);
242 <      sendto_realops_flags(UMODE_ALL, L_ALL,
243 <                           "Got signal SIGUSR1, reloading ircd motd file");
241 >      motd_recache();
242 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
243 >                           "Got signal SIGUSR1, reloading motd file(s)");
244        doremotd = 0;
245      }
246    }
# Line 317 | Line 250 | io_loop(void)
250   *
251   * inputs       - none
252   * output       - none
253 < * side effects - This sets all global set options needed
253 > * side effects - This sets all global set options needed
254   */
255   static void
256   initialize_global_set_options(void)
257   {
325  memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions));
326
258    GlobalSetOptions.autoconn  = 1;
259    GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME;
260    GlobalSetOptions.spam_num  = MAX_JOIN_LEAVE_COUNT;
261  
262 <  if (ConfigFileEntry.default_floodcount)
263 <    GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount;
262 >  if (ConfigGeneral.default_floodcount)
263 >    GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount;
264    else
265      GlobalSetOptions.floodcount = 10;
266  
267 <  /* XXX I have no idea what to try here - Dianora */
268 <  GlobalSetOptions.joinfloodcount = 16;
338 <  GlobalSetOptions.joinfloodtime = 8;
267 >  GlobalSetOptions.joinfloodcount = 18;
268 >  GlobalSetOptions.joinfloodtime = 6;
269  
270    split_servers = ConfigChannel.default_split_server_count;
271    split_users   = ConfigChannel.default_split_user_count;
# Line 348 | Line 278 | initialize_global_set_options(void)
278    }
279  
280    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
351  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
352  /* End of global set options */
353 }
354
355 /* initialize_message_files()
356 *
357 * inputs       - none
358 * output       - none
359 * side effects - Set up all message files needed, motd etc.
360 */
361 static void
362 initialize_message_files(void)
363 {
364  init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd);
365  init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd);
366  init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
367
368  read_message_file(&ConfigFileEntry.motd);
369  read_message_file(&ConfigFileEntry.opermotd);
370  read_message_file(&ConfigFileEntry.linksfile);
371
372  init_isupport();
281   }
282  
283   /* initialize_server_capabs()
# Line 381 | Line 289 | static void
289   initialize_server_capabs(void)
290   {
291    add_capability("QS", CAP_QS, 1);
384  add_capability("LL", CAP_LL, 1);
292    add_capability("EOB", CAP_EOB, 1);
293 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
387 <    add_capability("TS6", CAP_TS6, 0);
388 <  add_capability("ZIP", CAP_ZIP, 0);
293 >  add_capability("TS6", CAP_TS6, 0);
294    add_capability("CLUSTER", CAP_CLUSTER, 1);
295 < #ifdef HALFOPS
295 >  add_capability("SVS", CAP_SVS, 1);
296 >  add_capability("CHW", CAP_CHW, 1);
297    add_capability("HOPS", CAP_HOPS, 1);
392 #endif
298   }
299  
300   /* write_pidfile()
# Line 401 | Line 306 | initialize_server_capabs(void)
306   static void
307   write_pidfile(const char *filename)
308   {
309 <  FBFILE *fb;
309 >  FILE *fb;
310  
311 <  if ((fb = fbopen(filename, "w")))
311 >  if ((fb = fopen(filename, "w")))
312    {
313 <    char buff[32];
313 >    char buff[IRCD_BUFSIZE];
314      unsigned int pid = (unsigned int)getpid();
410    size_t nbytes = ircsprintf(buff, "%u\n", pid);
315  
316 <    if ((fbputs(buff, fb, nbytes) == -1))
317 <      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
316 >    snprintf(buff, sizeof(buff), "%u\n", pid);
317 >
318 >    if (fputs(buff, fb) == -1)
319 >      ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
320             pid, filename, strerror(errno));
321  
322 <    fbclose(fb);
417 <    return;
322 >    fclose(fb);
323    }
324    else
325    {
326 <    ilog(L_ERROR, "Error opening pid file %s", filename);
326 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s (%s)",
327 >         filename, strerror(errno));
328    }
329   }
330  
# Line 433 | Line 339 | write_pidfile(const char *filename)
339   static void
340   check_pidfile(const char *filename)
341   {
342 < #ifndef _WIN32
343 <  FBFILE *fb;
438 <  char buff[32];
342 >  FILE *fb;
343 >  char buff[IRCD_BUFSIZE];
344    pid_t pidfromfile;
345  
346    /* Don't do logging here, since we don't have log() initialised */
347 <  if ((fb = fbopen(filename, "r")))
347 >  if ((fb = fopen(filename, "r")))
348    {
349 <    if (fbgets(buff, 20, fb) == NULL)
349 >    if (!fgets(buff, 20, fb))
350      {
351        /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
352         * strerror(errno));
# Line 459 | Line 364 | check_pidfile(const char *filename)
364        }
365      }
366  
367 <    fbclose(fb);
367 >    fclose(fb);
368    }
369    else if (errno != ENOENT)
370    {
371      /* log(L_ERROR, "Error opening pid file %s", filename); */
372    }
468 #endif
373   }
374  
375   /* setup_corefile()
# Line 490 | Line 394 | setup_corefile(void)
394   #endif
395   }
396  
397 + #ifdef HAVE_LIBCRYPTO
398 + static int
399 + always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx)
400 + {
401 +  return 1;
402 + }
403 + #endif
404 +
405   /* init_ssl()
406   *
407   * inputs       - nothing
# Line 497 | Line 409 | setup_corefile(void)
409   * side effects - setups SSL context.
410   */
411   static void
412 < init_ssl(void)
412 > ssl_init(void)
413   {
414   #ifdef HAVE_LIBCRYPTO
415    SSL_load_error_strings();
416    SSLeay_add_ssl_algorithms();
417  
418 <  ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method());
507 <  if (!ServerInfo.ctx)
418 >  if (!(ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())))
419    {
420 <    const char *s;
420 >    const char *s = ERR_lib_error_string(ERR_get_error());
421  
422 <    fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n",
423 <            s = ERR_lib_error_string(ERR_get_error()));
424 <    ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
422 >    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
423 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s", s);
424 >    exit(EXIT_FAILURE);
425 >    return;  /* Not reached */
426    }
427  
428 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_NO_SSLv2);
429 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
430 <  SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL);
428 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET);
429 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE|SSL_OP_CIPHER_SERVER_PREFERENCE);
430 >  SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
431 >                     always_accept_verify_cb);
432 >  SSL_CTX_set_session_cache_mode(ConfigServerInfo.server_ctx, SSL_SESS_CACHE_OFF);
433 >  SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL");
434  
435 <  bio_spare_fd = save_spare_fd("SSL private key validation");
436 < #endif /* HAVE_LIBCRYPTO */
437 < }
435 > #if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH)
436 >  {
437 >    EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
438  
439 < /* init_callbacks()
440 < *
441 < * inputs       - nothing
442 < * output       - nothing
443 < * side effects - setups standard hook points
444 < */
445 < static void
446 < init_callbacks(void)
447 < {
448 <  iorecv_cb = register_callback("iorecv", iorecv_default);
449 <  iosend_cb = register_callback("iosend", iosend_default);
450 <  iorecvctrl_cb = register_callback("iorecvctrl", NULL);
451 <  iosendctrl_cb = register_callback("iosendctrl", NULL);
439 >    if (key)
440 >    {
441 >      SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key);
442 >      EC_KEY_free(key);
443 >    }
444 >  }
445 >
446 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE);
447 > #endif
448 >
449 >  if (!(ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())))
450 >  {
451 >    const char *s = ERR_lib_error_string(ERR_get_error());
452 >
453 >    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
454 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s", s);
455 >    exit(EXIT_FAILURE);
456 >    return;  /* Not reached */
457 >  }
458 >
459 >  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET);
460 >  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE);
461 >  SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
462 >                     always_accept_verify_cb);
463 >  SSL_CTX_set_session_cache_mode(ConfigServerInfo.client_ctx, SSL_SESS_CACHE_OFF);
464 > #endif /* HAVE_LIBCRYPTO */
465   }
466  
467   int
468   main(int argc, char *argv[])
469   {
470 <  /* Check to see if the user is running
471 <   * us as root, which is a nono
544 <   */
545 < #ifndef _WIN32
546 <  if (geteuid() == 0)
470 >  /* Check to see if the user is running us as root, which is a nono */
471 >  if (!geteuid())
472    {
473 <    fprintf(stderr, "Don't run ircd as root!!!\n");
474 <    return(-1);
473 >    fprintf(stderr, "ERROR: This server won't run as root/superuser\n");
474 >    return -1;
475    }
476  
477    /* Setup corefile size immediately after boot -kre */
478    setup_corefile();
479  
555  /* set initialVMTop before we allocate any memory */
556  initialVMTop = get_vm_top();
557 #endif
558
480    /* save server boot time right away, so getrusage works correctly */
481    set_time();
482  
483 <    /* It ain't random, but it ought to be a little harder to guess */
484 <  srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
564 <  memset(&me, 0, sizeof(me));
565 <  memset(&meLocalUser, 0, sizeof(meLocalUser));
566 <  me.localClient = &meLocalUser;
567 <  dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
568 <                                                   of Client list */
569 <
570 <  memset(&ServerInfo, 0, sizeof(ServerInfo));
483 >  /* It ain't random, but it ought to be a little harder to guess */
484 >  init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
485  
486 <  /* Initialise the channel capability usage counts... */
487 <  init_chcap_usage_counts();
486 >  dlinkAdd(&me, &me.node, &global_client_list);  /* Pointer to beginning
487 >                                                   of Client list */
488 >  ConfigLog.use_logging = 1;
489 >  ConfigGeneral.dpath      = DPATH;
490 >  ConfigGeneral.spath      = SPATH;
491 >  ConfigGeneral.mpath      = MPATH;
492 >  ConfigGeneral.configfile = CPATH;    /* Server configuration file */
493 >  ConfigGeneral.klinefile  = KPATH;    /* Server kline file         */
494 >  ConfigGeneral.glinefile  = GPATH;    /* Server gline file         */
495 >  ConfigGeneral.xlinefile  = XPATH;    /* Server xline file         */
496 >  ConfigGeneral.dlinefile  = DLPATH;   /* dline file                */
497 >  ConfigGeneral.resvfile   = RESVPATH; /* resv file                 */
498  
575  ConfigFileEntry.dpath      = DPATH;
576  ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
577  ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
578  ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
579  ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file   */
580  ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file   */
581  ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
582  ConfigFileEntry.glinefile  = GPATH;  /* gline log file            */
583  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
584  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
499    myargv = argv;
500    umask(077);                /* better safe than sorry --SRB */
501  
# Line 589 | Line 503 | main(int argc, char *argv[])
503  
504    if (printVersion)
505    {
506 <    printf("ircd: version %s\n", ircd_version);
506 >    printf("ircd: version %s(%s)\n", ircd_version, serno);
507      exit(EXIT_SUCCESS);
508    }
509  
510 <  if (chdir(ConfigFileEntry.dpath))
510 >  if (chdir(ConfigGeneral.dpath))
511    {
512      perror("chdir");
513      exit(EXIT_FAILURE);
514    }
515  
516 <  init_ssl();
516 >  ssl_init();
517  
604 #ifndef _WIN32
518    if (!server_state.foreground)
519    {
520      make_daemon();
# Line 611 | Line 524 | main(int argc, char *argv[])
524      print_startup(getpid());
525  
526    setup_signals();
614 #endif
615
616  get_ircd_platform(ircd_platform);
527  
618  /* Init the event subsystem */
619  eventInit();
528    /* We need this to initialise the fd array before anything else */
529    fdlist_init();
530 <  init_log(logFileName);
531 <  check_can_use_v6();
532 <  init_comm();         /* This needs to be setup early ! -- adrian */
530 >  log_set_file(LOG_TYPE_IRCD, 0, logFileName);
531 >
532 >  init_netio();         /* This needs to be setup early ! -- adrian */
533 >
534    /* Check if there is pidfile and daemon already running */
535    check_pidfile(pidFileName);
536  
537 < #ifndef NOBALLOC
629 <  initBlockHeap();
630 < #endif
537 >  mp_pool_init();
538    init_dlink_nodes();
539 <  init_callbacks();
633 <  initialize_message_files();
539 >  init_isupport();
540    dbuf_init();
541 <  init_hash();
542 <  init_ip_hash_table();      /* client host ip hash table */
543 <  init_host_hash();          /* Host-hashtable. */
544 <  clear_tree_parse();
545 <  init_client();
640 <  init_class();
641 <  init_whowas();
541 >  hash_init();
542 >  ipcache_init();
543 >  client_init();
544 >  class_init();
545 >  whowas_init();
546    watch_init();
547 <  init_stats();
547 >  auth_init();          /* Initialise the auth code */
548 >  init_resolver();      /* Needs to be setup before the io loop */
549 >  modules_init();
550    read_conf_files(1);   /* cold start init conf files */
645  initServerMask();
646  me.id[0] = '\0';
551    init_uid();
648  init_auth();          /* Initialise the auth code */
649 #ifndef _WIN32
650  init_resolver();      /* Needs to be setup before the io loop */
651 #endif
552    initialize_server_capabs();   /* Set up default_server_capabs */
553    initialize_global_set_options();
554 <  init_channels();
554 >  channel_init();
555 >  read_links_file();
556 >  motd_init();
557 >  user_usermodes_init();
558 > #ifdef HAVE_LIBGEOIP
559 >  geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE);
560 > #endif
561 >
562 >  if (EmptyString(ConfigServerInfo.sid))
563 >  {
564 >    ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block.");
565 >    exit(EXIT_FAILURE);
566 >  }
567 >
568 >  strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id));
569  
570 <  if (ServerInfo.name == NULL)
570 >  if (EmptyString(ConfigServerInfo.name))
571    {
572 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
572 >    ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
573      exit(EXIT_FAILURE);
574    }
575 <  strlcpy(me.name, ServerInfo.name, sizeof(me.name));
575 >
576 >  strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name));
577  
578    /* serverinfo{} description must exist.  If not, error out.*/
579 <  if (ServerInfo.description == NULL)
579 >  if (EmptyString(ConfigServerInfo.description))
580    {
581 <    ilog(L_CRIT,
667 <      "ERROR: No server description specified in serverinfo block.");
581 >    ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
582      exit(EXIT_FAILURE);
583    }
670  strlcpy(me.info, ServerInfo.description, sizeof(me.info));
584  
585 <  me.from    = &me;
586 <  me.servptr = &me;
585 >  strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info));
586 >
587 >  me.from                   = &me;
588 >  me.servptr                = &me;
589 >  me.connection->lasttime  = CurrentTime;
590 >  me.connection->since     = CurrentTime;
591 >  me.connection->firsttime = CurrentTime;
592  
593    SetMe(&me);
594    make_server(&me);
595  
596 <  me.lasttime = me.since = me.firsttime = CurrentTime;
596 >  hash_add_id(&me);
597    hash_add_client(&me);
680  
681  /* add ourselves to global_serv_list */
682  dlinkAdd(&me, make_dlink_node(), &global_serv_list);
598  
599 <  check_class();
599 >  dlinkAdd(&me, make_dlink_node(), &global_server_list);
600  
601 < #ifndef STATIC_MODULES
602 <  if (chdir(MODPATH))
603 <  {
604 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
605 <    exit(EXIT_FAILURE);
691 <  }
601 >  load_kline_database();
602 >  load_dline_database();
603 >  load_gline_database();
604 >  load_xline_database();
605 >  load_resv_database();
606  
607    load_all_modules(1);
608    load_conf_modules();
609    load_core_modules(1);
696  /* Go back to DPATH after checking to see if we can chdir to MODPATH */
697  chdir(ConfigFileEntry.dpath);
698 #else
699  load_all_modules(1);
700 #endif
701  /*
702   * assemble_umode_buffer() has to be called after
703   * reading conf/loading modules.
704   */
705  assemble_umode_buffer();
610  
611    write_pidfile(pidFileName);
612  
613 <  ilog(L_NOTICE, "Server Ready");
613 >  ilog(LOG_TYPE_IRCD, "Server Ready");
614  
615 <  eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
616 <  eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
615 >  event_addish(&event_cleanup_glines, NULL);
616 >  event_addish(&event_cleanup_tklines, NULL);
617  
618    /* We want try_connections to be called as soon as possible now! -- adrian */
619    /* No, 'cause after a restart it would cause all sorts of nick collides */
620 <  eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
717 <
718 <  eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
620 >  event_addish(&event_try_connections, NULL);
621  
622    /* Setup the timeout check. I'll shift it later :)  -- adrian */
623 <  eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
623 >  event_add(&event_comm_checktimeouts, NULL);
624 >
625 >  event_addish(&event_save_all_databases, NULL);
626  
627    if (ConfigServerHide.links_delay > 0)
628 <    eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
628 >  {
629 >    event_write_links_file.when = ConfigServerHide.links_delay;
630 >    event_addish(&event_write_links_file, NULL);
631 >  }
632    else
633      ConfigServerHide.links_disabled = 1;
634  
635    if (splitmode)
636 <    eventAddIsh("check_splitmode", check_splitmode, NULL, 60);
636 >    event_addish(&splitmode_event, NULL);
637  
638    io_loop();
639 <  return(0);
639 >  return 0;
640   }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)