Blame SOURCES/0006-Changes-to-support-named-file_trans-rules.patch

25bb7d
From 287f507657e162bc09b5c186bbd580901fbc942a Mon Sep 17 00:00:00 2001
25bb7d
From: Dan Walsh <dwalsh@redhat.com>
25bb7d
Date: Tue, 20 Sep 2011 15:47:28 -0400
25bb7d
Subject: [PATCH 6/6] Changes to support named file_trans rules
25bb7d
25bb7d
---
25bb7d
 libapol/include/apol/ftrule-query.h |  198 +++++++++++++++++++
25bb7d
 libapol/include/apol/policy-query.h |    1 +
25bb7d
 libapol/src/Makefile.am             |    1 +
25bb7d
 libapol/src/ftrule-query.c          |  363 +++++++++++++++++++++++++++++++++++
25bb7d
 libapol/src/libapol.map             |    1 +
25bb7d
 libqpol/include/qpol/ftrule_query.h |  116 +++++++++++
25bb7d
 libqpol/include/qpol/policy.h       |    1 +
25bb7d
 libqpol/src/Makefile.am             |    1 +
25bb7d
 libqpol/src/ftrule_query.c          |  277 ++++++++++++++++++++++++++
25bb7d
 libqpol/src/libqpol.map             |    1 +
25bb7d
 libqpol/src/module_compiler.c       |   12 ++
25bb7d
 libqpol/src/policy_define.c         |  186 ++++++++++++++++++-
25bb7d
 libqpol/src/policy_parse.y          |   13 +-
25bb7d
 libqpol/src/policy_scan.l           |    1 +
25bb7d
 secmds/sesearch.c                   |  101 ++++++++++
25bb7d
 15 files changed, 1270 insertions(+), 3 deletions(-)
25bb7d
 create mode 100644 libapol/include/apol/ftrule-query.h
25bb7d
 create mode 100644 libapol/src/ftrule-query.c
25bb7d
 create mode 100644 libqpol/include/qpol/ftrule_query.h
25bb7d
 create mode 100644 libqpol/src/ftrule_query.c
25bb7d
25bb7d
diff --git a/libapol/include/apol/ftrule-query.h b/libapol/include/apol/ftrule-query.h
25bb7d
new file mode 100644
25bb7d
index 0000000..119c52f
25bb7d
--- /dev/null
25bb7d
+++ b/libapol/include/apol/ftrule-query.h
25bb7d
@@ -0,0 +1,198 @@
25bb7d
+/**
25bb7d
+ * @file
25bb7d
+ *
25bb7d
+ * Routines to query filename_transition rules of a
25bb7d
+ * policy.  
25bb7d
+ *
25bb7d
+ * @author Jeremy A. Mowery jmowery@tresys.com
25bb7d
+ * @author Jason Tang  jtang@tresys.com
25bb7d
+ *
25bb7d
+ * Copyright (C) 2006-2007 Tresys Technology, LLC
25bb7d
+ *
25bb7d
+ *  This library is free software; you can redistribute it and/or
25bb7d
+ *  modify it under the terms of the GNU Lesser General Public
25bb7d
+ *  License as published by the Free Software Foundation; either
25bb7d
+ *  version 2.1 of the License, or (at your option) any later version.
25bb7d
+ *
25bb7d
+ *  This library is distributed in the hope that it will be useful,
25bb7d
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25bb7d
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25bb7d
+ *  Lesser General Public License for more details.
25bb7d
+ *
25bb7d
+ *  You should have received a copy of the GNU Lesser General Public
25bb7d
+ *  License along with this library; if not, write to the Free Software
25bb7d
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25bb7d
+ */
25bb7d
+
25bb7d
+#ifndef APOL_FILENAMERULE_QUERY_H
25bb7d
+#define APOL_FILENAMERULE_QUERY_H
25bb7d
+
25bb7d
+#ifdef	__cplusplus
25bb7d
+extern "C"
25bb7d
+{
25bb7d
+#endif
25bb7d
+
25bb7d
+#include "policy.h"
25bb7d
+#include "vector.h"
25bb7d
+#include <qpol/policy.h>
25bb7d
+
25bb7d
+	typedef struct apol_filename_trans_query apol_filename_trans_query_t;
25bb7d
+
25bb7d
+
25bb7d
+/******************** filename_transition queries ********************/
25bb7d
+
25bb7d
+/**
25bb7d
+ * Execute a query against all filename_transition rules within the
25bb7d
+ * policy.
25bb7d
+ *
25bb7d
+ * @param p Policy within which to look up filename_transition rules.
25bb7d
+ * @param r Structure containing parameters for query.	If this is
25bb7d
+ * NULL then return all filename_transition rules.
25bb7d
+ * @param v Reference to a vector of qpol_filename_trans_t.  The vector
25bb7d
+ * will be allocated by this function.  The caller must call
25bb7d
+ * apol_vector_destroy() afterwards.  This will be set to NULL upon no
25bb7d
+ * results or upon error.
25bb7d
+ *
25bb7d
+ * @return 0 on success (including none found), negative on error.
25bb7d
+ */
25bb7d
+	extern int apol_filename_trans_get_by_query(const apol_policy_t * p, const apol_filename_trans_query_t * r, apol_vector_t ** v);
25bb7d
+
25bb7d
+/**
25bb7d
+ * Allocate and return a new filename trans query structure.  All fields
25bb7d
+ * are initialized, such that running this blank query results in
25bb7d
+ * returning all filename_transitions within the policy.  The caller must
25bb7d
+ * call apol_filename_trans_query_destroy() upon the return value
25bb7d
+ * afterwards.
25bb7d
+ *
25bb7d
+ * @return An initialized filename trans query structure, or NULL upon
25bb7d
+ * error.
25bb7d
+ */
25bb7d
+	extern apol_filename_trans_query_t *apol_filename_trans_query_create(void);
25bb7d
+
25bb7d
+/**
25bb7d
+ * Deallocate all memory associated with the referenced filename trans
25bb7d
+ * query, and then set it to NULL.  This function does nothing if the
25bb7d
+ * query is already NULL.
25bb7d
+ *
25bb7d
+ * @param r Reference to a filename trans query structure to destroy.
25bb7d
+ */
25bb7d
+	extern void apol_filename_trans_query_destroy(apol_filename_trans_query_t ** r);
25bb7d
+
25bb7d
+/**
25bb7d
+ * Set a filename_trans query to return rules whose source symbol matches
25bb7d
+ * symbol.  Symbol may be a type or attribute; if it is an alias then
25bb7d
+ * the query will convert it to its primary prior to searching.  If
25bb7d
+ * is_indirect is non-zero then the search will be done indirectly.
25bb7d
+ * If the symbol is a type, then the query matches rules with one of
25bb7d
+ * the type's attributes.  If the symbol is an attribute, then it
25bb7d
+ * matches rule with any of the attribute's types.
25bb7d
+ *
25bb7d
+ * @param p Policy handler, to report errors.
25bb7d
+ * @param t TE rule query to set.
25bb7d
+ * @param symbol Limit query to rules with this symbol as their
25bb7d
+ * source, or NULL to unset this field.
25bb7d
+ * @param is_indirect If non-zero, perform indirect matching.
25bb7d
+ *
25bb7d
+ * @return 0 on success, negative on error.
25bb7d
+ */
25bb7d
+	extern int apol_filename_trans_query_set_source(const apol_policy_t * p, apol_filename_trans_query_t * t, const char *symbol,
25bb7d
+						int is_indirect);
25bb7d
+
25bb7d
+/**
25bb7d
+ * Set a filename trans query to return rules with a particular target
25bb7d
+ * symbol.  Symbol may be a type or attribute; if it is an alias then
25bb7d
+ * the query will convert it to its primary prior to searching.  If
25bb7d
+ * is_indirect is non-zero then the search will be done indirectly.
25bb7d
+ * If the symbol is a type, then the query matches rules with one of
25bb7d
+ * the type's attributes.  If the symbol is an attribute, then it
25bb7d
+ * matches rule with any of the attribute's types.
25bb7d
+ *
25bb7d
+ * @param p Policy handler, to report errors.
25bb7d
+ * @param r Role trans query to set.
25bb7d
+ * @param symbol Limit query to rules with this type or attribute as
25bb7d
+ * their target, or NULL to unset this field.
25bb7d
+ * @param is_indirect If non-zero, perform indirect matching.
25bb7d
+ *
25bb7d
+ * @return 0 on success, negative on error.
25bb7d
+ */
25bb7d
+	extern int apol_filename_trans_query_set_target(const apol_policy_t * p, apol_filename_trans_query_t * r, const char *symbol,
25bb7d
+						    int is_indirect);
25bb7d
+
25bb7d
+/**
25bb7d
+ * Set a filename trans query to return rules with a particular default
25bb7d
+ * filename.  This field is ignored if
25bb7d
+ * apol_filename_trans_query_set_source_any() is set to non-zero.
25bb7d
+ *
25bb7d
+ * @param p Policy handler, to report errors.
25bb7d
+ * @param r Role trans query to set.
25bb7d
+ * @param filename Limit query to rules with this filename as their default, or
25bb7d
+ * NULL to unset this field.
25bb7d
+ *
25bb7d
+ * @return 0 on success, negative on error.
25bb7d
+ */
25bb7d
+	extern int apol_filename_trans_query_set_default(const apol_policy_t * p, apol_filename_trans_query_t * r, const char *filename);
25bb7d
+
25bb7d
+/**
25bb7d
+ * Set at filename_trans query to return rules with this object (non-common)
25bb7d
+ * class.  If more than one class are appended to the query, the
25bb7d
+ * rule's class must be one of those appended.  (I.e., the rule's
25bb7d
+ * class must be a member of the query's classes.)  Pass a NULL to
25bb7d
+ * clear all classes.  Note that this performs straight string
25bb7d
+ * comparison, ignoring the regex flag.
25bb7d
+
25bb7d
+ *
25bb7d
+ * @param p Policy handler, to report errors.
25bb7d
+ * @param t TE rule query to set.
25bb7d
+ * @param obj_class Name of object class to add to search set.
25bb7d
+ *
25bb7d
+ * @return 0 on success, negative on error.
25bb7d
+ */
25bb7d
+	extern int apol_filename_trans_query_append_class(const apol_policy_t * p, apol_filename_trans_query_t * t, const char *obj_class);
25bb7d
+
25bb7d
+/**
25bb7d
+ * Set a filename trans query to treat the source filename as any.  That is,
25bb7d
+ * use the same symbol for either source or default of a
25bb7d
+ * filename_transition rule.  This flag does nothing if the source filename is
25bb7d
+ * not set.  Note that a filename_transition's target is a type, so thus
25bb7d
+ * this flag does not affect its searching.
25bb7d
+ *
25bb7d
+ * @param p Policy handler, to report errors.
25bb7d
+ * @param r Role trans query to set.
25bb7d
+ * @param is_any Non-zero to use source symbol for source or default
25bb7d
+ * field, 0 to keep source as only source.
25bb7d
+ *
25bb7d
+ * @return Always 0.
25bb7d
+ */
25bb7d
+	extern int apol_filename_trans_query_set_source_any(const apol_policy_t * p, apol_filename_trans_query_t * r, int is_any);
25bb7d
+
25bb7d
+/**
25bb7d
+ * Set a filename trans query to use regular expression searching for
25bb7d
+ * source, target, and default fields.  Strings will be treated as
25bb7d
+ * regexes instead of literals.  For the target type, matching will
25bb7d
+ * occur against the type name or any of its aliases.
25bb7d
+ *
25bb7d
+ * @param p Policy handler, to report errors.
25bb7d
+ * @param r Role trans query to set.
25bb7d
+ * @param is_regex Non-zero to enable regex searching, 0 to disable.
25bb7d
+ *
25bb7d
+ * @return Always 0.
25bb7d
+ */
25bb7d
+	extern int apol_filename_trans_query_set_regex(const apol_policy_t * p, apol_filename_trans_query_t * r, int is_regex);
25bb7d
+
25bb7d
+/**
25bb7d
+ *  Render a filename_transition rule to a string.
25bb7d
+ *
25bb7d
+ *  @param policy Policy handler, to report errors.
25bb7d
+ *  @param rule The rule to render.
25bb7d
+ *
25bb7d
+ *  @return A newly malloc()'d string representation of the rule, or NULL on
25bb7d
+ *  failure; if the call fails, errno will be set. The caller is responsible
25bb7d
+ *  for calling free() on the returned string.
25bb7d
+ */
25bb7d
+	extern char *apol_filename_trans_render(const apol_policy_t * policy, const qpol_filename_trans_t * rule);
25bb7d
+
25bb7d
+#ifdef	__cplusplus
25bb7d
+}
25bb7d
+#endif
25bb7d
+
25bb7d
+#endif
25bb7d
diff --git a/libapol/include/apol/policy-query.h b/libapol/include/apol/policy-query.h
25bb7d
index 315f70e..665e4cb 100644
25bb7d
--- a/libapol/include/apol/policy-query.h
25bb7d
+++ b/libapol/include/apol/policy-query.h
25bb7d
@@ -71,6 +71,7 @@ extern "C"
25bb7d
 #include "terule-query.h"
