From 04e1a88e14844fa692c6bb6b484a2a2d9207f194 Mon Sep 17 00:00:00 2001 From: epochqwert Date: Sat, 7 Feb 2015 03:43:14 -0600 Subject: took out startup_stuff because server messages can be handled now. !alias !004 !raw join #defualt or whatever you want the bot to do. --- Makefile | 4 +- cmd | 3 ++ libirc/libirc.c | 2 +- segfault.c | 111 ++++++++++++++++++++++---------------------------------- shell | 8 ++-- 5 files changed, 53 insertions(+), 75 deletions(-) create mode 100755 cmd diff --git a/Makefile b/Makefile index d1db303..4f9aa5e 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,6 @@ clean: rm -f segfault install: - cp -f libhashtable/libhashtable.so /usr/local/lib/ - cp -f libirc/libirc.so /usr/local/lib/ + cd libirc && $(MAKE) install + cd libhashtable && $(MAKE) install cp -f segfault /usr/local/bin/segfault diff --git a/cmd b/cmd new file mode 100755 index 0000000..0756f84 --- /dev/null +++ b/cmd @@ -0,0 +1,3 @@ +#!/bin/sh +export PATH=$PATH:/usr/pkg/bin:/usr/local/bin:/usr/pkg/sbin:/usr/local/sbin +exec tail -n1 /home/segfault/files/cmd_in | setuidgid segfault bash 2>&1 > /home/segfault/files/cmd_out 2>&1 diff --git a/libirc/libirc.c b/libirc/libirc.c index 101d40e..d2bff54 100644 --- a/libirc/libirc.c +++ b/libirc/libirc.c @@ -10,7 +10,7 @@ #include //#define DEBUG "epoch" //nick or channel to send debug info to. -#define CHUNK 16 +#define CHUNK 4096 int serverConnect(char *serv,char *port) { struct addrinfo hints, *servinfo, *p; diff --git a/segfault.c b/segfault.c index 1f063bc..8404577 100644 --- a/segfault.c +++ b/segfault.c @@ -15,6 +15,14 @@ #include "libirc/irc.h" //epoch's libirc. should be included with segfault. #include "libhashtable/hashtable.h" //epoch's also. +/*// just in case your system doesn't have strndup +char *strndup(char *s,int l) { + char *r=strdup(s); + r[l]=0; + return r; +} +*/ + //might want to change some of these. #define TSIZE 65535 #define SERVER "127.0.0.1" @@ -42,20 +50,6 @@ #define PRIVMSG_LINE_LIMIT 0 -//this function isn't with the rest of them because... meh. -char *tailmode_to_txt(int mode) { - char *modes="recmbsnf"; - int i,j=0; - char *m=malloc(strlen(modes)); - for(i=0;inick: ((fmt[i]=='u')?user->user: - ((fmt[i]=='~')?getcwd(seghome,SEGHOMELEN): + ((fmt[i]=='~')?seghome: ((fmt[i]=='h')?user->host: ((fmt[i]=='f')?from: ((fmt[i]=='p')?pid: @@ -234,8 +237,9 @@ char *format_magic(int fd,char *from,struct user *user,char *orig_fmt,char *arg) /* hate */ ((fmt[i]=='6')?argN[6]: /* this, */ ((fmt[i]=='7')?argN[7]: /* dontcha? :)*/ ((fmt[i]=='8')?argN[8]: - ((fmt[i]=='9')?argN[9]:"%" - )))))))))))))))))); + ((fmt[i]=='9')?argN[9]: + ((fmt[i]=='r')?randC[rand()%10]:"%" + ))))))))))))))))))); fmt[i-1]=0; if(!(fmt+j)) exit(68); if(!(notargs[c]=strdup(fmt+j))) exit(66); @@ -529,10 +533,6 @@ void prestartup_stuff(int fd) { } } -void startup_stuff(int fd) { - c_leettail(fd,"#cmd","150./scripts/startup",myuser); -} - void debug_time(int fd,char *from,char *msg) { char tmp[100]; if(debug) { @@ -598,7 +598,6 @@ void c_amnesia(int fd,char *from,...) {//forget aliases ht_freevalues(&alias); ht_destroy(&alias); inittable(&alias,TSIZE); - //put this as a builtin I guess. } void c_lobotomy(int fd,char *from,...) {//forget builtins @@ -689,7 +688,6 @@ void c_id(int fd,char *from,...) { privmsg(fd,from,tmp); } -//fix this fucking shit. void c_leetuntail(int fd,char *from,char *line,...) { if(!line) { privmsg(fd,from,"usage: !leetuntail [target|*] filename"); @@ -724,7 +722,6 @@ void c_leetuntail(int fd,char *from,char *line,...) { } } -//check for possibility of dedupping code. void c_istaillocked(int fd,char *from,char *file,...) { char *msg=0; int i; @@ -786,16 +783,7 @@ char append_file(int fd,char *from,char *file,char *line,unsigned short nl) { } fcntl(fileno(fp),F_SETFL,O_NONBLOCK); eofp(fp); -/* mywrite(fileno(fp),line); - mywrite(fileno(fp),"\n");*/ fprintf(fp,"%s\n",line); -/* - fcntl(fdd,F_SETFL,O_NONBLOCK); - eofd(fdd); - mywrite(fdd,line); - mywrite(fdd,"\n"); -*/ -// close(fdd); fclose(fp); return 1; } @@ -893,7 +881,6 @@ void c_rawrecord(int fd,char *from,char *line,...) { privmsg(fd,from,recording_raw?"1":"0"); } - void c_leetsetout(int fd,char *from,char *msg,...) { if(!msg) { privmsg(fd,from,"usage: don't"); @@ -988,6 +975,7 @@ void message_handler(int fd,char *from,struct user *user,char *msg,int redones) char tmp[512]; int len; int sz; + //privmsg(fd,"#debug",msg); //debug_time(fd,from); if(user->nick) { if(strcmp(user->nick,myuser->nick)) { @@ -1093,8 +1081,6 @@ void line_handler(int fd,char *line) {//this should be built into the libary? if(recording_raw) { append_file(fd,"epoch",RAWLOG,line,'\n'); } - - // rewrite this shit. if(line[0]==':') { if((user->nick=strchr(line,':'))) { *(user->nick)=0; @@ -1125,7 +1111,6 @@ void line_handler(int fd,char *line) {//this should be built into the libary? user->host=user->nick; } } - //all this shit. printf("<%s!%s@%s> '%s' '%s' '%s'\n", user->nick, @@ -1133,28 +1118,19 @@ void line_handler(int fd,char *line) {//this should be built into the libary? user->host, s,t,u); if(!user->user && s) { //server message - if(!strcmp(s,"433")) {//nick already used. - srand(time(NULL)*getpid()); - myuser->nick[strlen(myuser->nick)-3]=(rand()%10)+'0'; - myuser->nick[strlen(myuser->nick)-2]=(rand()%10)+'0'; - myuser->nick[strlen(myuser->nick)-1]=(rand()%10)+'0'; - irc_nick(fd,myuser->nick); - } - else if(!strcmp(s,"004")) {//we're connected. - startup_stuff(fd); - } //:armitage.hacking.allowed.org 353 asdf = #default :@SegFault @FreeArtMan @foobaz @wall @Lamb3_13 @gizmore @blackh0le strcpy(tmp,"!"); strcat(tmp,s); - if(ht_getnode(&alias,tmp) != NULL) { //don't bother to do a WHOLE message handler if the alias doesn't exist. + if(ht_getnode(&alias,tmp) != NULL) { snprintf(tmp,sizeof(tmp),"!%s %s",s,u); - message_handler(fd,"#cmd",user,tmp,0); + user->nick=strdup("epoch"); + user->user=strdup("epoch"); + user->host=strdup("localhost"); + message_handler(fd,"#cmd",user,tmp,1); + free(user->nick); + free(user->user); + free(user->host); } -/* -:armitage.hacking.allowed.org 376 asdf :End of MOTD commandWHO #default -:armitage.hacking.allowed.org 352 asdf #default user hostname server nick H@ :0 name -:armitage.hacking.allowed.org 315 asdf #default :End of WHO list -*/ } if(s && t && u) { if(!strcmp(s,"PRIVMSG") && strcmp(user->nick,myuser->nick)) { @@ -1178,12 +1154,11 @@ void line_handler(int fd,char *line) {//this should be built into the libary? } } } -//:Ishikawa-!~epoch@localhost NICK :checking - if(!strcmp(s,"NICK")) { + if(!strcmp(s,"NICK") && t) { if(!strcmp(user->nick,myuser->nick)) { free(myuser->nick); - if(!t+1) exit(79); - myuser->nick=strdup(t+1); + if(!t) exit(79); + if(!(myuser->nick=strdup(t+1))) exit(179); } } } diff --git a/shell b/shell index 2d98edf..d9fd19c 100755 --- a/shell +++ b/shell @@ -1,7 +1,7 @@ #!/bin/sh #this is to keep stale tails from hanging around... -pkill -P 1 -f "tail -f /home/segfault/files/cmd_in" +pkill -P 1 -f "tail -f /home/segfault/files/sh_in" mkdir -p /home/segfault/files -mkfifo /home/segfault/files/cmd_in -mkfifo /home/segfault/files/cmd_out -exec setuidgid segfault tail -f /home/segfault/files/cmd_in | su -l segfault 2>&1 > /home/segfault/files/cmd_out 2>&1 +mkfifo /home/segfault/files/sh_in +mkfifo /home/segfault/files/sh_out +exec setuidgid segfault tail -f /home/segfault/files/sh_in | su -l segfault 2>&1 > /home/segfault/files/sh_out 2>&1 -- cgit v1.2.3