public inbox for linux-audit@redhat.com
 help / color / mirror / Atom feed
* Regarding bug 435682
@ 2011-10-20 14:48 Alexander
  2011-10-21 12:49 ` Miloslav Trmac
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander @ 2011-10-20 14:48 UTC (permalink / raw)
  To: linux-audit


[-- Attachment #1.1: Type: text/plain, Size: 335 bytes --]

Here's a patch for version 2.1.3 which solves bug 435682 (
https://bugzilla.redhat.com/show_bug.cgi?id=435682).
Patched auditctl allows to specify files having spaces in ther names - just
surround a filename with apostrophes.

Hope this will help someone who encountered the same problem. And, maybe,
the bug will be closed at last :)

[-- Attachment #1.2: Type: text/html, Size: 419 bytes --]

[-- Attachment #2: audit-2.1.3.patch --]
[-- Type: text/x-patch, Size: 2108 bytes --]

diff -aurN audit-2.1.3/src/auditctl.c audit-2.1.3_patch//src/auditctl.c
--- audit-2.1.3/src/auditctl.c	2011-08-15 21:31:00.000000000 +0400
+++ audit-2.1.3_patch//src/auditctl.c	2011-10-20 18:10:31.000000000 +0400
@@ -939,6 +939,70 @@
 	return NULL;
 }
 
+
+void preprocess(char *buf)
+{
+    char quote_ctx = 0;
+
+    while (*buf)
+    {
+        if (*buf == '\'')
+            quote_ctx++;
+        
+        if (*buf == ' ' && (quote_ctx & 1))
+            *buf = 0xFF;
+        
+        buf++;
+    }
+}
+
+
+void postprocess(unsigned char *buf)
+{
+    unsigned char *str = strdup(buf);
+    unsigned char *pos1 = str;
+    unsigned char *pos2 = buf;
+    int i = 0;
+    
+    if (!str)
+        return;
+    
+    while (*pos1)
+    {
+        if (*pos1 == '\'')
+            *pos1 = ' ';
+    
+        pos1++;
+    }
+    
+    pos1 = str;
+    pos2 = buf;
+    
+    while (*pos1)
+    {
+        if (*pos1 != ' ')
+        {
+            *pos2 = *pos1;
+            pos2++;
+        }
+
+        pos1++;
+    }
+    
+    *pos2 = 0;
+    
+    while (*buf)
+    {
+        if (*buf == 0xFF)
+            *buf = ' ';
+    
+        buf++;
+    }
+    
+    free(str);
+}
+
+
 /*
  * This function reads the given file line by line and executes the rule.
  * It returns 0 if everything went OK, 1 if there are problems before reading
@@ -1001,6 +1065,8 @@
 		char *options[NUM_OPTIONS];
 		char *ptr;
 		int idx=0;
+		char apst = 0;
+		char *pos = 0;
 
 		/* Weed out blank lines */
 		while (buf[idx] == ' ')
@@ -1009,9 +1075,13 @@
 			lineno++;
 			continue;
 		}
+		
+		preprocess(buf);
+		
 		ptr = strtok(buf, " ");
 		if (ptr == NULL)
 			break;
+		
 		/* allow comments */
 		if (ptr[0] == '#') {
 			lineno++;
@@ -1021,8 +1091,10 @@
 		options[i++] = "auditctl";
 		options[i++] = ptr;
 		while( (ptr=strtok(NULL, " ")) && i<NUM_OPTIONS-1 ) {
+		        postprocess(ptr);
 			options[i++] = ptr;
 		}
+		
 		options[i] = NULL;
 
 		/* Parse it */
@@ -1094,6 +1166,7 @@
 			free(rule_new);
 			return 1;
 		}
+		
 		retval = setopt(argc, 0, argv);
 		if (retval == -3) {
 			free(rule_new);

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 6+ messages in thread
* Regarding bug 435682
@ 2011-10-28 13:56 Alexander
  2011-12-03 13:44 ` Steve Grubb
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander @ 2011-10-28 13:56 UTC (permalink / raw)
  To: linux-audit


