Blame include/db_config.h

Packit 762fc5
/* aide, Advanced Intrusion Detection Environment
Packit 762fc5
 *
Packit 762fc5
 * Copyright (C) 1999-2002,2004-2006,2010-2013,2015,2016 Rami Lehti, Pablo
Packit 762fc5
 * Virolainen, Richard van den Berg, Hannes von Haugwitz
Packit 762fc5
 * $Header$
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
#ifndef _DB_CONFIG_H_INCLUDED
Packit 762fc5
#define _DB_CONFIG_H_INCLUDED
Packit 762fc5
#include "aide.h"
Packit 762fc5
#include "types.h"
Packit 762fc5
#include <unistd.h>
Packit 762fc5
#include <stdio.h>
Packit 762fc5
#include <pcre.h>
Packit 762fc5
Packit 762fc5
#define E2O(n) (1<
Packit 762fc5
Packit 762fc5
#include "list.h"
Packit 762fc5
Packit 762fc5
#ifdef WITH_SUN_ACL /* First try to implement support for sun acl. */
Packit 762fc5
/*#define WITH_ACL    If we use sun acl then we have acl :) */
Packit 762fc5
/* Warning! if acl in database is corrupted then
Packit 762fc5
   this will break down. See and fix db.c */
Packit 762fc5
Packit 762fc5
#ifndef WITH_ACL
Packit 762fc5
# error "No ACL support ... but Sun ACL support."
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
#include <sys/acl.h>
Packit 762fc5
typedef struct acl_type{
Packit 762fc5
  int entries;
Packit 762fc5
  aclent_t* acl;
Packit 762fc5
} acl_type;
Packit 762fc5
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
#ifdef WITH_POSIX_ACL /* POSIX acl works for Sun ACL, AIUI but anyway... */
Packit 762fc5
#include <sys/acl.h>
Packit 762fc5
#ifndef WITH_ACL
Packit 762fc5
# error "No ACL support ... but POSIX ACL support."
Packit 762fc5
#endif
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
typedef struct acl_type {
Packit 762fc5
 char *acl_a; /* ACCESS */
Packit 762fc5
 char *acl_d; /* DEFAULT, directories only */
Packit 762fc5
} acl_type;
Packit 762fc5
Packit 762fc5
#ifdef WITH_XATTR /* Do generic user Xattrs. */
Packit 762fc5
#include <sys/xattr.h>
Packit 762fc5
#include <attr/xattr.h>
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
typedef struct xattr_node 
Packit 762fc5
{
Packit 762fc5
 char *key;
Packit 762fc5
 byte *val;
Packit 762fc5
 size_t vsz;
Packit 762fc5
} xattr_node;
Packit 762fc5
Packit 762fc5
typedef struct xattrs_type
Packit 762fc5
{
Packit 762fc5
  size_t num;
Packit 762fc5
  size_t sz;
Packit 762fc5
  struct xattr_node *ents;
Packit 762fc5
} xattrs_type;
Packit 762fc5
Packit 762fc5
#ifdef WITH_SELINUX
Packit 762fc5
#include <selinux/selinux.h>
Packit 762fc5
#ifndef ENOATTR
Packit 762fc5
# define ENOATTR ENODATA 
Packit 762fc5
#endif
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
#ifdef WITH_E2FSATTRS
Packit 762fc5
#include <e2p/e2p.h>
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
#ifdef WITH_MHASH
Packit 762fc5
#include <mhash.h>
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
#ifdef WITH_ZLIB
Packit 762fc5
#include <zlib.h>
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
#define RETOK 0
Packit 762fc5
#define RETFAIL -1
Packit 762fc5
Packit 762fc5
#define DO_INIT     (1<<0)
Packit 762fc5
#define DO_COMPARE  (1<<1)
Packit 762fc5
#define DO_DIFF     (1<<2)
Packit 762fc5
Packit 762fc5
#include "url.h"
Packit 762fc5
Packit 762fc5
/*
Packit 762fc5
typedef enum {
Packit 762fc5
  url_file, url_stdout, url_stdin, url_stderr, url_fd, url_http,
Packit 762fc5
  url_sql, url_syslog, url_database, url_multiplexer , url_unknown
Packit 762fc5
} URL_TYPE;
Packit 762fc5
*/
Packit 762fc5
/*
Packit 762fc5
  typedef struct url_t {*/
Packit 762fc5
  /* Everything before the first ':' */
