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

Adds support for un/serializing the database commit number.

---
 libsemanage/include/semanage/policy.h |   31 +++++++++++
 libsemanage/src/libsemanage.map       |    1 
 libsemanage/src/policy.c              |   91 ++++++++++++++++++++++++++++++++++
 libsemanage/src/policy.h              |    4 +
 4 files changed, 127 insertions(+)

Index: selinux-pms-support/libsemanage/include/semanage/policy.h
===================================================================
--- /dev/null
+++ selinux-pms-support/libsemanage/include/semanage/policy.h
@@ -0,0 +1,31 @@
+/* Authors: Caleb Case <ccase@tresys.com>
+ *
+ * Copyright (C)  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
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef _SEMANAGE_POLICY_H_
+#define _SEMANAGE_POLICY_H_
+
+#include <semanage/handle.h>
+#include <inttypes.h>
+
+int semanage_policy_table_serialize_serial(semanage_handle_t *handle, char **data, uint64_t *size);
+
+int semanage_policy_table_unserialize_serial(semanage_handle_t *handle,
+		char **data, uint64_t *size);
+
+#endif
Index: selinux-pms-support/libsemanage/src/libsemanage.map
===================================================================
--- selinux-pms-support.orig/libsemanage/src/libsemanage.map
+++ selinux-pms-support/libsemanage/src/libsemanage.map
@@ -16,5 +16,6 @@ LIBSEMANAGE_1.0 {
 	  semanage_fcontext_*; semanage_access_check; semanage_set_create_store;
 	  semanage_*_serialize; semanage_*_unserialize;
 	  semanage_is_connected;
+	  semanage_policy_table_serialize_serial;
   local: *;
 };
Index: selinux-pms-support/libsemanage/src/policy.c
===================================================================
--- /dev/null
+++ selinux-pms-support/libsemanage/src/policy.c
@@ -0,0 +1,91 @@
+/* Author: Caleb Case <ccase@tresys.com>
+ *         Ryan Haggerty <rhaggerty@tresys.com>
+ *
+ * Copyright (C)  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
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <stdlib.h>
+#include "debug.h"
+#include "policy.h"
+#include "serialize.h"
+
+/* Serialize the serial number into data and store the size of it in size.
+ * Returns status.
+ */
+int semanage_policy_table_serialize_serial(semanage_handle_t *handle, char **data, uint64_t *size)
+{
+	int status = STATUS_SUCCESS;
+	int serial = handle->funcs->get_serial(handle);
+	char* ptr = NULL;
+
+	/* sanity checks */
+	if (data == NULL || size == NULL) {
+		status = STATUS_ERR;
+		goto cleanup;
+	}
+
+	/* calculate size */
+	status = semanage_serialize(handle, &serial, 0, SEMANAGE_SERIAL_INT32_T, NULL, size);
+	if (status != STATUS_SUCCESS)
+		goto cleanup;
+
+	/* Allocate memory. */
+	ptr = *data = calloc(*size, sizeof(char));
+	if (*data == NULL) {
+		status = STATUS_ERR;
+		goto cleanup;
+	}
+
+	/* Serialize */
+	status = semanage_serialize(handle, &serial, 0, SEMANAGE_SERIAL_INT32_T, &ptr, NULL);
+	if (status != STATUS_SUCCESS)
+		goto cleanup;
+
+cleanup:
+	return status;
+}
+
+hidden_def(semanage_policy_table_serialize_serial)
+
+/* Unserialize the serial number from data.
+ * Function will move data pointer.
+ * Returns status if status is not equal to STATUS_SUCCESS or returns serial number.
+ */
+int semanage_policy_table_unserialize_serial(semanage_handle_t *handle,
+		char **data, uint64_t *size)
+{
+	int status = STATUS_SUCCESS;
+	int *serial = NULL;
+	int ret_serial = -1; /* assume we did not get a good serial number */
+
+	/* Sundry sanity checks. */
+	if (data == NULL || *data == NULL || size == NULL) {
+		status = STATUS_ERR;
+		goto cleanup;
+	}
+
+	status = semanage_unserialize(handle, data, size, (void **)&serial, 0, SEMANAGE_SERIAL_INT32_T);
+	if (status != STATUS_SUCCESS)
+		goto cleanup;
+
+	ret_serial = *serial; /* capture value so we can free */
+cleanup:
+	free(serial);
+	return status == STATUS_SUCCESS ? ret_serial : status;
+}
+
+hidden_def(semanage_policy_table_unserialize_serial)
Index: selinux-pms-support/libsemanage/src/policy.h
===================================================================
--- selinux-pms-support.orig/libsemanage/src/policy.h
+++ selinux-pms-support/libsemanage/src/policy.h
@@ -22,6 +22,7 @@
 #ifndef _SEMANAGE_POLICY_INTERNAL_H_
 #define _SEMANAGE_POLICY_INTERNAL_H_
 
+#include <semanage/policy.h>
 #include "modules.h"
 
 /* Circular dependency */
@@ -68,4 +69,7 @@ extern int semanage_base_merge_component
 
 extern int semanage_commit_components(struct semanage_handle *handle);
 
+hidden_proto(semanage_policy_table_serialize_serial)
+hidden_proto(semanage_policy_table_unserialize_serial)
+
 #endif

-- 

--
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 ` [PATCH 22/33] libsemanage: module serialization jbrindle
2007-04-23 21:35 ` jbrindle [this message]
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=20070423213743.080113000@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.