FreeBSD/sys/security/mac_portacl/mac_portacl.c
/*
 * Note: parsing routines are destructive on the passed string.
 */
parsing routines are destructive on the passed string.
parsing routines are destructive on the passed string .
static int
parse_rule_element(char *element, struct rule **rule)
{
	char *idtype, *id, *protocol, *portnumber, *p;
	struct rule *new;
	int error;
	error = 0;
	new = malloc(sizeof(*new), M_PORTACL, M_ZERO | M_WAITOK);
	idtype = strsep(&element, ":");
	if (idtype == NULL) {
		error = EINVAL;
		goto out;
	}
	id = strsep(&element, ":");
	if (id == NULL) {
		error = EINVAL;
		goto out;
	}
	new->r_id = strtol(id, &p, 10);
	if (*p != '\0') {
		error = EINVAL;
		goto out;
	}
	if (strcmp(idtype, UID_STRING) == 0)
		new->r_idtype = RULE_UID;
	else if (strcmp(idtype, GID_STRING) == 0)
		new->r_idtype = RULE_GID;
	else {
		error = EINVAL;
		goto out;
	}
	protocol = strsep(&element, ":");
	if (protocol == NULL) {
		error = EINVAL;
		goto out;
	}
	if (strcmp(protocol, TCP_STRING) == 0)
		new->r_protocol = RULE_PROTO_TCP;
	else if (strcmp(protocol, UDP_STRING) == 0)
		new->r_protocol = RULE_PROTO_UDP;
	else {
		error = EINVAL;
		goto out;
	}
	portnumber = element;
	if (portnumber == NULL) {
		error = EINVAL;
		goto out;
	}
	new->r_port = strtol(portnumber, &p, 10);
	if (*p != '\0') {
		error = EINVAL;
		goto out;
	}
out:
	if (error != 0) {
		free(new, M_PORTACL);
		*rule = NULL;
	} else
		*rule = new;
	return (error);
}
static int parse_rule_element ( char * element , struct rule * * rule ) { char * idtype , * id , * protocol , * portnumber , * p ; struct rule * new ; int error ; error = 0 ; new = malloc ( sizeof ( * new ) , M_PORTACL , M_ZERO | M_WAITOK ) ; idtype = strsep ( & element , " " ) ; if ( idtype == NULL ) { error = EINVAL ; goto out ; } id = strsep ( & element , " " ) ; if ( id == NULL ) { error = EINVAL ; goto out ; } new -> r_id = strtol ( id , & p , 10 ) ; if ( * p != ' \0 ' ) { error = EINVAL ; goto out ; } if ( strcmp ( idtype , UID_STRING ) == 0 ) new -> r_idtype = RULE_UID ; else if ( strcmp ( idtype , GID_STRING ) == 0 ) new -> r_idtype = RULE_GID ; else { error = EINVAL ; goto out ; } protocol = strsep ( & element , " " ) ; if ( protocol == NULL ) { error = EINVAL ; goto out ; } if ( strcmp ( protocol , TCP_STRING ) == 0 ) new -> r_protocol = RULE_PROTO_TCP ; else if ( strcmp ( protocol , UDP_STRING ) == 0 ) new -> r_protocol = RULE_PROTO_UDP ; else { error = EINVAL ; goto out ; } portnumber = element ; if ( portnumber == NULL ) { error = EINVAL ; goto out ; } new -> r_port = strtol ( portnumber , & p , 10 ) ; if ( * p != ' \0 ' ) { error = EINVAL ; goto out ; } out : if ( error != 0 ) { free ( new , M_PORTACL ) ; * rule = NULL ; } else * rule = new ; return ( error ) ; }
Note: parsing routines are destructive on the passed string.
Note : parsing routines are destructive on the passed string .