Packit 762fc5
/*
Packit 762fc5
  URL_TYPE type;
Packit 762fc5
  char* value;
Packit 762fc5
} url_t;
Packit 762fc5
*/
Packit 762fc5
Packit 762fc5
typedef enum { 
Packit 762fc5
   db_filename=0, 		/* "name",   */ 
Packit 762fc5
   db_linkname, 		/* "lname",   */
Packit 762fc5
   db_perm, 			/* "perm",    */
Packit 762fc5
   db_uid, 			/* "uid",     */
Packit 762fc5
   db_gid,			/* "gid",     */
Packit 762fc5
   db_size, 			/* "size",    */
Packit 762fc5
   db_atime, 			/* "atime",   */
Packit 762fc5
   db_ctime, 			/* "ctime",   */
Packit 762fc5
   db_mtime, 			/* "mtime",   */
Packit 762fc5
   db_inode,			/* "inode",   */
Packit 762fc5
   db_bcount, 			/* "bcount",  */
Packit 762fc5
   db_lnkcount, 		/* "lcount",  */
Packit 762fc5
   db_md5, 			/* "md5",     */
Packit 762fc5
   db_sha1, 			/* "sha1",    */
Packit 762fc5
   db_rmd160,			/* "rmd160",  */
Packit 762fc5
   db_tiger, 			/* "tiger",   */
Packit 762fc5
   db_crc32, 			/* "crc32",   */
Packit 762fc5
   db_haval,			/* "haval",   */
Packit 762fc5
   db_gost, 			/* "gost",    */
Packit 762fc5
   db_crc32b, 			/* "crc32b",  */
Packit 762fc5
   db_attr,                     /* attributes */
Packit 762fc5
   db_acl,                      /* access control list */
Packit 762fc5
   db_bsize,                    /* "bsize"    */
Packit 762fc5
   db_rdev,                     /* "rdev"     */
Packit 762fc5
   db_dev,                      /* "dev"      */
Packit 762fc5
   db_checkmask,                /* "checkmask"*/
Packit 762fc5
   db_allownewfile,		/* "allownewfile */
Packit 762fc5
   db_allowrmfile,		/* "allowrmfile" */
Packit 762fc5
   db_sha256, 			/* "sha256",  */
Packit 762fc5
   db_sha512, 			/* "sha512",  */
Packit 762fc5
   db_whirlpool,		/* "whirlpool",  */
Packit 762fc5
   db_selinux, 			/* "selinux",  */
Packit 762fc5
   db_xattrs, 			/* "xattrs",  */
Packit 762fc5
   db_e2fsattrs,        /* "e2fsattrs"     */
Packit 762fc5
   db_unknown } DB_FIELD; 	/* "unknown"  */
Packit 762fc5
Packit 762fc5
/* db_unknown must be last because it is used to determine size of
Packit 762fc5
   DB_FILED */
Packit 762fc5
Packit 762fc5
/* FIXME: THIS IS A HACK, sometimes we use AIDE_OFF_TYPE instead
Packit 762fc5
 * because that's what internal functions take. This bitmap needs to die. */
Packit 762fc5
#define DB_ATTR_TYPE unsigned long long
Packit 762fc5
#define DB_ATTR_UNDEF ((DB_ATTR_TYPE) -1)
Packit 762fc5
Packit 762fc5
/* WE need this for rx_rules since enums are not orrable (horrible) */
Packit 762fc5
#define DB_FILENAME (1LLU<<0)	/* "name",   */ 
Packit 762fc5
#define DB_LINKNAME (1LLU<<1)	/* "lname",   */
Packit 762fc5
#define DB_PERM     (1LLU<<2)	/* "perm",    */
Packit 762fc5
#define DB_UID      (1LLU<<3)	/* "uid",     */
Packit 762fc5
#define DB_GID      (1LLU<<4)	/* "gid",     */
Packit 762fc5
#define DB_SIZE     (1LLU<<5)	/* "size",    */
Packit 762fc5
#define DB_ATIME    (1LLU<<6)	/* "atime",   */
Packit 762fc5
#define DB_CTIME    (1LLU<<7)	/* "ctime",   */
Packit 762fc5
#define DB_MTIME    (1LLU<<8)	/* "mtime",   */
Packit 762fc5
#define DB_INODE    (1LLU<<9)	/* "inode",   */
Packit 762fc5
#define DB_BCOUNT   (1LLU<<10)	/* "bcount",  */
Packit 762fc5
#define DB_LNKCOUNT (1LLU<<11)	/* "lcount",  */
Packit 762fc5
#define DB_MD5      (1LLU<<12)	/* "md5",     */
Packit 762fc5
#define DB_SHA1     (1LLU<<13)	/* "sha1",    */
Packit 762fc5
#define DB_RMD160   (1LLU<<14)	/* "rmd160",  */
Packit 762fc5
#define DB_TIGER    (1LLU<<15)	/* "tiger",   */
Packit 762fc5
/*
Packit 762fc5
  We want to matk these newertheless we have a 
Packit 762fc5
  hash-functon or not.
Packit 762fc5
 */
