示例#1
0
/* log_failed_oper()
 *
 * inputs	- pointer to client that failed to oper up
 *              - oper name
 * output	- none
 * side effects - ffailed_operlog is written to, if its present
 */
void
log_failed_oper(struct Client *source_p, const char *name)
{
  if (ConfigLoggingEntry.failed_operlog[0] == '\0')
    return;

  if (IsPerson(source_p))
  {
    FBFILE *oper_fb;

    if ((oper_fb = fbopen(ConfigLoggingEntry.failed_operlog, "r")) != NULL)
    {
      fbclose(oper_fb);
      oper_fb = fbopen(ConfigLoggingEntry.failed_operlog, "a");
    }

    if (oper_fb != NULL)
    {
      char linebuf[BUFSIZE];
      size_t nbytes = ircsprintf(linebuf,
                                 "%s FAILED OPER (%s) by (%s!%s@%s)\n",
                                 myctime(CurrentTime), name, source_p->name,
                                 source_p->username, source_p->host);
      fbputs(linebuf, oper_fb, nbytes);
      fbclose(oper_fb);
    }
  }
}
示例#2
0
static void
sendhelpfile(struct Client *source_p, const char *path, const char *topic, const char *nick)
{
	FBFILE *file;
	char line[HELPLEN];

	if((file = fbopen(path, "r")) == NULL)
	{
		sendto_one(source_p, form_str(ERR_HELPNOTFOUND), me.name, nick, topic);
		return;
	}

	if(fbgets(line, sizeof(line), file) == NULL)
	{
		sendto_one(source_p, form_str(ERR_HELPNOTFOUND), me.name, nick, topic);
		return;
	}

	sendto_one(source_p, form_str(RPL_HELPSTART), me.name, nick, topic, line);

	while (fbgets(line, sizeof(line), file))
	{
		sendto_one(source_p, form_str(RPL_HELPTXT), me.name, nick, topic, line);
	}

	fbclose(file);
	sendto_one(source_p, form_str(RPL_ENDOFHELP), me.name, nick, topic);
	return;
}
示例#3
0
void
reopen_log(const char *filename)
{
  if (logFile != NULL)
    fbclose(logFile);
  open_log(filename);
}
示例#4
0
/** Tell a user that they are banned, dumping the message from a file.
 * @param sptr Client being rejected
 * @param filename Send this file's contents to \a sptr
 */
static void killcomment(struct Client* sptr, const char* filename)
{
  FBFILE*     file = 0;
  char        line[80];
  struct stat sb;

  if (NULL == (file = fbopen(filename, "r"))) {
    send_reply(sptr, ERR_NOMOTD);
    send_reply(sptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP,
               ":Connection from your host is refused on this server.");
    return;
  }
  fbstat(&sb, file);
  while (fbgets(line, sizeof(line) - 1, file)) {
    char* end = line + strlen(line);
    while (end > line) {
      --end;
      if ('\n' == *end || '\r' == *end)
        *end = '\0';
      else
        break;
    }
    send_reply(sptr, RPL_MOTD, line);
  }
  send_reply(sptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP,
             ":Connection from your host is refused on this server.");
  fbclose(file);
}
示例#5
0
void read_songs()
{
  int i = 0, tempnum = 0, templines = 0;
  FBFILE *lyricfile = NULL;

  if (!(lyricfile = fbopen("../lib/text/lyric", FB_READ)))
  {
      log("Error Reading Songs");
      return;
  }

  while (fbgetline(lyricfile, buf))
  {
    if (scanf(buf,"#%d", tempnum) != EOF)
    { 
      MAXSONGS++;
      jukebox[i].num = tempnum;
      templines = 0;
    }
    else if (!strcmp("^", buf))
    {
       jukebox[i].lines = templines;
       i++;
    }    
    else
    {
       strcpy(jukebox[i].lyrics[templines], buf);
       templines++;
    }
 } 

 fbclose(lyricfile);

}
示例#6
0
/* check_pidfile()
 *
 * inputs       - filename+path of pid file
 * output       - none
 * side effects - reads pid from pidfile and checks if ircd is in process
 *                list. if it is, gracefully exits
 * -kre
 */
