0fd1802
From e30036e358b8f1c3f56048b467e8646fa3bfffb6 Mon Sep 17 00:00:00 2001
0fd1802
From: Dan Walsh <dwalsh@redhat.com>
0fd1802
Date: Tue, 20 Sep 2011 16:40:26 -0400
0fd1802
Subject: [PATCH 7/7] Remove unused variables
0fd1802
0fd1802
---
0fd1802
 libapol/src/ftrule-query.c |   11 ++----
0fd1802
 libqpol/src/ftrule_query.c |    2 -
0fd1802
 secmds/sesearch.c          |   86 +++++++++++++++++++++++++++++++++-----------
0fd1802
 3 files changed, 68 insertions(+), 31 deletions(-)
0fd1802
0fd1802
diff --git a/libapol/src/ftrule-query.c b/libapol/src/ftrule-query.c
0fd1802
index dc248de..9c7a23b 100644
0fd1802
--- a/libapol/src/ftrule-query.c
0fd1802
+++ b/libapol/src/ftrule-query.c
0fd1802
@@ -45,14 +45,11 @@ struct apol_filename_trans_query
0fd1802
 int apol_filename_trans_get_by_query(const apol_policy_t * p, const apol_filename_trans_query_t * t, apol_vector_t ** v)
0fd1802
 {
0fd1802
 	apol_vector_t *source_list = NULL, *target_list = NULL, *class_list = NULL, *default_list = NULL;
0fd1802
-	int retval = -1, source_as_any = 0, is_regex = 0, append_filename_trans;
0fd1802
-	char *bool_name = NULL;
0fd1802
+	int retval = -1, source_as_any = 0, is_regex = 0;
0fd1802
 	*v = NULL;
0fd1802
-	unsigned int flags = 0;
0fd1802
-	qpol_iterator_t *iter = NULL, *type_iter = NULL;
0fd1802
+	qpol_iterator_t *iter = NULL;
0fd1802
 
0fd1802
 	if (t != NULL) {
0fd1802
-		flags = t->flags;
0fd1802
 		is_regex = t->flags & APOL_QUERY_REGEX;
0fd1802
 		if (t->source != NULL &&
0fd1802
 		    (source_list =
0fd1802
@@ -104,7 +101,7 @@ int apol_filename_trans_get_by_query(const apol_policy_t * p, const apol_filenam
0fd1802
 		if (qpol_iterator_get_item(iter, (void **)&filename_trans) < 0) {
0fd1802
 			goto cleanup;
0fd1802
 		}
0fd1802
-		int match_source = 0, match_target = 0, match_default = 0, match_bool = 0;
0fd1802
+		int match_source = 0, match_target = 0, match_default = 0;
0fd1802
 		size_t i;
0fd1802
 
0fd1802
 		if (source_list == NULL) {
0fd1802
@@ -265,10 +262,8 @@ char *apol_filename_trans_render(const apol_policy_t * policy, const qpol_filena
0fd1802
 {
0fd1802
 	char *tmp = NULL;
0fd1802
 	const char *tmp_name = NULL;
0fd1802
-	const char *filename_trans_type_str;
0fd1802
 	int error = 0;
0fd1802
 	size_t tmp_sz = 0;
0fd1802
-	uint32_t filename_trans_type = 0;
0fd1802
 	const qpol_type_t *type = NULL;
0fd1802
 	const qpol_class_t *obj_class = NULL;
0fd1802
 
0fd1802
diff --git a/libqpol/src/ftrule_query.c b/libqpol/src/ftrule_query.c
0fd1802
index d6db848..3148d30 100644
0fd1802
--- a/libqpol/src/ftrule_query.c
0fd1802
+++ b/libqpol/src/ftrule_query.c
0fd1802
@@ -254,7 +254,6 @@ int qpol_filename_trans_get_default_type(const qpol_policy_t * policy, const qpo
0fd1802
 
0fd1802
 int qpol_filename_trans_get_filename(const qpol_policy_t * policy, const qpol_filename_trans_t * rule, const char ** name)
0fd1802
 {
0fd1802
-	policydb_t *db = NULL;
0fd1802
 	filename_trans_t *ft = NULL;
0fd1802
 
0fd1802
 	if (name) {
0fd1802
@@ -267,7 +266,6 @@ int qpol_filename_trans_get_filename(const qpol_policy_t * policy, const qpol_fi
0fd1802
 		return STATUS_ERR;
0fd1802
 	}
0fd1802
 
0fd1802
-	db = &policy->p->p;
0fd1802
 	ft = (filename_trans_t *) rule;
0fd1802
 
0fd1802
 	*name = ft->name;
0fd1802
diff --git a/secmds/sesearch.c b/secmds/sesearch.c
0fd1802
index e44b3bc..319ffe7 100644
0fd1802
--- a/secmds/sesearch.c
0fd1802
+++ b/secmds/sesearch.c
0fd1802
@@ -72,6 +72,7 @@ static struct option const longopts[] = {
0fd1802
 
0fd1802
 	{"source", required_argument, NULL, 's'},
0fd1802
 	{"target", required_argument, NULL, 't'},
0fd1802
+	{"default", required_argument, NULL, 'D'},
0fd1802
 	{"role_source", required_argument, NULL, EXPR_ROLE_SOURCE},
0fd1802
 	{"role_target", required_argument, NULL, EXPR_ROLE_TARGET},
0fd1802
 	{"class", required_argument, NULL, 'c'},
0fd1802
@@ -92,6 +93,7 @@ typedef struct options
0fd1802
 {
0fd1802
 	char *src_name;
0fd1802
 	char *tgt_name;
0fd1802
+	char *default_name;
0fd1802
 	char *src_role_name;
0fd1802
 	char *tgt_role_name;
0fd1802
 	char *class_name;
0fd1802
@@ -293,7 +295,8 @@ static void print_syn_av_results(const apol_policy_t * policy, const options_t *
0fd1802
 				tmp = apol_cond_expr_render(policy, cond);
0fd1802
 				enable_char = (enabled ? 'E' : 'D');
0fd1802
 				branch_char = ((is_true && enabled) || (!is_true && !enabled) ? 'T' : 'F');
0fd1802
-				asprintf(&expr, "[ %s ]", tmp);
0fd1802
+				if (asprintf(&expr, "[ %s ]", tmp) < 0)
0fd1802
+					goto cleanup;
0fd1802
 				free(tmp);
0fd1802
 				tmp = NULL;
0fd1802
 				if (!expr)
0fd1802
@@ -356,7 +359,8 @@ static void print_av_results(const apol_policy_t * policy, const options_t * opt
0fd1802
 				qpol_iterator_destroy(&iter);
0fd1802
 				enable_char = (enabled ? 'E' : 'D');
0fd1802
 				branch_char = (list ? 'T' : 'F');
0fd1802
-				asprintf(&expr, "[ %s ]", tmp);
0fd1802
+				if (asprintf(&expr, "[ %s ]", tmp) < 0)
0fd1802
+					goto cleanup;
0fd1802
 				free(tmp);
0fd1802
 				tmp = NULL;
0fd1802
 				if (!expr)
0fd1802
@@ -488,7 +492,8 @@ static void print_syn_te_results(const apol_policy_t * policy, const options_t *
0fd1802
 				tmp = apol_cond_expr_render(policy, cond);
0fd1802
 				enable_char = (enabled ? 'E' : 'D');
0fd1802
 				branch_char = ((is_true && enabled) || (!is_true && !enabled) ? 'T' : 'F');
0fd1802
-				asprintf(&expr, "[ %s ]", tmp);
0fd1802
+				if (asprintf(&expr, "[ %s ]", tmp) < 0)
0fd1802
+					goto cleanup;
0fd1802
 				free(tmp);
0fd1802
 				tmp = NULL;
0fd1802
 				if (!expr)
0fd1802
@@ -553,7 +558,8 @@ static void print_te_results(const apol_policy_t * policy, const options_t * opt
0fd1802
 				qpol_iterator_destroy(&iter);
0fd1802
 				enable_char = (enabled ? 'E' : 'D');
0fd1802
 				branch_char = (list ? 'T' : 'F');
0fd1802
-				asprintf(&expr, "[ %s ]", tmp);
0fd1802
+				if (asprintf(&expr, "[ %s ]", tmp) < 0)
0fd1802
+					goto cleanup;
0fd1802
 				free(tmp);
0fd1802
 				tmp = NULL;
0fd1802
 				if (!expr)
0fd1802
@@ -586,7 +592,7 @@ static int perform_ft_query(const apol_policy_t * policy, const options_t * opt,
0fd1802
 		return -1;
0fd1802
 	}
0fd1802
 
0fd1802
-	if (!opt->type == QPOL_RULE_TYPE_TRANS && !opt->all) {
0fd1802
+	if (!opt->type && !opt->all) {
0fd1802
 		*v = NULL;
0fd1802
 		return 0;	       /* no search to do */
0fd1802
 	}
0fd1802
@@ -600,17 +606,44 @@ static int perform_ft_query(const apol_policy_t * policy, const options_t * opt,
0fd1802
 
0fd1802
 	apol_filename_trans_query_set_regex(policy, ftq, opt->useregex);
0fd1802
 	if (opt->src_name) {
0fd1802
-		if (apol_filename_trans_query_set_source(policy, ftq, opt->src_name)) {
0fd1802
+		if (apol_filename_trans_query_set_source(policy, ftq, opt->src_name, opt->indirect)) {
0fd1802
 			error = errno;
0fd1802
 			goto err;
0fd1802
 		}
0fd1802
 	}
0fd1802
+
0fd1802
 	if (opt->tgt_name) {
0fd1802
 		if (apol_filename_trans_query_set_target(policy, ftq, opt->tgt_name, opt->indirect)) {
0fd1802
 			error = errno;
0fd1802
 			goto err;
0fd1802
 		}
0fd1802
 	}
0fd1802
+	if (opt->default_name) {
0fd1802
+		if (apol_filename_trans_query_set_default(policy, ftq, opt->default_name)) {
0fd1802
+			error = errno;
0fd1802
+			goto err;
0fd1802
+		}
0fd1802
+	}
0fd1802
+
0fd1802
+	if (opt->class_name) {
0fd1802
+		if (opt->class_vector == NULL) {
0fd1802
+			if (apol_filename_trans_query_append_class(policy, ftq, opt->class_name)) {
0fd1802
+				error = errno;
0fd1802
+				goto err;
0fd1802
+			}
0fd1802
+		} else {
0fd1802
+			for (size_t i = 0; i < apol_vector_get_size(opt->class_vector); ++i) {
0fd1802
+				char *class_name;
0fd1802
+				class_name = apol_vector_get_element(opt->class_vector, i);
0fd1802
+				if (!class_name)
0fd1802
+					continue;
0fd1802
+				if (apol_filename_trans_query_append_class(policy, ftq, class_name)) {
0fd1802
+					error = errno;
0fd1802
+					goto err;
0fd1802
+				}
0fd1802
+			}
0fd1802
+		}
0fd1802
+	}
0fd1802
 
0fd1802
 	if (apol_filename_trans_get_by_query(policy, ftq, v)) {
0fd1802
 		error = errno;
0fd1802
@@ -630,37 +663,36 @@ static int perform_ft_query(const apol_policy_t * policy, const options_t * opt,
0fd1802
 
0fd1802
 static void print_ft_results(const apol_policy_t * policy, const options_t * opt, const apol_vector_t * v)
0fd1802
 {
0fd1802
-	qpol_policy_t *q = apol_policy_get_qpol(policy);
0fd1802
-	size_t i, num_rules = 0;
0fd1802
-	const qpol_filename_trans_t *rule = NULL;
0fd1802
-	char *tmp = NULL, *rule_str = NULL, *expr = NULL;
0fd1802
+	size_t i, num_filename_trans = 0;
0fd1802
+	const qpol_filename_trans_t *filename_trans = NULL;
0fd1802
+	char *tmp = NULL, *filename_trans_str = NULL, *expr = NULL;
0fd1802
 	char enable_char = ' ', branch_char = ' ';
0fd1802
 	qpol_iterator_t *iter = NULL;
0fd1802
 	const qpol_cond_t *cond = NULL;
0fd1802
 	uint32_t enabled = 0, list = 0;
0fd1802
 
0fd1802
-	if (!(num_rules = apol_vector_get_size(v)))
0fd1802
+	if (!(num_filename_trans = apol_vector_get_size(v)))
0fd1802
 		goto cleanup;
0fd1802
 
0fd1802
-	fprintf(stdout, "Found %zd named file transition rules:\n", num_rules);
0fd1802
+	fprintf(stdout, "Found %zd named file transition filename_trans:\n", num_filename_trans);
0fd1802
 
0fd1802
-	for (i = 0; i < num_rules; i++) {
0fd1802
+	for (i = 0; i < num_filename_trans; i++) {
0fd1802
 		enable_char = branch_char = ' ';
0fd1802
-		if (!(rule = apol_vector_get_element(v, i)))
0fd1802
+		if (!(filename_trans = apol_vector_get_element(v, i)))
0fd1802
 			goto cleanup;
0fd1802
 
0fd1802
-		if (!(rule_str = apol_filename_trans_render(policy, rule)))
0fd1802
+		if (!(filename_trans_str = apol_filename_trans_render(policy, filename_trans)))
0fd1802
 			goto cleanup;
0fd1802
-		fprintf(stdout, "%s %s\n", rule_str, expr ? expr : "");
0fd1802
-		free(rule_str);
0fd1802
-		rule_str = NULL;
0fd1802
+		fprintf(stdout, "%s %s\n", filename_trans_str, expr ? expr : "");
0fd1802
+		free(filename_trans_str);
0fd1802
+		filename_trans_str = NULL;
0fd1802
 		free(expr);
0fd1802
 		expr = NULL;
0fd1802
 	}
0fd1802
 
0fd1802
       cleanup:
0fd1802
 	free(tmp);
0fd1802
-	free(rule_str);
0fd1802
+	free(filename_trans_str);
0fd1802
 	free(expr);
0fd1802
 }
0fd1802
 
0fd1802
@@ -930,7 +962,7 @@ int main(int argc, char **argv)
0fd1802
 
0fd1802
 	memset(&cmd_opts, 0, sizeof(cmd_opts));
0fd1802
 	cmd_opts.indirect = true;
0fd1802
-	while ((optc = getopt_long(argc, argv, "ATs:t:c:p:b:dRnSChV", longopts, NULL)) != -1) {
0fd1802
+	while ((optc = getopt_long(argc, argv, "ATs:t:c:p:b:dD:RnSChV", longopts, NULL)) != -1) {
0fd1802
 		switch (optc) {
0fd1802
 		case 0:
0fd1802
 			break;
0fd1802
@@ -946,6 +978,18 @@ int main(int argc, char **argv)
0fd1802
 				exit(1);
0fd1802
 			}
0fd1802
 			break;
0fd1802
+		case 'D':	       /* source */
0fd1802
+			if (optarg == 0) {
0fd1802
+				usage(argv[0], 1);
0fd1802
+				printf("Missing source default type for -D (--default)\n");
0fd1802
+				exit(1);
0fd1802
+			}
0fd1802
+			cmd_opts.default_name = strdup(optarg);
0fd1802
+			if (!cmd_opts.default_name) {
0fd1802
+		
0fd1802
+				exit(1);
0fd1802
+			}
0fd1802
+			break;
0fd1802
 		case 't':	       /* target */
0fd1802
 			if (optarg == 0) {
0fd1802
 				usage(argv[0], 1);
0fd1802
@@ -1218,7 +1262,7 @@ int main(int argc, char **argv)
0fd1802
 		fprintf(stdout, "\n");
0fd1802
 	}
0fd1802
 
0fd1802
-	if (cmd_opts.all || cmd_opts.type == QPOL_RULE_TYPE_TRANS) {
0fd1802
+	if (cmd_opts.all || cmd_opts.type) {
0fd1802
 		apol_vector_destroy(&v);
0fd1802
 		if (perform_ft_query(policy, &cmd_opts, &v)) {
0fd1802
 			rt = 1;
0fd1802
-- 
0fd1802
1.7.6.2
0fd1802