void parse_d_file(FBFILE *file) { struct ConfItem *aconf; char* reason_field=(char *)NULL; char* host_field=(char *)NULL; char line[BUFSIZE]; char* p; while (fbgets(line, sizeof(line), file)) { if ((p = strchr(line, '\n'))) *p = '\0'; if ((*line == '\0') || (line[0] == '#')) continue; if ((host_field = getfield(line)) == NULL) continue; if ((reason_field = getfield(NULL)) == NULL) continue; aconf = make_conf(); aconf->status = CONF_DLINE; conf_add_fields(aconf,host_field,reason_field,"",0,NULL); conf_add_d_conf(aconf); } }
void parse_d_file(FILE * file) { struct ConfItem *aconf; char *reason_field = NULL; char *host_field = NULL; char *operreason_field = NULL; 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; operreason_field = getfield(NULL); aconf = make_conf(); aconf->status = CONF_DLINE; conf_add_fields(aconf, host_field, reason_field, "", operreason_field); conf_add_d_conf(aconf); } }
/* parse_csv_file() * * inputs - FILE pointer * - type of conf to parse * output - none * side effects - */ void parse_csv_file(FBFILE *file, ConfType conf_type) { struct ConfItem *conf; struct AccessItem *aconf; struct MatchItem *match_item; struct MatchItem *nresv; struct ResvChannel *cresv; char *name_field=NULL; char *user_field=NULL; char *reason_field=NULL; char *oper_reason=NULL; char *host_field=NULL; char *duration_field=NULL; char *temp=NULL; char line[IRCD_BUFSIZE]; char *p; while (fbgets(line, sizeof(line), file) != NULL) { duration_field = NULL; if ((p = strchr(line, '\n')) != NULL) *p = '\0'; if ((line[0] == '\0') || (line[0] == '#')) continue; switch(conf_type) { case KLINE_TYPE: parse_csv_line(line, &user_field, &host_field, &reason_field, &oper_reason, &temp, &temp, &temp, &duration_field, NULL); conf = make_conf_item(KLINE_TYPE); aconf = map_to_conf(conf); if (host_field != NULL) DupString(aconf->host, host_field); if (reason_field != NULL) DupString(aconf->reason, reason_field); if (oper_reason != NULL) DupString(aconf->oper_reason, oper_reason); if (user_field != NULL) DupString(aconf->user, user_field); if (duration_field != NULL) aconf->hold = atoi(duration_field); if (aconf->host != NULL) { if(duration_field == NULL) add_conf_by_address(CONF_KILL, aconf); else add_temp_line(conf); } break; case RKLINE_TYPE: { const char *errptr = NULL; pcre *exp_user = NULL, *exp_host = NULL; parse_csv_line(line, &user_field, &host_field, &reason_field, &oper_reason, &temp, &temp, &temp, &duration_field, NULL); if (host_field == NULL || user_field == NULL) break; if (!(exp_user = ircd_pcre_compile(user_field, &errptr)) || !(exp_host = ircd_pcre_compile(host_field, &errptr))) { sendto_realops_flags(UMODE_ALL, L_ALL, "Failed to add regular expression based K-Line: %s", errptr); break; } conf = make_conf_item(RKLINE_TYPE); aconf = map_to_conf(conf); aconf->regexuser = exp_user; aconf->regexhost = exp_host; DupString(aconf->user, user_field); DupString(aconf->host, host_field); if (reason_field != NULL) DupString(aconf->reason, reason_field); else DupString(aconf->reason, "No reason"); if (oper_reason != NULL) DupString(aconf->oper_reason, oper_reason); if(duration_field != NULL) { aconf->hold = atoi(duration_field); add_temp_line(conf); } } break; case DLINE_TYPE: parse_csv_line(line, &host_field, &reason_field, &temp, &temp, &temp, &temp, &duration_field, NULL); conf = make_conf_item(DLINE_TYPE); aconf = (struct AccessItem *)map_to_conf(conf); if (host_field != NULL) DupString(aconf->host, host_field); if (reason_field != NULL) DupString(aconf->reason, reason_field); if(duration_field != NULL) { aconf->hold = atoi(duration_field); add_temp_line(conf); } else conf_add_d_conf(aconf); break; case XLINE_TYPE: parse_csv_line(line, &name_field, &reason_field, &oper_reason, &temp, &temp, &temp, &temp, &duration_field, NULL); conf = make_conf_item(XLINE_TYPE); match_item = (struct MatchItem *)map_to_conf(conf); if (name_field != NULL) DupString(conf->name, name_field); if (reason_field != NULL) DupString(match_item->reason, reason_field); if(duration_field != NULL) { match_item->hold = atoi(duration_field); add_temp_line(conf); } break; case RXLINE_TYPE: { const char *errptr = NULL; pcre *exp_p = NULL; parse_csv_line(line, &name_field, &reason_field, &oper_reason, &temp, &temp, &temp, &temp, &duration_field, NULL); if (name_field == NULL) break; if (!(exp_p = ircd_pcre_compile(name_field, &errptr))) { sendto_realops_flags(UMODE_ALL, L_ALL, "Failed to add regular expression based X-Line: %s", errptr); break; } conf = make_conf_item(RXLINE_TYPE); conf->regexpname = exp_p; match_item = map_to_conf(conf); DupString(conf->name, name_field); if (reason_field != NULL) DupString(match_item->reason, reason_field); else DupString(match_item->reason, "No reason"); if(duration_field != NULL) { match_item->hold = atoi(duration_field); add_temp_line(conf); } } break; case CRESV_TYPE: parse_csv_line(line, &name_field, &reason_field, &duration_field, NULL); conf = create_channel_resv(name_field, reason_field, 0); if(duration_field != NULL) { cresv = map_to_conf(conf); cresv->hold = atoi(duration_field); add_temp_line(conf); } break; case NRESV_TYPE: parse_csv_line(line, &name_field, &reason_field, &duration_field, NULL); conf = create_nick_resv(name_field, reason_field, 0); if(duration_field != NULL) { nresv = map_to_conf(conf); nresv->hold = atoi(duration_field); add_temp_line(conf); } break; case GLINE_TYPE: case GDENY_TYPE: case CONF_TYPE: case OPER_TYPE: case CLIENT_TYPE: case SERVER_TYPE: case CLUSTER_TYPE: case HUB_TYPE: case LEAF_TYPE: case ULINE_TYPE: case EXEMPTDLINE_TYPE: case CLASS_TYPE: break; } } }