Example #1
0
int process_probs (DSPAM_CTX *CTX, int age) {
  struct _ds_storage_record *sr;
  struct _ds_spam_stat s;
  ds_diction_t del;
  int delta;

#ifdef DEBUG
  printf("Processing probabilities; age: %d\n", age);
#endif 

  del = ds_diction_create(196613);
  if (del == NULL)
    return -1;
  sr = _ds_get_nexttoken (CTX);
  while (sr != NULL)
  {
    s.innocent_hits = sr->innocent_hits;
    s.spam_hits = sr->spam_hits;
    s.probability = 0.00000;
    _ds_calc_stat(CTX, NULL, &s, DTT_DEFAULT, NULL);
    if (s.probability >= 0.3500 && s.probability <= 0.6500) {
      delta = (((time (NULL) - sr->last_hit) / 60) / 60) / 24;
      if (age == 0 || delta > age)
        ds_diction_touch(del, sr->token, "", 0);
    }
    free (sr);
    sr = _ds_get_nexttoken (CTX);
  }
 
  _ds_delall_spamrecords(CTX, del);
  ds_diction_destroy(del);

  return 0;
}
Example #2
0
int
dump_user (const char *username)
{
  struct passwd *p;
  struct _ds_storage_record *record;
  DSPAM_CTX *CTX;

  p = getpwnam (username);
  if (p == NULL)
  {
    fprintf (stderr, "Unable to obtain uid for user %s\n", username);
    return EUNKNOWN;
  }

  CTX = dspam_create (username, NULL, _ds_read_attribute(agent_config, "Home"), DSM_CLASSIFY, 0);
  open_mtx = CTX;
  if (CTX == NULL)
  {
    fprintf (stderr, "Could not init context: %s\n", strerror (errno));
    return EUNKNOWN;
  }

  set_libdspam_attributes(CTX);
  if (dspam_attach(CTX, NULL)) {
    LOG (LOG_WARNING, "unable to attach dspam context");
    fprintf (stderr, "Unable to attach DSPAM context\n");
    return EFAILURE;
  }

  printf
    ("insert into dspam_stats (uid, spam_learned, innocent_learned, spam_misclassified, innocent_misclassified, spam_corpusfed, innocent_corpusfed, spam_classified, innocent_classified) values(%d, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld);\n",
     (int) p->pw_uid, CTX->totals.spam_learned, CTX->totals.innocent_learned,
     CTX->totals.spam_misclassified, CTX->totals.innocent_misclassified,
     CTX->totals.spam_corpusfed, CTX->totals.innocent_corpusfed,
     CTX->totals.spam_classified, CTX->totals.innocent_classified);

  record = _ds_get_nexttoken (CTX);
  while (record != NULL)
  {
    printf
      ("insert into dspam_token_data (uid, token, spam_hits, innocent_hits, last_hit) values(%d, \"%"LLU_FMT_SPEC"\", %ld, %ld, %ld);\n",
       (int) p->pw_uid, record->token, record->spam_hits,
       record->innocent_hits, (long) record->last_hit);
    record = _ds_get_nexttoken (CTX);
  }

  dspam_destroy (CTX);
  open_mtx = NULL;
  return 0;
}
Example #3
0
int process_unused (DSPAM_CTX *CTX, int any, int quota, int nospam, int onehit) {
  struct _ds_storage_record *sr;
  ds_diction_t del;
  time_t t = time(NULL);
  int delta, toe = 0, tum = 0;
  agent_pref_t PTX;
                                                                                
#ifdef DEBUG
  printf("Processing unused; any: %d quota: %d nospam: %d onehit: %d\n",
         any, quota, nospam, onehit);
#endif

  PTX = _ds_pref_load(agent_config, CTX->username, _ds_read_attribute(agent_config, "Home"), NULL);

  if (PTX == NULL || PTX[0] == 0) {
    if (PTX)
      _ds_pref_free(PTX);
    PTX = pref_config();
  }
                                                                                
  if (!strcasecmp(_ds_pref_val(PTX, "trainingMode"), "toe")) {
#ifdef DEBUG
    printf("Limiting unused token purges for user %s - TOE Training Mode Set\n", CTX->username);
#endif
    toe = 1;
  }

  if (!strcasecmp(_ds_pref_val(PTX, "trainingMode"), "tum")) {
#ifdef DEBUG
    printf("Limiting unused token purges for user %s - TUM Training Mode Set\n", CTX->username);
#endif
    tum = 1;
  }

  if (PTX)
    _ds_pref_free(PTX);

  del = ds_diction_create(196613);
  if (del == NULL)
    return -1;
  sr = _ds_get_nexttoken (CTX);
  while (sr != NULL)
  {
    delta = (((t - sr->last_hit) / 60) / 60) / 24;
    if (!toe && (any == 0 || delta > any))
    { 
      if (!tum || sr->innocent_hits + sr->spam_hits < 50)
        ds_diction_touch(del, sr->token, "", 0);
    }
    else if ((sr->innocent_hits*2) + sr->spam_hits < 5)
    { 
      if (quota == 0 || delta > quota)
      {
        ds_diction_touch(del, sr->token, "", 0);
      }
      else if (sr->innocent_hits == 0 && sr->spam_hits == 1 &&
          (nospam == 0 || delta > nospam))
      {
        ds_diction_touch(del, sr->token, "", 0);
      }
      else if (sr->innocent_hits == 1 && sr->spam_hits == 0 &&
          (onehit == 0 || delta > onehit))
      {
        ds_diction_touch(del, sr->token, "", 0);
      }
    }
 
    free (sr);
    sr = _ds_get_nexttoken (CTX);
  }
                                                                                
  _ds_delall_spamrecords(CTX, del);
  ds_diction_destroy(del);
                                                                                
  return 0;
}