static void
check_pidfile (const char *filename)
{
  FBFILE *fb;
  char buff[32];
  pid_t pidfromfile;

  /* Don't do logging here, since we don't have log() initialised */
  if ((fb = fbopen (filename, "r")))
    {
      if (fbgets (buff, 20, fb) == NULL)
	{
	  /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
	   * strerror(errno));
	   */
	}
      else
	{
	  pidfromfile = atoi (buff);

	  if (!kill (pidfromfile, 0))
	    {
	      /* log(L_ERROR, "Server is already running"); */
	      printf ("ircd: daemon is already running\n");
	      exit (-1);
	    }
	}

      fbclose (fb);
    }
  else if (errno != ENOENT)
    {
      /* log(L_ERROR, "Error opening pid file %s", filename); */
    }
}
示例#7
0
/* parse_resvconf()
 *
 * inputs - NONE
 * output - -1 if failure 0 if success
 * side effects - fills in irc_nsaddr_list
 */
static int
parse_resvconf(void)
{
  char *p;
  char *opt;
  char *arg;
  char input[MAXLINE];
  FBFILE *file;

  /* XXX "/etc/resolv.conf" should be from a define in setup.h perhaps
   * for cygwin support etc. this hardcodes it to unix for now -db
   */
  if ((file = fbopen("/etc/resolv.conf", "r")) == NULL)
    return(-1);

  while (fbgets(input, MAXLINE, file) != NULL)
  {
    /* blow away any newline */
    if ((p = strpbrk(input, "\r\n")) != NULL)
      *p = '\0';

    /* Ignore comment lines immediately */
    if (*input == '#')
      continue;

    p = input;
    /* skip until something thats not a space is seen */
    while (IsSpace(*p))
      p++;
    /* if at this point, have a '\0' then continue */
    if (*p == '\0')
      continue;

    /* skip until a space is found */
    opt = input;
    while (!IsSpace(*p))
      if (*p++ == '\0')
        continue;  /* no arguments?.. ignore this line */
    /* blow away the space character */
    *p++ = '\0';

    /* skip these spaces that are before the argument */
    while (IsSpace(*p))
      p++;
    /* Now arg should be right where p is pointing */
    arg = p;
    if ((p = strpbrk(arg, " \t")) != NULL)
      *p = '\0';  /* take the first word */

    if (strcasecmp(opt, "domain") == 0)
      strlcpy(irc_domain, arg, HOSTLEN);
    else if (strcasecmp(opt, "nameserver") == 0)
      add_nameserver(arg);
  }

  fbclose(file);
  return(0);
}
示例#8
0
/* user_log_resync()
 *
 * inputs	- NONE
 * output	- NONE
 * side effects	-
 */
static void
user_log_resync(void *notused)
{
  if (user_log_fb != NULL)
  {
    fbclose(user_log_fb);
    user_log_fb = NULL;
  }
}
示例#9
0
/* log_user_exit()
 *
 * inputs	- pointer to connecting client
 * output	- NONE
 * side effects - Current exiting client is logged to
 *		  either SYSLOG or to file.
 */
