Esempio n. 1
0
int filter_check (char *line, int direction)
{
    if (rule_list.enabled == 0)
        return -1;

    struct ruleset *rule, *last = NULL, packet;
    memset(&packet, 0, sizeof(packet));

    char *from, *action, *to, *data;
    char temp[1024];
    strncpy(temp, line, 1023);

    from = temp;
    action = SeperateWord(from);
    to = SeperateWord(action);
    data = SeperateWord(to);

    if (strempty(from))
        return -1;

    if (*from == ':')
        from++;

    packet.direction = direction;
    strncpy(packet.from, from, NICKLEN);
    if (action)
        strncpy(packet.action, action, 128);
    if (to)
        strncpy(packet.to, to, NICKLEN);
    if (data) {
        if (*data == ':')
            data++;
        strncpy(packet.data, data, 1023);
    }

    for (rule = rule_list.ltail; rule; rule = rule->lprev) {
        packet.rule = rule->rule;
        if ((match_rules(rule, &packet)) == 1) {
            last = rule;
            if (rule->quick == 1)
                return rule->rule;
        }
    }

    if (last)
        return last->rule;

    return -1;
}
Esempio n. 2
0
void doop(struct user *user, char *tail)
{
  unsigned char flags;
  struct reggedchannel *chanptr;
  char *channel;

  channel = tail;
  SeperateWord(tail);

  if (channel == NULL) {
    NoticeToUser(user, "Usage: op #channel");
    return;
  }

  if ((chanptr = GetChannelPointer(channel)) == NULL) {
    NoticeToUser(user, "Unknown channel %s.", channel);
    return;
  }

  flags = GetChannelFlags(user->authedas, chanptr);

  /* Check for OP or MASTER or OWNER flag */
  if (!(flags & (CFLAG_OP | CFLAG_MASTER | CFLAG_OWNER)) || IsSuspended(chanptr)) {
    /* No flags -- perhaps they are an oper? */
    if (!((user->oper) && (user->authedas->authlevel > 200))) {
      /* Nope, not an oper either */
      NoticeToUser(user, "Sorry, you need the +o flag on %s to get ops.", channel);
      return;
    }
  }

  /* Do the actual op */
  OpUser(chanptr, user->numeric);

  /* Update lastused timestamp on channel */
  chanptr->lastused = time(NULL);

  NoticeToUser(user, "Done.");
}
Esempio n. 3
0
void docleanupdb2(struct user *usr_ptr, char *tail)
{
  char *option;
  struct user *target;
  int i;
  struct reggedchannel *chan;

  if (!usr_ptr->oper) {
    NoticeToUser(usr_ptr, "You are not an operator");
    return;
  }

  if (!CheckAuthLevel(usr_ptr, 255))
    return;

  option = tail;
  SeperateWord(tail);
  if (!option) {
    NoticeToUser(usr_ptr, "Usage: cleanupdb2 nick");
    return;
  }

  if ((target = FindUserByNick(option)) == NULL) {
    NoticeToUser(usr_ptr, "Can't find nick: %s", option);
  }

  Log("Cleanupdb2: %s (%s) requested cleanupdb2 %s", usr_ptr->nick, usr_ptr->authedas->authname, option);

  for (i = 0; i < HASHMAX; i++) {
    for (chan = channelhashtable[i]; chan; chan = chan->nextbychannelname) {
      if (!IsSuspended(chan)) {
        MessageToUser(target, "expirecheck %s", chan->channelname);
      }
    }
  }

  NoticeToUser(usr_ptr, "Done.");
}
Esempio n. 4
0
struct ruleset *add_rule (char *ruledata)
{
    struct ruleset ruleset;
    memset(&ruleset, 0, sizeof(ruleset));

    char *what, *direction, *stuff;
    char temp[1024];
    strncpy(temp, ruledata, 1023);
    what = temp;
    direction = SeperateWord(what);
    stuff = SeperateWord(direction);

    if (strempty(what) || strempty(direction))
        return NULL;

