void dieout (int signal) { fprintf (stderr, "terminated.\n"); _ds_destroy_config(agent_config); exit (EXIT_SUCCESS); }
void min_args(int argc, int min) { if (argc<(min+1)) { fprintf(stderr, "invalid command syntax.\n"); usage(); _ds_destroy_config(agent_config); exit(EXIT_FAILURE); } return; }
void usage (void) { (void)fprintf (stderr, "Usage: dspam_pg2int8 [-h] file\n" "\tCreates SQL file to migrate from NUMERIC to BIGINT type and vice-versa in PostgreSQL.\n" "\t-h: print this message\n"); _ds_destroy_config(agent_config); exit(EXIT_FAILURE); }
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); }
void usage (void) { fprintf(stderr, "%s\n", TSYNTAX); fprintf(stderr, "\tadd preference [user] [attrib] [value]\n"); fprintf(stderr, "\tchange preference [user] [attrib] [value]\n"); fprintf(stderr, "\tdelete preference [user] [attrib] [value]\n"); fprintf(stderr, "\tlist preference [user] [attrib] [value]\n"); fprintf(stderr, "\taggregate preference [user]\n"); _ds_destroy_config(agent_config); exit(EXIT_FAILURE); }
int main (int argc, char **argv) { #ifdef TRUSTED_USER_SECURITY struct passwd *p = getpwuid (getuid ()); #endif int i, valid = 0; /* 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); } libdspam_init(_ds_read_attribute(agent_config, "StorageDriver")); #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); 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); _ds_destroy_config(agent_config); goto BAIL; } else { _ds_overwrite_attribute(agent_config, "DefaultProfile", argv[i]+10); } break; } } signal (SIGINT, dieout); signal (SIGPIPE, dieout); signal (SIGTERM, dieout); dspam_init_driver (NULL); if (argc < 3 || !strcmp(argv[1], "help")) { usage(); } /* PREFERENCE FUNCTIONS */ if (!strncmp(argv[2], "pref", 4)) { /* Delete */ if (!strncmp(argv[1], "d", 1)) { min_args(argc, 4); valid = 1; del_preference_attribute(argv[3], argv[4]); } /* Add, Change */ if (!strncmp(argv[1], "ch", 2) || !strncmp(argv[1], "ad", 2)) { min_args(argc, 5); valid = 1; set_preference_attribute(argv[3], argv[4], argv[5]); } /* List */ if (!strncmp(argv[1], "l", 1)) { min_args(argc, 3); valid = 1; list_preference_attributes(argv[3]); } /* Aggregate - Preference attr + AllowOverride attr + user prefs */ if (!strncmp(argv[1], "ag", 2)) { min_args(argc, 3); valid = 1; list_aggregate_preference_attributes(argv[3]); } } if (!valid) usage(); dspam_shutdown_driver (NULL); _ds_destroy_config(agent_config); libdspam_shutdown(); exit (EXIT_SUCCESS); BAIL: libdspam_shutdown(); exit(EXIT_FAILURE); }
int main (int argc, char **argv) { #ifndef _WIN32 #ifdef TRUSTED_USER_SECURITY struct passwd *p = getpwuid (getuid ()); #endif #endif int i, ret; /* 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"); _ds_destroy_config(agent_config); exit(EXIT_FAILURE); } 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"); _ds_destroy_config(agent_config); 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); _ds_destroy_config(agent_config); goto BAIL; } 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); dspam_init_driver (NULL); ret = process_all_users(); dspam_shutdown_driver (NULL); _ds_destroy_config(agent_config); libdspam_shutdown(); exit((ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE); BAIL: libdspam_shutdown(); exit(EXIT_FAILURE); }
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[]) { AGENT_CTX ATX; int exitcode = EXIT_SUCCESS; buffer *message = NULL; /* input Message */ int agent_init = 0; /* agent is initialized */ setbuf (stdout, NULL); /* unbuffered output */ #ifdef DEBUG DO_DEBUG = 0; #endif srand ((long) time << (long) getpid()); umask (006); #ifndef DAEMON LOG(LOG_ERR, ERR_DAEMON_NO_SUPPORT); exit(EXIT_FAILURE); #endif /* Read dspam.conf into global config structure (ds_config_t) */ agent_config = read_config(NULL); if (!agent_config) { LOG(LOG_ERR, ERR_AGENT_READ_CONFIG); exitcode = EXIT_FAILURE; goto BAIL; } if (!_ds_read_attribute(agent_config, "Home")) { LOG(LOG_ERR, ERR_AGENT_DSPAM_HOME); exitcode = EXIT_FAILURE; goto BAIL; } /* Set up agent context to define behavior of processor */ if (initialize_atx(&ATX)) { LOG(LOG_ERR, ERR_AGENT_INIT_ATX); exitcode = EXIT_FAILURE; goto BAIL; } else { agent_init = 1; } if (process_arguments(&ATX, argc, argv)) { LOG(LOG_ERR, ERR_AGENT_INIT_ATX); exitcode = EXIT_FAILURE; goto BAIL; } if (apply_defaults(&ATX)) { LOG(LOG_ERR, ERR_AGENT_INIT_ATX); exitcode = EXIT_FAILURE; goto BAIL; } if (check_configuration(&ATX)) { LOG(LOG_ERR, ERR_AGENT_MISCONFIGURED); exitcode = EXIT_FAILURE; goto BAIL; } /* Read the message in and apply ParseTo services */ message = read_stdin(&ATX); if (message == NULL) { exitcode = EXIT_FAILURE; goto BAIL; } if (ATX.users->items == 0) { LOG (LOG_ERR, ERR_AGENT_USER_UNDEFINED); fprintf (stderr, "%s\n", SYNTAX); exitcode = EXIT_FAILURE; goto BAIL; } /* Perform client-based processing */ #ifdef DAEMON if (_ds_read_attribute(agent_config, "ClientIdent") && (_ds_read_attribute(agent_config, "ClientHost") || _ds_read_attribute(agent_config, "ServerDomainSocketPath"))) { exitcode = client_process(&ATX, message); } else { LOG(LOG_ERR, ERR_CLIENT_INVALID_CONFIG); exitcode = EINVAL; } #endif BAIL: if (message) buffer_destroy(message); if (agent_init) nt_destroy(ATX.users); if (agent_config) _ds_destroy_config(agent_config); exit (exitcode); }
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); }