void
log_user_exit(struct Client *source_p)
{
  time_t on_for = CurrentTime - source_p->firsttime;
#ifdef SYSLOG_USERS
  if (IsPerson(source_p))
  {
    ilog(L_INFO, "%s (%3ld:%02ld:%02ld): %s!%s@%s %ld/%ld\n",
         myctime(source_p->firsttime),
	  (signed long) on_for / 3600,
	  (signed long) (on_for % 3600)/60,
	  (signed long) on_for % 60,
	  source_p->name, source_p->username, source_p->host,
	  source_p->localClient->sendK,
	  source_p->localClient->receiveK);
    }
#else
  {
    char linebuf[BUFSIZ];

    /*
     * This conditional makes the logfile active only after
     * it's been created - thus logging can be turned off by
     * removing the file.
     * -Taner
     */
    if (IsPerson(source_p))
    {
      if (user_log_fb == NULL)
      {
	if ((ConfigLoggingEntry.userlog[0] != '\0') && 
	   (user_log_fb = fbopen(ConfigLoggingEntry.userlog, "r")) != NULL)
	{
	  fbclose(user_log_fb);
	  user_log_fb = fbopen(ConfigLoggingEntry.userlog, "a");
	}
      }

      if (user_log_fb != NULL)
      {
        size_t nbytes = ircsprintf(linebuf,
		   "%s (%3ld:%02ld:%02ld): %s!%s@%s %d/%d\n",
		   myctime(source_p->firsttime),
		   (signed long) on_for / 3600,
		   (signed long) (on_for % 3600)/60,
		   (signed long) on_for % 60,
		   source_p->name, source_p->username, source_p->host,
		   source_p->localClient->sendK,
		   source_p->localClient->receiveK);
	fbputs(linebuf, user_log_fb, nbytes);
      }
    }
  }
#endif
}
示例#10
0
文件: m_help.c 项目: mdharris/ircd
static void 
sendhelpfile(struct Client *source_p, const char *path, const char *topic)
{
  FBFILE *file;
  char line[HELPLEN];
  char started = 0;
  int type;

  if ((file = fbopen(path, "r")) == NULL)
  {
    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
               me.name, source_p->name, topic);
    return;
  }

  if (fbgets(line, sizeof(line), file) == NULL)
  {
    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
               me.name, source_p->name, topic);
    return;
  }

  else if (line[0] != '#')
  {
    line[strlen(line) - 1] = '\0';	  
    sendto_one(source_p, form_str(RPL_HELPSTART),
             me.name, source_p->name, topic, line);
    started = 1;
  }

  while (fbgets(line, sizeof(line), file))
  {
    line[strlen(line) - 1] = '\0';
    if (line[0] != '#')
    {
      if (!started)
      {
        type = RPL_HELPSTART;
        started = 1;
      }
      else
        type = RPL_HELPTXT;
      
      sendto_one(source_p, form_str(RPL_HELPTXT),
                 me.name, source_p->name, topic, line);
    }
  }

  fbclose(file);
  sendto_one(source_p, form_str(RPL_HELPTXT),
             me.name, source_p->name, topic, "");
  sendto_one(source_p, form_str(RPL_ENDOFHELP),
             me.name, source_p->name, topic);
}
示例#11
0
extern void write_log(const char *filename, const char *pattern, ...)
{
    FBFILE *logfile;
    va_list vl;
    static char logbuf[1024];

    logfile = fbopen(filename, "a");

    if (logfile)
    {
        va_start(vl, pattern);
        ircd_vsnprintf(0, logbuf, sizeof(logbuf) - 1, pattern, vl);
        va_end(vl);

        fbputs(logbuf, logfile);
        fbclose(logfile);
    }
}
示例#12
0
static void readconfig(adns_state ads, const char *filename, int warnmissing) {
  getline_ctx gl_ctx;
  
  gl_ctx.file= fbopen(filename,"r");
  if (gl_ctx.file == NULL) {
    if (errno == ENOENT) {
      if (warnmissing)
	adns__debug(ads,-1,0,"configuration file `%s' does not exist",filename);
      return;
    }
    saveerr(ads,errno);
    adns__diag(ads,-1,0,"cannot open configuration file `%s': %s",
	       filename,strerror(errno));
    return;
  }

  readconfiggeneric(ads,filename,gl_file,gl_ctx);
  
  fbclose(gl_ctx.file);
}
示例#13
0
static void
write_pidfile(const char *filename)
{
  FBFILE *fb;

  if ((fb = fbopen(filename, "w")))
  {
    char buff[32];
    unsigned int pid = (unsigned int)getpid();
    size_t nbytes = ircsprintf(buff, "%u\n", pid);

    if ((fbputs(buff, fb, nbytes) == -1))
      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
           pid, filename, strerror(errno));

    fbclose(fb);
  }
  else
  {
    ilog(L_ERROR, "Error opening pid file %s", filename);
  }
}
示例#14
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);
}
示例#15
0
文件: motd.c 项目: DamnIO/DamnIRCd
/** This function reads a motd out of a file (if needed) and caches it.
 * If a matching cache entry already exists, reuse it.  Otherwise,
 * allocate and populate a new MotdCache for it.
 * @param[in] motd Specification for MOTD file.
 * @return Matching MotdCache entry.
 */
