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/src/ircd.c (file contents), Revision 30 by adx, Sun Oct 2 20:03:27 2005 UTC vs.
ircd-hybrid/trunk/src/ircd.c (file contents), Revision 1592 by michael, Sat Oct 27 21:02:32 2012 UTC

# Line 19 | Line 19
19   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
20   *  USA
21   *
22 < *  $Id: ircd.c,v 7.369 2005/09/24 09:27:18 michael Exp $
22 > *  $Id$
23   */
24  
25   #include "stdinc.h"
26   #include "s_user.h"
27 < #include "tools.h"
27 > #include "list.h"
28   #include "ircd.h"
29   #include "channel.h"
30   #include "channel_mode.h"
31   #include "client.h"
32 #include "common.h"
32   #include "event.h"
33   #include "fdlist.h"
34   #include "hash.h"
35   #include "irc_string.h"
37 #include "sprintf_irc.h"
36   #include "ircd_signal.h"
39 #include "list.h"
37   #include "s_gline.h"
38   #include "motd.h"
42 #include "ircd_handler.h"
43 #include "msg.h"         /* msgtab */
39   #include "hostmask.h"
40   #include "numeric.h"
41   #include "packet.h"
42   #include "parse.h"
43   #include "irc_res.h"
44   #include "restart.h"
45 + #include "rng_mt.h"
46   #include "s_auth.h"
47   #include "s_bsd.h"
48 < #include "s_conf.h"
49 < #include "s_log.h"
48 > #include "conf.h"
49 > #include "log.h"
50   #include "s_misc.h"
51   #include "s_serv.h"      /* try_connections */
56 #include "s_stats.h"
52   #include "send.h"
53   #include "whowas.h"
54   #include "modules.h"
# Line 63 | Line 58
58   #include "balloc.h"
59   #include "motd.h"
60   #include "supported.h"
61 + #include "watch.h"
62  
67 /* Try and find the correct name to use with getrlimit() for setting the max.
68 * number of files allowed to be open by this process.
69 */
63  
64   /* /quote set variables */
65   struct SetOptions GlobalSetOptions;
# Line 77 | Line 70 | struct config_file_entry ConfigFileEntry
70   struct server_info ServerInfo;
71   /* admin info set from ircd.conf */
72   struct admin_info AdminInfo = { NULL, NULL, NULL };
73 < struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0 };
73 > struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
74   struct ServerState_t server_state = { 0 };
75 < struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} };
75 > struct logging_entry ConfigLoggingEntry = { .use_logging = 1 };
76 > struct ServerStatistics ServerStats;
77   struct timeval SystemTime;
78   struct Client me;             /* That's me */
79   struct LocalUser meLocalUser; /* That's also part of me */
86 unsigned long connect_id = 0; /* unique connect ID */
80  
88 static unsigned long initialVMTop = 0;   /* top of virtual memory at init */
81   const char *logFileName = LPATH;
82   const char *pidFileName = PPATH;
83  
84   char **myargv;
93 char ircd_platform[PLATFORMLEN];
85  
86   int dorehash = 0;
87   int doremotd = 0;
97 time_t nextconnect = 1;       /* time for next try_connections call */
88  
89   /* Set to zero because it should be initialized later using
90   * initialize_server_capabs
91   */
92   int default_server_capabs = 0;
93 <
94 < #ifdef HAVE_LIBCRYPTO
95 < int bio_spare_fd = -1;
106 < #endif
107 <
108 < int splitmode;
109 < int splitchecking;
110 < int split_users;
93 > unsigned int splitmode;
94 > unsigned int splitchecking;
95 > unsigned int split_users;
96   unsigned int split_servers;
97  
98   /* Do klines the same way hybrid-6 did them, i.e. at the
# Line 122 | Line 107 | unsigned int split_servers;
107  
108   int rehashed_klines = 0;
109  
125 /*
126 * get_vm_top - get the operating systems notion of the resident set size
127 */
128 #ifndef _WIN32
129 static unsigned long
130 get_vm_top(void)
131 {
132  /*
133   * NOTE: sbrk is not part of the ANSI C library or the POSIX.1 standard
134   * however it seems that everyone defines it. Calling sbrk with a 0
135   * argument will return a pointer to the top of the process virtual
136   * memory without changing the process size, so this call should be
137   * reasonably safe (sbrk returns the new value for the top of memory).
138   * This code relies on the notion that the address returned will be an
139   * offset from 0 (NULL), so the result of sbrk is cast to a size_t and
140   * returned. We really shouldn't be using it here but...
141   */
142
143  void *vptr = sbrk(0);
144  return((unsigned long)vptr);
145 }
110  
111   /*
112   * print_startup - print startup information
# Line 174 | Line 138 | make_daemon(void)
138  
139    setsid();
140   }
177 #endif
178
179 /*
180 * get_maxrss - get the operating systems notion of the resident set size
181 */
182 unsigned long
183 get_maxrss(void)
184 {
185 #ifdef _WIN32
186  return (0);   /* FIXME */
187 #else
188  return (get_vm_top() - initialVMTop);
189 #endif
190 }
141  
142   static int printVersion = 0;
143  
144 < struct lgetopt myopts[] = {
144 > static struct lgetopt myopts[] = {
145    {"dlinefile",  &ConfigFileEntry.dlinefile,
146     STRING, "File to use for dline.conf"},
147    {"configfile", &ConfigFileEntry.configfile,
# Line 217 | Line 167 | set_time(void)
167   {
168    static char to_send[200];
169    struct timeval newtime;
220 #ifdef _WIN32
221  FILETIME ft;
222
223  GetSystemTimeAsFileTime(&ft);
224  if (ft.dwLowDateTime < 0xd53e8000)
225    ft.dwHighDateTime--;
226  ft.dwLowDateTime -= 0xd53e8000;
227  ft.dwHighDateTime -= 0x19db1de;
228
229  newtime.tv_sec  = (*(uint64_t *) &ft) / 10000000;
230  newtime.tv_usec = (*(uint64_t *) &ft) / 10 % 1000000;
231 #else
170    newtime.tv_sec  = 0;
171    newtime.tv_usec = 0;
172  
173    if (gettimeofday(&newtime, NULL) == -1)
174    {
175 <    ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted",
175 >    ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted",
176           strerror(errno));
177      sendto_realops_flags(UMODE_ALL, L_ALL,
178                           "Clock Failure (%s), TS can be corrupted",
179                           strerror(errno));
180      restart("Clock Failure");
181    }
244 #endif
182  
183    if (newtime.tv_sec < CurrentTime)
184    {
185 <    ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)",
186 <               (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
185 >    snprintf(to_send, sizeof(to_send),
186 >             "System clock is running backwards - (%lu < %lu)",
187 >             (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
188      report_error(L_ALL, to_send, me.name, 0);
189      set_back_events(CurrentTime - newtime.tv_sec);
190    }
# Line 281 | Line 219 | io_loop(void)
219        {
220          struct Client *client_p = ptr->data;
221          assert(client_p->localClient->list_task);
222 <        safe_list_channels(client_p, client_p->localClient->list_task, 0, 0);
222 >        safe_list_channels(client_p, client_p->localClient->list_task, 0);
223        }
224      }
225  
# Line 347 | Line 285 | initialize_global_set_options(void)
285    }
286  
287    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
350  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
288    /* End of global set options */
289   }
290  
# Line 361 | Line 298 | static void
298   initialize_message_files(void)
299   {
300    init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd);
364  init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd);
301    init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
302  
303    read_message_file(&ConfigFileEntry.motd);
368  read_message_file(&ConfigFileEntry.opermotd);
304    read_message_file(&ConfigFileEntry.linksfile);
305  
306    init_isupport();
# Line 380 | Line 315 | static void
315   initialize_server_capabs(void)
316   {
317    add_capability("QS", CAP_QS, 1);
383  add_capability("LL", CAP_LL, 1);
318    add_capability("EOB", CAP_EOB, 1);
319 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
386 <    add_capability("TS6", CAP_TS6, 0);
387 <  add_capability("ZIP", CAP_ZIP, 0);
319 >  add_capability("TS6", CAP_TS6, 0);
320    add_capability("CLUSTER", CAP_CLUSTER, 1);
321 +  add_capability("SVS", CAP_SVS, 1);
322   #ifdef HALFOPS
323    add_capability("HOPS", CAP_HOPS, 1);
324   #endif
# Line 400 | Line 333 | initialize_server_capabs(void)
333   static void
334   write_pidfile(const char *filename)
335   {
336 <  FBFILE *fb;
336 >  FILE *fb;
337  
338 <  if ((fb = fbopen(filename, "w")))
338 >  if ((fb = fopen(filename, "w")))
339    {
340      char buff[32];
341      unsigned int pid = (unsigned int)getpid();
409    size_t nbytes = ircsprintf(buff, "%u\n", pid);
342  
343 <    if ((fbputs(buff, fb, nbytes) == -1))
344 <      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
343 >    snprintf(buff, sizeof(buff), "%u\n", pid);
344 >
345 >    if ((fputs(buff, fb) == -1))
346 >      ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
347             pid, filename, strerror(errno));
348  
349 <    fbclose(fb);
416 <    return;
349 >    fclose(fb);
350    }
351    else
352    {
353 <    ilog(L_ERROR, "Error opening pid file %s", filename);
353 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename);
354    }
355   }
356  
# Line 432 | Line 365 | write_pidfile(const char *filename)
365   static void
366   check_pidfile(const char *filename)
367   {
368 < #ifndef _WIN32
436 <  FBFILE *fb;
368 >  FILE *fb;
369    char buff[32];
370    pid_t pidfromfile;
371  
372    /* Don't do logging here, since we don't have log() initialised */
373 <  if ((fb = fbopen(filename, "r")))
373 >  if ((fb = fopen(filename, "r")))
374    {
375 <    if (fbgets(buff, 20, fb) == NULL)
375 >    if (fgets(buff, 20, fb) == NULL)
376      {
377        /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
378         * strerror(errno));
# Line 458 | Line 390 | check_pidfile(const char *filename)
390        }
391      }
392  
393 <    fbclose(fb);
393 >    fclose(fb);
394    }
395    else if (errno != ENOENT)
396    {
397      /* log(L_ERROR, "Error opening pid file %s", filename); */
398    }
467 #endif
399   }
400  
401   /* setup_corefile()
# Line 502 | Line 433 | init_ssl(void)
433    SSL_load_error_strings();
434    SSLeay_add_ssl_algorithms();
435  
436 <  ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method());
506 <  if (!ServerInfo.ctx)
436 >  if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
437    {
438      const char *s;
439  
440 <    fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n",
440 >    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n",
441              s = ERR_lib_error_string(ERR_get_error()));
442 <    ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
442 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
443    }
444  
445 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_NO_SSLv2);
446 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
447 <  SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL);
445 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
446 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
447 >  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
448 >
449 >  if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
450 >  {
451 >    const char *s;
452 >
453 >    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n",
454 >            s = ERR_lib_error_string(ERR_get_error()));
455 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
456 >  }
457  
458 <  bio_spare_fd = save_spare_fd("SSL private key validation");
458 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
459 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
460 >  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL);
461   #endif /* HAVE_LIBCRYPTO */
462   }
463  
# Line 529 | Line 470 | init_ssl(void)
470   static void
471   init_callbacks(void)
472   {
473 <  iorecv_cb = register_callback("iorecv", NULL);
474 <  iosend_cb = register_callback("iosend", NULL);
534 <  iorecvctrl_cb = register_callback("iorecvctrl", NULL);
535 <  iosendctrl_cb = register_callback("iosendctrl", NULL);
473 >  iorecv_cb = register_callback("iorecv", iorecv_default);
474 >  iosend_cb = register_callback("iosend", iosend_default);
475   }
476  
477   int
# Line 541 | Line 480 | main(int argc, char *argv[])
480    /* Check to see if the user is running
481     * us as root, which is a nono
482     */
544 #ifndef _WIN32
483    if (geteuid() == 0)
484    {
485      fprintf(stderr, "Don't run ircd as root!!!\n");
486 <    return(-1);
486 >    return -1;
487    }
488  
489    /* Setup corefile size immediately after boot -kre */
490    setup_corefile();
491  
554  /* set initialVMTop before we allocate any memory */
555  initialVMTop = get_vm_top();
556 #endif
557
492    /* save server boot time right away, so getrusage works correctly */
493    set_time();
494  
495 <    /* It ain't random, but it ought to be a little harder to guess */
496 <  srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
497 <  memset(&me, 0, sizeof(me));
564 <  memset(&meLocalUser, 0, sizeof(meLocalUser));
495 >  /* It ain't random, but it ought to be a little harder to guess */
496 >  init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
497 >
498    me.localClient = &meLocalUser;
499    dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
500                                                     of Client list */
568
569  memset(&ServerInfo, 0, sizeof(ServerInfo));
570
501    /* Initialise the channel capability usage counts... */
502    init_chcap_usage_counts();
503  
# Line 575 | Line 505 | main(int argc, char *argv[])
505    ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
506    ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
507    ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
578  ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file   */
579  ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file   */
508    ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
581  ConfigFileEntry.glinefile  = GPATH;  /* gline log file            */
509    ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
510    ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
511    myargv = argv;
# Line 600 | Line 527 | main(int argc, char *argv[])
527  
528    init_ssl();
529  
603 #ifndef _WIN32
530    if (!server_state.foreground)
531    {
532      make_daemon();
# Line 610 | Line 536 | main(int argc, char *argv[])
536      print_startup(getpid());
537  
538    setup_signals();
613 #endif
614
615  get_ircd_platform(ircd_platform);
539  
540    /* Init the event subsystem */
541    eventInit();
542    /* We need this to initialise the fd array before anything else */
543    fdlist_init();
544 <  init_log(logFileName);
544 >  log_add_file(LOG_TYPE_IRCD, 0, logFileName);
545    check_can_use_v6();
546    init_comm();         /* This needs to be setup early ! -- adrian */
547    /* Check if there is pidfile and daemon already running */
548    check_pidfile(pidFileName);
549  
627 #ifndef NOBALLOC
550    initBlockHeap();
629 #endif
551    init_dlink_nodes();
552    init_callbacks();
553    initialize_message_files();
# Line 634 | Line 555 | main(int argc, char *argv[])
555    init_hash();
556    init_ip_hash_table();      /* client host ip hash table */
557    init_host_hash();          /* Host-hashtable. */
637  clear_tree_parse();
558    init_client();
559    init_class();
560 <  init_whowas();
561 <  init_stats();
642 <  read_conf_files(1);   /* cold start init conf files */
643 <  initServerMask();
644 <  me.id[0] = '\0';
645 <  init_uid();
560 >  whowas_init();
561 >  watch_init();
562    init_auth();          /* Initialise the auth code */
647 #ifndef _WIN32
563    init_resolver();      /* Needs to be setup before the io loop */
564 < #endif
564 >  modules_init();
565 >  read_conf_files(1);   /* cold start init conf files */
566 >  init_uid();
567    initialize_server_capabs();   /* Set up default_server_capabs */
568    initialize_global_set_options();
569    init_channels();
570  
571 <  if (ServerInfo.name == NULL)
571 >  if (EmptyString(ServerInfo.sid))
572    {
573 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
573 >    ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block.");
574      exit(EXIT_FAILURE);
575    }
576 +
577 +  strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
578 +
579 +  if (EmptyString(ServerInfo.name))
580 +  {
581 +    ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
582 +    exit(EXIT_FAILURE);
583 +  }
584 +
585    strlcpy(me.name, ServerInfo.name, sizeof(me.name));
586  
587    /* serverinfo{} description must exist.  If not, error out.*/
588 <  if (ServerInfo.description == NULL)
588 >  if (EmptyString(ServerInfo.description))
589    {
590 <    ilog(L_CRIT,
665 <      "ERROR: No server description specified in serverinfo block.");
590 >    ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
591      exit(EXIT_FAILURE);
592    }
593 +
594    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
595  
596 <  me.from    = &me;
597 <  me.servptr = &me;
596 >  me.from                   = &me;
597 >  me.servptr                = &me;
598 >  me.localClient->lasttime  = CurrentTime;
599 >  me.localClient->since     = CurrentTime;
600 >  me.localClient->firsttime = CurrentTime;
601  
602    SetMe(&me);
603    make_server(&me);
604  
605 <  me.lasttime = me.since = me.firsttime = CurrentTime;
605 >  hash_add_id(&me);
606    hash_add_client(&me);
607    
608    /* add ourselves to global_serv_list */
609    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
610  
682  check_class();
683
684 #ifndef STATIC_MODULES
611    if (chdir(MODPATH))
612    {
613 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
613 >    ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!");
614      exit(EXIT_FAILURE);
615    }
616  
617    load_all_modules(1);
618    load_conf_modules();
619    load_core_modules(1);
620 +
621    /* Go back to DPATH after checking to see if we can chdir to MODPATH */
622 <  chdir(ConfigFileEntry.dpath);
623 < #else
624 <  load_all_modules(1);
625 < #endif
622 >  if (chdir(ConfigFileEntry.dpath))
623 >  {
624 >    perror("chdir");
625 >    exit(EXIT_FAILURE);
626 >  }
627 >
628    /*
629     * assemble_umode_buffer() has to be called after
630     * reading conf/loading modules.
# Line 704 | Line 633 | main(int argc, char *argv[])
633  
634    write_pidfile(pidFileName);
635  
636 <  ilog(L_NOTICE, "Server Ready");
636 >  ilog(LOG_TYPE_IRCD, "Server Ready");
637  
638    eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
639    eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
# Line 713 | Line 642 | main(int argc, char *argv[])
642    /* No, 'cause after a restart it would cause all sorts of nick collides */
643    eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
644  
716  eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
717
645    /* Setup the timeout check. I'll shift it later :)  -- adrian */
646    eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
647  
# Line 727 | Line 654 | main(int argc, char *argv[])
654      eventAddIsh("check_splitmode", check_splitmode, NULL, 60);
655  
656    io_loop();
657 <  return(0);
657 >  return 0;
658   }

Comparing:
ircd-hybrid/src/ircd.c (property svn:keywords), Revision 30 by adx, Sun Oct 2 20:03:27 2005 UTC vs.
ircd-hybrid/trunk/src/ircd.c (property svn:keywords), Revision 1592 by michael, Sat Oct 27 21:02:32 2012 UTC

# Line 1 | Line 1
1 < "Id Revision"
1 > Id Revision

Diff Legend

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