/*----------------------------------------------------------------------------*/
  void 
  match_packet(packet_t* p){
    entry_t *e;
    int found = 0;
    PRINTF("[FLT]: Matching Packet...\n");

    for(e = list_head(flowtable); e != NULL; e = e->next) {
      found = match_entry(p,e);
      if (found){
        break;
      }
    }
    if (!found){
      PRINTF("[FLT]: Match Not Found!\n");
      create_and_send_request(p);
    }
  }
Exemple #2
0
ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag,
		 char **resp, size_t size,
		 int argc, char * const argv[])
{
	ENTRY *list[htab->size];
	char *res, *p;
	size_t totlen;
	int i, n;

	/* Test for correct arguments.  */
	if ((resp == NULL) || (htab == NULL)) {
		__set_errno(EINVAL);
		return (-1);
	}

	debug("EXPORT  table = %p, htab.size = %d, htab.filled = %d, size = %lu\n",
	      htab, htab->size, htab->filled, (ulong)size);
	/*
	 * Pass 1:
	 * search used entries,
	 * save addresses and compute total length
	 */
	for (i = 1, n = 0, totlen = 0; i <= htab->size; ++i) {

		if (htab->table[i].used > 0) {
			ENTRY *ep = &htab->table[i].entry;
			int found = match_entry(ep, flag, argc, argv);

			if ((argc > 0) && (found == 0))
				continue;

			if ((flag & H_HIDE_DOT) && ep->key[0] == '.')
				continue;

			list[n++] = ep;

			totlen += strlen(ep->key) + 2;

			if (sep == '\0') {
				totlen += strlen(ep->data);
			} else {	/* check if escapes are needed */
				char *s = ep->data;

				while (*s) {
					++totlen;
					/* add room for needed escape chars */
					if ((*s == sep) || (*s == '\\'))
						++totlen;
					++s;
				}
			}
			totlen += 2;	/* for '=' and 'sep' char */
		}
	}

#ifdef DEBUG
	/* Pass 1a: print unsorted list */
	printf("Unsorted: n=%d\n", n);
	for (i = 0; i < n; ++i) {
		printf("\t%3d: %p ==> %-10s => %s\n",
		       i, list[i], list[i]->key, list[i]->data);
	}
#endif

	/* Sort list by keys */
	qsort(list, n, sizeof(ENTRY *), cmpkey);

	/* Check if the user supplied buffer size is sufficient */
	if (size) {
		if (size < totlen + 1) {	/* provided buffer too small */
			printf("Env export buffer too small: %lu, but need %lu\n",
			       (ulong)size, (ulong)totlen + 1);
			__set_errno(ENOMEM);
			return (-1);
		}
	} else {
		size = totlen + 1;
	}

	/* Check if the user provided a buffer */
	if (*resp) {
		/* yes; clear it */
		res = *resp;
		memset(res, '\0', size);
	} else {
		/* no, allocate and clear one */
		*resp = res = calloc(1, size);
		if (res == NULL) {
			__set_errno(ENOMEM);
			return (-1);
		}
	}
	/*
	 * Pass 2:
	 * export sorted list of result data
	 */
	for (i = 0, p = res; i < n; ++i) {
		const char *s;

		s = list[i]->key;
		while (*s)
			*p++ = *s++;
		*p++ = '=';

		s = list[i]->data;

		while (*s) {
			if ((*s == sep) || (*s == '\\'))
				*p++ = '\\';	/* escape */
			*p++ = *s++;
		}
		*p++ = sep;
	}
	*p = '\0';		/* terminate result */

	return size;
}
Exemple #3
0
/*
 * Is a tree entry interesting given the pathspec we have?
 *
 * Pre-condition: either baselen == base_offset (i.e. empty path)
 * or base[baselen-1] == '/' (i.e. with trailing slash).
 */
