Пример #1
0
/****************************************************************************
Append single file to tar file (or not)
***************************************************************************/
static void do_tar(file_info *finfo)
{
  pstring rname;

  if (strequal(finfo->name,"..") || strequal(finfo->name,"."))
    return;

  /* Is it on the exclude list ? */
  if (!tar_excl && clipn) {
    pstring exclaim;

    DEBUG(5, ("Excl: strlen(cur_dir) = %d\n", (int)strlen(cur_dir)));

    safe_strcpy(exclaim, cur_dir, sizeof(pstring));
    *(exclaim+strlen(exclaim)-1)='\0';

    safe_strcat(exclaim, "\\", sizeof(pstring));
    safe_strcat(exclaim, finfo->name, sizeof(exclaim));

    DEBUG(5, ("...tar_re_search: %d\n", tar_re_search));

    if ((!tar_re_search && clipfind(cliplist, clipn, exclaim)) ||
#ifdef HAVE_REGEX_H
	(tar_re_search && !regexec(preg, exclaim, 0, NULL, 0))) {
#else
        (tar_re_search && mask_match(exclaim, cliplist[0], True, False))) {
#endif
      DEBUG(3,("Skipping file %s\n", exclaim));
      return;
    }
  }
Пример #2
0
char *text_ban_get_list(char *_net, char *_chan, char *ident)
{
   static char list[1024];
   char row[512];
   int len, r;

   list[0] = 0;
   len = 0;

   r = config_get_row(cfgname, "bans", NULL, 0);

   while(r == CONFIG_OK)
   {
      char *bid, *uid, *net, *chan, *mask;
      int netok, chanok, identok;

      if((r = config_get_row(NULL, NULL, row, 512)) != CONFIG_OK)
         break;

      bid = strtok(row, " \t");
      uid = strtok(NULL, " \t");
      net = strtok(NULL, " \t");
      chan = strtok(NULL, " \t");
      mask = strtok(NULL, " \t");

      if((!bid) || (!uid) || (!net) || (!chan) || (!mask))
         continue;

      netok = 0;
      chanok = 0;
      identok = 0;

      if((_net == NULL) || (strcasecmp(net, _net) == 0))
         netok = 1;
      if((_chan == NULL) || (strcasecmp(chan, _chan) == 0))
         chanok = 1;
      if((ident == NULL) || mask_match(mask, ident))
         identok = 1;

      if(netok && chanok && identok)
      {
         if(len + strlen(bid) > 1020)
            break;

         strcat(list, bid);
         len += strlen(bid);
         strcat(list, " ");
         len++;
      }
   }

   if(len)
      len--;

   list[len] = 0;

   return list;
}
Пример #3
0
static BOOL masks_match(char** masks, char* str)
{
    char** p;
    for (p = masks; p-masks < MAX_MASK && *p != NULL; p++) {
        if (mask_match(*p, str)) {
            return TRUE;
        }
    }
    return FALSE;
}
Пример #4
0
static void notifylist_check_join(IRC_SERVER_REC *server, const char *nick,
				  const char *userhost, const char *realname, int away)
{
	NOTIFYLIST_REC *notify;
	NOTIFY_NICK_REC *rec;
	char *user, *host;

	if (nick == NULL)
		return;

	notify = notifylist_find(nick, server->connrec->chatnet);
	if (notify == NULL) return;

	rec = notify_nick_find(server, nick);
	if (rec != NULL && rec->join_announced) return;
	if (rec == NULL) rec = notify_nick_create(server, nick);

	user = g_strdup(userhost == NULL ? "" : userhost);
	host = strchr(user, '@');
	if (host != NULL) *host++ = '\0'; else host = "";

	if (!mask_match(SERVER(server), notify->mask, nick, user, host)) {
		g_free(user);
		return;
	}

	if (notify->away_check && away == -1) {
		/* we need to know if the nick is away */
		g_free(user);
		return;
	}

	g_free_not_null(rec->user);
	g_free_not_null(rec->host);
	g_free_not_null(rec->realname);
	rec->user = g_strdup(user);
	rec->host = g_strdup(host);
	rec->realname = realname == NULL || *realname == '\0' ? NULL : g_strdup(realname);

	if (away != -1) rec->away = away;
	rec->host_ok = TRUE;
	rec->join_announced = TRUE;
	rec->idle_time = 0;

	signal_emit("notifylist joined", 6,
		    server, rec->nick, rec->user, rec->host, realname, NULL);
	g_free(user);
}
Пример #5
0
static PyObject *PyServer_mask_match(PyServer *self, PyObject *args, PyObject *kwds)
{
    static char *kwlist[] = {"mask", "nick", "user", "host", NULL};
    char *mask = "";
    char *nick = "";
    char *user = "";
    char *host = "";

    RET_NULL_IF_INVALID(self->data);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "ssss", kwlist, 
           &mask, &nick, &user, &host))
        return NULL;

    return PyBool_FromLong(mask_match(self->data, mask, nick, user, host));
}
Пример #6
0
static void got_unexempt(struct chanset_t *chan, char *nick, char *from,
                         char *who, char *ch, struct userrec *u)
{
  masklist *e = chan->channel.exempt, *old = NULL;
  masklist *b;
  int match = 0;

  while (e && e->mask[0] && rfc_casecmp(e->mask, who)) {
    old = e;
    e = e->next;
  }
  if (e && e->mask[0]) {
    if (old)
      old->next = e->next;
    else
      chan->channel.exempt = e->next;
    nfree(e->mask);
    nfree(e->who);
    nfree(e);
  }
  check_tcl_mode(nick, from, u, chan->dname, "-e", who);
  if (!(chan = modebind_refresh(ch, from, &user, NULL, NULL)))
    return;

  if (channel_pending(chan))
    return;

  if (u_sticky_mask(chan->exempts, who) || u_sticky_mask(global_exempts, who))
    add_mode(chan, '+', 'e', who);

  /* If exempt was removed by master then leave it else check for bans */
  if (!nick[0] && glob_bot(user) && !glob_master(user) && !chan_master(user)) {
    b = chan->channel.ban;
    while (b->mask[0] && !match) {
      if (mask_match(b->mask, who)) {
        add_mode(chan, '+', 'e', who);
        match = 1;
      } else
        b = b->next;
    }
  }
  if ((u_equals_mask(global_exempts, who) ||
      u_equals_mask(chan->exempts, who)) && me_op(chan) &&
      !channel_dynamicexempts(chan) && (!glob_bot(user) ||
      !(bot_flags(u) & BOT_SHARE)))
    add_mode(chan, '+', 'e', who);
}
Пример #7
0
static void event_whois(IRC_SERVER_REC *server, const char *data)
{
        char *params, *nick, *user, *host, *realname;
	NOTIFY_NICK_REC *nickrec;
	NOTIFYLIST_REC *notify;

	g_return_if_fail(data != NULL);
	g_return_if_fail(server != NULL);

	params = event_get_params(data, 6, NULL, &nick, &user, &host, NULL, &realname);

	notify = notifylist_find(nick, server->connrec->chatnet);
	if (notify != NULL && !mask_match(SERVER(server), notify->mask, nick, user, host)) {
		/* user or host didn't match */
		g_free(params);
		return;
	}

	nickrec = notify_nick_find(server, nick);
	if (nickrec != NULL) {
                g_free_not_null(last_notify_nick);
		last_notify_nick = g_strdup(nick);

		g_free_not_null(nickrec->user);
		g_free_not_null(nickrec->host);
		g_free_not_null(nickrec->realname);
		g_free_and_null(nickrec->awaymsg);
		nickrec->user = g_strdup(user);
		nickrec->host = g_strdup(host);
		nickrec->realname = g_strdup(realname);

		nickrec->away = FALSE;
		nickrec->host_ok = TRUE;
		nickrec->idle_ok = TRUE;
	}
	g_free(params);
}
Пример #8
0
int text_ban_get_id(char *_net, char *_chan, char *ident)
{
   char row[512];
   int r;

   if(_net == NULL || _chan == NULL)
      return 0;

   r = config_get_row(cfgname, "bans", NULL, 0);

   while(r == CONFIG_OK)
   {
      char *bid, *uid, *net, *chan, *mask;

      if((r = config_get_row(NULL, NULL, row, 512)) != CONFIG_OK)
         break;

      bid = strtok(row, " \t");
      uid = strtok(NULL, " \t");
      net = strtok(NULL, " \t");
      chan = strtok(NULL, " \t");
      mask = strtok(NULL, " \t");

      if((!bid) || (!uid) || (!net) || (!chan) || (!mask))
         continue;

      if((strcasecmp(net, _net) == 0) &&
         (strcasecmp(chan, _chan) == 0) &&
         mask_match(mask, ident))
      {
         return atoi(bid);
      }
   }

   return 0;
}
Пример #9
0
static void check_expired_chanstuff()
{
    masklist *b, *e;
    memberlist *m, *n;
    char *key, s[UHOSTLEN];
    struct chanset_t *chan;
    struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };

    if (!server_online)
        return;
    for (chan = chanset; chan; chan = chan->next) {
        if (channel_active(chan)) {
            if (me_op(chan) || me_halfop(chan)) {
                if (channel_dynamicbans(chan) && chan->ban_time)
                    for (b = chan->channel.ban; b->mask[0]; b = b->next)
                        if (now - b->timer > 60 * chan->ban_time &&
                                !u_sticky_mask(chan->bans, b->mask) &&
                                !u_sticky_mask(global_bans, b->mask) &&
                                expired_mask(chan, b->who)) {
                            putlog(LOG_MODES, chan->dname,
                                   "(%s) Channel ban on %s expired.", chan->dname, b->mask);
                            add_mode(chan, '-', 'b', b->mask);
                            b->timer = now;
                        }

                if (use_exempts && channel_dynamicexempts(chan) && chan->exempt_time)
                    for (e = chan->channel.exempt; e->mask[0]; e = e->next)
                        if (now - e->timer > 60 * chan->exempt_time &&
                                !u_sticky_mask(chan->exempts, e->mask) &&
                                !u_sticky_mask(global_exempts, e->mask) &&
                                expired_mask(chan, e->who)) {
                            /* Check to see if it matches a ban */
                            int match = 0;

                            for (b = chan->channel.ban; b->mask[0]; b = b->next)
                                if (mask_match(b->mask, e->mask)) {
                                    match = 1;
                                    break;
                                }
                            /* Leave this extra logging in for now. Can be removed later
                             * Jason
                             */
                            if (match) {
                                putlog(LOG_MODES, chan->dname,
                                       "(%s) Channel exemption %s NOT expired. Exempt still set!",
                                       chan->dname, e->mask);
                            } else {
                                putlog(LOG_MODES, chan->dname,
                                       "(%s) Channel exemption on %s expired.",
                                       chan->dname, e->mask);
                                add_mode(chan, '-', 'e', e->mask);
                            }
                            e->timer = now;
                        }

                if (use_invites && channel_dynamicinvites(chan) &&
                        chan->invite_time && !(chan->channel.mode & CHANINV))
                    for (b = chan->channel.invite; b->mask[0]; b = b->next)
                        if (now - b->timer > 60 * chan->invite_time &&
                                !u_sticky_mask(chan->invites, b->mask) &&
                                !u_sticky_mask(global_invites, b->mask) &&
                                expired_mask(chan, b->who)) {
                            putlog(LOG_MODES, chan->dname,
                                   "(%s) Channel invitation on %s expired.",
                                   chan->dname, b->mask);
                            add_mode(chan, '-', 'I', b->mask);
                            b->timer = now;
                        }

                if (chan->idle_kick)
                    for (m = chan->channel.member; m && m->nick[0]; m = m->next)
                        if (now - m->last >= chan->idle_kick * 60 &&
                                !match_my_nick(m->nick) && !chan_issplit(m)) {
                            sprintf(s, "%s!%s", m->nick, m->userhost);
                            get_user_flagrec(m->user ? m->user : get_user_by_host(s),
                                             &fr, chan->dname);
                            if ((!(glob_bot(fr) || glob_friend(fr) || (glob_op(fr) &&
                                    !chan_deop(fr)) || chan_friend(fr) || chan_op(fr))) &&
                                    (me_op(chan) || (me_halfop(chan) && !chan_hasop(m)))) {
                                dprintf(DP_SERVER, "KICK %s %s :idle %d min\n", chan->name,
                                        m->nick, chan->idle_kick);
                                m->flags |= SENTKICK;
                            }
                        }
            }
            for (m = chan->channel.member; m && m->nick[0]; m = n) {
                n = m->next;
                if (m->split && now - m->split > wait_split) {
                    sprintf(s, "%s!%s", m->nick, m->userhost);
                    check_tcl_sign(m->nick, m->userhost,
                                   m->user ? m->user : get_user_by_host(s),
                                   chan->dname, "lost in the netsplit");
                    putlog(LOG_JOIN, chan->dname,
                           "%s (%s) got lost in the net-split.", m->nick, m->userhost);
                    killmember(chan, m->nick);
                }
                m = n;
            }
            check_lonely_channel(chan);
        } else if (!channel_inactive(chan) && !channel_pending(chan)) {

            key = chan->channel.key[0] ? chan->channel.key : chan->key_prot;
            if (key[0])
                dprintf(DP_SERVER, "JOIN %s %s\n",
                        chan->name[0] ? chan->name : chan->dname, key);
            else
                dprintf(DP_SERVER, "JOIN %s\n",
                        chan->name[0] ? chan->name : chan->dname);
        }
    }
}
Пример #10
0
/* Check for expired timed-exemptions
 */
