aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorepochqwert <epoch@53flpnlls43fcguy.onion>2015-02-07 03:43:14 -0600
committerepochqwert <epoch@53flpnlls43fcguy.onion>2015-02-07 03:43:14 -0600
commit04e1a88e14844fa692c6bb6b484a2a2d9207f194 (patch)
treeebd349be733506cbdb04db74846f5486a9ef8c86
parente80dd3006171b33705395b0c7547f03925670bf9 (diff)
downloadsegfault-04e1a88e14844fa692c6bb6b484a2a2d9207f194.tar.gz
segfault-04e1a88e14844fa692c6bb6b484a2a2d9207f194.zip
took out startup_stuff because server messages can be handled now. !alias !004 !raw join #defualt or whatever you want the bot to do.
-rw-r--r--Makefile4
-rwxr-xr-xcmd3
-rw-r--r--libirc/libirc.c2
-rw-r--r--segfault.c111
-rwxr-xr-xshell8
5 files changed, 53 insertions, 75 deletions
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 <sys/select.h>
//#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;i<strlen(modes);i++) {
- if(mode & 1<<i) {
- m[j++]=modes[i];
- }
- }
- m[j]=0;
- return m;
-}
-
struct user *myuser;
char pid[6];
char mode_magic;
@@ -105,6 +99,20 @@ char *shitlist[] = { 0 };
void message_handler(int fd,char *from,struct user *user,char *msg,int redones);
void c_leetuntail(int fd,char *from,char *line,...);
+//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;i<strlen(modes);i++) {
+ if(mode & 1<<i) {
+ m[j++]=modes[i];
+ }
+ }
+ m[j]=0;
+ return m;
+}
+
void mywrite(int fd,char *b) {
int r;
if(!b) return;
@@ -139,14 +147,6 @@ void irc_nick(int fd,char *nick) {
free(hrm);
}
-/*// just in case your system doesn't have strndup
-char *strndup(char *s,int l) {
- char *r=strdup(s);
- r[l]=0;
- return r;
-}
-*/
-
void privmsg(int fd,char *who,char *msg) {
int i=0;
char *chunk,*hrm;
@@ -180,9 +180,11 @@ char *format_magic(int fd,char *from,struct user *user,char *orig_fmt,char *arg)
char **args,**notargs;
char *argCopy;
char *argN[10];
+ char randC[10][2]={"0","1","2","3","4","5","6","7","8","9"};
//lets split up arg?
if(!arg) arg="%s";
if(!(argCopy=strdup(arg))) return 0;
+ getcwd(seghome,SEGHOMELEN);
for(argN[j]=argCopy;argCopy[i];i++) {
if(argCopy[i] == ' ') {
argN[j]=argCopy+i;
@@ -202,7 +204,8 @@ char *format_magic(int fd,char *from,struct user *user,char *orig_fmt,char *arg)
switch(fmt[i]) {
case '~':case 'p':case 'n':case 'h':case 'u':case 'f':case 's':
case 'm':case '%':case '0':case '1':case '2':case '3':case '4':
- case '5':case '6':case '7':case '8':case '9'://when adding new format things add here and...
+ case '5':case '6':case '7':case '8':case '9':case 'r':
+ //when adding new format things add here and...
c++;
}
}
@@ -216,10 +219,10 @@ char *format_magic(int fd,char *from,struct user *user,char *orig_fmt,char *arg)
switch(fmt[i]) {
case '~':case 'p':case 'n':case 'h':case 'u':case 'f':case 's':
case 'm':case '%':case '0':case '1':case '2':case '3':case '4':
- case '5':case '6':case '7':case '8':case '9'://here.
+ case '5':case '6':case '7':case '8':case '9':case 'r'://here.
args[c]=((fmt[i]=='n')?user->nick:
((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