コード例 #1
0
ファイル: m_testline.c プロジェクト: Cloudxtreme/ircd-ratbox
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;
}
コード例 #2
0
ファイル: mtrie_conf.c プロジェクト: grawity/ircd-hybrid-5
void report_mtrie_conf_links(aClient *sptr, int flags)
{
  aConfItem *found_conf;
  char *host;
  char *pass;
  char *name;
  char *mask;
  int  port;
  char c;		/* conf char used for CONF_CLIENT only */

  if(trie_list)
    report_sub_mtrie(sptr,flags,trie_list);

  /* If requesting I lines do this */
  if(flags & CONF_CLIENT)
    {
      for(found_conf = unsortable_list_ilines;
	  found_conf;found_conf=found_conf->next)
	{
	  host = BadPtr(found_conf->host) ? null : found_conf->host;
	  pass = BadPtr(found_conf->passwd) ? null : found_conf->passwd;
	  name = BadPtr(found_conf->name) ? null : found_conf->name;
	  mask = BadPtr(found_conf->mask) ? null : found_conf->mask;
	  port = (int)found_conf->port;

	  c = 'I';
#ifdef LITTLE_I_LINES
	  if(IsConfLittleI(found_conf))
	    c = 'i';
#endif
	  sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name,
		     sptr->name,
		     c,
		     mask,
		     show_iline_prefix(sptr,found_conf,name),
		     host,
		     port,
		     get_conf_class(found_conf));
	}

      for(found_conf = wild_card_ilines;
	  found_conf;found_conf=found_conf->next)
	{
	  host = BadPtr(found_conf->host) ? null : found_conf->host;
	  pass = BadPtr(found_conf->passwd) ? null : found_conf->passwd;
	  name = BadPtr(found_conf->name) ? null : found_conf->name;
	  mask = BadPtr(found_conf->mask) ? null : found_conf->mask;
	  port = (int)found_conf->port;

	  if(!(found_conf->status&CONF_CLIENT))
	    continue;

	  c = 'I';
#ifdef LITTLE_I_LINES
	  if(IsConfLittleI(found_conf))
	    c = 'i';
#endif
	  sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name,
		     sptr->name,
		     c,
		     mask,
		     show_iline_prefix(sptr,found_conf,name),
		     host,
		     port,
		     get_conf_class(found_conf));
	}
    }
  else
    {
      report_dline_hash(sptr,CONF_KILL);

      for(found_conf = unsortable_list_klines;
	  found_conf;found_conf=found_conf->next)
	{
	  host = BadPtr(found_conf->host) ? null : found_conf->host;
	  pass = BadPtr(found_conf->passwd) ? null : found_conf->passwd;
	  name = BadPtr(found_conf->name) ? null : found_conf->name;
	  port = (int)found_conf->port;

	  sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name,
		     sptr->name, 'K', host,
		     name, pass);
	}
    }
}
コード例 #3
0
ファイル: mtrie_conf.c プロジェクト: grawity/ircd-hybrid-5
static void report_sub_mtrie(aClient *sptr, int flags, DOMAIN_LEVEL *dl_ptr)
{
  DOMAIN_PIECE *dp_ptr;
  aConfItem *aconf;
  int i;
  char *p;
  char *host;
  char *pass;
  char *name;
  char *mask;
  int  port;
  char c;

  if(!dl_ptr)
    return;

  for(i=0; i < MAX_PIECE_LIST; i++)
    {
      for(dp_ptr=dl_ptr->piece_list[i];dp_ptr; dp_ptr = dp_ptr->next_piece)
	{
	  report_sub_mtrie(sptr,flags,dp_ptr->next_level);
	  if(dp_ptr->conf_ptr)
	    {
	      /* Only show desired I/K lines */
	      aconf = dp_ptr->conf_ptr;

	      if(aconf->status & flags)
		{
		  host = BadPtr(aconf->host) ? null : aconf->host;
		  pass = BadPtr(aconf->passwd) ? null : aconf->passwd;
		  name = BadPtr(aconf->name) ? null : aconf->name;
		  mask = BadPtr(aconf->mask) ? null : aconf->mask;
		  port = (int)aconf->port;

		  if (aconf->status == CONF_KILL)
		    {
		      sendto_one(sptr, rpl_str(RPL_STATSKLINE),
				 me.name,
				 sptr->name,
				 'K',
				 host,
				 name,
				 pass);
		    }
		  else
		    {
		      c = 'I';
#ifdef LITTLE_I_LINES
		      if(IsConfLittleI(aconf))
			c = 'i';
#endif
		      sendto_one(sptr, rpl_str(RPL_STATSILINE),
				 me.name,
				 sptr->name,
				 c,
				 mask,
				 show_iline_prefix(sptr,aconf,name),
				 host,
				 port,
				 get_conf_class(aconf));
		    }
		}
	    }

	  if(dp_ptr->wild_conf_ptr)
	    {
	      aconf = dp_ptr->wild_conf_ptr;

	      if(aconf->status & flags)
		{
		  host = BadPtr(aconf->host) ? null : aconf->host;
		  pass = BadPtr(aconf->passwd) ? null : aconf->passwd;
		  name = BadPtr(aconf->name) ? null : aconf->name;
		  mask = BadPtr(aconf->mask) ? null : aconf->mask;
		  port = (int)aconf->port;

		  if (aconf->status == CONF_KILL)
		    {
		      sendto_one(sptr, rpl_str(RPL_STATSKLINE),
				 me.name,
				 sptr->name,
				 'K',
				 host,
				 name,
				 pass);
		    }
		  else
		    {
		      sendto_one(sptr, rpl_str(RPL_STATSILINE),
				 me.name,
				 sptr->name,
				 c,
				 mask,
				 show_iline_prefix(sptr,aconf,name),
				 host,
				 port,
				 get_conf_class(aconf));
		    }
		}
	    }
	}
    }
}
コード例 #4
0
ファイル: m_testline.c プロジェクト: viatsko/charybdis
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;
}