Blame src/compare_db.c

Packit 762fc5
/* aide, Advanced Intrusion Detection Environment
Packit 762fc5
 *
Packit 762fc5
 * Copyright (C) 1999-2007,2010-2013,2015,2016 Rami Lehti, Pablo Virolainen,
Packit 762fc5
 * Richard van den Berg, Mike Markley, Hannes von Haugwitz
Packit 762fc5
 * $Id$
Packit 762fc5
 *
Packit 762fc5
 * This program is free software; you can redistribute it and/or
Packit 762fc5
 * modify it under the terms of the GNU General Public License as
Packit 762fc5
 * published by the Free Software Foundation; either version 2 of the
Packit 762fc5
 * License, or (at your option) any later version.
Packit 762fc5
 *
Packit 762fc5
 * This program is distributed in the hope that it will be useful, but
Packit 762fc5
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 762fc5
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Packit 762fc5
 * General Public License for more details.
Packit 762fc5
 *
Packit 762fc5
 * You should have received a copy of the GNU General Public License
Packit 762fc5
 * along with this program; if not, write to the Free Software
Packit 762fc5
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Packit 762fc5
 */
Packit 762fc5
Packit 762fc5
#include "aide.h"
Packit 762fc5
#include <stdlib.h>
Packit 762fc5
#include <string.h>
Packit 762fc5
#include <time.h>
Packit 762fc5
#include <sys/stat.h>
Packit 762fc5
#include <math.h>
Packit 762fc5
#ifdef WITH_AUDIT
Packit 762fc5
#include <libaudit.h>
Packit 762fc5
#ifdef HAVE_SYSLOG
Packit 762fc5
#include <syslog.h>
Packit 762fc5
#endif
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
#include "base64.h"
Packit 762fc5
#include "report.h"
Packit 762fc5
#include "db_config.h"
Packit 762fc5
#include "gen_list.h"
Packit 762fc5
#include "list.h"
Packit 762fc5
#include "db.h"
Packit 762fc5
#include "util.h"
Packit 762fc5
#include "commandconf.h"
Packit 762fc5
#include "gen_list.h"
Packit 762fc5
#include "compare_db.h"
Packit 762fc5
/*for locale support*/
Packit 762fc5
#include "locale-aide.h"
Packit 762fc5
/*for locale support*/
Packit 762fc5
Packit 762fc5
#include "md.h"
Packit 762fc5
Packit 762fc5
/*************/
Packit 762fc5
/* construction area for report lines */
Packit 762fc5
Packit 762fc5
const int width_details = 80;
Packit 762fc5
Packit 762fc5
const char time_format[] = "%Y-%m-%d %H:%M:%S %z";
Packit 762fc5
const int time_string_len = 26;
Packit 762fc5
Packit 762fc5
long ntotal, nadd, nrem, nchg = 0;
Packit 762fc5
Packit 762fc5
const char* report_top_format = "\n\n---------------------------------------------------\n%s:\n---------------------------------------------------\n";
Packit 762fc5
Packit 762fc5
DB_ATTR_TYPE ignored_added_attrs, ignored_removed_attrs, ignored_changed_attrs, forced_attrs;
Packit 762fc5
Packit 762fc5
const DB_ATTR_TYPE summary_attributes[] = { DB_FTYPE, DB_LINKNAME, DB_SIZE|DB_SIZEG, DB_BCOUNT, DB_PERM, DB_UID, DB_GID, DB_ATIME, DB_MTIME, DB_CTIME, DB_INODE, DB_LNKCOUNT, DB_HASHES
Packit 762fc5
#ifdef WITH_ACL
Packit 762fc5
        , DB_ACL
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_XATTR
Packit 762fc5
        , DB_XATTRS
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_SELINUX
Packit 762fc5
        , DB_SELINUX
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_E2FSATTRS
Packit 762fc5
        , DB_E2FSATTRS
Packit 762fc5
#endif
Packit 762fc5
};
Packit 762fc5
Packit 762fc5
const char summary_char[] = { '!' ,'l', '>', 'b', 'p', 'u', 'g', 'a', 'm', 'c', 'i', 'n', 'C'
Packit 762fc5
#ifdef WITH_ACL
Packit 762fc5
    , 'A'
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_XATTR
Packit 762fc5
    , 'X'
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_SELINUX
Packit 762fc5
    , 'S'
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_E2FSATTRS
Packit 762fc5
    , 'E'
Packit 762fc5
#endif
Packit 762fc5
};
Packit 762fc5
Packit 762fc5
const DB_ATTR_TYPE details_attributes[] = { DB_FTYPE, DB_LINKNAME, DB_SIZE, DB_SIZEG, DB_BCOUNT, DB_PERM, DB_UID, DB_GID, DB_ATIME, DB_MTIME, DB_CTIME, DB_INODE, DB_LNKCOUNT, DB_MD5, DB_SHA1, DB_RMD160, DB_TIGER, DB_SHA256, DB_SHA512
Packit 762fc5
#ifdef WITH_MHASH
Packit 762fc5
    , DB_CRC32, DB_HAVAL, DB_GOST, DB_CRC32B, DB_WHIRLPOOL
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_ACL
Packit 762fc5
        , DB_ACL
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_XATTR
Packit 762fc5
        , DB_XATTRS
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_SELINUX
Packit 762fc5
        , DB_SELINUX
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_E2FSATTRS
Packit 762fc5
        , DB_E2FSATTRS
Packit 762fc5
#endif
Packit 762fc5
};
Packit 762fc5
Packit Service b99ba9
const char* details_string[] = { _("File type") , _("Lname"), _("Size"), _("Size"), _("Bcount"), _("Perm"), _("Uid"), _("Gid"), _("Atime"), _("Mtime"), _("Ctime"), _("Inode"), _("Linkcount"), _("MD5"), _("SHA1"), _("RMD160"), _("TIGER"), _("SHA256"), _("SHA512")
Packit 762fc5
#ifdef WITH_MHASH
Packit 762fc5
    , _("CRC32"), _("HAVAL"), _("GOST"), _("CRC32B"), _("WHIRLPOOL")
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_ACL
Packit 762fc5
    , _("ACL")
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_XATTR
Packit 762fc5
    , _("XAttrs")
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_SELINUX
Packit 762fc5
    , _("SELinux")
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_E2FSATTRS
Packit 762fc5
    , _("E2FSAttrs")
Packit 762fc5
#endif
Packit 762fc5
};
Packit 762fc5
Packit 762fc5
const char* attrs_string[] = { "filename", "l", "p", "u", "g", "s", "a", "c", "m", "i", "b", "n",
Packit 762fc5
                               "md5", "sha1", "rmd160", "tiger", "crc32", "haval", "gost", "crc32b",
Packit 762fc5
                               "attr", "acl", "bsize", "rdev", "dev", "checkmask", "S", "I", "ANF",
Packit 762fc5
                               "ARF", "sha256", "sha512", "selinux", "xattrs", "whirlpool", "ftype",
Packit 762fc5
                               "e2fsattrs" };
