All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/5] libselinux: add string<->value functions that use discovery
@ 2007-06-06 19:11 Christopher J. PeBenito
  2007-06-07  0:06 ` Eamon Walsh
  0 siblings, 1 reply; 5+ messages in thread
From: Christopher J. PeBenito @ 2007-06-06 19:11 UTC (permalink / raw)
  To: SELinux Mail List

Add new value->name, name->value functions that use object class discovery.

Signed-off-by: Chris PeBenito <cpebenito@tresys.com>

---
 libselinux/src/stringrep.c |   56 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

Index: selinux-obj-class-discovery/libselinux/src/stringrep.c
===================================================================
--- selinux-obj-class-discovery.orig/libselinux/src/stringrep.c
+++ selinux-obj-class-discovery/libselinux/src/stringrep.c
@@ -407,6 +407,62 @@ static const char *security_av_perm_to_s
 	return NULL;
 }
 
+security_class_t string_to_security_class(const char *s)
+{
+	struct discover_class_node *node;
+
+	node = get_class_cache_entry_name(s);
+	if (node == NULL) {
+		node = discover_class(s);
+
+		if (node == NULL)
+			return 0;
+	}
+
+	return node->value;
+}
+
+access_vector_t string_to_av_perm(security_class_t tclass, const char *s)
+{
+	struct discover_class_node *node;
+
+	node = get_class_cache_entry_value(tclass);
+	if (node != NULL) {
+		size_t i;
+		for (i=0; i<MAXVECTORS && node->perms[i] != NULL; i++)
+			if (strcmp(node->perms[i],s) == 0)
+				return (1<<i);
+	}
+
+	return 0;
+}
+
+const char *security_class_to_string(security_class_t tclass)
+{
+	struct discover_class_node *node;
+
+	node = get_class_cache_entry_value(tclass);
+	if (node == NULL)
+		return NULL;
+	else
+		return node->name;
+}
+
+const char *security_av_perm_to_string(security_class_t tclass,
+				       access_vector_t av)
+{
+	struct discover_class_node *node;
+	size_t i;
+
+	node = get_class_cache_entry_value(tclass);
+	if (av && node)
+		for (i = 0; i<MAXVECTORS; i++)
+			if ((1<<i) & av)
+				return node->perms[i];
+
+	return NULL;
+}
+
 int security_av_string(security_class_t tclass, access_vector_t av, char **res)
 {
 	unsigned int i = 0;


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH 3/5] libselinux: add string<->value functions that use discovery
@ 2007-06-07 13:40 Christopher J. PeBenito
  0 siblings, 0 replies; 5+ messages in thread
From: Christopher J. PeBenito @ 2007-06-07 13:40 UTC (permalink / raw)
  To: SELinux Mail List

Add new value->name, name->value functions that use object class discovery.

Signed-off-by: Chris PeBenito <cpebenito@tresys.com>

---
 libselinux/src/stringrep.c |   61 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

Index: selinux-obj-class-discovery/libselinux/src/stringrep.c
===================================================================
--- selinux-obj-class-discovery.orig/libselinux/src/stringrep.c
+++ selinux-obj-class-discovery/libselinux/src/stringrep.c
@@ -413,6 +413,67 @@ static const char *security_av_perm_to_s
 	return NULL;
 }
 
+security_class_t string_to_security_class(const char *s)
+{
+	struct discover_class_node *node;
+
+	node = get_class_cache_entry_name(s);
+	if (node == NULL) {
+		node = discover_class(s);
+
+		if (node == NULL) {
+			errno = EINVAL;
+			return 0;
+		}
+	}
+
+	return node->value;
+}
+
+access_vector_t string_to_av_perm(security_class_t tclass, const char *s)
+{
+	struct discover_class_node *node;
+
+	node = get_class_cache_entry_value(tclass);
+	if (node != NULL) {
+		size_t i;
+		for (i=0; i<MAXVECTORS && node->perms[i] != NULL; i++)
+			if (strcmp(node->perms[i],s) == 0)
+				return (1<<i);
+	}
+
+	errno = EINVAL;
+	return 0;
+}
+
+const char *security_class_to_string(security_class_t tclass)
+{
+	struct discover_class_node *node;
+
+	node = get_class_cache_entry_value(tclass);
+	if (node == NULL) {
+		errno = EINVAL;
+		return NULL;
+	} else
+		return node->name;
+}
+
+const char *security_av_perm_to_string(security_class_t tclass,
+				       access_vector_t av)
+{
+	struct discover_class_node *node;
+	size_t i;
+
+	node = get_class_cache_entry_value(tclass);
+	if (av && node)
+		for (i = 0; i<MAXVECTORS; i++)
+			if ((1<<i) & av)
+				return node->perms[i];
+
+	errno = EINVAL;
+	return NULL;
+}
+
 int security_av_string(security_class_t tclass, access_vector_t av, char **res)
 {
 	unsigned int i = 0;


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-06-07 13:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-06 19:11 [PATCH 3/5] libselinux: add string<->value functions that use discovery Christopher J. PeBenito
2007-06-07  0:06 ` Eamon Walsh
2007-06-07 12:19   ` Christopher J. PeBenito
2007-06-07 12:20     ` Christopher J. PeBenito
  -- strict thread matches above, loose matches on Subject: below --
2007-06-07 13:40 Christopher J. PeBenito

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.