Author: Bleep <tomh@inxpress.net>
[ircu2.10.12-pk.git] / ircd / s_bsd.c
1 /*
2  * IRC - Internet Relay Chat, ircd/s_bsd.c
3  * Copyright (C) 1990 Jarkko Oikarinen and
4  *                    University of Oulu, Computing Center
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
8  * the Free Software Foundation; either version 1, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  * $Id$
21  */
22 #include "s_bsd.h"
23 #include "client.h"
24 #include "IPcheck.h"
25 #include "channel.h"
26 #include "class.h"
27 #include "hash.h"
28 #include "ircd_log.h"
29 #include "ircd_osdep.h"
30 #include "ircd_string.h"
31 #include "ircd.h"
32 #include "list.h"
33 #include "listener.h"
34 #include "numeric.h"
35 #include "numnicks.h"
36 #include "packet.h"
37 #include "parse.h"
38 #include "querycmds.h"
39 #include "res.h"
40 #include "s_auth.h"
41 #include "s_conf.h"
42 #include "s_debug.h"
43 #include "s_misc.h"
44 #include "s_user.h"
45 #include "send.h"
46 #include "sprintf_irc.h"
47 #include "struct.h"
48 #include "support.h"
49 #include "sys.h"
50 #include "version.h"
51
52 #include <arpa/inet.h>
53 #include <arpa/nameser.h>
54 #include <assert.h>
55 #include <errno.h>
56 #include <fcntl.h>
57 #include <netdb.h>
58 #include <resolv.h>
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
62 #include <sys/ioctl.h>
63 #include <sys/socket.h>
64 #include <sys/time.h>
65 #include <sys/utsname.h>
66 #include <unistd.h>
67
68 #ifdef USE_POLL
69 #include <sys/poll.h>
70 #endif /* USE_POLL */
71
72 #ifndef IN_LOOPBACKNET
73 #define IN_LOOPBACKNET  0x7f
74 #endif
75
76 #ifndef INADDR_NONE
77 #define INADDR_NONE 0xffffffff
78 #endif
79
80 struct Client*            LocalClientArray[MAXCONNECTIONS];
81 int                       HighestFd = -1;
82 static struct sockaddr_in virtualHost;
83 static char               readbuf[SERVER_TCP_WINDOW];
84 static int                running_in_background;
85
86 /*
87  * report_error text constants
88  */
89 const char* const ACCEPT_ERROR_MSG    = "error accepting connection for %s: %s";
90 const char* const BIND_ERROR_MSG      = "bind error for %s: %s";
91 const char* const CONNECT_ERROR_MSG   = "connect to host %s failed: %s";
92 const char* const CONNLIMIT_ERROR_MSG = "connect limit exceeded for %s: %s";
93 const char* const LISTEN_ERROR_MSG    = "listen error for %s: %s";
94 const char* const NONB_ERROR_MSG      = "error setting non-blocking for %s: %s";
95 const char* const PEERNAME_ERROR_MSG  = "getpeername failed for %s: %s";
96 const char* const POLL_ERROR_MSG      = "poll error for %s: %s";
97 const char* const REUSEADDR_ERROR_MSG = "error setting SO_REUSEADDR for %s: %s";
98 const char* const SELECT_ERROR_MSG    = "select error for %s: %s";
99 const char* const SETBUFS_ERROR_MSG   = "error setting buffer size for %s: %s";
100 const char* const SOCKET_ERROR_MSG    = "error creating socket for %s: %s";
101
102 #ifdef VIRTUAL_HOST
103 struct sockaddr_in vserv;
104 #endif
105
106 #ifdef GODMODE
107 #ifndef NODNS
108 #define NODNS
109 #endif
110 #ifndef NOFLOODCONTROL
111 #define NOFLOODCONTROL
112 #endif
113 #endif
114
115 #if !defined(USE_POLL)
116 #if FD_SETSIZE < (MAXCONNECTIONS + 4)
117 /*
118  * Sanity check
119  *
120  * All operating systems work when MAXCONNECTIONS <= 252.
121  * Most operating systems work when MAXCONNECTIONS <= 1020 and FD_SETSIZE is
122  *   updated correctly in the system headers (on BSD systems our sys.h has
123  *   defined FD_SETSIZE to MAXCONNECTIONS+4 before including the system's headers 
124  *   but sys/types.h might have abruptly redefined it so the check is still 
125  *   done), you might already need to recompile your kernel.
126  * For larger FD_SETSIZE your milage may vary (kernel patches may be needed).
127  * The check is _NOT_ done if we will not use FD_SETS at all (USE_POLL)
128  */
129 #error "FD_SETSIZE is too small or MAXCONNECTIONS too large."
130 #endif
131 #endif
132
133
134 /*
135  * Cannot use perror() within daemon. stderr is closed in
136  * ircd and cannot be used. And, worse yet, it might have
137  * been reassigned to a normal connection...
138  */
139
140 /*
141  * report_error
142  *
143  * This a replacement for perror(). Record error to log and
144  * also send a copy to all *LOCAL* opers online.
145  *
146  * text    is a *format* string for outputting error. It must
147  *         contain only two '%s', the first will be replaced
148  *         by the sockhost from the cptr, and the latter will
149  *         be taken from sys_errlist[errno].
150  *
151  * cptr    if not NULL, is the *LOCAL* client associated with
152  *         the error.
153  */
154 void report_error(const char* text, const char* who, int err)
155 {
156   static time_t last_notice = 0;
157   int           errtmp = errno;   /* debug may change 'errno' */
158   const char*   errmsg = (err) ? strerror(err) : "";
159   
160   if (!who)
161     who = "unknown";
162
163   if (last_notice + 20 < CurrentTime) {
164     /*
165      * pace error messages so opers don't get flooded by transients
166      */
167     sendto_ops(text, who, errmsg);
168     last_notice = CurrentTime;
169   }
170
171   ircd_log(L_ERROR, text, who, errmsg);
172
173   if (!running_in_background) {
174     fprintf(stderr, text, who, errmsg);
175     fprintf(stderr, "\n");
176   }
177   errno = errtmp;
178 }
179
180
181 /*
182  * connect_dns_callback - called when resolver query finishes
183  * if the query resulted in a successful search, reply will contain
184  * a non-null pointer, otherwise reply will be null.
185  * if successful start the connection, otherwise notify opers
186  */
187 static void connect_dns_callback(void* vptr, struct DNSReply* reply)
188 {
189   struct ConfItem* aconf = (struct ConfItem*) vptr;
190   aconf->dns_pending = 0;
191   if (reply) {
192     memcpy(&aconf->ipnum, reply->hp->h_addr, sizeof(struct in_addr));
193     connect_server(aconf, 0, reply);
194   }
195   else
196     sendto_ops("Connect to %s failed: host lookup", aconf->name);
197 }
198
199
200 /*
201  * connect_inet - set up address and port and make a connection
202  */
203 static int connect_inet(struct ConfItem* aconf, struct Client* cptr)
204 {
205   static struct sockaddr_in sin;
206   assert(0 != aconf);
207   assert(0 != cptr);
208   /*
209    * Might as well get sockhost from here, the connection is attempted
210    * with it so if it fails its useless.
211    */
212   cptr->fd = socket(AF_INET, SOCK_STREAM, 0);
213   if (-1 == cptr->fd) {
214     cptr->error = errno;
215     report_error(SOCKET_ERROR_MSG, cptr->name, errno);
216     return 0;
217   }
218   if (cptr->fd >= MAXCLIENTS) {
219     report_error(CONNLIMIT_ERROR_MSG, cptr->name, 0);
220     close(cptr->fd);
221     cptr->fd = -1;
222     return 0;
223   }
224   /*
225    * Bind to a local IP# (with unknown port - let unix decide) so
226    * we have some chance of knowing the IP# that gets used for a host
227    * with more than one IP#.
228    *
229    * No we don't bind it, not all OS's can handle connecting with
230    * an already bound socket, different ip# might occur anyway
231    * leading to a freezing select() on this side for some time.
232    * I had this on my Linux 1.1.88 --Run
233    */
234 #ifdef VIRTUAL_HOST
235   /*
236    * No, we do bind it if we have virtual host support. If we don't
237    * explicitly bind it, it will default to IN_ADDR_ANY and we lose
238    * due to the other server not allowing our base IP --smg
239    */
240   if (bind(cptr->fd, (struct sockaddr*) &virtualHost, sizeof(virtualHost))) {
241     report_error(BIND_ERROR_MSG, cptr->name, errno);
242     return 0;
243   }
244 #endif
245
246   memset(&sin, 0, sizeof(sin));
247   sin.sin_family      = AF_INET;
248   sin.sin_addr.s_addr = aconf->ipnum.s_addr;
249   sin.sin_port        = htons(aconf->port);
250   /*
251    * save connection info in client
252    */
253   cptr->ip.s_addr = aconf->ipnum.s_addr;
254   cptr->port      = aconf->port;
255   ircd_ntoa_r(cptr->sock_ip, (const char*) &cptr->ip);
256   /*
257    * we want a big buffer for server connections
258    */
259   if (!os_set_sockbufs(cptr->fd, SERVER_TCP_WINDOW)) {
260     cptr->error = errno;
261     report_error(SETBUFS_ERROR_MSG, cptr->name, errno);
262     return 0;
263   }
264   /*
265    * ALWAYS set sockets non-blocking
266    */
267   if (!os_set_nonblocking(cptr->fd)) {
268     cptr->error = errno;
269     report_error(NONB_ERROR_MSG, cptr->name, errno);
270     return 0;
271   }
272   if (!os_connect_nonb(cptr->fd, &sin)) {
273     cptr->error = errno;
274     report_error(CONNECT_ERROR_MSG, cptr->name, errno);
275     return 0;
276   }
277   return 1;
278 }
279
280 /*
281  * deliver_it
282  *   Attempt to send a sequence of bytes to the connection.
283  *   Returns
284  *
285  *   < 0     Some fatal error occurred, (but not EWOULDBLOCK).
286  *           This return is a request to close the socket and
287  *           clean up the link.
288  *
289  *   >= 0    No real error occurred, returns the number of
290  *           bytes actually transferred. EWOULDBLOCK and other
291  *           possibly similar conditions should be mapped to
292  *           zero return. Upper level routine will have to
293  *           decide what to do with those unwritten bytes...
294  *
295  *   *NOTE*  alarm calls have been preserved, so this should
296  *           work equally well whether blocking or non-blocking
297  *           mode is used...
298  *
299  *   We don't use blocking anymore, that is impossible with the
300  *      net.loads today anyway. Commented out the alarms to save cpu.
301  *      --Run
302  */
303 unsigned int deliver_it(struct Client *cptr, const char *str, unsigned int len)
304 {
305   unsigned int bytes_written = 0;
306   assert(0 != cptr);
307
308   switch (os_send_nonb(cptr->fd, str, len, &bytes_written)) {
309   case IO_SUCCESS:
310     cptr->flags &= ~FLAGS_BLOCKED;
311
312     cptr->sendB += bytes_written;
313     me.sendB    += bytes_written;
314     if (cptr->sendB > 1023) {
315       cptr->sendK += (cptr->sendB >> 10);
316       cptr->sendB &= 0x03ff;    /* 2^10 = 1024, 3ff = 1023 */
317     }
318     if (me.sendB > 1023) {
319       me.sendK += (me.sendB >> 10);
320       me.sendB &= 0x03ff;
321     }
322     if (bytes_written < len)
323       cptr->flags |= FLAGS_BLOCKED;
324     break;
325   case IO_BLOCKED:
326     cptr->flags |= FLAGS_BLOCKED;
327     break;
328   case IO_FAILURE:
329     cptr->error = errno;
330     cptr->flags |= FLAGS_DEADSOCKET;
331     break;
332   }
333   return bytes_written;
334 }
335
336 /*
337  * init_sys
338  */
339 void init_sys(void)
340 {
341   int fd;
342   int limit = os_set_fdlimit(MAXCONNECTIONS);
343   if (limit < 0) {
344     fprintf(stderr, "error setting max fd's to %d\n", limit);
345     exit(2);
346   }
347   else if (limit > 0) {
348     fprintf(stderr, "ircd fd table too big\nHard Limit: %d IRC max: %d\n",
349             limit, MAXCONNECTIONS);
350     fprintf(stderr, "set MAXCONNECTIONS to a smaller value");
351     exit(2);
352   }
353
354   for (fd = 3; fd < MAXCONNECTIONS; ++fd)
355   {
356     close(fd);
357     LocalClientArray[fd] = NULL;
358   }
359   LocalClientArray[2] = 0;
360   LocalClientArray[1] = 0;
361   LocalClientArray[0] = 0;
362   close(1);
363   close(0);
364
365   if (bootopt & BOOT_TTY) {
366     /* debugging is going to a tty */
367     init_resolver();
368     return;
369   }
370   if (!(bootopt & BOOT_DEBUG))
371     close(2);
372
373   if (fork())
374     exit(0);
375   running_in_background = 1;
376 #ifdef TIOCNOTTY
377   if ((fd = open("/dev/tty", O_RDWR)) > -1) {
378     ioctl(fd, TIOCNOTTY, 0);
379     close(fd);
380   }
381 #endif
382   setsid();
383   init_resolver();
384 }
385
386 void release_dns_reply(struct Client* cptr)
387 {
388   assert(0 != cptr);
389   assert(MyConnect(cptr));
390
391   if (cptr->dns_reply) {
392     assert(0 < cptr->dns_reply->ref_count);
393     --cptr->dns_reply->ref_count;
394     cptr->dns_reply = 0;
395   }
396 }
397
398 /*
399  * completed_connection
400  *
401  * Complete non-blocking connect()-sequence. Check access and
402  * terminate connection, if trouble detected.
403  *
404  * Return  TRUE, if successfully completed
405  *        FALSE, if failed and ClientExit
406  */
407 static int completed_connection(struct Client* cptr)
408 {
409   struct ConfItem *aconf;
410   time_t newts;
411   struct Client *acptr;
412   int i;
413
414   assert(0 != cptr);
415
416   /*
417    * get the socket status from the fd first to check if
418    * connection actually succeeded
419    */
420   if ((cptr->error = os_get_sockerr(cptr->fd))) {
421     sendto_ops("Connection failed to %s: %s", cptr->name,
422                strerror(cptr->error));
423     return 0;
424   }
425   if (!(aconf = find_conf_byname(cptr->confs, cptr->name, CONF_SERVER))) {
426     sendto_ops("Lost Server Line for %s", cptr->name);
427     return 0;
428   }
429   if (!EmptyString(aconf->passwd))
430     sendto_one(cptr, "PASS :%s", aconf->passwd);
431
432 #if 0 
433   /* dead code, already done in connect_server */
434   make_server(cptr);
435 #endif
436   /*
437    * Create a unique timestamp
438    */
439   newts = TStime();
440   for (i = HighestFd; i > -1; --i) {
441     if ((acptr = LocalClientArray[i]) && 
442         (IsServer(acptr) || IsHandshake(acptr))) {
443       if (acptr->serv->timestamp >= newts)
444         newts = acptr->serv->timestamp + 1;
445     }
446   }
447   assert(0 != cptr->serv);
448
449   cptr->serv->timestamp = newts;
450   SetHandshake(cptr);
451   /*
452    * Make us timeout after twice the timeout for DNS look ups
453    */
454   cptr->lasttime = CurrentTime;
455   cptr->flags |= FLAGS_PINGSENT;
456   sendto_one(cptr, "SERVER %s 1 " TIME_T_FMT " " TIME_T_FMT " J%s %s%s :%s",
457              me.name, me.serv->timestamp, newts, MAJOR_PROTOCOL, 
458              NumServCap(&me), me.info);
459
460   return (IsDead(cptr)) ? 0 : 1;
461 }
462
463 /*
464  * close_connection
465  *
466  * Close the physical connection. This function must make
467  * MyConnect(cptr) == FALSE, and set cptr->from == NULL.
468  */
469 void close_connection(struct Client *cptr)
470 {
471   struct ConfItem* aconf;
472
473   if (IsServer(cptr)) {
474     ServerStats->is_sv++;
475     ServerStats->is_sbs += cptr->sendB;
476     ServerStats->is_sbr += cptr->receiveB;
477     ServerStats->is_sks += cptr->sendK;
478     ServerStats->is_skr += cptr->receiveK;
479     ServerStats->is_sti += CurrentTime - cptr->firsttime;
480     if (ServerStats->is_sbs > 1023) {
481       ServerStats->is_sks += (ServerStats->is_sbs >> 10);
482       ServerStats->is_sbs &= 0x3ff;
483     }
484     if (ServerStats->is_sbr > 1023) {
485       ServerStats->is_skr += (ServerStats->is_sbr >> 10);
486       ServerStats->is_sbr &= 0x3ff;
487     }
488     /*
489      * If the connection has been up for a long amount of time, schedule
490      * a 'quick' reconnect, else reset the next-connect cycle.
491      */
492     if ((aconf = find_conf_exact(cptr->name, 0, cptr->sockhost, CONF_SERVER))) {
493       /*
494        * Reschedule a faster reconnect, if this was a automaticly
495        * connected configuration entry. (Note that if we have had
496        * a rehash in between, the status has been changed to
497        * CONF_ILLEGAL). But only do this if it was a "good" link.
498        */
499       aconf->hold = CurrentTime;
500       aconf->hold += (aconf->hold - cptr->since > HANGONGOODLINK) ?
501                      HANGONRETRYDELAY : ConfConFreq(aconf);
502       if (nextconnect > aconf->hold)
503         nextconnect = aconf->hold;
504     }
505   }
506   else if (IsUser(cptr)) {
507     ServerStats->is_cl++;
508     ServerStats->is_cbs += cptr->sendB;
509     ServerStats->is_cbr += cptr->receiveB;
510     ServerStats->is_cks += cptr->sendK;
511     ServerStats->is_ckr += cptr->receiveK;
512     ServerStats->is_cti += CurrentTime - cptr->firsttime;
513     if (ServerStats->is_cbs > 1023) {
514       ServerStats->is_cks += (ServerStats->is_cbs >> 10);
515       ServerStats->is_cbs &= 0x3ff;
516     }
517     if (ServerStats->is_cbr > 1023) {
518       ServerStats->is_ckr += (ServerStats->is_cbr >> 10);
519       ServerStats->is_cbr &= 0x3ff;
520     }
521   }
522   else
523     ServerStats->is_ni++;
524
525   if (-1 < cptr->fd) {
526     flush_connections(cptr);
527     LocalClientArray[cptr->fd] = 0;
528     close(cptr->fd);
529     cptr->fd = -1;
530   }
531   cptr->flags |= FLAGS_DEADSOCKET;
532
533   DBufClear(&cptr->sendQ);
534   DBufClear(&cptr->recvQ);
535   memset(cptr->passwd, 0, sizeof(cptr->passwd));
536   set_snomask(cptr, 0, SNO_SET);
537
538   det_confs_butmask(cptr, 0);
539
540   if (cptr->listener) {
541     release_listener(cptr->listener);
542     cptr->listener = 0;
543   }
544
545   for ( ; HighestFd > 0; --HighestFd) {
546     if (LocalClientArray[HighestFd])
547       break;
548   }
549 }
550
551 int net_close_unregistered_connections(struct Client* source)
552 {
553   int            i;
554   struct Client* cptr;
555   int            count = 0;
556   assert(0 != source);
557
558   for (i = HighestFd; i > 0; --i) {
559     if ((cptr = LocalClientArray[i]) && !IsRegistered(cptr)) {
560       sendto_one(source, rpl_str(RPL_CLOSING), me.name, source->name,
561                  get_client_name(source, HIDE_IP), cptr->status);
562       exit_client(source, cptr, &me, "Oper Closing");
563       ++count;
564     }
565   }
566   return count;
567 }
568
569 /*
570  * Creates a client which has just connected to us on the given fd.
571  * The sockhost field is initialized with the ip# of the host.
572  * The client is not added to the linked list of clients, it is
573  * passed off to the auth handler for dns and ident queries.
574  */
575 void add_connection(struct Listener* listener, int fd)
576 {
577   struct sockaddr_in addr;
578   struct Client*     new_client;
579   time_t             next_target = 0;
580   const char* const throttle_message =
581          "ERROR: Your host is trying to (re)connect too fast -- throttled\r\n";
582        /* 12345678901234567890123456789012345679012345678901234567890123456 */
583   
584   assert(0 != listener);
585   /*
586    * Removed preliminary access check. Full check is performed in
587    * m_server and m_user instead. Also connection time out help to
588    * get rid of unwanted connections.
589    */
590   if (!os_get_peername(fd, &addr) || !os_set_nonblocking(fd)) {
591     ++ServerStats->is_ref;
592     close(fd);
593     return;
594   }
595   /*
596    * XXX - do we really want to do this? is it needed?
597    */
598   os_disable_options(fd);
599
600   /*
601    * Add this local client to the IPcheck registry.
602    * If it is a connection to a user port and if the site has been throttled,
603    * reject the user.
604    */
605   if (!IPcheck_local_connect(addr.sin_addr, &next_target) && !listener->server) {
606     ++ServerStats->is_ref;
607     /*
608      * strlen(throttle_message) == 66
609      */
610     send(fd, throttle_message, 66, 0);
611     close(fd);
612     return;
613   }
614
615   new_client = make_client(NULL,
616       (listener->server) ? STAT_UNKNOWN_SERVER : STAT_UNKNOWN_USER);
617   /*
618    * Copy ascii address to 'sockhost' just in case. Then we
619    * have something valid to put into error messages...
620    */
621   ircd_ntoa_r(new_client->sock_ip, (const char*) &addr.sin_addr);   
622   strcpy(new_client->sockhost, new_client->sock_ip);
623   new_client->ip.s_addr = addr.sin_addr.s_addr;
624   new_client->port      = ntohs(addr.sin_port);
625
626   if (next_target)
627     new_client->nexttarget = next_target;
628
629   new_client->fd = fd;
630
631   if (!listener->server)
632     SetIPChecked(new_client);
633   new_client->listener = listener;
634   ++listener->ref_count;
635
636   Count_newunknown(UserStats);
637   /*
638    * if we've made it this far we can put the client on the auth query pile
639    */
640   start_auth(new_client);
641 }
642
643 /*
644  * read_packet
645  *
646  * Read a 'packet' of data from a connection and process it.  Read in 8k
647  * chunks to give a better performance rating (for server connections).
648  * Do some tricky stuff for client connections to make sure they don't do
649  * any flooding >:-) -avalon
650  */
651 static int read_packet(struct Client *cptr, int socket_ready)
652 {
653   unsigned int dolen = 0;
654   unsigned int length = 0;
655
656   if (socket_ready && !(IsUser(cptr) && DBufLength(&cptr->recvQ) > CLIENT_FLOOD)) {
657     switch (os_recv_nonb(cptr->fd, readbuf, sizeof(readbuf), &length)) {
658     case IO_SUCCESS:
659       if (length) {
660         cptr->lasttime = CurrentTime;
661         if (cptr->lasttime > cptr->since)
662           cptr->since = cptr->lasttime;
663         cptr->flags &= ~(FLAGS_PINGSENT | FLAGS_NONL);
664       }
665       break;
666     case IO_BLOCKED:
667       break;
668     case IO_FAILURE:
669       cptr->error = errno;
670       /* cptr->flags |= FLAGS_DEADSOCKET; */
671       return 0;
672     }
673   }
674
675   /*
676    * For server connections, we process as many as we can without
677    * worrying about the time of day or anything :)
678    */
679   if (length > 0 && IsServer(cptr)) {
680     return server_dopacket(cptr, readbuf, length);
681   }
682   else {
683     /*
684      * Before we even think of parsing what we just read, stick
685      * it on the end of the receive queue and do it when its
686      * turn comes around.
687      */
688     if (length > 0 && 0 == dbuf_put(&cptr->recvQ, readbuf, length)) {
689       return exit_client(cptr, cptr, &me, "dbuf_put fail");
690     }
691 #ifndef NOFLOODCONTROL
692     /*
693      * XXX - cptr will always be a user or unregistered
694      */
695     if (IsUser(cptr) && DBufLength(&cptr->recvQ) > CLIENT_FLOOD)
696       return exit_client(cptr, cptr, &me, "Excess Flood");
697
698     while (DBufLength(&cptr->recvQ) && !NoNewLine(cptr) && 
699            (IsTrusted(cptr) || cptr->since - CurrentTime < 10))
700 #else
701     while (DBufLength(&cptr->recvQ) && !NoNewLine(cptr))
702 #endif
703     {
704       /*
705        * If it has become registered as a Server
706        * then skip the per-message parsing below.
707        */
708       if (IsServer(cptr)) {
709         dolen = dbuf_get(&cptr->recvQ, readbuf, sizeof(readbuf));
710         return (dolen) ? server_dopacket(cptr, readbuf, dolen) : 1;
711       }
712       dolen = dbuf_getmsg(&cptr->recvQ, cptr->buffer, BUFSIZE);
713       /*
714        * Devious looking...whats it do ? well..if a client
715        * sends a *long* message without any CR or LF, then
716        * dbuf_getmsg fails and we pull it out using this
717        * loop which just gets the next 512 bytes and then
718        * deletes the rest of the buffer contents.
719        * -avalon
720        */
721       if (0 == dolen) {
722         if (DBufLength(&cptr->recvQ) < 510)
723           cptr->flags |= FLAGS_NONL;
724         else
725           DBufClear(&cptr->recvQ);
726       }
727       else if (CPTR_KILLED == client_dopacket(cptr, dolen))
728         return CPTR_KILLED;
729     }
730   }
731   return 1;
732 }
733
734 static int on_write_unblocked(struct Client* cptr)
735 {
736   /*
737    *  ...room for writing, empty some queue then...
738    */
739   cptr->flags &= ~FLAGS_BLOCKED;
740   if (IsConnecting(cptr)) {
741     if (!completed_connection(cptr))
742       return 0;
743   }
744   else if (cptr->listing && DBufLength(&cptr->sendQ) < 2048)
745     list_next_channels(cptr, 64);
746   send_queued(cptr);
747   return 1;
748 }
749
750 /*
751  * Select / Poll Read Algorithm for ircd
752  *
753  * We need to check the file descriptors for all the different types
754  * of things that use them, so check for reads on everything but connects
755  * and writes on connects and descriptors that are blocked
756  *
757  * for each (client in local) {
758  *   if (not connecting)
759  *     check for read;
760  *   if (connecting or blocked)
761  *     check for write;
762  * }
763  * wait for activity;
764  *
765  * for each (client in local) {
766  *   if (there are descriptors to check) {
767  *     if (write activity)
768  *       send data;
769  *     if (read activity)
770  *       read data;
771  *   }
772  *   process data read;
773  * }
774  * Note we must always process data read whether or not there has been
775  * read activity or file descriptors set, since data is buffered by the client.
776  */
777
778
779 #ifdef USE_POLL
780
781 /*
782  * poll macros
783  */
784 #if defined(POLLMSG) && defined(POLLIN) && defined(POLLRDNORM)
785 #  define POLLREADFLAGS (POLLMSG|POLLIN|POLLRDNORM)
786 #else
787 #  if defined(POLLIN) && defined(POLLRDNORM)
788 #    define POLLREADFLAGS (POLLIN|POLLRDNORM)
789 #  else
790 #    if defined(POLLIN)
791 #      define POLLREADFLAGS POLLIN
792 #    else
793 #      if defined(POLLRDNORM)
794 #        define POLLREADFLAGS POLLRDNORM
795 #      endif
796 #    endif
797 #  endif
798 #endif
799
800 #if defined(POLLOUT) && defined(POLLWRNORM)
801 #define POLLWRITEFLAGS (POLLOUT|POLLWRNORM)
802 #else
803 #  if defined(POLLOUT)
804 #    define POLLWRITEFLAGS POLLOUT
805 #  else
806 #    if defined(POLLWRNORM)
807 #      define POLLWRITEFLAGS POLLWRNORM
808 #    endif
809 #  endif
810 #endif
811
812 #ifdef POLLHUP
813 #define POLLERRORS (POLLHUP|POLLERR)
814 #else
815 #define POLLERRORS POLLERR
816 #endif
817
818 /*
819  * NOTE: pfd and pfd_count are local variable names in read_message
820  */
821 #define PFD_SETR(xfd) \
822   do { CHECK_ADD_PFD(xfd) pfd->events |= POLLREADFLAGS; } while(0)
823 #define PFD_SETW(xfd) \
824   do { CHECK_ADD_PFD(xfd) pfd->events |= POLLWRITEFLAGS; } while(0)
825
826 #define CHECK_ADD_PFD(xfd) \
827   if (pfd->fd != xfd) { \
828     pfd = &poll_fds[pfd_count++]; \
829     poll_fds[pfd_count].fd = -1; \
830     pfd->fd = xfd; \
831     pfd->events = 0; \
832   }
833
834 /*
835  * Check all connections for new connections and input data that is to be
836  * processed. Also check for connections with data queued and whether we can
837  * write it out.
838  *
839  * Don't ever use ZERO for `delay', unless you mean to poll and then
840  * you have to have sleep/wait somewhere else in the code.--msa
841  */
842 int read_message(time_t delay)
843 {
844   struct pollfd poll_fds[MAXCONNECTIONS + 1];
845   struct Client*    cptr;
846   struct Listener*    listener  = 0;
847   struct AuthRequest* auth      = 0;
848   struct AuthRequest* auth_next = 0;
849   int nfds;
850   time_t delay2 = delay;
851   int length;
852   int i;
853   int res = 0;
854   int pfd_count = 0;
855   struct pollfd* pfd = 0;
856   struct pollfd* res_pfd = 0;
857   int read_ready;
858   int write_ready;
859
860   unsigned int timeout;
861
862   for ( ; ; ) {
863     pfd_count = 0;
864     pfd = poll_fds;
865     res_pfd = 0;
866     pfd->fd = -1;
867
868     if (-1 < ResolverFileDescriptor) {
869       PFD_SETR(ResolverFileDescriptor);
870       res_pfd = pfd;
871     }
872     /*
873      * add auth file descriptors
874      */
875     for (auth = AuthPollList; auth; auth = auth->next) {
876       assert(-1 < auth->fd);
877       auth->index = pfd_count;
878       if (IsAuthConnect(auth))
879         PFD_SETW(auth->fd);
880       else
881         PFD_SETR(auth->fd);
882     }
883     /*
884      * add listener file descriptors
885      */    
886     for (listener = ListenerPollList; listener; listener = listener->next) {
887       assert(-1 < listener->fd);
888       /*
889        * pfd_count is incremented by PFD_SETR so we need to save the 
890        * index first 
891        */
892       listener->index = pfd_count;
893       PFD_SETR(listener->fd);
894     }
895
896     for (i = HighestFd; -1 < i; --i) {
897       if ((cptr = LocalClientArray[i])) {
898
899         if (DBufLength(&cptr->recvQ))
900           delay2 = 1;
901         if (DBufLength(&cptr->recvQ) < 4088 || IsServer(cptr)) {
902           PFD_SETR(i);
903         }
904         if (DBufLength(&cptr->sendQ) || IsConnecting(cptr) ||
905             (cptr->listing && DBufLength(&cptr->sendQ) < 2048)) {
906           PFD_SETW(i);
907         }
908       }
909     }
910
911     Debug((DEBUG_INFO, "poll: %d %d", delay, delay2));
912
913     timeout = (IRCD_MIN(delay2, delay)) * 1000;
914
915     nfds = poll(poll_fds, pfd_count, timeout);
916
917     CurrentTime = time(0);
918     if (-1 < nfds)
919       break;
920
921     if (EINTR == errno)
922       return -1;
923     report_error(POLL_ERROR_MSG, me.name, errno);
924     ++res;
925     if (res > 5)
926       server_restart("too many poll errors");
927     sleep(1);
928     CurrentTime = time(0);
929   }
930
931   if (res_pfd && (res_pfd->revents & (POLLREADFLAGS | POLLERRORS))) {
932     resolver_read();
933     --nfds;
934   }
935   /*
936    * check auth queries
937    */
938   for (auth = AuthPollList; auth; auth = auth_next) {
939     auth_next = auth->next;
940     i = auth->index;
941     /*
942      * check for any event, we only ask for one at a time
943      */
944     if (poll_fds[i].revents) {
945       if (IsAuthConnect(auth))
946         send_auth_query(auth);
947       else
948         read_auth_reply(auth);
949       if (0 == --nfds)
950         break;
951     }
952   }
953   /*
954    * check listeners
955    */
956   for (listener = ListenerPollList; listener; listener = listener->next) {
957     i = listener->index;
958     if (poll_fds[i].revents) {
959       accept_connection(listener);
960       if (0 == --nfds)
961         break;
962     }
963   }
964   /*
965    * i contains the next non-auth/non-listener index, since we put the
966    * resolver, auth and listener, file descriptors in poll_fds first,
967    * the very next one should be the start of the clients
968    */
969   pfd = &poll_fds[++i];
970
971   for ( ; (i < pfd_count); ++i, ++pfd) {
972     if (!(cptr = LocalClientArray[pfd->fd]))
973       continue;
974     read_ready = write_ready = 0;
975
976     if (0 < nfds && pfd->revents) {
977       --nfds;
978     
979       read_ready  = pfd->revents & POLLREADFLAGS;
980       write_ready = pfd->revents & POLLWRITEFLAGS;
981
982       if (pfd->revents & POLLERRORS) {
983         if (pfd->events & POLLREADFLAGS)
984           ++read_ready;
985         if (pfd->events & POLLWRITEFLAGS)
986           ++write_ready;
987       }
988     }
989     if (write_ready) {
990       if (!on_write_unblocked(cptr) || IsDead(cptr)) {
991         exit_client(cptr, cptr, &me,
992                     cptr->error ? strerror(cptr->error) : LastDeadComment(cptr));
993         continue;
994       }
995     }
996     length = 1;                 /* for fall through case */
997     if ((!NoNewLine(cptr) || read_ready) && !IsDead(cptr)) {
998       if (CPTR_KILLED == (length = read_packet(cptr, read_ready)))
999         continue;
1000     }
1001 #if 0
1002     /* Bullshit, why would we want to flush sockets while using non-blocking?
1003      * This uses > 4% cpu! --Run */
1004     if (length > 0)
1005       flush_connections(poll_cptr[i]);
1006 #endif
1007     if (IsDead(cptr)) {
1008       exit_client(cptr, cptr, &me,
1009          cptr->error ? strerror(cptr->error) : LastDeadComment(cptr));
1010       continue;
1011     }
1012     if (length > 0)
1013       continue;
1014     cptr->flags |= FLAGS_DEADSOCKET;
1015     /*
1016      * ...hmm, with non-blocking sockets we might get
1017      * here from quite valid reasons, although.. why
1018      * would select report "data available" when there
1019      * wasn't... So, this must be an error anyway...  --msa
1020      * actually, EOF occurs when read() returns 0 and
1021      * in due course, select() returns that fd as ready
1022      * for reading even though it ends up being an EOF. -avalon
1023      */
1024     Debug((DEBUG_ERROR, "READ ERROR: fd = %d %d %d", pfd->fd, errno, length));
1025
1026     if ((IsServer(cptr) || IsHandshake(cptr)) && cptr->error == 0 && length == 0)
1027       exit_client_msg(cptr, cptr, &me, "Server %s closed the connection (%s)",
1028                       cptr->name, cptr->serv->last_error_msg);
1029     else
1030       exit_client_msg(cptr, cptr, &me, "Read error to %s: %s",
1031                       get_client_name(cptr, HIDE_IP), 
1032                       (cptr->error) ?  strerror(cptr->error) : "EOF from client");
1033   }
1034   return 0;
1035 }
1036 #else /* USE_SELECT */
1037
1038 /*
1039  * Check all connections for new connections and input data that is to be
1040  * processed. Also check for connections with data queued and whether we can
1041  * write it out.
1042  *
1043  * Don't ever use ZERO for `delay', unless you mean to poll and then
1044  * you have to have sleep/wait somewhere else in the code.--msa
1045  */
1046 int read_message(time_t delay)
1047 {
1048   struct Client*   cptr;
1049   struct Listener* listener;
1050   int              nfds;
1051   struct timeval   wait;
1052   time_t           delay2 = delay;
1053   unsigned int     usec = 0;
1054   int              res = 0;
1055   int              length;
1056   int              i;
1057   struct AuthRequest* auth = 0;
1058   struct AuthRequest* auth_next = 0;
1059   int              read_ready;
1060   fd_set           read_set;
1061   fd_set           write_set;
1062
1063   for ( ; ; )
1064   {
1065     FD_ZERO(&read_set);
1066     FD_ZERO(&write_set);
1067
1068     if (-1 < ResolverFileDescriptor)
1069       FD_SET(ResolverFileDescriptor, &read_set);
1070     /*
1071      * set auth file descriptors
1072      */
1073     for (auth = AuthPollList; auth; auth = auth->next) {
1074       assert(-1 < auth->fd);
1075       if (IsAuthConnect(auth))
1076         FD_SET(auth->fd, &write_set);
1077       else /* if (IsAuthPending(auth)) */
1078         FD_SET(auth->fd, &read_set);
1079     }
1080     /*
1081      * set listener file descriptors
1082      */
1083     for (listener = ListenerPollList; listener; listener = listener->next) {
1084       assert(-1 < listener->fd);
1085       FD_SET(listener->fd, &read_set);
1086     }
1087
1088     for (i = HighestFd; i > -1; --i) {
1089       if ((cptr = LocalClientArray[i])) {
1090         if (DBufLength(&cptr->recvQ))
1091           delay2 = 1;
1092         if (DBufLength(&cptr->recvQ) < 4088 || IsServer(cptr))
1093           FD_SET(i, &read_set);
1094         if (DBufLength(&cptr->sendQ) || IsConnecting(cptr) ||
1095             (cptr->listing && DBufLength(&cptr->sendQ) < 2048))
1096           FD_SET(i, &write_set);
1097       }
1098     }
1099
1100     wait.tv_sec = IRCD_MIN(delay2, delay);
1101     wait.tv_usec = usec;
1102
1103     Debug((DEBUG_INFO, "select: %d %d", delay, delay2));
1104
1105     nfds = select(FD_SETSIZE, &read_set, &write_set, 0, &wait);
1106
1107     CurrentTime = time(0);
1108
1109     if (-1 < nfds)
1110       break;
1111
1112     if (errno == EINTR)
1113       return -1;
1114     report_error(SELECT_ERROR_MSG, me.name, errno);
1115     if (++res > 5)
1116       server_restart("too many select errors");
1117     sleep(1);
1118     CurrentTime = time(0);
1119   }
1120
1121   if (-1 < ResolverFileDescriptor && 
1122       FD_ISSET(ResolverFileDescriptor, &read_set)) {
1123     resolver_read();
1124     --nfds;
1125   }
1126   /*
1127    * Check fd sets for the auth fd's (if set and valid!) first
1128    * because these can not be processed using the normal loops below.
1129    * -avalon
1130    */
1131   for (auth = AuthPollList; auth; auth = auth_next) {
1132     auth_next = auth->next;
1133     assert(-1 < auth->fd);
1134     if (IsAuthConnect(auth) && FD_ISSET(auth->fd, &write_set)) {
1135       send_auth_query(auth);
1136       if (0 == --nfds)
1137         break;
1138     }
1139     else if (FD_ISSET(auth->fd, &read_set)) {
1140       read_auth_reply(auth);
1141       if (0 == --nfds)
1142         break;
1143     }
1144   }
1145   /*
1146    * next accept connections from active listeners
1147    */
1148   for (listener = ListenerPollList; listener; listener = listener->next) {
1149     assert(-1 < listener->fd);
1150     if (0 < nfds && FD_ISSET(listener->fd, &read_set))
1151       accept_connection(listener);
1152   } 
1153
1154   for (i = HighestFd; -1 < i; --i) {
1155     if (!(cptr = LocalClientArray[i]))
1156       continue;
1157     read_ready = 0;
1158     if (0 < nfds) {
1159       if (FD_ISSET(i, &write_set)) {
1160         --nfds;
1161         if (!on_write_unblocked(cptr) || IsDead(cptr)) {
1162           if (FD_ISSET(i, &read_set))
1163             --nfds;
1164           exit_client(cptr, cptr, &me,
1165                       cptr->error ? strerror(cptr->error) : LastDeadComment(cptr));
1166           continue;
1167         }
1168       }
1169       if ((read_ready = FD_ISSET(i, &read_set)))
1170         --nfds;
1171     }
1172     length = 1;                 /* for fall through case */
1173     if ((!NoNewLine(cptr) || read_ready) && !IsDead(cptr)) {
1174       if (CPTR_KILLED == (length = read_packet(cptr, read_ready)))
1175         continue;
1176     }
1177 #if 0
1178     /* Bullshit, why would we want to flush sockets while using non-blocking?
1179      * This uses > 4% cpu! --Run */
1180     if (length > 0)
1181       flush_connections(LocalClientArray[i]);
1182 #endif
1183     if (IsDead(cptr)) {
1184       exit_client(cptr, cptr, &me,
1185               cptr->error ? strerror(cptr->error) : LastDeadComment(cptr));
1186       continue;
1187     }
1188     if (length > 0)
1189       continue;
1190
1191     /*
1192      * ...hmm, with non-blocking sockets we might get
1193      * here from quite valid reasons, although.. why
1194      * would select report "data available" when there
1195      * wasn't... So, this must be an error anyway...  --msa
1196      * actually, EOF occurs when read() returns 0 and
1197      * in due course, select() returns that fd as ready
1198      * for reading even though it ends up being an EOF. -avalon
1199      */
1200     Debug((DEBUG_ERROR, "READ ERROR: fd = %d %d %d", i, cptr->error, length));
1201
1202     if ((IsServer(cptr) || IsHandshake(cptr)) && cptr->error == 0 && length == 0)
1203       exit_client_msg(cptr, cptr, &me, "Server %s closed the connection (%s)",
1204                       cptr->name, cptr->serv->last_error_msg);
1205     else
1206       exit_client_msg(cptr, cptr, &me, "Read error to %s: %s",
1207                       get_client_name(cptr, HIDE_IP),
1208                       cptr->error ? strerror(cptr->error) : "EOF from client");
1209   }
1210   return 0;
1211 }
1212
1213 #endif /* USE_SELECT */
1214
1215 /*
1216  * connect_server - start or complete a connection to another server
1217  * returns true (1) if successful, false (0) otherwise
1218  *
1219  * aconf must point to a valid C:line
1220  * m_connect            calls this with a valid by client and a null reply
1221  * try_connections      calls this with a null by client, and a null reply
1222  * connect_dns_callback call this with a null by client, and a valid reply
1223  *
1224  * XXX - if this comes from an m_connect message and a dns query needs to
1225  * be done, we loose the information about who started the connection and
1226  * it's considered an auto connect.
1227  */
1228 int connect_server(struct ConfItem* aconf, struct Client* by,
1229                    struct DNSReply* reply)
1230 {
1231   struct Client*   cptr = 0;
1232   assert(0 != aconf);
1233
1234   if (aconf->dns_pending) {
1235     sendto_ops("Server %s connect DNS pending");
1236     return 0;
1237   }
1238   Debug((DEBUG_NOTICE, "Connect to %s[@%s]", aconf->name,
1239          ircd_ntoa((const char*) &aconf->ipnum)));
1240
1241   if ((cptr = FindClient(aconf->name))) {
1242     if (IsServer(cptr) || IsMe(cptr)) {
1243       sendto_ops("Server %s already present from %s", 
1244                  aconf->name, cptr->from->name);
1245       if (by && IsUser(by) && !MyUser(by)) {
1246         sendto_one(by, "%s NOTICE %s%s :Server %s already present from %s",
1247                      NumServ(&me), NumNick(by), aconf->name, cptr->from->name);
1248       }
1249       return 0;
1250     }
1251     else if (IsHandshake(cptr) || IsConnecting(cptr)) {
1252       if (by && IsUser(by)) {
1253         if (MyUser(by))
1254           sendto_one(by, ":%s NOTICE %s :Connection to %s already in progress",
1255                      me.name, by->name, cptr->name);
1256         else
1257           sendto_one(by, "%s NOTICE %s%s :Connection to %s already in progress",
1258                      NumServ(&me), NumNick(by), cptr->name);
1259       }
1260       return 0;
1261     }
1262   }
1263   /*
1264    * If we dont know the IP# for this host and itis a hostname and
1265    * not a ip# string, then try and find the appropriate host record.
1266    */
1267   if (INADDR_NONE == aconf->ipnum.s_addr) {
1268     char buf[HOSTLEN + 1];
1269     assert(0 == reply);
1270     if (INADDR_NONE == (aconf->ipnum.s_addr = inet_addr(aconf->host))) {
1271       struct DNSQuery  query;
1272
1273       query.vptr     = aconf;
1274       query.callback = connect_dns_callback;
1275       host_from_uh(buf, aconf->host, HOSTLEN);
1276       buf[HOSTLEN] = '\0';
1277
1278       reply = gethost_byname(buf, &query);
1279
1280       if (!reply) {
1281         aconf->dns_pending = 1;
1282         return 0;
1283       }
1284       memcpy(&aconf->ipnum, reply->hp->h_addr, sizeof(struct in_addr));
1285     }
1286   }
1287   cptr = make_client(NULL, STAT_UNKNOWN_SERVER);
1288   if (reply)
1289     ++reply->ref_count;
1290   cptr->dns_reply = reply;
1291
1292   /*
1293    * Copy these in so we have something for error detection.
1294    */
1295   ircd_strncpy(cptr->name, aconf->name, HOSTLEN);
1296   ircd_strncpy(cptr->sockhost, aconf->host, HOSTLEN);
1297
1298   /*
1299    * Attach config entries to client here rather than in
1300    * completed_connection. This to avoid null pointer references
1301    */
1302   attach_confs_byhost(cptr, aconf->host, CONF_SERVER);
1303
1304   if (!find_conf_byhost(cptr->confs, aconf->host, CONF_SERVER)) {
1305     sendto_ops("Host %s is not enabled for connecting: no C-line", aconf->name);
1306     if (by && IsUser(by) && !MyUser(by)) {
1307       sendto_one(by, "%s NOTICE %s%s :Connect to host %s failed: no C-line",
1308                  NumServ(&me), NumNick(by), aconf->name);
1309     }
1310     det_confs_butmask(cptr, 0);
1311     free_client(cptr);
1312     return 0;
1313   }
1314   /*
1315    * attempt to connect to the server in the conf line
1316    */
1317   if (!connect_inet(aconf, cptr)) {
1318     if (by && IsUser(by) && !MyUser(by)) {
1319       sendto_one(by, "%s NOTICE %s%s :Couldn't connect to %s",
1320                  NumServ(&me), NumNick(by), cptr->name);
1321     }
1322     det_confs_butmask(cptr, 0);
1323     free_client(cptr);
1324     return 0;
1325   }
1326   /*
1327    * NOTE: if we're here we have a valid C:Line and the client should
1328    * have started the connection and stored the remote address/port and
1329    * ip address name in itself
1330    *
1331    * The socket has been connected or connect is in progress.
1332    */
1333   make_server(cptr);
1334   if (by && IsUser(by)) {
1335     sprintf_irc(cptr->serv->by, "%s%s", NumNick(by));
1336     assert(0 == cptr->serv->user);
1337     cptr->serv->user = by->user;
1338     by->user->refcnt++;
1339   }
1340   else {
1341     *cptr->serv->by = '\0';
1342     /* strcpy(cptr->serv->by, "Auto"); */
1343   }
1344   cptr->serv->up = &me;
1345   SetConnecting(cptr);
1346
1347   if (cptr->fd > HighestFd)
1348     HighestFd = cptr->fd;
1349   LocalClientArray[cptr->fd] = cptr;
1350
1351   Count_newunknown(UserStats);
1352   add_client_to_list(cptr);
1353   hAddClient(cptr);
1354   nextping = CurrentTime;
1355
1356   return 1;
1357 }
1358
1359 /*
1360  * Setup local socket structure to use for binding to.
1361  */
1362 void init_virtual_host(const struct ConfItem* conf)
1363 {
1364   assert(0 != conf);
1365
1366   memset(&virtualHost, 0, sizeof(virtualHost));
1367   virtualHost.sin_family = AF_INET;
1368   virtualHost.sin_addr.s_addr = INADDR_ANY;
1369
1370   if (EmptyString(conf->passwd) || 0 == strcmp(conf->passwd, "*"))
1371     return;
1372   virtualHost.sin_addr.s_addr = inet_addr(conf->passwd);
1373
1374   if (INADDR_NONE == virtualHost.sin_addr.s_addr)
1375     virtualHost.sin_addr.s_addr = INADDR_ANY;
1376 }  
1377
1378 /*
1379  * Find the real hostname for the host running the server (or one which
1380  * matches the server's name) and its primary IP#.  Hostname is stored
1381  * in the client structure passed as a pointer.
1382  */
1383 int init_server_identity()
1384 {
1385   struct ConfItem* conf = find_me();
1386
1387   if (!conf || EmptyString(conf->host))
1388     return 0;
1389
1390   ircd_strncpy(me.name, conf->host, HOSTLEN);
1391
1392   init_virtual_host(conf);
1393   return 1;
1394 }
1395
1396