Packit 762fc5
Packit 762fc5
#ifdef WITH_E2FSATTRS
Packit 762fc5
    /* flag->character mappings taken from lib/e2p/pf.c (git commit c46b57b)
Packit 762fc5
     * date: 2015-05-10
Packit 762fc5
     * sources: git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
Packit 762fc5
     *
Packit 762fc5
     * on update see also do_e2fsattrs in commandconf.c
Packit 762fc5
     */
Packit 762fc5
    unsigned long flag_bits[] = { EXT2_SECRM_FL, EXT2_UNRM_FL, EXT2_SYNC_FL, EXT2_DIRSYNC_FL, EXT2_IMMUTABLE_FL,
Packit 762fc5
        EXT2_APPEND_FL, EXT2_NODUMP_FL, EXT2_NOATIME_FL, EXT2_COMPR_FL, EXT2_COMPRBLK_FL,
Packit 762fc5
        EXT2_DIRTY_FL, EXT2_NOCOMPR_FL,
Packit 762fc5
#ifdef EXT2_ECOMPR_FL
Packit 762fc5
        EXT2_ECOMPR_FL,
Packit 762fc5
#else
Packit 762fc5
        EXT4_ENCRYPT_FL,
Packit 762fc5
#endif
Packit 762fc5
        EXT3_JOURNAL_DATA_FL, EXT2_INDEX_FL,
Packit 762fc5
        EXT2_NOTAIL_FL, EXT2_TOPDIR_FL
Packit 762fc5
#ifdef EXT4_EXTENTS_FL
Packit 762fc5
        , EXT4_EXTENTS_FL
Packit 762fc5
#endif
Packit 762fc5
#ifdef EXT4_HUGE_FILE_FL
Packit 762fc5
        , EXT4_HUGE_FILE_FL
Packit 762fc5
#endif
Packit 762fc5
#ifdef FS_NOCOW_FL
Packit 762fc5
    , FS_NOCOW_FL
Packit 762fc5
#endif
Packit 762fc5
#ifdef EXT4_INLINE_DATA_FL
Packit 762fc5
    , EXT4_INLINE_DATA_FL
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
    };
Packit 762fc5
    char flag_char[] = { 's', 'u', 'S', 'D', 'i', 'a', 'd', 'A', 'c', 'B', 'Z', 'X', 'E', 'j', 'I', 't', 'T'
Packit 762fc5
#ifdef EXT4_EXTENTS_FL
Packit 762fc5
    , 'e'
Packit 762fc5
#endif
Packit 762fc5
#ifdef EXT4_HUGE_FILE_FL
Packit 762fc5
    , 'h'
Packit 762fc5
#endif
Packit 762fc5
#ifdef FS_NOCOW_FL
Packit 762fc5
    , 'C'
Packit 762fc5
#endif
Packit 762fc5
#ifdef EXT4_INLINE_DATA_FL
Packit 762fc5
    , 'N'
Packit 762fc5
#endif
Packit 762fc5
    };