static struct MotdCache *
motd_cache(struct Motd *motd)
{
  FBFILE*		file;
  struct MotdCache*	cache;
  struct stat		sb;
  char			line[MOTD_LINESIZE + 2]; /* \r\n */
  char*			tmp;
  int			i;

  assert(0 != motd);
  assert(0 != motd->path);

  if (motd->cache)
    return motd->cache;

  /* try to find it in the list of cached files... */
  for (cache = MotdList.cachelist; cache; cache = cache->next) {
    if (!strcmp(cache->path, motd->path) &&
	cache->maxcount == motd->maxcount) { /* found one... */
      cache->ref++; /* increase reference count... */
      motd->cache = cache; /* remember cache... */
      return motd->cache; /* return it */
    }
  }

  /* gotta read in the file, now */
  if (!(file = fbopen(motd->path, "r"))) {
    Debug((DEBUG_ERROR, "Couldn't open \"%s\": %s", motd->path,
	   strerror(errno)));
    return 0;
  }

  /* need the file's modification time */
  if (-1 == fbstat(&sb, file)) {
    fbclose(file);
    return 0;
  }

  /* Ok, allocate a structure; we'll realloc later to trim memory */
  cache = (struct MotdCache *)MyMalloc(sizeof(struct MotdCache) +
				       (MOTD_LINESIZE * (MOTD_MAXLINES - 1)));

  cache->ref = 1;
  DupString(cache->path, motd->path);
  cache->maxcount = motd->maxcount;

  cache->modtime = *localtime((time_t *) &sb.st_mtime); /* store modtime */

  cache->count = 0;
  while (cache->count < cache->maxcount && fbgets(line, sizeof(line), file)) {
    /* copy over line, stopping when we overflow or hit line end */
    for (tmp = line, i = 0;
	 i < (MOTD_LINESIZE - 1) && *tmp && *tmp != '\r' && *tmp != '\n';
	 tmp++, i++)
      cache->motd[cache->count][i] = *tmp;
    cache->motd[cache->count][i] = '\0';

    cache->count++;
  }

  fbclose(file); /* close the file */

  /* trim memory usage a little */
  motd->cache = (struct MotdCache*)MyMalloc(sizeof(struct MotdCache) +
                                            (MOTD_LINESIZE * (cache->count - 1)));
  memcpy(motd->cache, cache, sizeof(struct MotdCache) +
         (MOTD_LINESIZE * (cache->count - 1)));
  MyFree(cache);

  /* now link it in... */
  motd->cache->next = MotdList.cachelist;
  motd->cache->prev_p = &MotdList.cachelist;
  if (MotdList.cachelist)
    MotdList.cachelist->prev_p = &motd->cache->next;
  MotdList.cachelist = motd->cache;

  return motd->cache;
}
示例#16
0
void
cleanup_log()
{
  if(logFile != NULL)
    fbclose(logFile);
}
示例#17
0
/*
 * read_message_file() - original From CoMSTuD, added Aug 29, 1996
 *
 * inputs	- pointer to MessageFileptr
 * output	-
 * side effects	-
 */
