Esempio n. 1
0
int attach_context(DSPAM_CTX *CTX, void *dbh) {
  int maxtries = 1, tries = 0;
  int r;

  if (!_ds_read_attribute(agent_config, "DefaultProfile"))
    return dspam_attach(CTX, dbh);

  /* Perform failover if an attach fails */

  if (_ds_read_attribute(agent_config, "FailoverAttempts"))
    maxtries = atoi(_ds_read_attribute(agent_config, "FailoverAttempts"));

  r = dspam_attach(CTX, dbh);
  while (r && tries < maxtries) {
    char key[128];
    char *failover;

    snprintf(key, sizeof(key), "Failover.%s", _ds_read_attribute(agent_config, "DefaultProfile"));

    failover = _ds_read_attribute(agent_config, key);

    if (!failover) {
      LOG(LOG_ERR, ERR_AGENT_FAILOVER_OUT);
      return r;
    }

    LOG(LOG_WARNING, ERR_AGENT_FAILOVER, failover);
    _ds_overwrite_attribute(agent_config, "DefaultProfile", failover);

    if (dspam_clearattributes(CTX)) {
      LOG(LOG_ERR, ERR_AGENT_CLEAR_ATTRIB);
      return r;
    }

    set_libdspam_attributes(CTX);

    tries++;
    r = dspam_attach(CTX, dbh);
  }

  return r;
}
Esempio n. 2
0
 /**
  *      Usage:
  *              CTX = attach_ctx_dbaccess(CTX);
  *
  29903: [3/2/2005 22:34:24] bailing on error 22
  29903: [3/2/2005 22:34:24] received invalid result (! DSR_ISSPAM || DSR_INNOCENT || DSR_ISWHITELISTED): 22
         -> happened because read_emailmem() was not returning the message ptr correctly...
  */
 DSPAM_CTX * attach_ctx_dbaccess(DSPAM_CTX * CTX) {

         if (dspam_clearattributes(CTX)) {
                 log_write(0, LOG_MAIN, "dspam_clearattributes failed!");
         }

         dspam_addattribute(CTX, "MySQLServer", (const char *)hostname);
         dspam_addattribute(CTX, "MySQLPort", (const char *)"3306");
         dspam_addattribute(CTX, "MySQLUser", (const char *)username);
         dspam_addattribute(CTX, "MySQLPass", (const char *)password);
         dspam_addattribute(CTX, "MySQLDb", (const char *)database);
         dspam_addattribute(CTX, "IgnoreHeader", (const char *)spamflag);

         if (dspam_attach(CTX, (void *)NULL)) {
                 log_write(0, LOG_MAIN, "dspam_attach failed!");
                 CTX = NULL;
         }

         return(CTX);
 } /** attach_ctx_dbaccess */