/** * @param cmd The cmd to execute * @param run_in_term Indicate if command should be run in a terminal * * Execute command and add to history. */ static void exec_cmd ( const char *cmd, int run_in_term ) { GError *error = NULL; if ( !cmd || !cmd[0] ) { return; } gsize lf_cmd_size = 0; gchar *lf_cmd = g_locale_from_utf8 ( cmd, -1, NULL, &lf_cmd_size, &error ); if ( error != NULL ) { fprintf ( stderr, "Failed to convert command to locale encoding: %s\n", error->message ); g_error_free ( error ); return; } if ( execsh ( lf_cmd, run_in_term ) ) { /** * This happens in non-critical time (After launching app) * It is allowed to be a bit slower. */ char *path = g_build_filename ( cache_dir, RUN_CACHE_FILE, NULL ); history_set ( path, cmd ); g_free ( path ); } g_free ( lf_cmd ); }
int mdm_dial(char *phone,char *port) { int rc; char s[MAX_STRING],conn[MAX_STRING]; if((rc=tty_openport(port))) { write_log("can't open port: %s",tty_errs[rc]); return MC_BAD; } reset(); xstrcpy(s,cfgs(CFG_DIALPREFIX),MAX_STRING); xstrcat(s,phone,MAX_STRING); xstrcat(s,cfgs(CFG_DIALSUFFIX),MAX_STRING); tty_local(1); sline("Dialing %s",s);vidle(); rc=modem_chat(s,cfgsl(CFG_MODEMCONNECT),cfgsl(CFG_MODEMNODIAL),cfgsl(CFG_MODEMERROR), cfgsl(CFG_MODEMBUSY),cfgs(CFG_MODEMRINGING),cfgi(CFG_MAXRINGS), cfgi(CFG_WAITCARRIER),conn,MAX_STRING); sline("Modem said: %s",conn); xfree(connstr);connstr=xstrdup(conn); if(rc!=MC_OK) { write_log("got %s",conn); if(rc==MC_FAIL)hangup(); tty_close(); if(rc==MC_RING) { sline("RING found.."); sleep(2); execsh("killall -USR1 mgetty vgetty >/dev/null 2>&1"); } else sline("Call failed (%s)",mcs[rc]); return rc; } write_log("*** %s",conn); tty_local(0); return rc; }
void chatlog_done() { FILE *chatlog=NULL; time_t tt;struct tm *t; char str[MAX_STRING]={0}; write_log("Chat closed"); if(rcpos)chatlog_write("\n",1); if(mcpos)chatlog_write("\n",0); if(cfgs(CFG_CHATLOG))chatlog=fopen(ccs,"at"); tt=time(NULL);t=localtime(&tt); strftime(str,MAX_STRING-1,"\n[--- Chat closed at %d %b %y %H:%M:%S ---]\n\n",t); if(chatlog){fwrite(str,strlen(str),1,chatlog);fclose(chatlog);} if(lemail)fwrite(str,strlen(str),1,lemail); if(cpkt) { if(cfgi(CFG_RECODEPKTS))recode_to_remote(str); strtr(str,'\n','\r'); fwrite(str,strlen(str)-1,1,cpkt); closeqpkt(cpkt,adr); snprintf(str,MAX_STRING-1,"%s/%s",cfgs(CFG_INBOUND),basename(pktname)); if(rename(pktname,str))write_log("can't rename %s to %s: %s",pktname,str,strerror(errno)); else chmod(str,cfgi(CFG_DEFPERM)); } if(lemail) { fclose(lemail); snprintf(str,MAX_STRING-1,"mail -s chatlog %s < /tmp/qlemail.%04lx",cfgs(CFG_CHATTOEMAIL),(long)getpid()); execsh(str); lunlink(strrchr(str,'<')+1); } }
void retrfile(char *s,int len,int port) { int i,pid; char data1; struct sockaddr_in client; memset(&client,0,sizeof(client)); sockfd1=socket(2,1,0); if(create_serv(sockfd1,port)<0) quit(); i=sizeof(client); sockfd2=accept(sockfd1,(struct sockaddr *)&client,&i); printf("[+] Accepted a client from %s\n",inet_ntoa(client.sin_addr)); memset(s,0,len); if(getshell==1) { if(bindmethod==0) { printf("[+] Is it a shell on %s:%d?\n",cbhost,pt); quit(); } else { printf("[+] Waiting for a shell.....\n"); sockfd2=socket(AF_INET,SOCK_STREAM,0); sleep(2); client_connect(sockfd2,server,pt); execsh(sockfd2); quit(); } } readbuf(NULL,sockfd2,s,len); close(sockfd2); close(sockfd1); }
// execute sub-process static pid_t exec_cmd ( const char *cmd, int run_in_term ) { if ( !cmd || !cmd[0] ) { return -1; } signal ( SIGCHLD, catch_exit ); pid_t pid = fork (); if ( !pid ) { setsid (); execsh ( cmd, run_in_term ); exit ( EXIT_FAILURE ); } /** * This happens in non-critical time (After launching app) * It is allowed to be a bit slower. */ char *path = NULL; if ( asprintf ( &path, "%s/%s", cache_dir, RUN_CACHE_FILE ) == -1 ) { return -1; } history_set ( path, cmd ); free ( path ); return pid; }
void start_kksh() { char command[BLOC_SIZE]; const programs_t prog[] = { {"tictactoe", &tictactoe}, {"connectFour", &connectFour}, // {"sw", &swascii}, {"clear", &cleanWrap}, {"", NULL} }; cleanWrap(NULL); for(;;){ put_prompt(); if (get_input_line(command, BLOC_SIZE) == -1) { syscall_puts_screen("READ ERROR"); continue; } if (!kstrcmp(command, "exit")) return ; //syscall_puts_screen("Prout !2"); execsh(command, prog); } }
// execute sub-process static void exec_cmd ( const char *cmd, int run_in_term ) { if ( !cmd || !cmd[0] ) { return; } execsh ( cmd, run_in_term ); }
static void sched(void) { char *flags; Job *j; Bufblock *buf; int slot; Node *n; Envy *e; if(jobs == 0){ usage(); return; } j = jobs; jobs = j->next; if(DEBUG(D_EXEC)) printf("firing up job for target %s\n", wtos(j->t, ' ')); slot = nextslot(); events[slot].job = j; buf = newbuf(); e = buildenv(j, slot); shprint(j->r->recipe, e, buf); if(!tflag && (nflag || !(j->r->attr&QUIET))) Bwrite(&bout, buf->start, (long)strlen(buf->start)); freebuf(buf); if(nflag||tflag){ for(n = j->n; n; n = n->next){ if(tflag){ if(!(n->flags&VIRTUAL)) touch(n->name); else if(explain) Bprint(&bout, "no touch of virtual '%s'\n", n->name); } n->time = time((long *)0); MADESET(n, MADE); } } else { if(DEBUG(D_EXEC)) printf("recipe='%s'", j->r->recipe);/**/ Bflush(&bout); if(j->r->attr&NOMINUSE) flags = 0; else flags = "-e"; events[slot].pid = execsh(flags, j->r->recipe, 0, e); usage(); nrunning++; if(DEBUG(D_EXEC)) printf("pid for target %s = %d\n", wtos(j->t, ' '), events[slot].pid); } }
// execute sub-process pid_t exec_cmd(char *cmd) { if (!cmd || !cmd[0]) return -1; signal(SIGCHLD, catch_exit); pid_t pid = fork(); if (!pid) { setsid(); execsh(cmd); exit(EXIT_FAILURE); } return pid; }
static void exec_cmd_entry ( DRunModeEntry *e ) { // strip % arguments gchar *str = g_strdup ( e->exec ); for ( ssize_t i = 0; str && str[i]; i++ ) { if ( str[i] == '%' ) { while ( str[i] != ' ' && str[i] != '\0' ) { str[i++] = ' '; } } } execsh ( str, e->terminal ); g_free ( str ); }
/* * assemble a back-quoted shell command into a buffer */ static int bquote(Biobuf *bp, Bufblock *buf) { int c, line, term, depth; int start; line = mkinline; while((c = Bgetrune(bp)) == ' ' || c == '\t') ; if(c == '{'){ term = '}'; /* rc style */ while((c = Bgetrune(bp)) == ' ' || c == '\t') ; } else term = '`'; /* sh style */ depth = 1; start = buf->current-buf->start; for(;c > 0; c = nextrune(bp, 0)){ if(c == '{' && term == '}') depth++; if(c == term && --depth == 0){ insert(buf, '\n'); insert(buf,0); buf->current = buf->start+start; execinit(); execsh(0, buf->current, buf, envy); return 1; } if(c == '\n') break; if(c == '\'' || c == '"' || c == '\\'){ insert(buf, c); if(!escapetoken(bp, buf, 1, c)) return 0; continue; } rinsert(buf, c); } SYNERR(line); fprint(2, "missing closing %c after `\n", term); return 0; }
static void exec_cmd_entry ( DRunModeEntry *e ) { // strip % arguments gchar *str = g_strdup ( e->exec ); for ( ssize_t i = 0; str != NULL && str[i] != '\0'; i++ ) { if ( str[i] == '%' ) { while ( str[i] != ' ' && str[i] != '\0' ) { str[i++] = ' '; } // We might have hit '\0' in prev. loop, break out of for then. if ( str[i] == '\0' ) { break; } } } gchar *fp = rofi_expand_path ( g_strstrip ( str ) ); if ( execsh ( fp, e->terminal ) ) { char *path = g_build_filename ( cache_dir, DRUN_CACHE_FILE, NULL ); history_set ( path, e->path ); g_free ( path ); } g_free ( str ); g_free ( fp ); }
int freq_ifextrp(slist_t *reqs) { FILE *f, *g, *r; char s[MAX_PATH], fn[MAX_PATH], sfn[MAX_PATH], *ss; char priv = 'a', *p, *sprt = "UNPROTEC", *slst = "UNLIS"; int got = 0, wz = cfgs( CFG_EXTRP ) ? 1 : 0, kil; long tpid = (long) getpid(); ftnaddr_t *ma = akamatch( &rnode->addrs->addr, cfgal( CFG_ADDRESS )); DEBUG(('R',1,"Freq received")); if ( rnode->options & O_LST ) { priv = 'l'; slst += 2; } if( rnode->options & O_PWD ) { priv = 'p'; sprt += 2; } snprintf( fn, MAX_PATH, "/tmp/qreq.%04lx", tpid ); if( !( f = fopen( fn, "wt" ))) { write_log( "can't open '%s' for writing: %s", fn, strerror( errno )); return 0; } while( reqs ) { if ( cfgs( CFG_MAPIN ) && strchr( ccs, 'r' )) recode_to_local( reqs->str ); DEBUG(('R',1,"requested '%s'", reqs->str)); fprintf( f, "%s\n", reqs->str ); reqs = reqs->next; } fclose( f ); if(!wz) { falist_t *ra; snprintf(sfn,MAX_PATH,"/tmp/qsrif.%04lx",tpid); if(!(r=fopen(sfn,"wt"))){write_log("can't open '%s' for writing: %s",sfn,strerror(errno));return 0;} fprintf(r,"SessionType %s\n",bink?"OTHER":"EMSI"); fprintf(r,"Sysop %s\n",rnode->sysop); for(ra=rnode->addrs;ra;ra=ra->next)fprintf(r,"AKA %s\n",ftnaddrtoa(&ra->addr)); if(!is_ip)fprintf(r,"Baud %d\n",rnode->realspeed); fprintf(r,"Time -1\n"); fprintf(r,"RemoteStatus %sTED\n",sprt); fprintf(r,"SystemStatus %sTED\n",slst); fprintf(r,"RequestList /tmp/qreq.%04lx\n",tpid); fprintf(r,"ResponseList /tmp/qfls.%04lx\n",tpid); fprintf(r,"Location %s\n",rnode->place); if(rnode->phone&&*rnode->phone)fprintf(r,"Phone %s\n",rnode->phone); if(rnode->options&O_PWD)fprintf(r,"Password %s\n",rnode->pwd); fprintf(r,"Mailer %s\n",rnode->mailer); fprintf(r,"Site %s\n",rnode->name); if(!is_ip&&(ss=getenv("CALLER_ID"))&&strcasecmp(ss,"none")&&strlen(ss)>3)fprintf(r,"CallerID %s\n",ss); fprintf(r,"OurAKA %s\n",ftnaddrtoa(ma)); fprintf(r,"TRANX %08lu\n",time(NULL)); fclose(r); snprintf(s,MAX_PATH,"%s %s",cfgs(CFG_SRIFRP),sfn); } else snprintf(s,MAX_PATH,"%s -wazoo -%c -s%d %s /tmp/qreq.%04lx /tmp/qfls.%04lx /tmp/qrep.%04lx", cfgs(CFG_EXTRP),priv,rnode->realspeed,ftnaddrtoa(&rnode->addrs->addr),tpid,tpid,tpid); write_log("exec '%s' returned rc=%d",s,execsh(s)); lunlink(fn);lunlink(sfn); snprintf(fn,MAX_PATH,"/tmp/qfls.%04lx",tpid); if(!(f=fopen(fn,"rt"))) { snprintf(fn,MAX_PATH,"/tmp/qrep.%04lx",tpid); lunlink(fn); snprintf(fn,MAX_PATH,"/tmp/qfls.%04lx",tpid); lunlink(fn); write_log("can't open '%s' for reading",fn); return 0; } while(fgets(s,MAX_PATH-1,f)) { if(*s=='\n'||*s=='\r'||*s==' '||!*s)continue; ss=s;kil=0;got=1; if(*s=='='||*s=='-'){ss++;kil=1;} else if(*s=='+')ss++; p=ss+strlen(ss)-1; while(*p=='\r'||*p=='\n')*p--=0; p=strrchr(ss,' '); if(p)*p++=0;else p=ss; DEBUG(('R',1,"sending '%s' as '%s'%s",ss,qbasename((p!=ss)?p:ss),kil?" and kill":"")); addflist(&fl,xstrdup(ss),xstrdup(qbasename((p!=ss)?p:ss)),kil?'^':' ',0,NULL,0); } fclose(f);lunlink(fn); snprintf(fn,MAX_PATH,"/tmp/qrep.%04lx",tpid); if(!(f=fopen(fn,"rt"))&&wz)write_log("can't open '%s' for reading",fn); snprintf(fn,MAX_PATH,"/tmp/qpkt.%04lx%02x",tpid,++freq_pktcount); g=openpktmsg(ma,&rnode->addrs->addr,cfgs(CFG_FREQFROM),rnode->sysop,cfgs(CFG_FREQSUBJ),NULL,fn,1); if(!g) { write_log("can't open '%s' for writing: %s",fn,strerror(errno)); if(f)fclose(f); freq_pktcount--; } if(f&&g) { while(fgets(s,MAX_PATH-1,f)) { p=s+strlen(s)-1; while(*p=='\r'||*p=='\n')*p--=0; if(cfgi(CFG_RECODEPKTS))recode_to_remote(s); fputs(s,g);fputc('\r',g); } fclose(f); closeqpkt(g,ma); snprintf(s,MAX_PATH,"/tmp/qpkt.%04lx%02x",tpid,freq_pktcount); p=xstrdup(s); snprintf(s,MAX_PATH,"%08lx.pkt",sequencer()); addflist(&fl,p,xstrdup(s),'^',0,NULL,1); } snprintf(fn,MAX_PATH,"/tmp/qrep.%04lx",tpid); lunlink(fn); return got; }