[Snort-devel] Version 1.9-dev (Build 160) spp_portscan2.c

Phil Wood cpw at ...86...
Wed Jun 19 13:25:02 EDT 2002


Apply this patch.  It will work a lot better while gathering options.

-- 
Phil Wood, cpw at ...86...

-------------- next part --------------
--- /home/cynosure/cpw/projects/barnyard/snort/src/preprocessors/spp_portscan2.c	Mon May 27 19:24:39 2002
+++ snort/src/preprocessors/spp_portscan2.c	Wed Jun 19 20:10:06 2002
@@ -223,7 +223,7 @@
 void ParseScanmungeArgs(u_char *args)
 {
     int num_toks, s_toks;
-    char **toks;
+    char **toks = NULL;
     char **stoks;
     int i;
     char* index;
@@ -233,17 +233,14 @@
     strncpy(logpath, pv.log_dir, STD_BUF);
     strncpy(tmp, "/scan.log", STD_BUF);
     strncat(logpath, tmp, STD_BUF);
-    logfile = fopen(logpath, "a+");
     sdata.psnodes = 100;
     sdata.tgtnodes = 250;
     sdata.tgtThreshold = 5;
     sdata.portThreshold = 20;
     sdata.timeout.tv_sec = 60;
 
-    if (args==NULL)
+    if (args)
     {
-        return;
-    }
 
     toks = mSplit(args, ",", 11, &num_toks, 0);
 
@@ -257,20 +254,24 @@
 
         stoks = mSplit(index, " ", 4, &s_toks, 0);
 
+	    if (!stoks[1] || stoks[1][0] == '\0')
+	    {
+                    FatalError("%s: %s(%d) => '%s' has null value. ",
+                            MODNAME, file_name, file_line, stoks[0]);
+	    }
         if(!strncasecmp(stoks[0], "psnodes", 7))
         {
             if(isdigit((int)stoks[1][0]))
             {
                 /* number of psnodes */
-                sdata.psnodes = (int)stoks[1][0];
+                    sdata.psnodes = atoi(stoks[1]);
                 i++;
             }
             else
             {
-                /* error */
-                ErrorMessage("ERROR %s %s(%d) => In argument psnodes, please "
-                        "specify a positive integer, using default (%d)\n", 
-                        MODNAME, file_name, file_line, sdata.psnodes);
+                    /* lets cool it with the leeway */
+                    FatalError("%s: %s(%d) => '%s' has invalid value '%s'. ",
+                            MODNAME, file_name, file_line, stoks[0], stoks[1]);
             }
         }
         else if(!strncasecmp(stoks[0], "tgtnodes", 8))
@@ -278,15 +279,13 @@
             if(isdigit((int)(stoks[1][0])))
             {
                 /* number of tgtnodes */
-                sdata.tgtnodes = (int)stoks[1][0];
+                    sdata.tgtnodes = atoi(stoks[1]);
                 i++;
             }
             else
             {
-                /* error */
-                ErrorMessage("ERROR %s %s(%d) => In argument tgtnodes, please "
-                        "specify a positive integer, using default (%d)\n",
-                        MODNAME, file_name, file_line, sdata.tgtnodes);
+                    FatalError("%s: %s(%d) => '%s' has invalid value '%s'. ",
+                            MODNAME, file_name, file_line, stoks[0], stoks[1]);
             }
         }
         else if(!strncasecmp(stoks[0], "targets", 7))
@@ -294,31 +293,27 @@
             if(isdigit((int)(stoks[1][0])))
             {
                 /* number of targets */
-                sdata.tgtThreshold = (int)stoks[1][0];
+                    sdata.tgtThreshold = atoi(stoks[1]);
                 i++;
             }
             else
             {
-                /* error */
-                ErrorMessage("ERROR %s %s(%d) => In argument targets, please "
-                        "specify a positive integer, using default (%d)\n",
-                        MODNAME, file_name, file_line, sdata.tgtThreshold);
+                    FatalError("%s: %s(%d) => '%s' has invalid value '%s'. ",
+                            MODNAME, file_name, file_line, stoks[0], stoks[1]);
             }
         }