[-- Attachment #1.1: Type: text/plain, Size: 271 bytes --]

  Here's another version of the patch for version 2.1.3 which solves bug
435682 (https://bugzilla.redhat.com/show_bug.cgi?id=435682).
Seems to be slightly better than previous version, 'cause now it's using
something like escape sequence to handle filenames with spaces.

[-- Attachment #1.2: Type: text/html, Size: 378 bytes --]

[-- Attachment #2: auditctl.patch1 --]
[-- Type: application/octet-stream, Size: 2500 bytes --]

diff -aurN audit-2.1.3/src/auditctl.c audit-2.1.3_patch//src/auditctl.c
--- audit-2.1.3/src/auditctl.c	2011-08-15 21:31:00.000000000 +0400
+++ audit-2.1.3_patch//src/auditctl.c	2011-10-24 11:14:02.000000000 +0400
@@ -939,6 +939,82 @@
 	return NULL;
 }
 
+
+void preprocess(char *buf)
+{
+    char esc_ctx = 0;
+
+    while (*buf)
+    {
+        if (*buf == '\\' && !esc_ctx)
+        {
+            esc_ctx++;
+        }
+        else
+        {
+            if (esc_ctx)
+            {
+                if (*buf == ' ')
+                {
+                    *buf = 0x07;
+                    *(buf - 1) = 0x07;
+                }
+                else if (*buf == '\\')
+                {
+                    *buf = 0x04;
+                    *(buf - 1) = 0x04;
+                }
+                    
+                esc_ctx--;
+            }
+        }
+        
+        buf++;
+    }
+}
+
+
+void postprocess(unsigned char *buf)
+{
+    unsigned char *str = strdup(buf);
+    unsigned char *pos1 = str;
+    unsigned char *pos2 = buf;
+    int i = 0;
+    
+    if (!str)
+        return;
+    
+    while (*pos1)
+    {
+        if (*pos1 == 0x07)
+        {
+            *pos2 = ' ';
+            pos1 += 2;
+            pos2++;
+
+            continue;
+        }
+        else if (*pos1 == 0x04)
+        {
+            *pos2 = '\\';
+            pos1 += 2;
+            pos2++;
+            
+            continue;
+        }
+        
+        *pos2 = *pos1;
+        
+        pos2++;
+        pos1++;
+    }
+    
+    *pos2 = 0;
+    
+    free(str);
+}
+
+
 /*
  * This function reads the given file line by line and executes the rule.
  * It returns 0 if everything went OK, 1 if there are problems before reading
@@ -1001,6 +1077,8 @@
 		char *options[NUM_OPTIONS];
 		char *ptr;
 		int idx=0;
+		char apst = 0;
+		char *pos = 0;
 
 		/* Weed out blank lines */
 		while (buf[idx] == ' ')
@@ -1009,9 +1087,13 @@
 			lineno++;
 			continue;
 		}
+		
+		preprocess(buf);
+		
 		ptr = strtok(buf, " ");
 		if (ptr == NULL)
 			break;
+		
 		/* allow comments */
 		if (ptr[0] == '#') {
 			lineno++;
@@ -1021,8 +1103,10 @@
 		options[i++] = "auditctl";
 		options[i++] = ptr;
 		while( (ptr=strtok(NULL, " ")) && i<NUM_OPTIONS-1 ) {
+		        postprocess(ptr);
 			options[i++] = ptr;
 		}
+		
 		options[i] = NULL;
 
 		/* Parse it */
@@ -1094,6 +1178,7 @@
 			free(rule_new);
 			return 1;
 		}
+		
 		retval = setopt(argc, 0, argv);
 		if (retval == -3) {
 			free(rule_new);

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-12-03 13:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-20 14:48 Regarding bug 435682 Alexander
2011-10-21 12:49 ` Miloslav Trmac
2011-10-21 12:58   ` Steve Grubb
2011-10-21 13:03   ` Alexander
  -- strict thread matches above, loose matches on Subject: below --
2011-10-28 13:56 Alexander
2011-12-03 13:44 ` Steve Grubb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox