Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / s_bsd.c
index 5e85a759c72044c3110e6a6aac2328891ae7678f..5ca23bfa047811a832b1057f3ec78f72adcd53fa 100644 (file)
@@ -151,6 +151,7 @@ void report_error(const char* text, const char* who, int err)
   static time_t last_notice = 0;
   int           errtmp = errno;   /* debug may change 'errno' */
   const char*   errmsg = (err) ? strerror(err) : "";
+
   if (!errmsg)
     errmsg = "Unknown error"; 
 
@@ -164,7 +165,7 @@ void report_error(const char* text, const char* who, int err)
     sendto_opmask_butone(0, SNO_OLDSNO, text, who, errmsg);
     last_notice = CurrentTime;
   }
-  ircd_log(L_ERROR, text, who, errmsg);
+  log_write(LS_SOCKET, L_ERROR, 0, text, who, errmsg);
   errno = errtmp;
 }
 
@@ -185,7 +186,7 @@ static void connect_dns_callback(void* vptr, struct DNSReply* reply)
   }
   else
     sendto_opmask_butone(0, SNO_OLDSNO, "Connect to %s failed: host lookup",
-                        aconf->name);
+                         aconf->name);
 }
 
 /*
@@ -345,6 +346,10 @@ unsigned int deliver_it(struct Client *cptr, const char *str, unsigned int len)
       me.sendK += (me.sendB >> 10);
       me.sendB &= 0x03ff;
     }
+    /*
+     * XXX - hrmm.. set blocked here? the socket didn't
+     * say it was blocked
+     */
     if (bytes_written < len)
       cptr->flags |= FLAGS_BLOCKED;
     break;
@@ -399,7 +404,7 @@ static int completed_connection(struct Client* cptr)
     if (!msg)
       msg = "Unknown error";
     sendto_opmask_butone(0, SNO_OLDSNO, "Connection failed to %s: %s",
-                        cptr->name, msg);
+                         cptr->name, msg);
     return 0;
   }
   if (!(aconf = find_conf_byname(cptr->confs, cptr->name, CONF_SERVER))) {
@@ -436,8 +441,8 @@ static int completed_connection(struct Client* cptr)
   cptr->flags |= FLAGS_PINGSENT;
 
   sendrawto_one(cptr, MSG_SERVER " %s 1 %Tu %Tu J%s %s%s :%s",
-               me.name, me.serv->timestamp, newts, MAJOR_PROTOCOL, 
-               NumServCap(&me), me.info);
+                me.name, me.serv->timestamp, newts, MAJOR_PROTOCOL, 
+                NumServCap(&me), me.info);
 
   return (IsDead(cptr)) ? 0 : 1;
 }
@@ -566,6 +571,7 @@ void add_connection(struct Listener* listener, int fd) {
   
   assert(0 != listener);
 
   /*
    * Removed preliminary access check. Full check is performed in m_server and
    * m_user instead. Also connection time out help to get rid of unwanted
@@ -577,26 +583,20 @@ void add_connection(struct Listener* listener, int fd) {
     return;
   }
 
-
   /*
    * Add this local client to the IPcheck registry.
    *
-   * If it is a connection to a user port and if the site has been throttled,
-   * reject the user.
+   * If they're throttled, murder them, but tell them why first.
    */
-  if (!ip_registry_check_local(addr.sin_addr.s_addr, &next_target) &&
-      !listener->server) {
-    send(fd, throttle_message, 66, 0);
-    close(fd);
+  if (!IPcheck_local_connect(addr.sin_addr, &next_target) && !listener->server) {
     ++ServerStats->is_ref;
-    return;
+     write(fd, throttle_message, strlen(throttle_message));
+     close(fd);
+     return;
   }
 
   new_client = make_client(0, ((listener->server) ? 
-                              STAT_UNKNOWN_SERVER : STAT_UNKNOWN_USER));
-
-  if (!listener->server)
-    ip_registry_local_connect(new_client);
+                               STAT_UNKNOWN_SERVER : STAT_UNKNOWN_USER));
 
   /*
    * Copy ascii address to 'sockhost' just in case. Then we have something
@@ -615,7 +615,6 @@ void add_connection(struct Listener* listener, int fd) {
   ++listener->ref_count;
 
   Count_newunknown(UserStats);
-
   /* if we've made it this far we can put the client on the auth query pile */
   start_auth(new_client);
 }
@@ -1061,8 +1060,7 @@ int read_message(time_t delay)
       const char* msg = (cptr->error) ? strerror(cptr->error) : "EOF from client";
       if (!msg)
         msg = "Unknown error";
-      exit_client_msg(cptr, cptr, &me, "Read error: %s",
-                      msg);
+      exit_client_msg(cptr, cptr, &me, "Read error: %s", msg);
     }
   }
   return 0;
@@ -1247,12 +1245,6 @@ int read_message(time_t delay)
       if (CPTR_KILLED == (length = read_packet(cptr, read_ready)))
         continue;
     }
