]> jfr.im git - irc/blitzed-org/bopm.git/commitdiff
No longer use individual read functions for each protocol, now search for
authorstrtok <redacted>
Tue, 12 Feb 2002 20:54:21 +0000 (20:54 +0000)
committerstrtok <redacted>
Tue, 12 Feb 2002 20:54:21 +0000 (20:54 +0000)
a TARGET_STRING within the data. (set in conf)

config.c
extern.h
options.h
scan.c
scan.h

index 7440a2e7b66e1218d4ace8b1040a373110dc648e..098396e221c3ba7d53aa5ae770743a4f4c82a23c 100644 (file)
--- a/config.c
+++ b/config.c
@@ -53,6 +53,7 @@ char *CONF_DNSBL_TO        = 0;
 char *CONF_SENDMAIL        = 0;
 char *CONF_HELP_EMAIL      = 0;
 char *CONF_AWAY            = 0;
+char *CONF_TARGET_STRING   = 0;
 
 int  CONF_SCANPORT         = 0;
 int  CONF_PORT             = 0;
@@ -83,6 +84,7 @@ config_hash hash[] = {
        {"SENDMAIL",            TYPE_STRING, 0,0,    &CONF_SENDMAIL           },
        {"HELP_EMAIL",          TYPE_STRING, 1,0,    &CONF_HELP_EMAIL         },
        {"AWAY",                TYPE_STRING, 1,0,    &CONF_AWAY               },
+       {"TARGET_STRING",       TYPE_STRING, 1,0,    &CONF_TARGET_STRING      },
        {0,                     0,           0,0,    0                        },
 };
 
index 5c614321d26875be51633991c71b47353c49a9f3..5b1996fac788fbf1a12a67197036435e90771a67 100644 (file)
--- a/extern.h
+++ b/extern.h
@@ -25,7 +25,7 @@
     extern char *CONF_SENDMAIL;
     extern char *CONF_HELP_EMAIL;
     extern char *CONF_AWAY;
-
+    extern char *CONF_TARGET_STRING;
 
     extern int   CONF_PORT;
     extern int   CONF_SCANPORT;
index f774a3d1d466874318e368b3797f1bd7d55011c8..cdf41832c608dcb9b9b54884ff940b6b4c086f66 100644 (file)
--- a/options.h
+++ b/options.h
@@ -7,8 +7,10 @@
 /* file extensions */
 /* config */
 #define CONFEXT "conf"
+
 /* log file */
 #define LOGEXT "log"
+
 /* PID file */
 #define PIDEXT "pid"
 
 #define NODATA_TIMEOUT 900
 
 /* If defined, BOPM will force an Unreal server to use Hybrid style
- * +c notices (PROTOCTL HCN)
- */
+ * +c notices (PROTOCTL HCN) */
+
 #undef UNREAL
 
 /* Use poll() instead of select() */
 #define USE_POLL
 #define MAX_POLL 1024
-                
+
+/* Client buffer size for scan 
+ * Increase as needed, but should never need to be be over 512 bytes */
+
+#define SCANBUFFER 128
+     
 #endif /* OPTIONS_H */
diff --git a/scan.c b/scan.c
index 5040c09a67a9924221b235a1698edbf8720c6cc7..2cacb55677eb773e0a1810b3ae942dc0334cd27a 100644 (file)
--- a/scan.c
+++ b/scan.c
@@ -201,7 +201,11 @@ void scan_establish(scan_struct *conn)
      time(&(conn->create_time));                             /* Log create time of connection for timeouts */
      conn->state = STATE_ESTABLISHED;                        /* Flag conn established (for write)          */
      fcntl(conn->fd, F_SETFL, O_NONBLOCK);                   /* Set socket non blocking                    */
-     connect(conn->fd, (struct sockaddr *) &(conn->sockaddr), sizeof(conn->sockaddr));  /* Connect !   */
+     connect(conn->fd, (struct sockaddr *) &(conn->sockaddr), sizeof(conn->sockaddr));  /* Connect !       */
+
+     conn->data = malloc(SCANBUFFER * sizeof(char));         /* Allocate memory for the scan buffer        */
+     conn->datasize = 0;
+
      FD_USE++;                                               /* Increase global FD Use counter             */      
 }
 
