void dieout (int signal) { fprintf (stderr, "terminated.\n"); if (open_ctx != NULL) dspam_destroy (open_ctx); if (open_mtx != NULL) dspam_destroy (open_mtx); _ds_destroy_config(agent_config); exit (EXIT_SUCCESS); }
int process_all_users (void) { DSPAM_CTX *CTX; char *user; CTX = dspam_create (NULL, NULL, _ds_read_attribute(agent_config, "Home"), DSM_TOOLS, 0); open_ctx = CTX; if (CTX == NULL) { fprintf (stderr, "Could not initialize context: %s\n", strerror (errno)); return EFAILURE; } 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; } user = _ds_get_nextuser (CTX); while (user != NULL) { dump_user (user); user = _ds_get_nextuser (CTX); } dspam_destroy (CTX); open_ctx = NULL; return 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; }
// create the context DspamCtx(int mode, unsigned flags) { m_ctx = dspam_create ( DSPAM_USER_NAME, // user name used as base file name NULL, // no group mApplication->GetLocalDir(), mode, flags ); if ( !m_ctx ) return; // use default algorithm/tokenizer m_ctx->algorithms = DSA_GRAHAM | DSA_BURTON | DSP_GRAHAM; m_ctx->tokenizer = DSZ_CHAIN; // unlimit the hash table size for now to avoid "hash table full" errors dspam_addattribute(m_ctx, "HashAutoExtend", "on"); // and now that the attributes are set we can attach the context to the // storage if ( dspam_attach(m_ctx, ms_hashMap) != 0 ) { dspam_destroy(m_ctx); m_ctx = NULL; } else if ( !ms_hashMap ) { // this is the first context we create so it has just mapped the hash // database into memory: tell it to not unmap it when we're done with // it and keep the pointer to reuse for the subsequent contexts _hash_drv_storage *storage = (_hash_drv_storage *)m_ctx->storage; storage->dbh_attached = 1; ms_hashMap = storage->map; ms_hashLock = storage->lock; } }
// destroy the context ~DspamCtx() { if ( m_ctx ) dspam_destroy(m_ctx); }
int report_spam(int spamflag) { int sflag = 0; char * message = malloc(1); DSPAM_CTX * CTX = NULL; /** DSPAM Context */ struct _ds_spam_signature SIG; /** Example signature */ message = read_emailmem(message); switch (spamflag) { case SPAMREPT: /** set up the context for error correction as spam */ CTX = dspam_create((char *)sender_address, NULL, NULL, DSM_PROCESS, DSF_CHAINED); CTX = attach_ctx_dbaccess(CTX); if (CTX == NULL) { log_write(0, LOG_MAIN, "ERROR: dspam_create failed!\n"); sflag = 1; } CTX->classification = DSR_ISSPAM; CTX->source = DSS_ERROR; break; case FALSEPOS: /** set up the context for error correction as innocent */ CTX = dspam_create((char *)sender_address, NULL, NULL, DSM_PROCESS, DSF_CHAINED | DSF_SIGNATURE); CTX = attach_ctx_dbaccess(CTX); if (CTX == NULL) { log_write(0, LOG_MAIN, "ERROR: dspam_create failed!\n"); sflag = 1; } CTX->classification = DSR_ISINNOCENT; CTX->source = DSS_ERROR; CTX->signature = &SIG; /** Attach the signature to the context */ break; default: /** no reporting required, scan for spam perhaps ? */ log_write(0, LOG_MAIN, "report_spam -> no reporting required"); break; } if (dspam_process(CTX, message) != 0) { /** Call DSPAM */ log_write(0, LOG_MAIN, "ERROR: dspam_process failed!"); sflag = 1; } if (dspam_destroy(CTX) != 0) { /** Destroy the context */ log_write(0, LOG_MAIN, "ERROR: dspam_destroy failed!"); sflag = 1; } memset(message, 0x0, sizeof(message)); free(message); memset(&CTX, 0x0, sizeof(CTX)); free(CTX); if (sflag == 0) { log_write(0, LOG_MAIN, "<= %s [%s] P=%s A=%s:%s", (char *)sender_address, (char *)sender_host_address, (char *)received_protocol, (char *)sender_host_authenticated, (char *)sender_address); log_write(0, LOG_MAIN, "=> (null) <%s> R=system_localuser T=local_delivery", (char *)recipients_list[0].address); } /** if we are reporting, which is pretty much so if you reach here, we blackhole the email */ recipients_count = 0; return(sflag); } /** report_spam */
void load_usersrs(_lusers_s * l_users) { _lusers_s * tmp = l_users; char * message = malloc(1); DSPAM_CTX * CTX = NULL; /** DSPAM Context */ struct _ds_spam_signature SIG; /** Example signature */ if (tmp == NULL) { memset(message, 0x0, sizeof(message)); free(message); return; } message = read_emailmem(message); while (tmp != NULL) { CTX = dspam_create((char *)tmp->realemail, NULL, NULL, DSM_PROCESS, DSF_CHAINED | DSF_SIGNATURE | DSF_NOISE); CTX = attach_ctx_dbaccess(CTX); if (CTX == NULL) { log_write(0, LOG_MAIN, "dspam_create failed!"); break; } if (dspam_process(CTX, message) != 0) { /** Call DSPAM's processor with the message text */ log_write(0, LOG_MAIN, "dspam_process failed!"); dspam_destroy(CTX); break; } if (CTX->result == DSR_ISSPAM) { /** Print processing results */ log_write(0, LOG_MAIN, "spam->[%s]:\n\tProbability:\t[%2.4f]\n\tConfidence:\t[%2.4f]", (char *)tmp->realemail, CTX->probability, CTX->confidence); header_add(' ', "%s: %s\n", (char *)spamflag, (char *)tmp->realemail); lscan.spamflag = SPAMFLAG; } else { log_write(0, LOG_MAIN, "not spam->[%s]", (char *)tmp->realemail); lscan.spamflag = 0; } if (CTX->signature != NULL) { SIG.data = malloc(CTX->signature->length); if (SIG.data != NULL) { memcpy(SIG.data, CTX->signature->data, CTX->signature->length); } } SIG.length = CTX->signature->length; if (dspam_destroy(CTX) != 0) { /** Destroy the context */ log_write(0, LOG_MAIN, "dspam_destroy failed!"); break; } tmp = (_lusers_s *)tmp->next; /** Move on to next user */ } memset(message, 0x0, sizeof(message)); free(message); memset(&CTX, 0x0, sizeof(CTX)); free(CTX); return; } /** load_usersrs */
int main (int argc, char **argv) { char dspam_home[] = "/var/dspam"; /* Our dspam data home */ char buffer[1024]; char *message = malloc (1); long len = 1; DSPAM_CTX *CTX; /* DSPAM Context */ struct _ds_spam_signature SIG; /* Example signature */ /* Performs any driver-specific startup functions (such as initializing internal lock tables). Call this only once when your application starts */ dspam_init_driver (NULL); /* read in the message from stdin */ message[0] = 0; while (fgets (buffer, sizeof (buffer), stdin) != NULL) { len += strlen (buffer); message = realloc (message, len); if (message == NULL) { fprintf (stderr, "out of memory!"); exit (EXIT_FAILURE); } strcat (message, buffer); } /* MESSAGE PROCESSING */ /* initialize dspam Operating Modes: DSM_PROCESS: Process message DSM_CLASSIFY: Classify message only (do not write changes) Flags: DSF_SIGNATURE Signature Mode (Use a signature) DSF_NOISE Use Bayesian Noise Reduction DSF_WHITELIST Use Automatic Whitelisting Tokenizers: DSZ_WORD Use WORD tokenizer DSZ_CHAIN Use CHAIN tokenizer DSZ_SBPH Use SBPH tokenizer DSZ_OSB Use OSB tokenizer Training Modes: DST_TEFT Train Everything DST_TOE Train-on-Error DST_TUM Train-until-Mature Classifications: Used to tell libdspam the message has already been classified, and should be processed in such a way that the result will match the classification. DSR_ISSPAM Message is spam (learn as spam) DSR_ISINNOCENT Message is innocent (learn as innocent) DSR_NONE No predetermined classification (classify message) Sources: Used to tell libdspam the source of the specified classification (if any). DSS_ERROR Misclassification by libdspam DSS_CORPUS Corpusfed message DSS_INOCULATION Message inoculation DSS_NONE No classification source (use only with DSR_NONE) NOTE: When using DSS_ERROR, a DSPAM signature should be provided, OR the original message in PRISTINE form (without any DSPAM headers and with the original message's headers). */ /* --------------------------- EXAMPLE 1 ----------------------------*/ /* STANDARD INBOUND PROCESSING */ /* In this example, DSF_SIGNATURE is specified to request that libdspam generate a signature, which can be stored internally for future retraining. This is useful if the original message in pristine form won't be available server-side should the user want to reclassify the message. */ /* Initialize the DSPAM context */ CTX = dspam_init (USERNAME, NULL, dspam_home, DSM_PROCESS, DSF_SIGNATURE | DSF_NOISE); if (CTX == NULL) { fprintf (stderr, "ERROR: dspam_init failed!\n"); exit (EXIT_FAILURE); } /* Use graham and robinson algorithms, graham's p-values */ CTX->algorithms = DSA_GRAHAM | DSA_BURTON | DSP_GRAHAM; /* Use CHAIN tokenizer */ CTX->tokenizer = DSZ_CHAIN; /* Call DSPAM's processor with the message text */ if (dspam_process (CTX, message) != 0) { fprintf (stderr, "ERROR: dspam_process failed"); exit (EXIT_FAILURE); } /* Print processing results */ printf ("Probability: %2.4f Confidence: %2.4f, Result: %s\n", CTX->probability, CTX->confidence, (CTX->result == DSR_ISSPAM) ? "Spam" : "Innocent"); /* Manage signature */ if (CTX->signature == NULL) { printf ("No signature provided\n"); } else { /* Copy to a safe place */ SIG.data = malloc (CTX->signature->length); if (SIG.data != NULL) memcpy (SIG.data, CTX->signature->data, CTX->signature->length); } SIG.length = CTX->signature->length; /* Destroy the context */ dspam_destroy(CTX); /* --------------------------- EXAMPLE 2 ----------------------------*/ /* SPAM REPORTING (AS MISCLASSIFICATION) */ /* We call everything just like before, with these exceptions: - We set the classification to DSR_ISSPAM - We set the source to DSS_ERROR This example will use the original message in pristine form instead of a signature. See the next example (false positives) for an example using a signature. */ /* Initialize the DSPAM context */ CTX = dspam_init (USERNAME, NULL, dspam_home, DSM_PROCESS, 0); if (CTX == NULL) { fprintf (stderr, "ERROR: dspam_init failed!\n"); exit (EXIT_FAILURE); } /* Set up the context for error correction as spam */ CTX->classification = DSR_ISSPAM; CTX->source = DSS_ERROR; /* Use graham and robinson algorithms, graham's p-values */ CTX->algorithms = DSA_GRAHAM | DSA_BURTON | DSP_GRAHAM; /* Use CHAIN tokenizer */ CTX->tokenizer = DSZ_CHAIN; /* Call DSPAM */ if (dspam_process(CTX, message) != 0) { fprintf (stderr, "ERROR: dspam_process failed\n"); exit (EXIT_FAILURE); } /* Destroy the context */ dspam_destroy (CTX); printf("Spam retrained successfully.\n"); /* --------------------------- EXAMPLE 3 ----------------------------*/ /* FALSE POSITIVE REPORTING */ /* Here we submit the message's signature for retraining as a false positive. We make the following changes from our original example: - We set the classification to DSR_ISINNOCENT - We set the source to DSS_ERROR - We attach the binary signature to the context, and pass in a NULL text */ /* Initialize DSPAM context */ CTX = dspam_init (USERNAME, NULL, dspam_home, DSM_PROCESS, DSF_SIGNATURE); if (CTX == NULL) { fprintf (stderr, "ERROR: dspam_init failed!\n"); exit (EXIT_FAILURE); } /* Set up the context for error correction as innocent */ CTX->classification = DSR_ISINNOCENT; CTX->source = DSS_ERROR; /* Use graham and robinson algorithms, graham's p-values */ CTX->algorithms = DSA_GRAHAM | DSA_BURTON | DSP_GRAHAM; /* Use CHAIN tokenizer */ CTX->tokenizer = DSZ_CHAIN; /* Attach the signature to the context */ CTX->signature = &SIG; /* Call DSPAM */ if (dspam_process(CTX, NULL) != 0) { fprintf (stderr, "ERROR: dspam_process failed\n"); exit (EXIT_FAILURE); } /* Destroy the context */ dspam_destroy(CTX); printf("False positive retrained successfully.\n"); /* --------------------------- EXAMPLE 4 ----------------------------*/ /* USE OF CREATE AND ATTACH WITH ATTRIBUTES API */ /* If we want to provide libdspam with a set of storage driver attributes so that it doesn't have to go looking for a [driver].data file to get SQL-server information from, we can use the create/attach mode of preparing a context, rather than calling dspam_init() */ /* Create the DSPAM context; called just like dspam_init() */ CTX = dspam_create (USERNAME, NULL, dspam_home, DSM_PROCESS, DSF_SIGNATURE); if (CTX == NULL) { fprintf (stderr, "ERROR: dspam_create failed!\n"); exit (EXIT_FAILURE); } /* Now we have a context but it is not attached to the storage driver. The next step is to set up our set of attributes to tell the driver how to connect. In this example, we'll assume we're using a MySQL backend. */ dspam_addattribute(CTX, "MySQLServer", "127.0.0.1"); dspam_addattribute(CTX, "MySQLPort", "3306"); dspam_addattribute(CTX, "MySQLUser", "example"); dspam_addattribute(CTX, "MySQLPass", "1234"); dspam_addattribute(CTX, "MySQLDb", "dspam"); /* Use graham and robinson algorithms, graham's p-values */ CTX->algorithms = DSA_GRAHAM | DSA_BURTON | DSP_GRAHAM; /* Use CHAIN tokenizer */ CTX->tokenizer = DSZ_CHAIN; /* Here, we can also pass in any other attributes used by libdspam (see dspam.conf). We can also do this after the attach, since they are not used until we process a message. */ dspam_addattribute(CTX, "IgnoreHeader", "X-Virus-Scanner-Result"); /* Now a call to dspam_attach() will connect our context to the storage driver interface and establish a connection. Alternatively, if you have an open database handle you may pass it in as the second parameter and avoid opening a new database connection */ if (dspam_attach(CTX, NULL)) { fprintf (stderr, "ERROR: dspam_attach failed!\n"); exit(EXIT_FAILURE); } /* Then proceed like normal and when we're done, destroy the context like we normally do */ dspam_destroy(CTX); printf("Create/attach performed successfully.\n"); /* Performs any driver-specific shutdown functions */ dspam_shutdown_driver (NULL); exit (EXIT_SUCCESS); }
int main (int argc, char **argv) { #ifndef _WIN32 #ifdef TRUSTED_USER_SECURITY struct passwd *p = getpwuid (getuid ()); #endif #endif struct _pgsql_drv_storage *store; char file[PATH_MAX+1]; int i, ch; #ifndef HAVE_GETOPT int optind = 1; #endif /* Read dspam.conf */ agent_config = read_config(NULL); if (!agent_config) { LOG(LOG_ERR, ERR_AGENT_READ_CONFIG); exit(EXIT_FAILURE); } if (!_ds_read_attribute(agent_config, "Home")) { LOG(LOG_ERR, ERR_AGENT_DSPAM_HOME); _ds_destroy_config(agent_config); exit(EXIT_FAILURE); } #ifndef _WIN32 #ifdef TRUSTED_USER_SECURITY if (!_ds_match_attribute(agent_config, "Trust", p->pw_name) && p->pw_uid) { fprintf(stderr, ERR_TRUSTED_MODE "\n"); _ds_destroy_config(agent_config); exit(EXIT_FAILURE); } #endif #endif for(i=0; i<argc; i++) { if (!strncmp (argv[i], "--profile=", 10)) { if (!_ds_match_attribute(agent_config, "Profile", argv[i]+10)) { LOG(LOG_ERR, ERR_AGENT_NO_SUCH_PROFILE, argv[i]+10); _ds_destroy_config(agent_config); exit(EXIT_FAILURE); } else { _ds_overwrite_attribute(agent_config, "DefaultProfile", argv[i]+10); } break; } } open_ctx = open_mtx = NULL; signal (SIGINT, dieout); signal (SIGPIPE, dieout); signal (SIGTERM, dieout); /* Process command line */ ch = 0; #ifdef HAVE_GETOPT while((ch = getopt(argc, argv, "h")) != -1) #else while ( argv[optind] && argv[optind][0] == '-' && (ch = argv[optind][1]) && argv[optind][2] == '\0' ) #endif { switch(ch) { case 'h': /* print help, and then exit. usage exits for us */ usage(); break; #ifndef HAVE_GETOPT default: fprintf(stderr, "%s: unknown option \"%s\".\n", argv[0], argv[optind] + 1); usage(); #endif } #ifndef HAVE_GETOPT optind++; #endif } /* reset our option array and index to where we are after getopt */ argv += optind; argc -= optind; if (argc == 0) { fprintf(stderr,"Must specify an output file\n"); usage(); } memset((void *)file, 0, PATH_MAX+1); strncpy(file, argv[0], PATH_MAX); open_ctx = dspam_create(NULL,NULL,_ds_read_attribute(agent_config, "Home"), DSM_TOOLS, 0); if (open_ctx == NULL) { fprintf(stderr, "Could not initialize context: %s\n", strerror (errno)); exit(EXIT_FAILURE); } set_libdspam_attributes(open_ctx); if (dspam_attach(open_ctx, NULL)) { fprintf(stderr,"Failed to init link to PostgreSQL\n"); dspam_destroy(open_ctx); exit(EXIT_FAILURE); } store = (struct _pgsql_drv_storage *)(open_ctx->storage); GenSQL(store->dbh,file); //PQfinish(store->dbh); OutputMessage(open_ctx,file); if (open_ctx != NULL) dspam_destroy (open_ctx); if (open_mtx != NULL) dspam_destroy (open_mtx); _ds_destroy_config(agent_config); exit (EXIT_SUCCESS); }
int main (int argc, char *argv[]) { DSPAM_CTX *CTX = NULL, *CTX2; char *user; int do_sigs = 0; int do_probs = 0; int do_unused = 0; int age_sigs = 14; int age_probs = 30; int age_unused[4] = { 90, 30, 15, 15 }; int i, help = 0; struct nt *users = NULL; struct nt_node *node = NULL; #ifndef _WIN32 #ifdef TRUSTED_USER_SECURITY struct passwd *p = getpwuid (getuid ()); #endif #endif /* Read dspam.conf */ agent_config = read_config(NULL); if (!agent_config) { LOG(LOG_ERR, ERR_AGENT_READ_CONFIG); fprintf (stderr, ERR_AGENT_READ_CONFIG "\n"); exit(EXIT_FAILURE); } if (!_ds_read_attribute(agent_config, "Home")) { LOG(LOG_ERR, ERR_AGENT_DSPAM_HOME); fprintf (stderr, ERR_AGENT_DSPAM_HOME "\n"); goto bail; } if (libdspam_init(_ds_read_attribute(agent_config, "StorageDriver")) != 0) { LOG(LOG_ERR, ERR_DRV_INIT); fprintf (stderr, ERR_DRV_INIT "\n"); _ds_destroy_config(agent_config); exit(EXIT_FAILURE); } #ifndef _WIN32 #ifdef TRUSTED_USER_SECURITY if (!_ds_match_attribute(agent_config, "Trust", p->pw_name) && p->pw_uid) { fprintf(stderr, ERR_TRUSTED_MODE "\n"); goto bail; } #endif #endif for(i=0;i<argc;i++) { if (!strncmp (argv[i], "--profile=", 10)) { if (!_ds_match_attribute(agent_config, "Profile", argv[i]+10)) { LOG(LOG_ERR, ERR_AGENT_NO_SUCH_PROFILE, argv[i]+10); fprintf (stderr, ERR_AGENT_NO_SUCH_PROFILE "\n", argv[i]+10); goto bail; } else { _ds_overwrite_attribute(agent_config, "DefaultProfile", argv[i]+10); } break; } } #ifdef DEBUG fprintf (stdout, "dspam_clean starting\n"); #endif if (_ds_read_attribute(agent_config, "PurgeSignatures") && !_ds_match_attribute(agent_config, "PurgeSignatures", "off")) { do_sigs = 1; age_sigs = atoi(_ds_read_attribute(agent_config, "PurgeSignatures")); } if (_ds_read_attribute(agent_config, "PurgeNeutral") && !_ds_match_attribute(agent_config, "PurgeNeutral", "off")) { do_probs = 1; age_probs = atoi(_ds_read_attribute(agent_config, "PurgeNeutral")); } if (_ds_read_attribute(agent_config, "PurgeUnused") && !_ds_match_attribute(agent_config, "PurgeUnused", "off")) { int i; do_unused = 1; age_unused[0] = atoi(_ds_read_attribute(agent_config, "PurgeUnused")); age_unused[1] = atoi(_ds_read_attribute(agent_config, "PurgeHapaxes")); age_unused[2] = atoi(_ds_read_attribute(agent_config, "PurgeHits1S")); age_unused[3] = atoi(_ds_read_attribute(agent_config, "PurgeHits1I")); for(i=0;i<4;i++) if (age_unused[i]==0) do_unused = 0; } users = nt_create(NT_CHAR); if (users == NULL) { fprintf(stderr, "%s", ERR_MEM_ALLOC); goto bail; } for(i=0;i<argc;i++) { if (!strncmp(argv[i], "-p", 2)) { do_probs = 1; if (strlen(argv[i])>2) age_probs = atoi(argv[i]+2); } else if (!strncmp(argv[i], "-s", 2)) { do_sigs = 1; if (strlen(argv[i])>2) age_sigs = atoi(argv[i]+2); } else if (!strncmp(argv[i], "-u", 2)) { do_unused = 1; if (strlen(argv[i])>2) { char *c = strdup(argv[i]+2); char *d = strtok(c, ","); int j = 0; while(d != NULL && j<4) { age_unused[j] = atoi(d); j++; d = strtok(NULL, ","); } free(c); } } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) help = 1; else if (i>0) nt_add(users, argv[i]); } if (help || (!do_probs && !do_sigs && !do_unused)) { fprintf(stderr, "%s", CLEANSYNTAX); _ds_destroy_config(agent_config); nt_destroy(users); libdspam_shutdown(); if (help) { exit(EXIT_SUCCESS); } exit(EXIT_FAILURE); } open_ctx = open_mtx = NULL; signal (SIGINT, dieout); signal (SIGPIPE, dieout); signal (SIGTERM, dieout); dspam_init_driver (NULL); if (users->items == 0) { CTX = dspam_create (NULL, NULL, _ds_read_attribute(agent_config, "Home"), DSM_TOOLS, 0); open_ctx = CTX; if (CTX == NULL) { fprintf (stderr, "Could not initialize context: %s\n", strerror (errno)); dspam_shutdown_driver (NULL); goto bail; } 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"); goto bail; } user = _ds_get_nextuser (CTX); } else { node = users->first; if (node != NULL) user = node->ptr; else goto bail; } while (user != NULL) { #ifdef DEBUG printf ("PROCESSING USER: %s\n", user); #endif CTX2 = dspam_create (user, NULL, _ds_read_attribute(agent_config, "Home"), DSM_TOOLS, 0); open_mtx = CTX2; if (CTX2 == NULL) { fprintf (stderr, "Could not initialize context: %s\n", strerror (errno)); return EUNKNOWN; } set_libdspam_attributes(CTX2); if (dspam_attach(CTX2, NULL)) { LOG (LOG_WARNING, "unable to attach dspam context"); fprintf (stderr, "Unable to attach DSPAM context\n"); goto bail; } if (do_sigs) process_sigs(CTX2, age_sigs); if (do_probs) process_probs(CTX2, age_probs); if (do_unused) process_unused(CTX2, age_unused[0], age_unused[1], age_unused[2], age_unused[3]); dspam_destroy (CTX2); open_mtx = NULL; if (users->items == 0) { user = _ds_get_nextuser (CTX); } else { if (node == NULL || node->next == NULL) { node = NULL; user = NULL; } else { node = node->next; user = node->ptr; } } } if (users->items == 0) { dspam_destroy (CTX); open_ctx = NULL; } dspam_shutdown_driver (NULL); _ds_destroy_config(agent_config); nt_destroy(users); libdspam_shutdown(); exit (EXIT_SUCCESS); bail: if (open_ctx) dspam_destroy(open_ctx); if (open_mtx) dspam_destroy(open_mtx); _ds_destroy_config(agent_config); nt_destroy(users); libdspam_shutdown(); exit(EXIT_FAILURE); }