Пример #1
0
/* 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;
    }
  }
}
Пример #2
0
/* parse_resv()
 *
 * inputs	- source_p, NULL supported
 *		- thing to resv
 *		- time_t if tkline
 *		- reason
 * outputs	- none
 * side effects	- parse resv, create if valid
 */
static void
parse_resv(struct Client *source_p, char *name, int tkline_time, char *reason)
{
	struct ConfItem *conf = NULL;
	int services = 0;

	if(IsServices(source_p))
		services = 1;

	if(IsChanPrefix(*name))
	{
		struct ResvChannel *resv_p;

		if((conf = create_channel_resv(name, reason, 0)) == NULL)
		{
			if(!services)
				sendto_one(source_p,
					   ":%s NOTICE %s :A RESV has already been placed on channel: %s",
					   me.name, source_p->name, name);
			return;
		}

		resv_p = map_to_conf(conf);

		if(tkline_time != 0)
		{
			if(!services)
			{
				sendto_one(source_p,
					   ":%s NOTICE %s :A %d minute %s RESV has been placed on channel: %s",
					   me.name, source_p->name,
					   tkline_time / 60,
					   (MyClient(source_p) ? "local" : "remote"), name);
				sendto_realops_flags(UMODE_ALL, L_ALL,
						     "%s has placed a %d minute %s RESV on channel: %s [%s]",
						     get_oper_name(source_p),
						     tkline_time / 60,
						     (MyClient(source_p) ? "local" : "remote"),
						     resv_p->name, resv_p->reason);
			}
			ilog(L_TRACE, "%s added temporary %d min. RESV for [%s] [%s]",
			     source_p->name, (int) tkline_time / 60, conf->name, resv_p->reason);
			resv_p->hold = CurrentTime + tkline_time;
			add_temp_line(conf);
		}
		else
		{
			if(!services)
			{
				sendto_one(source_p,
					   ":%s NOTICE %s :A %s RESV has been placed on channel %s",
					   me.name, source_p->name,
					   (MyClient(source_p) ? "local" : "remote"), name);
				sendto_realops_flags(UMODE_ALL, L_ALL,
						     "%s has placed a %s RESV on channel %s : [%s]",
						     get_oper_name(source_p),
						     (MyClient(source_p) ? "local" : "remote"),
						     resv_p->name, resv_p->reason);
			}
			write_conf_line(source_p, conf, NULL /* not used */ , 0 /* not used */ );
		}
	}
	else
	{
		struct MatchItem *resv_p = NULL;

		if(!valid_wild_card_simple(name) && !IsServices(source_p))
		{
			sendto_one(source_p,
				   ":%s NOTICE %s :Please include at least %d non-wildcard characters with the resv",
				   me.name, source_p->name, ConfigFileEntry.min_nonwildcard_simple);
			return;
		}

		if(!IsAdmin(source_p) && !IsServices(source_p) && strpbrk(name, "*?#"))
		{
			sendto_one(source_p, ":%s NOTICE %s :You must be an admin to perform a "
				   "wildcard RESV", me.name, source_p->name);
			return;
		}

		if((conf = create_nick_resv(name, reason, 0)) == NULL)
		{
			if(!services)
				sendto_one(source_p,
					   ":%s NOTICE %s :A RESV has already been placed on nick %s",
					   me.name, source_p->name, name);
			return;
		}

		resv_p = map_to_conf(conf);

		if(tkline_time != 0)
		{
			if(!services)
			{
				sendto_one(source_p,
					   ":%s NOTICE %s :A %d minute %s RESV has been placed on nick %s : [%s]",
					   me.name, source_p->name,
					   tkline_time / 60,
					   (MyClient(source_p) ? "local" : "remote"),
					   conf->name, resv_p->reason);
				sendto_realops_flags(UMODE_ALL, L_ALL,
						     "%s has placed a %d minute %s RESV on nick %s : [%s]",
						     get_oper_name(source_p),
						     tkline_time / 60,
						     (MyClient(source_p) ? "local" : "remote"),
						     conf->name, resv_p->reason);
			}
			ilog(L_TRACE, "%s added temporary %d min. RESV for [%s] [%s]",
			     source_p->name, (int) tkline_time / 60, conf->name, resv_p->reason);
			resv_p->hold = CurrentTime + tkline_time;
			add_temp_line(conf);
		}
		else
		{
			if(!services)
			{
				sendto_one(source_p,
					   ":%s NOTICE %s :A %s RESV has been placed on nick %s : [%s]",
					   me.name, source_p->name,
					   (MyClient(source_p) ? "local" : "remote"),
					   conf->name, resv_p->reason);
				sendto_realops_flags(UMODE_ALL, L_ALL,
						     "%s has placed a %s RESV on nick %s : [%s]",
						     get_oper_name(source_p),
						     (MyClient(source_p) ? "local" : "remote"),
						     conf->name, resv_p->reason);
			}
			write_conf_line(source_p, conf, NULL /* not used */ , 0 /* not used */ );
		}
	}
}