25bb7d
 #include "condrule-query.h"
25bb7d
 #include "rbacrule-query.h"
25bb7d
+#include "ftrule-query.h"
25bb7d
 #include "range_trans-query.h"
25bb7d
 #include "constraint-query.h"
25bb7d
 
25bb7d
diff --git a/libapol/src/Makefile.am b/libapol/src/Makefile.am
25bb7d
index 3fa4f06..baaa4f6 100644
25bb7d
--- a/libapol/src/Makefile.am
25bb7d
+++ b/libapol/src/Makefile.am
25bb7d
@@ -40,6 +40,7 @@ libapol_a_SOURCES = \
25bb7d
 	render.c \
25bb7d
 	role-query.c \
25bb7d
 	terule-query.c \
25bb7d
+	ftrule-query.c \
25bb7d
 	type-query.c \
25bb7d
 	types-relation-analysis.c \
25bb7d
 	user-query.c \
25bb7d
diff --git a/libapol/src/ftrule-query.c b/libapol/src/ftrule-query.c
25bb7d
new file mode 100644
25bb7d
index 0000000..dc248de
25bb7d
--- /dev/null
25bb7d
+++ b/libapol/src/ftrule-query.c
25bb7d
@@ -0,0 +1,363 @@
25bb7d
+/**
25bb7d
+ * @file
25bb7d
+ *
25bb7d
+ * Provides a way for setools to make queries about type enforcement
25bb7d
+ * filename_transs within a policy.  The caller obtains a query object, fills in
25bb7d
+ * its parameters, and then runs the query; it obtains a vector of
25bb7d
+ * results.  Searches are conjunctive -- all fields of the search
25bb7d
+ * query must match for a datum to be added to the results query.
25bb7d
+ *
25bb7d
+ * @author Jeremy A. Mowery jmowery@tresys.com
25bb7d
+ * @author Jason Tang  jtang@tresys.com
25bb7d
+ *
25bb7d
+ * Copyright (C) 2006-2007 Tresys Technology, LLC
25bb7d
+ *
25bb7d
+ *  This library is free software; you can redistribute it and/or
25bb7d
+ *  modify it under the terms of the GNU Lesser General Public
25bb7d
+ *  License as published by the Free Software Foundation; either
25bb7d
+ *  version 2.1 of the License, or (at your option) any later version.
25bb7d
+ *
25bb7d
+ *  This library is distributed in the hope that it will be useful,
25bb7d
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25bb7d
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25bb7d
+ *  Lesser General Public License for more details.
25bb7d
+ *
25bb7d
+ *  You should have received a copy of the GNU Lesser General Public
25bb7d
+ *  License along with this library; if not, write to the Free Software
25bb7d
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25bb7d
+ */
25bb7d
+
25bb7d
+#include "policy-query-internal.h"
25bb7d
+
25bb7d
+#include <errno.h>
25bb7d
+#include <string.h>
25bb7d
+
25bb7d
+struct apol_filename_trans_query
25bb7d
+{
25bb7d
+	char *source, *target, *default_type, *name;
25bb7d
+	apol_vector_t *classes;
25bb7d
+	unsigned int flags;
25bb7d
+};
25bb7d
+
25bb7d
+
25bb7d
+/******************** filename_transition queries ********************/
25bb7d
+
25bb7d
+int apol_filename_trans_get_by_query(const apol_policy_t * p, const apol_filename_trans_query_t * t, apol_vector_t ** v)
25bb7d
+{
25bb7d
+	apol_vector_t *source_list = NULL, *target_list = NULL, *class_list = NULL, *default_list = NULL;
25bb7d
+	int retval = -1, source_as_any = 0, is_regex = 0, append_filename_trans;
25bb7d
+	char *bool_name = NULL;
25bb7d
+	*v = NULL;
25bb7d
+	unsigned int flags = 0;
25bb7d
+	qpol_iterator_t *iter = NULL, *type_iter = NULL;
25bb7d
+
25bb7d
+	if (t != NULL) {
25bb7d
+		flags = t->flags;
25bb7d
+		is_regex = t->flags & APOL_QUERY_REGEX;
25bb7d
+		if (t->source != NULL &&
25bb7d
+		    (source_list =
25bb7d
+		     apol_query_create_candidate_type_list(p, t->source, is_regex,
25bb7d
+							   t->flags & APOL_QUERY_SOURCE_INDIRECT,
25bb7d
+							   ((t->flags & (APOL_QUERY_SOURCE_TYPE | APOL_QUERY_SOURCE_ATTRIBUTE)) /
25bb7d
+							    APOL_QUERY_SOURCE_TYPE))) == NULL) {
25bb7d
+			goto cleanup;
25bb7d
+		}
25bb7d
+
25bb7d
+		if ((t->flags & APOL_QUERY_SOURCE_AS_ANY) && t->source != NULL) {
25bb7d
+			default_list = target_list = source_list;
25bb7d
+			source_as_any = 1;
25bb7d
+		} else {
25bb7d
+			if (t->target != NULL &&
25bb7d
+			    (target_list =
25bb7d
+			     apol_query_create_candidate_type_list(p, t->target, is_regex,
25bb7d
+								   t->flags & APOL_QUERY_TARGET_INDIRECT,
25bb7d
+								   ((t->
25bb7d
+								     flags & (APOL_QUERY_TARGET_TYPE | APOL_QUERY_TARGET_ATTRIBUTE))
25bb7d
+								    / APOL_QUERY_TARGET_TYPE))) == NULL) {
25bb7d
+				goto cleanup;
25bb7d
+			}
25bb7d
+			if (t->default_type != NULL &&
25bb7d
+			    (default_list =
25bb7d
+			     apol_query_create_candidate_type_list(p, t->default_type, is_regex, 0,
25bb7d
+								   APOL_QUERY_SYMBOL_IS_TYPE)) == NULL) {
25bb7d
+				goto cleanup;
25bb7d
+			}
25bb7d
+		}
25bb7d
+		if (t->classes != NULL &&
25bb7d
+		    apol_vector_get_size(t->classes) > 0 &&
25bb7d
+		    (class_list = apol_query_create_candidate_class_list(p, t->classes)) == NULL) {
25bb7d
+			goto cleanup;
25bb7d
+		}
25bb7d
+	}
25bb7d
+
25bb7d
+	if (qpol_policy_get_filename_trans_iter(p->p, &iter) < 0) {
25bb7d
+		return -1;
25bb7d
+	}
25bb7d
+
25bb7d
+	if ((*v = apol_vector_create(NULL)) == NULL) {
25bb7d
+		ERR(p, "%s", strerror(errno));
25bb7d
+		goto cleanup;
25bb7d
+	}
25bb7d
+
25bb7d
+	for (; !qpol_iterator_end(iter); qpol_iterator_next(iter)) {
25bb7d
+		qpol_filename_trans_t *filename_trans;
25bb7d
+		if (qpol_iterator_get_item(iter, (void **)&filename_trans) < 0) {
25bb7d
+			goto cleanup;
25bb7d
+		}
25bb7d
+		int match_source = 0, match_target = 0, match_default = 0, match_bool = 0;
25bb7d
+		size_t i;
25bb7d
+
25bb7d
+		if (source_list == NULL) {
25bb7d
+			match_source = 1;
25bb7d
+		} else {
25bb7d
+			const qpol_type_t *source_type;
25bb7d
+			if (qpol_filename_trans_get_source_type(p->p, filename_trans, &source_type) < 0) {
25bb7d
+				goto cleanup;
25bb7d
+			}
25bb7d
+			if (apol_vector_get_index(source_list, source_type, NULL, NULL, &i) == 0) {
25bb7d
+				match_source = 1;
25bb7d
+			}
25bb7d
+		}
25bb7d
+
25bb7d
+		/* if source did not match, but treating source symbol
25bb7d
+		 * as any field, then delay rejecting this filename_trans until
25bb7d
+		 * the target and default have been checked */
25bb7d
+		if (!source_as_any && !match_source) {
25bb7d
+			continue;
25bb7d
+		}
25bb7d
+
25bb7d
+		if (target_list == NULL || (source_as_any && match_source)) {
25bb7d
+			match_target = 1;
25bb7d
+		} else {
25bb7d
+			const qpol_type_t *target_type;
25bb7d
+			if (qpol_filename_trans_get_target_type(p->p, filename_trans, &target_type) < 0) {
25bb7d
+				goto cleanup;
25bb7d
+			}
25bb7d
+			if (apol_vector_get_index(target_list, target_type, NULL, NULL, &i) == 0) {
25bb7d
+				match_target = 1;
25bb7d
+			}
25bb7d
+		}
25bb7d
+
25bb7d
+		if (!source_as_any && !match_target) {
25bb7d
+			continue;
25bb7d
+		}
25bb7d
+
25bb7d
+		if (default_list == NULL || (source_as_any && match_source) || (source_as_any && match_target)) {
25bb7d
+			match_default = 1;
25bb7d
+		} else {
25bb7d
+			const qpol_type_t *default_type;
25bb7d
+			if (qpol_filename_trans_get_default_type(p->p, filename_trans, &default_type) < 0) {
25bb7d
+				goto cleanup;
25bb7d
+			}
25bb7d
+			if (apol_vector_get_index(default_list, default_type, NULL, NULL, &i) == 0) {
25bb7d
+				match_default = 1;
25bb7d
+			}
25bb7d
+		}
25bb7d
+
25bb7d
+		if (!source_as_any && !match_default) {
25bb7d
+			continue;
25bb7d
+		}
25bb7d
+		/* at least one thing must match if source_as_any was given */
25bb7d
+		if (source_as_any && (!match_source && !match_target && !match_default)) {
25bb7d
+			continue;
25bb7d
+		}
25bb7d
+
25bb7d
+		if (class_list != NULL) {
25bb7d
+			const qpol_class_t *obj_class;
25bb7d
+			if (qpol_filename_trans_get_object_class(p->p, filename_trans, &obj_class) < 0) {
25bb7d
+				goto cleanup;
25bb7d
+			}
25bb7d
+			if (apol_vector_get_index(class_list, obj_class, NULL, NULL, &i) < 0) {
25bb7d
+				continue;
25bb7d
+			}
25bb7d
+		}
25bb7d
+
25bb7d
+		if (apol_vector_append(*v, filename_trans)) {
25bb7d
+			ERR(p, "%s", strerror(ENOMEM));
25bb7d
+			goto cleanup;
25bb7d
+		}
25bb7d
+	}
25bb7d
+
25bb7d
+	retval = 0;
25bb7d
+      cleanup:
25bb7d
+	if (retval != 0) {
25bb7d
+		apol_vector_destroy(v);
25bb7d
+	}
25bb7d
+	apol_vector_destroy(&source_list);
25bb7d
+	if (!source_as_any) {
25bb7d
+		apol_vector_destroy(&target_list);
25bb7d
+		apol_vector_destroy(&default_list);
25bb7d
+	}
25bb7d
+	apol_vector_destroy(&class_list);
25bb7d
+	return retval;
25bb7d
+}
25bb7d
+
25bb7d
+apol_filename_trans_query_t *apol_filename_trans_query_create(void)
25bb7d
+{
25bb7d
+	apol_filename_trans_query_t *t = calloc(1, sizeof(apol_filename_trans_query_t));
25bb7d
+	if (t != NULL) {
25bb7d
+		t->flags =
25bb7d
+			(APOL_QUERY_SOURCE_TYPE | APOL_QUERY_SOURCE_ATTRIBUTE | APOL_QUERY_TARGET_TYPE |
25bb7d
+			 APOL_QUERY_TARGET_ATTRIBUTE);
25bb7d
+	}
25bb7d
+	return t;
25bb7d
+}
25bb7d
+
25bb7d
+void apol_filename_trans_query_destroy(apol_filename_trans_query_t ** r)
25bb7d
+{
25bb7d
+	if (r != NULL && *r != NULL) {
25bb7d
+		free((*r)->source);
25bb7d
+		free((*r)->target);
25bb7d
+		free((*r)->default_type);
25bb7d
+		free((*r)->name);
25bb7d
+		free(*r);
25bb7d
+		*r = NULL;
25bb7d
+	}
25bb7d
+}
25bb7d
+
25bb7d
+int apol_filename_trans_query_set_source(const apol_policy_t * p, apol_filename_trans_query_t * t, const char *filename, int is_indirect)
25bb7d
+{
25bb7d
+	apol_query_set_flag(p, &t->flags, is_indirect, APOL_QUERY_TARGET_INDIRECT);
25bb7d
+	return apol_query_set(p, &t->source, NULL, filename);
25bb7d
+}
25bb7d
+
25bb7d
+int apol_filename_trans_query_set_target(const apol_policy_t * p, apol_filename_trans_query_t * t, const char *type, int is_indirect)
25bb7d
+{
25bb7d
+	apol_query_set_flag(p, &t->flags, is_indirect, APOL_QUERY_TARGET_INDIRECT);
25bb7d
+	return apol_query_set(p, &t->target, NULL, type);
25bb7d
+}
25bb7d
+
25bb7d
+int apol_filename_trans_query_set_default(const apol_policy_t * p, apol_filename_trans_query_t * t, const char *symbol)
25bb7d
+{
25bb7d
+	return apol_query_set(p, &t->default_type, NULL, symbol);
25bb7d
+}
25bb7d
+
25bb7d
+int apol_filename_trans_query_append_class(const apol_policy_t * p, apol_filename_trans_query_t * t, const char *obj_class)
25bb7d
+{
25bb7d
+	char *s = NULL;
25bb7d
+	if (obj_class == NULL) {
25bb7d
+		apol_vector_destroy(&t->classes);
25bb7d
+	} else if ((s = strdup(obj_class)) == NULL || (t->classes == NULL && (t->classes = apol_vector_create(free)) == NULL)
25bb7d
+		   || apol_vector_append(t->classes, s) < 0) {
25bb7d
+		ERR(p, "%s", strerror(errno));
25bb7d
+		free(s);
25bb7d
+		return -1;
25bb7d
+	}
25bb7d
+	return 0;
25bb7d
+}
25bb7d
+
25bb7d
+int apol_filename_trans_query_set_name(const apol_policy_t * p, apol_filename_trans_query_t * t, const char *filename)
25bb7d
+{
25bb7d
+	return apol_query_set(p, &t->name, NULL, filename);
25bb7d
+}
25bb7d
+
25bb7d
+int apol_filename_trans_query_set_source_any(const apol_policy_t * p, apol_filename_trans_query_t * t, int is_any)
25bb7d
+{
25bb7d
+	return apol_query_set_flag(p, &t->flags, is_any, APOL_QUERY_SOURCE_AS_ANY);
25bb7d
+}
25bb7d
+
25bb7d
+int apol_filename_trans_query_set_regex(const apol_policy_t * p, apol_filename_trans_query_t * t, int is_regex)
25bb7d
+{
25bb7d
+	return apol_query_set_regex(p, &t->flags, is_regex);
25bb7d
+}
25bb7d
+
25bb7d
+char *apol_filename_trans_render(const apol_policy_t * policy, const qpol_filename_trans_t * filename_trans)
25bb7d
+{
25bb7d
+	char *tmp = NULL;
25bb7d
+	const char *tmp_name = NULL;
25bb7d
+	const char *filename_trans_type_str;
25bb7d
+	int error = 0;
25bb7d
+	size_t tmp_sz = 0;
25bb7d
+	uint32_t filename_trans_type = 0;
25bb7d
+	const qpol_type_t *type = NULL;
25bb7d
+	const qpol_class_t *obj_class = NULL;
25bb7d
+
25bb7d
+	if (!policy || !filename_trans) {
25bb7d
+		ERR(policy, "%s", strerror(EINVAL));
25bb7d
+		errno = EINVAL;
25bb7d
+		return NULL;
25bb7d
+	}
25bb7d
+
25bb7d
+	/* source type */
25bb7d
+	if (qpol_filename_trans_get_source_type(policy->p, filename_trans, &type)) {
25bb7d
+		error = errno;
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+	if (qpol_type_get_name(policy->p, type, &tmp_name)) {
25bb7d
+		error = errno;
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+	if (apol_str_appendf(&tmp, &tmp_sz, "transition_type %s ", tmp_name)) {
25bb7d
+		error = errno;
25bb7d
+		ERR(policy, "%s", strerror(error));
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+
25bb7d
+	/* target type */
25bb7d
+	if (qpol_filename_trans_get_target_type(policy->p, filename_trans, &type)) {
25bb7d
+		error = errno;
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+	if (qpol_type_get_name(policy->p, type, &tmp_name)) {
25bb7d
+		error = errno;
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+	if (apol_str_appendf(&tmp, &tmp_sz, "%s : ", tmp_name)) {
25bb7d
+		error = errno;
25bb7d
+		ERR(policy, "%s", strerror(error));
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+
25bb7d
+	/* object class */
25bb7d
+	if (qpol_filename_trans_get_object_class(policy->p, filename_trans, &obj_class)) {
25bb7d
+		error = errno;
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+	if (qpol_class_get_name(policy->p, obj_class, &tmp_name)) {
25bb7d
+		error = errno;
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+	if (apol_str_appendf(&tmp, &tmp_sz, "%s ", tmp_name)) {
25bb7d
+		error = errno;
25bb7d
+		ERR(policy, "%s", strerror(error));
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+
25bb7d
+	/* default type */
25bb7d
+	if (qpol_filename_trans_get_default_type(policy->p, filename_trans, &type)) {
25bb7d
+		error = errno;
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+	if (qpol_type_get_name(policy->p, type, &tmp_name)) {
25bb7d
+		error = errno;
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+	if (apol_str_appendf(&tmp, &tmp_sz, "%s", tmp_name)) {
25bb7d
+		error = errno;
25bb7d
+		ERR(policy, "%s", strerror(error));
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+
25bb7d
+	if (qpol_filename_trans_get_filename(policy->p, filename_trans, &tmp_name)) {
25bb7d
+		error = errno;
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+
25bb7d
+	if (apol_str_appendf(&tmp, &tmp_sz, " %s", tmp_name)) {
25bb7d
+		error = errno;
25bb7d
+		ERR(policy, "%s", strerror(error));
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+
25bb7d
+	if (apol_str_appendf(&tmp, &tmp_sz, ";")) {
25bb7d
+		error = errno;
25bb7d
+		ERR(policy, "%s", strerror(error));
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+	return tmp;
25bb7d
+
25bb7d
+      err:
25bb7d
+	free(tmp);
25bb7d
+	errno = error;
25bb7d
+	return NULL;
25bb7d
+}
25bb7d
diff --git a/libapol/src/libapol.map b/libapol/src/libapol.map
25bb7d
index 4894374..7657a2d 100644
25bb7d
--- a/libapol/src/libapol.map
25bb7d
+++ b/libapol/src/libapol.map
25bb7d
@@ -34,6 +34,7 @@ VERS_4.0{
25bb7d
 		apol_protocol_to_str;
25bb7d
 		apol_qpol_context_render;
25bb7d
 		apol_range_trans_*;
25bb7d
+		apol_filename_trans_*;
25bb7d
 		apol_relabel_*;
25bb7d
 		apol_role_*;
25bb7d
 		apol_role_allow_*;
25bb7d
diff --git a/libqpol/include/qpol/ftrule_query.h b/libqpol/include/qpol/ftrule_query.h
25bb7d
new file mode 100644
25bb7d
index 0000000..1f533a4
25bb7d
--- /dev/null
25bb7d
+++ b/libqpol/include/qpol/ftrule_query.h
25bb7d
@@ -0,0 +1,116 @@
25bb7d
+/**
25bb7d
+ *  @file
25bb7d
+ *  Defines public interface for iterating over FTRULE rules.
25bb7d
+ *
25bb7d
+ *  @author Kevin Carr kcarr@tresys.com
25bb7d
+ *  @author Jeremy A. Mowery jmowery@tresys.com
25bb7d
+ *  @author Jason Tang jtang@tresys.com
25bb7d
+ *
25bb7d
+ *  Copyright (C) 2006-2007 Tresys Technology, LLC
25bb7d
+ *
25bb7d
+ *  This library is free software; you can redistribute it and/or
25bb7d
+ *  modify it under the terms of the GNU Lesser General Public
25bb7d
+ *  License as published by the Free Software Foundation; either
25bb7d
+ *  version 2.1 of the License, or (at your option) any later version.
25bb7d
+ *
25bb7d
+ *  This library is distributed in the hope that it will be useful,
25bb7d
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25bb7d
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25bb7d
+ *  Lesser General Public License for more details.
25bb7d
+ *
25bb7d
+ *  You should have received a copy of the GNU Lesser General Public
25bb7d
+ *  License along with this library; if not, write to the Free Software
25bb7d
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25bb7d
+ */
25bb7d
+
25bb7d
+#ifndef QPOL_FTRULERULE_QUERY
25bb7d
+#define QPOL_FTRULERULE_QUERY
25bb7d
+
25bb7d
+#ifdef	__cplusplus
25bb7d
+extern "C"
25bb7d
+{
25bb7d
+#endif
25bb7d
+
25bb7d
+#include <qpol/policy.h>
25bb7d
+#include <qpol/iterator.h>
25bb7d
+
25bb7d
+	typedef struct qpol_filename_trans qpol_filename_trans_t;
25bb7d
+
25bb7d
+/**
25bb7d
+ *  Get an iterator over all filename transition rules in the policy.
25bb7d
+ *  @param policy Policy from which to create the iterator.
25bb7d
+ *  @param iter Iterator over items of type qpol_filename_trans_t returned.
25bb7d
+ *  The caller is responsible for calling qpol_iterator_destroy()
25bb7d
+ *  to free memory used by this iterator.
25bb7d
+ *  It is important to note that this iterator is only valid as long as
25bb7d
+ *  the policy is unmodifed.
25bb7d
+ *  @returm 0 on success and < 0 on failure; if the call fails,
25bb7d
+ *  errno will be set and *iter will be NULL.
25bb7d
+ */
25bb7d
+	extern int qpol_policy_get_filename_trans_iter(const qpol_policy_t * policy, qpol_iterator_t ** iter);
25bb7d
+
25bb7d
+/**
25bb7d
+ *  Get the source type from a filename transition rule.
25bb7d
+ *  @param policy The policy from which the rule comes.
25bb7d
+ *  @param rule The rule from which to get the source type.
25bb7d
+ *  @param source Pointer in which to store the source type.
25bb7d
+ *  The caller should not free this pointer.
25bb7d
+ *  @return 0 on success and < 0 on failure; if the call fails,
25bb7d
+ *  errno will be set and *source will be NULL.
25bb7d
+ */
25bb7d
+	extern int qpol_filename_trans_get_source_type(const qpol_policy_t * policy, const qpol_filename_trans_t * rule,
25bb7d
+						   const qpol_type_t ** source);
25bb7d
+
25bb7d
+/**
25bb7d
+ *  Get the target type from a filename transition rule.
25bb7d
+ *  @param policy The policy from which the rule comes.
25bb7d
+ *  @param rule The rule from which to get the target type.
25bb7d
+ *  @param target Pointer in which to store the target type.
25bb7d
+ *  The caller should not free this pointer.
25bb7d
+ *  @return 0 on success and < 0 on failure; if the call fails,
25bb7d
+ *  errno will be set and *target will be NULL.
25bb7d
+ */
25bb7d
+	extern int qpol_filename_trans_get_target_type(const qpol_policy_t * policy, const qpol_filename_trans_t * rule,
25bb7d
+						   const qpol_type_t ** target);
25bb7d
+
25bb7d
+/**
25bb7d
+ *  Get the default type from a type rule.
25bb7d
+ *  @param policy Policy from which the rule comes.
25bb7d
+ *  @param rule The rule from which to get the default type.
25bb7d
+ *  @param dflt Pointer in which to store the default type.
25bb7d
+ *  The caller should not free this pointer.
25bb7d
+ *  @returm 0 on success and < 0 on failure; if the call fails,
25bb7d
+ *  errno will be set and *dflt will be NULL.
25bb7d
+ */
25bb7d
+	extern int qpol_filename_trans_get_default_type(const qpol_policy_t * policy, const qpol_filename_trans_t * rule,
25bb7d
+						const qpol_type_t ** dflt);
25bb7d
+
25bb7d
+/**
25bb7d
+ *  Get the object class from a type rule.
25bb7d
+ *  @param policy Policy from which the rule comes.
25bb7d
+ *  @param rule The rule from which to get the object class.
25bb7d
+ *  @param obj_class Pointer in which to store the object class.
25bb7d
+ *  The caller should not free this pointer.
25bb7d
+ *  @returm 0 on success and < 0 on failure; if the call fails,
25bb7d
+ *  errno will be set and *obj_class will be NULL.
25bb7d
+ */
25bb7d
+	extern int qpol_filename_trans_get_object_class(const qpol_policy_t * policy, const qpol_filename_trans_t * rule,
25bb7d
+						const qpol_class_t ** obj_class);
25bb7d
+
25bb7d
+/**
25bb7d
+ *  Get the transition filename type from a type rule.
25bb7d
+ *  @param policy Policy from which the rule comes.
25bb7d
+ *  @param rule The rule from which to get the transition filename.
25bb7d
+ *  @param target Pointer in which to store the transition filename.
25bb7d
+ *  The caller should not free this pointer.
25bb7d
+ *  @returm 0 on success and < 0 on failure; if the call fails,
25bb7d
+ *  errno will be set and *target will be NULL.
25bb7d
+ */
25bb7d
+	extern int qpol_filename_trans_get_filename(const qpol_policy_t * policy, const qpol_filename_trans_t * rule,
25bb7d
+						       const char ** name);
25bb7d
+
25bb7d
+#ifdef	__cplusplus
25bb7d
+}
25bb7d
+#endif
25bb7d
+
25bb7d
+#endif				       /* QPOL_FTRULERULE_QUERY */
25bb7d
diff --git a/libqpol/include/qpol/policy.h b/libqpol/include/qpol/policy.h
25bb7d
index ae4ea08..bf85718 100644
25bb7d
--- a/libqpol/include/qpol/policy.h
25bb7d
+++ b/libqpol/include/qpol/policy.h
25bb7d
@@ -55,6 +55,7 @@ extern "C"
25bb7d
 #include <qpol/polcap_query.h>
25bb7d
 #include <qpol/portcon_query.h>
25bb7d
 #include <qpol/rbacrule_query.h>
25bb7d
+#include <qpol/ftrule_query.h>
25bb7d
 #include <qpol/role_query.h>
25bb7d
 #include <qpol/syn_rule_query.h>
25bb7d
 #include <qpol/terule_query.h>
25bb7d
diff --git a/libqpol/src/Makefile.am b/libqpol/src/Makefile.am
25bb7d
index 34d87a6..0889a61 100644
25bb7d
--- a/libqpol/src/Makefile.am
25bb7d
+++ b/libqpol/src/Makefile.am
25bb7d
@@ -48,6 +48,7 @@ libqpol_a_SOURCES = \
25bb7d
 	syn_rule_internal.h \
25bb7d
 	syn_rule_query.c \
25bb7d
 	terule_query.c \
25bb7d
+	ftrule_query.c \
25bb7d
 	type_query.c \
25bb7d
 	user_query.c \
25bb7d
 	util.c \
25bb7d
diff --git a/libqpol/src/ftrule_query.c b/libqpol/src/ftrule_query.c
25bb7d
new file mode 100644
25bb7d
index 0000000..d6db848
25bb7d
--- /dev/null
25bb7d
+++ b/libqpol/src/ftrule_query.c
25bb7d
@@ -0,0 +1,277 @@
25bb7d
+/**
25bb7d
+ *  @file
25bb7d
+ *  Defines public interface for iterating over RBAC rules.
25bb7d
+ *
25bb7d
+ *  @author Jeremy A. Mowery jmowery@tresys.com
25bb7d
+ *  @author Jason Tang jtang@tresys.com
25bb7d
+ *
25bb7d
+ *  Copyright (C) 2006-2007 Tresys Technology, LLC
25bb7d
+ *
25bb7d
+ *  This library is free software; you can redistribute it and/or
25bb7d
+ *  modify it under the terms of the GNU Lesser General Public
25bb7d
+ *  License as published by the Free Software Foundation; either
25bb7d
+ *  version 2.1 of the License, or (at your option) any later version.
25bb7d
+ *
25bb7d
+ *  This library is distributed in the hope that it will be useful,
25bb7d
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25bb7d
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25bb7d
+ *  Lesser General Public License for more details.
25bb7d
+ *
25bb7d
+ *  You should have received a copy of the GNU Lesser General Public
25bb7d
+ *  License along with this library; if not, write to the Free Software
25bb7d
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25bb7d
+ */
25bb7d
+
25bb7d
+#include <qpol/iterator.h>
25bb7d
+#include <qpol/policy.h>
25bb7d
+#include <qpol/ftrule_query.h>
25bb7d
+#include <stdlib.h>
25bb7d
+#include "iterator_internal.h"
25bb7d
+#include "qpol_internal.h"
25bb7d
+#include <sepol/policydb/policydb.h>
25bb7d
+
25bb7d
+typedef struct filename_trans_state
25bb7d
+{
25bb7d
+	filename_trans_t *head;
25bb7d
+	filename_trans_t *cur;
25bb7d
+} filename_trans_state_t;
25bb7d
+
25bb7d
+static int filename_trans_state_end(const qpol_iterator_t * iter)
25bb7d
+{
25bb7d
+	filename_trans_state_t *fts = NULL;
25bb7d
+
25bb7d
+	if (!iter || !(fts = qpol_iterator_state(iter))) {
25bb7d
+		errno = EINVAL;
25bb7d
+		return STATUS_ERR;
25bb7d
+	}
25bb7d
+
25bb7d
+	return fts->cur ? 0 : 1;
25bb7d
+}
25bb7d
+
25bb7d
+static void *filename_trans_state_get_cur(const qpol_iterator_t * iter)
25bb7d
+{
25bb7d
+	filename_trans_state_t *fts = NULL;
25bb7d
+	const policydb_t *db = NULL;
25bb7d
+
25bb7d
+	if (!iter || !(fts = qpol_iterator_state(iter)) || !(db = qpol_iterator_policy(iter)) || filename_trans_state_end(iter)) {
25bb7d
+		errno = EINVAL;
25bb7d
+		return NULL;
25bb7d
+	}
25bb7d
+
25bb7d
+	return fts->cur;
25bb7d
+}
25bb7d
+
25bb7d
+static int filename_trans_state_next(qpol_iterator_t * iter)
25bb7d
+{
25bb7d
+	filename_trans_state_t *fts = NULL;
25bb7d
+	const policydb_t *db = NULL;
25bb7d
+
25bb7d
+	if (!iter || !(fts = qpol_iterator_state(iter)) || !(db = qpol_iterator_policy(iter))) {
25bb7d
+		errno = EINVAL;
25bb7d
+		return STATUS_ERR;
25bb7d
+	}
25bb7d
+
25bb7d
+	if (filename_trans_state_end(iter)) {
25bb7d
+		errno = ERANGE;
25bb7d
+		return STATUS_ERR;
25bb7d
+	}
25bb7d
+
25bb7d
+	fts->cur = fts->cur->next;
25bb7d
+
25bb7d
+	return STATUS_SUCCESS;
25bb7d
+}
25bb7d
+
25bb7d
+static size_t filename_trans_state_size(const qpol_iterator_t * iter)
25bb7d
+{
25bb7d
+	filename_trans_state_t *fts = NULL;
25bb7d
+	const policydb_t *db = NULL;
25bb7d
+	filename_trans_t *tmp = NULL;
25bb7d
+	size_t count = 0;
25bb7d
+
25bb7d
+	if (!iter || !(fts = qpol_iterator_state(iter)) || !(db = qpol_iterator_policy(iter))) {
25bb7d
+		errno = EINVAL;
25bb7d
+		return STATUS_ERR;
25bb7d
+	}
25bb7d
+
25bb7d
+	for (tmp = fts->head; tmp; tmp = tmp->next)
25bb7d
+		count++;
25bb7d
+
25bb7d
+	return count;
25bb7d
+}
25bb7d
+
25bb7d
+int qpol_policy_get_filename_trans_iter(const qpol_policy_t * policy, qpol_iterator_t ** iter)
25bb7d
+{
25bb7d
+	policydb_t *db = NULL;
25bb7d
+	filename_trans_state_t *fts = NULL;
25bb7d
+	int error = 0;
25bb7d
+
25bb7d
+	if (iter)
25bb7d
+		*iter = NULL;
25bb7d
+
25bb7d
+	if (!policy || !iter) {
25bb7d
+		ERR(policy, "%s", strerror(EINVAL));
25bb7d
+		errno = EINVAL;
25bb7d
+		return STATUS_ERR;
25bb7d
+	}
25bb7d
+
25bb7d
+	db = &policy->p->p;
25bb7d
+
25bb7d
+	fts = calloc(1, sizeof(filename_trans_state_t));
25bb7d
+	if (!fts) {
25bb7d
+		/* errno set by calloc */
25bb7d
+		ERR(policy, "%s", strerror(errno));
25bb7d
+		return STATUS_ERR;
25bb7d
+	}
25bb7d
+	fts->head = fts->cur = db->filename_trans;
25bb7d
+
25bb7d
+	if (qpol_iterator_create
25bb7d
+	    (policy, (void *)fts, filename_trans_state_get_cur, filename_trans_state_next, filename_trans_state_end, filename_trans_state_size,
25bb7d
+	     free, iter)) {
25bb7d
+		error = errno;
25bb7d
+		free(fts);
25bb7d
+		errno = error;
25bb7d
+		return STATUS_ERR;
25bb7d
+	}
25bb7d
+
25bb7d
+	return STATUS_SUCCESS;
25bb7d
+}
25bb7d
+
25bb7d
+int qpol_filename_trans_get_source_type(const qpol_policy_t * policy, const qpol_filename_trans_t * rule, const qpol_type_t ** source)
25bb7d
+{
25bb7d
+	policydb_t *db = NULL;
25bb7d
+	filename_trans_t *ft = NULL;
25bb7d
+
25bb7d
+	if (source) {
25bb7d
+		*source = NULL;
25bb7d
+	}
25bb7d
+
25bb7d
+	if (!policy || !rule || !source) {
25bb7d
+		ERR(policy, "%s", strerror(EINVAL));
25bb7d
+		errno = EINVAL;
25bb7d
+		return STATUS_ERR;
25bb7d
+	}
25bb7d
+
25bb7d
+	db = &policy->p->p;
25bb7d
+	ft = (filename_trans_t *) rule;
25bb7d
+
25bb7d
+	*source = (qpol_type_t *) db->type_val_to_struct[ft->stype - 1];
25bb7d
+
25bb7d
+	return STATUS_SUCCESS;
25bb7d
+}
25bb7d
+
25bb7d
+int qpol_filename_trans_get_target_type(const qpol_policy_t * policy, const qpol_filename_trans_t * rule, const qpol_type_t ** target)
25bb7d
+{
25bb7d
+	policydb_t *db = NULL;
25bb7d
+	filename_trans_t *ft = NULL;
25bb7d
+
25bb7d
+	if (target) {
25bb7d
+		*target = NULL;
25bb7d
+	}
25bb7d
+
25bb7d
+	if (!policy || !rule || !target) {
25bb7d
+		ERR(policy, "%s", strerror(EINVAL));
25bb7d
+		errno = EINVAL;
25bb7d
+		return STATUS_ERR;
25bb7d
+	}
25bb7d
+
25bb7d
+	db = &policy->p->p;
25bb7d
+	ft = (filename_trans_t *) rule;
25bb7d
+
25bb7d
+	*target = (qpol_type_t *) db->type_val_to_struct[ft->ttype - 1];
25bb7d
+
25bb7d
+	return STATUS_SUCCESS;
25bb7d
+}
25bb7d
+
25bb7d
+int qpol_filename_trans_get_object_class(const qpol_policy_t * policy, const qpol_filename_trans_t * rule,
25bb7d
+						const qpol_class_t ** obj_class)
25bb7d
+{
25bb7d
+	policydb_t *db = NULL;
25bb7d
+	filename_trans_t *ft = NULL;
25bb7d
+
25bb7d
+	if (obj_class) {
25bb7d
+		*obj_class = NULL;
25bb7d
+	}
25bb7d
+
25bb7d
+	if (!policy || !rule || !obj_class) {
25bb7d
+		ERR(policy, "%s", strerror(EINVAL));
25bb7d
+		errno = EINVAL;
25bb7d
+		return STATUS_ERR;
25bb7d
+	}
25bb7d
+
25bb7d
+	db = &policy->p->p;
25bb7d
+	ft = (filename_trans_t *) rule;
25bb7d
+
25bb7d
+	*obj_class = (qpol_class_t *) db->class_val_to_struct[ft->tclass - 1];
25bb7d
+
25bb7d
+	return STATUS_SUCCESS;
25bb7d
+}
25bb7d
+
25bb7d
+int qpol_filename_trans_get_trans_type(const qpol_policy_t * policy, const qpol_filename_trans_t * rule, const qpol_type_t ** output_type)
25bb7d
+{
25bb7d
+	policydb_t *db = NULL;
25bb7d
+	filename_trans_t *ft = NULL;
25bb7d
+
25bb7d
+	if (output_type) {
25bb7d
+		*output_type = NULL;
25bb7d
+	}
25bb7d
+
25bb7d
+	if (!policy || !rule || !output_type) {
25bb7d
+		ERR(policy, "%s", strerror(EINVAL));
25bb7d
+		errno = EINVAL;
25bb7d
+		return STATUS_ERR;
25bb7d
+	}
25bb7d
+
25bb7d
+	db = &policy->p->p;
25bb7d
+	ft = (filename_trans_t *) rule;
25bb7d
+
25bb7d
+	*output_type = (qpol_type_t *) db->type_val_to_struct[ft->otype - 1];
25bb7d
+
25bb7d
+	return STATUS_SUCCESS;
25bb7d
+}
25bb7d
+
25bb7d
+int qpol_filename_trans_get_default_type(const qpol_policy_t * policy, const qpol_filename_trans_t * rule, const qpol_type_t ** dflt)
25bb7d
+{
25bb7d
+	policydb_t *db = NULL;
25bb7d
+	filename_trans_t *ft = NULL;
25bb7d
+
25bb7d
+	if (dflt) {
25bb7d
+		*dflt = NULL;
25bb7d
+	}
25bb7d
+
25bb7d
+	if (!policy || !rule || !dflt) {
25bb7d
+		ERR(policy, "%s", strerror(EINVAL));
25bb7d
+		errno = EINVAL;
25bb7d
+		return STATUS_ERR;
25bb7d
+	}
25bb7d
+
25bb7d
+	db = &policy->p->p;
25bb7d
+	ft = (filename_trans_t *) rule;
25bb7d
+
25bb7d
+	*dflt = (qpol_type_t *) db->type_val_to_struct[ft->otype - 1];
25bb7d
+
25bb7d
+	return STATUS_SUCCESS;
25bb7d
+}
25bb7d
+
25bb7d
+int qpol_filename_trans_get_filename(const qpol_policy_t * policy, const qpol_filename_trans_t * rule, const char ** name)
25bb7d
+{
25bb7d
+	policydb_t *db = NULL;
25bb7d
+	filename_trans_t *ft = NULL;
25bb7d
+
25bb7d
+	if (name) {
25bb7d
+		*name = NULL;
25bb7d
+	}
25bb7d
+
25bb7d
+	if (!policy || !rule || !name) {
25bb7d
+		ERR(policy, "%s", strerror(EINVAL));
25bb7d
+		errno = EINVAL;
25bb7d
+		return STATUS_ERR;
25bb7d
+	}
25bb7d
+
25bb7d
+	db = &policy->p->p;
25bb7d
+	ft = (filename_trans_t *) rule;
25bb7d
+
25bb7d
+	*name = ft->name;
25bb7d
+
25bb7d
+	return STATUS_SUCCESS;
25bb7d
+}
25bb7d
+
25bb7d
diff --git a/libqpol/src/libqpol.map b/libqpol/src/libqpol.map
25bb7d
index dd293bc..6973cca 100644
25bb7d
--- a/libqpol/src/libqpol.map
25bb7d
+++ b/libqpol/src/libqpol.map
25bb7d
@@ -34,6 +34,7 @@ VERS_1.2 {
25bb7d
 		qpol_policy_reevaluate_conds;
25bb7d
 		qpol_portcon_*;
25bb7d
 		qpol_range_trans_*;
25bb7d
+		qpol_filename_trans_*;
25bb7d
 		qpol_role_*;
25bb7d
 		qpol_syn_avrule_*;
25bb7d
 		qpol_syn_terule_*;
25bb7d
diff --git a/libqpol/src/module_compiler.c b/libqpol/src/module_compiler.c
25bb7d
index dc19798..b06e285 100644
25bb7d
--- a/libqpol/src/module_compiler.c
25bb7d
+++ b/libqpol/src/module_compiler.c
25bb7d
@@ -1247,6 +1247,18 @@ void append_role_allow(role_allow_rule_t * role_allow_rules)
25bb7d
 }
25bb7d
 
25bb7d
 /* this doesn't actually append, but really prepends it */
25bb7d
+void append_filename_trans(filename_trans_rule_t * filename_trans_rules)
25bb7d
+{
25bb7d
+	avrule_decl_t *decl = stack_top->decl;
25bb7d
+
25bb7d
+	/* filename transitions are not allowed within conditionals */
25bb7d
+	assert(stack_top->type == 1);
25bb7d
+
25bb7d
+	filename_trans_rules->next = decl->filename_trans_rules;
25bb7d
+	decl->filename_trans_rules = filename_trans_rules;
25bb7d
+}
25bb7d
+
25bb7d
+/* this doesn't actually append, but really prepends it */
25bb7d
 void append_range_trans(range_trans_rule_t * range_tr_rules)
25bb7d
 {
25bb7d
 	avrule_decl_t *decl = stack_top->decl;
25bb7d
diff --git a/libqpol/src/policy_define.c b/libqpol/src/policy_define.c
25bb7d
index c94f7aa..0f3a45a 100644
25bb7d
--- a/libqpol/src/policy_define.c
25bb7d
+++ b/libqpol/src/policy_define.c
25bb7d
@@ -2133,7 +2133,7 @@ int define_role_trans(void)
25bb7d
 
25bb7d
 	/* This ebitmap business is just to ensure that there are not conflicting role_trans rules */
25bb7d
 #ifdef HAVE_SEPOL_USER_ROLE_MAPPING
25bb7d
-	if (role_set_expand(&roles, &e_roles, policydbp, NULL))
25bb7d
+	if (role_set_expand(&roles, &e_roles, policydbp, NULL, NULL))
25bb7d
 #else
25bb7d
 	if (role_set_expand(&roles, &e_roles, policydbp))
25bb7d
 #endif
25bb7d
@@ -2226,6 +2226,190 @@ int define_role_allow(void)
25bb7d
 	return 0;
25bb7d
 }
25bb7d
 
25bb7d
+avrule_t *define_cond_filename_trans(void)
25bb7d
+{
25bb7d
+	yyerror("type transitions with a filename not allowed inside "
25bb7d
+		"conditionals\n");
25bb7d
+	return COND_ERR;
25bb7d
+}
25bb7d
+
25bb7d
+int define_filename_trans(void)
25bb7d
+{
25bb7d
+	char *id, *name = NULL;
25bb7d
+	type_set_t stypes, ttypes;
25bb7d
+	ebitmap_t e_stypes, e_ttypes;
25bb7d
+	ebitmap_t e_tclasses;
25bb7d
+	ebitmap_node_t *snode, *tnode, *cnode;
25bb7d
+	filename_trans_t *ft;
25bb7d
+	filename_trans_rule_t *ftr;
25bb7d
+	class_datum_t *cladatum;
25bb7d
+	type_datum_t *typdatum;
25bb7d
+	uint32_t otype;
25bb7d
+	unsigned int c, s, t;
25bb7d
+	int add;
25bb7d
+
25bb7d
+	if (pass == 1) {
25bb7d
+		/* stype */
25bb7d
+		while ((id = queue_remove(id_queue)))
25bb7d
+			free(id);
25bb7d
+		/* ttype */
25bb7d
+		while ((id = queue_remove(id_queue)))
25bb7d
+			free(id);
25bb7d
+		/* tclass */
25bb7d
+		while ((id = queue_remove(id_queue)))
25bb7d
+			free(id);
25bb7d
+		/* otype */
25bb7d
+		id = queue_remove(id_queue);
25bb7d
+		free(id);
25bb7d
+		/* name */
25bb7d
+		id = queue_remove(id_queue);
25bb7d
+		free(id);
25bb7d
+		return 0;
25bb7d
+	}
25bb7d
+
25bb7d
+
25bb7d
+	add = 1;
25bb7d
+	type_set_init(&stypes);
25bb7d
+	while ((id = queue_remove(id_queue))) {
25bb7d
+		if (set_types(&stypes, id, &add, 0))
25bb7d
+			goto bad;
25bb7d
+	}
25bb7d
+
25bb7d
+	add =1;
25bb7d
+	type_set_init(&ttypes);
25bb7d
+	while ((id = queue_remove(id_queue))) {
25bb7d
+		if (set_types(&ttypes, id, &add, 0))
25bb7d
+			goto bad;
25bb7d
+	}
25bb7d
+
25bb7d
+	ebitmap_init(&e_tclasses);
25bb7d
+	while ((id = queue_remove(id_queue))) {
25bb7d
+		if (!is_id_in_scope(SYM_CLASSES, id)) {
25bb7d
+			yyerror2("class %s is not within scope", id);
25bb7d
+			free(id);
25bb7d
+			goto bad;
25bb7d
+		}
25bb7d
+		cladatum = hashtab_search(policydbp->p_classes.table, id);
25bb7d
+		if (!cladatum) {
25bb7d
+			yyerror2("unknown class %s", id);
25bb7d
+			goto bad;
25bb7d
+		}
25bb7d
+		if (ebitmap_set_bit(&e_tclasses, cladatum->s.value - 1, TRUE)) {
25bb7d
+			yyerror("Out of memory");
25bb7d
+			goto bad;
25bb7d
+		}
25bb7d
+		free(id);
25bb7d
+	}
25bb7d
+
25bb7d
+	id = (char *)queue_remove(id_queue);
25bb7d
+	if (!id) {
25bb7d
+		yyerror("no otype in transition definition?");
25bb7d
+		goto bad;
25bb7d
+	}
25bb7d
+	if (!is_id_in_scope(SYM_TYPES, id)) {
25bb7d
+		yyerror2("type %s is not within scope", id);
25bb7d
+		free(id);
25bb7d
+		goto bad;
25bb7d
+	}
25bb7d
+	typdatum = hashtab_search(policydbp->p_types.table, id);
25bb7d
+	if (!typdatum) {
25bb7d
+		yyerror2("unknown type %s used in transition definition", id);
25bb7d
+		goto bad;
25bb7d
+	}
25bb7d
+	free(id);
25bb7d
+	otype = typdatum->s.value;
25bb7d
+
25bb7d
+	name = queue_remove(id_queue);
25bb7d
+	if (!name) {
25bb7d
+		yyerror("no pathname specified in filename_trans definition?");
25bb7d
+		goto bad;
25bb7d
+	}
25bb7d
+
25bb7d
+	/* We expand the class set into seperate rules.  We expand the types
25bb7d
+	 * just to make sure there are not duplicates.  They will get turned
25bb7d
+	 * into seperate rules later */
25bb7d
+	ebitmap_init(&e_stypes);
25bb7d
+	if (type_set_expand(&stypes, &e_stypes, policydbp, 1))
25bb7d
+		goto bad;
25bb7d
+
25bb7d
+	ebitmap_init(&e_ttypes);
25bb7d
+	if (type_set_expand(&ttypes, &e_ttypes, policydbp, 1))
25bb7d
+		goto bad;
25bb7d
+
25bb7d
+	ebitmap_for_each_bit(&e_tclasses, cnode, c) {
25bb7d
+		if (!ebitmap_node_get_bit(cnode, c))
25bb7d
+			continue;
25bb7d
+		ebitmap_for_each_bit(&e_stypes, snode, s) {
25bb7d
+			if (!ebitmap_node_get_bit(snode, s))
25bb7d
+				continue;
25bb7d
+			ebitmap_for_each_bit(&e_ttypes, tnode, t) {
25bb7d
+				if (!ebitmap_node_get_bit(tnode, t))
25bb7d
+					continue;
25bb7d
+	
25bb7d
+				for (ft = policydbp->filename_trans; ft; ft = ft->next) {
25bb7d
+					if (ft->stype == (s + 1) &&
25bb7d
+					    ft->ttype == (t + 1) &&
25bb7d
+					    ft->tclass == (c + 1) &&
25bb7d
+					    !strcmp(ft->name, name)) {
25bb7d
+						yyerror2("duplicate filename transition for: filename_trans %s %s %s:%s",
25bb7d
+							 name, 
25bb7d
+							 policydbp->p_type_val_to_name[s],
25bb7d
+							 policydbp->p_type_val_to_name[t],
25bb7d
+							 policydbp->p_class_val_to_name[c]);
25bb7d
+						goto bad;
25bb7d
+					}
25bb7d
+				}
25bb7d
+	
25bb7d
+				ft = malloc(sizeof(*ft));
25bb7d
+				if (!ft) {
25bb7d
+					yyerror("out of memory");
25bb7d
+					goto bad;
25bb7d
+				}
25bb7d
+				memset(ft, 0, sizeof(*ft));
25bb7d
+	
25bb7d
+				ft->next = policydbp->filename_trans;
25bb7d
+				policydbp->filename_trans = ft;
25bb7d
+	
25bb7d
+				ft->name = strdup(name);
25bb7d
+				if (!ft->name) {
25bb7d
+					yyerror("out of memory");
25bb7d
+					goto bad;
25bb7d
+				}
25bb7d
+				ft->stype = s + 1;
25bb7d
+				ft->ttype = t + 1;
25bb7d
+				ft->tclass = c + 1;
25bb7d
+				ft->otype = otype;
25bb7d
+			}
25bb7d
+		}
25bb7d
+	
25bb7d
+		/* Now add the real rule since we didn't find any duplicates */
25bb7d
+		ftr = malloc(sizeof(*ftr));
25bb7d
+		if (!ftr) {
25bb7d
+			yyerror("out of memory");
25bb7d
+			goto bad;
25bb7d
+		}
25bb7d
+		filename_trans_rule_init(ftr);
25bb7d
+		append_filename_trans(ftr);
25bb7d
+
25bb7d
+		ftr->name = strdup(name);
25bb7d
+		ftr->stypes = stypes;
25bb7d
+		ftr->ttypes = ttypes;
25bb7d
+		ftr->tclass = c + 1;
25bb7d
+		ftr->otype = otype;
25bb7d
+	}
25bb7d
+
25bb7d
+	free(name);
25bb7d
+	ebitmap_destroy(&e_stypes);
25bb7d
+	ebitmap_destroy(&e_ttypes);
25bb7d
+	ebitmap_destroy(&e_tclasses);
25bb7d
+
25bb7d
+	return 0;
25bb7d
+
25bb7d
+bad:
25bb7d
+	free(name);
25bb7d
+	return -1;
25bb7d
+}
25bb7d
+
25bb7d
 static constraint_expr_t *constraint_expr_clone(constraint_expr_t * expr)
25bb7d
 {
25bb7d
 	constraint_expr_t *h = NULL, *l = NULL, *e, *newe;
25bb7d
diff --git a/libqpol/src/policy_parse.y b/libqpol/src/policy_parse.y
25bb7d
index 84f4114..dc16c6f 100644
25bb7d
--- a/libqpol/src/policy_parse.y
25bb7d
+++ b/libqpol/src/policy_parse.y
25bb7d
@@ -98,6 +98,7 @@ extern char *qpol_src_inputlim;/* end of data */
25bb7d
 %type <require_func> require_decl_def
25bb7d
 
25bb7d
 %token PATH
25bb7d
+%token FILENAME
25bb7d
 %token CLONE
25bb7d
 %token COMMON
25bb7d
 %token CLASS
25bb7d
@@ -360,7 +361,10 @@ cond_rule_def           : cond_transition_def
25bb7d
 			| require_block
25bb7d
 			{ $$ = NULL; }
25bb7d
                         ;
25bb7d
-cond_transition_def	: TYPE_TRANSITION names names ':' names identifier ';'
25bb7d
+cond_transition_def	: TYPE_TRANSITION names names ':' names identifier filename ';'
25bb7d
+                        { $$ = define_cond_filename_trans() ;
25bb7d
+                          if ($$ == COND_ERR) return -1;}
25bb7d
+                        | TYPE_TRANSITION names names ':' names identifier ';'
25bb7d
                         { $$ = define_cond_compute_type(AVRULE_TRANSITION) ;
25bb7d
                           if ($$ == COND_ERR) return -1;}
25bb7d
                         | TYPE_MEMBER names names ':' names identifier ';'
25bb7d
@@ -395,7 +399,9 @@ cond_dontaudit_def	: DONTAUDIT names names ':' names names ';'
25bb7d
 			{ $$ = define_cond_te_avtab(AVRULE_DONTAUDIT);
25bb7d
                           if ($$ == COND_ERR) return -1; }
25bb7d
 		        ;
25bb7d
-transition_def		: TYPE_TRANSITION names names ':' names identifier ';'
25bb7d
+transition_def		: TYPE_TRANSITION  names names ':' names identifier filename ';'
25bb7d
+			{if (define_filename_trans()) return -1; }
25bb7d
+			| TYPE_TRANSITION names names ':' names identifier ';'
25bb7d
                         {if (define_compute_type(AVRULE_TRANSITION)) return -1;}
25bb7d
                         | TYPE_MEMBER names names ':' names identifier ';'
25bb7d
                         {if (define_compute_type(AVRULE_MEMBER)) return -1;}
25bb7d
@@ -752,6 +758,9 @@ identifier		: IDENTIFIER
25bb7d
 path     		: PATH
25bb7d
 			{ if (insert_id(yytext,0)) return -1; }
25bb7d
 			;
25bb7d
+filename		: FILENAME
25bb7d
+			{ yytext[strlen(yytext) - 1] = '\0'; if (insert_id(yytext + 1,0)) return -1; }
25bb7d
+			;
25bb7d
 number			: NUMBER 
25bb7d
 			{ $$ = strtoul(yytext,NULL,0); }
25bb7d
 			;
25bb7d
diff --git a/libqpol/src/policy_scan.l b/libqpol/src/policy_scan.l
25bb7d
index 75485f3..30203cd 100644
25bb7d
--- a/libqpol/src/policy_scan.l
25bb7d
+++ b/libqpol/src/policy_scan.l
25bb7d
@@ -235,6 +235,7 @@ POLICYCAP			{ return(POLICYCAP); }
25bb7d
 permissive |
25bb7d
 PERMISSIVE			{ return(PERMISSIVE); }
25bb7d
 "/"({alnum}|[_\.\-/])*	        { return(PATH); }
25bb7d
+\"({alnum}|[_\.\-])+\"			{ return(FILENAME); }
25bb7d
 {letter}({alnum}|[_\-])*([\.]?({alnum}|[_\-]))*	{ return(IDENTIFIER); }
25bb7d
 {digit}+|0x{hexval}+            { return(NUMBER); }
25bb7d
 {digit}{1,3}(\.{digit}{1,3}){3}    { return(IPV4_ADDR); }
25bb7d
diff --git a/secmds/sesearch.c b/secmds/sesearch.c
25bb7d
index ec0315f..e44b3bc 100644
25bb7d
--- a/secmds/sesearch.c
25bb7d
+++ b/secmds/sesearch.c
25bb7d
@@ -575,6 +575,95 @@ static void print_te_results(const apol_policy_t * policy, const options_t * opt
25bb7d
 	free(expr);
25bb7d
 }
25bb7d
 
25bb7d
+static int perform_ft_query(const apol_policy_t * policy, const options_t * opt, apol_vector_t ** v)
25bb7d
+{
25bb7d
+	apol_filename_trans_query_t *ftq = NULL;
25bb7d
+	int error = 0;
25bb7d
+
25bb7d
+	if (!policy || !opt || !v) {
25bb7d
+		ERR(policy, "%s", strerror(EINVAL));
25bb7d
+		errno = EINVAL;
25bb7d
+		return -1;
25bb7d
+	}
25bb7d
+
25bb7d
+	if (!opt->type == QPOL_RULE_TYPE_TRANS && !opt->all) {
25bb7d
+		*v = NULL;
25bb7d
+		return 0;	       /* no search to do */
25bb7d
+	}
25bb7d
+
25bb7d
+	ftq = apol_filename_trans_query_create();
25bb7d
+	if (!ftq) {
25bb7d
+		ERR(policy, "%s", strerror(ENOMEM));
25bb7d
+		errno = ENOMEM;
25bb7d
+		return -1;
25bb7d
+	}
25bb7d
+
25bb7d
+	apol_filename_trans_query_set_regex(policy, ftq, opt->useregex);
25bb7d
+	if (opt->src_name) {
25bb7d
+		if (apol_filename_trans_query_set_source(policy, ftq, opt->src_name)) {
25bb7d
+			error = errno;
25bb7d
+			goto err;
25bb7d
+		}
25bb7d
+	}
25bb7d
+	if (opt->tgt_name) {
25bb7d
+		if (apol_filename_trans_query_set_target(policy, ftq, opt->tgt_name, opt->indirect)) {
25bb7d
+			error = errno;
25bb7d
+			goto err;
25bb7d
+		}
25bb7d
+	}
25bb7d
+
25bb7d
+	if (apol_filename_trans_get_by_query(policy, ftq, v)) {
25bb7d
+		error = errno;
25bb7d
+		goto err;
25bb7d
+	}
25bb7d
+
25bb7d
+	apol_filename_trans_query_destroy(&ftq);
25bb7d
+	return 0;
25bb7d
+
25bb7d
+      err:
25bb7d
+	apol_vector_destroy(v);
25bb7d
+	apol_filename_trans_query_destroy(&ftq);
25bb7d
+	ERR(policy, "%s", strerror(error));
25bb7d
+	errno = error;
25bb7d
+	return -1;
25bb7d
+}
25bb7d
+
25bb7d
+static void print_ft_results(const apol_policy_t * policy, const options_t * opt, const apol_vector_t * v)
25bb7d
+{
25bb7d
+	qpol_policy_t *q = apol_policy_get_qpol(policy);
25bb7d
+	size_t i, num_rules = 0;
25bb7d
+	const qpol_filename_trans_t *rule = NULL;
25bb7d
+	char *tmp = NULL, *rule_str = NULL, *expr = NULL;
25bb7d
+	char enable_char = ' ', branch_char = ' ';
25bb7d
+	qpol_iterator_t *iter = NULL;
25bb7d
+	const qpol_cond_t *cond = NULL;
25bb7d
+	uint32_t enabled = 0, list = 0;
25bb7d
+
25bb7d
+	if (!(num_rules = apol_vector_get_size(v)))
25bb7d
+		goto cleanup;
25bb7d
+
25bb7d
+	fprintf(stdout, "Found %zd named file transition rules:\n", num_rules);
25bb7d
+
25bb7d
+	for (i = 0; i < num_rules; i++) {
25bb7d
+		enable_char = branch_char = ' ';
25bb7d
+		if (!(rule = apol_vector_get_element(v, i)))
25bb7d
+			goto cleanup;
25bb7d
+
25bb7d
+		if (!(rule_str = apol_filename_trans_render(policy, rule)))
25bb7d
+			goto cleanup;
25bb7d
+		fprintf(stdout, "%s %s\n", rule_str, expr ? expr : "");
25bb7d
+		free(rule_str);
25bb7d
+		rule_str = NULL;
25bb7d
+		free(expr);
25bb7d
+		expr = NULL;
25bb7d
+	}
25bb7d
+
25bb7d
+      cleanup:
25bb7d
+	free(tmp);
25bb7d
+	free(rule_str);
25bb7d
+	free(expr);
25bb7d
+}
25bb7d
+
25bb7d
 static int perform_ra_query(const apol_policy_t * policy, const options_t * opt, apol_vector_t ** v)
25bb7d
 {
25bb7d
 	apol_role_allow_query_t *raq = NULL;
25bb7d
@@ -1128,6 +1217,18 @@ int main(int argc, char **argv)
25bb7d
 			print_te_results(policy, &cmd_opts, v);
25bb7d
 		fprintf(stdout, "\n");
25bb7d
 	}
25bb7d
+
25bb7d
+	if (cmd_opts.all || cmd_opts.type == QPOL_RULE_TYPE_TRANS) {
25bb7d
+		apol_vector_destroy(&v);
25bb7d
+		if (perform_ft_query(policy, &cmd_opts, &v)) {
25bb7d
+			rt = 1;
25bb7d
+			goto cleanup;
25bb7d
+		}
25bb7d
+
25bb7d
+		print_ft_results(policy, &cmd_opts, v);
25bb7d
+		fprintf(stdout, "\n");
25bb7d
+	}
25bb7d
+
25bb7d
 	apol_vector_destroy(&v);
25bb7d
 	if (perform_ra_query(policy, &cmd_opts, &v)) {
25bb7d
 		rt = 1;
25bb7d
-- 
25bb7d
1.7.6.2
25bb7d
25bb7d
diff -up setools-3.3.7/libapol/include/apol/Makefile.am.filenametrans setools-3.3.7/libapol/include/apol/Makefile.am
25bb7d
--- setools-3.3.7/libapol/include/apol/Makefile.am.filenametrans	2009-07-14 14:03:27.000000000 -0400
25bb7d
+++ setools-3.3.7/libapol/include/apol/Makefile.am	2011-10-26 16:24:59.948130442 -0400
25bb7d
@@ -27,6 +27,7 @@ apol_HEADERS = \
25bb7d
 	relabel-analysis.h \
25bb7d
 	render.h \
25bb7d
 	role-query.h \
25bb7d
+	ftrule-query.h \
25bb7d
 	terule-query.h \
25bb7d
 	type-query.h \
25bb7d
 	types-relation-analysis.h \
25bb7d
diff -up setools-3.3.7/libqpol/include/qpol/Makefile.am.filenametrans setools-3.3.7/libqpol/include/qpol/Makefile.am
25bb7d
--- setools-3.3.7/libqpol/include/qpol/Makefile.am.filenametrans	2011-10-26 16:22:28.723523155 -0400
25bb7d
+++ setools-3.3.7/libqpol/include/qpol/Makefile.am	2011-10-26 16:22:41.283493767 -0400
25bb7d
@@ -25,6 +25,7 @@ qpol_HEADERS = \
25bb7d
 	role_query.h \
25bb7d
 	syn_rule_query.h \
25bb7d
 	terule_query.h \
25bb7d
+	ftrule_query.h \
25bb7d
 	type_query.h \
25bb7d
 	user_query.h \
25bb7d
 	util.h