All of lore.kernel.org
 help / color / mirror / Atom feed
* [ SEMANAGE ] Stub iterate
@ 2005-09-18  1:23 Ivan Gyurdiev
  2005-09-19 19:51 ` Stephen Smalley
  0 siblings, 1 reply; 2+ messages in thread
From: Ivan Gyurdiev @ 2005-09-18  1:23 UTC (permalink / raw)
  To: SELinux List; +Cc: dwalsh

[-- Attachment #1: Type: text/plain, Size: 1934 bytes --]

The attached patch adds the file iterator config structure, and stubs 
iterate().
I actually have a lot of code written, but I can't merge any of it 
before figuring out
what to do with respect to debugging.

Anyway, in the mean time I can stub things out, and describe design.

The dbase_* functions will each fill out the iterator structure,
and invoke iterate(). On a different backend, those functions
wouldn't iterate, but would perform O(1) operations. The add()
function doesn't actually need to iterate - I have an alternative
implementation which seeks to the end of file, but it is not atomic.
I haven't decided which to use - given the sandbox, the non-atomic
implementation might be preferable.

The flat file engine will work by iterating over "records".
Those records are each described by the record table merged last week.
In particular, the table describes how to input (parse) and output (print)
such records. That's how we keep the engine generic by polymorphism.

The iterator will parse each record using the provided function.
It will then pass this record to a processing handler function, which can do
whatever it wants with it, and can send back signals to communicate with
the engine. Do not confuse this processing function with the one
supplied in dbase_iterate - the engine handler has specialized format
and return codes, and I'll be providing those.
 
If config->modify is set to true, a second file is opened, and
each record is printed to it as the original file is parsed. On SIGDEL,
the record is skipped. On SIGADD, the engine reads a feedback record
from the processing handler, and writes that out.  On SIGEXIT or SIGERR
processing is terminated with the appropriate status code (it has to be 
explicit,
otherwise it keeps calling the handler with NULL argument). On SIGOK,
processing continues. If config->merr_fatal is on, and SIGMATCH
was never received by the engine, an error is reported.



[-- Attachment #2: libsemanage.iterate.stub.diff --]
[-- Type: text/x-patch, Size: 4324 bytes --]

diff -Nrua libsemanage/src/database_file.c libsemanage.new/src/database_file.c
--- libsemanage/src/database_file.c	2005-09-14 11:44:44.000000000 -0400
+++ libsemanage.new/src/database_file.c	2005-09-17 21:00:24.000000000 -0400
@@ -41,8 +41,10 @@
 	record_key_t key,
 	record_t data) {
 
+	iterate_config_t config;
+	config.rtable = dconfig->rtable;
+
 	/* Stub */
-	dconfig = NULL;
 	key = NULL;
 	data = NULL;
 	return -1;
@@ -53,8 +55,10 @@
 	record_key_t key,
 	record_t data) {
 
+	iterate_config_t config;
+	config.rtable = dconfig->rtable;
+
 	/* Stub */
-	dconfig = NULL;
 	key = NULL;
 	data = NULL;
 	return -1;
@@ -63,9 +67,11 @@
 int dbase_del(
 	dbase_config_t* dconfig,
 	record_key_t key) {
+
+	iterate_config_t config;
+	config.rtable = dconfig->rtable;
 	
 	/* Stub */
-	dconfig = NULL;
 	key = NULL;
 	return -1;
 }
@@ -74,9 +80,11 @@
 	dbase_config_t* dconfig,
 	record_key_t key,
 	record_t* response) {
+
+	iterate_config_t config;
+	config.rtable = dconfig->rtable;
 	
 	/* Stub */
-	dconfig = NULL;
 	key = NULL;
 	response = NULL;
 	return -1;
@@ -86,9 +94,11 @@
 	dbase_config_t* dconfig,
 	record_key_t key,
 	int* response) {
+
+	iterate_config_t config;
+	config.rtable = dconfig->rtable;
 	
 	/* Stub */
-	dconfig = NULL;
 	key = NULL;
 	response = NULL;
 	return -1;
@@ -98,8 +108,10 @@
 	dbase_config_t* dconfig,
 	int* response) {
 	
+	iterate_config_t config;
+	config.rtable = dconfig->rtable;
+
 	/* Stub */
-	dconfig = NULL;
 	response = NULL;
 	return -1;
 }
@@ -111,8 +123,10 @@
 	                void* varg),
 	void* handler_arg) {
 
+	iterate_config_t config;
+	config.rtable = dconfig->rtable;
+
 	/* Stub */
-	dconfig = NULL;
 	handler = NULL;
 	handler_arg = NULL;
 	return -1;
@@ -124,9 +138,10 @@
 	record_t** dataset,	
 	size_t* count) {
 
-	
+	iterate_config_t config;
+	config.rtable = dconfig->rtable;
+
 	/* Stub */
-	dconfig = NULL;
 	keyset = NULL;
 	dataset = NULL;
 	count = NULL;
diff -Nrua libsemanage/src/record_file.c libsemanage.new/src/record_file.c
--- libsemanage/src/record_file.c	1969-12-31 19:00:00.000000000 -0500
+++ libsemanage.new/src/record_file.c	2005-09-17 20:50:42.000000000 -0400
@@ -0,0 +1,8 @@
+#include "record_file.h"
+
+int record_iterate_file(iterate_config_t* config) {
+
+	/* Stub */
+	config = NULL;
+	return 0;
+}
diff -Nrua libsemanage/src/record_file.h libsemanage.new/src/record_file.h
--- libsemanage/src/record_file.h	2005-09-14 11:44:44.000000000 -0400
+++ libsemanage.new/src/record_file.h	2005-09-17 20:50:46.000000000 -0400
@@ -9,6 +9,14 @@
 #define RECORD_DEFINED
 #endif
 
+/* Signals available to handlers during processing. */
+#define RECORD_HANDLER_SIGOK    0x00000001 /* Continue */
+#define RECORD_HANDLER_SIGERR   0x00000002 /* Exit with error */
+#define RECORD_HANDLER_SIGMATCH 0x00000004 /* Match is found */
+#define RECORD_HANDLER_SIGDEL   0x00000008 /* Delete current record */
+#define RECORD_HANDLER_SIGADD   0x00000010 /* Add feedback record */
+#define RECORD_HANDLER_SIGEXIT  0x00000020 /* Exit successfully */
+
 /* Structure available during parsing (created internally) */
 typedef struct parse_info {
 	/* Stub */	
@@ -44,4 +52,33 @@
 	void (*free) (record_t rec);
 } record_table_t;
 
+/* Structure to configure iterate */
+typedef struct iterate_config {
+
+	/* What and How? */
+	const char* filename;            /* Filename to process */
+	record_table_t* rtable;		 /* Table that describes how to do that */
+
+	/* Parsing stage */
+	void* parse_arg;                 /* Argument to pass to parser */
+	int perr_fatal;                  /* Is parse error fatal ? */
+
+	/* Processing stage */
+	int (*handler) (                  /* Processing handler */
+		record_t process_record,      /* Current record, or NULL */
+		record_t* feedback_record,    /* Record for SIGADD */
+		void* arg);                   /* Caller supplied argument */
+	void* handler_arg;                /* Argument to pass to handler */
+	int modify;                       /* Will the handler issue 
+					   * modification signals */
+	/* Post-processing */
+	int merr_fatal;                   /* Is lack of SIGMATCH fatal? */
+} iterate_config_t;
+
+/*
+ * Iterate over all records in the given file,
+ * subject to the provided parse and processing config.
+ */
+extern int record_iterate_file(iterate_config_t* config);
+
 #endif 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [ SEMANAGE ] Stub iterate
  2005-09-18  1:23 [ SEMANAGE ] Stub iterate Ivan Gyurdiev
@ 2005-09-19 19:51 ` Stephen Smalley
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Smalley @ 2005-09-19 19:51 UTC (permalink / raw)
  To: Ivan Gyurdiev; +Cc: SELinux List, dwalsh

On Sat, 2005-09-17 at 21:23 -0400, Ivan Gyurdiev wrote:
> The attached patch adds the file iterator config structure, and stubs 
> iterate().
> I actually have a lot of code written, but I can't merge any of it 
> before figuring out
> what to do with respect to debugging.

Thanks, merged.  

-- 
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-09-19 19:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-18  1:23 [ SEMANAGE ] Stub iterate Ivan Gyurdiev
2005-09-19 19:51 ` Stephen Smalley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.