    if (!strcmp(what,"drop"))
        ruleset.rule = RULE_DROP;
    else if (!strcmp(what,"pass"))
        ruleset.rule = RULE_PASS;
    else
        return NULL;

    if (!strcmp(direction,"in"))
        ruleset.direction = DIRECT_IN;
    else if (!strcmp(direction,"out"))
        ruleset.direction = DIRECT_OUT;
    else
        return NULL;

    char *param, *data;
    param = stuff;
    stuff = SeperateWord(param);

    if (!strcmp(param, "quick")) {
        ruleset.quick = 1;
        param = stuff;
        stuff = SeperateWord(param);
    }

    for (; stuff; param = stuff, stuff = SeperateWord(stuff)) {
        if (strcmp(param, "data")) { /* not data */
            data = stuff;
            stuff = SeperateWord(data);
            if (strempty(data))
                return NULL;
            if (!strcmp(param, "from"))
                strncpy(ruleset.from, data, 32);
            else if (!strcmp(param, "to")) {
                if (*data == '\\' && *(data+1) == '#')
                    data++;
                strncpy(ruleset.to, data, 32);
            } else if (!strcmp(param, "action"))
                strncpy(ruleset.action, data, 32);
            else
                return NULL;
        } else {
            data = strchr(stuff, '"');
            if (strempty(data))
                return NULL;
            data++;
            char *tmp = strchr(data, '"');
            if (strempty(tmp))
                return NULL;
            *tmp = '\0';
            if (*(tmp+1) == 'i')
                ruleset.icase = 1;
            stuff = StripBlanks(tmp+1);
            strncpy(ruleset.data, data, 1024);
        }
    }

    struct ruleset *new_rule;
    new_rule = (struct ruleset *)calloc(1, sizeof(struct ruleset));
    memcpy(new_rule, &ruleset, sizeof(ruleset));
    LIST_INSERT_HEAD(rule_list, new_rule, HASH_INT(new_rule->direction));
    if (rule_list.size == 1)
        rule_list.ltail = new_rule;