int
read_message_file(MessageFile *MessageFileptr)
{
  struct stat sb;
  struct tm *local_tm;

  /* used to clear out old MessageFile entries */
  MessageFileLine *mptr = 0;
  MessageFileLine *next_mptr = 0;

  /* used to add new MessageFile entries */
  MessageFileLine *newMessageLine = 0;
  MessageFileLine *currentMessageLine = 0;

  char buffer[MESSAGELINELEN];
  char *p;
  FBFILE *file;

  for (mptr = MessageFileptr->contentsOfFile; mptr; mptr = next_mptr)
  {
    next_mptr = mptr->next;
    MyFree(mptr);
  }

  MessageFileptr->contentsOfFile = NULL;

  if (stat(MessageFileptr->fileName, &sb) < 0)
    return(-1);

  local_tm = localtime(&sb.st_mtime);

  if (local_tm)
    ircsprintf(MessageFileptr->lastChangedDate,
               "%d/%d/%d %d:%02d",
               local_tm->tm_mday,
               local_tm->tm_mon + 1,
               1900 + local_tm->tm_year,
               local_tm->tm_hour,
               local_tm->tm_min);

  if ((file = fbopen(MessageFileptr->fileName, "r")) == NULL)
    return(-1);

  while (fbgets(buffer, sizeof(buffer), file))
  {
    if ((p = strchr(buffer, '\n')) != NULL)
      *p = '\0';

    newMessageLine = (MessageFileLine *)MyMalloc(sizeof(MessageFileLine));
    strlcpy(newMessageLine->line, buffer, sizeof(newMessageLine->line));
    newMessageLine->next = NULL;

    if (MessageFileptr->contentsOfFile != NULL)
    {
      if (currentMessageLine)
        currentMessageLine->next = newMessageLine;

      currentMessageLine = newMessageLine;
    }
    else
    {
      MessageFileptr->contentsOfFile = newMessageLine;
      currentMessageLine = newMessageLine;
    }
  }

  fbclose(file);
  return(0);
}
示例#18
0
static void
mo_spoof(struct Client *client_p, struct Client *source_p,
         int parc, char *parv[])
{
  char *host, *spoof, *password;
  const char *tmp = NULL;
  const char *user = NULL;
  const char *flags = NULL;
  int i = 0;
#ifdef SPOOF_FILE
  int class_opers;
  FBFILE *f;
  char buffer[1024];
  struct AddressRec *arec;
#endif

  if (MyConnect(source_p) && !IsOperAdmin(source_p))
  {
    sendto_one(source_p, form_str(ERR_NOPRIVS),
               me.name, source_p->name, "SPOOF");
    return;
  }

  /* check the user@host mask */
  if (strchr(parv[1], '!') != NULL)
  {
    syntax:
    if (MyConnect(source_p))
      sendto_one(source_p, ":%s NOTICE %s :Syntax: SPOOF <umask@hmask> "
                 "<spoof/-> [flags/- [password]]", me.name, source_p->name);
    return;
  }

  (void) collapse(parv[1]);

  for (tmp = parv[1]; *tmp; tmp++)
    if (!IsKWildChar(*tmp))
      if (++i >= ConfigFileEntry.min_nonwildcard)
        break;
  if (i < ConfigFileEntry.min_nonwildcard)
  {
    if (MyConnect(source_p))
      sendto_one(source_p, ":%s NOTICE %s :Not enough non-wildcard characters "
                           "in user@host mask",
                           me.name, source_p->name);
    return;
  }

  host = strchr(parv[1], '@');
  if (host)
  {
    user = parv[1];
    *host = '\0';
    host++;
  }
  else
  {
    user = "******";
    host = parv[1];
  }

  /* check the spoof field */
  spoof = parv[2];
  if (spoof == NULL || !*spoof)
    goto syntax;

  if (spoof[0] != '-' || spoof[1] != '\0')
  {
    for (tmp = spoof; *tmp; tmp++)
      if (!IsHostChar(*tmp)) {
        if (MyConnect(source_p))
          sendto_one(source_p, ":%s NOTICE %s :The spoof [%s] is invalid",
                     me.name, source_p->name, spoof);
        return;
      }
    if (strlen(spoof) >= HOSTLEN) {
      if (MyConnect(source_p))
        sendto_one(source_p, ":%s NOTICE %s :Spoofs must be less than %d.."
                             "ignoring it", me.name, source_p->name, HOSTLEN);
      return;
    }
  }

  flags = (parc > 3) ? parv[3] : "-";
  password = (parc > 4 && parv[4][0]) ? parv[4] : NULL;

#ifdef PROPAGATE_SPOOF
  sendto_server(client_p, source_p, NULL, NOCAPS, NOCAPS, LL_ICLIENT,
                ":%s SPOOF %s@%s %s %s :%s",
                source_p->name, user, host, spoof, flags, password ? password : "");
#endif

#ifdef SPOOF_FILE
  /* Walk through auth {} items and check if we have another auth block
   * for this hostname */
  for (i = 0; i < ATABLE_SIZE; i++)
    for (arec = atable[i]; arec; arec = arec->next)
      if (arec->type == CONF_CLIENT && !irccmp(arec->aconf->host, host) &&
        !irccmp(arec->aconf->user, user))
      {
        /* auth entry already exists */
        if (MyConnect(source_p))
          sendto_one(source_p,
                     ":%s NOTICE %s :auth for %s@%s already exists, you need "
                     "to use /DELSPOOF first", me.name, source_p->name, user, host);
#ifdef LOG_SPOOF
        sendto_realops_flags(UMODE_ALL, L_ALL,
                             "%s attemped to re-add auth for %s@%s "
                             "[spoof: %s, flags: %s]", source_p->name, user, host,
                             spoof, flags);
#endif
        return;
      }

  /* Add the spoof to the the spoof file */
  if ((f = fbopen(SPOOF_FILE, "a")) == NULL)
  {
    sendto_realops_flags(UMODE_ALL, L_ALL,
                         "Could not open %s file, auth for %s@%s "
                         "[spoof: %s, flags: %s, requested by %s] not added",
                         SPOOF_FILE, user, host, spoof, flags, source_p->name);
    return;
  }

  /* write the auth {} block */
  fbputs("auth {\n", f, 7);
  i = ircsprintf(buffer, "\tuser = \"%s@%s\";\n", user, host);
  fbputs(buffer, f, i);
  if (spoof[0] != '-' || spoof[1] != '\0')
  {
    i = ircsprintf(buffer, "\tspoof = \"%s\";\n", spoof);
    fbputs(buffer, f, i);
  }
  if (password)
  {
    i = ircsprintf(buffer, "\tpassword = \"%s\";\n", password);
    fbputs(buffer, f, i);
  }

  /* process given flags */
  i = class_opers = 0;
  for (tmp = flags; *tmp; ++tmp)
    switch (*tmp)
    {
      case 't': i |= CONF_FLAGS_NO_TILDE;      /* no_tilde = yes; */
                break;
      case 'i': i |= CONF_FLAGS_NEED_IDENTD;   /* need_ident = yes; */
                break;
      case 'k': i |= CONF_FLAGS_EXEMPTKLINE;   /* kline_exempt = yes; */
                break;
      case 'g': i |= CONF_FLAGS_EXEMPTGLINE;   /* gline_exempt = yes; */
                break;
      case 'l': i |= CONF_FLAGS_NOLIMIT;       /* exceed_limit = yes; */
                break;
      case 'o': class_opers = 1;               /* class = "opers"; */
                break;
      case 'f': i |= CONF_FLAGS_CAN_FLOOD;     /* can_flood = yes; */
                break;
      case 'p': i|= CONF_FLAGS_NEED_PASSWORD;  /* need_password = yes; */
    }

  if (i)
  {
    fbputs("\tflags = ", f, 9);
    try_flag(f, &i, CONF_FLAGS_NO_TILDE, "no_tilde");
    try_flag(f, &i, CONF_FLAGS_NEED_IDENTD, "need_ident");
    try_flag(f, &i, CONF_FLAGS_EXEMPTKLINE, "kline_exempt");
    try_flag(f, &i, CONF_FLAGS_EXEMPTGLINE, "gline_exempt");
    try_flag(f, &i, CONF_FLAGS_NOLIMIT, "exceed_limit");
    try_flag(f, &i, CONF_FLAGS_CAN_FLOOD, "can_flood");
    try_flag(f, &i, CONF_FLAGS_NEED_PASSWORD, "need_password");
  }

  if (class_opers)
    fbputs("\tclass = \"opers\";\n", f, 18);
  else
    fbputs("\tclass = \"users\";\n", f, 18);

  fbputs("};\n\n", f, 4);
  fbclose(f);

  rehash(0);
#endif

#ifdef LOG_SPOOF
  sendto_realops_flags(UMODE_ALL, L_ALL,
                       "%s added auth for %s@%s [spoof: %s, flags: %s]",
                       source_p->name, user, host, spoof, flags);
  ilog(L_TRACE, "%s added auth for %s@%s [spoof: %s, flags: %s]",
                source_p->name, user, host, spoof, flags);
#endif
}
示例#19
0
/* Now, our job is a bit harder. I will scan through the SPOOF_FILE
 * and read all auths{} (assuming they are written in our line formatting..),
 * then rewrite them skipping the one to delete. --adx */
