All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ivan Gyurdiev <ivg2@cornell.edu>
To: SELinux List <SELinux@tycho.nsa.gov>
Cc: dwalsh@redhat.com, jbrindle@tresys.com
Subject: Re: [ SEMANAGE ] Introduce record table
Date: Mon, 12 Sep 2005 10:14:32 -0400	[thread overview]
Message-ID: <43258D48.80702@cornell.edu> (raw)
In-Reply-To: <43256F48.7060909@cornell.edu>

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

The attached patch applies on top of the other one.
It introduces the record table as the first thing
which will be stored in the database config (a database config
stores parameters specific to a database (a.k.a. file))

To clarify how this works - there's two sets of files here - one
that works with generic record_t/record_key_t objects (treated as void*),
and one that works with specific types that replace record_t/record_key_t.
This essentially implements inheritance, which allows sharing of a lot of
code (not yet merged). It's also a bit tricky to get it working, because we
must keep track of where the specific types are defined.

The record table stores a set of functions which correspond
to the record headers previously merged. It defines how certain
operations are done for each particular type of record. In addition, it 
provides
some functions specific to the FILE backend. This table will
be used by the file engine for polymorphism - it will work with
the generic record types, but will be invoking the specific functions for
each record based on what the table says.

Regarding database_init/close - those need to be integrated somewhere.. 
likely
on CONNECT/DISCONNECT...but I haven't done that yet..and it might change
once semanage_handle_t appears.

