All of lore.kernel.org
 help / color / mirror / Atom feed
From: jbrindle@tresys.com
To: selinux@tycho.nsa.gov
Subject: [PATCH 22/33] libsemanage: module serialization
Date: Mon, 23 Apr 2007 17:35:17 -0400	[thread overview]
Message-ID: <20070423213741.907065000@tresys.com> (raw)
In-Reply-To: 20070423213455.741326000@tresys.com

---
 libsemanage/include/semanage/modules.h |   11 ++
 libsemanage/src/libsemanage.map        |    1 
 libsemanage/src/module_internal.h      |    3 
 libsemanage/src/modules.c              |  148 +++++++++++++++++++++++++++++++--
 4 files changed, 155 insertions(+), 8 deletions(-)

Index: selinux-pms-support/libsemanage/include/semanage/modules.h
===================================================================
--- selinux-pms-support.orig/libsemanage/include/semanage/modules.h
+++ selinux-pms-support/libsemanage/include/semanage/modules.h
@@ -21,6 +21,7 @@
 #ifndef _SEMANAGE_MODULES_H_
 #define _SEMANAGE_MODULES_H_
 
+#include <inttypes.h>
 #include <stddef.h>
 #include <semanage/handle.h>
 
@@ -48,4 +49,14 @@ semanage_module_info_t *semanage_module_
 const char *semanage_module_get_name(semanage_module_info_t *);
 const char *semanage_module_get_version(semanage_module_info_t *);
 
+int semanage_module_list_serialize(semanage_handle_t * handle,
+				   char **data,
+				   uint64_t * size);
+
+int semanage_module_list_unserialize(semanage_handle_t * handle,
+	char **data,
+	uint64_t *size,
+	semanage_module_info_t ** modules,
+	int *num_modules);
+
 #endif
