#include #include /* for exit(), atoi() */ #include /* for getpid() */ #include #include "libltgrey.h" #include "qq_exit_codes.h" #include "utils.h" #include using namespace std; pid_t mypid; string progname; #define exeunt exit void usage(const string parent_dir){ cout << "Usage: ltgrey [options]\n" "\n" "Options include\n" " -set40 mid # start quarantine for given message-id\n" " -get40 mid # look up the quarantine status for the given mID\n" " -scan40 # scan the quarantine directory\n" "\n" " -setrep dom # set the reputation for the given domain\n" " -getrep dom # look up the reputation for the given domain\n" " -scanrep # scan the reputation directory\n" "\n" " -copy # increment the 'copies' variable\n" " -dns_mode # enable DNS checks\n" " -verbose # increase the verbosity\n" " -shift ??? # no idea\n" " -stain ??? # not implemented\n" " -suffix ??? # no idea\n" " -help # print this msg (and exit immediately)\n" "\n" ; cout << "parent dir is " << parent_dir << endl; cout << "box_40.dir is " << box_40.dir << endl; cout << "box_rep.dir is " << box_rep.dir << endl; cout << "\n" "Principles of operation:\n" "\n" "1) Quarantine applies to a particular message. Messages\n" " are identified by their MID i.e. message-ID.\n" "\n" "2a) Ideally, reputation applies to a sending-domain.\n" "\n" "2b) If we can't identify a domain that will take responsibility\n" " for sending the message, then reputation applies to the host.\n" ; return; } int main(int _argc, char** _argv){ mypid = getpid(); int argc(_argc); char** argv(_argv); const string parent_dir("/var/qmail/ltgrey"); whatsit foo(argv[0], parent_dir); argc--; argv++; if (foo.setup()) return ex_syserr; int rslt; rslt = foo.maybe_mkdir(".", "parent dir"); if (rslt) return rslt; rslt = foo.maybe_mkdir(box_40.dir, "quarantine dir"); if (rslt) return rslt; rslt = foo.maybe_mkdir(box_rep.dir, "reputation dir"); if (rslt) return rslt; int scan40mode(0); int scanrepmode(0); int copies(1); int shift(0); int stain(0); int dns_mode(0); string get_40_mid; string set_40_mid; string get_rep_domain; string set_rep_domain; argParser ARGS(argc, argv); try {while (ARGS.size()) { ARGS.next(); if (0){ } else if (ARGS.prefix("-help")) { usage(foo.parent_dir); exit(0); } else if (ARGS.prefix("-scan40")) { scan40mode++; } else if (ARGS.prefix("-scanrep")) { scanrepmode++; } else if (ARGS.prefix("-copy")) { copies++; } else if (ARGS.prefix("-verbose")) { foo.verbosity++; } else if (ARGS.prefix("-dns_mode")) { dns_mode++; } else if (ARGS.prefix("-get40", 1)) { get_40_mid = ARGS.shift(); } else if (ARGS.prefix("-set40", 1)) { set_40_mid = ARGS.shift(); } else if (ARGS.prefix("-setrep", 1)) { set_rep_domain = ARGS.shift(); } else if (ARGS.prefix("-getrep", 1)) { get_rep_domain = ARGS.shift(); } else if (ARGS.prefix("-shift"), 1) { shift = atoi(*argv++); argc--; } else if (ARGS.prefix("-stain", 1)) { stain = atoi(*argv++); argc--; if (stain) {} /* FIXME */ } else if (ARGS.prefix("-suffix", 1)) { foo.suffix += ARGS.shift(); } else { cerr << "Unrecognized arg: " << ARGS.current_arg << endl; throw int(1); } }} catch (int){ exeunt(ex_syserr); } // dns_mode mode ... // Probably it would be better to make more thorough DNS checks. // if (dns_mode) { char* ipvar = getenv("TCPREMOTEIP"); char* namevar = getenv("TCPREMOTEHOST"); exeunt(foo.check_dns(ipvar, namevar)); } if (get_40_mid.length()){ box_state rslt = foo.get_40(get_40_mid); cerr << foo.decode_40[rslt] << endl; return 0; } if (set_40_mid.length()){ return foo.set_40(set_40_mid, shift); } if (get_rep_domain.length()){ box_state rslt = foo.get_rep(get_rep_domain); cerr << foo.decode_40[rslt] << endl; return 0; } if (set_rep_domain.length()){ return foo.set_rep(set_rep_domain, shift); } if (scan40mode) { foo.scan_box(box_40, copies); return 0; } if (scanrepmode) { foo.scan_box(box_rep, copies); return 0; } return 0; }