summaryrefslogtreecommitdiff
path: root/tools/wripper.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-22 21:43:07 (GMT)
committerJohn Denker <jsd@av8n.com>2012-07-22 21:43:07 (GMT)
commit216f1b40bc71468c0f644e39c57edbc63fada489 (patch)
tree9cceb0bc78baecf1bd36f50e84c7acf06e77bf54 /tools/wripper.c
parent178786bb76b9fdba550de3a49a159da6515931cc (diff)
set program gid (not just egid) the way mailman likes it
Diffstat (limited to 'tools/wripper.c')
-rw-r--r--tools/wripper.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/tools/wripper.c b/tools/wripper.c
new file mode 100644
index 0000000..2a19c8b
--- /dev/null
+++ b/tools/wripper.c
@@ -0,0 +1,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);
+}