示例#1
0
void
report_error(int level, const char* text, const char* who, int error) 
{
  who = (who) ? who : "";

  sendto_realops_flags(UMODE_DEBUG, level, text, who, strerror(error));
  log_oper_action(LOG_IOERR_TYPE, NULL, "%s %s %s\n", who, text, strerror(error));
  ilog(L_ERROR, text, who, strerror(error));
}
示例#2
0
/*
 * m_challenge - generate RSA challenge for wouldbe oper
 * parv[0] = sender prefix
 * parv[1] = operator to challenge for, or +response
 *
 */
static void
m_challenge(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
{
	char *challenge = NULL;
	struct ConfItem *conf = NULL;
	struct AccessItem *aconf = NULL;

	/* if theyre an oper, reprint oper motd and ignore */
	if(IsOper(source_p))
	{
		sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, parv[0]);
		send_message_file(source_p, &ConfigFileEntry.opermotd);
		return;
	}

	if(*parv[1] == '+')
	{
		/* Ignore it if we aren't expecting this... -A1kmm */
		if(source_p->localClient->response == NULL)
			return;

		if(svsnoop)
		{
			sendto_one(source_p,
				   ":%s NOTICE %s :*** This server is in NOOP mode, you cannot /oper",
				   me.name, source_p->name);
			failed_challenge_notice(source_p, source_p->localClient->auth_oper,
						"This server is in NOOP mode");
			log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n",
					source_p->localClient->auth_oper);
			return;
		}

		if(irccmp(source_p->localClient->response, ++parv[1]))
		{
			sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name);
			failed_challenge_notice(source_p, source_p->localClient->auth_oper,
						"challenge failed");
			return;
		}

		conf = find_exact_name_conf(OPER_TYPE,
					    source_p->localClient->auth_oper,
					    source_p->username, source_p->host);
		if(conf == NULL)
			conf = find_exact_name_conf(OPER_TYPE,
						    source_p->localClient->auth_oper,
						    source_p->username, source_p->realhost);
		if(conf == NULL)
			conf = find_exact_name_conf(OPER_TYPE,
						    source_p->localClient->auth_oper,
						    source_p->username, source_p->sockhost);
		if(conf == NULL)
		{
			sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, parv[0]);
			log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n",
					source_p->localClient->auth_oper);
			return;
		}

		if(attach_conf(source_p, conf) != 0)
		{
			sendto_one(source_p, ":%s NOTICE %s :Can't attach conf!",
				   me.name, source_p->name);
			failed_challenge_notice(source_p, conf->name, "can't attach conf!");
			log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n",
					source_p->localClient->auth_oper);
			return;
		}

		oper_up(source_p);

		ilog(L_TRACE, "OPER %s by %s!%s@%s",
		     source_p->localClient->auth_oper, source_p->name, source_p->username,
		     source_p->realhost);
		log_oper_action(LOG_OPER_TYPE, source_p, "%s\n", source_p->localClient->auth_oper);

		MyFree(source_p->localClient->response);
		MyFree(source_p->localClient->auth_oper);
		source_p->localClient->response = NULL;
		source_p->localClient->auth_oper = NULL;
		return;
	}

	MyFree(source_p->localClient->response);
	MyFree(source_p->localClient->auth_oper);
	source_p->localClient->response = NULL;
	source_p->localClient->auth_oper = NULL;

	if((conf = find_conf_exact(OPER_TYPE, parv[1], source_p->username, source_p->host)) != NULL)
		aconf = map_to_conf(conf);
	else if((conf = find_conf_exact(OPER_TYPE,
					parv[1], source_p->username, source_p->realhost)) != NULL)
		aconf = map_to_conf(conf);
	else if((conf = find_conf_exact(OPER_TYPE,
					parv[1], source_p->username, source_p->sockhost)) != NULL)
		aconf = map_to_conf(conf);

	if(aconf == NULL)
	{
		sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, parv[0]);
		conf = find_exact_name_conf(OPER_TYPE, parv[1], NULL, NULL);
		failed_challenge_notice(source_p, parv[1], (conf != NULL)
					? "host mismatch" : "no oper {} block");
		log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", parv[1]);
		return;
	}

	if(aconf->rsa_public_key == NULL)
	{
		sendto_one(source_p, ":%s NOTICE %s :I'm sorry, PK authentication "
			   "is not enabled for your oper{} block.", me.name, parv[0]);
		return;
	}

	if(!generate_challenge(&challenge, &(source_p->localClient->response),
			       aconf->rsa_public_key))
		sendto_one(source_p, form_str(RPL_RSACHALLENGE), me.name, parv[0], challenge);

	DupString(source_p->localClient->auth_oper, conf->name);
	MyFree(challenge);
}
示例#3
0
/* write_conf_line()
 *
 * inputs       - pointer to struct AccessItem
 *		- string current_date (small date)
 *              - time_t cur_time
 * output       - NONE
 * side effects - This function takes care of
 *                finding right conf file, writing
 *                the right lines to this file, 
 *                notifying the oper that their kline/dline etc. is in place
 *                notifying the opers on the server about the k/d etc. line
 *                
 * - Dianora
 */