-        else if(!strncasecmp(stoks[0], "ports", 7))
+            else if(!strncasecmp(stoks[0], "ports", 5))
         {
             if(isdigit((int)(stoks[1][0])))
             {
                 /*  number of ports */
-                sdata.portThreshold = (int)stoks[1][0];
+                    sdata.portThreshold = atoi(stoks[1]);
                 i++;
             }
             else
             {
-                /* error */
-                ErrorMessage("ERROR %s %s(%d) => In argument ports, please "
-                        "specify a positive integer, using default (%d)\n",
-                        MODNAME, file_name, file_line, sdata.portThreshold);
+                    FatalError("%s: %s(%d) => '%s' has invalid value '%s'. ",
+                            MODNAME, file_name, file_line, stoks[0], stoks[1]);
             }
         }
         else if(!strncasecmp(stoks[0], "timeout", 7))
@@ -326,37 +321,51 @@
             if(isdigit((int)(stoks[1][0])))
             {
                 /*  number of ports */
-                sdata.timeout.tv_sec = (int)stoks[1][0];
+                    sdata.timeout.tv_sec = atoi(stoks[1]);
                 i++;
             }
             else
             {
-                /* error */
-                ErrorMessage("ERROR %s %s(%d) => In argument timeout, please "
-                        "specify a positive integer, using default (%d)\n",
-                        MODNAME, file_name, file_line, sdata.timeout.tv_sec);
+                    FatalError("%s: %s(%d) => '%s' has invalid value '%s'. ",
+                            MODNAME, file_name, file_line, stoks[0], stoks[1]);
             }
         }
         else if(!strncasecmp(stoks[0], "log", 3))
         {
             if(isascii((int)(stoks[1][0])))
             {
-                char logpath[STD_BUF], tmp[STD_BUF];
+		    if (stoks[1][0] == '/')
+		        strncpy (logpath, stoks[1], STD_BUF);
+		    else
+		    {
                 strncpy(logpath, pv.log_dir, STD_BUF);
-                strncpy(tmp, "/scan.log", STD_BUF);
-                strncat(logpath, tmp, STD_BUF);
-                logfile = fopen(logpath, "a+");
+                        strncat(logpath, "/", 1);
+		        strncat(logpath, stoks[1], strlen (stoks[1]));
+		    }
                 i++;
             }
             else
             {
-                /* error */
-                ErrorMessage("ERROR %s %s(%d) => In argument log, please "
-                        "specify a valid log directory, using default (%s)\n",
-                        MODNAME, file_name, file_line, logpath);
+                    FatalError("%s: %s(%d) => '%s' has invalid value '%s'. ",
+                            MODNAME, file_name, file_line, stoks[0], stoks[1]);
+                }
+	    }
+	    else
+	    {
+		    FatalError("%s: %s(%d) => option '%s' is undefined. ",
+				MODNAME, file_name, file_line, stoks[0]);
             }
         }
     }		
+    LogMessage ("    log: %s\n", logpath);
+    LogMessage ("    psnodes: %d\n", sdata.psnodes);
+    LogMessage ("    tgtnodes: %d\n", sdata.tgtnodes);
+    LogMessage ("    targets: %d\n", sdata.tgtThreshold);
+    LogMessage ("    ports: %d\n", sdata.portThreshold);
+    LogMessage ("    timeout: %d\n", sdata.timeout.tv_sec);
+
+
+    logfile = fopen(logpath, "a+");
 
     FreeToks(toks, num_toks);
 }
@@ -1367,6 +1376,7 @@
                 " trying to activate spp_scanmunge\n");
     }	
 
+    LogMessage ("Portscan2 config:\n");
     ParseScanmungeArgs(args);
     gettimeofday(&tv, &tz);
 


More information about the Snort-devel mailing list