-#if 0
-    /* Bullshit, why would we want to flush sockets while using non-blocking?
-     * This uses > 4% cpu! --Run */
-    if (length > 0)
-      flush_connections(LocalClientArray[i]);
-#endif
     if (IsDead(cptr)) {
       const char* msg = (cptr->error) ? strerror(cptr->error) : cptr->info;
       if (!msg)
@@ -1281,8 +1273,7 @@ int read_message(time_t delay)
       const char* msg = (cptr->error) ? strerror(cptr->error) : "EOF from client";
       if (!msg)
         msg = "Unknown error";
-      exit_client_msg(cptr, cptr, &me, "Read error: %s",
-                      msg);
+      exit_client_msg(cptr, cptr, &me, "Read error: %s", msg);
     }
   }
   return 0;
@@ -1311,7 +1302,7 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
 
   if (aconf->dns_pending) {
     sendto_opmask_butone(0, SNO_OLDSNO, "Server %s connect DNS pending",
-                        aconf->name);
+                         aconf->name);
     return 0;
   }
   Debug((DEBUG_NOTICE, "Connect to %s[@%s]", aconf->name,
@@ -1320,17 +1311,17 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
   if ((cptr = FindClient(aconf->name))) {
     if (IsServer(cptr) || IsMe(cptr)) {
       sendto_opmask_butone(0, SNO_OLDSNO, "Server %s already present from %s", 
-                          aconf->name, cptr->from->name);
+                           aconf->name, cptr->from->name);
       if (by && IsUser(by) && !MyUser(by)) {
-       sendcmdto_one(&me, CMD_NOTICE, by, "%C :Server %s already present "
-                     "from %s", by, aconf->name, cptr->from->name);
+        sendcmdto_one(&me, CMD_NOTICE, by, "%C :Server %s already present "
+                      "from %s", by, aconf->name, cptr->from->name);
       }
       return 0;
     }
     else if (IsHandshake(cptr) || IsConnecting(cptr)) {
       if (by && IsUser(by)) {
-       sendcmdto_one(&me, CMD_NOTICE, by, "%C :Connection to %s already in "
-                     "progress", by, cptr->name);
+        sendcmdto_one(&me, CMD_NOTICE, by, "%C :Connection to %s already in "
+                      "progress", by, cptr->name);
       }
       return 0;
     }
@@ -1378,10 +1369,10 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
 
   if (!find_conf_byhost(cptr->confs, aconf->host, CONF_SERVER)) {
     sendto_opmask_butone(0, SNO_OLDSNO, "Host %s is not enabled for "
-                        "connecting: no C-line", aconf->name);
+                         "connecting: no C-line", aconf->name);
     if (by && IsUser(by) && !MyUser(by)) {
       sendcmdto_one(&me, CMD_NOTICE, by, "%C :Connect to host %s failed: no "
-                   "C-line", by, aconf->name);
+                    "C-line", by, aconf->name);
     }
     det_confs_butmask(cptr, 0);
     free_client(cptr);
@@ -1393,7 +1384,7 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
   if (!connect_inet(aconf, cptr)) {
     if (by && IsUser(by) && !MyUser(by)) {
       sendcmdto_one(&me, CMD_NOTICE, by, "%C :Couldn't connect to %s", by,
-                   cptr->name);
+                    cptr->name);
     }
     det_confs_butmask(cptr, 0);
     free_client(cptr);
@@ -1422,9 +1413,15 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
 
   if (cptr->fd > HighestFd)
     HighestFd = cptr->fd;
+
+  
   LocalClientArray[cptr->fd] = cptr;
 
   Count_newunknown(UserStats);
+  /* Actually we lie, the connect hasn't succeeded yet, but we have a valid
+   * cptr, so we register it now.
+   * Maybe these two calls should be merged.
+   */
   add_client_to_list(cptr);
   hAddClient(cptr);
   nextping = CurrentTime;
@@ -1435,20 +1432,11 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
 /*
  * Setup local socket structure to use for binding to.
  */
-void init_virtual_host(const struct ConfItem* conf)
+void set_virtual_host(struct in_addr addr)
 {
-  assert(0 != conf);
-
   memset(&VirtualHost, 0, sizeof(VirtualHost));
   VirtualHost.sin_family = AF_INET;
-  VirtualHost.sin_addr.s_addr = INADDR_ANY;
-
-  if (EmptyString(conf->passwd) || 0 == strcmp(conf->passwd, "*"))
-    return;
-  VirtualHost.sin_addr.s_addr = inet_addr(conf->passwd);
-
-  if (INADDR_NONE == VirtualHost.sin_addr.s_addr)
-    VirtualHost.sin_addr.s_addr = INADDR_ANY;
+  VirtualHost.sin_addr.s_addr = addr.s_addr;
 }  
 
 /*
@@ -1456,17 +1444,13 @@ void init_virtual_host(const struct ConfItem* conf)
  * matches the server's name) and its primary IP#.  Hostname is stored
  * in the client structure passed as a pointer.
  */
-int init_server_identity()
+void init_server_identity(void)
 {
-  struct ConfItem* conf = find_me();
-
-  if (!conf || EmptyString(conf->host))
-    return 0;
-
-  ircd_strncpy(me.name, conf->host, HOSTLEN);
+  const struct LocalConf* conf = conf_get_local();
+  assert(0 != conf);
 
-  init_virtual_host(conf);
-  return 1;
+  ircd_strncpy(me.name, conf->name, HOSTLEN);
+  SetYXXServerName(&me, conf->numeric);
 }