#include #include #include #include "nargv/nargv.h" #include /* for fork */ #include /* for pid_t */ #include /* for wait */ #define ANSI_COLOR_GREEN "\x1b[32m" #define ANSI_COLOR_RESET "\x1b[0m" #define AUTHORIZED_SHELL_COMMAND "bash-gitonly" #define AUTHORIZED_COMMANDS "git-receive-pack","git-upload-pack","git-upload-archive" #define AUTHORIZED_COMMANDS_COUNT 3 #define COMMANDS_PATH "/bin/" #define MAX_FULL_EXECFILENAME_LENGTH 24 char* isCmdAuthorized(char* cmd){ const char* authorizedCommands[] = {AUTHORIZED_COMMANDS}; for (int i=0; iargc); fprintf(stderr,"Error code: %i\n",subargv->error_code); for(int i = 0;iargc;i++){ fprintf(stderr,"%02d -> %s\n",i,subargv->argv[i]); } if (subargv->error_code) { fprintf(stderr,"nargv parse error: %i: %s: at input column %i\n", subargv->error_code, subargv->error_message, subargv->error_index); return 2; } pid_t pid=fork(); if (pid==0) { /* child process */ //static char *argv[]={"echo","Foo is my name.",NULL}; execve(execFilename, subargv->argv, (char *const []){NULL}); exit(127); /* only if execv fails */ } else { /* pid!=0; parent process */ waitpid(pid,0,0); /* wait for child to exit */ } nargv_free(subargv); return 0; }