[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ossec-cvs] ossec-hids: config.c (NEW) db_op.c (NEW) db_op.h (NEW) dbd.h (NEW) rules.c (NEW) [dcid]
- To: ossec-cvs@xxxxxxxxx
- Subject: [ossec-cvs] ossec-hids: config.c (NEW) db_op.c (NEW) db_op.h (NEW) dbd.h (NEW) rules.c (NEW) [dcid]
- From: OSSEC CVS <cvs-commit@xxxxxxxxx>
- Date: Sun, 12 Aug 2007 23:14:19 -0300 (ADT)
- Content-transfer-encoding: 8bit
Module name: ossec-hids
Changes by: dcid 07/08/12 23:14:16
Added files:
config.c db_op.c db_op.h dbd.h rules.c
Log message:
Description: Adding new ossec_dbd daemon. Yes, yes, I got convinced :)
--- NEW FILE: config.c ---
/* @(#) $Id: config.c,v 1.1 2007/08/13 02:14:16 dcid Exp $ */
/* Copyright (C) 2003-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 3) as published by the FSF - Free Software
* Foundation
*/
#include "dbd.h"
#include "config/global-config.h"
#include "config/config.h"
int OS_ReadDBConf(int test_config, char *cfgfile, DBConfig *db_config)
{
int modules = 0;
_Config *tmp_config;
/* Modules for the configuration */
modules|= CDBD;
modules|= CRULES;
/* Allocating config just to get the rules. */
os_calloc(1, sizeof(_Config), tmp_config);
/* Clearing configuration variables */
tmp_config->includes = NULL;
db_config->includes = NULL;
db_config->host = NULL;
db_config->user = NULL;
db_config->pass = NULL;
db_config->db = NULL;
/* Reading configuration */
if(ReadConfig(modules, cfgfile, tmp_config, db_config) < 0)
return(OS_INVALID);
/* Here, we assign the rules to db_config and free the rest
* of the Config.
*/
db_config->includes = tmp_config->includes;
free(tmp_config);
return(0);
}
/* EOF */
--- NEW FILE: db_op.c ---
/* @(#) $Id: db_op.c,v 1.1 2007/08/13 02:14:16 dcid Exp $ */
/* Copyright (C) 2003-2007 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 3) as published by the FSF - Free Software
* Foundation.
*
* License details at the LICENSE file included with OSSEC or
* online at: http://www.ossec.net/en/licensing.html
*/
/* Common lib for dealing with databases */
#ifdef DBD
#include "shared.h"
/* Using Mysql */
#ifdef UMYSQL
#include <mysql.h>
#endif
/* Create the tree
* Return NULL on error
*/
void *osdb_connect(char *host, char *user, char *pass, char *db)
{
MYSQL *conn;
conn = mysql_init(NULL);
if (conn == NULL)
{
merror(DBINIT_ERROR, ARGV0);
return(NULL);
}
if(mysql_real_connect(conn, host, user, pass, db, 0, NULL, 0) == NULL)
{
merror(DBCONN_ERROR, ARGV0, host, db, mysql_error(conn));
mysql_close(conn);
return(NULL);
}
return(conn);
}
void osdb_close(void *db_conn)
{
mysql_close(db_conn);
}
int osdb_query(void *db_conn, char *query)
{
if(mysql_query(db_conn, query) != 0)
{
/* failure; report error */
merror(DBQUERY_ERROR, ARGV0, query, mysql_error(db_conn));
return(0);
}
return(1);
}
#endif /* DBD */
/* EOF */
--- NEW FILE: db_op.h ---
/* @(#) $Id: db_op.h,v 1.1 2007/08/13 02:14:16 dcid Exp $ */
/* Copyright (C) 2003-2007 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 3) as published by the FSF - Free Software
* Foundation.
*
* License details at the LICENSE file included with OSSEC or
* online at: http://www.ossec.net/en/licensing.html
*/
/* Common API for dealing with databases */
#ifndef _OS_DBOP_H
#define _OS_DBOP_H
/* Connects to the database */
void *osdb_connect(char *host, char *user, char *pass, char *db);
int osdb_query(void *db_conn, char *query);
#endif
/* EOF */
--- NEW FILE: dbd.h ---
/* @(#) $Id: dbd.h,v 1.1 2007/08/13 02:14:16 dcid Exp $ */
/* Copyright (C) 2003-2007 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 3) as published by the FSF - Free Software
* Foundation.
*
* License details at the LICENSE file included with OSSEC or
* online at: http://www.ossec.net/en/licensing.html
*/
#ifndef _DBD_H
#define _DBD_H
#include "shared.h"
#include "db_op.h"
#include "config/dbd-config.h"
/** Prototypes **/
/* Read database config */
int OS_ReadDBConf(int test_config, char *cfgfile, DBConfig *db_config);
/* Insert rules in to the database */
int OS_InsertRulesDB(DBConfig *db_config);
/* Database inserting main function */
void OS_DBD(DBConfig *db_config);
#endif
--- NEW FILE: rules.c ---
/* @(#) $Id: rules.c,v 1.1 2007/08/13 02:14:16 dcid Exp $ */
/* Copyright (C) 2003-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 3) as published by the FSF - Free Software
* Foundation
*/
#include "dbd.h"
#include "config/config.h"
#include "rules_op.h"
void *_Rules_ReadInsertDB(RuleInfo *rule, void *db_config)
{
DBConfig *dbc = (DBConfig *)db_config;
char sql_query[OS_SIZE_1024];
memset(sql_query, '\0', OS_SIZE_1024);
merror("XXX inserting: %d", rule->sigid);
/* Generating SQL */
snprintf(sql_query, OS_SIZE_1024 -1,
"INSERT INTO "
"signature(id, rule_id, level, category, description) "
"VALUES (NULL, '%u','%u','%s','%s') "
"ON DUPLICATE KEY UPDATE level='%u'",
rule->sigid, rule->level, rule->group, rule->comment,
rule->level);
if(!osdb_query(dbc->conn, sql_query))
{
merror(DB_MAINERROR, ARGV0);
}
return(NULL);
}
int OS_InsertRulesDB(DBConfig *db_config)
{
char **rulesfiles;
rulesfiles = db_config->includes;
while(rulesfiles && *rulesfiles)
{
debug1("%s: Reading rules file: '%s'", ARGV0, *rulesfiles);
if(OS_ReadXMLRules(*rulesfiles, _Rules_ReadInsertDB, db_config) < 0)
{
merror(RULES_ERROR, ARGV0, *rulesfiles);
return(-1);
}
free(*rulesfiles);
rulesfiles++;
}
free(db_config->includes);
db_config->includes = NULL;
return(0);
}
/* EOF */
OSSEC home |
Main Index |
Thread Index
OSSEC project: www.ossec.net.
Mailling list information: http://www.ossec.net/en/mailing_lists.html.