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/trunk/src/ircd.c (file contents):
Revision 2150 by michael, Fri May 31 18:39:43 2013 UTC vs.
Revision 3239 by michael, Sun Mar 30 13:55:44 2014 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-2014 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 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
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"
# Line 56 | Line 58
58   #include "mempool.h"
59   #include "hook.h"
60   #include "ircd_getopt.h"
59 #include "message.h"
61   #include "supported.h"
62   #include "watch.h"
63   #include "conf_db.h"
# Line 66 | Line 67
67   #ifdef HAVE_LIBGEOIP
68   GeoIP *geoip_ctx;
69   #endif
70 +
71   /* /quote set variables */
72   struct SetOptions GlobalSetOptions;
73 <
74 < /* configuration set from ircd.conf */
73 < struct config_file_entry ConfigFileEntry;
74 < /* server info set from ircd.conf */
75 < struct server_info ServerInfo;
76 < /* admin info set from ircd.conf */
77 < struct admin_info AdminInfo = { NULL, NULL, NULL };
78 < struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
79 < struct ServerState_t server_state = { 0 };
80 < struct logging_entry ConfigLoggingEntry = { .use_logging = 1 };
73 > struct Counter Count;
74 > struct ServerState_t server_state;
75   struct ServerStatistics ServerStats;
76   struct timeval SystemTime;
77   struct Client me;             /* That's me */
# Line 119 | Line 113 | int rehashed_klines = 0;
113   static void
114   print_startup(int pid)
115   {
116 <  printf("ircd: version %s\n", ircd_version);
116 >  printf("ircd: version %s(%s)\n", ircd_version, serno);
117    printf("ircd: pid %d\n", pid);
118    printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
119           : "foreground", ConfigFileEntry.dpath);
# Line 146 | Line 140 | make_daemon(void)
140  
141   static int printVersion = 0;
142  
143 < static struct lgetopt myopts[] = {
144 <  {"configfile", &ConfigFileEntry.configfile,
143 > static struct lgetopt myopts[] =
144 > {
145 >  {"configfile", &ConfigFileEntry.configfile,
146     STRING, "File to use for ircd.conf"},
147    {"glinefile",  &ConfigFileEntry.glinefile,
148     STRING, "File to use for gline database"},
149 <  {"klinefile",  &ConfigFileEntry.klinefile,
149 >  {"klinefile",  &ConfigFileEntry.klinefile,
150     STRING, "File to use for kline database"},
151    {"dlinefile",  &ConfigFileEntry.dlinefile,
152     STRING, "File to use for dline database"},
153 <  {"xlinefile",  &ConfigFileEntry.xlinefile,
153 >  {"xlinefile",  &ConfigFileEntry.xlinefile,
154     STRING, "File to use for xline database"},
155    {"resvfile",  &ConfigFileEntry.resvfile,
156     STRING, "File to use for resv database"},
157 <  {"logfile",    &logFileName,
157 >  {"logfile",    &logFileName,
158     STRING, "File to use for ircd.log"},
159    {"pidfile",    &pidFileName,
160     STRING, "File to use for process ID"},
161 <  {"foreground", &server_state.foreground,
161 >  {"foreground", &server_state.foreground,
162     YESNO, "Run in foreground (don't detach)"},
163 <  {"version",    &printVersion,
163 >  {"version",    &printVersion,
164     YESNO, "Print version and exit"},
165    {"help", NULL, USAGE, "Print this text"},
166    {NULL, NULL, STRING, NULL},
# Line 174 | Line 169 | static struct lgetopt myopts[] = {
169   void
170   set_time(void)
171   {
172 <  static char to_send[200];
178 <  struct timeval newtime;
179 <  newtime.tv_sec  = 0;
180 <  newtime.tv_usec = 0;
172 >  struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 };
173  
174    if (gettimeofday(&newtime, NULL) == -1)
175    {
# Line 186 | Line 178 | set_time(void)
178      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
179                           "Clock Failure (%s), TS can be corrupted",
180                           strerror(errno));
181 <    restart("Clock Failure");
181 >    server_die("Clock Failure", 1);
182    }
183  
184    if (newtime.tv_sec < CurrentTime)
185    {
186 <    snprintf(to_send, sizeof(to_send),
187 <             "System clock is running backwards - (%lu < %lu)",
188 <             (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
189 <    report_error(L_ALL, to_send, me.name, 0);
186 >    ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)",
187 >         (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
188 >    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
189 >                         "System clock is running backwards - (%lu < %lu)",
190 >                         (unsigned long)newtime.tv_sec,
191 >                         (unsigned long)CurrentTime);
192      set_back_events(CurrentTime - newtime.tv_sec);
193    }
194  
# Line 205 | Line 199 | set_time(void)
199   static void
200   io_loop(void)
201   {
202 <  while (1 == 1)
202 >  while (1)
203    {
204      /*
205       * Maybe we want a flags word?
206 <     * ie. if (REHASHED_KLINES(global_flags))
206 >     * ie. if (REHASHED_KLINES(global_flags))
207       * SET_REHASHED_KLINES(global_flags)
208       * CLEAR_REHASHED_KLINES(global_flags)
209       *
# Line 241 | Line 235 | io_loop(void)
235      comm_select();
236      exit_aborted_clients();
237      free_exited_clients();
244    send_queued_all();
238  
239      /* Check to see whether we have to rehash the configuration .. */
240      if (dorehash)
# Line 249 | Line 242 | io_loop(void)
242        rehash(1);
243        dorehash = 0;
244      }
245 +
246      if (doremotd)
247      {
248        motd_recache();
249        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
250 <                           "Got signal SIGUSR1, reloading motd files");
250 >                           "Got signal SIGUSR1, reloading motd file(s)");
251        doremotd = 0;
252      }
253    }
# Line 263 | Line 257 | io_loop(void)
257   *
258   * inputs       - none
259   * output       - none
260 < * side effects - This sets all global set options needed
260 > * side effects - This sets all global set options needed
261   */
262   static void
263   initialize_global_set_options(void)
# Line 297 | Line 291 | initialize_global_set_options(void)
291    /* End of global set options */
292   }
293  
300 /* initialize_message_files()
301 *
302 * inputs       - none
303 * output       - none
304 * side effects - Set up all message files needed, motd etc.
305 */
306 static void
307 initialize_message_files(void)
308 {
309  init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
310
311  read_message_file(&ConfigFileEntry.linksfile);
312
313  init_isupport();
314 }
315
294   /* initialize_server_capabs()
295   *
296   * inputs       - none
# Line 344 | Line 322 | write_pidfile(const char *filename)
322  
323    if ((fb = fopen(filename, "w")))
324    {
325 <    char buff[32];
325 >    char buff[IRCD_BUFSIZE];
326      unsigned int pid = (unsigned int)getpid();
327  
328      snprintf(buff, sizeof(buff), "%u\n", pid);
# Line 373 | Line 351 | static void
351   check_pidfile(const char *filename)
352   {
353    FILE *fb;
354 <  char buff[32];
354 >  char buff[IRCD_BUFSIZE];
355    pid_t pidfromfile;
356  
357    /* Don't do logging here, since we don't have log() initialised */
# Line 427 | Line 405 | setup_corefile(void)
405   #endif
406   }
407  
408 + #ifdef HAVE_LIBCRYPTO
409 + static int
410 + always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx)
411 + {
412 +  return 1;
413 + }
414 + #endif
415 +
416   /* init_ssl()
417   *
418   * inputs       - nothing
# Line 437 | Line 423 | static void
423   ssl_init(void)
424   {
425   #ifdef HAVE_LIBCRYPTO
426 +  const unsigned char session_id[] = "ircd-hybrid";
427 +
428    SSL_load_error_strings();
429    SSLeay_add_ssl_algorithms();
430  
# Line 451 | Line 439 | ssl_init(void)
439  
440    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
441    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
442 <  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
442 >  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
443 >                     always_accept_verify_cb);
444 >  SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1);
445  
446    if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
447    {
# Line 464 | Line 454 | ssl_init(void)
454  
455    SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
456    SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
457 <  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL);
457 >  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
458 >                     always_accept_verify_cb);
459   #endif /* HAVE_LIBCRYPTO */
460   }
461  
462   int
463   main(int argc, char *argv[])
464   {
465 <  /* Check to see if the user is running
475 <   * us as root, which is a nono
476 <   */
465 >  /* Check to see if the user is running us as root, which is a nono */
466    if (geteuid() == 0)
467    {
468      fprintf(stderr, "Don't run ircd as root!!!\n");
# Line 490 | Line 479 | main(int argc, char *argv[])
479    init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
480  
481    me.localClient = &meLocalUser;
482 <  dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
482 >  dlinkAdd(&me, &me.node, &global_client_list);  /* Pointer to beginning
483                                                     of Client list */
495  /* Initialise the channel capability usage counts... */
496  init_chcap_usage_counts();
497
484    ConfigFileEntry.dpath      = DPATH;
485 +  ConfigFileEntry.spath      = SPATH;
486 +  ConfigFileEntry.mpath      = MPATH;
487    ConfigFileEntry.configfile = CPATH;    /* Server configuration file */
488    ConfigFileEntry.klinefile  = KPATH;    /* Server kline file         */
489    ConfigFileEntry.glinefile  = GPATH;    /* Server gline file         */
# Line 510 | Line 498 | main(int argc, char *argv[])
498  
499    if (printVersion)
500    {
501 <    printf("ircd: version %s\n", ircd_version);
501 >    printf("ircd: version %s(%s)\n", ircd_version, serno);
502      exit(EXIT_SUCCESS);
503    }
504  
# Line 534 | Line 522 | main(int argc, char *argv[])
522  
523    /* Init the event subsystem */
524    eventInit();
525 +
526    /* We need this to initialise the fd array before anything else */
527    fdlist_init();
528    log_set_file(LOG_TYPE_IRCD, 0, logFileName);
529    check_can_use_v6();
530 <  init_comm();         /* This needs to be setup early ! -- adrian */
530 >  init_netio();         /* This needs to be setup early ! -- adrian */
531 >
532    /* Check if there is pidfile and daemon already running */
533    check_pidfile(pidFileName);
534  
535    mp_pool_init();
536    init_dlink_nodes();
537 <  initialize_message_files();
537 >  init_isupport();
538    dbuf_init();
539    hash_init();
540    init_ip_hash_table();      /* client host ip hash table */
# Line 561 | Line 551 | main(int argc, char *argv[])
551    initialize_server_capabs();   /* Set up default_server_capabs */
552    initialize_global_set_options();
553    channel_init();
554 +  read_links_file();
555    motd_init();
556   #ifdef HAVE_LIBGEOIP
557    geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE);
# Line 602 | Line 593 | main(int argc, char *argv[])
593  
594    hash_add_id(&me);
595    hash_add_client(&me);
596 <  
596 >
597    /* add ourselves to global_serv_list */
598    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
599  

Diff Legend

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