Exemplo n.º 1
0
struct vars *parse_vars()
{
	struct vars *v;

	v = malloc(sizeof(struct vars));
	if (v == NULL)
	{
		perror("No memory");
		return NULL;
	}

	v->decl = parse_decl();
	if (v->decl == NULL)
	{
		free(v);
		return NULL;
	}

	if (get_token().type != T_SEP)
	{
		unget_token();
		v->v = NULL;
		return v;
	}

	v->v = parse_vars();

	if (v->v == NULL)
	{
		unget_token();
	}

	return v;
}
Exemplo n.º 2
0
int parse_ip(uint32_t *addr, const char *saddr)
{
	if (parse_vars(&saddr, saddr)) {
		return -1;
	}

	char *ip_parts[5];

	char saddr_cpy[MAX_STR_LEN_PROC];
	if (strlen(saddr) > MAX_STR_LEN_PROC) {
		set_errf("String too long (max supported: %d)", MAX_STR_LEN_PROC);
		return -2;
	}
	strncpy(saddr_cpy, saddr, MAX_STR_LEN_PROC);

	if (4 != rte_strsplit(saddr_cpy, strlen(saddr_cpy), ip_parts, 5, '.')) {
		set_errf("Expecting 4 octets in ip.");
		return -1;
	}

	uint32_t val;
	for (uint8_t i = 0; i < 4; ++i) {
		val = atoi(ip_parts[i]);
		if (val > 255) {
			set_errf("Maximum value for octet is 255 but octet %u is %u", i, val);
			return -1;
		}
		*addr = *addr << 8 | val;
	}
	return 0;
}
Exemplo n.º 3
0
int parse_int_mask(uint32_t *val, uint32_t *mask, const char *str)
{
	char str_cpy[MAX_STR_LEN_PROC];
	char *mask_str;

	if (parse_vars(&str, str)) {
		return -1;
	}

	if (strlen(str) > MAX_STR_LEN_PROC) {
		set_errf("String too long (max supported: %d)", MAX_STR_LEN_PROC);
		return -2;
	}
	strncpy(str_cpy, str, MAX_STR_LEN_PROC);


	mask_str = strchr(str_cpy, '&');

	if (mask_str == NULL) {
		set_errf("Missing '&' when parsing mask");
		return -2;
	}

	*mask_str = 0;

	if (parse_int(val, str))
		return -1;
	if (parse_int(mask, mask_str + 1))
		return -1;

	return 0;
}
Exemplo n.º 4
0
int parse_ip4_cidr(struct ip4_subnet *val, const char *str2)
{
	char str[MAX_STR_LEN_PROC];
	char *slash;
	int prefix;

	if (parse_vars(str, sizeof(str), str2))
		return -1;

	slash = strstr(str, "/");

	if (slash == NULL) {
		set_errf("Missing '/' when parsing CIDR notation");
		return -2;
	}

	*slash = 0;
	prefix = atoi(slash + 1);
	val->prefix = prefix;

	if (prefix > 32) {
		set_errf("Prefix %d is too big", prefix);
		return -2;
	}
	if (prefix < 1) {
		set_errf("Prefix %d is too small", prefix);
	}
	if (parse_ip(&val->ip, str))
		return -2;

	/* Apply mask making all bits outside the prefix zero */
	val->ip &= ((int)(1 << 31)) >> (prefix - 1);

	return 0;
}
Exemplo n.º 5
0
void parse_decl(context& ctx) throw (coord) {
	parse_enum(ctx);
	if (ctx.tag == IDENT)
		parse_vars(ctx);
	if (ctx.tag != SEMICOLON)
		throw ctx.start;
	next_token(ctx);

}
Exemplo n.º 6
0
int parse_range(uint32_t* lo, uint32_t* hi, const char *str2)
{
	char str[MAX_STR_LEN_PROC];
	char *dash;

	if (parse_vars(str, sizeof(str), str2))
		return -1;

	dash = strstr(str, "-");

	if (dash == NULL) {
		set_errf("Missing '-' when parsing mask");
		return -2;
	}

	*dash = 0;

	if (parse_int(lo, str))
		return -1;
	if (parse_int(hi, dash + 1))
		return -1;

	int64_t tmp = strtol(str, 0, 0);
	if (tmp > UINT32_MAX) {
		set_errf("Integer is bigger than %u", UINT32_MAX);
		return -1;
	}
	if (tmp < 0) {
		set_errf("Integer is negative");
		return -2;
	}

	*lo = tmp;

	tmp = strtol(dash + 1, 0, 0);
	if (tmp > UINT32_MAX) {
		set_errf("Integer is bigger than %u", UINT32_MAX);
		return -1;
	}
	if (tmp < 0) {
		set_errf("Integer is negative");
		return -2;
	}

	*hi = tmp;

	if (*lo > *hi) {
		set_errf("Low boundary is above high boundary in range");
		return -2;
	}

	return 0;
}
Exemplo n.º 7
0
struct program *parse_program()
{
	struct program *p;

