annotate defaults/hg-wrapper.cpp @ 9:a0c0ccd22ca5

progress on setuid wrapper script.
author Robert McIntyre <rlm@mit.edu>
date Wed, 09 Jan 2013 04:53:59 +0000
parents
children bd465da5cd0f
rev   line source
rlm@9 1 #include <stdio.h>
rlm@9 2 //#include <stdlib.h>
rlm@9 3 #include <cstdlib>
rlm@9 4 #include <iostream>
rlm@9 5 #include <vector>
rlm@9 6 #include <string>
rlm@9 7
rlm@9 8 #include <algorithm>
rlm@9 9
rlm@9 10 #include <unistd.h>
rlm@9 11 //#include <numeric>
rlm@9 12
rlm@9 13
rlm@9 14 #include <boost/algorithm/string/join.hpp>
rlm@9 15
rlm@9 16 // void print_element(std::string x){
rlm@9 17 // std::cout << x << std::endl;
rlm@9 18 // }
rlm@9 19
rlm@9 20
rlm@9 21 main( int argc, char ** argv){
rlm@9 22
rlm@9 23 // remove first element of argv, the program's name
rlm@9 24 std::vector<std::string> input(argv, argv+argc);
rlm@9 25
rlm@9 26
rlm@9 27 //std::cout << input.size() << std::endl;
rlm@9 28
rlm@9 29 input[0] = std::string("hg");
rlm@9 30
rlm@9 31 //input.insert(input.begin(),std::string("hg"));
rlm@9 32
rlm@9 33 //std::cout << input.size() << std::endl;
rlm@9 34
rlm@9 35 // for(unsigned i = 0; i < input.size(); i++){
rlm@9 36 // std::cout << input[i] << std::endl;
rlm@9 37
rlm@9 38 // }
rlm@9 39
rlm@9 40 //for_each(input.begin(),input.end(), print_element);
rlm@9 41
rlm@9 42
rlm@9 43 // std::string command =
rlm@9 44 // accumulate(input.begin(), input.end(), std::string(" "));
rlm@9 45
rlm@9 46 std::string command = boost::algorithm::join(input, " ");
rlm@9 47
rlm@9 48
rlm@9 49 //.c_str();
rlm@9 50
rlm@9 51 //std::cout << command << std::endl;
rlm@9 52
rlm@9 53 setreuid( geteuid(), geteuid() );
rlm@9 54 //envp = 0; /* blocks IFS attack on non-bash shells */
rlm@9 55 //system( "/usr/bin/hg", argv, envp );
rlm@9 56 return system(command.c_str());
rlm@9 57 //perror( argv[0] );
rlm@9 58 //return errno;
rlm@9 59 }