1. seandroid
  2. Untitled project
  3. external/sepolicy

Commits

William Roberts  committed 9dbb7de

Support strict duplicate checking

Change-Id: I3bb4755b86a90414a3912c8099dd7a4389249b24

  • Participants
  • Parent commits d334b17
  • Branches seandroid, seandroid-4.0.4 4
    1. seandroid-4.1
    2. seandroid-4.2
    3. seandroid-4.3
    4. seandroid-4.4

Comments (0)

Files changed (1)

File tools/check_seapp.c

View file
 /** Set to !0 to enable verbose logging */
 static int logging_verbose = 0;
 
+/** set to !0 to enable strict checking of duplicate entries */
+static int is_strict = 0;
+
 /** file handle to the output file */
 static FILE *output_file = NULL;
 
 
 	/*
 	 * If their is no policy file present,
-	 * then it is not in strict mode so just return.
+	 * then it is not going to enforce the types against the policy so just return.
 	 * User and name cannot really be checked.
 	 */
 	if (!pol.policy_file) {
 		        "and allows later declarations to override previous ones on a match.\n"
 		        "Options:\n"
 		        "-h - print this help message\n"
+			"-s - enable strict checking of duplicates. This causes the program to exit on a duplicate entry\n"
 		        "-v - enable verbose debugging informations\n"
-		        "-p policy file - specify policy file for strict checking of output selectors\n"
+		        "-p policy file - specify policy file for strict checking of output selectors against the policy\n"
 		        "-o output file - specify output file, default is stdout\n");
 }
 
 	int c;
 	int num_of_args;
 
-	while ((c = getopt(argc, argv, "ho:p:v")) != -1) {
+	while ((c = getopt(argc, argv, "ho:p:sv")) != -1) {
 		switch (c) {
 		case 'h':
 			usage();
 		case 'p':
 			pol.policy_file_name = optarg;
 			break;
+		case 's':
+			is_strict = 1;
+			break;
 		case 'v':
 			log_set_verbose();
 			break;
 				log_error(
 						"Unknown option character `\\x%x'.\n",
 						optopt);
-				exit(EXIT_FAILURE);
 			}
-			break;
 		default:
 			exit(EXIT_FAILURE);
 		}
 		}
 		/* Duplicate */
 		else {
-			log_error("Duplicate line detected in file: %s\n"
+			/* if is_strict is set, then don't allow duplicates */
+			if(is_strict) {
+				log_error("Duplicate line detected in file: %s\n"
+					"Lines %d and %d match!\n",
+					out_file_name, tmp->r->lineno, rm->lineno);
+				rule_map_free(rm, rule_map_destroy_key);
+				goto err;
+			}
+
+			/* Allow duplicates, just drop the entry*/
+			log_info("Duplicate line detected in file: %s\n"
 					"Lines %d and %d match!\n",
 					out_file_name, tmp->r->lineno, rm->lineno);
 			rule_map_free(rm, rule_map_destroy_key);
-			goto err;
 		}
 	}
 	/* It wasn't found, just add the rule map to the table */