void printJson() { pthread_rwlock_rdlock(&rwlock); if (strlen(path_tmp) < 5) return; FILE *fout = fopen(path_tmp, "w"); if (!fout) return; fprintf(fout, "{\n"); struct timeval tv; gettimeofday(&tv, NULL); long long current_time = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000; fprintf(fout, "\"time\": %lld,\n", current_time); fprintf(fout, "\"maclist\": ["); int i; int hasmac = 0; for (i = 0; i < 256; ++i) { struct Maclist *maclist = maclists[i]; while (maclist) { if (hasmac) fprintf(fout, ","); fprintf(fout, "\n {\n"); fprintf(fout, " \"macaddr\": \""); printmac(fout, maclist->addr); fprintf(fout, "\",\n"); fprintf(fout, " \"ip\": ["); struct Record* record = maclist->records; int hasrecord = 0; while (record) { if (hasrecord) fprintf(fout, ","); hasrecord = 1; fprintf(fout, "\n {\n"); fprintf(fout, " \"ipaddr\": \""); if (record->addrlen == 4) printipv4(fout, record->addr); else { char str[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, record->addr, str, INET6_ADDRSTRLEN); fprintf(fout, "%s", str); } fprintf(fout, "\",\n"); fprintf(fout, " \"upstream-bytes\": %lld,\n", record->bytes_up); fprintf(fout, " \"downstream-bytes\": %lld\n", record->bytes_down); fprintf(fout, " }"); record = record->next; } fprintf(fout, "]\n }"); hasmac = 1; maclist = maclist->next; } } fprintf(fout, "\n]}\n"); fclose(fout); char cmd[1000] = {0}; sprintf(cmd, "mv %s %s", path_tmp, path); system(cmd); pthread_rwlock_unlock(&rwlock); }
void dotrustdel(long unum, char *tail) { int res; char tmps2[TMPSSIZE], tmps3[TMPSSIZE], tmps4[TMPSSIZE]; trustedgroup *tg; trustedhost *th, *t2; unsigned long theip; int arw=0; res=sscanf(tail,"%s %s %s",tmps2,tmps3,tmps4); if (res!=2) { msgtouser(unum,"Syntax: trustdel IP"); return; } theip=parseipv4(tmps3); th=trustedhosts[tlhash(theip)]; t2=NULL; while (th!=NULL) { if (th->IPv4==theip) { long i; userdata *u; tg=findtrustgroupbyID(th->id); if (t2==NULL) { trustedhosts[tlhash(theip)]=(void *)th->next; } else { t2->next=th->next; } free(th); /* Recount the host */ for (i=0;i<SIZEOFUL;i++) { u=uls[i]; while (u!=NULL) { if (u->realip==theip) { int currenton; delfromtrustedhost(u->ident,tg->id); updatetrustedhost(theip,-1); currenton=sncget(theip,32); if (currenton>=mf4warn[32]) { /* Clonelimit for that host exceeded */ if ((mf4warn[32]>=0) && (arw==0)) { char * mycip=printipv4(u->realip); sprintf(tmps2,"[%d] clones detected from (previously trusted host) %s(=%s)",currenton,u->host,mycip); noticeallircops(tmps2); putlog("[clones] %d clones detected from (now) untrusted host %s(=%s)",currenton,u->host,mycip); free(mycip); arw++; } } } u=(void *)u->next; } } recreateimpsntrusts(); numtonick(unum,tmps4); sprintf(tmps2,"%s removed trust for IP %s",tmps4,tmps3); sendtonoticemask(NM_TRUSTS,tmps2); sprintf(tmps2,"IP removed from Trustgroup %s (#%lu)",tg->name,tg->id); msgtouser(unum,tmps2); return; } else { t2=th; th=(void *)th->next; } } msgtouser(unum,"That IP was not trusted."); }
static void dump(struct Maclist* mac, struct Record* record) { printmac(stdout, mac->addr); printf(" "); if (record->addrlen == 4) printipv4(stdout, record->addr); else printipv6(record->addr); printf(" "); printf("%lld %lld\n", record->bytes_up, record->bytes_down); }
void dotrustungline(long unum, char *tail) { int res; char tmps2[TMPSSIZE], tmps3[TMPSSIZE], tmps4[TMPSSIZE], tmps5[TMPSSIZE]; trustedgroup *tg; trustedhost *th; int i; array listofths; res=sscanf(tail, "%s %s %s",tmps2,tmps3,tmps4); if (res<3) { msgtouser(unum,"Syntax: trustungline <groupname OR #groupID> user"); msgtouser(unum,"user may contain wildcards"); return; } tmps4[USERLEN+2]='\0'; toLowerCase(tmps3); toLowerCase(tmps4); if (tmps3[0]=='#') { tg=findtrustgroupbyID(strtol(&tmps3[1],NULL,10)); } else { tg=findtrustgroupbyname(tmps3); } if (tg==NULL) { sprintf(tmps2,"A trustgroup with that %s does not exist.",(tmps3[0]=='#') ? "ID" : "name"); msgtouser(unum,tmps2); return; } /* First, create a list of all hosts in that trustgroup... */ array_init(&listofths,sizeof(unsigned long)); for (i=0;i<SIZEOFTL;i++) { th=trustedhosts[i]; while (th!=NULL) { if (th->id==tg->id) { /* mmkay, that one belongs to our group */ long j; j=array_getfreeslot(&listofths); ((unsigned long *)listofths.content)[j]=th->IPv4; } th=(void *)th->next; } } if (listofths.cursi==0) { msgtouser(unum,"There are no hosts in that trustgroup."); array_free(&listofths); return; } /* starting ungline.. */ for (i=0;i<listofths.cursi;i++) { char * mycip; mycip=printipv4(((unsigned long *)listofths.content)[i]); sprintf(tmps2,"%s@%s",tmps4,mycip); free(mycip); remgline(tmps2,1); } numtonick(unum,tmps5); sprintf(tmps2,"Removed GLINE for %s @ trustgroup %s (#%lu)",tmps4,tg->name,tg->id); msgtouser(unum,tmps2); sprintf(tmps2,"GLINE %s @ trustgroup %s (#%lu) removed by %s",tmps4, tg->name,tg->id,tmps5); sendtonoticemask(NM_GLINE,tmps2); array_free(&listofths); }
unsigned long displaytrustgroupwithid(long unum, unsigned long showid, unsigned int showhosts) { long i; trustedhost *th; trustedgroup *tg; char tmps2[TMPSSIZE], tmps3[TMPSSIZE]; char * mycip; unsigned long linesshown=0; tg=findtrustgroupbyID(showid); if (tg==NULL) { return linesshown; } newmsgtouser(unum,"Trustgroup '%s' (ID #%lu) last changed by %s - currently online: %d",tg->name,tg->id,tg->creator,tg->currentlyon); longtoduration(tmps3,tg->expires - getnettime()); newmsgtouser(unum,"Settings: Enforcing ident: %s - trusted for %d - %d per user - expires in %s", (tg->enforceident == 1) ? "yes" : "no ", tg->trustedfor, tg->maxperident, tmps3); newmsgtouser(unum,"Contact: %s - Comment: %s",tg->contact,tg->comment); longtoduration(tmps3,(getnettime() - tg->lastused)); strcat(tmps3," ago"); longtoduration(tmps2,(getnettime() - tg->maxreset)); strcat(tmps2," ago"); newmsgtouser(unum,"Last used: %s - Max usage: %lu - Last Maxuse reset: %s", (tg->currentlyon>0) ? "now" : ((tg->lastused==0) ? "never" : tmps3), tg->maxused, (tg->maxreset==0) ? "never" : tmps2); if (showhosts==0) { return 4; } tmps2[0]=0; linesshown=4; for (i=0;i<SIZEOFTL;i++) { th=trustedhosts[i]; while (th!=NULL) { if (th->id==showid) { longtoduration(tmps3,(getnettime() - th->lastused)); strcat(tmps3," ago"); mycip=printipv4(th->IPv4); if (tmps2[0]==0) { sprintf(tmps2,"%s (Cur: %lu Max: %lu Last: %s)",mycip, th->currentlyon,th->maxused,(th->currentlyon>0) ? "now" : ((th->lastused==0) ? "never" : tmps3)); } else { newmsgtouser(unum,"|-%s",tmps2); linesshown++; sprintf(tmps2,"%s (Cur: %lu Max: %lu Last: %s)",mycip, th->currentlyon,th->maxused,(th->currentlyon>0) ? "now" : ((th->lastused==0) ? "never" : tmps3)); } free(mycip); } th=(void *)th->next; } } if (tmps2[0]==0) { msgtouser(unum,"`- no hosts in that group"); } else { newmsgtouser(unum,"`-%s",tmps2); } linesshown++; return linesshown; }
void dotrustdenylist(long unum, char *tail) { int res; char tmps2[TMPSSIZE], tmps3[TMPSSIZE]; long i, j; trustdeny *td; unsigned long snet, smask; char * mycip; res=sscanf(tail,"%s %s",tmps2,tmps3); if (res<2) { strcpy(tmps3,"0.0.0.0/0"); } if (!ischarinstr('/',tmps3)) { smask=32; snet=parseipv4(tmps3); } else { char h1[TMPSSIZE]; char h2[TMPSSIZE]; char dumc; int r2; r2=sscanf(tmps3,"%[0-9.]%c%[0-9]",h1,&dumc,h2); if (r2!=3) { msgtouser(unum,"Invalid subnetmask."); return; } snet=parseipv4(h1); smask=strtoul(h2,NULL,10); if (smask>32) { msgtouser(unum,"Invalid subnetmask."); return; } } trustdenyexpire(); td=(trustdeny *)deniedtrusts.content; j=0; for (i=0;i<deniedtrusts.cursi;i++) { if (((td[i].v4net&netmasks[smask])==(snet&netmasks[smask])) || ((td[i].v4net&netmasks[td[i].v4mask])==(snet&netmasks[td[i].v4mask]))) { if (j==0) { newmsgtouser(unum,"%-30s %-15s %-17s %-1s %s","IP/mask","by","expires in","t","Reason"); } longtoduration(tmps2,td[i].expires-getnettime()); mycip=printipv4(td[i].v4net); newmsgtouser(unum,"%-27s/%02u %-15s %-17s %s %s",mycip,td[i].v4mask,td[i].creator, tmps2,(td[i].type==TRUSTDENY_DENY) ? "D" : "W", td[i].reason); free(mycip); j++; } } if (j==0) { msgtouser(unum,"--- No matches ---"); } else { newmsgtouser(unum,"--- End of list - %ld matches ---",j); } }
/* * IPCP RX protocol Handler */ void ipcp_rx(u8_t *buffer, u16_t count) { u8_t *bptr = buffer; // IPCPPKT *pkt=(IPCPPKT *)buffer; u16_t len; ANNOTATE("IPCP len %d\n",count); switch(*bptr++) { case CONF_REQ: /* parce request and see if we can ACK it */ ++bptr; len = (*bptr++ << 8); len |= *bptr++; /* len-=2; */ ANNOTATE("check ipcplist\n"); if(scan_packet(IPCP, ipcplist, buffer, bptr, (u16_t)(len - 4))) { ANNOTATE("option was bad\n"); } else { ANNOTATE("IPCP options are good\n"); /* * Parse out the results */ /* lets try to implement what peer wants */ /* Reject any protocol not */ /* Error? if we we need to send a config Reject ++++ this is good for a subroutine*/ /* All we should get is the peer IP address */ if(IPCP_IPADDRESS == *bptr++) { /* dump length */ ++bptr; #ifdef IPCP_GET_PEER_IP ((u8_t*)peer_ip_addr.u8)[0] = *bptr++; ((u8_t*)peer_ip_addr.u8)[1] = *bptr++; ((u8_t*)peer_ip_addr.u8)[2] = *bptr++; ((u8_t*)peer_ip_addr.u8)[3] = *bptr++; ANNOTATE("Peer IP, remote ip address:"); printipv4(peer_ip_addr); ANNOTATE("\n"); #else bptr += 4; #endif } else { ANNOTATE("HMMMM this shouldn't happen IPCP1\n"); } #if 0 if(error) { /* write the config NAK packet we've built above, take on the header */ bptr = buffer; *bptr++ = CONF_NAK; /* Write Conf_rej */ *bptr++; /*tptr++;*/ /* skip over ID */ /* Write new length */ *bptr++ = 0; *bptr = tptr - buffer; /* write the reject frame */ ANNOTATE("Writing NAK frame \n"); ahdlc_tx(IPCP, buffer, (u16_t)(tptr - buffer)); ANNOTATE("- End NAK Write frame\n"); } else { } #endif /* * If we get here then we are OK, lets send an ACK and tell the rest * of our modules our negotiated config. */ ipcp_state |= IPCP_RX_UP; ipcp_state &= ~IPCP_TX_UP;//phlb force send request with ipcp task ANNOTATE("Send IPCP ACK!\n"); bptr = buffer; *bptr++ = CONF_ACK; /* Write Conf_ACK */ bptr++; /* Skip ID (send same one) */ /* * Set stuff */ ppp_flags |= tflag; ANNOTATE("SET- stuff -- are we up? c=%d dif=%d \n", count, (u16_t)(bptr-buffer)); /* write the ACK frame */ ANNOTATE("Writing ACK frame \n"); /* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */ ahdlc_tx(IPCP, 0, buffer, 0, count /*bptr-buffer*/); ANNOTATE("- End ACK Write frame\n"); /* expire the timer to make things happen after a state change */ TIMER_expire(); //timer_expire(); //modify phlb uncomment /* } */ } break; case CONF_ACK: /* config Ack */ ANNOTATE("CONF ACK\n"); /* * Parse out the results * * Dump the ID and get the length. */ /* dump the ID */ bptr++; /* get the length */ len = (*bptr++ << 8); len |= *bptr++; //#if 0 //modify phlb /* Parse ACK and set data */ while(bptr < buffer + len) { switch(*bptr++) { case IPCP_IPADDRESS: /* dump length */ bptr++; ((u8_t*)pppif.ipaddr.u8)[0] = *bptr++; ((u8_t*)pppif.ipaddr.u8)[1] = *bptr++; ((u8_t*)pppif.ipaddr.u8)[2] = *bptr++; ((u8_t*)pppif.ipaddr.u8)[3] = *bptr++; break; case IPCP_PRIMARY_DNS: bptr++; pri_dns_addr.u8[0] = *bptr++; pri_dns_addr.u8[1] = *bptr++; pri_dns_addr.u8[2] = *bptr++; pri_dns_addr.u8[3] = *bptr++; break; case IPCP_SECONDARY_DNS: bptr++; sec_dns_addr.u8[0] = *bptr++; sec_dns_addr.u8[1] = *bptr++; sec_dns_addr.u8[2] = *bptr++; sec_dns_addr.u8[3] = *bptr++; break; default: ANNOTATE("IPCP CONFIG_ACK problem1\n"); } } //#endif ipcp_state |= IPCP_TX_UP; /*ipcp_state &= ~IPCP_RX_UP;*/ ANNOTATE("were up! \n"); printipv4(pppif.ipaddr); #ifdef IPCP_GET_PRI_DNS printipv4(pri_dns_addr); #endif #ifdef IPCP_GET_SEC_DNS printipv4(sec_dns_addr); #endif ANNOTATE("\n"); /* expire the timer to make things happen after a state change */ TIMER_expire(); break; case CONF_NAK: /* Config Nack */ ANNOTATE("CONF NAK\n"); /* dump the ID */ ppp_id=*bptr++; /* get the length */ len = (*bptr++ << 8); len |= *bptr++; /* Parse ACK and set data */ while(bptr < buffer + len) { switch(*bptr++) { case IPCP_IPADDRESS: /* dump length */ bptr++; ((u8_t*)pppif.ipaddr.u8)[0] = *bptr++; ((u8_t*)pppif.ipaddr.u8)[1] = *bptr++; ((u8_t*)pppif.ipaddr.u8)[2] = *bptr++; ((u8_t*)pppif.ipaddr.u8)[3] = *bptr++; uip_fw_register( &pppif ); //to do: force host ip address for uIP uip_hostaddr.u8[0]= pppif.ipaddr.u8[0]; uip_hostaddr.u8[1]= pppif.ipaddr.u8[1]; uip_hostaddr.u8[2]= pppif.ipaddr.u8[2]; uip_hostaddr.u8[3]= pppif.ipaddr.u8[3]; ANNOTATE("local ip address: (%d.%d.%d.%d)\n", ((u8_t*)pppif.ipaddr.u8)[0], ((u8_t*)pppif.ipaddr.u8)[1], ((u8_t*)pppif.ipaddr.u8)[2], ((u8_t*)pppif.ipaddr.u8)[3]); break; #ifdef IPCP_GET_PRI_DNS case IPCP_PRIMARY_DNS: bptr++; pri_dns_addr.u8[0] = *bptr++; pri_dns_addr.u8[1] = *bptr++; pri_dns_addr.u8[2] = *bptr++; pri_dns_addr.u8[3] = *bptr++; break; #endif #ifdef IPCP_GET_SEC_DNS case IPCP_SECONDARY_DNS: bptr++; sec_dns_addr.u8[0] = *bptr++; sec_dns_addr.u8[1] = *bptr++; sec_dns_addr.u8[2] = *bptr++; sec_dns_addr.u8[3] = *bptr++; break; #endif default: ANNOTATE("IPCP CONFIG_ACK problem 2\n"); } } ppp_id++; // printipv4(pppif.ipaddr); #ifdef IPCP_GET_PRI_DNS printipv4(pri_dns_addr); #endif #ifdef IPCP_GET_PRI_DNS printipv4(sec_dns_addr); #endif ANNOTATE("\n"); /*Send CONF_REQ with NACK config*/ ANNOTATE("Send IPCP REQ with NACK config!\n"); ipcp_state &= ~IPCP_TX_UP; bptr = buffer; *bptr++ = CONF_REQ; /* Write CONF_REQ */ *bptr++=ppp_id; /* Skip ID (send same one) */ /* write the ACK frame */ ANNOTATE("Writing REQ frame \n"); /* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */ ahdlc_tx(IPCP, 0, buffer, 0, count /*bptr-buffer*/); ANNOTATE("- End REQ Write frame\n"); /* expire the timer to make things happen after a state change */ TIMER_expire(); break; case CONF_REJ: /* Config Reject */ ANNOTATE("CONF REJ\n"); /* Remove the offending options*/ ppp_id++; /* dump the ID */ bptr++; /* get the length */ len = (*bptr++ << 8); len |= *bptr++; /* Parse ACK and set data */ while(bptr < buffer + len) { switch(*bptr++) { case IPCP_IPADDRESS: ipcp_state |= IPCP_IP_BIT; bptr += 5; break; #ifdef IPCP_GET_PRI_DNS case IPCP_PRIMARY_DNS: ipcp_state |= IPCP_PRI_DNS_BIT; bptr += 5; break; #endif #ifdef IPCP_GET_PRI_DNS case IPCP_SECONDARY_DNS: ipcp_state |= IPCP_SEC_DNS_BIT; bptr += 5; break; #endif default: ANNOTATE("IPCP this shoudln't happen 3\n"); } } /* expire the timer to make things happen after a state change */ /*timer_expire(); */ break; default: ANNOTATE("-Unknown 4\n"); } }
void dotrustspew(long unum, char *tail) { int res; char tmps2[TMPSSIZE], tmps3[TMPSSIZE], tmps4[TMPSSIZE], tmps5[TMPSSIZE]; trustedgroup *tg; trustedhost *th; int i; userdata *ud; long k, l; array listofths; int iamtired; res=sscanf(tail, "%s %s %s",tmps2,tmps3,tmps4); if (res<2) { msgtouser(unum,"Syntax: trustspew <groupname OR #groupID> [user]"); return; } if (res==2) { strcpy(tmps4,"*"); } tmps4[USERLEN+2]='\0'; toLowerCase(tmps3); toLowerCase(tmps4); if (tmps3[0]=='#') { tg=findtrustgroupbyID(strtol(&tmps3[1],NULL,10)); } else { tg=findtrustgroupbyname(tmps3); } if (tg==NULL) { sprintf(tmps2,"A trustgroup with that %s does not exist.",(tmps3[0]=='#') ? "ID" : "name"); msgtouser(unum,tmps2); return; } /* First, create a list of all hosts in that trustgroup... */ array_init(&listofths,sizeof(unsigned long)); for (i=0;i<SIZEOFTL;i++) { th=trustedhosts[i]; while (th!=NULL) { if (th->id==tg->id) { /* mmkay, that one belongs to our group */ long j; j=array_getfreeslot(&listofths); ((unsigned long *)listofths.content)[j]=th->IPv4; } th=(void *)th->next; } } if (listofths.cursi==0) { msgtouser(unum,"There are no hosts in that trustgroup."); array_free(&listofths); return; } /* We have the list - scan through the whole userlist, and match against our hostlist, and if that matches, match again against the username */ sprintf(tmps2,"Users in Trustgroup %s (#%lu) matching %s",tg->name,tg->id,tmps4); msgtouser(unum,tmps2); l=0; for (i=0;i<SIZEOFUL;i++) { ud=uls[i]; while (ud!=NULL) { for (k=0;k<listofths.cursi;k++) { if (((unsigned long *)listofths.content)[k]==ud->realip) { /* Host matches, check username */ strcpy(tmps5,ud->ident); toLowerCase(tmps5); if (match2strings(tmps4,tmps5)) { /* yay ident matches too - list that loser */ channel **d; int chanmodes; char * mycip; l++; /* inc counter of number of users found */ mycip=printipv4(ud->realip); sprintf(tmps2,"%s!%s@%s(=%s) (%s)",ud->nick,ud->ident,ud->host,mycip,ud->realname); msgtouser(unum,tmps2); if (ud->chans.cursi>0) { if (ud->chans.cursi==1) { strcpy(tmps2,"On channel:"); } else { strcpy(tmps2,"On channels:"); } for (iamtired=0;iamtired<(ud->chans.cursi);iamtired++) { d=(channel **)(ud->chans.content); if ((strlen(d[iamtired]->name)+strlen(tmps2))>400) { strcat(tmps2," [...]"); break; } else { chanmodes=getchanmode2(d[iamtired],ud->numeric); strcat(tmps2," "); if (chanmodes<0) { strcat(tmps2,"?"); } else { if (isflagset(chanmodes,um_o)) { strcat(tmps2,"@"); } else { strcat(tmps2," "); } } strcat(tmps2,d[iamtired]->name); } } } else { strcpy(tmps2,"Not on any (nonlocal-)channels"); } msgtouser(unum,tmps2); } } } ud=(void *)ud->next; } } sprintf(tmps2,"--- End of list - %ld matches ---",l); msgtouser(unum,tmps2); array_free(&listofths); }
void dotrustgline(long unum, char *tail) { int res; char tmps2[TMPSSIZE], tmps3[TMPSSIZE], tmps4[TMPSSIZE], tmps5[TMPSSIZE]; char tmps6[TMPSSIZE]; long r2; userdata *a; trustedgroup *tg; trustedhost *th; int i, j; long l; array listofths; res=sscanf(tail, "%s %s %s %s %[^\n]",tmps2,tmps3,tmps4,tmps5,tmps6); if (res<4) { msgtouser(unum,"Syntax: trustgline <groupname OR #groupID> user duration [reason]"); msgtouser(unum,"user may contain wildcards"); return; } if (res==4) { numtonick(unum,tmps2); sprintf(tmps6,"requested by %s",tmps2); } tmps4[USERLEN+2]='\0'; toLowerCase(tmps3); toLowerCase(tmps4); r2=durationtolong(tmps5); if (r2<=0) { sprintf(tmps2,"The duration you gave is invalid."); msgtouser(unum,tmps2); return; } if (tmps3[0]=='#') { tg=findtrustgroupbyID(strtol(&tmps3[1],NULL,10)); } else { tg=findtrustgroupbyname(tmps3); } if (tg==NULL) { sprintf(tmps2,"A trustgroup with that %s does not exist.",(tmps3[0]=='#') ? "ID" : "name"); msgtouser(unum,tmps2); return; } /* First, create a list of all hosts in that trustgroup... */ array_init(&listofths,sizeof(unsigned long)); for (i=0;i<SIZEOFTL;i++) { th=trustedhosts[i]; while (th!=NULL) { if (th->id==tg->id) { /* mmkay, that one belongs to our group */ long j; j=array_getfreeslot(&listofths); ((unsigned long *)listofths.content)[j]=th->IPv4; } th=th->next; } } if (listofths.cursi==0) { msgtouser(unum,"There are no hosts in that trustgroup."); array_free(&listofths); return; } /* Now that we have the list: count number of users hit */ l=0; for (j=0;j<SIZEOFUL;j++) { a=uls[j]; while (a!=NULL) { char tmpu[USERLEN+1]; strcpy(tmpu,a->ident); toLowerCase(tmpu); for (i=0;i<listofths.cursi;i++) { unsigned long *bla; bla=(unsigned long *)listofths.content; if (bla[i]==a->realip) { if (match2strings(tmps4,tmpu)) { l++; break; } } } a=(void *)a->next; } } if (l>GLINEMAXHIT) { newmsgtouser(unum,"That gline would hit more than %d (%d) Users/Channels. You probably mistyped something.",GLINEMAXHIT,l); if ((l<(GLINEMAXHIT*10)) && (getauthlevel(unum)>=999)) { msgtouser(unum,"However, your authlevel is >=999, so I hope you know what you're doing... Executing command."); } else { array_free(&listofths); return; } } /* OK, safety checks done - now gline the fuckers */ numtonick(unum,tmps5); for (i=0;i<listofths.cursi;i++) { unsigned long *bla; char * mycip; bla=(unsigned long *)listofths.content; mycip=printipv4(bla[i]); sprintf(tmps2,"%s@%s",tmps4,mycip); free(mycip); addgline(tmps2,tmps6,tmps5,r2,1); } sprintf(tmps2,"Added GLINE for %s @ trustgroup %s (#%lu), caused %lu glines, hit %ld users",tmps4,tg->name,tg->id, listofths.cursi,l); msgtouser(unum,tmps2); sprintf(tmps2,"GLINE %s @ trustgroup %s (#%lu) by %s, caused %lu glines, hit %ld users",tmps4, tg->name,tg->id,tmps5,listofths.cursi,l); sendtonoticemask(NM_GLINE,tmps2); array_free(&listofths); }
void dotrustlist(long unum, char *tail) { int res; char tmps2[TMPSSIZE], tmps3[TMPSSIZE], tmps4[TMPSSIZE]; array listofids; long i; trustedgroup *tg; trustedhost *th; long j; unsigned long lastshown, showid; unsigned long numshown=0; char tmps5[TMPSSIZE]; unsigned int showhosts=65000; res=sscanf(tail,"%s %s %s",tmps2,tmps3,tmps4); if (res>3) { msgtouser(unum,"Syntax: trustlist [-h] [pattern]"); return; } if (res>=2) { toLowerCase(tmps3); if (strcmp(tmps3,"-h")==0) { showhosts=0; if (res<3) { strcpy(tmps3,"*"); } else { strcpy(tmps3,tmps4); } } else { if (res==3) { msgtouser(unum,"Invalid parameter"); return; } } } if (res==1) { strcpy(tmps3,"*"); } toLowerCase(tmps3); trustgroupexpire(); if (tmps3[0]=='#') { if ((!ischarinstr('*',tmps3)) && (!ischarinstr('?',tmps3))) { newmsgtouser(unum,"Searching trustgroup with ID %lu...",strtoul(&tmps3[1],NULL,10)); numshown=displaytrustgroupwithid(unum,strtoul(&tmps3[1],NULL,10),showhosts); if (numshown==0) { msgtouser(unum,"A trustgroup with that ID does not exist."); } return; } } array_init(&listofids,sizeof(unsigned long)); for (i=0;i<SIZEOFIDMAP;i++) { tg=trustedgroups[i]; while (tg!=NULL) { strcpy(tmps4,tg->name); toLowerCase(tmps4); sprintf(tmps5,"#%lu",tg->id); if ((match2strings(tmps3,tmps4)) || (match2strings(tmps3,tmps5))) { j=array_getfreeslot(&listofids); ((unsigned long *)listofids.content)[j]=tg->id; } tg=(void *)tg->next; } } for (i=0;i<SIZEOFTL;i++) { th=trustedhosts[i]; while (th!=NULL) { char * mycip=printipv4(th->IPv4); if (match2strings(tmps3,mycip)) { j=array_getfreeslot(&listofids); ((unsigned long *)listofids.content)[j]=th->id; } free(mycip); th=(void *)th->next; } } if (listofids.cursi==0) { msgtouser(unum,"No matches."); array_free(&listofids); return; } qsort(listofids.content, listofids.cursi, sizeof(unsigned long), trustlistsorthelper); lastshown=0; for (i=0;i<listofids.cursi;i++) { showid=((unsigned long *)(listofids.content))[i]; if (showid!=lastshown) { lastshown=showid; numshown+=displaytrustgroupwithid(unum,showid,showhosts); if (numshown>500) { newmsgtouser(unum,"More than 500 lines (%lu) already shown - aborting now.",numshown); break; } } } array_free(&listofids); newmsgtouser(unum,"--- End of list - %lu lines returned from query ---",numshown); }