Skip to contentSkip to conversation

Interfaces, more parser things

SEMANAGE Ivan Gyurdiev 1 participant 1 message Nov 2, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

Changes:

- implement interface parse/print functions, and enable interfaces
- rewrite sscanf port parser using parse_utils - better error reporting, and now allows multiline
- simplify boolean parser using new parse_fetch_int helper

- Parser: remove parse_fetch_string.
- Parser: make parse_fetch_string_until the default (rename to parse_fetch_string). Pass ' ', when the delimiter shouldn't do anything.
- Parser: implement new helper parse_fetch_int.
- Parser: fix parse_assert_space to check for EOL (which is _not_ '\n' - it's '\0', at the end of the buffer).

Note: for some reason strtol doesn't seem to do what the manpage says, and does not set *endptr correctly on a string that begins with a number - need to investigate further.

Note: haven't really tested ports yet - but they're disabled right now...

libsemanage/include/semanage/semanage.h +3 -2
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/include/semanage/semanage.h new/libsemanage/include/semanage/semanage.h
@@ -29,8 +29,9 @@
 #include <semanage/boolean_record.h>
 #include <semanage/user_record.h>
 #include <semanage/seuser_record.h>
-#if 0
+#include <semanage/context_record.h>
 #include <semanage/iface_record.h>
+#if 0
 #include <semanage/port_record.h>
 #endif
 
@@ -43,8 +44,8 @@
 #if 0
 #include <semanage/ports_local.h>
 #include <semanage/ports_policy.h>
+#endif
 #include <semanage/interfaces_local.h>
 #include <semanage/interfaces_policy.h>
-#endif
 
 #endif
libsemanage/src/booleans_file.c +17 -28

73 lines not on this page · raw message

libsemanage/src/interfaces_file.c +108 -10

139 lines not on this page · raw message

libsemanage/src/libsemanage.map +1 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/libsemanage.map new/libsemanage/src/libsemanage.map
@@ -10,5 +10,6 @@ LIBSEMANAGE_1.0 {
 	  semanage_module_get_version; semanage_select_store;
 	  semanage_reload_policy; semanage_set_reload;
 	  semanage_user_*; semanage_bool_*; semanage_seuser_*;
+	  semanage_iface_*; semanage_context_*;
   local: *;
 };
libsemanage/src/parse_utils.c +30 -26

77 lines not on this page · raw message

libsemanage/src/parse_utils.h +13 -8
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/parse_utils.h new/libsemanage/src/parse_utils.h
@@ -83,17 +83,22 @@ extern int parse_optional_str(
 	parse_info_t* info, 
 	const char* str);
 
-/* Extract the next string (delimited by 
- * whitespace), and move the read pointer past it */
-extern int parse_fetch_string(
-	semanage_handle_t* handle,
+/* Extract the next integer, and move
+ * the read pointer past it. Stop if
+ * the optional character delim is encountered,
+ * or if whitespace/eof is encountered */
+int parse_fetch_int(
+	semanage_handle_t* hgandle,
 	parse_info_t* info,
-	char** str_ptr);
+	int* num,
+	char delim);
 
 /* Extract the next string (delimited by 
- * the specified character, or whitespace), and move the 
- * read pointer past it */
-extern int parse_fetch_string_until(
+ * whitespace), and move the read pointer past it.
+ * Stop of the optional character delim is encountered,
+ * or if whitespace/eof is encountered. Fail if the
+ * string is of length 0. */
+extern int parse_fetch_string(
 	semanage_handle_t* handle,
 	parse_info_t* info,
 	char** str_ptr,
libsemanage/src/ports_file.c +59 -32

134 lines not on this page · raw message

libsemanage/src/seusers_file.c +3 -3
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/seusers_file.c new/libsemanage/src/seusers_file.c
@@ -56,7 +56,7 @@ static int seuser_parse(
 		goto last;
 
 	/* Extract name */
-	if (parse_fetch_string_until(handle, info, &str, ':') < 0)
+	if (parse_fetch_string(handle, info, &str, ':') < 0)
 		goto err;
 	if (semanage_seuser_set_name(handle, seuser, str) < 0)
 		goto err;
@@ -75,7 +75,7 @@ static int seuser_parse(
 		goto err;
 
 	/* Extract sename */
-	if (parse_fetch_string_until(handle, info, &str, ':') < 0)
+	if (parse_fetch_string(handle, info, &str, ':') < 0)
 		goto err;
 	if (semanage_seuser_set_sename(handle, seuser, str) < 0)
 		goto err;
@@ -95,7 +95,7 @@ static int seuser_parse(
 			goto err;
 
 		/* NOTE: does not allow spaces/multiline */
-		if (parse_fetch_string(handle, info, &str) < 0)
+		if (parse_fetch_string(handle, info, &str, ' ') < 0)
 			goto err;
 
 		if (semanage_seuser_set_mlsrange(handle, seuser, str) <  0)
libsemanage/src/users_file.c +3 -3
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/users_file.c new/libsemanage/src/users_file.c
@@ -89,7 +89,7 @@ static int user_parse(
 		goto err;
 
 	/* Parse user name */
-	if (parse_fetch_string(handle, info, &name_str) < 0)
+	if (parse_fetch_string(handle, info, &name_str, ' ') < 0)
 		goto err;
 
 	if (semanage_user_set_name(handle, user, name_str) < 0) {
@@ -172,7 +172,7 @@ static int user_parse(
 			goto err;
 
 		/* NOTE: does not allow spaces/multiline */
-		if (parse_fetch_string(handle, info, &str) < 0)
+		if (parse_fetch_string(handle, info, &str, ' ') < 0)
 			goto err;
 		if (semanage_user_set_mlslevel(handle, user, str) < 0)
 			goto err;
@@ -190,7 +190,7 @@ static int user_parse(
 			goto err;
 
 		/* NOTE: does not allow spaces/multiline */
-		if (parse_fetch_string_until(handle, info, &str, ';') < 0)
+		if (parse_fetch_string(handle, info, &str, ';') < 0)
 			goto err;
 		if (semanage_user_set_mlsrange(handle, user, str) < 0)
 			goto err;