static enum interesting do_match(const struct name_entry *entry,
				 struct strbuf *base, int base_offset,
				 const struct pathspec *ps,
				 int exclude)
{
	int i;
	int pathlen, baselen = base->len - base_offset;
	enum interesting never_interesting = ps->has_wildcard ?
		entry_not_interesting : all_entries_not_interesting;

	GUARD_PATHSPEC(ps,
		       PATHSPEC_FROMTOP |
		       PATHSPEC_MAXDEPTH |
		       PATHSPEC_LITERAL |
		       PATHSPEC_GLOB |
		       PATHSPEC_ICASE |
		       PATHSPEC_EXCLUDE);

	if (!ps->nr) {
		if (!ps->recursive ||
		    !(ps->magic & PATHSPEC_MAXDEPTH) ||
		    ps->max_depth == -1)
			return all_entries_interesting;
		return within_depth(base->buf + base_offset, baselen,
				    !!S_ISDIR(entry->mode),
				    ps->max_depth) ?
			entry_interesting : entry_not_interesting;
	}

	pathlen = tree_entry_len(entry);

	for (i = ps->nr - 1; i >= 0; i--) {
		const struct pathspec_item *item = ps->items+i;
		const char *match = item->match;
		const char *base_str = base->buf + base_offset;
		int matchlen = item->len, matched = 0;

		if ((!exclude &&   item->magic & PATHSPEC_EXCLUDE) ||
		    ( exclude && !(item->magic & PATHSPEC_EXCLUDE)))
			continue;

		if (baselen >= matchlen) {
			/* If it doesn't match, move along... */
			if (!match_dir_prefix(item, base_str, match, matchlen))
				goto match_wildcards;

			if (!ps->recursive ||
			    !(ps->magic & PATHSPEC_MAXDEPTH) ||
			    ps->max_depth == -1)
				return all_entries_interesting;

			return within_depth(base_str + matchlen + 1,
					    baselen - matchlen - 1,
					    !!S_ISDIR(entry->mode),
					    ps->max_depth) ?
				entry_interesting : entry_not_interesting;
		}

		/* Either there must be no base, or the base must match. */
		if (baselen == 0 || !basecmp(item, base_str, match, baselen)) {
			if (match_entry(item, entry, pathlen,
					match + baselen, matchlen - baselen,
					&never_interesting))
				return entry_interesting;

			if (item->nowildcard_len < item->len) {
				if (!git_fnmatch(item, match + baselen, entry->path,
						 item->nowildcard_len - baselen))
					return entry_interesting;

				/*
				 * Match all directories. We'll try to
				 * match files later on.
				 */
				if (ps->recursive && S_ISDIR(entry->mode))
					return entry_interesting;
			}

			continue;
		}

match_wildcards:
		if (item->nowildcard_len == item->len)
			continue;

		if (item->nowildcard_len &&
		    !match_wildcard_base(item, base_str, baselen, &matched))
			continue;

		/*
		 * Concatenate base and entry->path into one and do
		 * fnmatch() on it.
		 *
		 * While we could avoid concatenation in certain cases
		 * [1], which saves a memcpy and potentially a
		 * realloc, it turns out not worth it. Measurement on
		 * linux-2.6 does not show any clear improvements,
		 * partly because of the nowildcard_len optimization
		 * in git_fnmatch(). Avoid micro-optimizations here.
		 *
		 * [1] if match_wildcard_base() says the base
		 * directory is already matched, we only need to match
		 * the rest, which is shorter so _in theory_ faster.
		 */

		strbuf_add(base, entry->path, pathlen);

		if (!git_fnmatch(item, match, base->buf + base_offset,
				 item->nowildcard_len)) {
			strbuf_setlen(base, base_offset + baselen);
			return entry_interesting;
		}
		strbuf_setlen(base, base_offset + baselen);

		/*
		 * Match all directories. We'll try to match files
		 * later on.
		 * max_depth is ignored but we may consider support it
		 * in future, see
		 * http://thread.gmane.org/gmane.comp.version-control.git/163757/focus=163840
		 */
		if (ps->recursive && S_ISDIR(entry->mode))
			return entry_interesting;
	}
	return never_interesting; /* No matches */
}
Exemple #4
0
/*ARGSUSED*/
static void
door_server(void *cookie, char *argp, size_t arg_size, door_desc_t *dp,
    uint_t n_desc)
{
	request_t		req;
	xmlDocPtr		x_doc;
	xmlChar			*resp_buf = NULL;
	int			ret, size = 0;
	pthread_t		tid;
	thr_elem_t		*thr;
	ucred_t			*uc = NULL;

	if (ISNS_MGMT_REQUEST_RECEIVED_ENABLED()) {
	    ISNS_MGMT_REQUEST_RECEIVED();
	}

	if (door_ucred(&uc) != 0) {
	    isnslog(LOG_DEBUG, "door_server",
		"door_ucred failed. errno: %d\n", errno);
	    ret = build_result_message(&resp_buf,
		ERR_DOOR_UCRED_FAILED, &size);
	    if (ret == ISNS_RSP_SUCCESSFUL) {
		(void) door_return((char *)resp_buf, size + 1,  NULL, 0);
		/* Not reached */
	    } else {
		ret = ERR_DOOR_UCRED_FAILED;
		(void) door_return((void *)&ret, sizeof (ret),  NULL, 0);
		/* Not reached */
	    }
	}

	isnslog(LOG_DEBUG, "door_server", "entered with request:\n %s\n", argp);
	if ((x_doc = xmlParseMemory(argp, arg_size)) != NULL) {
		isnslog(LOG_DEBUG, "door_server", "ParseMemory succeeded");
		if ((ret = process_mgmt_request(x_doc, &req, uc)) == 0) {
		    ret = build_mgmt_response(&resp_buf, req, &size);
		} else {
		    ret = build_result_message(&resp_buf, ret, &size);
		}
		xmlFreeDoc(x_doc);
		cleanup_request(req);
	} else {
		ret = build_result_message(&resp_buf,
		    ERR_XML_PARSE_MEMORY_FAILED, &size);
	}

	/* free the ucred */
	ucred_free(uc);

	if (resp_buf) {
	    tid = pthread_self();
	    if ((thr = match_entry(tid)) == NULL) {
		(void) add_entry(tid, resp_buf);
	    } else {
		isnslog(LOG_DEBUG, "door_server",
		    "free the previouly returned buffer %x on this thread\n",
		    thr->doc);
		xmlFree(thr->doc);
		isnslog(LOG_DEBUG, "door_server",
		    "store the currently allocated buffer %x on this thread\n",
		    resp_buf);
		thr->doc = resp_buf;
	    }
	    isnslog(LOG_DEBUG,
		"door_server", "exiting with response:\n %s\n",
		    (const char *)resp_buf);

	    if (ISNS_MGMT_REQUEST_RESPONDED_ENABLED()) {
		ISNS_MGMT_REQUEST_RESPONDED();
	    }

	    (void) door_return((char *)resp_buf, size + 1,  NULL, 0);
		/* Not reached */
	}

	isnslog(LOG_DEBUG,
	    "door_server", "exiting only with error code %d\n", ret);

	if (ISNS_MGMT_REQUEST_RESPONDED_ENABLED()) {
	    ISNS_MGMT_REQUEST_RESPONDED();
	}

	(void) door_return((void *)&ret, sizeof (ret),  NULL, 0);

}