SETools patch: adding exclude type feature in queries
Hi all
i developed a patch that allows to specify a type or an attribute to be excluded either from source and target criteria of a policy query performed with the 'sesearch' command line tool.
This patch is in a initial state, it works only for AV semantic queries and applies on 'setools' source from the Fedora 13 rpm:
setools-3.3.7-7.fc13.src.rpm
libapol/include/apol/avrule-query.h +4 -0
@@ -123,6 +123,8 @@ extern "C"*/ extern int apol_avrule_query_set_source (const apol_policy_t * p,apol_avrule_query_t * a,const char *symbol,int is_indirect); +extern int apol_avrule_query_set_source_neg (const apol_policy_t * p,apol_avrule_query_t * a,const char *symbol, +int is_indirect);/** * Set an avrule query to return rules whose source symbol is matched as a type
@@ -158,6 +160,8 @@ extern "C"*/ extern int apol_avrule_query_set_target (const apol_policy_t * p,apol_avrule_query_t * a,const char *symbol,int is_indirect); +extern int apol_avrule_query_set_target_neg (const apol_policy_t * p,apol_avrule_query_t * a,const char *symbol, +int is_indirect);/** * Set an avrule query to return rules whose target symbol is matched as a type
libapol/src/avrule-query.c +63 -11
177 lines not on this page · raw message
secmds/sesearch.c +37 -1
@@ -72,6 +72,8 @@ static struct option const longopts[] = {"source", required_argument, NULL, 's'}, {"target", required_argument, NULL, 't'}, + {"source-neg", required_argument, NULL, 'u'}, + {"target-neg", required_argument, NULL, 'v'}, {"role_source", required_argument, NULL, EXPR_ROLE_SOURCE}, {"role_target", required_argument, NULL, EXPR_ROLE_TARGET}, {"class", required_argument, NULL, 'c'},
@@ -92,6 +94,8 @@ typedef struct options {char *src_name;char *tgt_name; +char *srcneg_name; +char *tgtneg_name;char *src_role_name;char *tgt_role_name;char *class_name;
@@ -136,6 +140,8 @@ void usage(const char *program_name, intprintf ("EXPRESSIONS:\n" );printf (" -s NAME, --source=NAME rules with type/attribute NAME as source\n" );printf (" -t NAME, --target=NAME rules with type/attribute NAME as target\n" ); +printf (" -u NAME,--source-neg=NAME rules without type/attribute NAME as source\n" ); +printf (" -v NAME,--target-neg=NAME rules without type/attribute NAME as target\n" );printf (" --role_source=NAME rules with role NAME as source\n" );printf (" --role_target=NAME rules with role NAME as target\n" );printf (" -c NAME, --class=NAME rules with class NAME as the object class\n" );
@@ -197,6 +203,10 @@ static int perform_av_query(const apol_papol_avrule_query_set_source (policy, avq, opt->src_name, opt->indirect);if (opt->tgt_name)apol_avrule_query_set_target (policy, avq, opt->tgt_name, opt->indirect); +if (opt->srcneg_name) +apol_avrule_query_set_source_neg (policy, avq, opt->srcneg_name, opt->indirect); +if (opt->tgtneg_name) +apol_avrule_query_set_target_neg (policy, avq, opt->tgtneg_name, opt->indirect);if (opt->bool_name)apol_avrule_query_set_bool (policy, avq, opt->bool_name);if (opt->class_name) {
@@ -841,7 +851,7 @@ int main(int argc, char **argv)memset (&cmd_opts,0 ,sizeof (cmd_opts)); cmd_opts.indirect = true; -while ((optc =getopt_long (argc, argv,"ATs:t:c:p:b:dRnSChV" , longopts,NULL )) !=-1 ) { +while ((optc =getopt_long (argc, argv,"ATs:t:u:v:c:p:b:dRnSChV" , longopts,NULL )) !=-1 ) {switch (optc) {case 0 :break ;
@@ -869,6 +879,30 @@ int main(int argc, char **argv)exit (1 ); }break ; +case 'u' :/* source (negated) */ +if (optarg ==0 ) { +usage (argv[0 ],1 ); +printf ("Missing source type/attribute for -u (--source-neg)\n" ); +exit (1 ); + } + cmd_opts.srcneg_name =strdup (optarg); +if (!cmd_opts.srcneg_name) { +fprintf (stderr,"%s\n" ,strerror (errno)); +exit (1 ); + } +break ; +case 'v' :/* target (negated) */ +if (optarg ==0 ) { +usage (argv[0 ],1 ); +printf ("Missing target type/attribute for -v (--target-neg)\n" ); +exit (1 ); + } + cmd_opts.tgtneg_name =strdup (optarg); +if (!cmd_opts.tgtneg_name) { +fprintf (stderr,"%s\n" ,strerror (errno)); +exit (1 ); + } +break ;case EXPR_ROLE_SOURCE :if (optarg ==0 ) {usage (argv[0 ],1 );
@@ -1162,6 +1196,8 @@ int main(int argc, char **argv)apol_policy_path_destroy (&pol_path);free (cmd_opts.src_name);free (cmd_opts.tgt_name); +free (cmd_opts.srcneg_name); +free (cmd_opts.tgtneg_name);free (cmd_opts.class_name);free (cmd_opts.permlist);free (cmd_opts.bool_name);