|
Packit Service |
5e8d2a |
/* aide, Advanced Intrusion Detection Environment
|
|
Packit Service |
5e8d2a |
* vi: ts=2 sw=2
|
|
Packit Service |
5e8d2a |
*
|
|
Packit Service |
5e8d2a |
* Copyright (C) 1999-2006,2010,2011,2016 Rami Lehti, Pablo Virolainen,
|
|
Packit Service |
5e8d2a |
* Richard van den Berg, Mike Markley, Hannes von Haugwitz
|
|
Packit Service |
5e8d2a |
* $Header$
|
|
Packit Service |
5e8d2a |
*
|
|
Packit Service |
5e8d2a |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
5e8d2a |
* modify it under the terms of the GNU General Public License as
|
|
Packit Service |
5e8d2a |
* published by the Free Software Foundation; either version 2 of the
|
|
Packit Service |
5e8d2a |
* License, or (at your option) any later version.
|
|
Packit Service |
5e8d2a |
*
|
|
Packit Service |
5e8d2a |
* This program is distributed in the hope that it will be useful, but
|
|
Packit Service |
5e8d2a |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
5e8d2a |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
5e8d2a |
* General Public License for more details.
|
|
Packit Service |
5e8d2a |
*
|
|
Packit Service |
5e8d2a |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
5e8d2a |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
5e8d2a |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
#include "aide.h"
|
|
Packit Service |
5e8d2a |
#ifndef _POSIX_C_SOURCE
|
|
Packit Service |
5e8d2a |
# define _POSIX_C_SOURCE 199506L
|
|
Packit Service |
5e8d2a |
#endif
|
|
Packit Service |
5e8d2a |
#include <unistd.h>
|
|
Packit Service |
5e8d2a |
#include <stdio.h>
|
|
Packit Service |
5e8d2a |
#include <string.h>
|
|
Packit Service |
5e8d2a |
#include <sys/stat.h>
|
|
Packit Service |
5e8d2a |
#include <stdlib.h>
|
|
Packit Service |
5e8d2a |
#include <time.h>
|
|
Packit Service |
5e8d2a |
#include <dirent.h>
|
|
Packit Service |
5e8d2a |
#include <limits.h>
|
|
Packit Service |
5e8d2a |
#include <errno.h>
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
#include "seltree.h"
|
|
Packit Service |
5e8d2a |
#include "gen_list.h"
|
|
Packit Service |
5e8d2a |
#include "types.h"
|
|
Packit Service |
5e8d2a |
#include "base64.h"
|
|
Packit Service |
5e8d2a |
#include "db_disk.h"
|
|
Packit Service |
5e8d2a |
#include "conf_yacc.h"
|
|
Packit Service |
5e8d2a |
#include "util.h"
|
|
Packit Service |
5e8d2a |
#include "commandconf.h"
|
|
Packit Service |
5e8d2a |
/*for locale support*/
|
|
Packit Service |
5e8d2a |
#include "locale-aide.h"
|
|
Packit Service |
5e8d2a |
/*for locale support*/
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
#ifdef WITH_MHASH
|
|
Packit Service |
5e8d2a |
#include <mhash.h>
|
|
Packit Service |
5e8d2a |
#endif
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
#ifdef WITH_ZLIB
|
|
Packit Service |
5e8d2a |
#include <zlib.h>
|
|
Packit Service |
5e8d2a |
#endif
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
static DIR *dirh = NULL;
|
|
Packit Service |
5e8d2a |
static struct AIDE_DIRENT_TYPE *entp = NULL;
|
|
Packit Service |
5e8d2a |
static struct AIDE_DIRENT_TYPE **resp = NULL;
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
static struct seltree *r = NULL;
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
#if defined HAVE_READDIR && !defined HAVE_READDIR_R
|
|
Packit Service |
5e8d2a |
static long td = -1;
|
|
Packit Service |
5e8d2a |
#endif
|
|
Packit Service |
5e8d2a |
static int rdres = 0;
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
static int root_handled = 0;
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
static DIR *open_dir(char* path) {
|
|
Packit Service |
5e8d2a |
if (dirh != NULL) {
|
|
Packit Service |
5e8d2a |
if (closedir(dirh) != 0) {
|
|
Packit Service |
5e8d2a |
/* Closedir did not success? */
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
return opendir(path);
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
static void next_in_dir (void)
|
|
Packit Service |
5e8d2a |
{
|
|
Packit Service |
c89282 |
|
|
Packit Service |
5e8d2a |
#ifdef HAVE_READDIR_R
|
|
Packit Service |
c89282 |
if (dirh != NULL) {
|
|
Packit Service |
c89282 |
#pragma GCC diagnostic push
|
|
Packit Service |
c89282 |
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
Packit Service |
5e8d2a |
rdres = AIDE_READDIR_R_FUNC (dirh, entp, resp);
|
|
Packit Service |
c89282 |
#pragma GCC diagnostic pop
|
|
Packit Service |
c89282 |
}
|
|
Packit Service |
c89282 |
|
|
Packit Service |
5e8d2a |
#else
|
|
Packit Service |
5e8d2a |
#ifdef HAVE_READDIR
|
|
Packit Service |
5e8d2a |
if (dirh != NULL) {
|
|
Packit Service |
5e8d2a |
entp = AIDE_READDIR_FUNC (dirh);
|
|
Packit Service |
5e8d2a |
if(entp!=NULL)
|
|
Packit Service |
5e8d2a |
td = telldir(dirh);
|
|
Packit Service |
5e8d2a |
else
|
|
Packit Service |
5e8d2a |
td=-1;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
#endif
|
|
Packit Service |
5e8d2a |
#endif
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
static int in_this (void)
|
|
Packit Service |
5e8d2a |
{
|
|
Packit Service |
5e8d2a |
#ifdef HAVE_READDIR_R
|
|
Packit Service |
5e8d2a |
return (dirh != NULL && rdres == 0 && (*resp) != NULL);
|
|
Packit Service |
5e8d2a |
#else
|
|
Packit Service |
5e8d2a |
#ifdef HAVE_READDIR
|
|
Packit Service |
5e8d2a |
return (dirh != NULL && entp != NULL && td >= 0);
|
|
Packit Service |
5e8d2a |
#endif
|
|
Packit Service |
5e8d2a |
#endif
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
static char *name_construct (const char *s)
|
|
Packit Service |
5e8d2a |
{
|
|
Packit Service |
5e8d2a |
char *ret;
|
|
Packit Service |
5e8d2a |
int len2 = strlen (r->path);
|
|
Packit Service |
5e8d2a |
int len = len2 + strlen (s) + 2 + conf->root_prefix_length;
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
if (r->path[len2 - 1] != '/') {
|
|
Packit Service |
5e8d2a |
len++;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
ret = (char *) malloc (len);
|
|
Packit Service |
5e8d2a |
ret[0] = (char) 0;
|
|
Packit Service |
5e8d2a |
strncpy(ret, conf->root_prefix, conf->root_prefix_length+1);
|
|
Packit Service |
5e8d2a |
strncat (ret, r->path, len2);
|
|
Packit Service |
5e8d2a |
if (r->path[len2 - 1] != '/') {
|
|
Packit Service |
5e8d2a |
strncat (ret, "/", 1);
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
strcat (ret, s);
|
|
Packit Service |
5e8d2a |
return ret;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
void add_child (db_line * fil)
|
|
Packit Service |
5e8d2a |
{
|
|
Packit Service |
5e8d2a |
int i;
|
|
Packit Service |
5e8d2a |
struct seltree *new_r;
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
error (255, "Adding child %s\n", fil->filename);
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
new_r = get_seltree_node (r, fil->filename);
|
|
Packit Service |
5e8d2a |
if (new_r != NULL) {
|
|
Packit Service |
5e8d2a |
if (S_ISDIR (fil->perm_o)) {
|
|
Packit Service |
5e8d2a |
;
|
|
Packit Service |
5e8d2a |
} else {
|
|
Packit Service |
5e8d2a |
new_r->checked |= NODE_CHECKED;
|
|
Packit Service |
5e8d2a |
new_r->checked |= NODE_TRAVERSE;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
return;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
new_r = malloc (sizeof (seltree));
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
new_r->attr = 0;
|
|
Packit Service |
5e8d2a |
i = strlen (fil->filename);
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
new_r->path = malloc (i + 1);
|
|
Packit Service |
5e8d2a |
strncpy(new_r->path, fil->filename, i+1);
|
|
Packit Service |
5e8d2a |
new_r->childs = NULL;
|
|
Packit Service |
5e8d2a |
new_r->sel_rx_lst = NULL;
|
|
Packit Service |
5e8d2a |
new_r->neg_rx_lst = NULL;
|
|
Packit Service |
5e8d2a |
new_r->equ_rx_lst = NULL;
|
|
Packit Service |
5e8d2a |
new_r->parent = r;
|
|
Packit Service |
5e8d2a |
new_r->checked = 0;
|
|
Packit Service |
5e8d2a |
new_r->new_data = NULL;
|
|
Packit Service |
5e8d2a |
new_r->old_data = NULL;
|
|
Packit Service |
5e8d2a |
if (S_ISDIR (fil->perm_o)) {
|
|
Packit Service |
5e8d2a |
;
|
|
Packit Service |
5e8d2a |
} else {
|
|
Packit Service |
5e8d2a |
new_r->checked |= NODE_CHECKED;
|
|
Packit Service |
5e8d2a |
new_r->checked |= NODE_TRAVERSE;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
r->childs = list_sorted_insert (r->childs, new_r, compare_node_by_path);
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
static int get_file_status(char *filename, struct AIDE_STAT_TYPE *fs) {
|
|
Packit Service |
5e8d2a |
int sres = 0;
|
|
Packit Service |
5e8d2a |
sres = AIDE_LSTAT_FUNC(filename,fs);
|
|
Packit Service |
5e8d2a |
if(sres == -1){
|
|
Packit Service |
5e8d2a |
char* er = strerror(errno);
|
|
Packit Service |
5e8d2a |
if (er == NULL) {
|
|
Packit Service |
5e8d2a |
error(0,"get_file_status: lstat() failed for %s. strerror() failed for %i\n", filename, errno);
|
|
Packit Service |
5e8d2a |
} else {
|
|
Packit Service |
5e8d2a |
error(0,"get_file_status: lstat() failed for %s: %s\n", filename, er);
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
return sres;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
/*
|
|
Packit Service |
5e8d2a |
It might be a good idea to make this non recursive.
|
|
Packit Service |
5e8d2a |
Now implemented with goto-statement. Yeah, it's ugly and easy.
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
db_line *db_readline_disk ()
|
|
Packit Service |
5e8d2a |
{
|
|
Packit Service |
5e8d2a |
db_line *fil = NULL;
|
|
Packit Service |
5e8d2a |
DB_ATTR_TYPE attr;
|
|
Packit Service |
5e8d2a |
char *fullname;
|
|
Packit Service |
5e8d2a |
int add = 0;
|
|
Packit Service |
5e8d2a |
struct AIDE_STAT_TYPE fs;
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
/* root needs special handling */
|
|
Packit Service |
5e8d2a |
if (!root_handled) {
|
|
Packit Service |
5e8d2a |
root_handled = 1;
|
|
Packit Service |
5e8d2a |
fullname=malloc((conf->root_prefix_length+2)*sizeof(char));
|
|
Packit Service |
5e8d2a |
strncpy(fullname, conf->root_prefix, conf->root_prefix_length+1);
|
|
Packit Service |
5e8d2a |
strncat (fullname, "/", 1);
|
|
Packit Service |
5e8d2a |
if (!get_file_status(&fullname[conf->root_prefix_length], &fs)) {
|
|
Packit Service |
5e8d2a |
add = check_rxtree (&fullname[conf->root_prefix_length], conf->tree, &attr, fs.st_mode);
|
|
Packit Service |
5e8d2a |
error (240, "%s match=%d, tree=%p, attr=%llu\n", &fullname[conf->root_prefix_length], add,
|
|
Packit Service |
5e8d2a |
conf->tree, attr);
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
if (add > 0) {
|
|
Packit Service |
5e8d2a |
fil = get_file_attrs (fullname, attr, &fs);
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
error (240, "%s attr=%llu\n", &fullname[conf->root_prefix_length], attr);
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
if (fil != NULL) {
|
|
Packit Service |
5e8d2a |
error (240, "%s attr=%llu\n", fil->filename, fil->attr);
|
|
Packit Service |
5e8d2a |
return fil;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
free (fullname);
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
recursion:
|
|
Packit Service |
5e8d2a |
next_in_dir ();
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
if (in_this ()) {
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
/*
|
|
Packit Service |
5e8d2a |
Let's check if we have '.' or '..' entry.
|
|
Packit Service |
5e8d2a |
If have, just skipit.
|
|
Packit Service |
5e8d2a |
If don't do the 'normal' thing.
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
if (strcmp (entp->d_name, ".") == 0 || strcmp (entp->d_name, "..") == 0) {
|
|
Packit Service |
5e8d2a |
goto recursion; // return db_readline_disk(db);
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
/*
|
|
Packit Service |
5e8d2a |
Now we know that we actually can do something.
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
fullname = name_construct (entp->d_name);
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
/*
|
|
Packit Service |
5e8d2a |
Now we have a filename, which we must remember to free if it is
|
|
Packit Service |
5e8d2a |
not used.
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
Next thing is to see if we want to do something with it.
|
|
Packit Service |
5e8d2a |
If not call, db_readline_disk again...
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
if (get_file_status(&fullname[conf->root_prefix_length], &fs)) {
|
|
Packit Service |
5e8d2a |
free (fullname);
|
|
Packit Service |
5e8d2a |
goto recursion;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
add = check_rxtree (&fullname[conf->root_prefix_length], conf->tree, &attr, fs.st_mode);
|
|
Packit Service |
5e8d2a |
error (240, "%s match=%d, tree=%p, attr=%llu\n", &fullname[conf->root_prefix_length], add,
|
|
Packit Service |
5e8d2a |
conf->tree, attr);
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
if (add > 0) {
|
|
Packit Service |
5e8d2a |
fil = get_file_attrs (fullname, attr, &fs);
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
error (240, "%s attr=%llu\n", &fullname[conf->root_prefix_length], attr);
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
if (fil != NULL) {
|
|
Packit Service |
5e8d2a |
error (240, "%s attr=%llu\n", fil->filename, fil->attr);
|
|
Packit Service |
5e8d2a |
} else {
|
|
Packit Service |
5e8d2a |
/*
|
|
Packit Service |
5e8d2a |
Something went wrong during read process ->
|
|
Packit Service |
5e8d2a |
Let's try next one.
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
free (fullname);
|
|
Packit Service |
5e8d2a |
goto recursion; // return db_readline_disk(db);
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
if (add == 1) {
|
|
Packit Service |
5e8d2a |
/*
|
|
Packit Service |
5e8d2a |
add_children -> if dir, then add to children list.
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
/* If ee are adding a file that is not a dir */
|
|
Packit Service |
5e8d2a |
/* add_child can make the determination and mark the tree
|
|
Packit Service |
5e8d2a |
accordingly
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
add_child (fil);
|
|
Packit Service |
5e8d2a |
} else if (add == 2) {
|
|
Packit Service |
5e8d2a |
/*
|
|
Packit Service |
5e8d2a |
Don't add to children list.
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
/*
|
|
Packit Service |
5e8d2a |
Should we do something?
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
} else {
|
|
Packit Service |
5e8d2a |
/*
|
|
Packit Service |
5e8d2a |
Make us traverse the tree:)
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
/*
|
|
Packit Service |
5e8d2a |
We have no use for fullname.
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
free (fullname);
|
|
Packit Service |
5e8d2a |
goto recursion;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
/*
|
|
Packit Service |
5e8d2a |
Make sure that next time we enter
|
|
Packit Service |
5e8d2a |
we have something.
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
} else {
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
if (r == NULL) {
|
|
Packit Service |
5e8d2a |
return NULL;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
error (255, "r->childs %p, r->parent %p, r->checked %i\n", r->childs,
|
|
Packit Service |
5e8d2a |
r->parent, r->checked);
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
if ((0 == (r->checked & NODE_CHECKED)) && r->childs != NULL) {
|
|
Packit Service |
5e8d2a |
seltree *rr;
|
|
Packit Service |
5e8d2a |
list *l;
|
|
Packit Service |
5e8d2a |
l = r->childs->header->head;
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
while (l != NULL
|
|
Packit Service |
5e8d2a |
&& (((seltree *) (l->data))->checked & NODE_TRAVERSE) != 0) {
|
|
Packit Service |
5e8d2a |
l = l->next;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
if (l != NULL) {
|
|
Packit Service |
5e8d2a |
if (l == l->header->tail) {
|
|
Packit Service |
5e8d2a |
r->checked |= NODE_CHECKED;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
rr = (seltree *) l->data;
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
error (255, "rr->checked %i\n", rr->checked);
|
|
Packit Service |
5e8d2a |
rr->checked |= NODE_TRAVERSE;
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
r = rr;
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
error (255, "r->childs %p, r->parent %p,r->checked %i\n",
|
|
Packit Service |
5e8d2a |
r->childs, r->parent, r->checked);
|
|
Packit Service |
5e8d2a |
fullname=malloc((conf->root_prefix_length+strlen(r->path)+1)*sizeof(char));
|
|
Packit Service |
5e8d2a |
strncpy(fullname, conf->root_prefix, conf->root_prefix_length+1);
|
|
Packit Service |
5e8d2a |
strncat(fullname, r->path, strlen(r->path));
|
|
Packit Service |
5e8d2a |
dirh=open_dir(fullname);
|
|
Packit Service |
5e8d2a |
if (! dirh) {
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
/* open_dir failed so we need to know why and print
|
|
Packit Service |
5e8d2a |
an errormessage if needed.
|
|
Packit Service |
5e8d2a |
errno should still be the one from opendir() since it's global
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
if (errno == ENOENT && r->old_data != NULL &&
|
|
Packit Service |
5e8d2a |
r->sel_rx_lst == NULL && r->neg_rx_lst == NULL &&
|
|
Packit Service |
5e8d2a |
r->equ_rx_lst == NULL) {
|
|
Packit Service |
5e8d2a |
/* The path did not exist and there is old data for this node
|
|
Packit Service |
5e8d2a |
and there are no regexps for this node
|
|
Packit Service |
5e8d2a |
There is no new data for this node otherwise it would not
|
|
Packit Service |
5e8d2a |
come to this part of the code.
|
|
Packit Service |
5e8d2a |
So we don't print any error message.
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
} else if (errno == ENOENT &&
|
|
Packit Service |
5e8d2a |
((r->sel_rx_lst != NULL || r->neg_rx_lst != NULL ||
|
|
Packit Service |
5e8d2a |
r->equ_rx_lst != NULL) || r->childs != NULL)) {
|
|
Packit Service |
5e8d2a |
/* The dir did not exist and there are regexps referring to
|
|
Packit Service |
5e8d2a |
this node or there are children to this node.
|
|
Packit Service |
5e8d2a |
The only way a nonexistent dirnode can have children is by
|
|
Packit Service |
5e8d2a |
having rules referring to them.
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
error (10,
|
|
Packit Service |
5e8d2a |
"There are rules referring to non-existent directory %s\n", fullname);
|
|
Packit Service |
5e8d2a |
} else if (errno != ENOTDIR) {
|
|
Packit Service |
5e8d2a |
/* We print the message unless it is "Not a directory". */
|
|
Packit Service |
5e8d2a |
char *er = strerror (errno);
|
|
Packit Service |
5e8d2a |
if (er != NULL) {
|
|
Packit Service |
5e8d2a |
error (3, "open_dir(): %s: %s\n", er, fullname);
|
|
Packit Service |
5e8d2a |
} else {
|
|
Packit Service |
5e8d2a |
error (3, "open_dir(): %i: %s\n", errno, fullname);
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
r->checked |= NODE_TRAVERSE | NODE_CHECKED;
|
|
Packit Service |
5e8d2a |
r = r->parent;
|
|
Packit Service |
5e8d2a |
error (255, "dropping back to parent\n");
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
free(fullname);
|
|
Packit Service |
5e8d2a |
} else {
|
|
Packit Service |
5e8d2a |
r->checked |= NODE_TRAVERSE | NODE_CHECKED;
|
|
Packit Service |
5e8d2a |
r = r->parent;
|
|
Packit Service |
5e8d2a |
/* We have gone out of the tree. This happens in some instances */
|
|
Packit Service |
5e8d2a |
if (r == NULL) {
|
|
Packit Service |
5e8d2a |
return NULL;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
error (255, "dropping back to parent\n");
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
goto recursion;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
if (r->parent != NULL) {
|
|
Packit Service |
5e8d2a |
/*
|
|
Packit Service |
5e8d2a |
Go back in time:)
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
r->checked |= NODE_CHECKED;
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
r = r->parent;
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
goto recursion;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
/*
|
|
Packit Service |
5e8d2a |
The end has been reached. Nothing to do.
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
return fil;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
int db_disk_init ()
|
|
Packit Service |
5e8d2a |
{
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
r = conf->tree;
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
# ifdef HAVE_READDIR_R
|
|
Packit Service |
5e8d2a |
resp = (struct AIDE_DIRENT_TYPE **)
|
|
Packit Service |
5e8d2a |
malloc (sizeof (struct AIDE_DIRENT_TYPE) + _POSIX_PATH_MAX);
|
|
Packit Service |
5e8d2a |
entp = (struct AIDE_DIRENT_TYPE *)
|
|
Packit Service |
5e8d2a |
malloc (sizeof (struct AIDE_DIRENT_TYPE) + _POSIX_PATH_MAX);
|
|
Packit Service |
5e8d2a |
# else
|
|
Packit Service |
5e8d2a |
# ifdef HAVE_READDIR
|
|
Packit Service |
5e8d2a |
/*
|
|
Packit Service |
5e8d2a |
Should we do something here?
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
# else
|
|
Packit Service |
5e8d2a |
# error AIDE needs readdir or readdir_r
|
|
Packit Service |
5e8d2a |
# endif
|
|
Packit Service |
5e8d2a |
# endif
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
char* fullname=malloc((conf->root_prefix_length+2)*sizeof(char));
|
|
Packit Service |
5e8d2a |
strncpy(fullname, conf->root_prefix, conf->root_prefix_length+1);
|
|
Packit Service |
5e8d2a |
strncat (fullname, "/", 1);
|
|
Packit Service |
5e8d2a |
dirh=open_dir(fullname);
|
|
Packit Service |
5e8d2a |
free(fullname);
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
return RETOK;
|
|
Packit Service |
5e8d2a |
}
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
/*
|
|
Packit Service |
5e8d2a |
We don't support writing to the pseudo-database disk, since we are'n a
|
|
Packit Service |
5e8d2a |
backup/restore software. Hence the functions db_writespec_disk,
|
|
Packit Service |
5e8d2a |
db_writeline_disk and db_close_disk aren't declared.
|
|
Packit Service |
5e8d2a |
*/
|
|
Packit Service |
5e8d2a |
|
|
Packit Service |
5e8d2a |
const char *aide_key_6 = CONFHMACKEY_06;
|
|
Packit Service |
5e8d2a |
const char *db_key_6 = DBHMACKEY_06;
|