	if (get_token().type != T_HAI)
	{
		unget_token();
		return NULL;
	}

	if (get_token().type != T_SEP)
	{
		unget_token();
		parse_error("expected separator");
		return NULL;
	}

	p = malloc(sizeof(struct program));

	if (p == NULL)
	{
		perror("No memory");
		return NULL;
	}


	p->v = parse_vars();

	if (p->v != NULL)
		if (get_token().type != T_SEP)
		{
			parse_error("expected separator");
			free(p);
			return NULL;
		}

	p->i = parse_instruction();

	while (get_token().type == T_SEP);

	unget_token();

	if (tokens[current_token].type != T_EOF)
	{
		parse_error("expecting instruction");
		return NULL;
	}

	return p;
}
Exemplo n.º 8
0
void		exec_cmd(char *str)
{
	char **cmd;

	str = ft_strdup(parse_vars(str));
	if (!(cmd = split_cmd(str)) || !cmd[0])
	{
		free_tab(cmd);
		return ;
	}
	if (!exec_file(cmd) && !exec_builtin(cmd))
		exec_path(cmd);
	free(str);
	free_tab(cmd);
}
Exemplo n.º 9
0
int parse_ip6_cidr(struct ip6_subnet *val, const char *saddr)
{
	char saddr_cpy[MAX_STR_LEN_PROC];
	char *slash;
	int prefix;
	if (parse_vars(&saddr, saddr)) {
		return -1;
	}

	if (strlen(saddr) > MAX_STR_LEN_PROC) {
		set_errf("String too long (max supported: %d)", MAX_STR_LEN_PROC);
		return -2;
	}

	strncpy(saddr_cpy, saddr, MAX_STR_LEN_PROC);
	slash = strstr(saddr_cpy, "/");

	if (slash == NULL) {
		set_errf("Missing '/' when parsing CIDR notation");
		return -2;
	}

	*slash = 0;
	prefix = atoi(slash + 1);
	val->prefix = prefix;

	parse_ip6((struct ipv6_addr *)&val->ip, saddr_cpy);

	/* Apply mask making all bits outside the prefix zero */

	int p = 120;
	int cnt = 0;

	while (p >= prefix) {
		val->ip[15-cnt] = 0;
		p -= 8;
		cnt++;
	}

	if (prefix % 8 != 0) {
		val->ip[15-cnt] &= ((int8_t)(1 << 7)) >> ((prefix %8) - 1);
	}
Exemplo n.º 10
0
int parse_ip4_cidr(struct ip4_subnet *val, const char *saddr)
{
	char saddr_cpy[MAX_STR_LEN_PROC];
	char *slash;
	int prefix;

	if (parse_vars(&saddr, saddr)) {
		return -1;
	}

	if (strlen(saddr) > MAX_STR_LEN_PROC) {
		set_errf("String too long (max supported: %d)", MAX_STR_LEN_PROC);
		return -2;
	}

	strncpy(saddr_cpy, saddr, MAX_STR_LEN_PROC);
	slash = strstr(saddr_cpy, "/");

	if (slash == NULL) {
		set_errf("Missing '/' when parsing CIDR notation");
		return -2;
	}

	*slash = 0;
	prefix = atoi(slash + 1);
	val->prefix = prefix;

	if (prefix > 32) {
		set_errf("Prefix %d is too big", prefix);
		return -2;
	}
	if (prefix < 1) {
		set_errf("Prefix %d is too small", prefix);
	}
	if (parse_ip(&val->ip, saddr_cpy))
		return -2;

	/* Apply mask making all bits outside the prefix zero */
	val->ip &= ((int)(1 << 31)) >> (prefix - 1);

	return 0;
}
Exemplo n.º 11
0
static ssize_t
dbus_dldr_write(struct file *filp, const char *buf, size_t count, loff_t *off)
{
	int n, k;
	bool isvars;
	char *bp = (char *) buf;

	down(&g_probe_info.dlsem);

	n = count >= DL_BLKSZ ? DL_BLKSZ : count;
	if (copy_from_user(g_wrblk, bp, n)) {
		n = -EFAULT;
		goto exit;
	}

	isvars = is_vars(g_wrblk, n);

	if (isvars == TRUE) {
		k = parse_vars(bp, n, g_vars, sizeof(g_vars));
		probe_dlwrite((uint8 *)g_vars, k, TRUE);
		goto exit;
	}

	n = 0;
	bp = (char *) buf;
	while (count > 0) {
		k = count >= DL_BLKSZ ? DL_BLKSZ : count;
		if (copy_from_user(g_wrblk, bp, k)) {
			n = -EFAULT;
			break;
		}

		n += k;
		bp += k;
		count -= k;
		probe_dlwrite((uint8 *)g_wrblk, k, isvars);
	}

exit:
	up(&g_probe_info.dlsem);
	return n;
}
Exemplo n.º 12
0
int parse_ip6_cidr(struct ip6_subnet *val, const char *str2)
{
	char str[MAX_STR_LEN_PROC];
	char *slash;
	int prefix;

	if (parse_vars(str, sizeof(str), str2))
		return -1;

	slash = strstr(str, "/");

	if (slash == NULL) {
		set_errf("Missing '/' when parsing CIDR notation");
		return -2;
	}

	*slash = 0;
	prefix = atoi(slash + 1);
	val->prefix = prefix;

	parse_ip6((struct ipv6_addr *)&val->ip, str);

	/* Apply mask making all bits outside the prefix zero */

	int p = 120;
	int cnt = 0;

	while (p >= prefix) {
		val->ip[15-cnt] = 0;
		p -= 8;
		cnt++;
	}

	if (prefix % 8 != 0) {
		val->ip[15-cnt] &= ((int8_t)(1 << 7)) >> ((prefix %8) - 1);
	}
Exemplo n.º 13
0
int parse_int_mask(uint32_t *val, uint32_t *mask, const char *str2)
{
	char str[MAX_STR_LEN_PROC];
	char *mask_str;

	if (parse_vars(str, sizeof(str), str2))
		return -1;

	mask_str = strchr(str, '&');

	if (mask_str == NULL) {
		set_errf("Missing '&' when parsing mask");
		return -2;
	}

	*mask_str = 0;

	if (parse_int(val, str))
		return -1;
	if (parse_int(mask, mask_str + 1))
		return -1;

	return 0;
}
Exemplo n.º 14
0
int parse_range(uint32_t* lo, uint32_t* hi, const char *str)
{
	char str_cpy[MAX_STR_LEN_PROC];
	char *dash;

	if (parse_vars(&str, str)) {
		return -1;
	}

	if (strlen(str) > MAX_STR_LEN_PROC) {
		set_errf("String too long (max supported: %d)", MAX_STR_LEN_PROC);
		return -2;
	}

	strncpy(str_cpy, str, MAX_STR_LEN_PROC);

	dash = strstr(str_cpy, "-");

	if (dash == NULL) {
		set_errf("Missing '-' when parsing mask");
		return -2;
	}

	*dash = 0;

	if (parse_int(lo, str_cpy))
		return -1;
	if (parse_int(hi, dash + 1))
		return -1;


	int64_t tmp = strtol(str_cpy, 0, 0);
	if (tmp > UINT32_MAX) {
		set_errf("Integer is bigger than %u", UINT32_MAX);
		return -1;
	}
	if (tmp < 0) {
		set_errf("Integer is negative");
		return -2;
	}

	*lo = tmp;

	tmp = strtol(dash + 1, 0, 0);
	if (tmp > UINT32_MAX) {
		set_errf("Integer is bigger than %u", UINT32_MAX);
		return -1;
	}
	if (tmp < 0) {
		set_errf("Integer is negative");
		return -2;
	}

	*hi = tmp;

	if (*lo > *hi) {
		set_errf("Low boundary is above high boundary in range");
		return -2;
	}

	return 0;
}