[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ossec-cvs] ossec-hids: dirtree_op.c (HEAD) mem_op.c (HEAD) [dcid]



Module name:	ossec-hids
Changes by:	dcid	07/08/12 23:11:49

Modified files:
	dirtree_op.c mem_op.c

Log message:
Description: A few new pix/sshd rules. Adding some additional libraries too (organizing mem_op).
Reviewed by: dcid
Bug:

Index: dirtree_op.c
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/shared/dirtree_op.c,v
diff -u -r1.1 -r1.2
--- dirtree_op.c	10 Aug 2007 00:56:23 -0000	1.1
+++ dirtree_op.c	13 Aug 2007 02:11:49 -0000	1.2
@@ -107,7 +107,7 @@
     if(!curnode)
     {
         os_calloc(1, sizeof(OSTreeNode), newnode);
-        printf("XXXX Adding node: %s\n", str);
+        //printf("XXXX Adding node: %s\n", str);
         
 
         if(!tree->first_node && !tree->last_node)
@@ -117,10 +117,6 @@
         }
         else
         {
-            if(!tree->first_node)
-            {
-                tree->first_node = newnode;
-            }
             tree->last_node->next = newnode;
         }
 
@@ -157,7 +153,7 @@
         
 
 
-/** void *OSDirTree_AddToTree
+/** void OSDirTree_AddToTree
  * Adds a new string to the tree, setting the data at the final leaf.
  * The tree will be divided by the "separator", where each token
  * will delimiter the child.
@@ -182,7 +178,6 @@
     }
     
     
-    /* If our tree is not empty, look for the main entry */
     curnode = tree->first_node;
     while(curnode)
     {
@@ -214,15 +209,12 @@
         }
         else
         {
-            if(!tree->first_node)
-            {
-                tree->first_node = newnode;
-            }
+            printf("XXX last new node: %s\n", tree->last_node->value);
             tree->last_node->next = newnode;
+            tree->last_node = newnode;
         }
         
         newnode->next = NULL;
-        tree->last_node = newnode;
         os_strdup(str, newnode->value);
 
 
@@ -246,6 +238,8 @@
     {
         *tmp_str = sep;
     }
+
+    return;
 }
 
 

Index: mem_op.c
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/shared/mem_op.c,v
diff -u -r1.3 -r1.4
--- mem_op.c	15 Feb 2007 02:41:02 -0000	1.3
+++ mem_op.c	13 Aug 2007 02:11:49 -0000	1.4
@@ -10,13 +10,11 @@
  */
 
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "mem_op.h"
 
 
 /* Check if String is on array (Must be NULL terminated) */
-int IsStrOnArray(char *str, char **array)
+int os_IsStrOnArray(char *str, char **array)
 {
     if(!str || !array)
     {
@@ -36,7 +34,7 @@
 
 
 /* Clear the memory of one char and one char** */
-void ClearStrMem(char *ch1, char **ch2)
+void os_FreeArray(char *ch1, char **ch2)
 {
     /* Cleaning char * */
     if(ch1)
@@ -62,5 +60,64 @@
     
     return;
 }
+
+
+/* os_LoadString: v0.1
+ * Allocate memory at "*at" and copy *str to it.
+ * If *at already exist, realloc the memory and strcat str
+ * on it.
+ * It will return the new string on success or NULL on memory error.
+ */
+char *os_LoadString(char *at, char *str)
+{
+    if(at == NULL)
+    {
+        int strsize = 0;
+        if((strsize = strlen(str)) < OS_SIZE_2048)
+        {
+            at = calloc(strsize+1,sizeof(char));
+            if(at == NULL)
+            {
+                merror(MEM_ERROR,ARGV0);
+                return(NULL);
+            }
+            strncpy(at, str, strsize);
+            return(at);
+        }
+        else
+        {
+            merror(SIZE_ERROR,ARGV0,str);
+            return(NULL);
+        }
+    }
+    else /*at is not null. Need to reallocat its memory and copy str to it*/
+    {
+        int strsize = strlen(str);
+        int atsize = strlen(at);
+        int finalsize = atsize+strsize+1;
+
+        if((atsize > OS_SIZE_2048) || (strsize > OS_SIZE_2048))
+        {
+            merror(SIZE_ERROR,ARGV0,str);
+            return(NULL);
+        }
+
+        at = realloc(at, (finalsize)*sizeof(char));
+
+        if(at == NULL)
+        {
+            merror(MEM_ERROR,ARGV0);
+            return(NULL);
+        }
+
+        strncat(at,str,strsize);
+
+        at[finalsize-1] = '\0';
+
+        return(at);
+    }
+    return(NULL);
+}
+
 
 /* EOF */


OSSEC home | Main Index | Thread Index


OSSEC project: www.ossec.net.
Mailling list information: http://www.ossec.net/en/mailing_lists.html.