Index: selinux-pms-support/libsemanage/src/libsemanage.map
===================================================================
--- selinux-pms-support.orig/libsemanage/src/libsemanage.map
+++ selinux-pms-support/libsemanage/src/libsemanage.map
@@ -7,6 +7,7 @@ LIBSEMANAGE_1.0 {
 	  semanage_module_install_base; semanage_module_remove;
 	  semanage_module_list; semanage_module_info_datum_destroy;
 	  semanage_module_list_nth; semanage_module_get_name;
+	  semanage_module_list_serialize; semanage_module_list_unserialize;
 	  semanage_module_get_version; semanage_select_store;
 	  semanage_reload_policy; semanage_set_reload; semanage_set_rebuild;
 	  semanage_user_*; semanage_bool_*; semanage_seuser_*;
Index: selinux-pms-support/libsemanage/src/module_internal.h
===================================================================
--- selinux-pms-support.orig/libsemanage/src/module_internal.h
+++ selinux-pms-support/libsemanage/src/module_internal.h
@@ -8,4 +8,7 @@ hidden_proto(semanage_module_get_name)
     hidden_proto(semanage_module_get_version)
     hidden_proto(semanage_module_info_datum_destroy)
     hidden_proto(semanage_module_list_nth)
+    hidden_proto(semanage_module_list_serialize)
+    hidden_proto(semanage_module_list_unserialize)
+
 #endif
Index: selinux-pms-support/libsemanage/src/modules.c
===================================================================
--- selinux-pms-support.orig/libsemanage/src/modules.c
+++ selinux-pms-support/libsemanage/src/modules.c
@@ -1,7 +1,8 @@
-/* Author: Joshua Brindle <jbrindle@tresys.co
- *	   Jason Tang	  <jtang@tresys.com>
+/* Author: Joshua Brindle       <jbrindle@tresys.com>
+ *         Jason Tang           <jtang@tresys.com>
+ *         Christopher Ashworth <cashworth@tresys.com>
  *
- * Copyright (C) 2004-2005 Tresys Technology, LLC
+ * Copyright (C) 2004-2007 Tresys Technology, LLC
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -20,18 +21,24 @@
 
 /* This file implements only the publicly-visible module functions to libsemanage. */
 
-#include "direct_api.h"
-#include "semanage_conf.h"
-#include "semanage_store.h"
-
 #include <stdarg.h>
 #include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <limits.h>
 
+#include "direct_api.h"
+#include "semanage_conf.h"
+#include "semanage_store.h"
+#include "handle_internal.h"
 #include "handle.h"
 #include "modules.h"
 #include "debug.h"
+#include "byteswap.h"
+#include "serialize.h"
 
 int semanage_module_install(semanage_handle_t * sh,
 			    char *module_data, size_t data_len)
@@ -120,6 +127,131 @@ int semanage_module_list(semanage_handle
 	return sh->funcs->list(sh, modinfo, num_modules);
 }
 
+/* serialize a list of modules into a string, for sending over the wire.
+ * this function (and the corresponding unserialize function) will have to be
+ * able to handle changes to semanage_module_info_t since it is opaque.
+ * caller is responsible for freeing results
+ */
+int semanage_module_list_serialize(semanage_handle_t * handle,
+				   char **data,
+				   uint64_t * size)
+{
+	int status = STATUS_SUCCESS;
+	const char *name = NULL;
+	const char *version = NULL;
+	int i;
+	semanage_module_info_t * modules = NULL;
+	semanage_module_info_t * module = NULL;
+	int modules_size;
+	char *ptr = NULL;
+
+	/* Get the modules. */
+	status = semanage_module_list(handle, &modules, &modules_size);
+	if (status < 0)
+		goto cleanup;
+
+	/* Number of modules. */
+	status = semanage_serialize(handle, &modules_size, 0, SEMANAGE_SERIAL_UINT32_T, data, size);
+	if (status != STATUS_SUCCESS)
+		goto cleanup;
+
+	for (i = 0; i < modules_size; i++) {
+		module = semanage_module_list_nth(modules, i);
+
+		/* Module name. */
+		name = semanage_module_get_name(module);
+		status = semanage_serialize(handle, name, (name == NULL) ? 0 : strlen(name), SEMANAGE_SERIAL_STRING, NULL, size);
+		if (status != STATUS_SUCCESS)
+			goto cleanup;
+
+		/* Module version. */
+		version = semanage_module_get_version(module);
+		status = semanage_serialize(handle, version, (version == NULL) ? 0 : strlen(version), SEMANAGE_SERIAL_STRING, NULL, size);
+		if (status != STATUS_SUCCESS)
+			goto cleanup;
+	}
+
+	*data = calloc(*size, sizeof(char));
+	if (*data == NULL) {
+		status = STATUS_ERR;
+		goto cleanup;
+	}
+
+	ptr = *data;
+
+	/* Number of modules. */
+	status = semanage_serialize(handle, &modules_size, 0, SEMANAGE_SERIAL_UINT32_T, &ptr, NULL);
+	if (status != STATUS_SUCCESS)
+		goto cleanup;
+
+	for (i = 0; i < modules_size; i++) {
+		module = semanage_module_list_nth(modules, i);
+
+		/* Module name. */
+		name = semanage_module_get_name(module);
+		status = semanage_serialize(handle, name, (name == NULL) ? 0 : strlen(name), SEMANAGE_SERIAL_STRING, &ptr, NULL);
+		if (status != STATUS_SUCCESS)
+			goto cleanup;
+
+		/* Module version. */
+		version = semanage_module_get_version(module);
+		status = semanage_serialize(handle, version, (version == NULL) ? 0 : strlen(version), SEMANAGE_SERIAL_STRING, &ptr, NULL);
+		if (status != STATUS_SUCCESS)
+			goto cleanup;
+	}
+
+	/* Cleanup. */
+cleanup:
+	free(modules);
+	return status;
+}
+
+hidden_def(semanage_module_list_serialize)
+
+	/* unserialize a list of modules from a string that has been received over the wire.
+	 * caller is responsible for freeing modules.
+	 * NOTE: *data is modified by this function.
+	 */
+int semanage_module_list_unserialize(semanage_handle_t * handle,
+		char **data,
+		uint64_t *size,
+		semanage_module_info_t ** modules,
+		int *modules_size)
+{
+	int status = STATUS_SUCCESS;
+	int i;
+	size_t *temp_size = NULL;
+
+	/* Number of modules. */
+	status = semanage_unserialize(handle, data, size, (void **)&temp_size, NULL, SEMANAGE_SERIAL_UINT32_T);
+	if (status != STATUS_SUCCESS)
+		goto cleanup;
+	*modules_size = *temp_size;
+
+	*modules = calloc(*modules_size, sizeof(**modules));
+	if (*modules == NULL)
+		goto cleanup;
+
+	for (i = 0; i < *modules_size; i++) {
+		/* Module name. */
+		status = semanage_unserialize(handle, data, size, (void **)&(*modules)[i].name, &temp_size, SEMANAGE_SERIAL_STRING);
+		if (status != STATUS_SUCCESS)
+			goto cleanup;
+
+		/* Module version. */
+		status = semanage_unserialize(handle, data, size, (void **)&(*modules)[i].version, &temp_size, SEMANAGE_SERIAL_STRING);
+		if (status != STATUS_SUCCESS)
+			goto cleanup;
+	}
+
+	/* Cleanup. */
+cleanup:
+	free(temp_size);
+	return status;
+}
+
+hidden_def(semanage_module_list_unserialize)
+
 void semanage_module_info_datum_destroy(semanage_module_info_t * modinfo)
 {
 	if (modinfo != NULL) {
@@ -131,7 +263,7 @@ void semanage_module_info_datum_destroy(
 hidden_def(semanage_module_info_datum_destroy)
 
 semanage_module_info_t *semanage_module_list_nth(semanage_module_info_t * list,
-						 int n)
+		int n)
 {
 	return list + n;
 }

-- 

--
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.

  parent reply	other threads:[~2007-04-24 18:30 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-23 21:34 [PATCH 00/33] libsemanage/libsepol object serialization and ps-api jbrindle
2007-04-23 21:34 ` [PATCH 01/33] libsepol: basic serilization support jbrindle
2007-04-24 20:00   ` Karl MacMillan
2007-04-24 22:29     ` Joshua Brindle
2007-04-25  4:49       ` Karl MacMillan
2007-04-25 14:14         ` Joshua Brindle
2007-04-25 15:16           ` Karl MacMillan
2007-04-25 15:21             ` Joshua Brindle
2007-04-25 15:40               ` Karl MacMillan
2007-04-25 15:52                 ` Joshua Brindle
2007-04-25 16:00                   ` Karl MacMillan
2007-04-25 16:25                     ` Joshua Brindle
2007-04-25 17:11                       ` James Antill
2007-04-25 18:08                         ` Karl MacMillan
2007-04-23 21:34 ` [PATCH 02/33] libsepol: boolean serialization jbrindle
2007-04-25  4:56   ` Karl MacMillan
2007-04-23 21:34 ` [PATCH 03/33] libsepol: context serialization jbrindle
2007-04-23 21:34 ` [PATCH 04/33] libsepol: interface serialization jbrindle
2007-04-23 21:35 ` [PATCH 05/33] libsepol: node serialization jbrindle
2007-04-23 21:35 ` [PATCH 06/33] libsepol: port serialization jbrindle
2007-04-23 21:35 ` [PATCH 07/33] libsepol: user serialization jbrindle
2007-04-23 21:35 ` [PATCH 08/33] libsemanage: DESTDIR support in INCLUDE and safe test target jbrindle
2007-04-23 21:35 ` [PATCH 09/33] libsemanage: dbase/dconfig cleanup jbrindle
2007-04-23 21:35 ` [PATCH 10/33] libsemanage: database serialization jbrindle
2007-04-23 21:35 ` [PATCH 11/33] libsemanage: endianness macros jbrindle
2007-04-23 21:35 ` [PATCH 12/33] libsemanage: basic serialization jbrindle
2007-04-24 21:16   ` Karl MacMillan
2007-04-24 22:31     ` Joshua Brindle
2007-04-24 22:39       ` Karl MacMillan
2007-04-23 21:35 ` [PATCH 13/33] libsemanage: testing infrastructure jbrindle
2007-04-23 21:35 ` [PATCH 14/33] libsemanage: boolean serialization jbrindle
2007-04-23 21:35 ` [PATCH 15/33] libsemanage: context serialization jbrindle
2007-04-23 21:35 ` [PATCH 16/33] libsemanage: fcontext serialization jbrindle
2007-04-23 21:35 ` [PATCH 17/33] libsemanage: interface serialization jbrindle
2007-04-23 21:35 ` [PATCH 18/33] libsemanage: node serialization jbrindle
2007-04-23 21:35 ` [PATCH 19/33] libsemanage: port serialization jbrindle
2007-04-23 21:35 ` [PATCH 20/33] libsemanage: seuser serialization jbrindle
2007-04-23 21:35 ` [PATCH 21/33] libsemanage: user serialization jbrindle
2007-04-23 21:35 ` jbrindle [this message]
2007-04-23 21:35 ` [PATCH 23/33] libsemanage: commit number serialization jbrindle
2007-04-23 21:35 ` [PATCH 24/33] libsemanage: networking support jbrindle
2007-04-23 21:35 ` [PATCH 25/33] libsemanage: policy server database hooks jbrindle
2007-04-24 21:39   ` Karl MacMillan
2007-04-24 22:39     ` Joshua Brindle
2007-04-24 23:20       ` Karl MacMillan
2007-04-24 23:57         ` Joshua Brindle
2007-04-25  4:42           ` Karl MacMillan
2007-04-23 21:35 ` [PATCH 26/33] libsemanage: module serialization tests jbrindle
2007-04-23 21:35 ` [PATCH 27/33] libsemanage: booleans " jbrindle
2007-04-23 21:35 ` [PATCH 28/33] libsemanage: fcontexts " jbrindle
2007-04-23 21:35 ` [PATCH 29/33] libsemanage: interface " jbrindle
2007-04-23 21:35 ` [PATCH 30/33] libsemanage: node " jbrindle
2007-04-23 21:35 ` [PATCH 31/33] libsemanage: port " jbrindle
2007-04-23 21:35 ` [PATCH 32/33] libsemanage: seuser " jbrindle
2007-04-23 21:35 ` [PATCH 33/33] libsemanage: user " jbrindle
2007-04-24 19:48 ` [PATCH 00/33] libsemanage/libsepol object serialization and ps-api Joshua Brindle
2007-04-24 23:12 ` James Antill
2007-04-25  4:46   ` James Antill

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=20070423213741.907065000@tresys.com \
    --to=jbrindle@tresys.com \
    --cc=selinux@tycho.nsa.gov \
    /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.