[-- Attachment #2: libsemanage.rtable.diff --]
[-- Type: text/x-patch, Size: 5462 bytes --]

diff -Naur libsemanage/src/database_file.c libsemanage.new/src/database_file.c
--- libsemanage/src/database_file.c	2005-09-12 09:56:33.000000000 -0400
+++ libsemanage.new/src/database_file.c	2005-09-12 09:49:33.000000000 -0400
@@ -1,13 +1,41 @@
 #include <stdlib.h>
 #include <stddef.h>
 #include "database.h"
+#include "record_file.h"
+#include "users_file.h"
+#include "ports_file.h"
 
 struct dbase_config {
-	/* Stub */
+	record_table_t* rtable;
 };
 
 dbase_config_t* dbase[DBASE_COUNT];
 
+int dbase_init() {
+	int i;
+	for (i = 0; i < DBASE_COUNT; i++) {
+		dbase[i] = (dbase_config_t*) malloc(sizeof(dbase_config_t));
+		if (dbase[i] == NULL) 
+			goto err;
+	}
+
+	dbase[DBASE_USERS]->rtable = &RTABLE_USER;
+	dbase[DBASE_PORTS]->rtable = &RTABLE_PORT; 	
+
+	return 0;
+	
+	err:
+	for (i--; i >= 0; i--) 
+		free(dbase[i]);
+	return -1;
+}	
+
+void dbase_close() {
+	int i;
+	for (i = 0; i < DBASE_COUNT; i++)
+		free(dbase[i]);
+}
+
 int dbase_add(
 	dbase_config_t* dconfig,
 	record_key_t key,
diff -Naur libsemanage/src/ports_file.c libsemanage.new/src/ports_file.c
--- libsemanage/src/ports_file.c	1969-12-31 19:00:00.000000000 -0500
+++ libsemanage.new/src/ports_file.c	2005-09-12 09:51:39.000000000 -0400
@@ -0,0 +1,42 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <semanage/port_record.h>
+
+typedef semanage_port_t record_t;
+typedef semanage_port_key_t record_key_t;
+#define RECORD_DEFINED
+#include "record_file.h"
+
+static int semanage_port_print(
+	semanage_port_t port, 
+	FILE* str) {
+
+	/* Stub */
+	port = NULL;
+	str = NULL;
+	return -1;
+}
+
+static int semanage_port_parse(
+	parse_info_t* info, 
+	semanage_port_t port) {
+
+	/* Stub */
+	info = NULL;
+	port = NULL;
+	return -1;	
+}
+
+record_table_t RTABLE_PORT = {
+	/* Record base functions */
+	.create      = semanage_port_create,
+	.key_extract = semanage_port_key_extract,
+	.key_free    = semanage_port_key_free,
+	.clone       = semanage_port_clone,
+	.compare     = semanage_port_compare,
+	.free        = semanage_port_free,
+
+	/* Record functions for FILE backend */
+	.parse       = semanage_port_parse,
+	.print       = semanage_port_print,
+};
diff -Naur libsemanage/src/ports_file.h libsemanage.new/src/ports_file.h
--- libsemanage/src/ports_file.h	1969-12-31 19:00:00.000000000 -0500
+++ libsemanage.new/src/ports_file.h	2005-09-12 09:51:10.000000000 -0400
@@ -0,0 +1,8 @@
+#ifndef _SEMANAGE_PORTS_FILE_H_
+#define _SEMANAGE_PORTS_FILE_H_
+
+#include "record_file.h"
+
+extern record_table_t RTABLE_PORT;
+
+#endif 
diff -Naur libsemanage/src/record_file.h libsemanage.new/src/record_file.h
--- libsemanage/src/record_file.h	1969-12-31 19:00:00.000000000 -0500
+++ libsemanage.new/src/record_file.h	2005-09-12 09:38:06.000000000 -0400
@@ -0,0 +1,47 @@
+#ifndef _SEMANAGE_RECORD_FILE_H_
+#define _SEMANAGE_RECORD_FILE_H_
+
+#include <stdio.h>
+
+#ifndef RECORD_DEFINED
+typedef void* record_t;
+typedef void* record_key_t;
+#define RECORD_DEFINED
+#endif
+
+/* Structure available during parsing (created internally) */
+typedef struct parse_info {
+	/* Stub */	
+} parse_info_t;
+
+/* Record table format - necessary during processing */
+typedef struct record_table {
+
+	/* Create a record */
+	int (*create) (record_t* rec);
+
+	/* Extract key from record */
+	int (*key_extract) (record_t rec, record_key_t* key);
+	
+	/* Free record key */
+	int (*key_free) (record_key_t key);
+
+	/* Return 0 if record can be matched against key,
+	 * and 1 otherwise */
+	int (*compare) (record_t rec, record_key_t key);
+
+	/* Deep-copy clone of this record */
+	int (*clone) (record_t rec, record_t* new_rec);
+
+	/* Fill record structuure based on supplied parse info */
+	int (*parse) (parse_info_t* info, record_t record);
+
+	/* Print record to stream */
+	int (*print) (record_t record, FILE* str);
+
+	/* Deallocate record resources. Must
+	 * sucessfully handle NULL. */
+	void (*free) (record_t rec);
+} record_table_t;
+
+#endif 
diff -Naur libsemanage/src/users_file.c libsemanage.new/src/users_file.c
--- libsemanage/src/users_file.c	1969-12-31 19:00:00.000000000 -0500
+++ libsemanage.new/src/users_file.c	2005-09-12 09:51:52.000000000 -0400
@@ -0,0 +1,42 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <semanage/user_record.h>
+
+typedef semanage_user_t record_t;
+typedef semanage_user_key_t record_key_t;
+#define RECORD_DEFINED
+#include "record_file.h"
+
+static int semanage_user_print(
+	semanage_user_t user, 
+	FILE* str) {
+
+	/* Stub */
+	user = NULL;
+	str = NULL;
+	return -1;
+}
+
+static int semanage_user_parse(
+	parse_info_t* info, 
+	semanage_user_t user) {
+
+	/* Stub */
+	info = NULL;
+	user = NULL;
+	return -1;	
+}
+
+record_table_t RTABLE_USER = {
+	/* Record base functions */
+	.create      = semanage_user_create,
+	.key_extract = semanage_user_key_extract,
+	.key_free    = semanage_user_key_free,
+	.clone       = semanage_user_clone,
+	.compare     = semanage_user_compare,
+	.free        = semanage_user_free,
+
+	/* Record functions for FILE backend */
+	.parse       = semanage_user_parse,
+	.print       = semanage_user_print,
+};
diff -Naur libsemanage/src/users_file.h libsemanage.new/src/users_file.h
--- libsemanage/src/users_file.h	1969-12-31 19:00:00.000000000 -0500
+++ libsemanage.new/src/users_file.h	2005-09-12 09:49:53.000000000 -0400
@@ -0,0 +1,8 @@
+#ifndef _SEMANAGE_USERS_FILE_H_
+#define _SEMANAGE_USERS_FILE_H_
+
+#include "record_file.h"
+
+extern record_table_t RTABLE_USER;
+
+#endif 

  reply	other threads:[~2005-09-12 14:14 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-12 12:06 [ SEMANAGE ] Stub out user/port functionality Ivan Gyurdiev
2005-09-12 14:14 ` Ivan Gyurdiev [this message]
2005-09-13  3:55   ` [ SEPOL ] Move more things to newer debug system Ivan Gyurdiev
2005-09-13 19:59     ` Stephen Smalley
2005-09-13 22:26       ` Ivan Gyurdiev
2005-09-13 23:03         ` Joshua Brindle
2005-09-14  3:33           ` Ivan Gyurdiev
2005-09-14  3:37             ` Ivan Gyurdiev
2005-09-14 13:16               ` Stephen Smalley
2005-09-14 14:05                 ` Dale Amon
2005-09-14 18:07                   ` Stephen Smalley
2005-09-14 23:44                     ` Dale Amon
2005-09-14  7:00             ` Luke Kenneth Casson Leighton
2005-09-14 12:11               ` Stephen Smalley
2005-09-14  7:01             ` Luke Kenneth Casson Leighton
2005-09-14 13:00             ` Stephen Smalley
2005-09-14 13:21               ` Joshua Brindle
2005-09-14 13:51                 ` Stephen Smalley
2005-09-14 14:45                   ` Joshua Brindle
2005-09-14 15:04                     ` Stephen Smalley
2005-09-14 15:26                       ` info on SELinux support for IPSEC Prakash Saivasan
2005-09-14 18:20                         ` Stephen Smalley
2005-09-14 15:33                       ` [ SEPOL ] Move more things to newer debug system Joshua Brindle
2005-09-14 15:38                         ` Stephen Smalley
2005-09-14 16:06                           ` Joshua Brindle
2005-09-14 16:24                             ` Stephen Smalley
2005-09-14 17:16                               ` Ivan Gyurdiev
2005-09-14 17:21                                 ` Ivan Gyurdiev
2005-09-14 18:53                                 ` Stephen Smalley
2005-09-16 13:48                                 ` Luke Kenneth Casson Leighton
2005-09-14 19:37                             ` Ivan Gyurdiev
2005-09-14 19:50                               ` Stephen Smalley
2005-09-14 20:01                                 ` Stephen Smalley
2005-09-14 20:32                                 ` Ivan Gyurdiev
2005-09-15  7:31                                   ` Ivan Gyurdiev
2005-09-15 12:22                                     ` Stephen Smalley
2005-09-15 13:01                                     ` Stephen Smalley
2005-09-15 15:17                               ` Stephen Smalley
2005-09-15 16:03                                 ` Ivan Gyurdiev
2005-09-16 12:19                                   ` Stephen Smalley
2005-09-18  3:14                                     ` Ivan Gyurdiev
2005-09-16 13:45                               ` Luke Kenneth Casson Leighton
2005-09-16 13:55                           ` Luke Kenneth Casson Leighton
2005-09-18  3:16                           ` Ivan Gyurdiev
2005-09-18  3:52                             ` Ivan Gyurdiev
2005-09-18 15:45                               ` Ivan Gyurdiev
2005-09-19 12:49                               ` Stephen Smalley
2005-09-19 14:05                                 ` Ivan Gyurdiev
2005-09-19 14:45                                   ` Stephen Smalley
2005-09-19 16:24                                     ` Ivan Gyurdiev
2005-09-19 16:49                                       ` Stephen Smalley
2005-09-19 17:16                                         ` Ivan Gyurdiev
2005-09-19 18:26                                           ` Stephen Smalley
2005-09-14 19:57                     ` Ivan Gyurdiev
2005-09-14 12:35         ` Stephen Smalley
2005-09-14 15:51     ` Stephen Smalley
2005-09-13 19:43   ` [ SEMANAGE ] Introduce record table Stephen Smalley
2005-09-13 22:15     ` Ivan Gyurdiev
2005-09-13 22:46       ` Ivan Gyurdiev
2005-09-14 15:46   ` Stephen Smalley
2005-09-14 15:45 ` [ SEMANAGE ] Stub out user/port functionality Stephen Smalley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43258D48.80702@cornell.edu \
    --to=ivg2@cornell.edu \
    --cc=SELinux@tycho.nsa.gov \
    --cc=dwalsh@redhat.com \
    --cc=jbrindle@tresys.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.