/* * request.c * (C) Peter Salanki 2002 * This program is copyright, and covered by the Gnu Public License. * The Natasha bot. * sorcer@linux.se */ #include #include #include #include #include #include #include #include #include #include #include #include "../../settings.h" #include "../../globals.h" #include "../../bottypes.h" #include "settings.h" #define NAME "Trojan" #define VERSION 1.00 void checkfile(void); void *threadfunc(void* ptr); void TaGlobalBan (struct activeuser *u, char *reason, int len); MODULE_INIT _module_init(MODULE m); MODULE_DESTROY _module_destroy(MODULE m); int nextread; short destroythread = 0; pthread_t threadptr; MODULE_INIT _module_init(MODULE m) { strncpy(m->name, NAME, 20); strncpy(m->compiledate, __DATE__ " " __TIME__, 30); m->version = VERSION; nextread = time(NULL) + CHECKTIME; /* Create thread */ if(pthread_create(&threadptr, NULL, threadfunc, NULL)) printf("Error creating thread for trojan scan comfile check.\n"); } MODULE_DESTROY _module_destroy(MODULE m) { destroythread = 1; /* Join thread */ if(pthread_join(threadptr, NULL)) printf("Error joining thread for trojan scan.\n"); } void *threadfunc(void* ptr) { while(1) { if(nextread <= time(NULL)) { checkfile(); nextread = time(NULL) + CHECKTIME; } else if(destroythread == 1) return NULL; sleep(1); } } void checkfile(void) { char user[NICKLEN], link[512], reason[512]; int len; struct activeuser *u; FILE * pFile; pFile = fopen (COMFILE,"r"); while(fscanf (pFile, "%s %i %s", user, &len, link) != EOF) { if((u = findauser(user)) != NULL) { snprintf(reason, 512, "Infected by trojan, head to: %s for more info", link); TaGlobalBan(u, reason, len); } } fclose (pFile); /* Empty */ pFile = fopen (COMFILE,"w"); fclose (pFile); return; } void TaGlobalBan (struct activeuser *u, char *reason, int len) { struct aculink *aculink; char target[HOSTLEN+USERLEN+2]; char msg[512]; aculink = u->firstlink; snprintf(target, HOSTLEN+USERLEN+2, "%s@%s", u->username, u->hostname); while(aculink != NULL) { if(aculink->link->channel->isop == 1 && aculink->link->channel->ison == 1) { addban(aculink->link->channel, target, reason, 0, time(NULL) + len, u, reason, u->userid, 1); } else if(aculink->link->channel->isop == 0 && aculink->link->channel->ison == 1) { snprintf(msg, 512, "Warning: %c%s%c is infected by a trojan.", BOLD, u->nick, BOLD); privmsg(aculink->link->channel->name, msg); } aculink = aculink->next; } }