    return new_rule;
}
Esempio n. 5
0
void dogrep(struct user *user, char *tail)
{
  FILE *fp;
  int i = 1, errptr, opt = 0;
  const char *error;
  char *options, *pattern, *ep;
  char logfile[256];

  /* Check auth level.. */
  if (!CheckAuthLevel(user, 250))
    return;

  options = tail;
  pattern = SeperateWord(tail);

  if (NULL == options) {
    Usage(user, 1);
    return;
  }

  invert = FALSE;
  max_hits = HITS;
  if ('-' == options[0]) {
    while (options[i]) {
      switch (options[i++]) {
      case 'i':
        opt |= PCRE_CASELESS;
        break;
      case 'v':
        invert = TRUE;
        break;
      case 'l':
        if (NULL != pattern) {
          if ((max_hits = (int) strtol(pattern, &ep, 10)) > MAX_HITS)
            max_hits = MAX_HITS;
          if (0 == max_hits)
            max_hits = HITS;
          pattern = SeperateWord(pattern);
        }
        break;
      case 'V':
        NoticeToUser(user, "PCRE version %s", pcre_version());
        break;
      default:
        NoticeToUser(user, "unknown option \"%c\"", options[i - 1]);
        return;
        break;
      }
    }
  } else {
    pattern = options;
  }

  SeperateWord(pattern);

  if (NULL == pattern) {
    Usage(user, 1);
    return;
  }

  if (NULL == (cpattern = pcre_compile(pattern, opt, &error, &errptr, NULL))) {
    NoticeToUser(user, "error in regex at offset %d: %s", errptr, error);
    return;
  }

  hints = pcre_study(cpattern, 0, &error);
  if (NULL != error) {
    NoticeToUser(user, "error while studing regex: %s", error);
    return;
  }

  NoticeToUser(user, "Log entries%smatching \"%s\"", (TRUE == invert) ? " NOT " : " ", pattern);

  count = 0;
  for (i = NUMBEROFLOGFILES; (i >= 0 && count < max_hits); i--) {
    snprintf(logfile, 256, "%s.%i", LOGFILE, i);
    if (NULL == (fp = fopen(logfile, "r"))) {
      NoticeToUser(user, "failed to open: %s (%s)", logfile, strerror(errno));
    } else {
      pcregrep(fp, logfile, user);
      fclose(fp);
    }
  }

  if (cpattern != NULL)
    free(cpattern);
  if (hints != NULL)
    free(hints);

  if (count >= max_hits)
    NoticeToUser(user, "--- More than %d hits, list truncated", max_hits);

  NoticeToUser(user, "--- End of list - %d matc%s", count, (1 == count) ? "h" : "hes");
  NoticeToUser(user, "Done.");
}
Esempio n. 6
0
void dodeopall(struct user *user, char *tail)
{
  unsigned char flags;
  struct reggedchannel *chanptr;
  char *channel;

#if defined(HORRIBLE_DEOPALL_HACK) || defined(HAVE_CLEARMODE)
  char buf[512];
#endif /* HORRIBLE_DEOPALL_HACK */

  channel = tail;
  SeperateWord(tail);

  if (channel == NULL) {
    NoticeToUser(user, "Usage: deopall #channel");
    return;
  }

  if ((chanptr = GetChannelPointer(channel)) == NULL) {
    NoticeToUser(user, "Unknown channel %s.", channel);
    return;
  }

  flags = GetChannelFlags(user->authedas, chanptr);

  /* Check for MASTER or OWNER flag */
  if (!(flags & (CFLAG_MASTER | CFLAG_OWNER)) || IsSuspended(chanptr)) {
    /* No flags -- perhaps they are an oper? */
    if (!((user->oper) && (user->authedas->authlevel > 200))) {
      /* Nope, not an oper either */
      NoticeToUser(user, "Sorry, you need the +m or +n flag on %s to use deopall.", channel);
      return;
    }
  }

  /* Do the actual deopall */
  /* erm, how? */

/*
  sprintf(buf,"%s GL * +%s 0 :Clearing channel\r\n",my_numeric,channel);
  SendLine(buf);
*/

#ifdef HAVE_CLEARMODE
  sprintf(buf, "%sAAA CM %s o\r\n", my_numeric, channel);
  SendLine(buf);
  sprintf(buf, "%s M %s +o %sAAA\r\n", my_numeric, channel, my_numeric);
  SendLine(buf);
#else /* !HAVE_CLEARMODE */
# ifdef HORRIBLE_DEOPALL_HACK
  if (chanptr->timestamp > 0) {
    chanptr->timestamp--;
#  ifdef SIT_ON_CHANNELS
    /* If we're sitting on the channel, we can just rejoin it with a new timestamp... */
    if (IsJoined(chanptr)) {
      sprintf(buf, "%sAAA L %s\r\n", my_numeric, channel);
      SendLine(buf);
    }
    SetJoined(chanptr);
    sprintf(buf, "%s B %s %ld %sAAA:o\r\n", my_numeric, channel, chanptr->timestamp, my_numeric);
#  else /* !SIT_ON_CHANNELS */
    /* We're not sitting on the channel, so we send a burst with a _fake_ user */
    sprintf(buf, "%s B %s %ld %sAAB:o\r\n", my_numeric, channel, chanptr->timestamp, my_numeric);
#  endif /* SIT_ON_CHANNELS */
    SendLine(buf);
  } else {
    NoticeToUser(user, "Sorry, cannot deopall on %s at this time.", channel);
    return;
  }
# else /* !HORRIBLE_DEOPALL_HACK */
  if (NULL == Optr) {
    NoticeToUser(user, "Sorry, cannot deopall on %s at this time.", channel);
    return;
  } else {
    MessageToUser(Optr, "deopall -l %s", channel);
/*** This is no longer required
    MessageToUser(Optr, "opchan %s %s", channel, my_nick); */
  }
# endif /* HORRIBLE_DEOPALL_HACK */
#endif /* HAVE_CLEARMODE */

  Log("DeopAll: %s (%s) requested deopall in %s", user->nick, user->authedas->authname, channel);
  NoticeToUser(user, "Done.");
}