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

[ossec-dev] ossec-hids: wait_op.c (NEW) file_op.c (HEAD) mem_op.c (HEAD) mq_op.c (HEAD) read-agents.c (HEAD) regex_op.c (HEAD) validate_op.c (HEAD) [dcid]



Module name:	ossec-hids
Changes by:	dcid	06/08/29 16:35:43

Modified files:
	file_op.c mem_op.c mq_op.c read-agents.c regex_op.c validate_op.c
Added files:
	wait_op.c

Log message:
Description: More fixes for the client/server control. Added global ossec lock and some new rules..
Reviewed by: dcid
Bug:

--- NEW FILE: wait_op.c ---
/* @(#) $Id: wait_op.c,v 1.1 2006/08/29 19:35:43 dcid Exp $ */

/* Copyright (C) 2006 Daniel B. Cid <dcid@xxxxxxxxx>
 * All rights reserved.
 *
 * This program is a free software; you can redistribute it
 * and/or modify it under the terms of the GNU General Public
 * License (version 2) as published by the FSF - Free Software
 * Foundation
 */


#include "shared.h"
#define LOCK_LOOP   5


/* Creates global lock */
void os_setwait()
{
    FILE *fp = NULL;
    if(isChroot())
    {
        fp = fopen(WAIT_FILE, "w");
    }
    else
    {
        fp = fopen(WAIT_FILE_PATH, "w");
    }

    if(fp)
    {
        fprintf(fp, "l");
        fclose(fp);
    }

    return;
}


/* Removes global lock */
void os_delwait()
{
    if(isChroot())
    {
        unlink(WAIT_FILE);
    }
    else
    {
        unlink(WAIT_FILE_PATH);
    }
    return;
}



/* Check for the wait file. If present, wait.
 * Works as a simple inter process lock (only the main
 * process is allowed to lock).
 */
void os_wait()
{
    struct stat file_status;
    
    /* If the wait file is not present, keep going.
     */
    if(isChroot())
    {
        if(stat(WAIT_FILE, &file_status) == -1)
            return;
    }
    else
    {
        if(stat(WAIT_FILE_PATH, &file_status) == -1)
            return;
    }
    

    /* Wait until the lock is gone. */
    verbose(WAITING_MSG, __local_name);
    while(1)
    {
        if(isChroot())
        {
            if(stat(WAIT_FILE, &file_status) == -1)
                break;
        }
        else
        {
            if(stat(WAIT_FILE_PATH, &file_status) == -1)
                break;
        }

        /* Sleep LOCK_LOOP seconds and check it lock is gone. */
        sleep(LOCK_LOOP);
    }

    verbose(WAITING_FREE, __local_name);
    return;
}



/* EOF */

Index: file_op.c
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/shared/file_op.c,v
diff -u -r1.14 -r1.15
--- file_op.c	13 Jul 2006 19:38:06 -0000	1.14
+++ file_op.c	29 Aug 2006 19:35:43 -0000	1.15
@@ -1,6 +1,6 @@
-/*      $OSSEC, file_op.c, v0.2, 2004/08/03, Daniel B. Cid$      */
+/* @(#) $Id$ */
 
-/* Copyright (C) 2004 Daniel B. Cid <dcid@xxxxxxxxx>
+/* Copyright (C) 2004-2006 Daniel B. Cid <dcid@xxxxxxxxx>
  * All rights reserved.
  *
  * This program is a free software; you can redistribute it
@@ -9,9 +9,6 @@
  * Foundation
  */
 
-/* Part of the OSSEC HIDS.
- * Available at http://www.ossec.net/hids/
- */
 
 /* Functions to handle operation with files 
  */

Index: mem_op.c
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/shared/mem_op.c,v
diff -u -r1.1.1.1 -r1.2
--- mem_op.c	23 Sep 2005 15:10:03 -0000	1.1.1.1
+++ mem_op.c	29 Aug 2006 19:35:43 -0000	1.2
@@ -1,6 +1,6 @@
-/*   $OSSEC, mem_op.c, v0.1, 2005/04/05, Daniel B. Cid$   */
+/* @(#) $Id$ */
 