static void check_expired_exempts(void)
{
  maskrec *u, *u2;
  struct chanset_t *chan;
  masklist *b, *e;
  int match;

  if (!use_exempts)
    return;
  for (u = global_exempts; u; u = u2) {
    u2 = u->next;
    if (!(u->flags & MASKREC_PERM) && (now >= u->expire)) {
      putlog(LOG_MISC, "*", "%s %s (%s)", EXEMPTS_NOLONGER,
             u->mask, MISC_EXPIRED);
      for (chan = chanset; chan; chan = chan->next) {
        match = 0;
        b = chan->channel.ban;
        while (b->mask[0] && !match) {
          if (mask_match(b->mask, u->mask))
            match = 1;
          else
            b = b->next;
        }
        if (match)
          putlog(LOG_MISC, chan->dname,
                 "Exempt not expired on channel %s. Ban still set!",
                 chan->dname);
        else
          for (e = chan->channel.exempt; e->mask[0]; e = e->next)
            if (!rfc_casecmp(e->mask, u->mask) &&
                expired_mask(chan, e->who) && e->timer != now) {
              add_mode(chan, '-', 'e', u->mask);
              e->timer = now;
            }
      }
      u_delexempt(NULL, u->mask, 1);
    }
  }
  /* Check for specific channel-domain exempts expiring */
  for (chan = chanset; chan; chan = chan->next) {
    for (u = chan->exempts; u; u = u2) {
      u2 = u->next;
      if (!(u->flags & MASKREC_PERM) && (now >= u->expire)) {
        match = 0;
        b = chan->channel.ban;
        while (b->mask[0] && !match) {
          if (mask_match(b->mask, u->mask))
            match = 1;
          else
            b = b->next;
        }
        if (match)
          putlog(LOG_MISC, chan->dname,
                 "Exempt not expired on channel %s. Ban still set!",
                 chan->dname);
        else {
          putlog(LOG_MISC, "*", "%s %s %s %s (%s)", EXEMPTS_NOLONGER,
                 u->mask, MISC_ONLOCALE, chan->dname, MISC_EXPIRED);
          for (e = chan->channel.exempt; e->mask[0]; e = e->next)
            if (!rfc_casecmp(e->mask, u->mask) &&
                expired_mask(chan, e->who) && e->timer != now) {
              add_mode(chan, '-', 'e', u->mask);
              e->timer = now;
            }
          u_delexempt(chan, u->mask, 1);
        }
      }
    }
  }
}
Пример #11
0
uint32 trans2_get_direntries( PDENT_HND dhnd,
				uint32 SearchCount,
				uint16 Flags,
				uint16 info,
				uint32 ResumeKey,
				SMBSTR *filename,
				TRANS2_FIND_FIRST2_D_R *rd,
				uint16 *FoundCount,
				uint16 *EndOfSearch,
				uint16 *EaErrorOffset,
				uint16 *LastNameOffset)
{
	uint32 i;
	SMBSTR *dir_path;
	SMBSTR *mask;
	TRANS2_FIND_FIRST2_P_Q qp;

	if (info != 0x104)
		return NT_STATUS_INVALID_INFO_CLASS;

	if (!get_dirent_info(dhnd, &qp))
		return NT_STATUS_INVALID_HANDLE;

	DEBUG(10,("trans2_get_direntries: %s", smbstrA(&qp.FileName)));
	DEBUG(10,("count: %d flags: %x infolevel: %d key: %d\n",
				SearchCount,
				Flags,
				info,
				ResumeKey));

	if (!get_dirent_seekdir(dhnd, ResumeKey))
	{
		return NT_STATUS_INVALID_HANDLE;
	}

	
	mask = smbstr_filename(&qp.FileName);
	if (mask == NULL)
	{
		return NT_STATUS_NO_MEMORY;
	}

	dir_path = smbstr_dirname(&qp.FileName);
	if (dir_path == NULL)
	{
		return NT_STATUS_NO_MEMORY;
	}

	DEBUG(10,("dir: %s, mask: %s\n", smbstrA(dir_path), smbstrA(mask)));

	if (SearchCount != 0)
	{
		rd->ff = talloc(hnd_get_ctx(dhnd),
				sizeof(FIND_FIRST2_INFO) * SearchCount);
		if (rd->ff == NULL)
		{
			return NT_STATUS_NO_MEMORY;
		}
		memset(rd->ff, 0, sizeof(FIND_FIRST2_INFO) * SearchCount);
	}
	*FoundCount = 0;
	*LastNameOffset = 0;
	*EaErrorOffset = 0;
	for (i = ResumeKey; (*FoundCount) < SearchCount; i++)
	{
		smb_find_file_both_directory_info ent;
		uint16 NextEntryOffset;
		SMB_STRUCT_STAT sbuf;
		const SMBSTR *str = get_dirent_readdirname(dhnd);
		const SMBSTR *full_str;

		ResumeKey = get_dirent_telldir(dhnd);

		if (str == NULL || ResumeKey == -1)
		{
			*EndOfSearch = 1;
			*LastNameOffset = 0;
			break;
		}
		DEBUG(10,("file: %s mask: %s\n", smbstrA(str), smbstrA(mask)));
		if (!mask_match(smbstrA(str), smbstrA(mask), True))
			continue;

		if (strequal(smbstrA(str), ".") || 
		    strequal(smbstrA(str), ".."))
			continue;

		full_str = smbstr_make_filename(dir_path, str);
		DEBUG(10,("filename: %s\n", smbstrA(full_str)));

		if (get_dirent_stat(dhnd, &sbuf, full_str) != 0)
			continue;

		trans2_smbffbdi_make(&sbuf, str, &ent);

		DEBUG(10,("search: %d rk: %d\n", i, ResumeKey));
		NextEntryOffset = ALIGN4(94 + ent.FileNameLength, 0);
		rd->ff[*FoundCount].ctr.fbd = ent;
		rd->ff[*FoundCount].NextEntryOffset = NextEntryOffset;
		rd->ff[*FoundCount].FileIndex = ResumeKey;
		(*FoundCount)++;
		(*LastNameOffset) += NextEntryOffset;
	}

	return NT_STATUS_NOPROBLEMO;
}
Пример #12
0
int
encap6_input(struct mbuf **mp, int *offp, int proto)
{
	struct mbuf *m = *mp;
	struct ip6_hdr *ip6;
	struct sockaddr_in6 s, d;
	const struct ip6protosw *psw;
	struct encaptab *ep, *match;
	int prio, matchprio;

	/* Expect 32-bit aligned data pointer on strict-align platforms */
	MBUF_STRICT_DATA_ALIGNMENT_CHECK_32(m);

	ip6 = mtod(m, struct ip6_hdr *);
	bzero(&s, sizeof(s));
	s.sin6_family = AF_INET6;
	s.sin6_len = sizeof(struct sockaddr_in6);
	s.sin6_addr = ip6->ip6_src;
	bzero(&d, sizeof(d));
	d.sin6_family = AF_INET6;
	d.sin6_len = sizeof(struct sockaddr_in6);
	d.sin6_addr = ip6->ip6_dst;

	match = NULL;
	matchprio = 0;
	for (ep = LIST_FIRST(&encaptab); ep; ep = LIST_NEXT(ep, chain)) {
		if (ep->af != AF_INET6)
			continue;
		if (ep->proto >= 0 && ep->proto != proto)
			continue;
		if (ep->func)
			prio = (*ep->func)(m, *offp, proto, ep->arg);
		else {
			/*
			 * it's inbound traffic, we need to match in reverse
			 * order
			 */
			prio = mask_match(ep, (struct sockaddr *)&d,
			    (struct sockaddr *)&s);
		}

		/* see encap4_input() for issues here */
		if (prio <= 0)
			continue;
		if (prio > matchprio) {
			matchprio = prio;
			match = ep;
		}
	}

	if (match) {
		/* found a match */
		psw = (const struct ip6protosw *)match->psw;
		if (psw && psw->pr_input) {
			encap_fillarg(m, match);
			return (*psw->pr_input)(mp, offp, proto);
		} else {
			m_freem(m);
			return IPPROTO_DONE;
		}
	}

	/* last resort: inject to raw socket */
	return rip6_input(mp, offp, proto);
}
Пример #13
0
void
encap4_input(struct mbuf *m, int off)
{
	int proto;
	struct ip *ip;
	struct sockaddr_in s, d;
	const struct protosw *psw;
	struct encaptab *ep, *match;
	int prio, matchprio;

#ifndef __APPLE__
	va_start(ap, m);
	off = va_arg(ap, int);
	proto = va_arg(ap, int);
	va_end(ap);
#endif

	/* Expect 32-bit aligned data pointer on strict-align platforms */
	MBUF_STRICT_DATA_ALIGNMENT_CHECK_32(m);

	ip = mtod(m, struct ip *);
#ifdef __APPLE__
	proto = ip->ip_p;
#endif

	bzero(&s, sizeof(s));
	s.sin_family = AF_INET;
	s.sin_len = sizeof(struct sockaddr_in);
	s.sin_addr = ip->ip_src;
	bzero(&d, sizeof(d));
	d.sin_family = AF_INET;
	d.sin_len = sizeof(struct sockaddr_in);
	d.sin_addr = ip->ip_dst;

	match = NULL;
	matchprio = 0;
	for (ep = LIST_FIRST(&encaptab); ep; ep = LIST_NEXT(ep, chain)) {
		if (ep->af != AF_INET)
			continue;
		if (ep->proto >= 0 && ep->proto != proto)
			continue;
		if (ep->func)
			prio = (*ep->func)(m, off, proto, ep->arg);
		else {
			/*
			 * it's inbound traffic, we need to match in reverse
			 * order
			 */
			prio = mask_match(ep, (struct sockaddr *)&d,
			    (struct sockaddr *)&s);
		}

		/*
		 * We prioritize the matches by using bit length of the
		 * matches.  mask_match() and user-supplied matching function
		 * should return the bit length of the matches (for example,
		 * if both src/dst are matched for IPv4, 64 should be returned).
		 * 0 or negative return value means "it did not match".
		 *
		 * The question is, since we have two "mask" portion, we
		 * cannot really define total order between entries.
		 * For example, which of these should be preferred?
		 * mask_match() returns 48 (32 + 16) for both of them.
		 *	src=3ffe::/16, dst=3ffe:501::/32
		 *	src=3ffe:501::/32, dst=3ffe::/16
		 *
		 * We need to loop through all the possible candidates
		 * to get the best match - the search takes O(n) for
		 * n attachments (i.e. interfaces).
		 */
		if (prio <= 0)
			continue;
		if (prio > matchprio) {
			matchprio = prio;
			match = ep;
		}
	}

	if (match) {
		/* found a match, "match" has the best one */
		psw = (const struct protosw *)match->psw;
		if (psw && psw->pr_input) {
			encap_fillarg(m, match);
			(*psw->pr_input)(m, off);
		} else
			m_freem(m);
		return;
	}

	/* last resort: inject to raw socket */
	rip_input(m, off);
}