summaryrefslogtreecommitdiff
path: root/tools/ltgrey.c
blob: b707dc2f592a5c06682216e5e76f20f023aa7ee7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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 get_40_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);
      }
      get_40_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 (get_40_mid.length()){
    box_state rslt = foo.get_40(get_40_mid);
    cerr << foo.decode_40[rslt] << endl;
    return 0;
  }

  if (set40_mid.length()){
    return foo.set_40(set40_mid, shift);
  }

  if (scanmode) {
    foo.scan_box(box_40, copies);
    return 0;
  }

  int sts = foo.doit(shift, stain);
  return sts;

}