diff 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
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/defaults/hg-wrapper.cpp	Wed Jan 09 04:53:59 2013 +0000
     1.3 @@ -0,0 +1,59 @@
     1.4 +#include <stdio.h>
     1.5 +//#include <stdlib.h>
     1.6 +#include <cstdlib>
     1.7 +#include <iostream>
     1.8 +#include <vector>
     1.9 +#include <string>
    1.10 +
    1.11 +#include <algorithm>
    1.12 +
    1.13 +#include <unistd.h>
    1.14 +//#include <numeric>
    1.15 +
    1.16 +
    1.17 +#include <boost/algorithm/string/join.hpp>
    1.18 +
    1.19 +// void print_element(std::string x){
    1.20 +//   std::cout << x << std::endl;
    1.21 +// }
    1.22 +
    1.23 +
    1.24 +main( int argc, char ** argv){
    1.25 +
    1.26 +  // remove first element of argv, the program's name
    1.27 +  std::vector<std::string> input(argv, argv+argc);
    1.28 +  
    1.29 +
    1.30 +  //std::cout << input.size() << std::endl;
    1.31 +  
    1.32 +  input[0] = std::string("hg");
    1.33 +  
    1.34 +  //input.insert(input.begin(),std::string("hg"));
    1.35 +  
    1.36 +  //std::cout << input.size() << std::endl;
    1.37 +
    1.38 +  // for(unsigned i = 0; i < input.size(); i++){
    1.39 +  //   std::cout << input[i] << std::endl;
    1.40 +    
    1.41 +  // }
    1.42 +
    1.43 +  //for_each(input.begin(),input.end(), print_element);
    1.44 + 
    1.45 +
    1.46 +  // std::string command = 
    1.47 +  //   accumulate(input.begin(), input.end(), std::string(" "));
    1.48 +  
    1.49 +  std::string command = boost::algorithm::join(input, " ");
    1.50 +
    1.51 +
    1.52 +  //.c_str();
    1.53 +
    1.54 +  //std::cout << command << std::endl;
    1.55 +
    1.56 +  setreuid( geteuid(),  geteuid() );
    1.57 +  //envp = 0; /* blocks IFS attack on non-bash shells */
    1.58 +  //system( "/usr/bin/hg", argv, envp );
    1.59 +  return system(command.c_str());
    1.60 +  //perror( argv[0] );
    1.61 +  //return errno;
    1.62 +}