static void
mo_delspoof(struct Client *client_p, struct Client *source_p,
            int parc, char *parv[])
{
#ifdef SPOOF_FILE
  FBFILE *f, *fout;
  int ignore_it = 1, spoof_found = 0;
  char buffer[1024], *tmp;
#endif
  const char *user = NULL;
  char *host = NULL;

  if (MyConnect(source_p) && !IsOperAdmin(source_p))
  {
    sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, parv[0], "DELSPOOF");
    return;
  }

  if (parv[1] == NULL || !*parv[1])
  {
    if (MyConnect(source_p))
      sendto_one(source_p, ":%s NOTICE %s :Syntax: /DELSPOOF <user@host>",
                           me.name, source_p->name);
    return;
  }

  /* check user@host mask */
  (void) collapse(parv[1]);

  host = strchr(parv[1], '@');
  if (host != NULL)
  {
    user = parv[1];
    *host = '\0';
    host++;
  }
  else
  {
    user = "******";
    host = parv[1];
  }

#ifdef PROPAGATE_SPOOF
  sendto_server(client_p, source_p, NULL, NOCAPS, NOCAPS, LL_ICLIENT,
    ":%s DELSPOOF %s@%s", source_p->name, user, host);
#endif

#ifdef SPOOF_FILE
  if ((f = fbopen(SPOOF_FILE, "r")) == NULL)
  {
    sendto_realops_flags(UMODE_ALL, L_ALL,
                         "Could not open %s file, auth for %s@%s not deleted "
                         "(requested by %s)",
                         SPOOF_FILE, user, host, source_p->name);
    return;
  }

  if ((fout = fbopen(SPOOF_FILE ".new", "w")) == NULL)
  {
    sendto_realops_flags(UMODE_ALL, L_ALL,
                         "Could not create %s.new file, auth for %s@%s not "
                         "deleted (requested by %s)",
                         SPOOF_FILE, user, host, source_p->name);
    return;
  }

  while (fbgets(buffer, 1024, f))
  {
    if (!ircncmp(buffer, "auth {", 6))
    {
      /* don't process it yet.. we have to check whether the user="******"; field
       * matches the user@host mask which is being deleted
       */
      ignore_it = 1;
      continue;
    }

    /* a simple parser substitute... */
    for (tmp = buffer; *tmp == '\t' || *tmp == ' '; tmp++)
      ;
    if (!ircncmp(tmp, "user", 4))
    {
      for (tmp += 4; *tmp == '\t' || *tmp == ' '; tmp++)
        ;
      if (*tmp == '=') {
        for (++tmp; *tmp == '\t' || *tmp == ' '; tmp++)
          ;
        if (*tmp == '\"')
        {
          /* yuppi, we've just reached the user="******"; field */
          int matches;
          char *tmp2 = strchr(++tmp, '\"');

          if (tmp2 != NULL)
            *tmp2 = '\0';
          tmp2 = strchr(tmp, '@');

          /* is it matching our mask? */
          if (tmp2 == NULL)
            matches = !irccmp(user, "*") && !irccmp(host, tmp);
          else
          {
            *tmp2++ = '\0';
            matches = !irccmp(user, tmp) && !irccmp(host, tmp2);
          }

          if (!matches)
          {
            /* no.. so leave it unchanged */
            if (ignore_it)
            {
              ignore_it = 0;
              fbputs("auth {\n", fout, 7);
              /* user="******" should be the first field in the auth {}; block,
               * otherwise we could have problems...
               */
            }

            fbputs("\tuser = \"", fout, 9);
            if (tmp2 == NULL)
              fbputs("*", fout, 1);
            else
              fbputs(tmp, fout, strlen(tmp));
            fbputs("@", fout, 1);
            fbputs(tmp2, fout, strlen(tmp2));
            fbputs("\";\n", fout, 3);
          }
          else
          {
            /* we've got it! - omit and continue working */
            spoof_found = 1;
          }

          continue;
        }
      }
    }

    if (!ignore_it)
      fbputs(buffer, fout, strlen(buffer));
  }

  fbclose(f);
  fbclose(fout);

  if (!spoof_found)
  {
    if (MyConnect(source_p))
      sendto_one(source_p, ":%s NOTICE %s :No auth for %s@%s found",
                 me.name, source_p->name, user, host);
    unlink(SPOOF_FILE ".new");
    return;
  }

  unlink(SPOOF_FILE);
  rename(SPOOF_FILE ".new", SPOOF_FILE);
  rehash(0);
#endif

#ifdef LOG_SPOOF
  sendto_realops_flags(UMODE_ALL, L_ALL, "%s deleted auth for %s@%s",
                       source_p->name, user, host);
#endif
}
示例#20
0
void
reopen_log(const char *filename)
{
  fbclose(logFile);
  open_log(filename);
}