Packit 762fc5
/*************/
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
static DB_ATTR_TYPE get_special_report_group(char* group) {
Packit 762fc5
    DB_ATTR_TYPE attr = get_groupval(group);
Packit 762fc5
    return attr==DB_ATTR_UNDEF?0:attr;
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
static char* report_attrs(DB_ATTR_TYPE attrs) {
Packit 762fc5
    char* str;
Packit 762fc5
    int j = 1;
Packit 762fc5
    int num_attrs = sizeof(attrs_string)/sizeof(char*);
Packit 762fc5
    for (int i = 0; i < num_attrs; ++i) {
Packit 762fc5
        if ((1LLU<
Packit 762fc5
            j += strlen(attrs_string[i])+1;
Packit 762fc5
        }
Packit 762fc5
    }
Packit 762fc5
    str = malloc(j * sizeof (char));
Packit 762fc5
    j=0;
Packit 762fc5
    for (int i = 0; i < num_attrs; ++i) {
Packit 762fc5
        if ((1LLU<
Packit 762fc5
            if (j) { str[j++] = '+'; }
Packit 762fc5
            j += sprintf(&str[j], "%s", attrs_string[i]);
Packit 762fc5
        }
Packit 762fc5
    }
Packit 762fc5
    str[j] = '\0';
Packit 762fc5
    return str;
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
static char get_file_type_char(mode_t mode) {
Packit 762fc5
    switch (mode & S_IFMT) {
Packit 762fc5
        case S_IFREG: return 'f';
Packit 762fc5
        case S_IFDIR: return 'd';
Packit 762fc5
#ifdef S_IFIFO
Packit 762fc5
        case S_IFIFO: return 'p';
Packit 762fc5
#endif
Packit 762fc5
        case S_IFLNK: return 'l';
Packit 762fc5
        case S_IFBLK: return 'b';
Packit 762fc5
        case S_IFCHR: return 'c';
Packit 762fc5
#ifdef S_IFSOCK
Packit 762fc5
        case S_IFSOCK: return 's';
Packit 762fc5
#endif
Packit 762fc5
#ifdef S_IFDOOR
Packit 762fc5
        case S_IFDOOR: return 'D';
Packit 762fc5
#endif
Packit 762fc5
#ifdef S_IFPORT
Packit 762fc5
        case S_IFPORT: return 'P';
Packit 762fc5
#endif
Packit 762fc5
        default: return '?';
Packit 762fc5
    }
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
Packit 762fc5
Packit 762fc5
#ifdef WITH_XATTR
Packit 762fc5
static size_t xstrnspn(const char *s1, size_t len, const char *srch)
Packit 762fc5
{
Packit 762fc5
  const char *os1 = s1;
Packit 762fc5
  
Packit 762fc5
  while (len-- && strchr(srch, *s1))
Packit 762fc5
    ++s1;
Packit 762fc5
Packit 762fc5
  return (s1 - os1);
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
#define PRINTABLE_XATTR_VALS                    \
Packit 762fc5
    "0123456789"                                \
Packit 762fc5
    "abcdefghijklmnopqrstuvwxyz"                \
Packit 762fc5
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"                \
Packit 762fc5
    ".-_:;,[]{}<>()!@#$%^&*|\\/?~"
Packit 762fc5
Packit 762fc5
static int xattrs2array(xattrs_type* xattrs, char* **values) {
Packit 762fc5
    int n = 0;
Packit 762fc5
    if (xattrs==NULL) { n=1; }
Packit 762fc5
    else { n=1+xattrs->num; }
Packit 762fc5
    *values = malloc(n * sizeof(char*));
Packit 762fc5
    (*values)[0]=malloc((6+floor(log10(n)))*sizeof(char));
Packit 762fc5
    snprintf((*values)[0], 6+floor(log10(n)), "num=%d", n-1);
Packit 762fc5
    if (n>1) {
Packit 762fc5
        size_t num = 0;
Packit 762fc5
        int width, length;
Packit 762fc5
        width = log10(xattrs->num); /* make them the same width */
Packit 762fc5
        while (num++ < xattrs->num) {
Packit 762fc5
            char *val = NULL;
Packit 762fc5
            size_t len = 0;
Packit 762fc5
            val = (char *)xattrs->ents[num - 1].val;
Packit 762fc5
            len = xstrnspn(val, xattrs->ents[num - 1].vsz, PRINTABLE_XATTR_VALS);
Packit 762fc5
            if ((len ==  xattrs->ents[num - 1].vsz) || ((len == (xattrs->ents[num - 1].vsz - 1)) && !val[len])) {
Packit 762fc5
                length = 8 + width + strlen(xattrs->ents[num - 1].key) + strlen(val);
Packit 762fc5
                (*values)[num]=malloc(length *sizeof(char));
Packit Service b99ba9
Packit Service b99ba9
                char * fmt = "[%.*zd] %s = %s";
Packit Service b99ba9
                if (conf->syslog_format) fmt = "[%.*zd]%s=%s"; // its smaller so it has to be enough space allocated.
Packit Service b99ba9
                snprintf((*values)[num], length , fmt, width, num, xattrs->ents[num - 1].key, val);
Packit Service b99ba9
Packit 762fc5
            } else {
Packit 762fc5
                val = encode_base64(xattrs->ents[num - 1].val, xattrs->ents[num - 1].vsz);
Packit 762fc5
                length = 10 + width + strlen(xattrs->ents[num - 1].key) + strlen(val);
Packit 762fc5
                (*values)[num]=malloc( length  *sizeof(char));
Packit Service b99ba9
Packit Service b99ba9
                char * fmt = "[%.*zd] %s <=> %s";
Packit Service b99ba9
                if (conf->syslog_format) fmt = "[%.*zd]%s<=>%s"; // its smaller so it has to be enough space allocated.
Packit Service b99ba9
                snprintf((*values)[num], length , fmt, width, num, xattrs->ents[num - 1].key, val);
Packit 762fc5
                free(val);
Packit 762fc5
            }
Packit 762fc5
        }
Packit 762fc5
    }
Packit 762fc5
    return n;
Packit 762fc5
}
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
#ifdef WITH_ACL
Packit 762fc5
static int acl2array(acl_type* acl, char* **values) {
Packit 762fc5
    int n = 0;
Packit 762fc5
#ifdef WITH_POSIX_ACL
Packit 762fc5
#define easy_posix_acl(x,y) \
Packit 762fc5
        if (acl->x) { \
Packit 762fc5
            i = k = 0; \
Packit 762fc5
            while (acl->x[i]) { \
Packit 762fc5
                if (acl->x[i]=='\n') { \
Packit 762fc5
                    (*values)[j]=malloc(4+(i-k)*sizeof(char)); \
Packit 762fc5
                    snprintf((*values)[j], 4+(i-k), "%c: %s", y, &acl->x[k]); \
Packit 762fc5
                    j++; \
Packit 762fc5
                    k=i+1; \
Packit 762fc5
                } \
Packit 762fc5
                i++; \
Packit 762fc5
            } \
Packit 762fc5
        }
Packit 762fc5
    if (acl->acl_a || acl->acl_d) {
Packit 762fc5
        int j, k, i;
Packit Service b99ba9
        if (conf->syslog_format) {
Packit Service b99ba9
            *values = malloc(2 * sizeof(char*));
Packit Service b99ba9
Packit Service b31cf3
            char *A= "<NONE>", *D = "<NONE>";
Packit Service b99ba9
Packit Service b99ba9
            if (acl->acl_a) { A = acl->acl_a; } 
Packit Service b99ba9
            if (acl->acl_d) { D = acl->acl_d; } 
Packit Service b99ba9
Packit Service b99ba9
            (*values)[0] = (char*) malloc(strlen(A) + 3); // "A:" and \0
Packit Service b99ba9
            snprintf((*values)[0], strlen(A) + 3, "A:%s", A);
Packit Service b99ba9
Packit Service b99ba9
            (*values)[1] = (char*) malloc(strlen(D) + 3); // "D:" and \0
Packit Service b99ba9
            snprintf((*values)[1], strlen(D) + 3, "D:%s", D);
Packit Service b99ba9
Packit Service b99ba9
            i = 0; while ( (*values)[0][i] ) { if ( (*values)[0][i]=='\n') { (*values)[0][i] = ' '; } i++; }
Packit Service b99ba9
            i = 0; while ( (*values)[1][i] ) { if ( (*values)[1][i]=='\n') { (*values)[1][i] = ' '; } i++; }
Packit Service b99ba9
Packit Service b99ba9
            return 2;
Packit Service b99ba9
        }
Packit Service b99ba9
Packit 762fc5
        if (acl->acl_a) { i = 0; while (acl->acl_a[i]) { if (acl->acl_a[i++]=='\n') { n++; } } }
Packit 762fc5
        if (acl->acl_d) { i = 0; while (acl->acl_d[i]) { if (acl->acl_d[i++]=='\n') { n++; } } }
Packit 762fc5
        *values = malloc(n * sizeof(char*));
Packit 762fc5
        j = 0;
Packit 762fc5
        easy_posix_acl(acl_a, 'A')
Packit 762fc5
        easy_posix_acl(acl_d, 'D')
Packit 762fc5
    }
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_SUN_ACL
Packit 762fc5
/* FIXME: readd sun acl support */
Packit 762fc5
#endif
Packit 762fc5
    return n;
Packit 762fc5
}
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
#ifdef WITH_E2FSATTRS
Packit 762fc5
static char* e2fsattrs2string(unsigned long flags, int flags_only) {
Packit 762fc5
    int length = sizeof(flag_bits)/sizeof(long);
Packit 762fc5
    char* string = malloc ((length+1) * sizeof (char));
Packit 762fc5
    int j = 0;
Packit 762fc5
    for (int i = 0 ; i < length ; i++) {
Packit 762fc5
        if (!flags_only && flag_bits[i]&(conf->report_ignore_e2fsattrs)) {
Packit 762fc5
            string[j++]=':';
Packit 762fc5
        } else if (flag_bits[i] & flags) {
Packit 762fc5
            string[j++]=flag_char[i];
Packit 762fc5
        } else if (!flags_only) {
Packit 762fc5
            string[j++]='-';
Packit 762fc5
        }
Packit 762fc5
    }
Packit 762fc5
    string[j] = '\0';
Packit 762fc5
    return string;
Packit 762fc5
}
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
static char* get_file_type_string(mode_t mode) {
Packit 762fc5
    switch (mode & S_IFMT) {
Packit Service b99ba9
        case S_IFREG: return conf->syslog_format ? "file" : _("File");
Packit Service b99ba9
        case S_IFDIR: return conf->syslog_format ? "dir" : _("Directory");
Packit 762fc5
#ifdef S_IFIFO
Packit Service b99ba9
        case S_IFIFO: return conf->syslog_format ? "fifo" : _("FIFO");
Packit 762fc5
#endif
Packit Service b99ba9
        case S_IFLNK: return conf->syslog_format ? "link" : _("Link");
Packit Service b99ba9
        case S_IFBLK: return conf->syslog_format ? "blockd" : _("Block device");
Packit Service b99ba9
        case S_IFCHR: return conf->syslog_format ? "chard" : _("Character device");
Packit 762fc5
#ifdef S_IFSOCK
Packit Service b99ba9
        case S_IFSOCK: return conf->syslog_format ? "socket" : _("Socket");
Packit 762fc5
#endif
Packit 762fc5
#ifdef S_IFDOOR
Packit Service b99ba9
        case S_IFDOOR: return conf->syslog_format ? "door" : _("Door");
Packit 762fc5
#endif
Packit 762fc5
#ifdef S_IFPORT
Packit Service b99ba9
        case S_IFPORT: return conf->syslog_format ? "port" : _("Port");
Packit 762fc5
#endif
Packit 762fc5
        case 0: return NULL;
Packit Service b99ba9
        default: return conf->syslog_format ? "unknown" : _("Unknown file type");
Packit 762fc5
    }
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
static char* byte_to_base16(byte* src, size_t ssize) {
Packit 762fc5
    char* str = malloc((2*ssize+1) * sizeof (char));
Packit 762fc5
    size_t i;
Packit 762fc5
    for(i=0; i < ssize; ++i) {
Packit 762fc5
        snprintf(&str[2*i], 3, "%02x", src[i]);
Packit 762fc5
    }
Packit 762fc5
    return str;
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
static int get_attribute_values(DB_ATTR_TYPE attr, db_line* line,
Packit 762fc5
        char* **values) {
Packit 762fc5
Packit 762fc5
#define easy_string(s) \
Packit 762fc5
l = strlen(s)+1; \
Packit 762fc5
*values[0] = malloc(l * sizeof (char)); \
Packit 762fc5
snprintf(*values[0], l, "%s",s);
Packit 762fc5
Packit 762fc5
#define easy_md(a,b,c) \
Packit 762fc5
} else if (a&attr) { \
Packit 762fc5
    if (conf->report_base16) { \
Packit 762fc5
        *values[0] = byte_to_base16(line->b, c); \
Packit 762fc5
    } else { \
Packit 762fc5
        *values[0] = encode_base64(line->b, c); \
Packit 762fc5
    }
Packit 762fc5
Packit 762fc5
#define easy_number(a,b,c) \
Packit 762fc5
} else if (a&attr) { \
Packit 762fc5
    l = 2+floor(line->b?log10(line->b):0); \
Packit 762fc5
    *values[0] = malloc(l * sizeof (char)); \
Packit 762fc5
    snprintf(*values[0], l, c,line->b);
Packit 762fc5
Packit 762fc5
#define easy_time(a,b) \
Packit 762fc5
} else if (a&attr) { \
Packit 762fc5
    *values[0] = malloc(time_string_len * sizeof (char));  \
Packit 762fc5
    strftime(*values[0], time_string_len, time_format, localtime(&(line->b)));
Packit 762fc5
Packit 762fc5
    int l;
Packit 762fc5
    if (line==NULL || !(line->attr&attr)) {
Packit 762fc5
        *values = NULL;
Packit 762fc5
        return 0;
Packit 762fc5
#ifdef WITH_ACL
Packit 762fc5
    } else if (DB_ACL&attr) {
Packit 762fc5
        return acl2array(line->acl, &*values);
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_XATTR
Packit 762fc5
    } else if (DB_XATTRS&attr) {
Packit 762fc5
        return xattrs2array(line->xattrs, &*values);
Packit 762fc5
#endif
Packit 762fc5
    } else {
Packit 762fc5
        *values = malloc(1 * sizeof (char*));
Packit 762fc5
        if (DB_FTYPE&attr) {
Packit Service a81404
            char *file_type = get_file_type_string(line->perm);
Packit Service a81404
            if (!file_type) {
Packit Service a81404
                error(2,"%s: ", file_type);
Packit Service a81404
            }
Packit Service a81404
            easy_string(file_type)
Packit 762fc5
        } else if (DB_LINKNAME&attr) {
Packit 762fc5
            easy_string(line->linkname)
Packit 762fc5
        easy_number((DB_SIZE|DB_SIZEG),size,"%li")
Packit 762fc5
        } else if (DB_PERM&attr) {
Packit 762fc5
            *values[0] = perm_to_char(line->perm);
Packit 762fc5
        easy_time(DB_ATIME,atime)
Packit 762fc5
        easy_time(DB_MTIME,mtime)
Packit 762fc5
        easy_time(DB_CTIME,ctime)
Packit 762fc5
        easy_number(DB_BCOUNT,bcount,"%li")
Packit 762fc5
        easy_number(DB_UID,uid,"%i")
Packit 762fc5
        easy_number(DB_GID,gid,"%i")
Packit 762fc5
        easy_number(DB_INODE,inode,"%lu")
Packit 762fc5
        easy_number(DB_LNKCOUNT,nlink,"%lu")
Packit 762fc5
        easy_md(DB_MD5,md5,HASH_MD5_LEN)
Packit 762fc5
        easy_md(DB_SHA1,sha1,HASH_SHA1_LEN)
Packit 762fc5
        easy_md(DB_RMD160,rmd160,HASH_RMD160_LEN)
Packit 762fc5
        easy_md(DB_TIGER,tiger,HASH_TIGER_LEN)
Packit 762fc5
        easy_md(DB_SHA256,sha256,HASH_SHA256_LEN)
Packit 762fc5
        easy_md(DB_SHA512,sha512,HASH_SHA512_LEN)
Packit 762fc5
#ifdef WITH_MHASH
Packit 762fc5
        easy_md(DB_CRC32,crc32,HASH_CRC32_LEN)
Packit 762fc5
        easy_md(DB_HAVAL,haval,HASH_HAVAL256_LEN)
Packit 762fc5
        easy_md(DB_GOST,gost,HASH_GOST_LEN)
Packit 762fc5
        easy_md(DB_CRC32B,crc32b,HASH_CRC32B_LEN)
Packit 762fc5
        easy_md(DB_WHIRLPOOL,whirlpool,HASH_WHIRLPOOL_LEN)
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_SELINUX
Packit 762fc5
        } else if (DB_SELINUX&attr) {
Packit 762fc5
            easy_string(line->cntx)
Packit 762fc5
#endif
Packit 762fc5
#ifdef WITH_E2FSATTRS
Packit 762fc5
        } else if (DB_E2FSATTRS&attr) {
Packit 762fc5
            *values[0]=e2fsattrs2string(line->e2fsattrs, 0);
Packit 762fc5
#endif
Packit 762fc5
        } else {
Packit 762fc5
            easy_string("unknown attribute")
Packit 762fc5
        }
Packit 762fc5
        return 1;
Packit 762fc5
    }
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
static void print_line(seltree* node) {
Packit 762fc5
    if(conf->summarize_changes==1) {
Packit 762fc5
        int i;
Packit 762fc5
        int length = sizeof(summary_attributes)/sizeof(DB_ATTR_TYPE);
Packit 762fc5
        char* summary = malloc ((length+1) * sizeof (char));
Packit 762fc5
        if (node->checked&(NODE_ADDED|NODE_REMOVED)) {
Packit 762fc5
            summary[0]=get_file_type_char((node->checked&NODE_REMOVED?node->old_data:node->new_data)->perm);
Packit 762fc5
            for(i=1;i
Packit 762fc5
                summary[i]=node->checked&NODE_ADDED?'+':'-';
Packit 762fc5
            }
Packit 762fc5
        } else if (node->checked&NODE_CHANGED) {
Packit 762fc5
            char c, u, a, r, g, s;
Packit 762fc5
            for(i=0;i
Packit 762fc5
                c = summary_char[i];
Packit 762fc5
                r = '-'; a = '+'; g = ':'; u = '.'; s = ' ';
Packit 762fc5
                switch (i) {
Packit 762fc5
                    case 0:
Packit 762fc5
                        summary[i]=get_file_type_char((node->new_data)->perm);
Packit 762fc5
                        continue;
Packit 762fc5
                    case 2:
Packit 762fc5
                        if (summary_attributes[i]&(node->changed_attrs&(~ignored_changed_attrs)) && (node->old_data)->size > (node->new_data)->size) {
Packit 762fc5
                            c = '<';
Packit 762fc5
                        }
Packit 762fc5
                        u = '=';
Packit 762fc5
                        break;
Packit 762fc5
                }
Packit 762fc5
                if (summary_attributes[i]&node->changed_attrs&(forced_attrs|(~ignored_changed_attrs))) {
Packit 762fc5
                    summary[i]=c;
Packit 762fc5
                } else if (summary_attributes[i]&((node->old_data)->attr&~((node->new_data)->attr)&(forced_attrs|~(ignored_removed_attrs)))) {
Packit 762fc5
                    summary[i]=r;
Packit 762fc5
                } else if (summary_attributes[i]&~((node->old_data)->attr)&(node->new_data)->attr&(forced_attrs|~(ignored_added_attrs))) {
Packit 762fc5
                    summary[i]=a;
Packit 762fc5
                } else if (summary_attributes[i]& (
Packit 762fc5
                             (((node->old_data)->attr&~((node->new_data)->attr)&ignored_removed_attrs))|
Packit 762fc5
                            (~((node->old_data)->attr)&(node->new_data)->attr&ignored_added_attrs)|
Packit 762fc5
                             (((node->old_data)->attr&(node->new_data)->attr)&ignored_changed_attrs)
Packit 762fc5
                            ) ) {
Packit 762fc5
                    summary[i]=g;
Packit 762fc5
                } else if (summary_attributes[i]&((node->old_data)->attr&(node->new_data)->attr)) {
Packit 762fc5
                    summary[i]=u;
Packit 762fc5
                } else {
Packit 762fc5
                    summary[i]=s;
Packit 762fc5
                }
Packit 762fc5
            }
Packit 762fc5
        }
Packit 762fc5
        summary[length]='\0';
Packit 762fc5
        error(2,"\n%s: %s", summary, (node->checked&NODE_REMOVED?node->old_data:node->new_data)->filename);
Packit 762fc5
        free(summary); summary=NULL;
Packit 762fc5
    } else {
Packit 762fc5
        if (node->checked&NODE_ADDED) {
Packit 762fc5
            error(2,"added: %s\n",(node->new_data)->filename);
Packit 762fc5
        } else if (node->checked&NODE_REMOVED) {
Packit 762fc5
            error(2,"removed: %s\n",(node->old_data)->filename);
Packit 762fc5
        } else if (node->checked&NODE_CHANGED) {
Packit 762fc5
            error(2,"changed: %s\n",(node->new_data)->filename);
Packit 762fc5
        }
Packit 762fc5
    }
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
static void print_dbline_attributes(db_line* oline, db_line* nline, DB_ATTR_TYPE
Packit 762fc5
        changed_attrs, DB_ATTR_TYPE force_attrs) {
Packit 762fc5
    char **ovalue, **nvalue;
Packit 762fc5
    int onumber, nnumber, olen, nlen, i, j, k, c;
Packit 762fc5
    int length = sizeof(details_attributes)/sizeof(DB_ATTR_TYPE);
Packit 762fc5
    int p = (width_details-(width_details%2?13:14))/2;
Packit 762fc5
    DB_ATTR_TYPE attrs;
Packit 762fc5
    error(2,"\n");
Packit 762fc5
    char *file_type = get_file_type_string((nline==NULL?oline:nline)->perm);
Packit 762fc5
    if (file_type) {
Packit 762fc5
        error(2,"%s: ", file_type);
Packit 762fc5
    }
Packit 762fc5
    error(2,"%s\n", (nline==NULL?oline:nline)->filename);
Packit 762fc5
    attrs=force_attrs|(~(ignored_changed_attrs)&changed_attrs);
Packit 762fc5
    for (j=0; j < length; ++j) {
Packit 762fc5
        if (details_attributes[j]&attrs) {
Packit 762fc5
            onumber=get_attribute_values(details_attributes[j], oline, &ovalue);
Packit 762fc5
            nnumber=get_attribute_values(details_attributes[j], nline, &nvalue);
Packit 762fc5
            i = 0;
Packit 762fc5
            while (i
Packit 762fc5
                olen = i
Packit 762fc5
                nlen = i
Packit 762fc5
                k = 0;
Packit 762fc5
                while (olen-p*k >= 0 || nlen-p*k >= 0) {
Packit 762fc5
                    c = k*(p-1);
Packit 762fc5
                    if (!onumber) {
Packit 762fc5
                        error(2," %s%-9s%c %-*c  %.*s\n", width_details%2?"":" ", i+k?"":details_string[j], i+k?' ':':', p, ' ', p-1, nlen-c>0?&nvalue[i][c]:"");
Packit 762fc5
                    } else if (!nnumber) {
Packit 762fc5
                        error(2," %s%-9s%c %.*s\n", width_details%2?"":" ", i+k?"":details_string[j], i+k?' ':':', p-1, olen-c>0?&ovalue[i][c]:"");
Packit 762fc5
                    } else {
Packit 762fc5
                        error(2," %s%-9s%c %-*.*s| %.*s\n", width_details%2?"":" ", i+k?"":details_string[j], i+k?' ':':', p, p-1, olen-c>0?&ovalue[i][c]:"", p-1, nlen-c>0?&nvalue[i][c]:"");
Packit 762fc5
                    }
Packit 762fc5
                    k++;
Packit 762fc5
                }
Packit 762fc5
                ++i;
Packit 762fc5
            }
Packit 762fc5
            for(i=0; i < onumber; ++i) { free(ovalue[i]); ovalue[i]=NULL; } free(ovalue); ovalue=NULL;
Packit 762fc5
            for(i=0; i < nnumber; ++i) { free(nvalue[i]); nvalue[i]=NULL; } free(nvalue); nvalue=NULL;
Packit 762fc5
        }
Packit 762fc5
    }
Packit 762fc5
}
Packit 762fc5
Packit Service b99ba9
Packit Service b99ba9
static void print_dbline_attributes_syslog(db_line* oline, db_line* nline, DB_ATTR_TYPE
Packit Service b99ba9
        changed_attrs, DB_ATTR_TYPE force_attrs) {
Packit Service b99ba9
    char **ovalue, **nvalue;
Packit Service b99ba9
    int onumber, nnumber, i, j;
Packit Service b99ba9
    int length = sizeof(details_attributes)/sizeof(DB_ATTR_TYPE);
Packit Service b99ba9
    DB_ATTR_TYPE attrs;
Packit Service b99ba9
    char *file_type = get_file_type_string((nline==NULL?oline:nline)->perm);
Packit Service b99ba9
    if (file_type) {
Packit Service b99ba9
        error(0,"%s=", file_type);
Packit Service b99ba9
    }
Packit Service b99ba9
    error(0,"%s", (nline==NULL?oline:nline)->filename);
Packit Service b99ba9
    attrs=force_attrs|(~(ignored_changed_attrs)&changed_attrs);
Packit Service b99ba9
    for (j=0; j < length; ++j) {
Packit Service b99ba9
        if (details_attributes[j]&attrs) {
Packit Service b99ba9
            onumber=get_attribute_values(details_attributes[j], oline, &ovalue);
Packit Service b99ba9
            nnumber=get_attribute_values(details_attributes[j], nline, &nvalue);
Packit Service b99ba9
Packit Service b99ba9
            if (details_attributes[j] == DB_ACL || details_attributes[j] == DB_XATTRS) {
Packit Service b99ba9
Packit Service b99ba9
                error(0, ";%s_old=|", details_string[j]);
Packit Service b99ba9
Packit Service b99ba9
                for (i = 0 ; i < onumber ; i++) {
Packit Service b99ba9
                    error(0, "%s|", ovalue[i]);
Packit Service b99ba9
                }
Packit Service b99ba9
Packit Service b99ba9
                error(0, ";%s_new=|", details_string[j]);
Packit Service b99ba9
Packit Service b99ba9
                for (i = 0 ; i < nnumber ; i++) {
Packit Service b99ba9
                    error(0, "%s|", nvalue[i]);
Packit Service b99ba9
                }
Packit Service b99ba9
Packit Service b99ba9
            } else {
Packit Service b99ba9
Packit Service b99ba9
                error(0, ";%s_old=%s;%s_new=%s", details_string[j], *ovalue, details_string[j], *nvalue);
Packit Service b99ba9
Packit Service b99ba9
            }
Packit Service b99ba9
Packit Service b99ba9
            for(i=0; i < onumber; ++i) { free(ovalue[i]); ovalue[i]=NULL; } free(ovalue); ovalue=NULL;
Packit Service b99ba9
            for(i=0; i < nnumber; ++i) { free(nvalue[i]); nvalue[i]=NULL; } free(nvalue); nvalue=NULL;
Packit Service b99ba9
        }
Packit Service b99ba9
    }
Packit Service b99ba9
    error(0, "\n");
Packit Service b99ba9
}
Packit Service b99ba9
Packit 762fc5
static void print_attributes_added_node(db_line* line) {
Packit 762fc5
    print_dbline_attributes(NULL, line, 0, line->attr);
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
static void print_attributes_removed_node(db_line* line) {
Packit 762fc5
    print_dbline_attributes(line, NULL, 0, line->attr);
Packit 762fc5
}
Packit 762fc5
Packit Service b99ba9
static void print_attributes_added_node_syslog(db_line* line) {
Packit Service b99ba9
Packit Service b99ba9
    char *file_type = get_file_type_string(line->perm);
Packit Service b99ba9
    if (file_type) {
Packit Service b99ba9
        error(0,"%s=", file_type);
Packit Service b99ba9
    }
Packit Service b99ba9
    error(0,"%s; added\n", line->filename);
Packit Service b99ba9
Packit Service b99ba9
}
Packit Service b99ba9
Packit Service b99ba9
static void print_attributes_removed_node_syslog(db_line* line) {
Packit Service b99ba9
Packit Service b99ba9
    char *file_type = get_file_type_string(line->perm);
Packit Service b99ba9
    if (file_type) {
Packit Service b99ba9
        error(0,"%s=", file_type);
Packit Service b99ba9
    }
Packit Service b99ba9
    error(0,"%s; removed\n", line->filename);
Packit Service b99ba9
Packit Service b99ba9
}
Packit Service b99ba9
Packit 762fc5
static void terse_report(seltree* node) {
Packit 762fc5
    list* r=NULL;
Packit 762fc5
    if ((node->checked&(DB_OLD|DB_NEW)) != 0) {
Packit 762fc5
        ntotal += ((node->checked&DB_NEW) != 0);
Packit 762fc5
        if (!(node->checked&DB_OLD)){
Packit 762fc5
            /* File is in new db but not old. (ADDED) */
Packit 762fc5
            /* unless it was moved in */
Packit 762fc5
            if (!((node->checked&NODE_ALLOW_NEW)||(node->checked&NODE_MOVED_IN))) {
Packit 762fc5
                nadd++;
Packit 762fc5
                node->checked|=NODE_ADDED;
Packit 762fc5
            }
Packit 762fc5
        } else if (!(node->checked&DB_NEW)){
Packit 762fc5
            /* File is in old db but not new. (REMOVED) */
Packit 762fc5
            /* unless it was moved out */
Packit 762fc5
            if (!((node->checked&NODE_ALLOW_RM)||(node->checked&NODE_MOVED_OUT))) {
Packit 762fc5
                nrem++;
Packit 762fc5
                node->checked|=NODE_REMOVED;
Packit 762fc5
            }
Packit 762fc5
        } else if ((node->old_data!=NULL)&&(node->new_data!=NULL)){
Packit 762fc5
            /* File is in both db's and the data is still there. (CHANGED) */
Packit 762fc5
            if (!(node->checked&(NODE_MOVED_IN|NODE_MOVED_OUT))){
Packit 762fc5
                nchg++;
Packit 762fc5
                node->checked|=NODE_CHANGED;
Packit 762fc5
            }else if (!((node->checked&NODE_ALLOW_NEW)||(node->checked&NODE_MOVED_IN))) {
Packit 762fc5
                nadd++;
Packit 762fc5
                node->checked|=NODE_ADDED;
Packit 762fc5
            }else if (!((node->checked&NODE_ALLOW_RM)||(node->checked&NODE_MOVED_OUT))) {
Packit 762fc5
                nrem++;
Packit 762fc5
                node->checked|=NODE_REMOVED;
Packit 762fc5
            }
Packit 762fc5
        }
Packit 762fc5
    }
Packit 762fc5
    for (r=node->childs;r;r=r->next) {
Packit 762fc5
        terse_report((seltree*)r->data);
Packit 762fc5
    }
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
static void print_report_list(seltree* node, const int node_status) {
Packit 762fc5
    list* r=NULL;
Packit 762fc5
    if (node->checked&node_status) {
Packit 762fc5
        print_line(node);
Packit 762fc5
    }
Packit 762fc5
    for(r=node->childs;r;r=r->next){
Packit 762fc5
        print_report_list((seltree*)r->data, node_status);
Packit 762fc5
    }
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
static void print_report_details(seltree* node) {
Packit 762fc5
    list* r=NULL;
Packit 762fc5
    if (conf->verbose_level>=5) {
Packit 762fc5
        if (node->checked&NODE_CHANGED) {
Packit 762fc5
            print_dbline_attributes(node->old_data, node->new_data, node->changed_attrs, (conf->verbose_level>=6?(
Packit 762fc5
                ((node->old_data)->attr&~((node->new_data)->attr)&~(ignored_removed_attrs))|(~((node->old_data)->attr)&(node->new_data)->attr&~(ignored_added_attrs))
Packit 762fc5
                            ):0)|forced_attrs);
Packit 762fc5
        } else if ((conf->verbose_level>=7)) {
Packit 762fc5
            if (node->checked&NODE_ADDED) { print_attributes_added_node(node->new_data); }
Packit 762fc5
            if (node->checked&NODE_REMOVED) { print_attributes_removed_node(node->old_data); }
Packit 762fc5
        }
Packit 762fc5
    }
Packit 762fc5
    for(r=node->childs;r;r=r->next){
Packit 762fc5
        print_report_details((seltree*)r->data);
Packit 762fc5
    }
Packit 762fc5
}
Packit 762fc5
Packit Service b99ba9
static void print_syslog_format(seltree* node) {
Packit Service b99ba9
    list* r=NULL;
Packit Service b99ba9
Packit Service b99ba9
    if (node->checked&NODE_CHANGED) {
Packit Service b99ba9
        print_dbline_attributes_syslog(node->old_data, node->new_data, node->changed_attrs, forced_attrs);
Packit Service b99ba9
    }
Packit Service b99ba9
   
Packit Service b99ba9
    if (node->checked&NODE_ADDED) {
Packit Service b99ba9
        print_attributes_added_node_syslog(node->new_data);
Packit Service b99ba9
    }
Packit Service b99ba9
Packit Service b99ba9
    if (node->checked&NODE_REMOVED) {
Packit Service b99ba9
        print_attributes_removed_node_syslog(node->old_data); 
Packit Service b99ba9
    }
Packit Service b99ba9
        
Packit Service b99ba9
    for(r=node->childs;r;r=r->next){
Packit Service b99ba9
        print_syslog_format((seltree*)r->data);
Packit Service b99ba9
    }
Packit Service b99ba9
}
Packit Service b99ba9
Packit 762fc5
static void print_report_header() {
Packit 762fc5
    char *time;
Packit 762fc5
    int first = 1;
Packit 762fc5
Packit 762fc5
    time = malloc(time_string_len * sizeof (char));
Packit 762fc5
    strftime(time, time_string_len, time_format, localtime(&(conf->start_time)));
Packit 762fc5
    error(2,_("Start timestamp: %s (AIDE " AIDEVERSION ")\n"), time);
Packit 762fc5
    free(time); time=NULL;
Packit 762fc5
Packit 762fc5
    error(0,_("AIDE"));
Packit 762fc5
    if(conf->action&(DO_COMPARE|DO_DIFF)) {
Packit 762fc5
        error(0,_(" found %sdifferences between %s%s!!\n"), (nadd||nrem||nchg)?"":"NO ", conf->action&DO_COMPARE?_("database and filesystem"):_("the two databases"), (nadd||nrem||nchg)?"":_(". Looks okay"));
Packit 762fc5
        if(conf->action&(DO_INIT)) {
Packit 762fc5
            error(0,_("New AIDE database written to %s\n"),conf->db_out_url->value);
Packit 762fc5
        }
Packit 762fc5
    } else {
Packit 762fc5
        error(0,_(" initialized database at %s\n"),conf->db_out_url->value);
Packit 762fc5
    }
Packit 762fc5
Packit 762fc5
    if(conf->config_version)
Packit 762fc5
        error(2,_("Config version used: %s\n"),conf->config_version);
Packit 762fc5
Packit 762fc5
    if (conf->limit != NULL) {
Packit 762fc5
        error (2,_("Limit: %s"), conf->limit);
Packit 762fc5
        first = 0;
Packit 762fc5
    }
Packit 762fc5
    if (conf->action&(DO_INIT|DO_COMPARE) && conf->root_prefix_length > 0) {
Packit 762fc5
        if (first) { first=0; }
Packit 762fc5
        else { error (2," | "); }
Packit 762fc5
        error (2,_("Root prefix: %s"),conf->root_prefix);
Packit 762fc5
    }
Packit 762fc5
    if (conf->verbose_level != 5) {
Packit 762fc5
        if (first) { first=0; }
Packit 762fc5
        else { error (2," | "); }
Packit 762fc5
        error (2,_("Verbose level: %d"), conf->verbose_level);
Packit 762fc5
    }
Packit 762fc5
    if (!first) { error (2,"\n"); }
Packit 762fc5
    if (ignored_added_attrs) {
Packit 762fc5
        error (2,_("Ignored added attributes: %s\n"),report_attrs(ignored_added_attrs));
Packit 762fc5
    }
Packit 762fc5
    if (ignored_removed_attrs) {
Packit 762fc5
        error (2,_("Ignored removed attributes: %s\n"),report_attrs(ignored_removed_attrs));
Packit 762fc5
    }
Packit 762fc5
    if (ignored_changed_attrs) {
Packit 762fc5
        error (2,_("Ignored changed attributes: %s\n"),report_attrs(ignored_changed_attrs));
Packit 762fc5
    }
Packit 762fc5
    if (forced_attrs) {
Packit 762fc5
        error (2,_("Forced attributes: %s\n"),report_attrs(forced_attrs));
Packit 762fc5
    }
Packit 762fc5
#ifdef WITH_E2FSATTRS
Packit 762fc5
    if (conf->report_ignore_e2fsattrs) {
Packit 762fc5
        error (2,_("Ignored e2fs attributes: %s\n"), e2fsattrs2string(conf->report_ignore_e2fsattrs, 1) );
Packit 762fc5
    }
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
    if(conf->action&(DO_COMPARE|DO_DIFF) && (nadd||nrem||nchg)) {
Packit 762fc5
        error(0,_("\nSummary:\n  Total number of entries:\t%li\n  Added entries:\t\t%li\n"
Packit 762fc5
                    "  Removed entries:\t\t%li\n  Changed entries:\t\t%li"), ntotal, nadd, nrem, nchg);
Packit 762fc5
    } else {
Packit 762fc5
        error(0,_("\nNumber of entries:\t%li"), ntotal);
Packit 762fc5
    }
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
static void print_report_databases() {
Packit 762fc5
    if (conf->verbose_level>=2 && (conf->line_db_in || conf->line_db_out)) {
Packit 762fc5
        error(2,(char*)report_top_format,_("The attributes of the (uncompressed) database(s)"));
Packit 762fc5
        if (conf->line_db_in) {
Packit 762fc5
            print_attributes_removed_node(conf->line_db_in);
Packit 762fc5
        }
Packit 762fc5
        if (conf->line_db_out) {
Packit 762fc5
            print_attributes_removed_node(conf->line_db_out);
Packit 762fc5
        }
Packit 762fc5
    }
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
static void print_report_footer()
Packit 762fc5
{
Packit 762fc5
  char *time = malloc(time_string_len * sizeof (char));
Packit 762fc5
  int run_time = (int) difftime(conf->end_time, conf->start_time);
Packit 762fc5
Packit 762fc5
  strftime(time, time_string_len, time_format, localtime(&(conf->end_time)));
Packit 762fc5
  error(2,_("\n\nEnd timestamp: %s (run time: %dm %ds)\n"), time, run_time/60, run_time%60);
Packit 762fc5
  free(time); time=NULL;
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
#ifdef WITH_AUDIT
Packit 762fc5
  /* Something changed, send audit anomaly message */
Packit 762fc5
void send_audit_report()
Packit 762fc5
{
Packit 762fc5
  if(nadd!=0||nrem!=0||nchg!=0){
Packit 762fc5
    int fd=audit_open();
Packit 762fc5
    if (fd>=0){
Packit 762fc5
       char msg[64];
Packit 762fc5
Packit 762fc5
       snprintf(msg, sizeof(msg), "added=%ld removed=%ld changed=%ld", 
Packit 762fc5
                nadd, nrem, nchg);
Packit 762fc5
Packit 762fc5
       if (audit_log_user_message(fd, AUDIT_ANOM_RBAC_INTEGRITY_FAIL,
Packit 762fc5
                                  msg, NULL, NULL, NULL, 0)<=0)
Packit 762fc5
#ifdef HAVE_SYSLOG
Packit 762fc5
          syslog(LOG_ERR, "Failed sending audit message:%s", msg);
Packit 762fc5
#else
Packit 762fc5
          ;
Packit 762fc5
#endif
Packit 762fc5
       close(fd);
Packit 762fc5
    }
Packit 762fc5
  }
Packit 762fc5
}
Packit 762fc5
#endif /* WITH_AUDIT */
Packit 762fc5
Packit 762fc5
int gen_report(seltree* node) {
Packit 762fc5
    forced_attrs = get_special_report_group("report_force_attrs");
Packit 762fc5
    ignored_added_attrs = get_special_report_group("report_ignore_added_attrs");
Packit 762fc5
    ignored_removed_attrs = get_special_report_group("report_ignore_removed_attrs");
Packit 762fc5
    ignored_changed_attrs = get_special_report_group("report_ignore_changed_attrs");
Packit 762fc5
Packit 762fc5
    terse_report(node);
Packit 762fc5
#ifdef WITH_AUDIT
Packit 762fc5
    send_audit_report();
Packit 762fc5
#endif
Packit 762fc5
    if ((nadd|nrem|nchg) > 0 || conf->report_quiet == 0) {
Packit Service b99ba9
Packit Service b99ba9
        if (!conf->syslog_format) {
Packit Service b99ba9
            print_report_header();
Packit 762fc5
        }
Packit Service b99ba9
Packit Service b99ba9
        if(conf->action&(DO_COMPARE|DO_DIFF) || (conf->action&DO_INIT && conf->report_detailed_init) ) {
Packit Service b99ba9
            if (!conf->syslog_format && conf->grouped) {
Packit Service b99ba9
                if (nadd) {
Packit Service b99ba9
                    error(2,(char*)report_top_format,_("Added entries"));
Packit Service b99ba9
                    print_report_list(node, NODE_ADDED);
Packit Service b99ba9
                }
Packit Service b99ba9
                if (nrem) {
Packit Service b99ba9
                    error(2,(char*)report_top_format,_("Removed entries"));
Packit Service b99ba9
                    print_report_list(node, NODE_REMOVED);
Packit Service b99ba9
                }
Packit Service b99ba9
                if (nchg) {
Packit Service b99ba9
                    error(2,(char*)report_top_format,_("Changed entries"));
Packit Service b99ba9
                    print_report_list(node, NODE_CHANGED);
Packit Service b99ba9
                }
Packit Service b99ba9
            } else if (!conf->syslog_format && ( nadd || nrem || nchg ) ) {
Packit Service b99ba9
                if (nadd && nrem && nchg) { error(2,(char*)report_top_format,_("Added, removed and changed entries")); }
Packit Service b99ba9
                else if (nadd && nrem) { error(2,(char*)report_top_format,_("Added and removed entries")); }
Packit Service b99ba9
                else if (nadd && nchg) { error(2,(char*)report_top_format,_("Added and changed entries")); }
Packit Service b99ba9
                else if (nrem && nchg) { error(2,(char*)report_top_format,_("Removed and changed entries")); }
Packit Service b99ba9
                else if (nadd) { error(2,(char*)report_top_format,_("Added entries")); }
Packit Service b99ba9
                else if (nrem) { error(2,(char*)report_top_format,_("Removed entries")); }
Packit Service b99ba9
                else if (nchg) { error(2,(char*)report_top_format,_("Changed entries")); }
Packit Service b99ba9
                print_report_list(node, NODE_ADDED|NODE_REMOVED|NODE_CHANGED);
Packit Service b99ba9
            }
Packit Service b99ba9
            if (nadd || nrem || nchg) {
Packit Service b99ba9
                if (!conf->syslog_format) {
Packit Service b99ba9
                    error(nchg?5:7,(char*)report_top_format,_("Detailed information about changes"));
Packit Service b99ba9
                    print_report_details(node);
Packit Service b99ba9
                } else {
Packit Service b99ba9
                    /* Syslog Format */
Packit Service b99ba9
                    error(0, "AIDE found differences between database and filesystem!!\n");
Packit Service b99ba9
                    error(0, "summary;total_number_of_files=%ld;added_files=%ld;"
Packit Service b99ba9
                              "removed_files=%ld;changed_files=%ld\n",ntotal,nadd,nrem,nchg);
Packit Service b99ba9
                    print_syslog_format(node);
Packit Service b99ba9
                }
Packit Service b99ba9
            }
Packit 762fc5
        }
Packit Service b99ba9
        if (!conf->syslog_format) {
Packit Service b99ba9
            print_report_databases();
Packit Service b99ba9
            conf->end_time=time(&(conf->end_time));
Packit Service b99ba9
            print_report_footer();
Packit 762fc5
        }
Packit 762fc5
    }
Packit 762fc5
Packit 762fc5
    return conf->action&(DO_COMPARE|DO_DIFF) ? (nadd!=0)*1+(nrem!=0)*2+(nchg!=0)*4 : 0;
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
const char* aide_key_9=CONFHMACKEY_09;
Packit 762fc5
const char* db_key_9=DBHMACKEY_09;
Packit 762fc5
Packit 762fc5
// vi: ts=8 sw=8