-/* Copyright (C) 2005 Daniel B. Cid <dcid@xxxxxxxxx>
+/* Copyright (C) 2005,2006 Daniel B. Cid <dcid@xxxxxxxxx>
  * All rights reserved.
  *
  * This program is a free software; you can redistribute it

Index: mq_op.c
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/shared/mq_op.c,v
diff -u -r1.17 -r1.18
--- mq_op.c	10 May 2006 00:22:07 -0000	1.17
+++ mq_op.c	29 Aug 2006 19:35:43 -0000	1.18
@@ -1,6 +1,6 @@
-/*      $OSSEC, mq_op.c, v0.2, 2005/02/15, Daniel B. Cid$      */
+/* @(#) $Id$ */
 
-/* Copyright (C) 2004 Daniel B. Cid <dcid@xxxxxxxxx>
+/* Copyright (C) 2004-2006 Daniel B. Cid <dcid@xxxxxxxxx>
  * All rights reserved.
  *
  * This program is a free software; you can redistribute it
@@ -82,6 +82,11 @@
 
     tmpstr[OS_MAXSTR] = '\0';
 
+
+    /* Checking for global locks */
+    os_wait();
+    
+    
     if(loc == SECURE_MQ)
     {
         loc = message[0];

Index: read-agents.c
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/shared/read-agents.c,v
diff -u -r1.1 -r1.2
--- read-agents.c	28 Aug 2006 18:45:28 -0000	1.1
+++ read-agents.c	29 Aug 2006 19:35:43 -0000	1.2
@@ -50,7 +50,7 @@
     if(!dp) 
     {
         merror("%s: Error opening directory: '%s': %s ",
-                ARGV0,
+                __local_name,
                 AGENTINFO_DIR,
                 strerror(errno));
         return(NULL);
@@ -92,7 +92,7 @@
         f_files = (char **)realloc(f_files, (f_size +2) * sizeof(char *));
         if(!f_files)
         {
-            ErrorExit(MEM_ERROR,ARGV0);
+            ErrorExit(MEM_ERROR, __local_name);
         }
 
         os_strdup(entry->d_name, f_files[f_size]);

Index: regex_op.c
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/shared/regex_op.c,v
diff -u -r1.7 -r1.8
--- regex_op.c	5 Apr 2006 01:25:36 -0000	1.7
+++ regex_op.c	29 Aug 2006 19:35:43 -0000	1.8
@@ -1,6 +1,6 @@
-/*      $OSSEC, regex_op.c, v0.1, 2005/10/02, Daniel B. Cid$      */
+/* @(#) $Id$ */
 
-/* Copyright (C) 2005 Daniel B. Cid <dcid@xxxxxxxxx>
+/* Copyright (C) 2005,2006 Daniel B. Cid <dcid@xxxxxxxxx>
  * All rights reserved.
  *
  * This program is a free software; you can redistribute it

Index: validate_op.c
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/shared/validate_op.c,v
diff -u -r1.15 -r1.16
--- validate_op.c	11 Aug 2006 14:31:23 -0000	1.15
+++ validate_op.c	29 Aug 2006 19:35:43 -0000	1.16
@@ -741,7 +741,7 @@
 
         if(!days[i])
         {
-            merror(INVALID_DAY, ARGV0, day_str);
+            merror(INVALID_DAY, __local_name, day_str);
             return(NULL);
         }
         
@@ -756,7 +756,7 @@
             break;
         else
         {
-            merror(INVALID_DAY, ARGV0, day_str);
+            merror(INVALID_DAY, __local_name, day_str);
             return(NULL);
         }
     }
@@ -782,7 +782,7 @@
     if(ng == 0)
     {
         free(ret);
-        merror(INVALID_DAY, ARGV0, day_str);
+        merror(INVALID_DAY, __local_name, day_str);
         return(NULL);
     }
     


OSSEC home | Main Index | Thread Index


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