void parse_resv_file(FILE * file) { struct ConfItem *aconf; char *reason_field; char *host_field; char line[BUFSIZE]; char *p; while (fgets(line, sizeof(line), file)) { if((p = strpbrk(line, "\r\n"))) *p = '\0'; if((*line == '\0') || (line[0] == '#')) continue; host_field = getfield(line); if(EmptyString(host_field)) continue; reason_field = getfield(NULL); if(EmptyString(reason_field)) continue; if(IsChannelName(host_field)) { if(hash_find_resv(host_field)) continue; aconf = make_conf(); aconf->status = CONF_RESV_CHANNEL; aconf->port = 0; DupString(aconf->name, host_field); DupString(aconf->passwd, reason_field); add_to_resv_hash(aconf->name, aconf); } else if(clean_resv_nick(host_field)) { if(find_nick_resv(host_field)) continue; aconf = make_conf(); aconf->status = CONF_RESV_NICK; aconf->port = 0; DupString(aconf->name, host_field); DupString(aconf->passwd, reason_field); dlinkAddAlloc(aconf, &resv_conf_list); } } }
int find_channel_resv(char *name) { struct ResvChannel *resv_p; resv_p = (struct ResvChannel *)hash_find_resv(name); if (resv_p == NULL) return 0; return 1; }
static int mo_testline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { struct ConfItem *aconf; struct ConfItem *resv_p; struct rb_sockaddr_storage ip; const char *name = NULL; const char *username = NULL; const char *host = NULL; char *mask; char *p; int host_mask; int type; mask = LOCAL_COPY(parv[1]); if(IsChannelName(mask)) { resv_p = hash_find_resv(mask); if(resv_p != NULL) { sendto_one(source_p, form_str(RPL_TESTLINE), me.name, source_p->name, (resv_p->flags & CONF_FLAGS_TEMPORARY) ? 'q' : 'Q', (resv_p->flags & CONF_FLAGS_TEMPORARY) ? (long)((resv_p->hold - rb_current_time ()) / 60) : 0L, resv_p->host, resv_p->passwd); /* this is a false positive, so make sure it isn't counted in stats q * --nenolod */ resv_p->port--; } else sendto_one(source_p, form_str(RPL_NOTESTLINE), me.name, source_p->name, parv[1]); return 0; } if((p = strchr(mask, '!'))) { *p++ = '\0'; name = mask; mask = p; if(EmptyString(mask)) return 0; } if((p = strchr(mask, '@'))) { *p++ = '\0'; username = mask; host = p; if(EmptyString(host)) return 0; } else host = mask; /* parses as an IP, check for a dline */ if((type = parse_netmask(host, (struct sockaddr *)&ip, &host_mask)) != HM_HOST) { aconf = find_dline((struct sockaddr *)&ip); if(aconf && aconf->status & CONF_DLINE) { sendto_one(source_p, form_str(RPL_TESTLINE), me.name, source_p->name, (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'd' : 'D', (aconf->flags & CONF_FLAGS_TEMPORARY) ? (long)((aconf->hold - rb_current_time()) / 60) : 0L, aconf->host, aconf->passwd); return 0; } } /* now look for a matching I/K/G */ if((aconf = find_address_conf(host, NULL, username ? username : "******", (type != HM_HOST) ? (struct sockaddr *)&ip : NULL, (type != HM_HOST) ? ( #ifdef RB_IPV6 (type == HM_IPV6) ? AF_INET6 : #endif AF_INET) : 0))) { static char buf[HOSTLEN + USERLEN + 2]; if(aconf->status & CONF_KILL) { rb_snprintf(buf, sizeof(buf), "%s@%s", aconf->user, aconf->host); sendto_one(source_p, form_str(RPL_TESTLINE), me.name, source_p->name, (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'k' : 'K', (aconf->flags & CONF_FLAGS_TEMPORARY) ? (long)((aconf->hold - rb_current_time()) / 60) : 0L, buf, aconf->passwd); return 0; } else if(aconf->status & CONF_GLINE) { rb_snprintf(buf, sizeof(buf), "%s@%s", aconf->user, aconf->host); sendto_one(source_p, form_str(RPL_TESTLINE), me.name, source_p->name, 'G', (long)((aconf->hold - rb_current_time()) / 60), buf, aconf->passwd); return 0; } } /* they asked us to check a nick, so hunt for resvs.. */ if(name && (resv_p = find_nick_resv(name))) { sendto_one(source_p, form_str(RPL_TESTLINE), me.name, source_p->name, (resv_p->flags & CONF_FLAGS_TEMPORARY) ? 'q' : 'Q', (resv_p->flags & CONF_FLAGS_TEMPORARY) ? (long)((resv_p->hold - rb_current_time()) / 60) : 0L, resv_p->host, resv_p->passwd); /* this is a false positive, so make sure it isn't counted in stats q * --nenolod */ resv_p->port--; return 0; } /* no matching resv, we can print the I: if it exists */ if(aconf && aconf->status & CONF_CLIENT) { sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE), aconf->info.name, show_iline_prefix(source_p, aconf, aconf->user), aconf->host, aconf->port, get_class_name(aconf)); return 0; } /* nothing matches.. */ sendto_one(source_p, form_str(RPL_NOTESTLINE), me.name, source_p->name, parv[1]); return 0; }
static int mo_testline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { struct ConfItem *aconf; struct ConfItem *resv_p; struct rb_sockaddr_storage ip; char user_trunc[USERLEN + 1], notildeuser_trunc[USERLEN + 1]; const char *name = NULL; const char *username = NULL; const char *host = NULL; char *mask; char *p; int host_mask; int type; int duration; char *puser, *phost, *reason, *operreason; char reasonbuf[BUFSIZE]; mask = LOCAL_COPY(parv[1]); if (IsChannelName(mask)) { resv_p = hash_find_resv(mask); if (resv_p != NULL) { sendto_one(source_p, form_str(RPL_TESTLINE), me.name, source_p->name, resv_p->hold ? 'q' : 'Q', resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L, resv_p->host, resv_p->passwd); /* this is a false positive, so make sure it isn't counted in stats q * --nenolod */ resv_p->port--; } else sendto_one(source_p, form_str(RPL_NOTESTLINE), me.name, source_p->name, parv[1]); return 0; } if((p = strchr(mask, '!'))) { *p++ = '\0'; name = mask; mask = p; if(EmptyString(mask)) return 0; } if((p = strchr(mask, '@'))) { *p++ = '\0'; username = mask; host = p; if(EmptyString(host)) return 0; } else host = mask; /* parses as an IP, check for a dline */ if((type = parse_netmask(host, &ip, &host_mask)) != HM_HOST) { #ifdef RB_IPV6 if(type == HM_IPV6) aconf = find_dline((struct sockaddr *)&ip, AF_INET6); else #endif aconf = find_dline((struct sockaddr *)&ip, AF_INET); if(aconf && aconf->status & CONF_DLINE) { get_printable_kline(source_p, aconf, &phost, &reason, &puser, &operreason); snprintf(reasonbuf, sizeof(reasonbuf), "%s%s%s", reason, operreason ? "|" : "", operreason ? operreason : ""); sendto_one(source_p, form_str(RPL_TESTLINE), me.name, source_p->name, (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'd' : 'D', (aconf->flags & CONF_FLAGS_TEMPORARY) ? (long) ((aconf->hold - rb_current_time()) / 60) : 0L, phost, reasonbuf); return 0; } /* Otherwise, aconf is an exempt{} */ if(aconf == NULL && (duration = is_reject_ip((struct sockaddr *)&ip))) sendto_one(source_p, form_str(RPL_TESTLINE), me.name, source_p->name, '!', duration / 60L, host, "Reject cache"); if(aconf == NULL && (duration = is_throttle_ip((struct sockaddr *)&ip))) sendto_one(source_p, form_str(RPL_TESTLINE), me.name, source_p->name, '!', duration / 60L, host, "Throttled"); } if (username != NULL) { rb_strlcpy(user_trunc, username, sizeof user_trunc); rb_strlcpy(notildeuser_trunc, *username == '~' ? username + 1 : username, sizeof notildeuser_trunc); } else { rb_strlcpy(user_trunc, "dummy", sizeof user_trunc); rb_strlcpy(notildeuser_trunc, "dummy", sizeof notildeuser_trunc); } /* now look for a matching I/K/G */ if((aconf = find_address_conf(host, NULL, user_trunc, notildeuser_trunc, (type != HM_HOST) ? (struct sockaddr *)&ip : NULL, (type != HM_HOST) ? ( #ifdef RB_IPV6 (type == HM_IPV6) ? AF_INET6 : #endif AF_INET) : 0, NULL))) { static char buf[HOSTLEN+USERLEN+2]; if(aconf->status & CONF_KILL) { get_printable_kline(source_p, aconf, &phost, &reason, &puser, &operreason); snprintf(buf, sizeof(buf), "%s@%s", puser, phost); snprintf(reasonbuf, sizeof(reasonbuf), "%s%s%s", reason, operreason ? "|" : "", operreason ? operreason : ""); sendto_one(source_p, form_str(RPL_TESTLINE), me.name, source_p->name, (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'k' : 'K', (aconf->flags & CONF_FLAGS_TEMPORARY) ? (long) ((aconf->hold - rb_current_time()) / 60) : 0L, buf, reasonbuf); return 0; } } /* they asked us to check a nick, so hunt for resvs.. */ if(name && (resv_p = find_nick_resv(name))) { sendto_one(source_p, form_str(RPL_TESTLINE), me.name, source_p->name, resv_p->hold ? 'q' : 'Q', resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L, resv_p->host, resv_p->passwd); /* this is a false positive, so make sure it isn't counted in stats q * --nenolod */ resv_p->port--; return 0; } /* no matching resv, we can print the I: if it exists */ if(aconf && aconf->status & CONF_CLIENT) { sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE), aconf->info.name, EmptyString(aconf->spasswd) ? "<NULL>" : aconf->spasswd, show_iline_prefix(source_p, aconf, aconf->user), aconf->host, aconf->port, aconf->className); return 0; } /* nothing matches.. */ sendto_one(source_p, form_str(RPL_NOTESTLINE), me.name, source_p->name, parv[1]); return 0; }
/* Join a channel, ignoring forwards, +ib, etc. It notifes source_p of any errors joining * NB: this assumes a local user. */ void user_join_override(struct Client * client_p, struct Client * source_p, struct Client * target_p, const char * channels) { static char jbuf[BUFSIZE]; struct ConfItem *aconf; struct Channel *chptr = NULL; char *name; const char *modes; char *p = NULL; int flags; char *chanlist; jbuf[0] = '\0'; if(channels == NULL) return; /* rebuild the list of channels theyre supposed to be joining. */ chanlist = LOCAL_COPY(channels); for(name = rb_strtok_r(chanlist, ",", &p); name; name = rb_strtok_r(NULL, ",", &p)) { /* check the length and name of channel is ok */ if(!check_channel_name_loc(target_p, name) || (strlen(name) > LOC_CHANNELLEN)) { sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), (unsigned char *) name); continue; } /* join 0 parts all channels */ if(*name == '0' && (name[1] == ',' || name[1] == '\0') && name == chanlist) { (void) strcpy(jbuf, "0"); continue; } /* check it begins with # or & */ else if(!IsChannelName(name)) { sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); continue; } /* see if its resv'd */ if(!IsExemptResv(target_p) && (aconf = hash_find_resv(name))) { sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), name); /* dont update tracking for jupe exempt users, these * are likely to be spamtrap leaves */ if(IsExemptJupe(source_p)) aconf->port--; continue; } if(splitmode && !IsOper(target_p) && (*name != '&') && ConfigChannel.no_join_on_split) { sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), me.name, source_p->name, name); continue; } if(*jbuf) (void) strcat(jbuf, ","); (void) rb_strlcat(jbuf, name, sizeof(jbuf)); } for(name = rb_strtok_r(jbuf, ",", &p); name; name = rb_strtok_r(NULL, ",", &p)) { /* JOIN 0 simply parts all channels the user is in */ if(*name == '0' && !atoi(name)) { if(target_p->user->channel.head == NULL) continue; do_join_0(&me, target_p); continue; } if((chptr = find_channel(name)) != NULL) { if(IsMember(target_p, chptr)) { /* debugging is fun... */ sendto_one_notice(source_p, ":*** Notice -- %s is already in %s", target_p->name, chptr->chname); return; } add_user_to_channel(chptr, target_p, CHFL_PEON); if (chptr->mode.join_num && rb_current_time() - chptr->join_delta >= chptr->mode.join_time) { chptr->join_count = 0; chptr->join_delta = rb_current_time(); } chptr->join_count++; sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", target_p->name, target_p->username, target_p->host, chptr->chname); sendto_server(target_p, chptr, CAP_TS6, NOCAPS, ":%s JOIN %ld %s +", get_id(target_p, client_p), (long) chptr->channelts, chptr->chname); del_invite(chptr, target_p); if(chptr->topic != NULL) { sendto_one(target_p, form_str(RPL_TOPIC), me.name, target_p->name, chptr->chname, chptr->topic); sendto_one(target_p, form_str(RPL_TOPICWHOTIME), me.name, source_p->name, chptr->chname, chptr->topic_info, chptr->topic_time); } channel_member_names(chptr, target_p, 1); } else { hook_data_channel_activity hook_info; char statusmodes[5] = ""; if(!check_channel_name(name)) { sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name, source_p->name, (unsigned char *) name); return; } /* channel name must begin with & or # */ if(!IsChannelName(name)) { sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name, source_p->name, (unsigned char *) name); return; } /* name can't be longer than CHANNELLEN */ if(strlen(name) > CHANNELLEN) { sendto_one_notice(source_p, ":Channel name is too long"); return; } chptr = get_or_create_channel(target_p, name, NULL); flags = CHFL_CHANOP; add_user_to_channel(chptr, target_p, flags); if (chptr->mode.join_num && rb_current_time() - chptr->join_delta >= chptr->mode.join_time) { chptr->join_count = 0; chptr->join_delta = rb_current_time(); } chptr->join_count++; sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", target_p->name, target_p->username, target_p->host, chptr->chname); chptr->mode.mode |= MODE_TOPICLIMIT; chptr->mode.mode |= MODE_NOPRIVMSGS; modes = channel_modes(chptr, &me); sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s %s", me.name, chptr->chname, modes); strcat(statusmodes, "@"); sendto_server(target_p, chptr, CAP_TS6, NOCAPS, ":%s SJOIN %ld %s %s :%s%s", me.id, (long) chptr->channelts, chptr->chname, modes, statusmodes, get_id(target_p, client_p)); target_p->localClient->last_join_time = rb_current_time(); channel_member_names(chptr, target_p, 1); /* Call channel join hooks */ hook_info.client = source_p; hook_info.chptr = chptr; hook_info.key = chptr->mode.key; call_hook(h_channel_join, &hook_info); /* we do this to let the oper know that a channel was created, this will be * seen from the server handling the command instead of the server that * the oper is on. */ sendto_one_notice(source_p, ":*** Notice -- Creating channel %s", chptr->chname); } } return; }
static void remove_resv(struct Client *source_p, const char *name) { struct ConfItem *conf = NULL; int services = 0; if(IsServices(source_p)) services = 1; if(IsChanPrefix(*name)) { struct ResvChannel *resv_p; if(resv_channel_list.head == NULL || !(resv_p = hash_find_resv(name))) { if(!services) sendto_one(source_p, ":%s NOTICE %s :A RESV does not exist for channel: %s", me.name, source_p->name, name); return; } if(resv_p->conf) { if(!services) sendto_one(source_p, ":%s NOTICE %s :The RESV for channel: %s is in ircd.conf and must be removed by hand.", me.name, source_p->name, name); return; } delete_channel_resv(resv_p); remove_conf_line(CRESV_TYPE, source_p, name, NULL); if(!services) { sendto_one(source_p, ":%s NOTICE %s :The RESV has been removed on channel: %s", me.name, source_p->name, name); sendto_realops_flags(UMODE_ALL, L_ALL, "%s has removed the RESV for channel: %s", get_oper_name(source_p), name); } } else { struct MatchItem *resv_p = NULL; if((conf = find_exact_name_conf(NRESV_TYPE, name, NULL, NULL, NULL)) == NULL) { if(!services) sendto_one(source_p, ":%s NOTICE %s :A RESV does not exist for nick: %s", me.name, source_p->name, name); return; } resv_p = map_to_conf(conf); if(resv_p->action) { if(!services) sendto_one(source_p, ":%s NOTICE %s :The RESV for nick: %s is in ircd.conf and must be removed by hand.", me.name, source_p->name, name); return; } delete_conf_item(conf); remove_conf_line(NRESV_TYPE, source_p, name, NULL); if(!services) { sendto_one(source_p, ":%s NOTICE %s :The RESV has been removed on nick: %s", me.name, source_p->name, name); sendto_realops_flags(UMODE_ALL, L_ALL, "%s has removed the RESV for nick: %s", get_oper_name(source_p), name); } } }
static void remove_resv (struct Client *source_p, char *name, int cluster) { struct ConfItem *conf; if (IsChanPrefix (*name)) { struct ResvChannel *resv_p; if (resv_channel_list.head == NULL || !(resv_p = hash_find_resv (name))) { if (!cluster) sendto_one (source_p, ":%s NOTICE %s :A RESV does not exist for channel: %s", me.name, source_p->name, name); return; } else if (resv_p->conf) { if (!cluster) sendto_one (source_p, ":%s NOTICE %s :The RESV for channel: %s is in ircd.conf and must be removed by hand.", me.name, source_p->name, name); return; } else { delete_channel_resv (resv_p); (void) remove_conf_line (CRESV_TYPE, source_p, name, NULL); if (!cluster) sendto_one (source_p, ":%s NOTICE %s :The RESV has been removed on channel: %s", me.name, source_p->name, name); sendto_realops_flags (UMODE_ALL, L_ALL, "%s has removed the RESV for channel: %s", get_oper_name (source_p), name); } } else if (clean_resv_nick (name)) { struct MatchItem *resv_p; conf = find_matching_name_conf (NRESV_TYPE, name, NULL, NULL, 0); if (conf == NULL) { if (!cluster) sendto_one (source_p, ":%s NOTICE %s :A RESV does not exist for nick: %s", me.name, source_p->name, name); return; } resv_p = (struct MatchItem *) map_to_conf (conf); if (resv_p->action) { if (!cluster) sendto_one (source_p, ":%s NOTICE %s :The RESV for nick: %s is in ircd.conf and must be removed by hand.", me.name, source_p->name, name); return; } else { delete_conf_item (conf); (void) remove_conf_line (NRESV_TYPE, source_p, name, NULL); if (!cluster) sendto_one (source_p, ":%s NOTICE %s :The RESV has been removed on nick: %s", me.name, source_p->name, name); sendto_realops_flags (UMODE_ALL, L_ALL, "%s has removed the RESV for nick: %s", get_oper_name (source_p), name); } } }