int main(int argc, char ** argv)
{
    DIR * cleandir;
    struct dirent * curfile;
    unsigned long long curval;

	setlimits();
	if(argc!=3)
		usage();
	matchlimit = atoi(argv[1]);
	if(matchlimit == 0)
		usage();

    cleandir = opendir(argv[2]);
    if(cleandir == NULL)
    {
        perror(argv[2]);
        return 3;
    }

    while(curfile = readdir(cleandir))
    {
        if(curfile->d_name[0] == '.')
            continue;
        curval = load_rules(curfile->d_name);
        if(curval < matchlimit)
            printf("%s %lld\n", curfile->d_name, curval);
    }

	return 0;
}
Beispiel #2
0
int pa__init(pa_module*m) {
    pa_modargs *ma = NULL;
    struct userdata *u;
    pa_bool_t restore_device = TRUE, restore_volume = TRUE;

    pa_assert(m);

    if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
        pa_log("Failed to parse module arguments");
        goto fail;
    }

    u = pa_xnew(struct userdata, 1);
    u->core = m->core;
    u->hashmap = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
    u->table_file = pa_xstrdup(pa_modargs_get_value(ma, "table", NULL));
    u->modified = FALSE;
    u->subscription = NULL;
    u->sink_input_new_hook_slot = u->sink_input_fixate_hook_slot = u->source_output_new_hook_slot = NULL;
    u->save_time_event = NULL;

    m->userdata = u;

    if (pa_modargs_get_value_boolean(ma, "restore_device", &restore_device) < 0 ||
        pa_modargs_get_value_boolean(ma, "restore_volume", &restore_volume) < 0) {
        pa_log("restore_volume= and restore_device= expect boolean arguments");
        goto fail;
    }

    if (!(restore_device || restore_volume)) {
        pa_log("Both restrong the volume and restoring the device are disabled. There's no point in using this module at all then, failing.");
        goto fail;
    }

    if (load_rules(u) < 0)
        goto fail;

    u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK_INPUT|PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT, subscribe_callback, u);

    if (restore_device) {
        u->sink_input_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_NEW], (pa_hook_cb_t) sink_input_new_hook_callback, u);
        u->source_output_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_NEW], (pa_hook_cb_t) source_output_new_hook_callback, u);
    }

    if (restore_volume)
        u->sink_input_fixate_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], (pa_hook_cb_t) sink_input_fixate_hook_callback, u);

    pa_modargs_free(ma);
    return 0;

fail:
    pa__done(m);
    if (ma)
        pa_modargs_free(ma);

    return  -1;
}
Datum
connection_reload_config(PG_FUNCTION_ARGS)
{
	elog(DEBUG1, "reloading connection rules from configuration file");

	load_rules();

	elog(DEBUG1, "connection rules reloaded : %d rules found",
				 rules->n_rules);

	PG_RETURN_VOID();
}
/*
 * Probably the most important part - allocates the shared segment
 * with space for all the rules (and process info), loads the rules
 * from file and performs all the initialization necessary.
 */
static void
pg_limits_shmem_startup()
{

	bool	found = FALSE;
	char   *segment = NULL;

	if (prev_shmem_startup_hook)
		prev_shmem_startup_hook();

	/* Create or attach to the shared memory state (for the rules). */
	LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);

	segment = ShmemInitStruct(SEGMENT_NAME, SEGMENT_SIZE, &found);

#if (PG_VERSION_NUM < 90000)	/* since 9.0, it always throws an error */
	if (segment == NULL)
		elog(ERROR, "a call to ShmemInitStruct failed (connection_limits)");