void 
write_conf_line(struct Client *source_p, struct ConfItem *conf,
		const char *current_date, time_t cur_time, time_t duration)
{
  FBFILE *out;
  const char *filename, *from, *to;
  struct AccessItem *aconf;
  struct MatchItem *xconf;
  struct ResvChannel *cresv_p=NULL;
  struct MatchItem *nresv_p=NULL;
  ConfType type;

  type = conf->type;
  filename = get_conf_name(type);

  if (!MyConnect(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
  {
    from = me.id;
    to = source_p->id;
  }
  else
  {
    from = me.name;
    to = source_p->name;
  }

  if ((out = fbopen(filename, "a")) == NULL)
  {
    sendto_realops_flags(UMODE_ALL, L_ALL,
                         "*** Problem opening %s ", filename);
    return;
  }

  switch(type)
  {
  case KLINE_TYPE:
    aconf = (struct AccessItem *)map_to_conf(conf);
    if(duration == 0)
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added K-Line for [%s@%s] [%s]",
          get_oper_name(source_p), aconf->user, aconf->host, aconf->reason);
      sendto_one(source_p, ":%s NOTICE %s :Added K-Line [%s@%s]",
          from, to, aconf->user, aconf->host);
      ilog(L_TRACE, "%s added K-Line for [%s@%s] [%s]",
          source_p->name, aconf->user, aconf->host, aconf->reason);
      log_oper_action(LOG_KLINE_TYPE, source_p, "[%s@%s] [%s]\n",
          aconf->user, aconf->host, aconf->reason);
      write_csv_line(out, "%s%s%s%s%s%s%d",
          aconf->user, aconf->host, aconf->reason, aconf->oper_reason, 
          current_date, get_oper_name(source_p), cur_time);
    }
    else
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added temporary %d min. K-Line for [%s@%s] [%s]",
          get_oper_name(source_p), duration/60, aconf->user, aconf->host, 
          aconf->reason);
      sendto_one(source_p,
          ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]", from, to, 
          duration/60, aconf->user, aconf->host);
      ilog(L_TRACE, "%s added temporary %ld min. K-Line for [%s@%s] [%s]",
          source_p->name, duration/60, aconf->user, aconf->host, aconf->reason);
      log_oper_action(LOG_TEMP_KLINE_TYPE, source_p, "[%s@%s] [%s]\n",
          aconf->user, aconf->host, aconf->reason);
      write_csv_line(out, "%s%s%s%s%s%s%d%d", aconf->user, aconf->host,
          aconf->reason, aconf->oper_reason, current_date,
          get_oper_name(source_p), cur_time, aconf->hold);
    }
    break;

  case RKLINE_TYPE:
    aconf = map_to_conf(conf);
    if(duration == 0)
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added RK-Line for [%s@%s] [%s]",
          get_oper_name(source_p),
          aconf->user, aconf->host, aconf->reason);
      sendto_one(source_p, ":%s NOTICE %s :Added RK-Line [%s@%s]",
          from, to, aconf->user, aconf->host);
      ilog(L_TRACE, "%s added K-Line for [%s@%s] [%s]",
          source_p->name, aconf->user, aconf->host, aconf->reason);
      log_oper_action(LOG_RKLINE_TYPE, source_p, "[%s@%s] [%s]\n",
          aconf->user, aconf->host, aconf->reason);
      write_csv_line(out, "%s%s%s%s%s%s%d",
          aconf->user, aconf->host,
          aconf->reason, aconf->oper_reason, current_date,
          get_oper_name(source_p), cur_time);
    }
    else
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added temporary %d min. RK-Line for [%s@%s] [%s]",
          get_oper_name(source_p), duration/60, aconf->user, aconf->host,
          aconf->reason);
      sendto_one(source_p, 
          ":%s NOTICE %s :Added temporary %d min. RK-Line [%s@%s]", from, to, 
          duration/60, aconf->user, aconf->host);
      ilog(L_TRACE, "%s added temporary %ld min. RK-Line for [%s@%s] [%s]",
          source_p->name, duration/60,
          aconf->user, aconf->host, aconf->reason);
      log_oper_action(LOG_TEMP_RKLINE_TYPE, source_p, "[%s@%s] [%s]\n",
          aconf->user, aconf->host, aconf->reason);
      write_csv_line(out, "%s%s%s%s%s%s%d%d",
          aconf->user, aconf->host,
          aconf->reason, aconf->oper_reason, current_date,
          get_oper_name(source_p), cur_time, aconf->hold);
    }
    break;

  case DLINE_TYPE:
    aconf = (struct AccessItem *)map_to_conf(conf);
    if(duration == 0)
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added D-Line for [%s] [%s]",
          get_oper_name(source_p), aconf->host, aconf->reason);
      sendto_one(source_p, ":%s NOTICE %s :Added D-Line [%s] to %s",
          from, to, aconf->host, filename);
      ilog(L_TRACE, "%s added D-Line for [%s] [%s]",
          get_oper_name(source_p), aconf->host, aconf->reason);
      log_oper_action(LOG_DLINE_TYPE, source_p, "[%s] [%s]\n",
          aconf->host, aconf->reason);
      write_csv_line(out, "%s%s%s%s%s%d",
          aconf->host, aconf->reason, aconf->oper_reason, 
          current_date,
          get_oper_name(source_p), cur_time);
    }
    else
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added temporary %d min. D-Line for [%s] [%s]",
          get_oper_name(source_p), duration/60, aconf->host, aconf->reason);

      sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]",
          from, to, duration/60, aconf->host);
      ilog(L_TRACE, "%s added temporary %d min. D-Line for [%s] [%s]",
          source_p->name, (int)duration/60, aconf->host, aconf->reason);
      log_oper_action(LOG_TEMP_DLINE_TYPE, source_p, "[%s@%s] [%s]\n",
          aconf->user, aconf->host, aconf->reason);
      write_csv_line(out, "%s%s%s%s%s%d%d",
          aconf->host, aconf->reason, aconf->oper_reason, 
          current_date, get_oper_name(source_p), cur_time, aconf->hold);
    }
    break;

  case XLINE_TYPE:
    xconf = (struct MatchItem *)map_to_conf(conf);
    if(duration == 0)
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added X-Line for [%s] [%s]",
          get_oper_name(source_p), conf->name,
          xconf->reason);
      sendto_one(source_p,
          ":%s NOTICE %s :Added X-Line [%s] [%d] [%s] to %s",
          from, to, conf->name, 
          xconf->action, xconf->reason, filename);
      ilog(L_TRACE, "%s added X-Line for [%s] [%s]",
          get_oper_name(source_p), conf->name, xconf->reason);
      write_csv_line(out, "%s%s%s%s%s%d",
          conf->name, xconf->reason, xconf->oper_reason,
          current_date, get_oper_name(source_p), cur_time);
    }
    else
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added temporary %d min. X-Line for [%s] [%s]",
          get_oper_name(source_p), (int)duration/60,
          conf->name, xconf->reason);
      sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. X-Line [%s]",
          MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
          source_p->name, (int)duration/60, conf->name);
      ilog(L_TRACE, "%s added temporary %d min. X-Line for [%s] [%s]",
          source_p->name, (int)duration/60,
          conf->name, xconf->reason);
      write_csv_line(out, "%s%s%s%s%s%d%d",
          conf->name, xconf->reason, xconf->oper_reason,
          current_date, get_oper_name(source_p), cur_time, xconf->hold);
 
    }
    break;

  case RXLINE_TYPE:
    xconf = (struct MatchItem *)map_to_conf(conf);
    if(duration == 0)
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added RX-Line for [%s] [%s]",
          get_oper_name(source_p), conf->name,
          xconf->reason);
      sendto_one(source_p,
          ":%s NOTICE %s :Added RX-Line [%s] [%s] to %s",
          from, to, conf->name,
          xconf->reason, filename);
      ilog(L_TRACE, "%s added X-Line for [%s] [%s]",
          get_oper_name(source_p), conf->name, xconf->reason);
      write_csv_line(out, "%s%s%s%s%s%d",
          conf->name, xconf->reason, xconf->oper_reason,
          current_date, get_oper_name(source_p), cur_time);
    }
    else
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added temporary %d min. RX-Line for [%s] [%s]",
          get_oper_name(source_p), (int)duration/60, conf->name, xconf->reason);
      sendto_one(source_p, 
          ":%s NOTICE %s :Added temporary %d min. RX-Line [%s]",
          from, to, (int)duration/60, conf->name);
      ilog(L_TRACE, "%s added temporary %d min. RX-Line for [%s] [%s]",
          source_p->name, (int)duration/60,
          conf->name, xconf->reason);
      write_csv_line(out, "%s%s%s%s%s%d%d",
          conf->name, xconf->reason, xconf->oper_reason,
          current_date, get_oper_name(source_p), cur_time, xconf->hold);
    }
    break;

  case CRESV_TYPE:
    cresv_p = (struct ResvChannel *)map_to_conf(conf);
    if(duration == 0)
      write_csv_line(out, "%s%s", cresv_p->name, cresv_p->reason);
    else
      write_csv_line(out, "%s%s%d", cresv_p->name, cresv_p->reason, cresv_p->hold);
    break;

  case NRESV_TYPE:
    nresv_p = (struct MatchItem *)map_to_conf(conf);
    if(duration == 0)
      write_csv_line(out, "%s%s", conf->name, nresv_p->reason);
    else
      write_csv_line(out, "%s%s%d", conf->name, nresv_p->reason, nresv_p->hold);
    break;

  default:
    fbclose(out);
    return;
  }

  fbclose(out);
}