Skip to contentSkip to conversation

Export selinux_string_to_sid from SELinux (fwd)

RFC New James Morris 1 participant 1 message May 7, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC 2/8 Export selinux_string_to_sid from SELinux (fwd)

---------- Forwarded message ----------
Date: Sun, 7 May 2006 11:34:17 -0400 (EDT)
From: James Morris <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
Stephen Smalley <[email protected]>, Daniel J Walsh <[email protected]>
Subject: [RFC][SECMARK 02/08] Export selinux_string_to_sid from SELinux

This patch exports adds a new function to the in-kernel SELinux API: selinux_string_to_sid(). It maps a text security context to an SELiux security ID (SID).

---

 include/linux/selinux.h    |   16 ++++++++++++++++
 security/selinux/exports.c |   11 +++++++++++
 2 files changed, 27 insertions(+)
include/linux/selinux.h +16 -0
diff -purN -X dontdiff linux-2.6.17-rc2-mm1.p/include/linux/selinux.h linux-2.6.17-rc2-mm1.w/include/linux/selinux.h
@@ -118,6 +118,16 @@ void selinux_get_ipc_sid(const struct ke
  */
 void selinux_get_task_sid(struct task_struct *tsk, u32 *sid);
 
+/**
+ *     selinux_string_to_sid - map a security context string to a security ID
+ *     @str: the security context string to be mapped
+ *     @sid: ID value returned via this.
+ *
+ *     Returns 0 if successful, with the SID stored in sid.  A value
+ *     of zero for sid indicates no SID could be determined (but no error
+ *     occurred).
+ */
+int selinux_string_to_sid(char *str, u32 *sid);
 
 #else
 
@@ -172,6 +182,12 @@ static inline void selinux_get_task_sid(
 	*sid = 0;
 }
 
+static inline int selinux_string_to_sid(const char *str, u32 *sid)
+{
+       *sid = 0;
+       return 0;
+}
+
 #endif	/* CONFIG_SECURITY_SELINUX */
 
 #endif /* _LINUX_SELINUX_H */
security/selinux/exports.c +11 -0
diff -purN -X dontdiff linux-2.6.17-rc2-mm1.p/security/selinux/exports.c linux-2.6.17-rc2-mm1.w/security/selinux/exports.c
@@ -72,3 +72,14 @@ void selinux_get_task_sid(struct task_st
 	*sid = 0;
 }
 
+int selinux_string_to_sid(char *str, u32 *sid)
+{
+	if (selinux_enabled)
+		return security_context_to_sid(str, strlen(str), sid);
+	else {
+		*sid = 0;
+		return 0;
+	}
+}
+EXPORT_SYMBOL_GPL(selinux_string_to_sid);
+