int send_uptime(void) { struct sockaddr_in sai; struct stat st; PackUp *mem; int len, servidx; char servhost[UHOSTLEN] = "none"; module_entry *me; if (uptimeip == -1) { uptimeip = get_ip(); if (uptimeip == -1) return -2; } uptimecount++; upPack.packets_sent = htonl(uptimecount); /* Tell the server how many uptime packets we've sent. */ upPack.now2 = htonl(time(NULL)); upPack.ontime = 0; if ((me = module_find("server", 1, 0))) { Function *server_funcs = me->funcs; if (server_online) { servidx = findanyidx(serv); strncpyz(servhost, dcc[servidx].host, sizeof servhost); upPack.ontime = htonl(server_online); } } if (!upPack.pid) upPack.pid = htonl(getpid()); if (!upPack.uptime) upPack.uptime = htonl(online_since); if (stat("/proc", &st) < 0) upPack.sysup = 0; else upPack.sysup = htonl(st.st_ctime); len = sizeof(upPack) + strlen(botnetnick) + strlen(servhost) + strlen(uptime_version); mem = (PackUp *) nmalloc(len); egg_bzero(mem, len); /* mem *should* be completely filled before it's * sent to the server. But belt-and-suspenders * is always good. */ my_memcpy(mem, &upPack, sizeof(upPack)); sprintf(mem->string, "%s %s %s", botnetnick, servhost, uptime_version); egg_bzero(&sai, sizeof(sai)); sai.sin_family = AF_INET; sai.sin_addr.s_addr = uptimeip; sai.sin_port = htons(uptime_port); len = sendto(uptimesock, (void *) mem, len, 0, (struct sockaddr *) &sai, sizeof(sai)); nfree(mem); return len; }
static char *cmd_putwire(int idx, char *message) { wire_list *w = wirelist; wire_list *w2 = wirelist; int wiretype; char wirecmd[512]; char wiremsg[512]; char wiretmp[512]; char wiretmp2[512]; char *enctmp; while (w) { if (w->sock == dcc[idx].sock) break; w = w->next; } if (!w) return ""; if (!message[1]) return ""; if ((strlen(message) > 3) && !strncmp(&message[1], "me", 2) && (message[3] == ' ')) { sprintf(wiretmp2, "!%s@%s", dcc[idx].nick, botnetnick); enctmp = encrypt_string(w->key, &message[3]); wiretype = 1; } else { sprintf(wiretmp2, "%s@%s", dcc[idx].nick, botnetnick); enctmp = encrypt_string(w->key, &message[1]); wiretype = 0; } strcpy(wiremsg, enctmp); nfree(enctmp); enctmp = encrypt_string(w->key, "wire"); strcpy(wiretmp, enctmp); nfree(enctmp); sprintf(wirecmd, "!wire%s", wiretmp); sprintf(wiretmp, "%s %s", wiretmp2, wiremsg); botnet_send_zapf_broad(-1, botnetnick, wirecmd, wiretmp); sprintf(wiretmp, "%s%s", wiretype ? "!" : "", dcc[findanyidx(w->sock)].nick); while (w2) { if (!strcmp(w2->key, w->key)) wire_display(findanyidx(w2->sock), w2->key, wiretmp, wiremsg); w2 = w2->next; } return ""; }
static int cmd_onwire(struct userrec *u, int idx, char *par) { wire_list *w, *w2; char wiretmp[512], wirecmd[512], idxtmp[512]; char idle[20], *enctmp; time_t now2 = now; w = wirelist; while (w) { if (w->sock == dcc[idx].sock) break; w = w->next; } if (!w) { dprintf(idx, "%s\n", WIRE_NOTONWIRE); return 0; } dprintf(idx, "----- %s '%s':\n", WIRE_CURRENTLYON, w->key); dprintf(idx, "----- Nick Bot Host\n"); dprintf(idx, "----- ---------- ---------- ------------------------------\n"); enctmp = encrypt_string(w->key, "wire"); sprintf(wirecmd, "!wire%s", enctmp); nfree(enctmp); enctmp = encrypt_string(w->key, dcc[idx].nick); strcpy(wiretmp, enctmp); nfree(enctmp); simple_sprintf(idxtmp, "!wirereq %d %s", dcc[idx].sock, wiretmp); botnet_send_zapf_broad(-1, botnetnick, wirecmd, idxtmp); w2 = wirelist; while (w2) { if (!strcmp(w2->key, w->key)) { int idx2 = findanyidx(w2->sock); if (now2 - dcc[idx2].timeval > 300) { unsigned long Days, hrs, mins; Days = (now2 - dcc[idx2].timeval) / 86400; hrs = ((now2 - dcc[idx2].timeval) - (Days * 86400)) / 3600; mins = ((now2 - dcc[idx2].timeval) - (hrs * 3600)) / 60; if (Days > 0) sprintf(idle, " [%s %lud%luh]", WIRE_IDLE, Days, hrs); else if (hrs > 0) sprintf(idle, " [%s %luh%lum]", WIRE_IDLE, hrs, mins); else sprintf(idle, " [%s %lum]", WIRE_IDLE, mins); } else idle[0] = 0; dprintf(idx, "----- %c%-9s %-9s %s%s\n", geticon(idx2), dcc[idx2].nick, botnetnick, dcc[idx2].host, idle); if (dcc[idx2].u.chat->away) dprintf(idx, "----- %s: %s\n", WIRE_AWAY, dcc[idx2].u.chat->away); } w2 = w2->next; } return 0; }
static void away_notes(char *bot, int sock, char *msg) { int idx = findanyidx(sock); if (egg_strcasecmp(bot, botnetnick)) return; if (msg && msg[0]) dprintf(idx, "%s\n", NOTES_STORED); else notes_read(dcc[idx].nick, 0, "+", idx); }
/* Close the current server connection. */ static void nuke_server(char *reason) { if (serv >= 0) { int servidx = findanyidx(serv); if (reason && (servidx > 0)) dprintf(servidx, "QUIT :%s\n", reason); disconnect_server(servidx); lostdcc(servidx); } }
static int cmd_wirelist(struct userrec *u, int idx, char *par) { wire_list *w = wirelist; int entry = 0; dprintf(idx, "Current Wire table: (Base table address = %p)\n", w); while (w) { dprintf(idx, "entry %d: w=%p idx=%d sock=%d next=%p\n", ++entry, w, findanyidx(w->sock), w->sock, w->next); w = w->next; } return 0; }
static char *wire_close() { wire_list *w = wirelist; char wiretmp[512]; char *enctmp; p_tcl_bind_list H_temp; /* Remove any current wire encrypt bindings for now, don't worry * about duplicate unbinds. */ while (w) { enctmp = encrypt_string(w->key, "wire"); sprintf(wiretmp, "!wire%s", enctmp); nfree(enctmp); wire_bot[0].name = wiretmp; wire_bot[0].flags = ""; wire_bot[0].func = (IntFunc) wire_filter; rem_builtins(H_bot, wire_bot); w = w->next; } w = wirelist; while (w && w->sock) { dprintf(findanyidx(w->sock), "----- %s\n", WIRE_UNLOAD); dprintf(findanyidx(w->sock), "----- %s\n", WIRE_NOLONGERWIRED); wire_leave(w->sock); w = wirelist; } rem_help_reference("wire.help"); rem_builtins(H_dcc, wire_dcc); H_temp = find_bind_table("filt"); rem_builtins(H_temp, wire_filt); H_temp = find_bind_table("chof"); rem_builtins(H_temp, wire_chof); del_lang_section("wire"); module_undepend(MODULE_NAME); return NULL; }
static int tcl_getpwd(ClientData cd, Tcl_Interp *irp, int argc, char *argv[]) { int i, idx; BADARGS(2, 2, " idx"); i = atoi(argv[1]); idx = findanyidx(i); if ((idx < 0) || (dcc[idx].type != &DCC_FILES)) { Tcl_AppendResult(irp, "invalid idx", NULL); return TCL_ERROR; } Tcl_AppendResult(irp, dcc[idx].u.file->dir, NULL); return TCL_OK; }
static int builtin_charidx(ClientData cd, Tcl_Interp *irp, int argc, char *argv[]) { Function F = (Function) cd; int idx; BADARGS(3, 3, " handle idx"); CHECKVALIDITY(builtin_charidx); idx = findanyidx(atoi(argv[2])); if (idx < 0) { Tcl_AppendResult(irp, "invalid idx", NULL); return TCL_ERROR; } Tcl_AppendResult(irp, int_to_base10(F(argv[1], idx)), NULL); return TCL_OK; }
static int gotmode(char *from, char *msg) { char *ch; ch = newsplit(&msg); /* Usermode changes? */ if (strchr(CHANMETA, ch[0]) == NULL) { if (match_my_nick(ch) && check_mode_r) { /* umode +r? - D0H dalnet uses it to mean something different */ fixcolon(msg); if ((msg[0] == '+') && strchr(msg, 'r')) { int servidx = findanyidx(serv); putlog(LOG_MISC | LOG_JOIN, "*", "%s has me i-lined (jumping)", dcc[servidx].host); nuke_server("i-lines suck"); } } } return 0; }
static int tcl_fileresend_send(ClientData cd, Tcl_Interp *irp, int argc, char *argv[], int resend) { int i, idx; char s[HANDLEN + 1]; BADARGS(3, 4, " idx filename ?nick?"); i = atoi(argv[1]); idx = findanyidx(i); if ((idx < 0) || (dcc[idx].type != &DCC_FILES)) { Tcl_AppendResult(irp, "invalid idx", NULL); return TCL_ERROR; } if (argc == 4) i = files_reget(idx, argv[2], argv[3], resend); else i = files_reget(idx, argv[2], "", resend); sprintf(s, "%d", i); Tcl_AppendResult(irp, s, NULL); return TCL_OK; }
static void wire_leave(int sock) { char wirecmd[513]; char wiremsg[513]; char wiretmp[513]; char *enctmp; wire_list *w = wirelist; wire_list *w2 = wirelist; wire_list *wlast = wirelist; while (w) { if (w->sock == sock) break; w = w->next; } if (!w) return; enctmp = encrypt_string(w->key, "wire"); strcpy(wirecmd, enctmp); nfree(enctmp); sprintf(wiretmp, "%s left the wire.", dcc[findanyidx(w->sock)].nick); enctmp = encrypt_string(w->key, wiretmp); strcpy(wiremsg, enctmp); nfree(enctmp); { char x[1024]; simple_sprintf(x, "!wire%s %s", wirecmd, botnetnick); botnet_send_zapf_broad(-1, botnetnick, x, wiremsg); } w2 = wirelist; while (w2) { if (w2->sock != sock && !strcmp(w2->key, w->key)) { dprintf(findanyidx(w2->sock), "----- %s %s\n", dcc[findanyidx(w->sock)].nick, WIRE_LEFT); } w2 = w2->next; } /* Check to see if someone else is using this wire key. * If so, then don't remove the wire filter binding. */ w2 = wirelist; while (w2) { if (w2 != w && !strcmp(w2->key, w->key)) break; w2 = w2->next; } if (!w2) { /* Someone else is NOT using this key */ wire_bot[0].name = wirecmd; wire_bot[0].flags = ""; wire_bot[0].func = (IntFunc) wire_filter; rem_builtins(H_bot, wire_bot); } w2 = wirelist; wlast = 0; while (w2) { if (w2 == w) break; wlast = w2; w2 = w2->next; } if (wlast) { if (w->next) wlast->next = w->next; else wlast->next = 0; } else if (!w->next) wirelist = 0; else wirelist = w->next; nfree(w->crypt); nfree(w->key); nfree(w); }
static void wire_join(int idx, char *key) { char wirecmd[512]; char wiremsg[512]; char wiretmp[512]; char *enctmp; wire_list *w = wirelist, *w2; while (w) { if (w->next == 0) break; w = w->next; } if (!wirelist) { wirelist = nmalloc(sizeof *wirelist); w = wirelist; } else { w->next = nmalloc(sizeof *w->next); w = w->next; } w->sock = dcc[idx].sock; w->key = nmalloc(strlen(key) + 1); strcpy(w->key, key); w->next = 0; enctmp = encrypt_string(w->key, "wire"); strcpy(wiretmp, enctmp); nfree(enctmp); w->crypt = nmalloc(strlen(wiretmp) + 1); strcpy(w->crypt, wiretmp); sprintf(wirecmd, "!wire%s", wiretmp); sprintf(wiremsg, "%s joined wire '%s'", dcc[idx].nick, key); enctmp = encrypt_string(w->key, wiremsg); strcpy(wiretmp, enctmp); nfree(enctmp); { char x[1024]; simple_sprintf(x, "%s %s", botnetnick, wiretmp); botnet_send_zapf_broad(-1, botnetnick, wirecmd, x); } w2 = wirelist; while (w2) { if (!strcmp(w2->key, w->key)) dprintf(findanyidx(w2->sock), "----- %s %s '%s'.\n", dcc[findanyidx(w->sock)].nick, WIRE_JOINED, w2->key); w2 = w2->next; } w2 = wirelist; while (w2) { /* Is someone using this key here already? */ if (w2 != w) if (!strcmp(w2->key, w->key)) break; w2 = w2->next; } if (!w2) { /* Someone else is NOT using this key, so * we add a bind */ wire_bot[0].name = wirecmd; wire_bot[0].flags = ""; wire_bot[0].func = (IntFunc) wire_filter; add_builtins(H_bot, wire_bot); } }
static void wire_filter(char *from, char *cmd, char *param) { char wirecrypt[512]; char wirewho[512]; char wiretmp2[512]; char wiretmp[512]; char wirereq[512]; wire_list *w = wirelist; char reqsock; time_t now2 = now; char idle[20]; char *enctmp; strcpy(wirecrypt, &cmd[5]); strcpy(wiretmp, param); nsplit(wirereq, param); /* * !wire<crypt"wire"> !wirereq <destbotsock> <crypt"destbotnick"> * ----- wirecrypt wirereq wirewho param */ if (!strcmp(wirereq, "!wirereq")) { nsplit(wirewho, param); while (w) { if (!strcmp(w->crypt, wirecrypt)) { int idx = findanyidx(w->sock); reqsock = atoi(wirewho); if (now2 - dcc[idx].timeval > 300) { unsigned long Days, hrs, mins; Days = (now2 - dcc[idx].timeval) / 86400; hrs = ((now2 - dcc[idx].timeval) - (Days * 86400)) / 3600; mins = ((now2 - dcc[idx].timeval) - (hrs * 3600)) / 60; if (Days > 0) sprintf(idle, " [%s %lud%luh]", WIRE_IDLE, Days, hrs); else if (hrs > 0) sprintf(idle, " [%s %luh%lum]", WIRE_IDLE, hrs, mins); else sprintf(idle, " [%s %lum]", WIRE_IDLE, mins); } else idle[0] = 0; sprintf(wirereq, "----- %c%-9s %-9s %s%s", geticon(idx), dcc[idx].nick, botnetnick, dcc[idx].host, idle); enctmp = encrypt_string(w->key, wirereq); strcpy(wiretmp, enctmp); nfree(enctmp); sprintf(wirereq, "zapf %s %s !wire%s !wireresp %s %s %s", botnetnick, from, wirecrypt, wirewho, param, wiretmp); dprintf(nextbot(from), "%s\n", wirereq); if (dcc[idx].u.chat->away) { sprintf(wirereq, "----- %s: %s\n", WIRE_AWAY, dcc[idx].u.chat->away); enctmp = encrypt_string(w->key, wirereq); strcpy(wiretmp, enctmp); nfree(enctmp); sprintf(wirereq, "zapf %s %s !wire%s !wireresp %s %s %s", botnetnick, from, wirecrypt, wirewho, param, wiretmp); dprintf(nextbot(from), "%s\n", wirereq); } } w = w->next; } return; } if (!strcmp(wirereq, "!wireresp")) { nsplit(wirewho, param); reqsock = atoi(wirewho); w = wirelist; nsplit(wiretmp2, param); while (w) { if (w->sock == reqsock) { int idx = findanyidx(reqsock); enctmp = decrypt_string(w->key, wiretmp2); strcpy(wirewho, enctmp); nfree(enctmp); if (!strcmp(dcc[idx].nick, wirewho)) { enctmp = decrypt_string(w->key, param); dprintf(idx, "%s\n", enctmp); nfree(enctmp); return; } } w = w->next; } return; } while (w) { if (!strcmp(wirecrypt, w->crypt)) wire_display(findanyidx(w->sock), w->key, wirereq, param); w = w->next; } }