@@ -388,44 +392,85 @@ void scan_negfail(scan_struct *conn)
 
 void scan_readready(scan_struct *conn)
 {
-        scan_struct *ss;
+        char c;
 
-        if((*conn->protocol->r_handler)(conn)) /* If read returns true, flag socket for closed and kline*/
-          {
-              irc_kline(conn->irc_addr, conn->addr);
+        while(1)
+         {
+             switch(read(conn->fd, &c, 1))
+              {
 
-              if(CONF_DNSBL_FROM && CONF_DNSBL_TO && CONF_SENDMAIL && !conn->verbose)                
-                    dnsbl_report(conn);
-                
-              log("SCAN -> %s: %s!%s@%s (%d)", conn->protocol->type , conn->irc_nick, conn->irc_user,
-                             conn->irc_addr, conn->protocol->port);
+                   case  0:
+                   case -1:
+                          return;
+
+                   default:
+                          if(c == 0 || c == '\r')
+                               continue;
+                          
+                          if(c == '\n')
+                           {
+                               conn->data[conn->datasize] = 0;
+                               conn->datasize = 0;
+                               scan_read(conn);              
+                               continue;
+                           }
+
+                          if(conn->datasize < SCANBUFFER)
+                               conn->data[++(conn->datasize) - 1] = c;
+              }
 
-              irc_send("PRIVMSG %s :%s (%d): OPEN PROXY -> "
-                            "%s!%s@%s", CONF_CHANNELS,
-                            conn->protocol->type, conn->protocol->port,
-                            conn->irc_nick, conn->irc_user,
-                            conn->irc_addr);
+         }
+              
+}
 
-              conn->protocol->stat_numopen++; /* Increase number OPEN (insecure) of this type */
+/*  Read one line in from remote, check line against 
+ *  target line.
+ */
 
-              conn->state = STATE_CLOSED;
+void scan_read(scan_struct *conn)
+{
+   if(OPT_DEBUG >= 3)
+        log("SCAN -> Checking data from %s [%s:%d] against TARGET_STRING: %s", conn->addr, 
+                                      conn->protocol->type, conn->protocol->port, conn->data);
+   if(strstr(conn->data, CONF_TARGET_STRING))
+      scan_openproxy(conn);
+}
 
-              /* Flag connections with the same addr CLOSED aswell (if not verbose */
-              if(!conn->verbose)
-                {
-                    for(ss = CONNECTIONS;ss;ss = ss->next)
-                      {
-                         if(!strcmp(conn->irc_addr, ss->irc_addr))
-                                     ss->state = STATE_CLOSED;
-                       }
-                }
+/*   Test proved positive for open proxy
+ *
+ */
 
-            }
-         else
-           scan_negfail(conn);
-             
-           
-              
+void scan_openproxy(scan_struct *conn)
+{
+     scan_struct *ss;
+
+     irc_kline(conn->irc_addr, conn->addr);
+
+     if(CONF_DNSBL_FROM && CONF_DNSBL_TO && CONF_SENDMAIL && !conn->verbose)                
+         dnsbl_report(conn);
+                
+     log("SCAN -> %s: %s!%s@%s (%d)", conn->protocol->type , conn->irc_nick, conn->irc_user,
+                  conn->irc_addr, conn->protocol->port);
+
+     irc_send("PRIVMSG %s :%s (%d): OPEN PROXY -> "
+                  "%s!%s@%s", CONF_CHANNELS,
+                  conn->protocol->type, conn->protocol->port,
+                  conn->irc_nick, conn->irc_user,
+                  conn->irc_addr);
+
+     conn->protocol->stat_numopen++; /* Increase number OPEN (insecure) of this type */
+
+     conn->state = STATE_CLOSED;
+
+     /* Flag connections with the same addr CLOSED aswell (if not verbose */
+     if(!conn->verbose)
+       {
+            for(ss = CONNECTIONS;ss;ss = ss->next)
+              {
+                  if(!strcmp(conn->irc_addr, ss->irc_addr))
+                  ss->state = STATE_CLOSED;
+              }
+       }
 }
 
 /* Poll or select returned back that this connect 
@@ -483,6 +528,9 @@ void scan_del(scan_struct *delconn)
      close(delconn->fd);
      FD_USE--;            /* 1 file descriptor freed up for use */
 
+     if(delconn->state != STATE_UNESTABLISHED)  /* If it's established, free the scan buffer */
+          free(delconn->data); 
+
      lastss = 0;
 
      for(ss = CONNECTIONS; ss; ss = ss->next)
diff --git a/scan.h b/scan.h
index 15ff9ab8d68fb0aded74b909db78012c9dc0946c..bbdfcf4483baedede87b0ae3f97fe5983ce159a1 100644 (file)
--- a/scan.h
+++ b/scan.h
           char *irc_user;              /* Username of user on IRC (for logging)            */
          char *conn_notice;           /* original server notice for this connect, used
                                        * for evidence                                     */
+          char *data;                  /* Buffered data                                    */
+          int  datasize;               /* Length of buffered data                          */
+
           int fd;                      /* File descriptor of socket                        */
           struct sockaddr_in sockaddr; /* holds information about remote host for socket() */
           time_t create_time;          /* Creation time, for timeout                       */         
      void scan_del(scan_struct *ss);
      void scan_cycle();
      void scan_check();
+     void scan_read(scan_struct *conn);
      void scan_timer();    
-     void scan_readready();
-     void scan_writeready();
-     void scan_negfail();
-     int scan_listsize();
-    
+     void scan_readready(scan_struct *conn);
+     void scan_writeready(scan_struct *conn);
+     void scan_negfail(scan_struct *conn);
+     void scan_openproxy(scan_struct *conn);
+     
      int scan_w_squid(scan_struct *ss);
      int scan_r_squid(scan_struct *ss);