Packit 762fc5
Packit 762fc5
#define DB_CRC32    (1LLU<<16)	/* "crc32",   */
Packit 762fc5
#define DB_HAVAL    (1LLU<<17)	/* "haval",   */
Packit 762fc5
#define DB_GOST     (1LLU<<18)	/* "gost",    */
Packit 762fc5
#define DB_CRC32B   (1LLU<<19)	/* "crc32b",  */
Packit 762fc5
// #define DB_ATTR    (1LLU<<20)     /* "attr"    */
Packit 762fc5
#define DB_ACL      (1LLU<<21)  /* "acl"      */
Packit 762fc5
#define DB_BSIZE    (1LLU<<22)  /* "bsize"    */
Packit 762fc5
#define DB_RDEV     (1LLU<<23)  /* "rdev"     */
Packit 762fc5
#define DB_DEV      (1LLU<<24)  /* "dev"      */
Packit 762fc5
Packit 762fc5
#define DB_CHECKMASK  (1LLU<<25) /* "checkmask"*/
Packit 762fc5
#define DB_SIZEG      (1LLU<<26) /* "unknown"  */
Packit 762fc5
#define DB_CHECKINODE (1LLU<<27) /* "checkinode"*/
Packit 762fc5
#define DB_NEWFILE    (1LLU<<28) /* "allow new file" */
Packit 762fc5
#define DB_RMFILE     (1LLU<<29) /* "allot rm file" */
Packit 762fc5
#define DB_SHA256     (1LLU<<30) /* "sha256",  */
Packit 762fc5
#define DB_SHA512     (1LLU<<31) /* "sha512",  */
Packit 762fc5
#define DB_SELINUX    (1LLU<<32) /* "selinux", */
Packit 762fc5
#define DB_XATTRS     (1LLU<<33) /* "xattrs",  */
Packit 762fc5
#define DB_WHIRLPOOL  (1LLU<<34) /* "whirlpool",  */
Packit 762fc5
#define DB_FTYPE      (1LLU<<35) /* "file type",  */
Packit 762fc5
#define DB_E2FSATTRS  (1LLU<<36) /* "ext2 file system attributes"  */
Packit 762fc5
Packit 762fc5
#define DB_HASHES    (DB_MD5|DB_SHA1|DB_RMD160|DB_TIGER|DB_CRC32|DB_HAVAL| \
Packit 762fc5
		      DB_GOST|DB_CRC32B|DB_SHA256|DB_SHA512|DB_WHIRLPOOL)
Packit 762fc5
Packit 762fc5
extern const char* db_names[db_unknown+1];
Packit 762fc5
extern const int db_value[db_unknown+1];
Packit 762fc5
Packit 762fc5
/* db_namealias && db_aliasvalue are here to support earlier database 
Packit 762fc5
 * names that are no longer used. */
Packit 762fc5
#define db_alias_size 1
Packit 762fc5
extern const char* db_namealias[db_alias_size];
Packit 762fc5
extern const int db_aliasvalue[db_alias_size];
Packit 762fc5
Packit 762fc5
/* TIMEBUFSIZE should be exactly ceil(sizeof(time_t)*8*ln(2)/ln(10))
Packit 762fc5
 * Now it is ceil(sizeof(time_t)*2.5)
Packit 762fc5
 * And of course we add one for end of string char
Packit 762fc5
 */
