[apparmor] [patch 03/12] provide a mapping of sock type and name and a fn to look access the mapping

Steve Beattie steve at nxnw.org
Tue Aug 19 07:55:11 UTC 2014


On Fri, Aug 15, 2014 at 12:20:38PM -0700, john.johansen at canonical.com wrote:
> Signed-off-by: John Johansen <john.johansen at canonical.com>
> Acked-by: Seth Arnold <seth.arnold at canonical.com>

Acked-by: Steve Beattie <steve at nxnw.org>

> ---
>  parser/network.c |   54 +++++++++++++++++++++++++++++++++++++++++-------------
>  parser/network.h |    3 +++
>  2 files changed, 44 insertions(+), 13 deletions(-)
> 
> --- 2.9-test.orig/parser/network.c
> +++ 2.9-test/parser/network.c
> @@ -35,23 +35,51 @@
>   * have to make sure these are in order.  This means we are more brittle
>   * but there isn't much we can do.
>   */
> -const char *sock_types[] = {
> -	"none",		/* 0 */
> -	"stream",	/* 1 [SOCK_STREAM] */
> -	"dgram",	/* 2 [SOCK_DGRAM] */
> -	"raw",		/* 3 [SOCK_RAW] */
> -	"rdm",		/* 4 [SOCK_RDM] */
> -	"seqpacket",	/* 5 [SOCK_SEQPACKET] */
> -	"dccp",		/* 6 [SOCK_DCCP] */
> -	"invalid",	/* 7 */
> -	"invalid",	/* 8 */
> -	"invalid",	/* 9 */
> -	"packet",	/* 10 [SOCK_PACKET] */
> +struct sock_type_map {
> +	const char *name;
> +	int	value;
> +};
> +
> +struct sock_type_map sock_types[] = {
> +	{ "none",	0 },
> +	{ "stream",	SOCK_STREAM },
> +	{ "dgram",	SOCK_DGRAM },
> +	{ "raw",	SOCK_RAW },
> +	{ "rdm",	SOCK_RDM },
> +	{ "seqpacket",	SOCK_SEQPACKET },
> +	{ "dccp",	SOCK_DCCP },
> +	{ "invalid",	-1 },
> +	{ "invalid",	-1 },
> +	{ "invalid",	-1 },
> +	{ "packet",	SOCK_PACKET },
> +	{ NULL, -1 },
>  	/*
>  	 * See comment above
>  	*/
>  };
>  
> +int net_find_type_val(const char *type)
> +{
> +	int i;
> +	for (i = 0; sock_types[i].name; i++) {
> +		if (strcmp(sock_types[i].name, type) == 0)
> +			return sock_types[i].value;
> +	}
> +
> +	return -1;
> +}
> +
> +const char *net_find_type_name(int type)
> +{
> +	int i;
> +	for (i = 0; sock_types[i].name; i++) {
> +		if (sock_types[i].value  == type)
> +			return sock_types[i].name;
> +	}
> +
> +	return NULL;
> +}
> +
>  struct network_tuple {
>  	const char *family_name;
>  	unsigned int family;
> @@ -319,7 +347,7 @@
>  			for (j = 0; j < count; j++) {
>  				const char *type;
>  				if (array[i] & (1 << j)) {
> -					type = sock_types[j];
> +					type = sock_types[j].name;
>  					if (type)
>  						printf("%s ", type);
>  					else
> --- 2.9-test.orig/parser/network.h
> +++ 2.9-test/parser/network.h
> @@ -75,4 +75,7 @@
>  	}
>  };
>  
> +int net_find_type_val(const char *type);
> +const char *net_find_type_name(int type);
> +
>  #endif /* __AA_NETWORK_H */
> 
> 
> -- 
> AppArmor mailing list
> AppArmor at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor

-- 
Steve Beattie
<sbeattie at ubuntu.com>
http://NxNW.org/~steve/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20140819/fcb2edc5/attachment.pgp>


More information about the AppArmor mailing list