Blame SOURCES/0008-Add-alias-support-to-seinfo-t.patch

4ea9f2
From 1136e61a9839ad3b60eb2da4d624413c02545c7d Mon Sep 17 00:00:00 2001
4ea9f2
From: Miroslav Grepl <mgrepl@redhat.com>
4ea9f2
Date: Fri, 11 Apr 2014 18:42:27 +0200
4ea9f2
Subject: [PATCH 08/11] Add alias support to seinfo -t
4ea9f2
4ea9f2
---
4ea9f2
 secmds/seinfo.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
4ea9f2
 1 file changed, 48 insertions(+)
4ea9f2
4ea9f2
diff --git a/secmds/seinfo.c b/secmds/seinfo.c
4ea9f2
index 54b2a6a..1878c49 100644
4ea9f2
--- a/secmds/seinfo.c
4ea9f2
+++ b/secmds/seinfo.c
4ea9f2
@@ -46,6 +46,7 @@
4ea9f2
 #include <string.h>
4ea9f2
 #include <assert.h>
4ea9f2
 #include <getopt.h>
4ea9f2
+#include <selinux/selinux.h>
4ea9f2
 
4ea9f2
 #define COPYRIGHT_INFO "Copyright (C) 2003-2007 Tresys Technology, LLC"
4ea9f2
 
4ea9f2
@@ -54,6 +55,7 @@
4ea9f2
 
4ea9f2
 static char *policy_file = NULL;
4ea9f2
 
4ea9f2
+static void print_type_aliases(FILE * fp, const qpol_type_t * type_datum, const apol_policy_t * policydb);
4ea9f2
 static int print_type_attrs(FILE * fp, const qpol_type_t * type_datum, const apol_policy_t * policydb, const int expand);
4ea9f2
 static int print_attr_types(FILE * fp, const qpol_type_t * type_datum, const apol_policy_t * policydb, const int expand);
4ea9f2
 static int print_user_roles(FILE * fp, const qpol_user_t * user_datum, const apol_policy_t * policydb, const int expand);
4ea9f2
@@ -514,6 +516,7 @@ static int print_types(FILE * fp, const char *name, int expand, const apol_polic
4ea9f2
 			goto cleanup;
4ea9f2
 		if (print_type_attrs(fp, type_datum, policydb, expand))
4ea9f2
 			goto cleanup;
4ea9f2
+        print_type_aliases(fp, type_datum, policydb);
4ea9f2
 	} else {
4ea9f2
 		if (qpol_policy_get_type_iter(q, &iter))
4ea9f2
 			goto cleanup;
4ea9f2
@@ -1912,6 +1915,51 @@ int main(int argc, char **argv)
4ea9f2
 }
4ea9f2
 
4ea9f2
 /**
4ea9f2
+ * Prints the alias of a type.
4ea9f2
+ *
4ea9f2
+ * @param fp Reference to a file to which to print type information
4ea9f2
+ * @param type_datum Reference to sepol type_datum
4ea9f2
+ * @param policydb Reference to a policy
4ea9f2
+ * attributes
4ea9f2
+ */
4ea9f2
+static void print_type_aliases(FILE * fp, const qpol_type_t * type_datum, const apol_policy_t * policydb)
4ea9f2
+{
4ea9f2
+	qpol_iterator_t *iter = NULL;
4ea9f2
+	size_t alias_size;
4ea9f2
+	unsigned char isattr, isalias;
4ea9f2
+	const char *type_name = NULL;
4ea9f2
+	const char *alias_name;
4ea9f2
+	qpol_policy_t *q = apol_policy_get_qpol(policydb);
4ea9f2
+
4ea9f2
+	if (qpol_type_get_name(q, type_datum, &type_name))
4ea9f2
+		goto cleanup;
4ea9f2
+	if (qpol_type_get_isattr(q, type_datum, &isattr))
4ea9f2
+		goto cleanup;
4ea9f2
+	if (qpol_type_get_isalias(q, type_datum, &isalias))
4ea9f2
+		goto cleanup;
4ea9f2
+
4ea9f2
+	if (isalias) {
4ea9f2
+		fprintf(fp, "   TypeName %s\n", type_name);
4ea9f2
+	}
4ea9f2
+	if (qpol_type_get_alias_iter(q, type_datum, &iter))
4ea9f2
+		goto cleanup;
4ea9f2
+	if (qpol_iterator_get_size(iter, &alias_size))
4ea9f2
+		goto cleanup;
4ea9f2
+	if (alias_size >  0) {
4ea9f2
+		fprintf(fp, "   Aliases\n");
4ea9f2
+		for (; !qpol_iterator_end(iter); qpol_iterator_next(iter)) {
4ea9f2
+			if (qpol_iterator_get_item(iter, (void **)&alias_name))
4ea9f2
+				goto cleanup;
4ea9f2
+			fprintf(fp, "      %s\n", alias_name);
4ea9f2
+		}
4ea9f2
+	}
4ea9f2
+
4ea9f2
+      cleanup:
4ea9f2
+	qpol_iterator_destroy(&iter);
4ea9f2
+	return;
4ea9f2
+}
4ea9f2
+
4ea9f2
+/**
4ea9f2
  * Prints a textual representation of a type, and possibly
4ea9f2
  * all of that type's attributes.
4ea9f2
  *
4ea9f2
-- 
4ea9f2
1.8.5.3
4ea9f2