Author: ZenShadow
[ircu2.10.12-pk.git] / ircd / s_auth.c
index 58ca8a1eba3a42a9adac697d3d2bc15d2741165c..ebb1dd64f3c040e581b8e86a7e6d717c03746347 100644 (file)
@@ -48,6 +48,7 @@
 #include "struct.h"
 #include "sys.h"               /* TRUE bleah */
 
+#include <arpa/inet.h>         /* inet_netof */
 #include <netdb.h>             /* struct hostent */
 #include <string.h>
 #include <stdlib.h>
@@ -96,6 +97,8 @@ typedef enum {
 struct AuthRequest* AuthPollList = 0; /* GLOBAL - auth queries pending io */
 static struct AuthRequest* AuthIncompleteList = 0;
 
+enum { AUTH_TIMEOUT = 60 };
+
 /*
  * make_auth_request - allocate a new auth request
  */
@@ -107,7 +110,7 @@ static struct AuthRequest* make_auth_request(struct Client* client)
   memset(auth, 0, sizeof(struct AuthRequest));
   auth->fd      = -1;
   auth->client  = client;
-  auth->timeout = CurrentTime + CONNECTTIMEOUT;
+  auth->timeout = CurrentTime + AUTH_TIMEOUT;
   return auth;
 }
 
@@ -174,7 +177,7 @@ static void auth_kill_client(struct AuthRequest* auth)
 
   if (IsDNSPending(auth))
     delete_resolver_queries(auth);
-  IPcheck_disconnect(auth->client);
+  ip_registry_disconnect(auth->client);
   Count_unknowndisconnects(UserStats);
   free_client(auth->client);
   free_auth_request(auth);
@@ -215,9 +218,9 @@ static void auth_dns_callback(void* vptr, struct DNSReply* reply)
     if (!hp->h_addr_list[i]) {
       if (IsUserPort(auth->client))
         sendheader(auth->client, REPORT_IP_MISMATCH);
-      sendto_op_mask(SNO_IPMISMATCH, "IP# Mismatch: %s != %s[%s]",
-                     auth->client->sock_ip, hp->h_name, 
-                     ircd_ntoa(hp->h_addr_list[0]));
+      sendto_opmask_butone(0, SNO_IPMISMATCH, "IP# Mismatch: %s != %s[%s]",
+                          auth->client->sock_ip, hp->h_name, 
+                          ircd_ntoa(hp->h_addr_list[0]));
 #if defined(KILL_IPMISMATCH)
       auth_kill_client(auth);
       return;
@@ -507,9 +510,10 @@ static char* GetValidIdent(char *buf)
 /*
  * start_auth - starts auth (identd) and dns queries for a client
  */
+enum { LOOPBACK = 127 };
+
 void start_auth(struct Client* client)
 {
-  struct DNSQuery     query;
   struct AuthRequest* auth = 0;
 
   assert(0 != client);
@@ -517,22 +521,30 @@ void start_auth(struct Client* client)
   auth = make_auth_request(client);
   assert(0 != auth);
 
-  query.vptr     = auth;
-  query.callback = auth_dns_callback;
+#if !defined(NODNS)
+  if (LOOPBACK == inet_netof(client->ip)) {
+    strcpy(client->sockhost, me.name);
+  }
+  else {
+    struct DNSQuery query;
 
-  if (IsUserPort(auth->client))
-    sendheader(client, REPORT_DO_DNS);
+    query.vptr     = auth;
+    query.callback = auth_dns_callback;
 
-#if !defined(NODNS)
-  client->dns_reply = gethost_byaddr((const char*) &client->ip, &query);
-  if (client->dns_reply) {
-    ++client->dns_reply->ref_count;
-    ircd_strncpy(client->sockhost, client->dns_reply->hp->h_name, HOSTLEN);
     if (IsUserPort(auth->client))
-      sendheader(client, REPORT_FIN_DNSC);
+      sendheader(client, REPORT_DO_DNS);
+
+    client->dns_reply = gethost_byaddr((const char*) &client->ip, &query);
+
+    if (client->dns_reply) {
+      ++client->dns_reply->ref_count;
+      ircd_strncpy(client->sockhost, client->dns_reply->hp->h_name, HOSTLEN);
+      if (IsUserPort(auth->client))
+        sendheader(client, REPORT_FIN_DNSC);
+    }
+    else
+      SetDNSPending(auth);
   }
-  else
-    SetDNSPending(auth);
 #endif
 
   if (start_auth_query(auth))