diff options
author | John Denker <jsd@av8n.com> | 2012-07-30 14:34:05 -0700 |
---|---|---|
committer | John Denker <jsd@av8n.com> | 2012-07-30 14:34:05 -0700 |
commit | 7024dc330299921af649330c45b99c21c3d7f022 (patch) | |
tree | 9f747a0423647b016376fe353ceea197a5848cbf /tools/ltgrey.c | |
parent | ce0dbe5332d4eb921c09cc48cc52634211d7089a (diff) | |
parent | f8be4baf5a2318363b42f8883f66ed8a976dfc79 (diff) |
Merge branch 'master' of ephedra:usr/src/qmail into e_master
Conflicts:
tools/makefile
Diffstat (limited to 'tools/ltgrey.c')
-rw-r--r-- | tools/ltgrey.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/tools/ltgrey.c b/tools/ltgrey.c new file mode 100644 index 0000000..1494338 --- /dev/null +++ b/tools/ltgrey.c @@ -0,0 +1,109 @@ +#include <iostream> +#include <stdlib.h> /* for exit(), atoi() */ + +#include "libltgrey.h" +#include "utils.h" +#include "qq_exit_codes.h" + +using namespace std; +pid_t mypid; +string progname; + +#define exeunt exit + +// forward reference: +void scan(const string progid, const string p, const int copies=1); + + +int main(int _argc, char** _argv){ + std::string hostname; + std::string ipname; + + mypid = getpid(); + int argc(_argc); + char** argv(_argv); + const string parent_dir("/var/qmail/ltgrey"); + whatsit foo(argv[0], parent_dir); argc--; argv++; + int scanmode(0); + int copies(1); + int shift(0); + int stain(0); + int dns_mode(0); + string get40_mid; + string set40_mid; + while (argc > 0) { + string arg = argv[0]; argc--; argv++; + if (prefix(arg, "-scan40")) { + scanmode++; + } else if (prefix(arg, "-copy")) { + copies++; + } else if (prefix(arg, "-verbose")) { + foo.verbosity++; + } else if (prefix(arg, "-dns_mode")) { + dns_mode++; + } else if (prefix(arg, "-get40")) { + if (!argc){ + cerr << "Option '" << arg << "' requires an argument" << endl; + exeunt(ex_syserr); + } + get40_mid = *argv++; argc--; + } else if (prefix(arg, "-set40")) { + if (!argc){ + cerr << "Option '" << arg << "' requires an argument" << endl; + exeunt(ex_syserr); + } + set40_mid = *argv++; argc--; + } else if (prefix(arg, "-shift") + || prefix(arg, "-shift")) { + if (!argc){ + cerr << "Option '" << arg << "' requires an argument" << endl; + exeunt(ex_syserr); + } + shift = atoi(*argv++); argc--; + } else if (prefix(arg, "-stain")) { + if (!argc){ + cerr << "Option '" << arg << "' requires an argument" << endl; + exeunt(ex_syserr); + } + stain = atoi(*argv++); argc--; + } else if (prefix(arg, "-suffix")) { + if (!argc){ + cerr << "Option '" << arg << "' requires an argument" << endl; + exeunt(ex_syserr); + } + foo.suffix += *argv++; argc--; + } else { + cerr << "Unrecognized arg: " << arg << endl; + exeunt(ex_syserr); + } + } + if (foo.setup()) return 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 (get40_mid.length()){ + state_40 rslt = foo.get40(get40_mid); + cerr << foo.decode_40[rslt] << endl; + return 0; + } + + if (set40_mid.length()){ + return foo.set40(set40_mid, shift); + } + + if (scanmode) { + foo.scan40(copies); + return 0; + } + + int sts = foo.doit(shift, stain); + return sts; + +} |