[Snort-devel] umask patch

Brian Caswell bmc at ...227...
Thu Feb 15 11:47:19 EST 2001


Because someone asked for it, I finally got around to redoing a
commandline umask setting diff.  Yes, you can shoot yourself in the foot
with this, but it is useful in many settings.

-brian
-------------- next part --------------
Index: snort.c
===================================================================
RCS file: /cvsroot/snort/snort/snort.c,v
retrieving revision 1.58
diff -u -r1.58 snort.c
--- snort.c	2001/02/15 04:41:13	1.58
+++ snort.c	2001/02/15 21:36:15
@@ -84,9 +84,6 @@
     signal(SIGHUP, CleanExit);
     signal(SIGUSR1, DropStats);
 
-    /* sane permissions */
-    umask(077);
-
     /*
      * set a global ptr to the program name so other functions can tell what
      * the program name is
@@ -528,6 +525,7 @@
     fputs("        -i <if>    Listen on interface <if>\n", stderr);
     fputs("        -I         Add Interface name to alert output\n", stderr);
     fputs("        -l <ld>    Log to directory <ld>\n", stderr);
+    fputs("        -m <umask> Set umask = <umask>\n", stderr);
 #ifdef ENABLE_SMB_ALERTS
     fputs("        -M <wrkst> Sends SMB message to workstations in file <wrkst>\n", stderr);
     fputs("                   (Requires smbclient to be in PATH)\n", stderr);
@@ -582,6 +580,8 @@
     char *eq_n;
     char *eq_p;
     char errorbuf[PCAP_ERRBUF_SIZE];
+    int umaskchange = 1;
+    int defumask = 0;
 
 #ifdef DEBUG
     printf("Parsing command line...\n");
@@ -596,7 +596,7 @@
 
     /* loop through each command line var and process it */
     while((ch = getopt(argc, argv,
-            "XL:IOCqS:pNA:F:DM:br:xeh:l:dc:n:P:i:vV?aso6u:g:t:U")) != -1)
+            "XL:IOCqS:pNAm:F:DM:br:xeh:l:dc:n:P:i:vV?aso6u:g:t:U")) != -1)
     {
 #ifdef DEBUG
         printf("Processing cmd line switch: %c\n", ch);
@@ -776,6 +776,27 @@
                 }
                 break;
 
+
+            case 'm':
+                {
+                    char *p;
+                    long val = 0;
+
+                    umaskchange = 0;
+
+                    val = strtol(optarg, &p, 8);
+                    if (*p != '\0' || val < 0 || (val & ~ACCESSPERMS))
+                      {
+                          FatalError("ERROR: bad umask %s\n", optarg);
+                      }
+                    else
+                      {
+                          defumask = val;
+                      }
+                    break;
+                }
+
+
             case 'M':                /* SMB Message Option */
 
                 pv.smbmsg_flag = 1;
@@ -962,6 +983,17 @@
         }
     }
 
+
+    /* if the umask arg happened, set umask */
+    if (umaskchange)
+    {
+        umask(077);           /* set default to be sane */
+    }
+    else
+    {
+        umask(defumask);
+    }
+
     /* if we're reading in BPF filters from a file */
     if(read_bpf)
     {
@@ -2214,7 +2246,6 @@
 
     dup(0);
     dup(0);
-    umask(077);
 
     return;
 }


More information about the Snort-devel mailing list