#endif

	/* rules are placed first, then the cached backend info */
	rules = (rules_t*)(segment);
	backends = (BackendInfo*)(segment + offsetof(rules_t, rules) + sizeof(rule_t) * MAX_RULES);

	elog(DEBUG1, "initializing segment with connection limit rules (size: %lu B)",
		 SEGMENT_SIZE);

	/* Perform initialization if this is the first time we see the segment. */
	if (! found)
	{
		/*
		 * make sure the segment is empty (no rules, ...)
		 *
		 * load_rules() resets only the part where the rules are stored,
		 * and we need to reset the whole segment (including backend info)
		 */
		memset(rules, 0, SEGMENT_SIZE);

		load_rules();

		elog(DEBUG1, "shared memory segment successfully created, %d rules loaded",
					 rules->n_rules);
	}

	LWLockRelease(AddinShmemInitLock);
}
Beispiel #5
0
Keyswitch::Keyswitch(XKeyboard *keyboard, QWidget *parent) : QLabel(parent)
{
	keys=keyboard;
	QSettings * antico = new QSettings(QCoreApplication::applicationDirPath() + "/antico.cfg", QSettings::IniFormat, this);
	antico->beginGroup("Style");
	map_path = antico->value("path").toString()+"/language/";
	antico->endGroup(); //Style
	xkbConf = X11tools::loadXKBconf();
	if (xkbConf->status!=DONT_USE_XKB) {
		load_rules();
		qDebug()<<"XKB status : " <<xkbConf->status;
		if (xkbConf->status==USE_XKB)
			set_xkb();
		init();
		if (groupeName.count()>1 || xkbConf->showSingle) {
			draw_icon();
			createMenu();
		}
	}

}
bool http_server::load_hosts(const xmlconf& conf, const general_conf& general_conf)
{
	const char* host;
	size_t hostlen;
	const char* value;
	size_t len;
	bool b;

	for (unsigned i = 0; conf.get_child(i, host, hostlen, "config", "hosts", NULL); i++) {
		bool def;
		if (!conf.get_value(def, "config", "hosts", host, "default", NULL)) {
			def = false;
		}

		const char* document_root;
		size_t document_root_len;
		if (!conf.get_value(document_root, document_root_len, "config", "hosts", host, "document_root", NULL)) {
			logger::instance().log(logger::LOG_ERROR, "Empty document root for host %s.", host);
			return false;
		} else {
			if (document_root[document_root_len - 1] == '/') {
				document_root_len--;
			}
		}

		bool log_requests;
		char dir[PATH_MAX + 1];
		const char* filename = NULL;
		const char* log_format = general_conf.log_format;
		size_t bufsize = general_conf.log_buffer_size;
		size_t access_log_max_file_size = general_conf.access_log_max_file_size;

		if (general_conf.log_requests == TRIBOOL_FALSE) {
			log_requests = false;
		} else {
			if (conf.get_value(b, "config", "hosts", host, "log_requests", NULL)) {
				log_requests = b;
			} else {
				log_requests = (general_conf.log_requests == TRIBOOL_TRUE) ? true : false;
			}

			if (log_requests) {
				if (!conf.get_value(value, len, "config", "hosts", host, "access_log", NULL)) {
					logger::instance().log(logger::LOG_ERROR, "Empty access log for host %s.", host);
					return false;
				}

				if (!get_dirname_basename(value, len, dir, filename)) {
					return false;
				}

				if (conf.get_value(value, len, "config", "hosts", host, "log_format", NULL)) {
					log_format = value;
				}

				if (conf.get_value(bufsize, "config", "hosts", host, "log_buffer_size", NULL)) {
					if (bufsize > 1024) {
						bufsize = 1024;

						logger::instance().log(logger::LOG_INFO, "Log buffer size too big, set to %u KB.", bufsize);
					}
				}

				if (conf.get_value(access_log_max_file_size, "config", "hosts", host, "access_log_max_file_size", NULL)) {
					if (access_log_max_file_size < 32) {
						access_log_max_file_size = 32;

						logger::instance().log(logger::LOG_INFO, "Access log maximum file size too small, set to %u KB.", access_log_max_file_size);
					} else if (access_log_max_file_size > 4 * 1024 * 1024) {
						access_log_max_file_size = 4 * 1024 * 1024;

						logger::instance().log(logger::LOG_INFO, "Access log maximum file size too big, set to %u KB.", access_log_max_file_size);
					}
				}
			}
		}

		bool have_dirlisting;
		if (general_conf.have_dirlisting == TRIBOOL_FALSE) {
			have_dirlisting = false;
		} else {
			if (conf.get_value(b, "config", "hosts", host, "directory_listing", NULL)) {
				have_dirlisting = b;
			} else {
				have_dirlisting = (general_conf.have_dirlisting == TRIBOOL_TRUE) ? true : false;
			}
		}

		virtual_hosts::vhost* vhost;
		if ((vhost = _M_vhosts.add(host, hostlen, document_root, document_root_len, have_dirlisting, log_requests, def)) == NULL) {
			return false;
		}

		if (log_requests) {
			if (!vhost->log->create(dir, filename, log_format, bufsize * 1024, access_log_max_file_size * 1024L)) {
				logger::instance().log(logger::LOG_ERROR, "Couldn't create access log for host %s.", host);
				return false;
			}
		}

		if (have_dirlisting) {
			if (conf.get_value(value, len, "config", "hosts", host, "directory_listing_footer", NULL)) {
				if (!vhost->dir_listing->load_footer(value)) {
					logger::instance().log(logger::LOG_ERROR, "Couldn't load footer file %s for host %s.", value, host);
					return false;
				}
			} else if (general_conf.footer_file) {
				if (!vhost->dir_listing->load_footer(general_conf.footer_file)) {
					logger::instance().log(logger::LOG_ERROR, "Couldn't load footer file %s for host %s.", general_conf.footer_file, host);
					return false;
				}
			}
		}

		for (unsigned j = 0; conf.get_child(j, value, len, "config", "hosts", host, "aliases", NULL); j++) {
			if (!_M_vhosts.add_alias(vhost, value, len)) {
				return false;
			}
		}

		if (!load_rules(conf, general_conf, host, vhost->rules)) {
			return false;
		}
	}

	return (_M_vhosts.count() > 0);
}
Beispiel #7
0
static STANDARDIZER *
CreateStd(char *lextab, char *gaztab, char *rultab)
{
    STANDARDIZER        *std;
    LEXICON             *lex;
    LEXICON             *gaz;
    RULES               *rules;
    int                  err;
    int                  SPIcode;

    DBG("Enter: CreateStd");
    SPIcode = SPI_connect();
    if (SPIcode != SPI_OK_CONNECT) {
        elog(ERROR, "CreateStd: couldn't open a connection to SPI");
    }

    std = std_init();
    if (!std)
        elog(ERROR, "CreateStd: could not allocate memory (std)");

    lex = lex_init(std->err_p);
    if (!lex) {
        std_free(std);
        SPI_finish();
        elog(ERROR, "CreateStd: could not allocate memory (lex)");
    }

    err = load_lex(lex, lextab);
    if (err == -1) {
        lex_free(lex);
        std_free(std);
        SPI_finish();
        elog(ERROR, "CreateStd: failed to load '%s' for lexicon", lextab);
    }

    gaz = lex_init(std->err_p);
    if (!gaz) {
        lex_free(lex);
        std_free(std);
        SPI_finish();
        elog(ERROR, "CreateStd: could not allocate memory (gaz)");
    }

    err = load_lex(gaz, gaztab);
    if (err == -1) {
        lex_free(gaz);
        lex_free(lex);
        std_free(std);
        SPI_finish();
        elog(ERROR, "CreateStd: failed to load '%s' for gazeteer", gaztab);
    }

    rules = rules_init(std->err_p);
    if (!rules) {
        lex_free(gaz);
        lex_free(lex);
        std_free(std);
        SPI_finish();
        elog(ERROR, "CreateStd: could not allocate memory (rules)");
    }

    err = load_rules(rules, rultab);
    if (err == -1) {
        rules_free(rules);
        lex_free(gaz);
        lex_free(lex);
        std_free(std);
        SPI_finish();
        elog(ERROR, "CreateStd: failed to load '%s' for rules", rultab);
    }

    std_use_lex(std, lex);
    std_use_gaz(std, gaz);
    std_use_rules(std, rules);
    std_ready_standardizer(std);

    SPI_finish();

    return std;
}
Beispiel #8
0
void load_config( _SaganDebug *debug, _SaganConfig *config  ) { 

FILE *sagancfg; 

char normfile[MAXPATH];

char *filename;
char ruleset[MAXPATH];

char tmpbuf[CONFBUF];
char tmpstring[CONFBUF];

char *sagan_option=NULL;
char *sagan_var=NULL;
char *ptmp=NULL;

char *tok=NULL;

int i,check;

/* Set some system defaults */

snprintf(config->sagan_alert_filepath, sizeof(config->sagan_alert_filepath), "%s", ALERTLOG);
snprintf(config->sagan_lockfile, sizeof(config->sagan_lockfile), "%s", LOCKFILE);
snprintf(config->sagan_log_path, sizeof(config->sagan_log_path), "%s", SAGANLOGPATH);
config->sagan_proto = 17;		/* Default to UDP */
config->max_output_threads = MAX_OUTPUT_THREADS;
config->max_processor_threads = MAX_PROCESSOR_THREADS;

/* Start loading configuration */

rulestruct = (_Rule_Struct *) realloc(rulestruct, (counters->rulecount+1) * sizeof(_Rule_Struct));

/* Gather information for the master configuration file */


if ((sagancfg = fopen(config->sagan_config, "r")) == NULL) {
   fprintf(stderr, "[%s, line %d] Cannot open configuration file (%s)\n", __FILE__,  __LINE__, config->sagan_config);
   exit(1);
   }

while(fgets(tmpbuf, sizeof(tmpbuf), sagancfg) != NULL) {
     if (tmpbuf[0] == '#') continue;
     if (tmpbuf[0] == ';') continue;
     if (tmpbuf[0] == 10 ) continue;
     if (tmpbuf[0] == 32 ) continue;

     sagan_option = strtok_r(tmpbuf, " ", &tok);

     if (!strcmp(remrt(sagan_option), "max_output_threads")) { 
	 sagan_var = strtok_r(NULL, " ", &tok);
         config->max_output_threads = atol(sagan_var);
	 }

     if (!strcmp(remrt(sagan_option), "max_processor_threads")) {
	 sagan_var = strtok_r(NULL, " ", &tok);
         config->max_processor_threads = atol(sagan_var);
         }

     if (!strcmp(remrt(sagan_option), "disable_dns_warnings")) { 
         sagan_log(config, 0, "Supressing DNS warnings");
         config->disable_dns_warnings = 1;
	 }

     if (!strcmp(remrt(sagan_option), "syslog_src_lookup")) { 
         sagan_log(config, 0, "DNS lookup of source address supplied by syslog daemon");
	 config->syslog_src_lookup = 1; 
	 }


     if (!strcmp(sagan_option, "sagan_host")) {
        snprintf(config->sagan_host, sizeof(config->sagan_host)-1, "%s", strtok_r(NULL, " " , &tok));
        config->sagan_host[strlen(config->sagan_host)-1] = '\0';
        }

     if (!strcmp(sagan_option, "sagan_port")) {
         sagan_var = strtok_r(NULL, " ", &tok);
	 config->sagan_port = atoi(sagan_var);
         }

#ifndef HAVE_LIBESMTP
if (!strcmp(sagan_option, "send-to") || !strcmp(sagan_option, "min_email_priority")) 
   sagan_log(config,1, "\"libesmtp\" support not found. Re-compile with ESMTP support or disable in the sagan.conf.");
#endif

#ifdef HAVE_LIBESMTP

   if (!strcmp(sagan_option, "send-to")) { 
      sagan_var = strtok_r(NULL, " ", &tok);
      snprintf(config->sagan_esmtp_to, sizeof(config->sagan_esmtp_to), "%s", sagan_var);
      remrt(config->sagan_esmtp_to);
      config->sagan_esmtp_flag=1;
      config->sagan_sendto_flag=1;
      }

   if (!strcmp(sagan_option, "min_email_priority")) {
       sagan_var = strtok_r(NULL, " ", &tok);
       config->min_email_priority = atoi(sagan_var);
       }

#endif

#ifndef HAVE_LIBPCAP
if (!strcmp(sagan_option, "plog_interface") || !strcmp(sagan_option, "plog_logdev") || !strcmp(sagan_option, "plog_port")) 
   sagan_log(config,1, "\"libpcap\" support not found. Re-compile with PCAP support or disable in the sagan.conf.");
#endif

#ifdef HAVE_LIBPCAP

    if (!strcmp(sagan_option, "plog_interface")) { 
       snprintf(config->plog_interface, sizeof(config->plog_interface)-1, "%s", strtok_r(NULL, " ", &tok));
       config->plog_interface[strlen(config->plog_interface)-1] = '\0';
       config->plog_flag=1;
       }

    if (!strcmp(sagan_option, "plog_logdev")) { 
       snprintf(config->plog_logdev, sizeof(config->plog_logdev)-1, "%s", strtok_r(NULL, " ", &tok));
       config->plog_logdev[strlen(config->plog_logdev)-1] = '\0';
       config->plog_flag=1;
       }

    if (!strcmp(sagan_option, "plog_port")) {
       sagan_var = strtok_r(NULL, " ", &tok); 
       config->plog_port = atoi(sagan_var);
       config->plog_flag = 1;
       }

#endif

#if defined(HAVE_LIBMYSQLCLIENT_R) || defined(HAVE_LIBPQ)

     if (!strcmp(sagan_option, "sagan_proto")) { 
        sagan_var = strtok_r(NULL, " ", &tok);
	config->sagan_proto = atoi(sagan_var);
	}
     
     if (!strcmp(sagan_option, "sagan_hostname")) { 
        snprintf(config->sagan_hostname, sizeof(config->sagan_hostname)-1, "%s", strtok_r(NULL, " ", &tok));
	config->sagan_hostname[strlen(config->sagan_hostname)-1] = '\0';
	}

     if (!strcmp(sagan_option, "sagan_interface")) { 
        snprintf(config->sagan_interface, sizeof(config->sagan_interface)-1, "%s", strtok_r(NULL, " ", &tok)); 
	config->sagan_interface[strlen(config->sagan_interface)-1] = '\0';
	}

     if (!strcmp(sagan_option, "sagan_filter")) { 
        snprintf(config->sagan_filter, sizeof(config->sagan_filter)-1, "%s", strtok_r(NULL, " ", &tok)); 
	config->sagan_filter[strlen(config->sagan_filter)-1] = '\0';
	}
    
     if (!strcmp(sagan_option, "sagan_detail")) {  
         sagan_var = strtok_r(NULL, " ", &tok);
         config->sagan_detail = atoi(sagan_var);
	 }

#endif

#ifndef HAVE_LIBLOGNORM
if (!strcmp(sagan_option, "normalize:")) {
   sagan_log(config, 0, "WARNING: Sagan was not compiled with \"liblognorm\" support!");
   sagan_log(config, 0, "WARNING: Sagan will continue,  but _without_ liblognorm!");
   }
#endif

#ifdef HAVE_LIBLOGNORM

/*
 We load the location for liblognorm's 'rule base/samples'.  We don't want to 
 load them quiet yet.  We only want to load samples we need,  so we do the
 actual ln_loadSamples() after the configuration file and all rules have
 been analyzed */

if (!strcmp(sagan_option, "normalize:")) {
	liblognormstruct = (liblognorm_struct *) realloc(liblognormstruct, (liblognorm_count+1) * sizeof(liblognorm_struct));
	
	sagan_var = strtok_r(NULL, ",", &tok);
	remspaces(sagan_var);
	snprintf(liblognormstruct[liblognorm_count].type, sizeof(liblognormstruct[liblognorm_count].type), "%s", sagan_var);

	snprintf(tmpstring, sizeof(tmpstring), "%s", strtok_r(NULL, ",", &tok));
	remspaces(tmpstring);
	tmpstring[strlen(tmpstring)-1] = '\0';
	strlcpy(normfile, sagan_replace_str(tmpstring, "$RULE_PATH", config->sagan_rule_path), sizeof(normfile));
	snprintf(liblognormstruct[liblognorm_count].filepath, sizeof(liblognormstruct[liblognorm_count].filepath), "%s", normfile);

	liblognorm_count++;
}

#endif

if (!strcmp(sagan_option, "output")) {
     
     config->output_thread_flag = 1;

     sagan_var = strtok_r(NULL," ", &tok);

     if (!strcmp(sagan_var, "external:")) {
        config->sagan_ext_flag=1;
        snprintf(config->sagan_extern, sizeof(config->sagan_extern), "%s", strtok_r(NULL, " ", &tok));
        if (strstr(strtok_r(NULL, " ", &tok), "parsable")) config->sagan_exttype=1;
        }


#ifdef WITH_SNORTSAM
if (!strcmp(sagan_var, "alert_fwsam:")) { 
       snprintf(config->sagan_fwsam_info, sizeof(config->sagan_fwsam_info), "%s", remrt(strtok_r(NULL, " ", &tok)));
       config->sagan_fwsam_flag=1; 
       }
#endif

#ifndef HAVE_LIBDNET
if (!strcmp(sagan_var, "unified2:")) { 
   sagan_log(config, 0,"\"libdnet\" support not found.  This is needed for unified2."); 
   sagan_log(config, 1, "Re-compile with libdnet support or disable in the sagan.conf.");
   }
#endif

#ifdef HAVE_LIBDNET

if (!strcmp(sagan_var, "unified2:")) { 
  
  	   config->sagan_unified2_flag = 1;
	   
	   ptmp = sagan_var; 
	   remrt(ptmp);

	   while (ptmp != NULL ) {
	     
	     if (!strcmp(ptmp, "filename")) { 
	        ptmp = strtok_r(NULL, ",", &tok);
	 	snprintf(config->unified2_filepath, sizeof(config->unified2_filepath), "%s/%s", config->sagan_log_path, ptmp);
		}

	     if (!strcmp(ptmp, "limit")) { 
	        ptmp = strtok_r(NULL, " ", &tok);
	        config->unified2_limit = atoi(ptmp) * 1024 * 1024;
		}

             if (!strcmp(ptmp, "nostamp")) config->unified2_nostamp = 1;
	   
	   ptmp = strtok_r(NULL, " ", &tok);

	   }
}

#endif

#ifndef HAVE_LIBPRELUDE
	if (!strcmp(sagan_var, "prelude:"))
           sagan_log(config,1, " libprelude support not found. Re-compile with Prelude support or disable in the sagan.conf.");
#endif 

#ifdef HAVE_LIBPRELUDE
	
	if (!strcmp(sagan_var, "prelude:")) { 
	   ptmp = sagan_var; 

	   while (ptmp != NULL ) { 

	     if (!strcmp(ptmp, "profile")) { 
	         ptmp = strtok_r(NULL, " ", &tok);
		 snprintf(config->sagan_prelude_profile, sizeof(config->sagan_prelude_profile), "%s", ptmp); 
		 remrt(config->sagan_prelude_profile);
		 config->sagan_prelude_flag=1;
		 }
           
	   ptmp = strtok_r(NULL, "=", &tok);
	   }
	}
#endif


#ifdef HAVE_LIBESMTP

	if (!strcmp(sagan_var, "email:")) { 
	   ptmp = sagan_var;

	   while (ptmp != NULL ) { 

             if (!strcmp(ptmp, "from")) {
                ptmp = strtok_r(NULL, " ", &tok);
                snprintf(config->sagan_esmtp_from, sizeof(config->sagan_esmtp_from), "%s", ptmp);
		remrt(config->sagan_esmtp_from);
                }

             if (!strcmp(ptmp, "smtpserver")) {
                ptmp = strtok_r(NULL, " ", &tok);
                snprintf(config->sagan_esmtp_server, sizeof(config->sagan_esmtp_server), "%s", ptmp);
		remrt(config->sagan_esmtp_server);
                }

          ptmp = strtok_r(NULL, "=", &tok);    
	  }

	}
#endif


#if defined(HAVE_LIBMYSQLCLIENT_R) || defined(HAVE_LIBPQ)

	/* output type (database, etc) */

	if (!strcmp(sagan_var, "database:")) {
	   sagan_var = strtok_r(NULL, ",", &tok);
	
	   /* Type (only "log" is used right now */

	   if (!strcmp(sagan_var, "log")) { 
	      sagan_var = strtok_r(NULL, ",", &tok); 
	      }

	      /* MySQL/PostgreSQL/Oracle/etc */

	      remspaces(sagan_var);


	      if (!strcmp(sagan_var, "mysql" )) { 
#ifndef HAVE_LIBMYSQLCLIENT_R
   	         sagan_log(config, 1,"MySQL support not found. Re-compile with MySQL support or disable in the sagan.conf.");
#endif
	         config->dbtype=1; 
	         }

	      if (!strcmp(sagan_var, "postgresql" )) { 
#ifndef HAVE_LIBPQ
		 sagan_log(config, 1,"PostgreSQL support not found. Re-compile with PostgreSQL support or disable in the sagan.conf.");
#endif
		 config->dbtype=2; 
		 }


	      sagan_var = strtok_r(NULL, ",", &tok);
	      remrt(sagan_var);					/* rm NL */
	      
	      strlcpy(tmpbuf, sagan_var, sizeof(tmpbuf));

	      ptmp = strtok_r(tmpbuf, "=", &tok);

	      while (ptmp != NULL) { 
	        remspaces(ptmp); 

	        if (!strcmp(ptmp, "user")) { 
		   ptmp = strtok_r(NULL, " ", &tok);
		   snprintf(config->dbuser, sizeof(config->dbuser), "%s", ptmp);
		   }

                if (!strcmp(ptmp , "password")) {
		   ptmp = strtok_r(NULL, " ", &tok);
		   snprintf(config->dbpassword, sizeof(config->dbpassword), "%s", ptmp);
                   }

		if (!strcmp(ptmp, "dbname")) { 
		   ptmp = strtok_r(NULL, " ", &tok);
		   snprintf(config->dbname, sizeof(config->dbname), "%s", ptmp);
		   }

		if (!strcmp(ptmp, "host")) { 
		   ptmp = strtok_r(NULL, " ", &tok);
		   snprintf(config->dbhost, sizeof(config->dbhost), "%s", ptmp);
		   }

		if (!strcmp(ptmp, "port")) {
		   config->dbport = atoi(ptmp);
		   }

	      ptmp = strtok_r(NULL, "=", &tok);


	     }
	   
	   }
#endif      
   }
       
     /* "var" */

     if (!strcmp(sagan_option, "var")) {
         sagan_var = strtok_r(NULL, " ", &tok);

	if (config->sagan_fifo_flag == 0 ) { 		/* File overides FIFO settings */

        if (!strcmp(sagan_var, "FIFO" )) {
	   snprintf(config->sagan_fifo, sizeof(config->sagan_fifo), "%s", strtok_r(NULL, " ", &tok));
           config->sagan_fifo[strlen(config->sagan_fifo)-1] = '\0'; 
	   }
	
	}

        if (!strcmp(sagan_var, "RULE_PATH" )) {
	   snprintf(config->sagan_rule_path, sizeof(config->sagan_rule_path), "%s", strtok_r(NULL, " ", &tok));
	   config->sagan_rule_path[strlen(config->sagan_rule_path)-1] = '\0';
	   }

        if (!strcmp(sagan_var, "LOCKFILE" )) {
	   snprintf(config->sagan_lockfile, sizeof(config->sagan_lockfile), "%s", strtok_r(NULL, " ", &tok));
           config->sagan_lockfile[strlen(config->sagan_lockfile)-1] = '\0'; 
	   }

        if (!strcmp(sagan_var, "ALERTLOG" )) {
           snprintf(config->sagan_alert_filepath, sizeof(config->sagan_alert_filepath), "%s", strtok_r(NULL, " ", &tok));
           config->sagan_alert_filepath[strlen(config->sagan_alert_filepath)-1] = '\0'; 
	   }
	
	if (!strcmp(sagan_var, "SAGANLOGPATH" )) {
           snprintf(config->sagan_log_path, sizeof(config->sagan_log_path), "%s", strtok_r(NULL, " ", &tok));
           config->sagan_log_path[strlen(config->sagan_log_path)-1] = '\0';
           }
	}

/* "include */

     if (!strcmp(sagan_option, "include" )) {

         snprintf(tmpstring, sizeof(tmpstring), "%s", strtok_r(NULL, " ", &tok));

         tmpstring[strlen(tmpstring)-1] = '\0';
	
         strlcpy(ruleset, sagan_replace_str(tmpstring, "$RULE_PATH", config->sagan_rule_path), sizeof(ruleset));

	 filename=sagan_getfilename(ruleset);   /* Get the file name to figure out "what" we're loading */

         if (!strcmp(filename, "classification.config"))
            {
                   load_classifications(debug, config, ruleset);
            }

         if (!strcmp(filename, "reference.config"))
            {
                   load_reference(debug, config, ruleset);
            }

	 /* It's not a classifcations file or reference,  so it must be a ruleset */

         if (strcmp(filename, "reference.config") && strcmp(filename, "classification.config"))  {
                   
		   load_rules(debug, config,  ruleset);
          }
     }
}

fclose(sagancfg);

/* Check rules for duplicate sid.  We can't have that! */

for (i = 0; i < counters->rulecount; i++) {
   for ( check = i+1; check < counters->rulecount; check ++) {
       if (!strcmp (rulestruct[check].s_sid, rulestruct[i].s_sid ))
            sagan_log(config, 1, "[%s, line %d] Detected duplicate signature id [sid] number %s.  Please correct this.", __FILE__, __LINE__, rulestruct[check].s_sid, rulestruct[i].s_sid);
       }
   }

/* If we have the "send-to" option,  verify the configuration has the proper smtpserver, etc.  */

#ifdef HAVE_LIBESMTP

if (config->sagan_esmtp_flag && !strcmp(config->sagan_esmtp_server, "")) sagan_log(config, 1, "[%s, line %d] Configuration SMTP 'smtpserver' field is missing! |%s|", __FILE__, __LINE__, config->sagan_esmtp_server);
if (config->sagan_esmtp_flag && !strcmp(config->sagan_esmtp_from, "" )) sagan_log(config, 1, "[%s, line %d] Configuration SMTP 'from' field is missing!", __FILE__,  __LINE__);

#endif 

if (!strcmp(config->sagan_fifo, "")) sagan_log(config, 1, "No FIFO option found which is required! Aborting!");
if (!strcmp(config->sagan_host, "" )) sagan_log(config, 1, "The 'sagan_host' option was not found and is required.");
if ( config->sagan_port == 0 ) sagan_log(config, 1, "The 'sagan_port' option was not set and is required.");

}