Imported Upstream version 2.7
[ossec-hids.git] / src / rootcheck / os_string.c
index a3ad59a..069f5bd 100755 (executable)
@@ -1,9 +1,10 @@
-/* @(#) $Id$ */
+/* @(#) $Id: ./src/rootcheck/os_string.c, 2011/09/08 dcid Exp $
+ */
 
 /* Included and modified strings.c from the OpenBSD project.
  * Copyright bellow.
  */
+
 /*
  * Copyright (c) 1980, 1987, 1993
  *     The Regents of the University of California.  All rights reserved.
@@ -135,9 +136,9 @@ struct exec
 
 
 #ifdef AIX
-typedef struct aouthdr EXEC;    
+typedef struct aouthdr EXEC;
 #else
-typedef struct exec EXEC;    
+typedef struct exec EXEC;
 #endif
 
 typedef struct _os_strings
@@ -161,25 +162,25 @@ int os_getch(os_strings *oss);
 int os_string(char *file, char *regex)
 {
     int ch, cnt;
-    
+
     unsigned char *C;
     unsigned char *bfr;
+
     char line[OS_SIZE_1024 +1];
     char *buf;
-    
+
     EXEC *head;
 
     os_strings oss;
-   
+
     /* Return didn't match */
     if(!file || !regex)
     {
         return(0);
     }
-    
-    
-    /* Allocating for the buffer */ 
+
+
+    /* Allocating for the buffer */
     bfr = calloc(STR_MINLEN + 2, sizeof(char *));
     if (!bfr)
     {
@@ -197,21 +198,21 @@ int os_string(char *file, char *regex)
 
     /* cleaning the line */
     memset(line, '\0', OS_SIZE_1024 +1);
-    
+
     /* starting .. (from old strings.c) */
     oss.foff = 0;
     oss.head_len = 0;
-    
+
     oss.read_len = -1;
     head = (EXEC *)oss.hbfr;
 
-    
+
     if ((oss.head_len = read(fileno(oss.fp), head, sizeof(EXEC))) == -1)
     {
         oss.head_len = 0;
         oss.read_len = -1;
     }
-    else if (oss.head_len == sizeof(EXEC) && !N_BADMAG(*head)) 
+    else if (oss.head_len == sizeof(EXEC) && !N_BADMAG(*head))
     {
         oss.foff = N_TXTOFF(*head);
         if (fseek(stdin, oss.foff, SEEK_SET) == -1)
@@ -235,20 +236,20 @@ int os_string(char *file, char *regex)
     }
 
     /* Read the file and perform the regex comparison */
-    for (cnt = 0; (ch = os_getch(&oss)) != EOF;) 
+    for (cnt = 0; (ch = os_getch(&oss)) != EOF;)
     {
-        if (ISSTR(ch)) 
+        if (ISSTR(ch))
         {
             if (!cnt)
                 C = bfr;
             *C++ = ch;
             if (++cnt < STR_MINLEN)
                 continue;
-            
+
             strncpy(line, (char *)bfr, STR_MINLEN +1);
             buf = line;
             buf+=strlen(line);
-            
+
 
             while ((ch = os_getch(&oss)) != EOF && ISSTR(ch))
             {
@@ -293,7 +294,7 @@ int os_string(char *file, char *regex)
 int os_getch(os_strings *oss)
 {
        ++oss->foff;
-       if (oss->head_len) 
+       if (oss->head_len)
     {
                if (oss->hcnt < oss->head_len)
                        return((int)oss->hbfr[oss->hcnt++]);