Packit 762fc5
Packit 762fc5
#define TIMEBUFSIZE (((sizeof(time_t)*5+1)>>1)+1)
Packit 762fc5
Packit 762fc5
Packit 762fc5
/*
Packit 762fc5
  New db_config
Packit 762fc5
  Not used yet, maybe someday.
Packit 762fc5
*/
Packit 762fc5
Packit 762fc5
/*  typedef struct _db_config { */
Packit 762fc5
/*    url_t* url; */
Packit 762fc5
/*    config* conf; */
Packit 762fc5
/*    int inout; */
Packit 762fc5
/*    int (*init)(url*,int,config*); */
Packit 762fc5
/*    char** (*readline)(_db_config*); */
Packit 762fc5
/*    int (*writeline)(_db_config*,db_line* line); */
Packit 762fc5
/*    int (*close)(_db_config*); */
Packit 762fc5
/*    int db_size; */
Packit 762fc5
/*    DB_FIELD* db_order; */
Packit 762fc5
/*    void* local; */  
Packit 762fc5
/*  }_db_config ; */
Packit 762fc5
Packit 762fc5
Packit 762fc5
#include "seltree.h"
Packit 762fc5
Packit 762fc5
typedef struct db_line {
Packit 762fc5
  byte* md5;
Packit 762fc5
  byte* sha1;
Packit 762fc5
  byte* rmd160;
Packit 762fc5
  byte* tiger;
Packit 762fc5
Packit 762fc5
  byte* sha256;
Packit 762fc5
  byte* sha512;
Packit 762fc5
Packit 762fc5
  byte* crc32; /* MHASH only */
Packit 762fc5
  byte* haval;
Packit 762fc5
  byte* gost;
Packit 762fc5
  byte* crc32b;
Packit 762fc5
  byte* whirlpool;
Packit 762fc5
Packit 762fc5
  acl_type* acl;
Packit 762fc5
  /* Something here.. */
Packit 762fc5
Packit 762fc5
  mode_t perm;
Packit 762fc5
  mode_t perm_o; /* Permission for tree traverse */
Packit 762fc5
  uid_t uid;
Packit 762fc5
  gid_t gid;
Packit 762fc5
  time_t atime;
Packit 762fc5
  time_t ctime;
Packit 762fc5
  time_t mtime;
Packit 762fc5
  AIDE_INO_TYPE inode;
Packit 762fc5
  nlink_t nlink;
Packit 762fc5
Packit 762fc5
  AIDE_OFF_TYPE size;
Packit 762fc5
  AIDE_OFF_TYPE size_o; /* ... */
Packit 762fc5
  AIDE_BLKCNT_TYPE bcount;
Packit 762fc5
  char* filename;
Packit 762fc5
  char* fullpath;
Packit 762fc5
  char* linkname;
Packit 762fc5
Packit 762fc5
  char *cntx;
Packit 762fc5
Packit 762fc5
  xattrs_type* xattrs;
Packit 762fc5
Packit 762fc5
  unsigned long e2fsattrs;
Packit 762fc5
Packit 762fc5
  /* Attributes .... */
Packit 762fc5
  DB_ATTR_TYPE attr;
Packit 762fc5
Packit 762fc5
} db_line;
Packit 762fc5
Packit 762fc5
typedef struct db_config {
Packit 762fc5
  
Packit 762fc5
  url_t* db_in_url;
Packit 762fc5
  FILE* db_in;
Packit 762fc5
  
Packit 762fc5
  url_t* db_new_url;
Packit 762fc5
  FILE* db_new;
Packit 762fc5
  
Packit 762fc5
  url_t* db_out_url;
Packit 762fc5
  FILE* db_out;
Packit 762fc5
  
Packit 762fc5
  int config_check;
Packit Service b99ba9
  int syslog_format;
Packit 762fc5
Packit 762fc5
  struct md_container *mdc_in;
Packit 762fc5
  struct md_container *mdc_out;
Packit 762fc5
Packit 762fc5
  struct db_line *line_db_in;
Packit 762fc5
  struct db_line *line_db_out;
Packit 762fc5
Packit 762fc5
  DB_ATTR_TYPE db_attrs;
Packit 762fc5
Packit 762fc5
#ifdef WITH_ZLIB
Packit 762fc5
  gzFile db_gzin;
Packit 762fc5
  gzFile db_gznew;
Packit 762fc5
  gzFile db_gzout;
Packit 762fc5
  /* Is dbout gzipped or not */
Packit 762fc5
  int gzip_dbout;
Packit 762fc5
  
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
  int db_in_size;
Packit 762fc5
  DB_FIELD* db_in_order;
Packit 762fc5
  
Packit 762fc5
  int db_new_size;
Packit 762fc5
  DB_FIELD* db_new_order;
Packit 762fc5
Packit 762fc5
  int db_out_size;
Packit 762fc5
  DB_FIELD* db_out_order;
Packit 762fc5
  
Packit 762fc5
  char* config_file;
Packit 762fc5
  char* config_version;
Packit 762fc5
Packit 762fc5
 
Packit 762fc5
  int do_dbnewmd;
Packit 762fc5
  int do_dboldmd; 
Packit 762fc5
#ifdef WITH_MHASH
Packit 762fc5
  int do_configmd;
Packit 762fc5
  MHASH confmd;
Packit 762fc5
  hashid confhmactype;
Packit 762fc5
  char* old_confmdstr;
Packit 762fc5
Packit 762fc5
  hashid dbhmactype;
Packit 762fc5
  MHASH dbnewmd;
Packit 762fc5
  MHASH dboldmd;
Packit 762fc5
#endif
Packit 762fc5
  char* old_dbnewmdstr;
Packit 762fc5
  char* old_dboldmdstr;
Packit 762fc5
Packit 762fc5
Packit 762fc5
  /* The following three a lists of rx_rule*s */
Packit 762fc5
  list* selrxlst;
Packit 762fc5
  list* equrxlst;
Packit 762fc5
  list* negrxlst;
Packit 762fc5
Packit 762fc5
  int verbose_level;
Packit 762fc5
  int database_add_metadata;
Packit 762fc5
  int report_detailed_init;
Packit 762fc5
  int report_base16;
Packit 762fc5
  int report_quiet;
Packit 762fc5
  int use_initial_errorsto;
Packit 762fc5
Packit 762fc5
#ifdef WITH_E2FSATTRS
Packit 762fc5
  unsigned long report_ignore_e2fsattrs;
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
  url_t* initial_report_url;
Packit Service b31cf3
  void* initial_report_fd;
Packit 762fc5
  
Packit 762fc5
  /* report_url is a list of url_t*s */
Packit 762fc5
  list* report_url;
Packit 762fc5
Packit 762fc5
  /* report_fd is a list of FILE*s */
Packit 762fc5
  list* report_fd;
Packit 762fc5
Packit 762fc5
  /* Report syslog */
Packit 762fc5
  
Packit 762fc5
  int report_syslog;
Packit 762fc5
  int report_db;
Packit 762fc5
  
Packit 762fc5
  /* defsyms is a list of symba*s */
Packit 762fc5
  list* defsyms;
Packit 762fc5
  /* so is groupsyms */
Packit 762fc5
  list* groupsyms;
Packit 762fc5
Packit 762fc5
  /* What are we supposed to do */
Packit 762fc5
  int action;
Packit 762fc5
Packit 762fc5
  /* Should we catch errors from mmapping */
Packit 762fc5
  int catch_mmap;
Packit 762fc5
Packit 762fc5
  time_t start_time;
Packit 762fc5
  time_t end_time;
Packit 762fc5
Packit 762fc5
  int symlinks_found;
Packit 762fc5
  DB_ATTR_TYPE attr;
Packit 762fc5
Packit 762fc5
#ifdef WITH_ACL  
Packit 762fc5
  int no_acl_on_symlinks;
Packit 762fc5
#endif
Packit 762fc5
  int warn_dead_symlinks;
Packit 762fc5
Packit 762fc5
  int grouped;
Packit 762fc5
Packit 762fc5
  int summarize_changes;
Packit 762fc5
Packit 762fc5
  char* root_prefix;
Packit 762fc5
  int root_prefix_length;
Packit 762fc5
Packit 762fc5
  char* limit;
Packit 762fc5
  pcre* limit_crx;
Packit 762fc5
Packit 762fc5
  struct seltree* tree;
Packit 762fc5
Packit 762fc5
} db_config;
Packit 762fc5
Packit 762fc5
#ifdef WITH_PSQL
Packit 762fc5
#include "libpq-fe.h"
Packit 762fc5
Packit 762fc5
typedef struct psql_data{
Packit 762fc5
  PGconn* conn;
Packit 762fc5
  char* table;
Packit 762fc5
  PGresult *res;
Packit 762fc5
  int des[db_unknown];
Packit 762fc5
  int curread;
Packit 762fc5
  int maxread;
Packit 762fc5
} psql_data;
Packit 762fc5
Packit 762fc5
#endif
Packit 762fc5
Packit 762fc5
#endif