summaryrefslogtreecommitdiff
path: root/tools/wripper.c
blob: 2a19c8b4c6f7904c04f8b537040fd3a9cb97d55d (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
//////////////

using namespace std;
#include <iostream>
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>              /* for perror() */

string dirname(const string path){
  size_t where = path.rfind("/");
  if (where == string::npos) return ".";
  return path.substr(0, where);
}

int main(int argc, char** argv){
  int uid=getuid();
  int euid=geteuid();
  int gid=getgid();
  int egid=getegid();
  int sts;
  int verbosity(0);

  if (verbosity) cout << "uid: " << uid
        << "  euid: " << euid
        << "  gid: " << gid
        << "  egid: " << egid
        << endl;

  sts = setreuid(euid, euid);
  if (sts){
     cerr << "wripper: setreuid failed: ";
     perror(0);
  }

  sts = setregid(egid, egid);
  if (sts){
     cerr << "wripper: setregid failed: ";
     perror(0);
  }

  if (verbosity) cout << "uid: " << getuid()
        << "  euid: " << geteuid()
        << "  gid: " << getgid()
        << "  egid: " << getegid()
        << endl;
  
  string path = dirname(*argv) + "/mailman";
  *argv = (char*) path.c_str();
  execv(*argv, argv);
  cerr << "wripper: exec failed for '" << *argv << "' : ";
  perror(0);
}