#include #include #include #include #include #include #include #include #include #include #include using namespace std; struct CLIINFO: public ARRAY_OBJ{ string user; }; struct COMMAND{ string name; int nbarg; bool stream; COMMAND(){ nbarg = -1; stream = false; } COMMAND(const char *_name, int _nbarg, bool _stream){ name = _name; nbarg = _nbarg; stream = _stream; } }; static void cfshell_exec (const char *cmddir, int fd, const SSTRINGS &words) { pid_t pid = fork(); if (pid == (pid_t)0){ int nb = words.getnb(); const char *tb[nb+1]; string tmp = string(cmddir) + "/" + words.getitem(0)->c_str(); tb[0] = tmp.c_str(); for (int i=1; ic_str(); tb[nb] = NULL; dup2 (fd,0); dup2 (fd,1); dup2 (fd,2); execv (tb[0],(char**)tb); tlmp_error ("Exec %s failed (%s)\n",tb[0],strerror(errno)); _exit (0); }else if (pid == (pid_t)-1){ tlmp_error ("Ne peut executer fork() (%s)\n",strerror(errno)); } } int main (int argc, char *argv[]) { glocal int ret = -1; glocal bool daemon = false; glocal const char *cmddir = "/etc/cfshell/commands"; glocal const char *unixport = "/var/run/cfshellserver.sock"; glocal const char *user = "root"; glocal const char *pidfile = "/var/run/cfshellserver.pid"; glocal.ret = (argc,argv); setarg (' ',"cmddir","Repertoire contenant les commandes permises",glocal.cmddir,false); setarg (' ',"daemon","Execute en arriere plan",glocal.daemon,false); setarg (' ',"pidfile","Fichier PID",glocal.pidfile,false); setarg ('p',"unixport","Socket unix",glocal.unixport,false); glocal vector cmds; glocal map > vars; int ret = -1; string tmp = string("unix:") + glocal.unixport; (tmp.c_str(),10); CLIINFO *inf = new CLIINFO; info.data = inf; CLIINFO *inf = (CLIINFO*)info.data; if (strchr(line,'"')!=NULL || strchr(line,'\'')!=NULL || strchr(line,';')!=NULL || strchr(line,'?')!=NULL || strchr(line,'*')!=NULL || strchr(line,'`')!=NULL || strchr(line,'$')!=NULL || strstr(line,"..")!=NULL){ tlmp_error ("Line with invalid character: %s\n",line); }else{ SSTRINGS words; int n = str_splitline (line,' ',words); if (n >= 1){ const char *cmd = words.getitem(0)->c_str(); if (strcmp(cmd,"defcmd")==0 && n == 4){ const char *cmd = words.getitem(1)->c_str(); int nbarg = words.getitem(2)->getval(); bool stream = words.getitem(3)->getval() != 0; glocal.cmds.push_back (COMMAND(cmd,nbarg,stream)); }else if (strcmp(cmd,"setvarval")==0 && n == 3){ glocal.vars[words.getitem(1)->c_str()].push_back(words.getitem(2)->c_str()); }else if (strcmp(cmd,"resetcmds")==0 && n == 1){ glocal.cmds.clear(); }else if (strcmp(cmd,"resetvars")==0 && n == 1){ glocal.vars.clear(); }else{ bool found = false; for (unsigned i=0; i if (o.is_ok()){ signal (SIGPIPE,SIG_IGN); signal (SIGCHLD,SIG_IGN); if (glocal.daemon){ daemon_init (glocal.user,glocal.pidfile); } ret = 0; o.loop(); }else{ tlmp_error ("Ne peut initiliser %s (%s)\n",glocal.unixport,strerror(errno)); } return ret; return glocal.ret; }