Skip to contentSkip to conversation

libsemanage/libsepol object serialization and ps-api

PATCH In review [email protected] 3 participants 58 messages Apr 24, 2007 – Apr 25, 2007 SELinux security module

lore
Share & tools
lore
#0 lore raw

cover libsemanage/libsepol object serialization and ps-api

This is the majority of the patches from the policy server release a few months ago. This implements object serialization to send objects (eg., booleans, file contexts, etc) across the line to the policy server. It also implements the line protocol to connect to the policy server and the backend for libsemanage so that semodule, semanage, etc will talk to a policy server instead of doing local operations.

The object serialization will also be necessary for the policy representation branch as we will use this infrastructure to serialize the policy tree for module reading and writing.

The only part left for the policy server is the hooks that were implemented in the expander. As the policy representation work is going on and should remove the expander entirely these patches will have to wait until we have enough of the new representation work to implement them there.

This is obviously meant only for trunk and the policyrep branch.

Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw

PATCH 1/33 libsepol: basic serilization support

Serialization versioning added to the sepol handle.

Serialization utility functions added in serialize.[ch]

---
 libsepol/include/sepol/handle.h |   17 +
 libsepol/src/handle.c           |   89 +++++++++
 libsepol/src/handle.h           |    5 
 libsepol/src/libsepol.map       |    1 
 libsepol/src/serialize.c        |  389 ++++++++++++++++++++++++++++++++++++++++
 libsepol/src/serialize.h        |   45 ++++
 6 files changed, 546 insertions(+)
libsepol/include/sepol/handle.h +17 -0
Index: selinux-pms-support/libsepol/include/sepol/handle.h
===================================================================
@@ -1,6 +1,11 @@
 #ifndef _SEPOL_HANDLE_H_
 #define _SEPOL_HANDLE_H_
 
+#include <inttypes.h>
+
+#define SEPOL_SERIAL_VERSION_MAJOR 1
+#define SEPOL_SERIAL_VERSION_MINOR 0
+
 struct sepol_handle;
 typedef struct sepol_handle sepol_handle_t;
 
@@ -10,4 +15,16 @@ sepol_handle_t *sepol_handle_create(void
 /* Destroy a sepol handle. */
 void sepol_handle_destroy(sepol_handle_t *);
 
+/* Serialize the serialization version. */
+int sepol_handle_version_serialize(sepol_handle_t * sh, char **data, uint64_t *size);
+
+/* Unserialize the serialization version. */
+int sepol_handle_version_unserialize(sepol_handle_t * sh, char **data, uint64_t *size);
+
+/* Get the serialization version. */
+int sepol_handle_get_version(sepol_handle_t *sh, uint32_t * major, uint32_t * minor);
+
+/* Set the serialization version. */
+int sepol_handle_set_version(sepol_handle_t *sh, uint32_t major, uint32_t minor);
+
 #endif
libsepol/src/handle.c +89 -0

104 lines not on this page · raw message

libsepol/src/handle.h +5 -0
Index: selinux-pms-support/libsepol/src/handle.h
===================================================================
@@ -1,9 +1,14 @@
 #ifndef _SEPOL_INTERNAL_HANDLE_H_
 #define _SEPOL_INTERNAL_HANDLE_H_
 
+#include <inttypes.h>
 #include <sepol/handle.h>
 
 struct sepol_handle {
+	/* Serialization version. */
+	uint32_t version_major;
+	uint32_t version_minor;
+
 	/* Error handling */
 	int msg_level;
 	const char *msg_channel;
libsepol/src/libsepol.map +1 -0
Index: selinux-pms-support/libsepol/src/libsepol.map
===================================================================
@@ -12,5 +12,6 @@
 	sepol_policydb_*; sepol_set_policydb_from_file; 
 	sepol_policy_kern_*;
 	sepol_policy_file_*;
+	sepol_*_serialize; sepol_*_unserialize;
   local: *;
 };
libsepol/src/serialize.c new file +389 -0

389 lines not on this page · raw message

libsepol/src/serialize.h new file +45 -0

45 lines not on this page · raw message

Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#2 lore raw

Re: [PATCH 01/33] libsepol: basic serilization support

Quoted 36 lines · On Mon, 2007-04-23 at 17:34 -0400, [email protected] wrote:

plain text document attachment (sepol.serialize.diff) Serialization versioning added to the sepol handle.

Serialization utility functions added in serialize.[ch]

---
 libsepol/include/sepol/handle.h |   17 +
 libsepol/src/handle.c           |   89 +++++++++
 libsepol/src/handle.h           |    5 
 libsepol/src/libsepol.map       |    1 
 libsepol/src/serialize.c        |  389 ++++++++++++++++++++++++++++++++++++++++
 libsepol/src/serialize.h        |   45 ++++
 6 files changed, 546 insertions(+)

Index: selinux-pms-support/libsepol/include/sepol/handle.h
===================================================================

libsepol/include/sepol/handle.h +8 -0
@@ -1,6 +1,11 @@
 #ifndef _SEPOL_HANDLE_H_
 #define _SEPOL_HANDLE_H_
 
+#include <inttypes.h>
+
+#define SEPOL_SERIAL_VERSION_MAJOR 1
+#define SEPOL_SERIAL_VERSION_MINOR 0
+
 struct sepol_handle;
 typedef struct sepol_handle sepol_handle_t;
 
@@ -10,4 +15,16 @@ sepol_handle_t *sepol_handle_create(void
 /* Destroy a sepol handle. */
 void sepol_handle_destroy(sepol_handle_t *);
 
+/* Serialize the serialization version. */
+int sepol_handle_version_serialize(sepol_handle_t * sh, char **data, uint64_t *size);
+

libsepol/include/sepol/handle.h sepol_handle_t *sepol_handle_create(void · line 30

Quoted 10 lines
libsepol/include/sepol/handle.h +9 -0
+/* Unserialize the serialization version. */
+int sepol_handle_version_unserialize(sepol_handle_t * sh, char **data, uint64_t *size);
+
+/* Get the serialization version. */
+int sepol_handle_get_version(sepol_handle_t *sh, uint32_t * major, uint32_t * minor);
+
+/* Set the serialization version. */
+int sepol_handle_set_version(sepol_handle_t *sh, uint32_t major, uint32_t minor);
+
 #endif

Can you give some idea about how the versioning is supposed to work? In particular:

* How is it related to the policy version?
* Why would it change separately from the policy version?
* Is there any advantage to version each component separately rather that a global version?

<snip>

Quoted 37 lines

Index: selinux-pms-support/libsepol/src/serialize.c
===================================================================

libsepol/src/serialize.c new file +32 -0
@@ -0,0 +1,389 @@
+/* Author: Caleb Case <[email protected]>
+ *
+ * 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
+ *  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 <string.h>
+#include <limits.h>
+
+#include "handle.h"
+#include "debug.h"
+#include "serialize.h"
+#include "private.h"
+
+/* This file provides general serialize and unserialize functions. */
+
+/** Serializes various kinds of datum.
+ *

libsepol/src/serialize.c line 42

Quoted 10 lines
libsepol/src/serialize.c new file +10 -0
+ *  Two use cases:
+ *  1) Calling serialize with a non-NULL size.
+ *     This causes serialize to calculate the expected
+ *     size of serializing.  No serialization occurs.
+ *     Destructively modifies size.  Data may be NULL.
+ *  2) Calling serialize with a NULL size.
+ *     This results in data being filled with the
+ *     serialized information.  Caller must pre-allocate
+ *     space for data.  Destructively modifies data.
+ *

Why don't you allocate space for the caller? These two use cases are, well, odd. If you allocate then the caller can memcpy and free if they want.

Quoted 6 lines
libsepol/src/serialize.c new file +6 -0
+ *  This function acts iteratively moving the *data or size values.
+ *
+ *  Supported datum_types (defined in serialize.h):
+ *
+ *  SEPOL_SERIAL_INT32_T
+ *    Serializes datum to a int32_t as defined in inttypes.h

libsepol/src/serialize.c line 58

Quoted 10 lines
libsepol/src/serialize.c new file +10 -0
+ *    datum may NOT be NULL.
+ *    datum_length is not utilized.
+ *  SEPOL_SERIAL_UINT32_T
+ *    Serializes datum to a uint32_t as defined in inttypes.h
+ *    datum may NOT be NULL.
+ *    datum_length is not utilized.
+ *  SEPOL_SERIAL_SIZE_T
+ *    Serializes datum to a size_t as defined in stddef.h
+ *    datum may NOT be NULL.
+ *    datum_length is not utilized.

How can you serialize a type that is platform specific? How would this be handled when communication between a 32 and 64 bit host? I thought we always used fixed width types for all binary communication anyway.

libsepol/src/serialize.c line 62

Quoted 4 lines
libsepol/src/serialize.c new file +4 -0
+ *  SEPOL_SERIAL_STRING
+ *    Serializes a char*.
+ *    datum may be NULL.
+ *    datum_length should be the length of the string as returned by strlen.

Why not call strlen? Especially since the string array version does.

libsepol/src/serialize.c line 72

Quoted 10 lines
libsepol/src/serialize.c new file +10 -0
+ *  SEPOL_SERIAL_STRING_ARRAY
+ *    Serializes a char**.
+ *    datum may be NULL.
+ *    datum_length should be the size of the array.
+ *    Each string will be serialized as per SEPOL_SERIAL_STRING and its size
+ *    determined via strlen.
+ *
+ *  NULL pointers are distinguished (where they are allowed at all).
+ *  In the case of strings this means that a NULL char* has a different
+ *  serialization from the empty string "".

Why?

libsepol/src/serialize.c line 79

Quoted 7 lines
libsepol/src/serialize.c new file +7 -0
+ *
+ */
+int sepol_serialize(sepol_handle_t * handle,
+		    const void *datum,
+		    size_t datum_length,
+		    unsigned int datum_type, char **data, uint64_t * size)
+{

Why a single multiplexed function? Seems _much_ easier to have a sepol_serialize_string, sepol_serialize_uint32, etc. This would allow type safety and improve readability, both at the call site and the definition.

<snip>

Quoted 6 lines
libsepol/src/serialize.c new file +6 -0
+		case SEPOL_SERIAL_SIZE_T:
+			if (size == NULL) {
+				temp = calloc(1, sizeof(uint64_t));
+				if (temp == NULL) {
+					status = STATUS_ERR;
+					goto cleanup;

libsepol/src/serialize.c line 117

Quoted 10 lines
libsepol/src/serialize.c new file +10 -0
+				}
+
+				*((uint64_t *)temp) = cpu_to_le64(*((size_t *) datum));
+
+				memcpy(*data, temp, sizeof(uint64_t));
+				*data += sizeof(uint64_t);
+			}
+			else
+				*size += sizeof(uint64_t);
+			break;

Err - I don't think this is allowed. I believe that size_t is supposed to be word size and there is no reason that word size is limited to 64 bits.

Karl

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#3 lore raw

RE: [PATCH 01/33] libsepol: basic serilization support

Quoted 59 lines

From: Karl MacMillan [mailto:[email protected]]

Quoted 10 lines · On Mon, 2007-04-23 at 17:34 -0400, [email protected] wrote:

plain text document attachment (sepol.serialize.diff) Serialization versioning added to the sepol handle.

Serialization utility functions added in serialize.[ch]

---
 libsepol/include/sepol/handle.h |   17 +
 libsepol/src/handle.c           |   89 +++++++++
 libsepol/src/handle.h           |    5 
 libsepol/src/libsepol.map       |    1 
 libsepol/src/serialize.c        |  389 

++++++++++++++++++++++++++++++++++++++++

Quoted 30 lines
 libsepol/src/serialize.h        |   45 ++++
 6 files changed, 546 insertions(+)

Index: selinux-pms-support/libsepol/include/sepol/handle.h
===================================================================

libsepol/include/sepol/handle.h +12 -0
@@ -1,6 +1,11 @@
 #ifndef _SEPOL_HANDLE_H_
 #define _SEPOL_HANDLE_H_
 
+#include <inttypes.h>
+
+#define SEPOL_SERIAL_VERSION_MAJOR 1
+#define SEPOL_SERIAL_VERSION_MINOR 0
+
 struct sepol_handle;
 typedef struct sepol_handle sepol_handle_t;
 
@@ -10,4 +15,16 @@ sepol_handle_t *sepol_handle_create(void
 /* Destroy a sepol handle. */
 void sepol_handle_destroy(sepol_handle_t *);
 
+/* Serialize the serialization version. */ int 
+sepol_handle_version_serialize(sepol_handle_t * sh, char **data, 
+uint64_t *size);
+
+/* Unserialize the serialization version. */ int 
+sepol_handle_version_unserialize(sepol_handle_t * sh, char **data, 
+uint64_t *size);

libsepol/include/sepol/handle.h sepol_handle_t *sepol_handle_create(void · line 30

Quoted 10 lines
libsepol/include/sepol/handle.h +9 -0
+
+/* Get the serialization version. */
+int sepol_handle_get_version(sepol_handle_t *sh, uint32_t * major, 
+uint32_t * minor);
+
+/* Set the serialization version. */
+int sepol_handle_set_version(sepol_handle_t *sh, uint32_t major, 
+uint32_t minor);
+
 #endif

Can you give some idea about how the versioning is supposed to work? In
particular:

Quoted 5 lines

* How is it related to the policy version?
* Why would it change separately from the policy version?
* Is there any advantage to version each component separately rather that a global version?

Most of the stuff we are serializing isn't actually in policy, modules are already a serialized version of policy and we don't do anything with it, the stuff we are serializing is mostly semanage stuff (file contexts, seusers, etc) that have nothing to do with policy. The per-component versioning was discussed but thought to be too much overhead for the number of objects we are serializing.

Quoted 50 lines

<snip>

libsepol/src/serialize.c line 8

Quoted 13 lines

Index: selinux-pms-support/libsepol/src/serialize.c
===================================================================

libsepol/src/serialize.c new file +8 -0
@@ -0,0 +1,389 @@
+/* Author: Caleb Case <[email protected]>
+ *
+ * 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
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any 

later version.

libsepol/src/serialize.c

Quoted 4 lines
libsepol/src/serialize.c new file +4 -0
+ *
+ *  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

libsepol/src/serialize.c

Quoted 3 lines
libsepol/src/serialize.c new file +3 -0
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser 

General Public

Quoted 5 lines
libsepol/src/serialize.c new file +5 -0
+ *  License along with this library; if not, write to the Free 
+Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  
+02110-1301  USA  */
+

libsepol/src/serialize.c

Quoted 10 lines
libsepol/src/serialize.c new file +10 -0
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+#include "handle.h"
+#include "debug.h"
+#include "serialize.h"
+#include "private.h"
+
+/* This file provides general serialize and unserialize 

functions. */

Quoted 9 lines
libsepol/src/serialize.c new file +9 -0
+
+/** Serializes various kinds of datum.
+ *
+ *  Two use cases:
+ *  1) Calling serialize with a non-NULL size.
+ *     This causes serialize to calculate the expected
+ *     size of serializing.  No serialization occurs.
+ *     Destructively modifies size.  Data may be NULL.
+ *  2) Calling serialize with a NULL size.
Quoted 9 lines

libsepol/src/serialize.c line 42

Quoted 4 lines
libsepol/src/serialize.c new file +4 -0
+ *     This results in data being filled with the
+ *     serialized information.  Caller must pre-allocate
+ *     space for data.  Destructively modifies data.
+ *

Why don't you allocate space for the caller? These two use cases are, well, odd. If you allocate then the caller can memcpy and free if they want.

It works basically the same way the current policy serialization works, pass in the data once to get size, allocate and pass in the buffer to which its being serialized. We did this for consistency with the current mechanisms.

Quoted 17 lines
Quoted 6 lines
libsepol/src/serialize.c new file +6 -0
+ *  This function acts iteratively moving the *data or size values.
+ *
+ *  Supported datum_types (defined in serialize.h):
+ *
+ *  SEPOL_SERIAL_INT32_T
+ *    Serializes datum to a int32_t as defined in inttypes.h

libsepol/src/serialize.c line 58

Quoted 10 lines
libsepol/src/serialize.c new file +10 -0
+ *    datum may NOT be NULL.
+ *    datum_length is not utilized.
+ *  SEPOL_SERIAL_UINT32_T
+ *    Serializes datum to a uint32_t as defined in inttypes.h
+ *    datum may NOT be NULL.
+ *    datum_length is not utilized.
+ *  SEPOL_SERIAL_SIZE_T
+ *    Serializes datum to a size_t as defined in stddef.h
+ *    datum may NOT be NULL.
+ *    datum_length is not utilized.
Quoted 5 lines

How can you serialize a type that is platform specific? How would this be handled when communication between a 32 and 64 bit host? I thought we always used fixed width types for all binary communication anyway.

SEPOL_SERIAL_SIZE_T is always 64 bits. We should be checking if it tries to serialize into a smaller type, if not that's a bug.

Quoted 8 lines

libsepol/src/serialize.c

Quoted 4 lines
libsepol/src/serialize.c new file +4 -0
+ *  SEPOL_SERIAL_STRING
+ *    Serializes a char*.
+ *    datum may be NULL.
+ *    datum_length should be the length of the string as 

returned by strlen.

Why not call strlen? Especially since the string array version does.

IIRC because we use the same entry point for all data types to get to these.

Quoted 9 lines

libsepol/src/serialize.c

Quoted 5 lines
libsepol/src/serialize.c new file +5 -0
+ *  SEPOL_SERIAL_STRING_ARRAY
+ *    Serializes a char**.
+ *    datum may be NULL.
+ *    datum_length should be the size of the array.
+ *    Each string will be serialized as per 

SEPOL_SERIAL_STRING and its size

libsepol/src/serialize.c

Quoted 3 lines
libsepol/src/serialize.c new file +3 -0
+ *    determined via strlen.
+ *
+ *  NULL pointers are distinguished (where they are 
Quoted 7 lines

allowed at all).

libsepol/src/serialize.c line 74

Quoted 3 lines
libsepol/src/serialize.c new file +3 -0
+ *  In the case of strings this means that a NULL char* has a 
+ different
+ *  serialization from the empty string "".

Why?

Not sure, will check.

Quoted 8 lines

libsepol/src/serialize.c

Quoted 6 lines
libsepol/src/serialize.c new file +6 -0
+ *
+ */
+int sepol_serialize(sepol_handle_t * handle,
+		    const void *datum,
+		    size_t datum_length,
+		    unsigned int datum_type, char **data, 

uint64_t * size) {

Quoted 5 lines

Why a single multiplexed function? Seems _much_ easier to have a sepol_serialize_string, sepol_serialize_uint32, etc. This would allow type safety and improve readability, both at the call site and the definition.

We can do that I guess, IMO it doesn't make much of a difference.

Quoted 13 lines

<snip>

libsepol/src/serialize.c

Quoted 9 lines
libsepol/src/serialize.c new file +9 -0
+		case SEPOL_SERIAL_SIZE_T:
+			if (size == NULL) {
+				temp = calloc(1, sizeof(uint64_t));
+				if (temp == NULL) {
+					status = STATUS_ERR;
+					goto cleanup;
+				}
+
+				*((uint64_t *)temp) = 

cpu_to_le64(*((size_t *) datum));

Quoted 12 lines

libsepol/src/serialize.c line 117

Quoted 7 lines
libsepol/src/serialize.c new file +7 -0
+
+				memcpy(*data, temp, sizeof(uint64_t));
+				*data += sizeof(uint64_t);
+			}
+			else
+				*size += sizeof(uint64_t);
+			break;

Err - I don't think this is allowed. I believe that size_t is supposed to be word size and there is no reason that word size is limited to 64 bits.

IIRC in ANSI C it is limited to 64 bits. I might be wrong on this but I remember us looking it up when this happened.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#4 lore raw

RE: [PATCH 01/33] libsepol: basic serilization support

Quoted 65 lines · Joshua Brindle
Quoted 59 lines

From: Karl MacMillan [mailto:[email protected]]

Quoted 10 lines · On Mon, 2007-04-23 at 17:34 -0400, [email protected] wrote:

plain text document attachment (sepol.serialize.diff) Serialization versioning added to the sepol handle.

Serialization utility functions added in serialize.[ch]

---
 libsepol/include/sepol/handle.h |   17 +
 libsepol/src/handle.c           |   89 +++++++++
 libsepol/src/handle.h           |    5 
 libsepol/src/libsepol.map       |    1 
 libsepol/src/serialize.c        |  389 

++++++++++++++++++++++++++++++++++++++++

Quoted 30 lines
 libsepol/src/serialize.h        |   45 ++++
 6 files changed, 546 insertions(+)

Index: selinux-pms-support/libsepol/include/sepol/handle.h
===================================================================

libsepol/include/sepol/handle.h +12 -0
@@ -1,6 +1,11 @@
 #ifndef _SEPOL_HANDLE_H_
 #define _SEPOL_HANDLE_H_
 
+#include <inttypes.h>
+
+#define SEPOL_SERIAL_VERSION_MAJOR 1
+#define SEPOL_SERIAL_VERSION_MINOR 0
+
 struct sepol_handle;
 typedef struct sepol_handle sepol_handle_t;
 
@@ -10,4 +15,16 @@ sepol_handle_t *sepol_handle_create(void
 /* Destroy a sepol handle. */
 void sepol_handle_destroy(sepol_handle_t *);
 
+/* Serialize the serialization version. */ int 
+sepol_handle_version_serialize(sepol_handle_t * sh, char **data, 
+uint64_t *size);
+
+/* Unserialize the serialization version. */ int 
+sepol_handle_version_unserialize(sepol_handle_t * sh, char **data, 
+uint64_t *size);

libsepol/include/sepol/handle.h sepol_handle_t *sepol_handle_create(void · line 30

Quoted 10 lines
libsepol/include/sepol/handle.h +9 -0
+
+/* Get the serialization version. */
+int sepol_handle_get_version(sepol_handle_t *sh, uint32_t * major, 
+uint32_t * minor);
+
+/* Set the serialization version. */
+int sepol_handle_set_version(sepol_handle_t *sh, uint32_t major, 
+uint32_t minor);
+
 #endif

Can you give some idea about how the versioning is supposed to work? In
particular:

Quoted 5 lines

* How is it related to the policy version?
* Why would it change separately from the policy version?
* Is there any advantage to version each component separately rather that a global version?

Quoted 4 lines

Most of the stuff we are serializing isn't actually in policy, modules are already a serialized version of policy and we don't do anything with it, the stuff we are serializing is mostly semanage stuff (file contexts, seusers, etc) that have nothing to do with policy.

Well - most of it is closely related.

Quoted 4 lines

The
per-component versioning was discussed but thought to be too much overhead for the number of objects we are serializing.

I guess the problem with this is it is hard to know exactly what the version is for. Per-component headers seem better to me.

Quoted 60 lines
Quoted 50 lines

<snip>

libsepol/src/serialize.c line 8

Quoted 13 lines

Index: selinux-pms-support/libsepol/src/serialize.c
===================================================================

libsepol/src/serialize.c new file +8 -0
@@ -0,0 +1,389 @@
+/* Author: Caleb Case <[email protected]>
+ *
+ * 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
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any 

later version.

libsepol/src/serialize.c

Quoted 4 lines
libsepol/src/serialize.c new file +4 -0
+ *
+ *  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

libsepol/src/serialize.c

Quoted 3 lines
libsepol/src/serialize.c new file +3 -0
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser 

General Public

Quoted 5 lines
libsepol/src/serialize.c new file +5 -0
+ *  License along with this library; if not, write to the Free 
+Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  
+02110-1301  USA  */
+

libsepol/src/serialize.c

Quoted 10 lines
libsepol/src/serialize.c new file +10 -0
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+#include "handle.h"
+#include "debug.h"
+#include "serialize.h"
+#include "private.h"
+
+/* This file provides general serialize and unserialize 

functions. */

Quoted 9 lines
libsepol/src/serialize.c new file +9 -0
+
+/** Serializes various kinds of datum.
+ *
+ *  Two use cases:
+ *  1) Calling serialize with a non-NULL size.
+ *     This causes serialize to calculate the expected
+ *     size of serializing.  No serialization occurs.
+ *     Destructively modifies size.  Data may be NULL.
+ *  2) Calling serialize with a NULL size.
Quoted 9 lines

libsepol/src/serialize.c line 42

Quoted 4 lines
libsepol/src/serialize.c new file +4 -0
+ *     This results in data being filled with the
+ *     serialized information.  Caller must pre-allocate
+ *     space for data.  Destructively modifies data.
+ *

Why don't you allocate space for the caller? These two use cases are, well, odd. If you allocate then the caller can memcpy and free if they want.

Quoted 5 lines

It works basically the same way the current policy serialization works, pass in the data once to get size, allocate and pass in the buffer to which its being serialized. We did this for consistency with the current mechanisms.

I'm not certain that I would use the current policy serialization code as an example for anything - it is very difficult to work with.

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
libsepol/src/serialize.c new file +16 -0
+ *  This function acts iteratively moving the *data or size values.
+ *
+ *  Supported datum_types (defined in serialize.h):
+ *
+ *  SEPOL_SERIAL_INT32_T
+ *    Serializes datum to a int32_t as defined in inttypes.h
+ *    datum may NOT be NULL.
+ *    datum_length is not utilized.
+ *  SEPOL_SERIAL_UINT32_T
+ *    Serializes datum to a uint32_t as defined in inttypes.h
+ *    datum may NOT be NULL.
+ *    datum_length is not utilized.
+ *  SEPOL_SERIAL_SIZE_T
+ *    Serializes datum to a size_t as defined in stddef.h
+ *    datum may NOT be NULL.
+ *    datum_length is not utilized.
Quoted 9 lines
Quoted 5 lines

How can you serialize a type that is platform specific? How would this be handled when communication between a 32 and 64 bit host? I thought we always used fixed width types for all binary communication anyway.

SEPOL_SERIAL_SIZE_T is always 64 bits. We should be checking if it tries to serialize into a smaller type, if not that's a bug.

How can that be? On a 64bit platform I can represent a size that can't be represented by a 32bit size_t. How can I transfer this data to a 32bit system? I can't put it in a data structure with size_t - it would have to be unint64_t. So why not just use that?

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
libsepol/src/serialize.c new file +4 -0
+ *  SEPOL_SERIAL_STRING
+ *    Serializes a char*.
+ *    datum may be NULL.
+ *    datum_length should be the length of the string as 
Quoted 8 lines
Quoted 4 lines

returned by strlen.

Why not call strlen? Especially since the string array version does.

IIRC because we use the same entry point for all data types to get to these.

But you know it is a string.

Quoted 27 lines
Quoted 9 lines

libsepol/src/serialize.c

Quoted 5 lines
libsepol/src/serialize.c new file +5 -0
+ *  SEPOL_SERIAL_STRING_ARRAY
+ *    Serializes a char**.
+ *    datum may be NULL.
+ *    datum_length should be the size of the array.
+ *    Each string will be serialized as per 

SEPOL_SERIAL_STRING and its size

libsepol/src/serialize.c

Quoted 3 lines
libsepol/src/serialize.c new file +3 -0
+ *    determined via strlen.
+ *
+ *  NULL pointers are distinguished (where they are 
Quoted 7 lines

allowed at all).

libsepol/src/serialize.c line 74

Quoted 3 lines
libsepol/src/serialize.c new file +3 -0
+ *  In the case of strings this means that a NULL char* has a 
+ different
+ *  serialization from the empty string "".

Why?

Not sure, will check.

Quoted 8 lines

libsepol/src/serialize.c

Quoted 6 lines
libsepol/src/serialize.c new file +6 -0
+ *
+ */
+int sepol_serialize(sepol_handle_t * handle,
+		    const void *datum,
+		    size_t datum_length,
+		    unsigned int datum_type, char **data, 

uint64_t * size) {

Quoted 8 lines
Quoted 5 lines

Why a single multiplexed function? Seems _much_ easier to have a sepol_serialize_string, sepol_serialize_uint32, etc. This would allow type safety and improve readability, both at the call site and the definition.

We can do that I guess, IMO it doesn't make much of a difference.

I think it makes a big difference.

Quoted 26 lines
Quoted 13 lines

<snip>

libsepol/src/serialize.c

Quoted 9 lines
libsepol/src/serialize.c new file +9 -0
+		case SEPOL_SERIAL_SIZE_T:
+			if (size == NULL) {
+				temp = calloc(1, sizeof(uint64_t));
+				if (temp == NULL) {
+					status = STATUS_ERR;
+					goto cleanup;
+				}
+
+				*((uint64_t *)temp) = 

cpu_to_le64(*((size_t *) datum));

Quoted 12 lines

libsepol/src/serialize.c line 117

Quoted 7 lines
libsepol/src/serialize.c new file +7 -0
+
+				memcpy(*data, temp, sizeof(uint64_t));
+				*data += sizeof(uint64_t);
+			}
+			else
+				*size += sizeof(uint64_t);
+			break;

Err - I don't think this is allowed. I believe that size_t is supposed to be word size and there is no reason that word size is limited to 64 bits.

Quoted 3 lines

IIRC in ANSI C it is limited to 64 bits. I might be wrong on this but I remember us looking it up when this happened.

That sounds unlikely, but more importantly, why? Why not just use uint64_t?

Karl

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#5 lore raw

RE: [PATCH 01/33] libsepol: basic serilization support

Quoted 1 line

From: Karl MacMillan [mailto:[email protected]]

<snip>

Quoted 8 lines
Quoted 4 lines

The
per-component versioning was discussed but thought to be too much overhead for the number of objects we are serializing.

I guess the problem with this is it is hard to know exactly what the version is for. Per-component headers seem better to me.

Ok, we can talk about it but it seems like a lot of overhead for no good reason to version everything.

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

<snip>

It works basically the same way the current policy serialization works, pass in the data once to get size, allocate and pass in the buffer to which its being serialized. We did this for

Quoted 8 lines

consistency with

Quoted 2 lines

the current mechanisms.

I'm not certain that I would use the current policy serialization code as an example for anything - it is very difficult to work with.

Fair enough.

Quoted 11 lines
Quoted 4 lines

SEPOL_SERIAL_SIZE_T is always 64 bits. We should be checking if it tries to serialize into a smaller type, if not that's a bug.

How can that be? On a 64bit platform I can represent a size that can't be represented by a 32bit size_t. How can I transfer this data to a 32bit system? I can't put it in a data structure with size_t - it would have to be unint64_t. So why not just use that?

That's why I said "We should be checking if it tries to serialize into a smaller type, if not that's a bug"

IIRC we needed something that could serialize/unserialize size_t because its used in some components that we serialize. We could always cast to uint64_t and serialize it that way (which is pretty much what we are doing anyway).

Quoted 8 lines
Quoted 2 lines

IIRC because we use the same entry point for all data types

to get to

Quoted 2 lines

these.

But you know it is a string.

Fine.

Quoted 33 lines
Quoted 33 lines
Quoted 9 lines
Quoted 5 lines

+ * SEPOL_SERIAL_STRING_ARRAY

+ *    Serializes a char**.
+ *    datum may be NULL.
+ *    datum_length should be the size of the array.
+ *    Each string will be serialized as per 

SEPOL_SERIAL_STRING and its size

Quoted 3 lines

+ * determined via strlen.
+ *
+ * NULL pointers are distinguished (where they are

Quoted 7 lines

allowed at all).

Quoted 3 lines

+ * In the case of strings this means that a NULL char* has a
+ different
+ * serialization from the empty string "".

Why?

Not sure, will check.

Quoted 13 lines

libsepol/src/serialize.c

Quoted 6 lines

+ *
+ */

libsepol/src/serialize.c new file +4 -0
+int sepol_serialize(sepol_handle_t * handle,
+		    const void *datum,
+		    size_t datum_length,
+		    unsigned int datum_type, char **data,

uint64_t * size) {

Why a single multiplexed function? Seems _much_ easier to have a sepol_serialize_string, sepol_serialize_uint32, etc. This would allow type safety and improve readability, both at the call site and the definition.

Quoted 5 lines
Quoted 2 lines

We can do that I guess, IMO it doesn't make much of a difference.

I think it makes a big difference.

I don't know why, this is closer to what we want anyway, where we can just call object->serialize and get a serialized version.

Quoted 28 lines
Quoted 6 lines
Quoted 6 lines

<snip>

libsepol/src/serialize.c

Quoted 3 lines
libsepol/src/serialize.c new file +3 -0
+		case SEPOL_SERIAL_SIZE_T:
+			if (size == NULL) {
+				temp = calloc(1, 

sizeof(uint64_t));

Quoted 9 lines
Quoted 9 lines

libsepol/src/serialize.c

Quoted 6 lines
libsepol/src/serialize.c new file +6 -0
+				if (temp == NULL) {
+					status = STATUS_ERR;
+					goto cleanup;
+				}
+
+				*((uint64_t *)temp) =

cpu_to_le64(*((size_t *) datum));

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+				memcpy(*data, temp, 

sizeof(uint64_t));

Quoted 11 lines
Quoted 10 lines

libsepol/src/serialize.c line 117

Quoted 5 lines
libsepol/src/serialize.c new file +5 -0
+				*data += sizeof(uint64_t);
+			}
+			else
+				*size += sizeof(uint64_t);
+			break;

Err - I don't think this is allowed. I believe that size_t is supposed to be word size and there is no reason that word size is limited to 64 bits.

Quoted 8 lines
Quoted 1 line

IIRC in ANSI C it is limited to 64 bits. I might be wrong

on this but

Quoted 2 lines

I remember us looking it up when this happened.

That sounds unlikely, but more importantly, why? Why not just use uint64_t?

Because some things we serialize are size_t so we must unserialize into size_t.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#6 lore raw

RE: [PATCH 01/33] libsepol: basic serilization support

Quoted 1 line · Joshua Brindle
Quoted 1 line

From: Karl MacMillan [mailto:[email protected]]

<snip>

Quoted 12 lines
Quoted 11 lines
Quoted 4 lines

SEPOL_SERIAL_SIZE_T is always 64 bits. We should be checking if it tries to serialize into a smaller type, if not that's a bug.

How can that be? On a 64bit platform I can represent a size that can't be represented by a 32bit size_t. How can I transfer this data to a 32bit system? I can't put it in a data structure with size_t - it would have to be unint64_t. So why not just use that?

Quoted 8 lines

That's why I said "We should be checking if it tries to serialize into a smaller type, if not that's a bug"

IIRC we needed something that could serialize/unserialize size_t because its used in some components that we serialize. We could always cast to uint64_t and serialize it that way (which is pretty much what we are doing anyway).

Something is going wrong in our communication here. You _cannot_ reliably transfer size_t from a 64bit system to a 32bit system (assuming that size_t is 64 and 32 bits respectively). That means that you cannot reliably serialize data structures that use size_t - you must change the data structures. Otherwise the serialized data will not be valid on all systems.

There is no way to check "if it tries to serialize into a smaller type"
- you will always hit this condition at some point.

As for the size, C99 says:

"The value of the result [of sizeof] is implementation-defined, and its type (an unsigned integer type) is size_t,"

Later it says:

"The types used for size_t and ptrdiff_t should not have an integer conversion rank greater than that of signed long int unless the implementation supports objects large enough to make this necessary."

I read that to say that the width of size_t is implementation defined and could be larger that 64 bits.

Karl

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#7 lore raw

RE: [PATCH 01/33] libsepol: basic serilization support

Quoted 54 lines

From: Karl MacMillan [mailto:[email protected]]

Quoted 1 line · Joshua Brindle
Quoted 1 line

From: Karl MacMillan [mailto:[email protected]]

<snip>

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

SEPOL_SERIAL_SIZE_T is always 64 bits. We should be

checking if it

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

tries to serialize into a smaller type, if not that's a bug.

How can that be? On a 64bit platform I can represent a size that can't be represented by a 32bit size_t. How can I

transfer this data

Quoted 1 line
Quoted 1 line

to a 32bit system? I can't put it in a data structure

with size_t -

Quoted 5 lines
Quoted 3 lines

it would have to be unint64_t.
So why not just use that?

That's why I said "We should be checking if it tries to

serialize into

Quoted 4 lines

a smaller type, if not that's a bug"

IIRC we needed something that could serialize/unserialize size_t because its used in some components that we serialize. We

could always

Quoted 1 line

cast to uint64_t and serialize it that way (which is pretty

much what

Quoted 2 lines

we are doing anyway).

Something is going wrong in our communication here. You _cannot_ reliably transfer size_t from a 64bit system to a 32bit system (assuming that size_t is 64 and 32 bits respectively). That means that you cannot reliably serialize data structures that use size_t - you must change the data structures. Otherwise the serialized data will not be valid on all systems.

There is no way to check "if it tries to serialize into a smaller type"
- you will always hit this condition at some point.

As for the size, C99 says:

"The value of the result [of sizeof] is implementation-defined, and its type (an unsigned integer type) is size_t,"

Later it says:

Quoted 7 lines

"The types used for size_t and ptrdiff_t should not have an integer conversion rank greater than that of signed long int unless the implementation supports objects large enough to make this necessary."

I read that to say that the width of size_t is implementation defined and could be larger that 64 bits.

How do you suppose we should serialize variables that are normally size_t then? For example, a policy module is essentially a file that gets sent across and has a length of size_t, all the policy module functions (eg., sepol_load_policy, etc) use a size_t so we have to serialize it and unserialize it in some way.

There is an assumption here that a policy file will never be longer than uint64 long, probably a fair assumption. On 32 bit systems I'll cast into a 32 bit and if its too long it should error out.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#8 lore raw

RE: [PATCH 01/33] libsepol: basic serilization support

Quoted 59 lines · Joshua Brindle
Quoted 59 lines

From: Karl MacMillan [mailto:[email protected]]

Quoted 1 line · Joshua Brindle
Quoted 1 line

From: Karl MacMillan [mailto:[email protected]]

<snip>

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

SEPOL_SERIAL_SIZE_T is always 64 bits. We should be

checking if it

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

tries to serialize into a smaller type, if not that's a bug.

How can that be? On a 64bit platform I can represent a size that can't be represented by a 32bit size_t. How can I

transfer this data

Quoted 1 line
Quoted 1 line

to a 32bit system? I can't put it in a data structure

with size_t -

Quoted 5 lines
Quoted 3 lines

it would have to be unint64_t.
So why not just use that?

That's why I said "We should be checking if it tries to

serialize into

Quoted 4 lines

a smaller type, if not that's a bug"

IIRC we needed something that could serialize/unserialize size_t because its used in some components that we serialize. We

could always

Quoted 1 line

cast to uint64_t and serialize it that way (which is pretty

much what

Quoted 2 lines

we are doing anyway).

Something is going wrong in our communication here. You _cannot_ reliably transfer size_t from a 64bit system to a 32bit system (assuming that size_t is 64 and 32 bits respectively). That means that you cannot reliably serialize data structures that use size_t - you must change the data structures. Otherwise the serialized data will not be valid on all systems.

There is no way to check "if it tries to serialize into a smaller type"
- you will always hit this condition at some point.

As for the size, C99 says:

"The value of the result [of sizeof] is implementation-defined, and its type (an unsigned integer type) is size_t,"

Later it says:

"The types used for size_t and ptrdiff_t should not have an integer conversion rank greater than that of signed long int unless the implementation supports objects large enough to make this necessary."

Quoted 9 lines
Quoted 2 lines

I read that to say that the width of size_t is implementation defined and could be larger that 64 bits.

How do you suppose we should serialize variables that are normally size_t then? For example, a policy module is essentially a file that gets sent across and has a length of size_t, all the policy module functions (eg., sepol_load_policy, etc) use a size_t so we have to serialize it and unserialize it in some way.

You define the size as uint64_t or uint32_t and check for overflow everywhere you convert from size_t (or long for things like fseek).

Quoted 3 lines

There is an assumption here that a policy file will never be longer than uint64 long, probably a fair assumption. On 32 bit systems I'll cast into a 32 bit and if its too long it should error out.

Are you using this only for policy file offsets or for length? I would consider using uint32_t - that is likely sufficient.

Karl

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#9 lore raw

RE: [PATCH 01/33] libsepol: basic serilization support

Quoted 73 lines

From: Karl MacMillan [mailto:[email protected]]

Quoted 8 lines · Joshua Brindle
Quoted 8 lines

From: Karl MacMillan [mailto:[email protected]]

Quoted 1 line · Joshua Brindle
Quoted 1 line

From: Karl MacMillan [mailto:[email protected]]

<snip>

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

SEPOL_SERIAL_SIZE_T is always 64 bits. We should be

checking if it

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

tries to serialize into a smaller type, if not that's a bug.

How can that be? On a 64bit platform I can represent

a size that

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line

can't be represented by a 32bit size_t. How can I

transfer this data

Quoted 1 line
Quoted 1 line

to a 32bit system? I can't put it in a data structure

with size_t -

Quoted 4 lines
Quoted 3 lines

it would have to be unint64_t.
So why not just use that?

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

That's why I said "We should be checking if it tries to

serialize into

Quoted 3 lines

a smaller type, if not that's a bug"

IIRC we needed something that could

serialize/unserialize size_t

Quoted 11 lines
Quoted 11 lines
Quoted 1 line

because its used in some components that we serialize. We

could always

Quoted 1 line

cast to uint64_t and serialize it that way (which is pretty

much what

Quoted 2 lines

we are doing anyway).

Something is going wrong in our communication here. You _cannot_ reliably transfer size_t from a 64bit system to a 32bit system (assuming that size_t is 64 and 32 bits respectively). That means that you cannot reliably serialize data structures that

use size_t -

Quoted 1 line
Quoted 1 line

you must change the data structures. Otherwise the

serialized data

Quoted 9 lines
Quoted 9 lines

will not be valid on all systems.

There is no way to check "if it tries to serialize into a smaller type"
- you will always hit this condition at some point.

As for the size, C99 says:

"The value of the result [of sizeof] is

implementation-defined, and

Quoted 6 lines
Quoted 6 lines

its type (an unsigned integer
type) is size_t,"

Later it says:

"The types used for size_t and ptrdiff_t should not have

an integer

Quoted 9 lines
Quoted 6 lines

conversion rank greater than that of signed long int unless the implementation supports objects large enough to make this necessary."

I read that to say that the width of size_t is implementation defined and could be larger that 64 bits.

How do you suppose we should serialize variables that are normally size_t then? For example, a policy module is essentially a

file that

Quoted 9 lines
Quoted 4 lines

gets sent across and has a length of size_t, all the policy module functions (eg., sepol_load_policy, etc) use a size_t so we have to serialize it and unserialize it in some way.

You define the size as uint64_t or uint32_t and check for overflow everywhere you convert from size_t (or long for things like fseek).

*sigh* I must not be making myself clear. That's what we are doing.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#10 lore raw

RE: [PATCH 01/33] libsepol: basic serilization support

Quoted 1 line · Joshua Brindle
Quoted 1 line

From: Karl MacMillan [mailto:[email protected]]

<snip>

Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

How do you suppose we should serialize variables that are normally size_t then? For example, a policy module is essentially a

file that

Quoted 4 lines

gets sent across and has a length of size_t, all the policy module functions (eg., sepol_load_policy, etc) use a size_t so we have to serialize it and unserialize it in some way.

Quoted 6 lines
Quoted 4 lines

You define the size as uint64_t or uint32_t and check for overflow everywhere you convert from size_t (or long for things like fseek).

*sigh* I must not be making myself clear. That's what we are doing.

No - it is about where you are doing the checking. This doesn't belong in the generic layer because it obscures what the problem is. It belongs at the call site that interprets the fields.

Offering to serialize size_t is not a good interface - it makes it look like you are actually handling the problem when you are not. By forcing all of the serialized data into fixed-width types you are bringing the problem to the foreground.

That way the representation is always clear and valid and good error messages can be generated.

Karl

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#11 lore raw

RE: [PATCH 01/33] libsepol: basic serilization support

Quoted 32 lines

From: Karl MacMillan [mailto:[email protected]]

Quoted 1 line · Joshua Brindle
Quoted 1 line

From: Karl MacMillan [mailto:[email protected]]

<snip>

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

How do you suppose we should serialize variables that

are normally

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

size_t then? For example, a policy module is essentially a

file that

Quoted 1 line

gets sent across and has a length of size_t, all the

policy module

Quoted 1 line
Quoted 1 line
Quoted 1 line

functions (eg., sepol_load_policy, etc) use a size_t so

we have to

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

serialize it and unserialize it in some way.

You define the size as uint64_t or uint32_t and check for

overflow

Quoted 1 line
Quoted 1 line

everywhere you convert from size_t (or long for things

like fseek).

Quoted 3 lines
Quoted 1 line

*sigh* I must not be making myself clear. That's what we are doing.

No - it is about where you are doing the checking. This doesn't belong in the generic layer because it obscures what the problem is. It belongs at the call site that interprets the fields.

Quoted 8 lines

Offering to serialize size_t is not a good interface - it makes it look like you are actually handling the problem when you are not. By forcing all of the serialized data into fixed-width types you are bringing the problem to the foreground.

That way the representation is always clear and valid and good error messages can be generated.

So move boiler plate casting and checking to the call site? I guess we can do that... :\

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#12 lore raw

RE: [PATCH 01/33] libsepol: basic serilization support

Quoted 2 lines · Joshua Brindle

So move boiler plate casting and checking to the call site? I guess we can do that... :\

Having a wrapper that does it for you isn't such a bad thing, and
calling that wrapper serialize_sizet/unserialize_sizet or whatever isn't the worst thing in the world[1].
The problem, from my POV, is that you check on the receiving side if
size_t happens to be bigger than uint32_t[2]. You are basically sending a uint64_t over the network that can never hold a value bigger than a uint32_t, so everything gets to send extra zeros. This is very misleading, just say what you mean by having the protocol use uint32_t, and check at the sending side if the value > uint32_t can hold, if so error in some way.

Dito with SERIAL_STRING (although that probably fails by accident
atm.), just fail to ever send "large" strings, and use uint32_t for the length. You should probably also pick a limit on receive instead of hoping calloc() will save you.

[1] Although an interface name that makes it obvious the size_t is going to be down converted to uint32_t would be better.

[2] Well it actually uses (unsigned int), via. UINT_MAX, which is another bug as it should be using UINT32_MAX from stdint.h.

Signature · 1 line
James Antill <[email protected]>
#13 lore raw

RE: [PATCH 01/33] libsepol: basic serilization support

Quoted 8 lines · James Antill
Quoted 2 lines · Joshua Brindle

So move boiler plate casting and checking to the call site? I guess we can do that... :\

Having a wrapper that does it for you isn't such a bad thing, and
calling that wrapper serialize_sizet/unserialize_sizet or whatever isn't the worst thing in the world[1].

Like serialize_sizet_to_uint32.

Quoted 8 lines

The problem, from my POV, is that you check on the receiving side if
size_t happens to be bigger than uint32_t[2]. You are basically sending a uint64_t over the network that can never hold a value bigger than a uint32_t, so everything gets to send extra zeros. This is very misleading, just say what you mean by having the protocol use uint32_t, and check at the sending side if the value > uint32_t can hold, if so error in some way.

I would say that the problem is more general. The goal here is to serialize data structures - i.e., convert the data structure to/from a byte stream. Unfortunately, you are using data structures that you cannot reliably turn into a byte stream.

So the solution is to change the data structures and check for overflow when you insert into the data structure not when you [un]serialize the structure. As James points out, this approach will put the error much closer to the failure point. As it stands now the error is as far away from the failure point as possible (and possibly on another system entirely).

I would suggest:

sepol_sizet_to_uint32: conversion only - checks for overflow
sepol_serialize_uint32: serialize only

Karl

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#14 lore raw

PATCH 2/33 libsepol: boolean serialization

In reply to [email protected]

This adds serialize/unserialize methods for boolean records.

---
 libsepol/include/sepol/boolean_record.h |   10 +++
 libsepol/src/boolean_internal.h         |    2 
 libsepol/src/boolean_record.c           |   96 ++++++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+)
libsepol/include/sepol/boolean_record.h +10 -0
Index: selinux-pms-support/libsepol/include/sepol/boolean_record.h
===================================================================
@@ -1,6 +1,7 @@
 #ifndef _SEPOL_BOOLEAN_RECORD_H_
 #define _SEPOL_BOOLEAN_RECORD_H_
 
+#include <inttypes.h>
 #include <stddef.h>
 #include <sepol/handle.h>
 
@@ -48,4 +49,13 @@ extern int sepol_bool_clone(sepol_handle
 
 extern void sepol_bool_free(sepol_bool_t * boolean);
 
+/* Serialize/Unserialize */
+extern int sepol_bool_serialize(sepol_handle_t * handle,
+				const sepol_bool_t * boolean,
+				char **data, uint64_t * size);
+
+extern int sepol_bool_unserialize(sepol_handle_t * handle,
+				  char **data, uint64_t * size,
+				  sepol_bool_t ** boolean);
+
 #endif
libsepol/src/boolean_internal.h +2 -0
Index: selinux-pms-support/libsepol/src/boolean_internal.h
===================================================================
@@ -13,4 +13,6 @@ hidden_proto(sepol_bool_key_create)
     hidden_proto(sepol_bool_set_value)
     hidden_proto(sepol_bool_create)
     hidden_proto(sepol_bool_free)
+    hidden_proto(sepol_bool_serialize)
+    hidden_proto(sepol_bool_unserialize)
 #endif
libsepol/src/boolean_record.c +96 -0

108 lines not on this page · raw message

Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#15 lore raw

Re: [PATCH 02/33] libsepol: boolean serialization

On Mon, 2007-04-23 at 17:34 -0400, [email protected] wrote:

<snip>

Quoted 9 lines
libsepol/src/boolean_record.c +9 -0
+
+/* Serialize/Unserialize */
+/** Destructively modifies data and size.
+ *  Caller must pre-allocate space for data.
+ *  Use sepol_bool_calculate_serialized_size(). */
+int sepol_bool_serialize(sepol_handle_t * handle,
+			 const sepol_bool_t * boolean,
+			 char **data, uint64_t * size)
+{

libsepol/src/boolean_record.c void sepol_bool_free(sepol_bool_t * bool · line 201

Quoted 10 lines
libsepol/src/boolean_record.c +10 -0
+	int status = STATUS_SUCCESS;
+	const char *name = NULL;
+	int value;
+
+	/* Sundry sanity checks. */
+	if (handle == NULL || boolean == NULL) {
+		status = STATUS_ERR;
+		goto cleanup;
+	}
+

Why not assert here?

libsepol/src/boolean_record.c void sepol_bool_free(sepol_bool_t * bool · line 206

Quoted 5 lines
libsepol/src/boolean_record.c +5 -0
+	/* Boolean name. */
+	name = sepol_bool_get_name(boolean);
+	status =
+	    sepol_serialize(handle, name, (name == NULL) ? 0 : strlen(name),
+			    SEPOL_SERIAL_STRING, data, size);

Why doesn't the serialization function handle null strings?

libsepol/src/boolean_record.c void sepol_bool_free(sepol_bool_t * bool · line 215

Quoted 9 lines
libsepol/src/boolean_record.c +9 -0
+	if (status != STATUS_SUCCESS)
+		goto cleanup;
+
+	/* Value of boolean. */
+	value = sepol_bool_get_value(boolean);
+	status = sepol_serialize(handle, &value, 0, SEPOL_SERIAL_INT32_T, data, size);
+	if (status != STATUS_SUCCESS)
+		goto cleanup;
+

I think that it would be nice to put a header on each of these serialized chunks that identifies what the data represents (e.g., boolean, seuser, etc). You could add a version there. That would also allow you to generically handle lists of objects and, in the future, trees of these for the policy rep work.

libsepol/src/boolean_record.c void sepol_bool_free(sepol_bool_t * bool · line 218

Quoted 3 lines
libsepol/src/boolean_record.c +3 -0
+	/* Cleanup. */
+      cleanup:
+	return status;

Why use this idiom when there is no cleanup?

Quoted 22 lines
libsepol/src/boolean_record.c +22 -0
+}
+
+hidden_def(sepol_bool_serialize)
+
+/** Destructively modifies boolean, data and size.
+ *  Allocates space for boolean.
+ *  Caller must free. */
+int sepol_bool_unserialize(sepol_handle_t * handle,
+			   char **data, uint64_t * size,
+			   sepol_bool_t ** boolean)
+{
+	int status = STATUS_SUCCESS;
+	char *name = NULL;
+	size_t *name_size = NULL;
+	int *value = NULL;
+
+	/* Sundry sanity checks. */
+	if (handle == NULL || data == NULL || *data == NULL || size == NULL) {
+		status = STATUS_ERR;
+		goto cleanup;
+	}
+

libsepol/src/boolean_record.c void sepol_bool_free(sepol_bool_t * bool · line 250

Quoted 10 lines
libsepol/src/boolean_record.c +10 -0
+	/* Allocate space. */
+	status = sepol_bool_create(handle, boolean);
+	if (status != STATUS_SUCCESS)
+		goto cleanup;
+
+	/* Boolean name. */
+	status =
+	    sepol_unserialize(handle,
+			      data, size,
+					(void **)&name, &name_size, SEPOL_SERIAL_STRING);

As James said - this isn't valid. Another reason to have the type safe versions.

Karl

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#16 lore raw

PATCH 3/33 libsepol: context serialization

In reply to [email protected]

This adds serialize/unserialize methods for context records.

---
 libsepol/include/sepol/context_record.h |   10 +++
 libsepol/src/context_internal.h         |    2 
 libsepol/src/context_record.c           |   84 ++++++++++++++++++++++++++++++++
 3 files changed, 96 insertions(+)
libsepol/include/sepol/context_record.h +10 -0
Index: selinux-pms-support/libsepol/include/sepol/context_record.h
===================================================================
@@ -1,6 +1,7 @@
 #ifndef _SEPOL_CONTEXT_RECORD_H_
 #define _SEPOL_CONTEXT_RECORD_H_
 
+#include <inttypes.h>
 #include <sepol/handle.h>
 
 struct sepol_context;
@@ -43,6 +44,15 @@ extern int sepol_context_clone(sepol_han
 
 extern void sepol_context_free(sepol_context_t * con);
 
+/* Serialize/Unserialize */
+extern int sepol_context_serialize(sepol_handle_t * handle,
+				   const sepol_context_t * context,
+				   char **data, uint64_t * size);
+
+extern int sepol_context_unserialize(sepol_handle_t * handle,
+				     char **data, uint64_t * size,
+				     sepol_context_t ** context);
+
 /* Parse to/from string */
 extern int sepol_context_from_string(sepol_handle_t * handle,
 				     const char *str, sepol_context_t ** con);
libsepol/src/context_internal.h +2 -0
Index: selinux-pms-support/libsepol/src/context_internal.h
===================================================================
@@ -16,4 +16,6 @@ hidden_proto(sepol_context_clone)
     hidden_proto(sepol_context_set_role)
     hidden_proto(sepol_context_set_type)
     hidden_proto(sepol_context_set_user)
+    hidden_proto(sepol_context_serialize)
+    hidden_proto(sepol_context_unserialize)
 #endif
libsepol/src/context_record.c +84 -0

99 lines not on this page · raw message

Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#17 lore raw

PATCH 4/33 libsepol: interface serialization

In reply to [email protected]

This adds serialize/unserialize methods for iface records.

---
 libsepol/include/sepol/iface_record.h |   10 ++
 libsepol/src/iface_internal.h         |    2 
 libsepol/src/iface_record.c           |  115 ++++++++++++++++++++++++++++++++++
 3 files changed, 127 insertions(+)
libsepol/include/sepol/iface_record.h +10 -0
Index: selinux-pms-support/libsepol/include/sepol/iface_record.h
===================================================================
@@ -1,6 +1,7 @@
 #ifndef _SEPOL_IFACE_RECORD_H_
 #define _SEPOL_IFACE_RECORD_H_
 
+#include <inttypes.h>
 #include <sepol/handle.h>
 #include <sepol/context_record.h>
 
@@ -56,4 +57,13 @@ extern int sepol_iface_clone(sepol_handl
 
 extern void sepol_iface_free(sepol_iface_t * iface);
 
+/* Serialize/Unserialize */
+extern int sepol_iface_serialize(sepol_handle_t * handle,
+				 const sepol_iface_t * iface,
+				 char **data, uint64_t * size);
+
+extern int sepol_iface_unserialize(sepol_handle_t * handle,
+				   char **data, uint64_t * size,
+				   sepol_iface_t ** iface);
+
 #endif
libsepol/src/iface_internal.h +2 -0
Index: selinux-pms-support/libsepol/src/iface_internal.h
===================================================================
@@ -15,4 +15,6 @@ hidden_proto(sepol_iface_create)
     hidden_proto(sepol_iface_set_ifcon)
     hidden_proto(sepol_iface_set_msgcon)
     hidden_proto(sepol_iface_set_name)
+    hidden_proto(sepol_iface_serialize)
+    hidden_proto(sepol_iface_unserialize)
 #endif
libsepol/src/iface_record.c +115 -0

127 lines not on this page · raw message

Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#18 lore raw

PATCH 5/33 libsepol: node serialization

In reply to [email protected]

This adds serialize/unserialize methods for node records.

---
 libsepol/include/sepol/node_record.h |   10 ++
 libsepol/src/node_internal.h         |    2 
 libsepol/src/node_record.c           |  155 +++++++++++++++++++++++++++++++++++
 3 files changed, 167 insertions(+)
libsepol/include/sepol/node_record.h +10 -0
Index: selinux-pms-support/libsepol/include/sepol/node_record.h
===================================================================
@@ -1,6 +1,7 @@
 #ifndef _SEPOL_NODE_RECORD_H_
 #define _SEPOL_NODE_RECORD_H_
 
+#include <inttypes.h>
 #include <stddef.h>
 #include <sepol/context_record.h>
 #include <sepol/handle.h>
@@ -89,4 +90,13 @@ extern int sepol_node_clone(sepol_handle
 
 extern void sepol_node_free(sepol_node_t * node);
 
+/* Serialize/Unserialize */
+extern int sepol_node_serialize(sepol_handle_t * handle,
+				const sepol_node_t * node,
+				char **data, uint64_t * size);
+
+extern int sepol_node_unserialize(sepol_handle_t * handle,
+				  char **data, uint64_t * size,
+				  sepol_node_t ** node);
+
 #endif
libsepol/src/node_internal.h +2 -0
Index: selinux-pms-support/libsepol/src/node_internal.h
===================================================================
@@ -23,4 +23,6 @@ hidden_proto(sepol_node_create)
     hidden_proto(sepol_node_set_mask)
     hidden_proto(sepol_node_set_mask_bytes)
     hidden_proto(sepol_node_set_proto)
+    hidden_proto(sepol_node_serialize)
+    hidden_proto(sepol_node_unserialize)
 #endif
libsepol/src/node_record.c +155 -0

167 lines not on this page · raw message

Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#19 lore raw

PATCH 6/33 libsepol: port serialization

In reply to [email protected]

This adds serialize/unserialize methods for port records.

---
 libsepol/include/sepol/port_record.h |   10 ++
 libsepol/src/port_internal.h         |    2 
 libsepol/src/port_record.c           |  125 +++++++++++++++++++++++++++++++++++
 3 files changed, 137 insertions(+)
libsepol/include/sepol/port_record.h +10 -0
Index: selinux-pms-support/libsepol/include/sepol/port_record.h
===================================================================
@@ -1,6 +1,7 @@
 #ifndef _SEPOL_PORT_RECORD_H_
 #define _SEPOL_PORT_RECORD_H_
 
+#include <inttypes.h>
 #include <sepol/context_record.h>
 #include <sepol/handle.h>
 
@@ -63,4 +64,13 @@ extern int sepol_port_clone(sepol_handle
 
 extern void sepol_port_free(sepol_port_t * port);
 
+/* Serialize/Unserialize */
+extern int sepol_port_serialize(sepol_handle_t * handle,
+				const sepol_port_t * port,
+				char **data, uint64_t * size);
+
+extern int sepol_port_unserialize(sepol_handle_t * handle,
+				  char **data, uint64_t * size,
+				  sepol_port_t ** port);
+
 #endif
libsepol/src/port_internal.h +2 -0
Index: selinux-pms-support/libsepol/src/port_internal.h
===================================================================
@@ -17,4 +17,6 @@ hidden_proto(sepol_port_create)
     hidden_proto(sepol_port_set_con)
     hidden_proto(sepol_port_set_proto)
     hidden_proto(sepol_port_set_range)
+    hidden_proto(sepol_port_serialize)
+    hidden_proto(sepol_port_unserialize)
 #endif
libsepol/src/port_record.c +125 -0

137 lines not on this page · raw message

Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#20 lore raw

PATCH 7/33 libsepol: user serialization

In reply to [email protected]

This adds serialize/unserialize methods for user records.

---
 libsepol/include/sepol/user_record.h |   10 +
 libsepol/src/user_internal.h         |    2 
 libsepol/src/user_record.c           |  178 +++++++++++++++++++++++++++++++++++
 3 files changed, 190 insertions(+)
libsepol/include/sepol/user_record.h +10 -0
Index: selinux-pms-support/libsepol/include/sepol/user_record.h
===================================================================
@@ -1,6 +1,7 @@
 #ifndef _SEPOL_USER_RECORD_H_
 #define _SEPOL_USER_RECORD_H_
 
+#include <inttypes.h>
 #include <stddef.h>
 #include <sepol/handle.h>
 
@@ -73,4 +74,13 @@ extern int sepol_user_clone(sepol_handle
 
 extern void sepol_user_free(sepol_user_t * user);
 
+/* Serialize/Unserialize */
+extern int sepol_user_serialize(sepol_handle_t * handle,
+				const sepol_user_t * user,
+				char **data, uint64_t * size);
+
+extern int sepol_user_unserialize(sepol_handle_t * handle,
+				  char **data, uint64_t * size,
+				  sepol_user_t ** user);
+
 #endif
libsepol/src/user_internal.h +2 -0
Index: selinux-pms-support/libsepol/src/user_internal.h
===================================================================
@@ -17,4 +17,6 @@ hidden_proto(sepol_user_add_role)
     hidden_proto(sepol_user_set_mlslevel)
     hidden_proto(sepol_user_set_mlsrange)
     hidden_proto(sepol_user_set_name)
+    hidden_proto(sepol_user_serialize)
+    hidden_proto(sepol_user_unserialize)
 #endif
libsepol/src/user_record.c +178 -0

190 lines not on this page · raw message

Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#21 lore raw

PATCH 8/33 libsemanage: DESTDIR support in INCLUDE and safe test target

In reply to [email protected]

Added DESTDIR support for the INCLUDE variable. Tests will now properly use the DESTDIR headers instead of the system headers.

Tests are always cleaned before they are remade.

---
 libsemanage/tests/Makefile |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libsemanage/tests/Makefile +2 -2
Index: selinux-pms-support/libsemanage/tests/Makefile
===================================================================
@@ -12,7 +12,7 @@ LIBS = ../src/libsemanage.a ../../libsel
 EXECUTABLE = libsemanage-tests
 CC = gcc
 CFLAGS = -c -g -o0 -Wall -W -Wundef -Wmissing-noreturn -Wmissing-format-attribute -Wno-unused-parameter
-INCLUDE = -I$(TESTSRC) -I$(TESTSRC)/../include/semanage
+INCLUDE = -I$(TESTSRC) -I$(TESTSRC)/../include/semanage -I$(DESTDIR)/usr/include
 LDFLAGS = -lcunit
 OBJECTS = $(SOURCES:.c=.o) 
 
@@ -27,6 +27,6 @@ $(EXECUTABLE): $(OBJECTS) 
 clean distclean: 
 	rm -rf $(OBJECTS) $(EXECUTABLE)
 
-test: all 
+test: clean all
 	./$(EXECUTABLE)
 
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#22 lore raw

PATCH 9/33 libsemanage: dbase/dconfig cleanup

In reply to [email protected]

This passes the entire dconfig for all calls which is necessary to serialize the databases.

---
 libsemanage/src/booleans_policydb.c   |    2 
 libsemanage/src/database.c            |   42 +++++++--
 libsemanage/src/database.h            |   58 +++++++++----
 libsemanage/src/database_activedb.c   |   17 ++-
 libsemanage/src/database_file.c       |   12 +-
 libsemanage/src/database_join.c       |   24 +++--
 libsemanage/src/database_llist.c      |   70 ++++++++++++----
 libsemanage/src/database_llist.h      |   55 ++++++++----
 libsemanage/src/database_policydb.c   |  145 +++++++++++++++++++++-------------
 libsemanage/src/database_policydb.h   |   61 +++++++++++++-
 libsemanage/src/direct_api.c          |   35 +++-----
 libsemanage/src/interfaces_policydb.c |    2 
 libsemanage/src/nodes_policydb.c      |    2 
 libsemanage/src/policy_components.c   |   32 +++----
 libsemanage/src/ports_policydb.c      |    2 
 libsemanage/src/users_base_policydb.c |    2 
 16 files changed, 381 insertions(+), 180 deletions(-)
libsemanage/src/booleans_policydb.c +1 -1
Index: selinux-pms-support/libsemanage/src/booleans_policydb.c
===================================================================
@@ -67,5 +67,5 @@ int bool_policydb_dbase_init(semanage_ha
 void bool_policydb_dbase_release(dbase_config_t * dconfig)
 {
 
-	dbase_policydb_release(dconfig->dbase);
+	dbase_policydb_release(dconfig);
 }
libsemanage/src/database.c +31 -11

105 lines not on this page · raw message

libsemanage/src/database.h +42 -16

140 lines not on this page · raw message

libsemanage/src/database_activedb.c +10 -7
Index: selinux-pms-support/libsemanage/src/database_activedb.c
===================================================================
@@ -30,10 +30,11 @@ struct dbase_activedb {
 };
 
 static int dbase_activedb_cache(semanage_handle_t * handle,
-				dbase_activedb_t * dbase)
+				dbase_config_t * dconfig)
 {
 
-	record_table_t *rtable = dbase_llist_get_rtable(&dbase->llist);
+	dbase_activedb_t *dbase = dconfig->dbase;
+	record_table_t *rtable = dbase_llist_get_rtable(dconfig);
 	record_activedb_table_t *ratable = dbase->ratable;
 
 	record_t **records = NULL;
@@ -74,10 +75,11 @@ static int dbase_activedb_cache(semanage
 }
 
 static int dbase_activedb_flush(semanage_handle_t * handle,
-				dbase_activedb_t * dbase)
+				dbase_config_t * dconfig)
 {
-
-	record_table_t *rtable = dbase_llist_get_rtable(&dbase->llist);
+	int status = STATUS_SUCCESS;
+	dbase_activedb_t *dbase = dconfig->dbase;
+	record_table_t *rtable = dbase_llist_get_rtable(dconfig);
 	record_activedb_table_t *ratable = dbase->ratable;
 
 	record_t **records = NULL;
@@ -89,7 +91,8 @@ static int dbase_activedb_flush(semanage
 		return STATUS_SUCCESS;
 
 	/* Fetch list */
-	if (dbase_llist_list(handle, &dbase->llist, &records, &rcount) < 0)
+	status = dbase_llist_list(handle, dconfig, &records, &rcount);
+	if (status != STATUS_SUCCESS)
 		goto err;
 
 	/* Commit */
@@ -123,7 +126,7 @@ int dbase_activedb_init(semanage_handle_
 		goto omem;
 
 	tmp_dbase->ratable = ratable;
-	dbase_llist_init(&tmp_dbase->llist, rtable, &SEMANAGE_ACTIVEDB_DTABLE);
+	dbase_llist_init(&tmp_dbase->llist, rtable);
 
 	*dbase = tmp_dbase;
 
libsemanage/src/database_file.c +8 -4
Index: selinux-pms-support/libsemanage/src/database_file.c
===================================================================
@@ -58,10 +58,12 @@ static int construct_filename(semanage_h
 	return STATUS_SUCCESS;
 }
 
-static int dbase_file_cache(semanage_handle_t * handle, dbase_file_t * dbase)
+static int dbase_file_cache(semanage_handle_t * handle,
+			    dbase_config_t * dconfig)
 {
 
-	record_table_t *rtable = dbase_llist_get_rtable(&dbase->llist);
+	dbase_file_t *dbase = dconfig->dbase;
+	record_table_t *rtable = dbase_llist_get_rtable(dconfig);
 	record_file_table_t *rftable = dbase->rftable;
 
 	record_t *process_record = NULL;
@@ -135,9 +137,11 @@ static int dbase_file_cache(semanage_han
 }
 
 /* Flush database to file */
-static int dbase_file_flush(semanage_handle_t * handle, dbase_file_t * dbase)
+static int dbase_file_flush(semanage_handle_t * handle,
+			    dbase_config_t * dconfig)
 {
 
+	dbase_file_t *dbase = dconfig->dbase;
 	record_file_table_t *rftable = dbase->rftable;
 
 	cache_entry_t *ptr;
@@ -197,7 +201,7 @@ int dbase_file_init(semanage_handle_t * 
 
 	tmp_dbase->suffix = suffix;
 	tmp_dbase->rftable = rftable;
-	dbase_llist_init(&tmp_dbase->llist, rtable, &SEMANAGE_FILE_DTABLE);
+	dbase_llist_init(&tmp_dbase->llist, rtable);
 
 	*dbase = tmp_dbase;
 
libsemanage/src/database_join.c +15 -9
Index: selinux-pms-support/libsemanage/src/database_join.c
===================================================================
@@ -34,15 +34,18 @@ struct dbase_join {
 	record_join_table_t *rjtable;
 };
 
-static int dbase_join_cache(semanage_handle_t * handle, dbase_join_t * dbase)
+static int dbase_join_cache(semanage_handle_t * handle,
+			    dbase_config_t * dconfig)
 {
 
+	dbase_join_t *dbase = dconfig->dbase;
+
 	/* Extract all the object tables information */
-	dbase_t *dbase1 = dbase->join1->dbase;
-	dbase_t *dbase2 = dbase->join2->dbase;
+	dbase_config_t *dbase1 = dbase->join1;
+	dbase_config_t *dbase2 = dbase->join2;
 	dbase_table_t *dtable1 = dbase->join1->dtable;
 	dbase_table_t *dtable2 = dbase->join2->dtable;
-	record_table_t *rtable = dbase_llist_get_rtable(&dbase->llist);
+	record_table_t *rtable = dbase_llist_get_rtable(dconfig);
 	record_join_table_t *rjtable = dbase->rjtable;
 	record_table_t *rtable1 = dtable1->get_rtable(dbase1);
 	record_table_t *rtable2 = dtable2->get_rtable(dbase2);
@@ -166,15 +169,18 @@ static int dbase_join_cache(semanage_han
 }
 
 /* Flush database */
-static int dbase_join_flush(semanage_handle_t * handle, dbase_join_t * dbase)
+static int dbase_join_flush(semanage_handle_t * handle,
+			    dbase_config_t * dconfig)
 {
 
+	dbase_join_t *dbase = dconfig->dbase;
+
 	/* Extract all the object tables information */
-	dbase_t *dbase1 = dbase->join1->dbase;
-	dbase_t *dbase2 = dbase->join2->dbase;
+	dbase_config_t *dbase1 = dbase->join1;
+	dbase_config_t *dbase2 = dbase->join2;
 	dbase_table_t *dtable1 = dbase->join1->dtable;
 	dbase_table_t *dtable2 = dbase->join2->dtable;
-	record_table_t *rtable = dbase_llist_get_rtable(&dbase->llist);
+	record_table_t *rtable = dbase_llist_get_rtable(dconfig);
 	record_join_table_t *rjtable = dbase->rjtable;
 	record_table_t *rtable1 = dtable1->get_rtable(dbase1);
 	record_table_t *rtable2 = dtable2->get_rtable(dbase2);
@@ -247,7 +253,7 @@ int dbase_join_init(semanage_handle_t * 
 	if (!tmp_dbase)
 		goto omem;
 
-	dbase_llist_init(&tmp_dbase->llist, rtable, &SEMANAGE_JOIN_DTABLE);
+	dbase_llist_init(&tmp_dbase->llist, rtable);
 
 	tmp_dbase->rjtable = rjtable;
 	tmp_dbase->join1 = join1;
libsemanage/src/database_llist.c +52 -18

185 lines not on this page · raw message

libsemanage/src/database_llist.h +37 -18

109 lines not on this page · raw message

libsemanage/src/database_policydb.c +91 -54

307 lines not on this page · raw message

libsemanage/src/database_policydb.h +57 -4

83 lines not on this page · raw message

libsemanage/src/direct_api.c +17 -18
Index: selinux-pms-support/libsemanage/src/direct_api.c
===================================================================
@@ -467,25 +467,25 @@ static int semanage_direct_commit(semana
 
 	/* Before we do anything else, flush the join to its component parts.
 	 * This *does not* flush to disk automatically */
-	if (users->dtable->is_modified(users->dbase)) {
-		retval = users->dtable->flush(sh, users->dbase);
+	if (users->dtable->is_modified(users)) {
+		retval = users->dtable->flush(sh, users);
 		if (retval < 0)
 			goto cleanup;
 	}
 
 	/* Decide if anything was modified */
-	fcontexts_modified = fcontexts->dtable->is_modified(fcontexts->dbase);
-	seusers_modified = seusers->dtable->is_modified(seusers->dbase);
+	fcontexts_modified = fcontexts->dtable->is_modified(fcontexts);
+	seusers_modified = seusers->dtable->is_modified(seusers);
 	users_extra_modified =
-	    users_extra->dtable->is_modified(users_extra->dbase);
-	ports_modified = ports->dtable->is_modified(ports->dbase);
+	    users_extra->dtable->is_modified(users_extra);
+	ports_modified = ports->dtable->is_modified(ports);
 
 	modified = sh->modules_modified;
 	modified |= ports_modified;
-	modified |= users->dtable->is_modified(users_base->dbase);
-	modified |= bools->dtable->is_modified(bools->dbase);
-	modified |= ifaces->dtable->is_modified(ifaces->dbase);
-	modified |= nodes->dtable->is_modified(nodes->dbase);
+	modified |= users->dtable->is_modified(users_base);
+	modified |= bools->dtable->is_modified(bools);
+	modified |= ifaces->dtable->is_modified(ifaces);
+	modified |= nodes->dtable->is_modified(nodes);
 
 	/* FIXME: get rid of these, once we support loading the existing policy,
 	 * instead of rebuilding it */
@@ -588,7 +588,7 @@ static int semanage_direct_commit(semana
 			pseusers->dtable->drop_cache(pseusers->dbase);
 
 		} else {
-			retval = pseusers->dtable->clear(sh, pseusers->dbase);
+			retval = pseusers->dtable->clear(sh, pseusers);
 			if (retval < 0)
 				goto cleanup;
 		}
@@ -608,7 +608,7 @@ static int semanage_direct_commit(semana
 			pusers_extra->dtable->drop_cache(pusers_extra->dbase);
 
 		} else {
-			retval = pusers_extra->dtable->clear(sh, pusers_extra->dbase);
+			retval = pusers_extra->dtable->clear(sh, pusers_extra);
 			if (retval < 0)
 				goto cleanup;
 		}
@@ -641,12 +641,11 @@ static int semanage_direct_commit(semana
 		if (retval < 0)
 			goto cleanup;
 
-		dbase_policydb_attach((dbase_policydb_t *) pusers_base->dbase,
-				      out);
-		dbase_policydb_attach((dbase_policydb_t *) pports->dbase, out);
-		dbase_policydb_attach((dbase_policydb_t *) pifaces->dbase, out);
-		dbase_policydb_attach((dbase_policydb_t *) pbools->dbase, out);
-		dbase_policydb_attach((dbase_policydb_t *) pnodes->dbase, out);
+		dbase_policydb_attach(pusers_base, out);
+		dbase_policydb_attach(pports, out);
+		dbase_policydb_attach(pifaces, out);
+		dbase_policydb_attach(pbools, out);
+		dbase_policydb_attach(pnodes, out);
 
 		/* ============= Apply changes, and verify  =============== */
 
libsemanage/src/interfaces_policydb.c +1 -1
Index: selinux-pms-support/libsemanage/src/interfaces_policydb.c
===================================================================
@@ -63,5 +63,5 @@ int iface_policydb_dbase_init(semanage_h
 void iface_policydb_dbase_release(dbase_config_t * dconfig)
 {
 
-	dbase_policydb_release(dconfig->dbase);
+	dbase_policydb_release(dconfig);
 }
libsemanage/src/nodes_policydb.c +1 -1
Index: selinux-pms-support/libsemanage/src/nodes_policydb.c
===================================================================
@@ -63,5 +63,5 @@ int node_policydb_dbase_init(semanage_ha
 void node_policydb_dbase_release(dbase_config_t * dconfig)
 {
 
-	dbase_policydb_release(dconfig->dbase);
+	dbase_policydb_release(dconfig);
 }
libsemanage/src/policy_components.c +16 -16
Index: selinux-pms-support/libsemanage/src/policy_components.c
===================================================================
@@ -17,25 +17,28 @@ static int clear_obsolete(semanage_handl
 			  unsigned int nrecords,
 			  dbase_config_t * src, dbase_config_t * dst)
 {
-
+	int status = STATUS_SUCCESS;
 	record_key_t *key = NULL;
 	unsigned int i;
 
 	dbase_table_t *src_dtable = src->dtable;
 	dbase_table_t *dst_dtable = dst->dtable;
-	record_table_t *rtable = src_dtable->get_rtable(src->dbase);
+	record_table_t *rtable = src_dtable->get_rtable(src);
 
 	for (i = 0; i < nrecords; i++) {
 		int exists;
 
-		if (rtable->key_extract(handle, records[i], &key) < 0)
+		status = rtable->key_extract(handle, records[i], &key);
+		if (status != STATUS_SUCCESS)
 			goto err;
 
-		if (dst_dtable->exists(handle, dst->dbase, key, &exists) < 0)
+		status = dst_dtable->exists(handle, dst, key, &exists);
+		if (status != STATUS_SUCCESS)
 			goto err;
 
 		if (!exists) {
-			if (src_dtable->del(handle, src->dbase, key) < 0)
+			status = src_dtable->del(handle, src, key);
+			if (status != STATUS_SUCCESS)
 				goto err;
 
 			rtable->free(records[i]);
@@ -64,9 +67,8 @@ static int load_records(semanage_handle_
 	unsigned int i;
 	record_key_t *rkey = NULL;
 
-	dbase_t *dbase = dst->dbase;
 	dbase_table_t *dtable = dst->dtable;
-	record_table_t *rtable = dtable->get_rtable(dbase);
+	record_table_t *rtable = dtable->get_rtable(dst);
 
 	for (i = 0; i < nrecords; i++) {
 
@@ -78,11 +80,11 @@ static int load_records(semanage_handle_
 			goto err;
 
 		if (mode & MODE_SET &&
-		    dtable->set(handle, dbase, rkey, records[i]) < 0)
+		    dtable->set(handle, dst, rkey, records[i]) < 0)
 			goto err;
 
 		else if (mode & MODE_MODIFY &&
-			 dtable->modify(handle, dbase, rkey, records[i]) < 0)
+			 dtable->modify(handle, dst, rkey, records[i]) < 0)
 			goto err;
 
 		rtable->key_free(rkey);
@@ -149,17 +151,16 @@ int semanage_base_merge_components(seman
 		dbase_config_t *src = components[i].src;
 		dbase_config_t *dst = components[i].dst;
 		int mode = components[i].mode;
-		record_table_t *rtable = src->dtable->get_rtable(src->dbase);
+		record_table_t *rtable = src->dtable->get_rtable(src);
 
 		/* Must invoke cache function first */
-		if (src->dtable->cache(handle, src->dbase) < 0)
+		if (src->dtable->cache(handle, src) < 0)
 			goto err;
-		if (dst->dtable->cache(handle, dst->dbase) < 0)
+		if (dst->dtable->cache(handle, dst) < 0)
 			goto err;
 
 		/* List all records */
-		if (src->dtable->list(handle, src->dbase,
-				      &records, &nrecords) < 0)
+		if (src->dtable->list(handle, src, &records, &nrecords) < 0)
 			goto err;
 
 		/* Sort records on MODE_SORT */
@@ -223,8 +224,7 @@ int semanage_commit_components(semanage_
 
 	for (i = 0; i < CCOUNT; i++) {
 		/* Flush to disk */
-		if (components[i]->dtable->flush(handle, components[i]->dbase) <
-		    0)
+		if (components[i]->dtable->flush(handle, components[i]) < 0)
 			goto err;
 	}
 
libsemanage/src/ports_policydb.c +1 -1
Index: selinux-pms-support/libsemanage/src/ports_policydb.c
===================================================================
@@ -63,5 +63,5 @@ int port_policydb_dbase_init(semanage_ha
 void port_policydb_dbase_release(dbase_config_t * dconfig)
 {
 
-	dbase_policydb_release(dconfig->dbase);
+	dbase_policydb_release(dconfig);
 }
libsemanage/src/users_base_policydb.c +1 -1
Index: selinux-pms-support/libsemanage/src/users_base_policydb.c
===================================================================
@@ -62,5 +62,5 @@ int user_base_policydb_dbase_init(semana
 void user_base_policydb_dbase_release(dbase_config_t * dconfig)
 {
 
-	dbase_policydb_release(dconfig->dbase);
+	dbase_policydb_release(dconfig);
 }
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#23 lore raw

PATCH 10/33 libsemanage: database serialization

In reply to [email protected]

This adds serialize/unserialize methods for databases

---
 libsemanage/src/database.c          |  153 ++++++++++++++++++++++++++++++++++++
 libsemanage/src/database.h          |   21 ++++
 libsemanage/src/database_policydb.c |   10 ++
 3 files changed, 184 insertions(+)
libsemanage/src/database.c +153 -0
Index: selinux-pms-support/libsemanage/src/database.c
===================================================================
@@ -20,6 +20,8 @@
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <limits.h>
+#include <stdlib.h>
 #include <semanage/handle.h>
 #include "semanage_store.h"
 #include "semanage_conf.h"
@@ -219,3 +221,154 @@ int dbase_list(semanage_handle_t * handl
 
 	return exit_ro(handle, dconfig);
 }
+
+/* Serialize the given database. */
+int dbase_serialize(struct semanage_handle *handle,
+		    dbase_config_t * dconfig,
+		    char **data, uint64_t * data_length)
+{
+	int status = 0;
+	unsigned int count = 0;
+	unsigned int completed_count = 0;
+	unsigned int i = 0;
+	uint64_t size = 0;
+	char *ptr = NULL;
+	record_t **records = NULL;
+
+	status = enter_ro(handle, dconfig);
+	if (status != STATUS_SUCCESS)
+		goto err;
+
+	record_table_t *rtable = dconfig->dtable->get_rtable(dconfig);
+
+	/* Initialize */
+	*data = NULL;
+	*data_length = 0;
+
+	/* Get a list of the records. */
+	status = dconfig->dtable->list(handle, dconfig, &records, &count);
+	if (status != STATUS_SUCCESS)
+		goto err;
+
+	/* Iterate over all records and calculate
+	 * the size of the serialized data. */
+	for (i = 0; i < count; i++) {
+		status = rtable->serialize(handle, records[i], NULL, &size);
+		if (status != STATUS_SUCCESS) {
+			completed_count = i - 1;
+			goto err;
+		}
+	}
+
+	*data_length = size;
+
+	/* Allocate space for the serialized data. */
+	*data = calloc((size_t) size, sizeof(char));
+	if (data == NULL)
+		goto err;
+
+	/* Iterate over all records and serialize them. */
+	ptr = *data;
+	completed_count = 0;
+	for (i = 0; i < count; i++) {
+		status = rtable->serialize(handle, records[i], &ptr, NULL);
+		if (status != STATUS_SUCCESS) {
+			completed_count = i - 1;
+			goto err;
+		}
+	}
+
+	/* Clean up. */
+	for (i = 0; i < count; i++)
+		rtable->free(records[i]);
+	free(records);
+
+	if (exit_ro(handle, dconfig) < 0)
+		goto err;
+
+	return STATUS_SUCCESS;
+
+      err:
+	if (records) {
+		for (i = 0; i < completed_count; i++)
+			rtable->free(records[i]);
+	}
+	free(records);
+	free(*data);
+	*data = NULL;
+	*data_length = 0;
+
+	exit_ro(handle, dconfig);
+
+	return STATUS_ERR;
+}
+
+/* Unserialize the given database.
+ * This function DOES move the data pointer passed in.
+ */
+int dbase_unserialize(struct semanage_handle *handle,
+		      dbase_config_t * dconfig,
+		      char *data, uint64_t data_length)
+{
+	int status = 0;
+	char *ptr = data;
+	uint64_t current_length = data_length;
+	record_t *record = NULL;
+	record_key_t *key = NULL;
+	record_table_t *rtable = dconfig->dtable->get_rtable(dconfig);
+	unsigned int write = 0;
+
+	if ((data == NULL) || (data_length == 0)) {
+		status = dconfig->dtable->clear(handle, dconfig);
+		if (status < 0)
+			goto err;
+		return STATUS_SUCCESS;
+	}
+
+	/* Iterate over the serialized records, adding them
+	 * to the database one by one. */
+	while (current_length > 0) {
+		status =
+		    rtable->unserialize(handle, &ptr, &current_length, &record);
+		if (status != STATUS_SUCCESS)
+			goto err;
+
+		status = rtable->key_extract(handle, record, &key);
+		if (status != STATUS_SUCCESS)
+			goto err;
+
+		if (write == 1) {
+			status = dconfig->dtable->add(handle, dconfig, key, record);
+			if (status != STATUS_SUCCESS)
+				goto err;
+		}
+
+		rtable->key_free(key);
+		key = NULL;
+		rtable->free(record);
+		record = NULL;
+
+		if (current_length == 0 && write == 0) {
+			/* Remove all current entries to the database. */
+			status = dconfig->dtable->clear(handle, dconfig);
+			if (status < 0)
+				goto err;
+
+			/* Rerun and actually add the entries. */
+			write = 1;
+			ptr = data;
+			current_length = data_length;
+		}
+	}
+	/* Unserializing should move the pointer passed in */
+	data = ptr;
+
+	return STATUS_SUCCESS;
+
+err:
+	rtable->key_free(key);
+	key = NULL;
+	rtable->free(record);
+	record = NULL;
+	return STATUS_ERR;
+}
libsemanage/src/database.h +21 -0
Index: selinux-pms-support/libsemanage/src/database.h
===================================================================
@@ -23,6 +23,8 @@
 #ifndef _SEMANAGE_DATABASE_H_
 #define _SEMANAGE_DATABASE_H_
 
+#include <inttypes.h>
+
 #ifndef DBASE_RECORD_DEFINED
 typedef void *record_t;
 typedef void *record_key_t;
@@ -70,6 +72,17 @@ typedef struct record_table {
 	int (*clone) (struct semanage_handle * handle,
 		      const record_t * rec, record_t ** new_rec);
 
+	/* Serialize this record.  rec_data must be allocated
+	 * and large enough to hold the result. */
+	int (*serialize) (struct semanage_handle * handle,
+			  const record_t * rec,
+			  char **rec_data, uint64_t * size);
+
+	/* Unserialize this record data */
+	int (*unserialize) (struct semanage_handle * handle,
+					char **rec_data, uint64_t * size,
+			    record_t ** rec);
+
 	/* Deallocate record resources. Must sucessfully handle NULL. */
 	void (*free) (record_t * rec);
 
@@ -241,4 +254,12 @@ extern int dbase_list(struct semanage_ha
 		      dbase_config_t * dconfig,
 		      record_t *** records, unsigned int *count);
 
+extern int dbase_serialize(struct semanage_handle *handle,
+			   dbase_config_t * dconfig,
+			   char **data, uint64_t * data_length);
+
+extern int dbase_unserialize(struct semanage_handle *handle,
+			     dbase_config_t * dconfig,
+			     char *data, uint64_t data_length);
+
 #endif
libsemanage/src/database_policydb.c +10 -0
Index: selinux-pms-support/libsemanage/src/database_policydb.c
===================================================================
@@ -21,6 +21,7 @@
  */
 
 /* Object: dbase_policydb_t (Policy)
+ * Extends: dbase_llist_t (Linked List)
  * Implements: dbase_t (Database)
  */
 
@@ -38,6 +39,7 @@ typedef struct dbase_policydb dbase_t;
 #include <sepol/policydb.h>
 
 #include "database_policydb.h"
+#include "database_llist.h"
 #include "semanage_store.h"
 #include "handle.h"
 #include "debug.h"
@@ -45,6 +47,11 @@ typedef struct dbase_policydb dbase_t;
 /* POLICYDB dbase */
 struct dbase_policydb {
 
+	/* Parent object - must always be
+	 * the first field - here we are using
+	 * a linked list to store the records */
+	dbase_llist_t llist;
+
 	/* Backing file suffix */
 	const char *suffix;
 
@@ -65,6 +72,7 @@ void dbase_policydb_drop_cache(dbase_t *
 {
 
 	if (dbase->cache_serial >= 0) {
+		dbase_llist_drop_cache(&dbase->llist);
 		sepol_policydb_free(dbase->policydb);
 		dbase->cache_serial = -1;
 		dbase->modified = 0;
@@ -242,6 +250,8 @@ int dbase_policydb_init(semanage_handle_
 	tmp_dbase->cache_serial = -1;
 	tmp_dbase->modified = 0;
 	tmp_dbase->attached = 0;
+
+	dbase_llist_init(&tmp_dbase->llist, rtable);
 	*dbase = tmp_dbase;
 
 	return STATUS_SUCCESS;
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#24 lore raw

PATCH 11/33 libsemanage: endianness macros

In reply to [email protected]
---
 libsemanage/src/byteswap.h |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
libsemanage/src/byteswap.h new file +20 -0
Index: selinux-pms-support/libsemanage/src/byteswap.h
===================================================================
@@ -0,0 +1,20 @@
+/* Byte swap macros for libsemanage. */
+#ifndef __SEMANAGE_BYTESWAP_H__
+#define __SEMANAGE_BYTESWAP_H__
+
+#include <byteswap.h>
+#include <endian.h>
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define cpu_to_le32(x) (x)
+#define le32_to_cpu(x) (x)
+#define cpu_to_le64(x) (x)
+#define le64_to_cpu(x) (x)
+#else
+#define cpu_to_le32(x) bswap_32(x)
+#define le32_to_cpu(x) bswap_32(x)
+#define cpu_to_le64(x) bswap_64(x)
+#define le64_to_cpu(x) bswap_64(x)
+#endif
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#25 lore raw

PATCH 12/33 libsemanage: basic serialization

In reply to [email protected]

This is the serialization infrastructure for libsemanage.

---
 libsemanage/include/semanage/handle.h |   17 +
 libsemanage/src/handle.c              |   28 ++
 libsemanage/src/handle_internal.h     |    5 
 libsemanage/src/libsemanage.map       |    1 
 libsemanage/src/serialize.c           |  389 ++++++++++++++++++++++++++++++++++
 libsemanage/src/serialize.h           |   45 +++
 6 files changed, 485 insertions(+)
libsemanage/include/semanage/handle.h +17 -0
Index: selinux-pms-support/libsemanage/include/semanage/handle.h
===================================================================
@@ -21,6 +21,11 @@
 #ifndef _SEMANAGE_HANDLE_H_
 #define _SEMANAGE_HANDLE_H_
 
+#define SEMANAGE_SERIAL_VERSION_MAJOR 1
+#define SEMANAGE_SERIAL_VERSION_MINOR 0
+
+#include <inttypes.h>
+
 /* All accesses with semanage are through a "semanage_handle".  The
  * handle may ultimately reference local config files,
  * the binary policy file, a module store, or a policy management server. 
@@ -38,6 +43,18 @@ semanage_handle_t *semanage_handle_creat
  * previously called if the handle was connected. */
 void semanage_handle_destroy(semanage_handle_t *);
 
+/* Get the serialization version. */
+int semanage_handle_get_version(semanage_handle_t *sh, uint32_t * major, uint32_t * minor);
+
+/* Set the serialization version. */
+int semanage_handle_set_version(semanage_handle_t *sh, uint32_t major, uint32_t minor);
+
+/* Serialize the serialization version. */
+int semanage_handle_version_serialize(semanage_handle_t *sh, char **data, uint64_t *size);
+
+/* Unserialize the serialization version. */
+int semanage_handle_version_unserialize(semanage_handle_t *sh, char **data, uint64_t *size);
+
 /* This is the type of connection to the store, for now only
  * direct is supported */
 enum semanage_connect_type {
libsemanage/src/handle.c +28 -0
Index: selinux-pms-support/libsemanage/src/handle.c
===================================================================
@@ -82,6 +82,34 @@ semanage_handle_t *semanage_handle_creat
 	return NULL;
 }
 
+int semanage_handle_get_version(semanage_handle_t *sh, uint32_t * major, uint32_t * minor)
+{
+	return sepol_handle_get_version(sh->sepolh, major, minor);
+}
+
+hidden_def(semanage_handle_get_version)
+
+int semanage_handle_set_version(semanage_handle_t *sh, uint32_t major, uint32_t minor)
+{
+	return sepol_handle_set_version(sh->sepolh, major, minor);
+}
+
+hidden_def(semanage_handle_set_version)
+
+int semanage_handle_version_serialize(semanage_handle_t *sh, char **data, uint64_t *size)
+{
+	return sepol_handle_version_serialize(sh->sepolh, data, size);
+}
+
+hidden_def(semanage_handle_version_serialize)
+
+int semanage_handle_version_unserialize(semanage_handle_t *sh, char **data, uint64_t *size)
+{
+	return sepol_handle_version_unserialize(sh->sepolh, data, size);
+}
+
+hidden_def(semanage_handle_version_unserialize)
+
 void semanage_set_rebuild(semanage_handle_t * sh, int do_rebuild)
 {
 
libsemanage/src/handle_internal.h +5 -0
Index: selinux-pms-support/libsemanage/src/handle_internal.h
===================================================================
@@ -8,4 +8,9 @@ hidden_proto(semanage_begin_transaction)
     hidden_proto(semanage_handle_destroy)
     hidden_proto(semanage_reload_policy)
     hidden_proto(semanage_access_check)
+hidden_proto(semanage_handle_get_version)
+hidden_proto(semanage_handle_set_version)
+hidden_proto(semanage_handle_version_serialize)
+hidden_proto(semanage_handle_version_unserialize)
+
 #endif
libsemanage/src/libsemanage.map +1 -0
Index: selinux-pms-support/libsemanage/src/libsemanage.map
===================================================================
@@ -13,6 +13,7 @@ LIBSEMANAGE_1.0 {
 	  semanage_iface_*; semanage_port_*; semanage_context_*;
 	  semanage_node_*;
 	  semanage_fcontext_*; semanage_access_check; semanage_set_create_store;
+	  semanage_*_serialize; semanage_*_unserialize;
 	  semanage_is_connected;
   local: *;
 };
libsemanage/src/serialize.c new file +389 -0

389 lines not on this page · raw message

libsemanage/src/serialize.h new file +45 -0

45 lines not on this page · raw message

Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#26 lore raw

Re: [PATCH 12/33] libsemanage: basic serialization

Quoted 3 lines · On Mon, 2007-04-23 at 17:35 -0400, [email protected] wrote:

plain text document attachment (semanage.serialize.diff) This is the serialization infrastructure for libsemanage.

We have talked about this in the past, but I think the duplication between libsemanage and libsepol should be removed. This is just ridiculous.

Karl

Quoted 544 lines
---
 libsemanage/include/semanage/handle.h |   17 +
 libsemanage/src/handle.c              |   28 ++
 libsemanage/src/handle_internal.h     |    5 
 libsemanage/src/libsemanage.map       |    1 
 libsemanage/src/serialize.c           |  389 ++++++++++++++++++++++++++++++++++
 libsemanage/src/serialize.h           |   45 +++
 6 files changed, 485 insertions(+)

Index: selinux-pms-support/libsemanage/include/semanage/handle.h
===================================================================

libsemanage/include/semanage/handle.h +17 -0
@@ -21,6 +21,11 @@
 #ifndef _SEMANAGE_HANDLE_H_
 #define _SEMANAGE_HANDLE_H_
 
+#define SEMANAGE_SERIAL_VERSION_MAJOR 1
+#define SEMANAGE_SERIAL_VERSION_MINOR 0
+
+#include <inttypes.h>
+
 /* All accesses with semanage are through a "semanage_handle".  The
  * handle may ultimately reference local config files,
  * the binary policy file, a module store, or a policy management server. 
@@ -38,6 +43,18 @@ semanage_handle_t *semanage_handle_creat
  * previously called if the handle was connected. */
 void semanage_handle_destroy(semanage_handle_t *);
 
+/* Get the serialization version. */
+int semanage_handle_get_version(semanage_handle_t *sh, uint32_t * major, uint32_t * minor);
+
+/* Set the serialization version. */
+int semanage_handle_set_version(semanage_handle_t *sh, uint32_t major, uint32_t minor);
+
+/* Serialize the serialization version. */
+int semanage_handle_version_serialize(semanage_handle_t *sh, char **data, uint64_t *size);
+
+/* Unserialize the serialization version. */
+int semanage_handle_version_unserialize(semanage_handle_t *sh, char **data, uint64_t *size);
+
 /* This is the type of connection to the store, for now only
  * direct is supported */
 enum semanage_connect_type {

Index: selinux-pms-support/libsemanage/src/handle.c
===================================================================

libsemanage/src/handle.c +28 -0
@@ -82,6 +82,34 @@ semanage_handle_t *semanage_handle_creat
 	return NULL;
 }
 
+int semanage_handle_get_version(semanage_handle_t *sh, uint32_t * major, uint32_t * minor)
+{
+	return sepol_handle_get_version(sh->sepolh, major, minor);
+}
+
+hidden_def(semanage_handle_get_version)
+
+int semanage_handle_set_version(semanage_handle_t *sh, uint32_t major, uint32_t minor)
+{
+	return sepol_handle_set_version(sh->sepolh, major, minor);
+}
+
+hidden_def(semanage_handle_set_version)
+
+int semanage_handle_version_serialize(semanage_handle_t *sh, char **data, uint64_t *size)
+{
+	return sepol_handle_version_serialize(sh->sepolh, data, size);
+}
+
+hidden_def(semanage_handle_version_serialize)
+
+int semanage_handle_version_unserialize(semanage_handle_t *sh, char **data, uint64_t *size)
+{
+	return sepol_handle_version_unserialize(sh->sepolh, data, size);
+}
+
+hidden_def(semanage_handle_version_unserialize)
+
 void semanage_set_rebuild(semanage_handle_t * sh, int do_rebuild)
 {
 

Index: selinux-pms-support/libsemanage/src/handle_internal.h
===================================================================

libsemanage/src/handle_internal.h +5 -0
@@ -8,4 +8,9 @@ hidden_proto(semanage_begin_transaction)
     hidden_proto(semanage_handle_destroy)
     hidden_proto(semanage_reload_policy)
     hidden_proto(semanage_access_check)
+hidden_proto(semanage_handle_get_version)
+hidden_proto(semanage_handle_set_version)
+hidden_proto(semanage_handle_version_serialize)
+hidden_proto(semanage_handle_version_unserialize)
+
 #endif

Index: selinux-pms-support/libsemanage/src/libsemanage.map
===================================================================

libsemanage/src/libsemanage.map +1 -0
@@ -13,6 +13,7 @@ LIBSEMANAGE_1.0 {
 	  semanage_iface_*; semanage_port_*; semanage_context_*;
 	  semanage_node_*;
 	  semanage_fcontext_*; semanage_access_check; semanage_set_create_store;
+	  semanage_*_serialize; semanage_*_unserialize;
 	  semanage_is_connected;
   local: *;
 };

Index: selinux-pms-support/libsemanage/src/serialize.c
===================================================================

libsemanage/src/serialize.c new file +389 -0
@@ -0,0 +1,389 @@
+/* Author: Caleb Case <[email protected]>
+ *
+ * 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
+ *  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 <string.h>
+#include <limits.h>
+
+#include "handle.h"
+#include "debug.h"
+#include "serialize.h"
+#include "byteswap.h"
+
+/* This file provides general serialize and unserialize functions. */
+
+/** Serializes various kinds of datum.
+ *
+ *  Two use cases:
+ *  1) Calling serialize with a non-NULL size.
+ *     This causes serialize to calculate the expected
+ *     size of serializing.  No serialization occurs.
+ *     Destructively modifies size.  Data may be NULL.
+ *  2) Calling serialize with a NULL size.
+ *     This results in data being filled with the
+ *     serialized information.  Caller must pre-allocate
+ *     space for data.  Destructively modifies data.
+ *
+ *  This function acts iteratively moving the *data or size values.
+ *
+ *  Supported datum_types (defined in serialize.h):
+ *
+ *  SEMANAGE_SERIAL_INT32_T
+ *    Serializes datum to a int32_t as defined in inttypes.h
+ *    datum may NOT be NULL.
+ *    datum_length is not utilized.
+ *  SEMANAGE_SERIAL_UINT32_T
+ *    Serializes datum to a uint32_t as defined in inttypes.h
+ *    datum may NOT be NULL.
+ *    datum_length is not utilized.
+ *  SEMANAGE_SERIAL_SIZE_T
+ *    Serializes datum to a size_t as defined in stddef.h
+ *    datum may NOT be NULL.
+ *    datum_length is not utilized.
+ *  SEMANAGE_SERIAL_STRING
+ *    Serializes a char*.
+ *    datum may be NULL.
+ *    datum_length should be the length of the string as returned by strlen.
+ *  SEMANAGE_SERIAL_STRING_ARRAY
+ *    Serializes a char**.
+ *    datum may be NULL.
+ *    datum_length should be the size of the array.
+ *    Each string will be serialized as per SEMANAGE_SERIAL_STRING and its size
+ *    determined via strlen.
+ *
+ *  NULL pointers are distinguished (where they are allowed at all).
+ *  In the case of strings this means that a NULL char* has a different
+ *  serialization from the empty string "".
+ *
+ */
+int semanage_serialize(semanage_handle_t * handle,
+		    const void *datum,
+		    size_t datum_length,
+		    unsigned int datum_type, char **data, uint64_t * size)
+{
+	int status;
+	unsigned int flags;
+	uint32_t i;
+	void *temp = NULL;
+
+	switch (datum_type) {
+		case SEMANAGE_SERIAL_INT32_T:
+		case SEMANAGE_SERIAL_UINT32_T:
+			if (size == NULL) {
+				temp = calloc(1, sizeof(int32_t));
+				if (temp == NULL) {
+					status = STATUS_ERR;
+					goto cleanup;
+				}
+
+				*((int32_t *)temp) = cpu_to_le32(*((int32_t *) datum));
+				memcpy(*data, temp, sizeof(int32_t));
+				*data += sizeof(int32_t);
+			}
+			else
+				*size += sizeof(int32_t);
+			break;
+		case SEMANAGE_SERIAL_SIZE_T:
+			if (size == NULL) {
+				temp = calloc(1, sizeof(uint64_t));
+				if (temp == NULL) {
+					status = STATUS_ERR;
+					goto cleanup;
+				}
+
+				*((uint64_t *)temp) = cpu_to_le64(*((size_t *) datum));
+
+				memcpy(*data, temp, sizeof(uint64_t));
+				*data += sizeof(uint64_t);
+			}
+			else
+				*size += sizeof(uint64_t);
+			break;
+		case SEMANAGE_SERIAL_STRING:
+			/* Flags (intended as a bitmap):
+			 * 0 == NULL
+			 * 1 == Non NULL
+			 */
+			flags = (datum == NULL) ? 0 : 1;
+
+			status =
+				semanage_serialize(handle, &flags, 0, SEMANAGE_SERIAL_UINT32_T, data,
+						size);
+			if (status != STATUS_SUCCESS)
+				goto cleanup;
+
+			/* Write if not null. */
+			if (flags & 1) {
+				/* Size. */
+				status =
+					semanage_serialize(handle, &datum_length, 0,
+							SEMANAGE_SERIAL_SIZE_T, data, size);
+				if (status != STATUS_SUCCESS)
+					goto cleanup;
+
+				/* Datum. */
+				if (size == NULL) {
+					status =
+						snprintf(*data, datum_length + 1, "%s",
+								(char *)datum);
+					if (status < 0 || (unsigned)status > datum_length)
+						goto cleanup;
+					else {
+						*data += status + 1;
+						status = STATUS_SUCCESS;
+					}
+				} else {
+					*size += datum_length + 1;
+				}
+			}
+			break;
+		case SEMANAGE_SERIAL_STRING_ARRAY:
+			/* Flags (intended as a bitmap):
+			 * 0 == NULL
+			 * 1 == Non NULL
+			 */
+			flags = (datum == NULL) ? 0 : 1;
+
+			status =
+				semanage_serialize(handle, &flags, 0, SEMANAGE_SERIAL_UINT32_T, data,
+						size);
+			if (status != STATUS_SUCCESS)
+				goto cleanup;
+
+			/* Write if not null. */
+			if (flags & 1) {
+				/* Size. */
+				status =
+					semanage_serialize(handle, &datum_length, 0,
+							SEMANAGE_SERIAL_UINT32_T, data, size);
+				if (status != STATUS_SUCCESS)
+					goto cleanup;
+
+				/* Datum. */
+				for (i = 0; i < datum_length; i++) {
+					status =
+						semanage_serialize(handle, ((char **)datum)[i],
+								strlen(((char **)datum)[i]),
+								SEMANAGE_SERIAL_STRING, data, size);
+					if (status != STATUS_SUCCESS)
+						goto cleanup;
+				}
+			}
+			break;
+		default:
+			status = STATUS_ERR;
+			goto cleanup;
+	}
+
+	/* Cleanup. */
+	status = STATUS_SUCCESS;
+cleanup:
+	free(temp);
+	return status;
+}
+
+/** Unserializes various kinds of datum as serialized by semanage_serialize.
+ *
+ *  This function acts iteratively moving the *data AND size values.
+ *  size is decremented as data is unserialized.
+ *
+ *  It also allocates memory for datum and, depending on datum_type, datum_length.
+ *  Caller must free.
+ *
+ *  Supported datum_types (defined in serialize.h):
+ *
+ *  SEMANAGE_SERIAL_INT32_T
+ *    Unserializes data into an int32_t as defined in inttypes.h.
+ *    datum_length may be NULL.
+ *  SEMANAGE_SERIAL_UINT32_T
+ *    Unserializes data into an uint32_t as defined in inttypes.h.
+ *    datum_length may be NULL.
+ *  SEMANAGE_SERIAL_SIZE_T
+ *    Unserializes data into an size_t as defined in stddef.h.
+ *    datum_length may be NULL.
+ *  SEMANAGE_SERIAL_STRING
+ *    Unserializes data into a NULL terminated char*.
+ *    datum_length may NOT be NULL and will be the size of the string.
+ *  SEMANAGE_SERIAL_STRING_ARRAY
+ *    Unserializes data into a char**.
+ *    Each entry in the array will be unserialized as per SEMANAGE_SERIAL_STRING.
+ *    datum_length may NOT be NULL and will be the size of the array.
+ */
+int semanage_unserialize(semanage_handle_t * handle,
+		char **data, uint64_t * size,
+		void **datum,
+		size_t ** datum_length,
+		unsigned int datum_type)
+{
+	int status;
+	unsigned int *flags = NULL;
+	uint32_t i;
+	void *temp = NULL;
+	size_t *temp_length = NULL;
+
+	switch (datum_type) {
+		case SEMANAGE_SERIAL_INT32_T:
+		case SEMANAGE_SERIAL_UINT32_T:
+			*datum = calloc(1, sizeof(int32_t));
+			if (*datum == NULL) {
+				status = STATUS_ERR;
+				goto cleanup;
+			}
+
+			memcpy(*datum, *data, sizeof(int32_t));
+			**((int32_t **)datum) = le32_to_cpu(**((int32_t **) datum));
+
+			*size -= sizeof(int32_t);
+			*data += sizeof(int32_t);
+			break;
+		case SEMANAGE_SERIAL_SIZE_T:
+			temp = calloc(1, sizeof(uint64_t));
+			if (temp == NULL) {
+				status = STATUS_ERR;
+				goto cleanup;
+			}
+
+			memcpy(temp, *data, sizeof(uint64_t));
+
+			*((uint64_t *) temp) = le64_to_cpu(*((uint64_t *) temp));
+
+			if (*((uint64_t *) temp) > UINT_MAX) {
+				status = STATUS_ERR;
+				goto cleanup;
+			}
+
+			*datum = calloc(1, sizeof(size_t));
+			if (datum == NULL) {
+				status = STATUS_ERR;
+				goto cleanup;
+			}
+
+			**((size_t **)datum) = *((uint64_t *) temp);
+
+			*size -= sizeof(uint64_t);
+			*data += sizeof(uint64_t);
+			break;
+		case SEMANAGE_SERIAL_STRING:
+			/* Flags (intended as a bitmap):
+			 * 0 == NULL
+			 * 1 == Non NULL
+			 */
+			status =
+				semanage_unserialize(handle,
+						data, size,
+						(void **)(&flags), NULL,
+						SEMANAGE_SERIAL_UINT32_T);
+			if (status != STATUS_SUCCESS)
+				goto cleanup;
+
+			if (*flags & 1) {
+				/* Size. */
+				status =
+					semanage_unserialize(handle,
+							data, size,
+							(void **)datum_length, NULL,
+							SEMANAGE_SERIAL_SIZE_T);
+				if (status != STATUS_SUCCESS)
+					goto cleanup;
+
+				/* Datum. */
+				*datum = calloc(**datum_length + 1, sizeof(char));
+				if (*datum == NULL) {
+					status = STATUS_ERR;
+					goto cleanup;
+				}
+
+				memcpy(*datum, *data, **datum_length + 1);
+
+				*size -= **datum_length + 1;
+				*data += **datum_length + 1;
+			} else {
+				*datum = NULL;
+				*datum_length = NULL;
+			}
+
+			free(flags);
+			flags = NULL;
+			break;
+		case SEMANAGE_SERIAL_STRING_ARRAY:
+			/* Flags (intended as a bitmap):
+			 * 0 == NULL
+			 * 1 == Non NULL
+			 */
+			status =
+				semanage_unserialize(handle,
+						data, size,
+						(void **)(&flags), NULL,
+						SEMANAGE_SERIAL_UINT32_T);
+			if (status != STATUS_SUCCESS)
+				goto cleanup;
+
+			/* Write if not null. */
+			if (*flags & 1) {
+				/* Size. */
+				status =
+					semanage_unserialize(handle,
+							data, size,
+							(void **)datum_length, NULL,
+							SEMANAGE_SERIAL_UINT32_T);
+				if (status != STATUS_SUCCESS)
+					goto cleanup;
+
+				/* Datum. */
+				*datum =
+					calloc(sizeof(char *),
+							sizeof(char *) * (**datum_length));
+				if (*datum == NULL) {
+					status = STATUS_ERR;
+					goto cleanup;
+				}
+
+				for (i = 0; i < **datum_length; i++) {
+					status = semanage_unserialize(handle,
+							data,
+							size,
+							(void **)&(((char **)(*datum))[i]),
+							&temp_length,
+							SEMANAGE_SERIAL_STRING);
+
+					if (status != STATUS_SUCCESS)
+						goto cleanup;
+
+					free(temp_length);
+					temp_length = NULL;
+				}
+			}
+
+			free(flags);
+			flags = NULL;
+			break;
+		default:
+			status = STATUS_ERR;
+			goto cleanup;
+	}
+
+	/* Cleanup. */
+	status = STATUS_SUCCESS;
+cleanup:
+	free(flags);
+	free(temp);
+	free(temp_length);
+	return status;
+}
+

Index: selinux-pms-support/libsemanage/src/serialize.h
===================================================================

libsemanage/src/serialize.h new file +35 -0
@@ -0,0 +1,45 @@
+/* Author: Caleb Case <[email protected]>
+ *
+ * Copyright (C) 2005-2007 Tresys Technology, LLC
+ * Copyright (C) 2005 Red Hat Inc.
+ *
+ *  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_SERIALIZE_INTERNAL_H_
+#define _SEMANAGE_SERIALIZE_INTERNAL_H_
+
+#include <inttypes.h>
+#include "handle.h"
+
+/* Datum types. */
+#define SEMANAGE_SERIAL_INT32_T 0
+#define SEMANAGE_SERIAL_UINT32_T 1
+#define SEMANAGE_SERIAL_SIZE_T 2
+#define SEMANAGE_SERIAL_STRING 3
+#define SEMANAGE_SERIAL_STRING_ARRAY 4
+
+int semanage_serialize(semanage_handle_t * handle,
+		    const void *datum,

libsemanage/src/serialize.h line 45

Quoted 10 lines
libsemanage/src/serialize.h new file +10 -0
+		    size_t datum_size,
+		    unsigned int datum_type, char **data, uint64_t * size);
+
+int semanage_unserialize(semanage_handle_t * handle,
+    char **data, uint64_t * size,
+    void **datum,
+    size_t ** datum_length,
+    unsigned int datum_type);
+
+#endif

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#27 lore raw

RE: [PATCH 12/33] libsemanage: basic serialization

Quoted 12 lines

From: Karl MacMillan [mailto:[email protected]]

Quoted 1 line · On Mon, 2007-04-23 at 17:35 -0400, [email protected] wrote:

plain text document attachment (semanage.serialize.diff)

This is the

Quoted 2 lines

serialization infrastructure for libsemanage.

We have talked about this in the past, but I think the duplication between libsemanage and libsepol should be removed. This is just ridiculous.

We haven't figured out how to remove it. There are lots of objects that are only in semanage (fcontext, seuser, etc) and many that are in sepol (user, boolean, etc). We could do serialization of all sepol types (we are going to do that anyway for the new policy rep) and remove that stuff from libsemanage (I thought that was the plan anyway), for now this is how we did it. Hopefully that'll change. Both libraries are going to have to have serialization/unserialization infrastructure in any case.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#28 lore raw

RE: [PATCH 12/33] libsemanage: basic serialization

Quoted 8 lines · Joshua Brindle
Quoted 8 lines

From: Karl MacMillan [mailto:[email protected]]

Quoted 1 line · On Mon, 2007-04-23 at 17:35 -0400, [email protected] wrote:

plain text document attachment (semanage.serialize.diff)

This is the

Quoted 2 lines

serialization infrastructure for libsemanage.

Quoted 8 lines
Quoted 4 lines

We have talked about this in the past, but I think the duplication between libsemanage and libsepol should be removed. This is just ridiculous.

We haven't figured out how to remove it. There are lots of objects that are only in semanage (fcontext, seuser, etc) and many that are in sepol (user, boolean, etc).

We should move this into libsepol. I actually think that would make the library split clearer.

Quoted 6 lines

We could do serialization of all sepol types (we
are going to do that anyway for the new policy rep) and remove that stuff from libsemanage (I thought that was the plan anyway), for now this is how we did it. Hopefully that'll change. Both libraries are going to have to have serialization/unserialization infrastructure in any case.

Why? Just have a generic way to serialize lists (and perhaps name / value pairs) in libsepol and all of the code falls out of libsemanage.

Karl

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#29 lore raw

PATCH 13/33 libsemanage: testing infrastructure

In reply to [email protected]

Adding a globals.h for tests to hold joint variables for all tests such as a shared semanage handle.

---
 libsemanage/tests/globals.h |   27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
libsemanage/tests/globals.h new file +27 -0
Index: selinux-pms-support/libsemanage/tests/globals.h
===================================================================
@@ -0,0 +1,27 @@
+/* Authors: Caleb Case <[email protected]>
+ *
+ * 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 __GLOBALS_H__
+#define __GLOBALS_H__
+
+#include "handle.h"
+
+semanage_handle_t *sh;
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#30 lore raw

PATCH 14/33 libsemanage: boolean serialization

In reply to [email protected]
---
 libsemanage/include/semanage/booleans_active.h |   28 ++++
 libsemanage/include/semanage/booleans_local.h  |   28 ++++
 libsemanage/include/semanage/booleans_policy.h |    6 +
 libsemanage/src/boolean_internal.h             |   53 +++++++++
 libsemanage/src/boolean_record.c               |   48 ++++++++
 libsemanage/src/booleans_active.c              |   16 ++
 libsemanage/src/booleans_local.c               |   16 ++
 libsemanage/src/booleans_policy.c              |   16 ++
 libsemanage/tests/libsemanage-tests.c          |    4 
 libsemanage/tests/test_boolean_record.c        |  142 +++++++++++++++++++++++++
 libsemanage/tests/test_boolean_record.h        |   32 +++++
 11 files changed, 386 insertions(+), 3 deletions(-)
libsemanage/include/semanage/booleans_active.h +27 -1
Index: selinux-pms-support/libsemanage/include/semanage/booleans_active.h
===================================================================
@@ -1,8 +1,28 @@
-/* Copyright (C) 2005 Red Hat, Inc. */
+/* Authors: Ivan Gyurdiev        <[email protected]>
+ *          Christopher Ashworth <[email protected]>
+ *
+ * Copyright (C) 2005 Red Hat, Inc.
+ * 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_BOOLEANS_ACTIVE_H_
 #define _SEMANAGE_BOOLEANS_ACTIVE_H_
 
+#include <inttypes.h>
 #include <semanage/boolean_record.h>
 #include <semanage/handle.h>
 
@@ -30,4 +50,10 @@ extern int semanage_bool_list_active(sem
 				     semanage_bool_t *** records,
 				     unsigned int *count);
 
+extern int semanage_bool_serialize_active(semanage_handle_t * handle,
+					  char **data, uint64_t * data_length);
+
+extern int semanage_bool_unserialize_active(semanage_handle_t * handle,
+					    char *data, uint64_t data_length);
+
 #endif
libsemanage/include/semanage/booleans_local.h +27 -1
Index: selinux-pms-support/libsemanage/include/semanage/booleans_local.h
===================================================================
@@ -1,8 +1,28 @@
-/* Copyright (C) 2005 Red Hat, Inc. */
+/* Authors: Ivan Gyurdiev        <[email protected]>
+ *          Christopher Ashworth <[email protected]>
+ *
+ * Copyright (C) 2005 Red Hat, Inc.
+ * 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_BOOLEANS_LOCAL_H_
 #define _SEMANAGE_BOOLEANS_LOCAL_H_
 
+#include <inttypes.h>
 #include <semanage/boolean_record.h>
 #include <semanage/handle.h>
 
@@ -33,4 +53,10 @@ extern int semanage_bool_list_local(sema
 				    semanage_bool_t *** records,
 				    unsigned int *count);
 
+extern int semanage_bool_serialize_local(semanage_handle_t * handle,
+					 char **data, uint64_t * data_length);
+
+extern int semanage_bool_unserialize_local(semanage_handle_t * handle,
+					   char *data, uint64_t data_length);
+
 #endif
libsemanage/include/semanage/booleans_policy.h +6 -0
Index: selinux-pms-support/libsemanage/include/semanage/booleans_policy.h
===================================================================
@@ -24,4 +24,10 @@ extern int semanage_bool_iterate(semanag
 extern int semanage_bool_list(semanage_handle_t * handle,
 			      semanage_bool_t *** records, unsigned int *count);
 
+extern int semanage_bool_serialize_policy(semanage_handle_t * handle,
+					  char **data, uint64_t * data_length);
+
+extern int semanage_bool_unserialize_policy(semanage_handle_t * handle,
+					    char *data, uint64_t data_length);
+
 #endif
libsemanage/src/boolean_internal.h +53 -0

74 lines not on this page · raw message

libsemanage/src/boolean_record.c +47 -1

73 lines not on this page · raw message

libsemanage/src/booleans_active.c +16 -0
Index: selinux-pms-support/libsemanage/src/booleans_active.c
===================================================================
@@ -60,3 +60,19 @@ int semanage_bool_list_active(semanage_h
 	dbase_config_t *dconfig = semanage_bool_dbase_active(handle);
 	return dbase_list(handle, dconfig, records, count);
 }
+
+int semanage_bool_serialize_active(semanage_handle_t * handle,
+				   char **data, uint64_t * data_length)
+{
+
+	dbase_config_t *dconfig = semanage_bool_dbase_active(handle);
+	return dbase_serialize(handle, dconfig, data, data_length);
+}
+
+int semanage_bool_unserialize_active(semanage_handle_t * handle,
+				     char *data, uint64_t data_length)
+{
+
+	dbase_config_t *dconfig = semanage_bool_dbase_active(handle);
+	return dbase_unserialize(handle, dconfig, data, data_length);
+}
libsemanage/src/booleans_local.c +16 -0
Index: selinux-pms-support/libsemanage/src/booleans_local.c
===================================================================
@@ -68,3 +68,19 @@ int semanage_bool_list_local(semanage_ha
 	dbase_config_t *dconfig = semanage_bool_dbase_local(handle);
 	return dbase_list(handle, dconfig, records, count);
 }
+
+int semanage_bool_serialize_local(semanage_handle_t * handle,
+				  char **data, uint64_t * data_length)
+{
+
+	dbase_config_t *dconfig = semanage_bool_dbase_local(handle);
+	return dbase_serialize(handle, dconfig, data, data_length);
+}
+
+int semanage_bool_unserialize_local(semanage_handle_t * handle,
+				    char *data, uint64_t data_length)
+{
+
+	dbase_config_t *dconfig = semanage_bool_dbase_local(handle);
+	return dbase_unserialize(handle, dconfig, data, data_length);
+}
libsemanage/src/booleans_policy.c +16 -0
Index: selinux-pms-support/libsemanage/src/booleans_policy.c
===================================================================
@@ -50,3 +50,19 @@ int semanage_bool_list(semanage_handle_t
 	dbase_config_t *dconfig = semanage_bool_dbase_policy(handle);
 	return dbase_list(handle, dconfig, records, count);
 }
+
+int semanage_bool_serialize_policy(semanage_handle_t * handle,
+				   char **data, uint64_t * data_length)
+{
+
+	dbase_config_t *dconfig = semanage_bool_dbase_policy(handle);
+	return dbase_serialize(handle, dconfig, data, data_length);
+}
+
+int semanage_bool_unserialize_policy(semanage_handle_t * handle,
+				     char *data, uint64_t data_length)
+{
+
+	dbase_config_t *dconfig = semanage_bool_dbase_policy(handle);
+	return dbase_unserialize(handle, dconfig, data, data_length);
+}
libsemanage/tests/libsemanage-tests.c +4 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -21,6 +21,8 @@
 
 #include "test_semanage_store.h"
 
+#include "test_boolean_record.h"
+
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
 #include <CUnit/TestDB.h>
@@ -56,6 +58,8 @@ static int do_tests(int interactive, int
 
 	DECLARE_SUITE(semanage_store);
 
+	DECLARE_SUITE(boolean_record);
+
 	if (verbose)
 		CU_basic_set_mode(CU_BRM_VERBOSE);
 	else
libsemanage/tests/test_boolean_record.c new file +142 -0

142 lines not on this page · raw message

libsemanage/tests/test_boolean_record.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_boolean_record.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_BOOLEAN_RECORD_H__
+#define __TEST_BOOLEAN_RECORD_H__
+
+#include <CUnit/Basic.h>
+
+int boolean_record_test_init(void);
+int boolean_record_test_cleanup(void);
+int boolean_record_add_tests(CU_pSuite suite);
+
+void test_semanage_bool_serialize(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#31 lore raw

PATCH 15/33 libsemanage: context serialization

In reply to [email protected]
---
 libsemanage/src/context_internal.h      |   38 +++++++
 libsemanage/src/context_record.c        |   48 +++++++++
 libsemanage/tests/libsemanage-tests.c   |    2 
 libsemanage/tests/test_context_record.c |  154 ++++++++++++++++++++++++++++++++
 libsemanage/tests/test_context_record.h |   32 ++++++
 5 files changed, 272 insertions(+), 2 deletions(-)
libsemanage/src/context_internal.h +38 -0
Index: selinux-pms-support/libsemanage/src/context_internal.h
===================================================================
@@ -1,6 +1,29 @@
+/* Authors: Ivan Gyurdiev        <[email protected]>
+ *          Christopher Ashworth <[email protected]>
+ *          Caleb Case           <[email protected]>
+ *
+ * Copyright (C) 2005 Red Hat, Inc.
+ * 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_CONTEXT_INTERNAL_H_
 #define _SEMANAGE_CONTEXT_INTERNAL_H_
 
+#include <inttypes.h>
 #include <semanage/context_record.h>
 #include "dso.h"
 
@@ -8,4 +31,19 @@ hidden_proto(semanage_context_clone)
     hidden_proto(semanage_context_free)
     hidden_proto(semanage_context_from_string)
     hidden_proto(semanage_context_to_string)
+
+/*======== Internal API:  Serialize/Unserialize ========== */
+hidden int semanage_context_calculate_serialized_size(semanage_handle_t *
+						      handle,
+						      const semanage_context_t *
+						      context, uint64_t * size);
+
+hidden int semanage_context_serialize(semanage_handle_t * handle,
+				      const semanage_context_t * context,
+				      char **data, uint64_t * size);
+
+hidden int semanage_context_unserialize(semanage_handle_t * handle,
+					char **data, uint64_t * size,
+					semanage_context_t ** context);
+
 #endif
libsemanage/src/context_record.c +46 -2

64 lines not on this page · raw message

libsemanage/tests/libsemanage-tests.c +2 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -22,6 +22,7 @@
 #include "test_semanage_store.h"
 
 #include "test_boolean_record.h"
+#include "test_context_record.h"
 
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
@@ -59,6 +60,7 @@ static int do_tests(int interactive, int
 	DECLARE_SUITE(semanage_store);
 
 	DECLARE_SUITE(boolean_record);
+	DECLARE_SUITE(context_record);
 
 	if (verbose)
 		CU_basic_set_mode(CU_BRM_VERBOSE);
libsemanage/tests/test_context_record.c new file +154 -0

154 lines not on this page · raw message

libsemanage/tests/test_context_record.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_context_record.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_CONTEXT_RECORD_H__
+#define __TEST_CONTEXT_RECORD_H__
+
+#include <CUnit/Basic.h>
+
+int context_record_test_init(void);
+int context_record_test_cleanup(void);
+int context_record_add_tests(CU_pSuite suite);
+
+void test_semanage_context_serialize(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#32 lore raw

PATCH 16/33 libsemanage: fcontext serialization

In reply to [email protected]
---
 libsemanage/include/semanage/fcontexts_local.h  |   30 ++++
 libsemanage/include/semanage/fcontexts_policy.h |    8 +
 libsemanage/src/fcontext_internal.h             |   46 ++++++
 libsemanage/src/fcontext_record.c               |  164 +++++++++++++++++++++++
 libsemanage/src/fcontexts_local.c               |   37 +++++
 libsemanage/src/fcontexts_policy.c              |   16 ++
 libsemanage/tests/libsemanage-tests.c           |    2 
 libsemanage/tests/test_fcontext_record.c        |  171 ++++++++++++++++++++++++
 libsemanage/tests/test_fcontext_record.h        |   32 ++++
 9 files changed, 503 insertions(+), 3 deletions(-)
libsemanage/include/semanage/fcontexts_local.h +29 -1
Index: selinux-pms-support/libsemanage/include/semanage/fcontexts_local.h
===================================================================
@@ -1,8 +1,28 @@
-/* Copyright (C) 2005 Red Hat, Inc. */
+/* Authors: Ivan Gyurdiev        <[email protected]>
+ *          Christopher Ashworth <[email protected]>
+ *
+ * Copyright (C) 2005 Red Hat, Inc.
+ * 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_FCONTEXTS_LOCAL_H_
 #define _SEMANAGE_FCONTEXTS_LOCAL_H_
 
+#include <inttypes.h>
 #include <semanage/fcontext_record.h>
 #include <semanage/handle.h>
 
@@ -34,4 +54,12 @@ extern int semanage_fcontext_list_local(
 					semanage_fcontext_t *** records,
 					unsigned int *count);
 
+extern int semanage_fcontext_serialize_local(semanage_handle_t * handle,
+					     char **data,
+					     uint64_t * data_length);
+
+extern int semanage_fcontext_unserialize_local(semanage_handle_t * handle,
+					       char *data,
+					       uint64_t data_length);
+
 #endif
libsemanage/include/semanage/fcontexts_policy.h +8 -0
Index: selinux-pms-support/libsemanage/include/semanage/fcontexts_policy.h
===================================================================
@@ -26,4 +26,12 @@ extern int semanage_fcontext_list(semana
 				  semanage_fcontext_t *** records,
 				  unsigned int *count);
 
+extern int semanage_fcontext_serialize_policy(semanage_handle_t * handle,
+					      char **data,
+					      uint64_t * data_length);
+
+extern int semanage_fcontext_unserialize_policy(semanage_handle_t * handle,
+						char *data,
+						uint64_t data_length);
+
 #endif
libsemanage/src/fcontext_internal.h +45 -1

66 lines not on this page · raw message

libsemanage/src/fcontext_record.c +164 -0

189 lines not on this page · raw message

libsemanage/src/fcontexts_local.c +36 -1
Index: selinux-pms-support/libsemanage/src/fcontexts_local.c
===================================================================
@@ -1,4 +1,23 @@
-/* Copyright (C) 2005 Red Hat, Inc. */
+/* Authors: Ivan Gyurdiev        <[email protected]>
+ *          Christopher Ashworth <[email protected]>
+ *
+ * Copyright (C) 2005 Red Hat, Inc.
+ * 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
+ */
 
 struct semanage_fcontext;
 struct semanage_fcontext_key;
@@ -79,6 +98,22 @@ int semanage_fcontext_list_local(semanag
 	return dbase_list(handle, dconfig, records, count);
 }
 
+int semanage_fcontext_serialize_local(semanage_handle_t * handle,
+				      char **data, uint64_t * data_length)
+{
+
+	dbase_config_t *dconfig = semanage_fcontext_dbase_local(handle);
+	return dbase_serialize(handle, dconfig, data, data_length);
+}
+
+int semanage_fcontext_unserialize_local(semanage_handle_t * handle,
+					char *data, uint64_t data_length)
+{
+
+	dbase_config_t *dconfig = semanage_fcontext_dbase_local(handle);
+	return dbase_unserialize(handle, dconfig, data, data_length);
+}
+
 struct validate_handler_arg {
 	semanage_handle_t *handle;
 	const sepol_policydb_t *policydb;
libsemanage/src/fcontexts_policy.c +16 -0
Index: selinux-pms-support/libsemanage/src/fcontexts_policy.c
===================================================================
@@ -51,3 +51,19 @@ int semanage_fcontext_list(semanage_hand
 	dbase_config_t *dconfig = semanage_fcontext_dbase_policy(handle);
 	return dbase_list(handle, dconfig, records, count);
 }
+
+int semanage_fcontext_serialize_policy(semanage_handle_t * handle,
+				       char **data, uint64_t * data_length)
+{
+
+	dbase_config_t *dconfig = semanage_fcontext_dbase_policy(handle);
+	return dbase_serialize(handle, dconfig, data, data_length);
+}
+
+int semanage_fcontext_unserialize_policy(semanage_handle_t * handle,
+					 char *data, uint64_t data_length)
+{
+
+	dbase_config_t *dconfig = semanage_fcontext_dbase_policy(handle);
+	return dbase_unserialize(handle, dconfig, data, data_length);
+}
libsemanage/tests/libsemanage-tests.c +2 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -23,6 +23,7 @@
 
 #include "test_boolean_record.h"
 #include "test_context_record.h"
+#include "test_fcontext_record.h"
 
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
@@ -61,6 +62,7 @@ static int do_tests(int interactive, int
 
 	DECLARE_SUITE(boolean_record);
 	DECLARE_SUITE(context_record);
+	DECLARE_SUITE(fcontext_record);
 
 	if (verbose)
 		CU_basic_set_mode(CU_BRM_VERBOSE);
libsemanage/tests/test_fcontext_record.c new file +171 -0

171 lines not on this page · raw message

libsemanage/tests/test_fcontext_record.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_fcontext_record.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_FCONTEXT_RECORD_H__
+#define __TEST_FCONTEXT_RECORD_H__
+
+#include <CUnit/Basic.h>
+
+int fcontext_record_test_init(void);
+int fcontext_record_test_cleanup(void);
+int fcontext_record_add_tests(CU_pSuite suite);
+
+void test_semanage_fcontext_serialize(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#33 lore raw

PATCH 17/33 libsemanage: interface serialization

In reply to [email protected]
---
 libsemanage/include/semanage/interfaces_local.h  |   28 +++
 libsemanage/include/semanage/interfaces_policy.h |    6 
 libsemanage/src/iface_internal.h                 |   49 ++++++
 libsemanage/src/iface_record.c                   |   48 ++++++
 libsemanage/src/interfaces_local.c               |   16 ++
 libsemanage/src/interfaces_policy.c              |   16 ++
 libsemanage/tests/libsemanage-tests.c            |    2 
 libsemanage/tests/test_iface_record.c            |  172 +++++++++++++++++++++++
 libsemanage/tests/test_iface_record.h            |   32 ++++
 9 files changed, 367 insertions(+), 2 deletions(-)
libsemanage/include/semanage/interfaces_local.h +27 -1
Index: selinux-pms-support/libsemanage/include/semanage/interfaces_local.h
===================================================================
@@ -1,8 +1,28 @@
-/* Copyright (C) 2005 Red Hat, Inc. */
+/* Authors: Ivan Gyurdiev        <[email protected]>
+ *          Christopher Ashworth <[email protected]>
+ *
+ * Copyright (C) 2005 Red Hat, Inc.
+ * 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_INTERFACES_LOCAL_H_
 #define _SEMANAGE_INTERFACES_LOCAL_H_
 
+#include <inttypes.h>
 #include <semanage/iface_record.h>
 #include <semanage/handle.h>
 
@@ -33,4 +53,10 @@ extern int semanage_iface_list_local(sem
 				     semanage_iface_t *** records,
 				     unsigned int *count);
 
+extern int semanage_iface_serialize_local(semanage_handle_t * handle,
+					  char **data, uint64_t * data_length);
+
+extern int semanage_iface_unserialize_local(semanage_handle_t * handle,
+					    char *data, uint64_t data_length);
+
 #endif
libsemanage/include/semanage/interfaces_policy.h +6 -0
Index: selinux-pms-support/libsemanage/include/semanage/interfaces_policy.h
===================================================================
@@ -26,4 +26,10 @@ extern int semanage_iface_list(semanage_
 			       semanage_iface_t *** records,
 			       unsigned int *count);
 
+extern int semanage_iface_serialize_policy(semanage_handle_t * handle,
+					   char **data, uint64_t * data_length);
+
+extern int semanage_iface_unserialize_policy(semanage_handle_t * handle,
+					     char *data, uint64_t data_length);
+
 #endif
libsemanage/src/iface_internal.h +49 -0

69 lines not on this page · raw message

libsemanage/src/iface_record.c +47 -1

70 lines not on this page · raw message

libsemanage/src/interfaces_local.c +16 -0
Index: selinux-pms-support/libsemanage/src/interfaces_local.c
===================================================================
@@ -69,3 +69,19 @@ int semanage_iface_list_local(semanage_h
 	dbase_config_t *dconfig = semanage_iface_dbase_local(handle);
 	return dbase_list(handle, dconfig, records, count);
 }
+
+int semanage_iface_serialize_local(semanage_handle_t * handle,
+				   char **data, uint64_t * data_length)
+{
+
+	dbase_config_t *dconfig = semanage_iface_dbase_local(handle);
+	return dbase_serialize(handle, dconfig, data, data_length);
+}
+
+int semanage_iface_unserialize_local(semanage_handle_t * handle,
+				     char *data, uint64_t data_length)
+{
+
+	dbase_config_t *dconfig = semanage_iface_dbase_local(handle);
+	return dbase_unserialize(handle, dconfig, data, data_length);
+}
libsemanage/src/interfaces_policy.c +16 -0
Index: selinux-pms-support/libsemanage/src/interfaces_policy.c
===================================================================
@@ -50,3 +50,19 @@ int semanage_iface_list(semanage_handle_
 	dbase_config_t *dconfig = semanage_iface_dbase_policy(handle);
 	return dbase_list(handle, dconfig, records, count);
 }
+
+int semanage_iface_serialize_policy(semanage_handle_t * handle,
+				    char **data, uint64_t * data_length)
+{
+
+	dbase_config_t *dconfig = semanage_iface_dbase_policy(handle);
+	return dbase_serialize(handle, dconfig, data, data_length);
+}
+
+int semanage_iface_unserialize_policy(semanage_handle_t * handle,
+				      char *data, uint64_t data_length)
+{
+
+	dbase_config_t *dconfig = semanage_iface_dbase_policy(handle);
+	return dbase_unserialize(handle, dconfig, data, data_length);
+}
libsemanage/tests/libsemanage-tests.c +2 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -24,6 +24,7 @@
 #include "test_boolean_record.h"
 #include "test_context_record.h"
 #include "test_fcontext_record.h"
+#include "test_iface_record.h"
 
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
@@ -63,6 +64,7 @@ static int do_tests(int interactive, int
 	DECLARE_SUITE(boolean_record);
 	DECLARE_SUITE(context_record);
 	DECLARE_SUITE(fcontext_record);
+	DECLARE_SUITE(iface_record);
 
 	if (verbose)
 		CU_basic_set_mode(CU_BRM_VERBOSE);
libsemanage/tests/test_iface_record.c new file +172 -0

172 lines not on this page · raw message

libsemanage/tests/test_iface_record.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_iface_record.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_IFACE_RECORD_H__
+#define __TEST_IFACE_RECORD_H__
+
+#include <CUnit/Basic.h>
+
+int iface_record_test_init(void);
+int iface_record_test_cleanup(void);
+int iface_record_add_tests(CU_pSuite suite);
+
+void test_semanage_iface_serialize(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#34 lore raw

PATCH 18/33 libsemanage: node serialization

In reply to [email protected]
---
 libsemanage/include/semanage/nodes_local.h  |   28 ++++
 libsemanage/include/semanage/nodes_policy.h |    6 
 libsemanage/src/node_internal.h             |   49 +++++++
 libsemanage/src/node_record.c               |   48 +++++++
 libsemanage/src/nodes_local.c               |   16 ++
 libsemanage/src/nodes_policy.c              |   16 ++
 libsemanage/tests/libsemanage-tests.c       |    2 
 libsemanage/tests/test_node_record.c        |  173 ++++++++++++++++++++++++++++
 libsemanage/tests/test_node_record.h        |   32 +++++
 9 files changed, 368 insertions(+), 2 deletions(-)
libsemanage/include/semanage/nodes_local.h +27 -1
Index: selinux-pms-support/libsemanage/include/semanage/nodes_local.h
===================================================================
@@ -1,8 +1,28 @@
-/* Copyright (C) 2005 Red Hat, Inc. */
+/* Authors: Ivan Gyurdiev        <[email protected]>
+ *          Christopher Ashworth <[email protected]>
+ *
+ * Copyright (C) 2005 Red Hat, Inc.
+ * 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_NODES_LOCAL_H_
 #define _SEMANAGE_NODES_LOCAL_H_
 
+#include <inttypes.h>
 #include <semanage/node_record.h>
 #include <semanage/handle.h>
 
@@ -33,4 +53,10 @@ extern int semanage_node_list_local(sema
 				    semanage_node_t *** records,
 				    unsigned int *count);
 
+extern int semanage_node_serialize_local(semanage_handle_t * handle,
+					 char **data, uint64_t * data_length);
+
+extern int semanage_node_unserialize_local(semanage_handle_t * handle,
+					   char *data, uint64_t data_length);
+
 #endif
libsemanage/include/semanage/nodes_policy.h +6 -0
Index: selinux-pms-support/libsemanage/include/semanage/nodes_policy.h
===================================================================
@@ -24,4 +24,10 @@ extern int semanage_node_iterate(semanag
 extern int semanage_node_list(semanage_handle_t * handle,
 			      semanage_node_t *** records, unsigned int *count);
 
+extern int semanage_node_serialize_policy(semanage_handle_t * handle,
+					  char **data, uint64_t * data_length);
+
+extern int semanage_node_unserialize_policy(semanage_handle_t * handle,
+					    char *data, uint64_t data_length);
+
 #endif
libsemanage/src/node_internal.h +49 -0

75 lines not on this page · raw message

libsemanage/src/node_record.c +47 -1

73 lines not on this page · raw message

libsemanage/src/nodes_local.c +16 -0
Index: selinux-pms-support/libsemanage/src/nodes_local.c
===================================================================
@@ -70,3 +70,19 @@ int semanage_node_list_local(semanage_ha
 }
 
 hidden_def(semanage_node_list_local)
+
+int semanage_node_serialize_local(semanage_handle_t * handle,
+				  char **data, uint64_t * data_length)
+{
+
+	dbase_config_t *dconfig = semanage_node_dbase_local(handle);
+	return dbase_serialize(handle, dconfig, data, data_length);
+}
+
+int semanage_node_unserialize_local(semanage_handle_t * handle,
+				    char *data, uint64_t data_length)
+{
+
+	dbase_config_t *dconfig = semanage_node_dbase_local(handle);
+	return dbase_unserialize(handle, dconfig, data, data_length);
+}
libsemanage/src/nodes_policy.c +16 -0
Index: selinux-pms-support/libsemanage/src/nodes_policy.c
===================================================================
@@ -50,3 +50,19 @@ int semanage_node_list(semanage_handle_t
 	dbase_config_t *dconfig = semanage_node_dbase_policy(handle);
 	return dbase_list(handle, dconfig, records, count);
 }
+
+int semanage_node_serialize_policy(semanage_handle_t * handle,
+				   char **data, uint64_t * data_length)
+{
+
+	dbase_config_t *dconfig = semanage_node_dbase_policy(handle);
+	return dbase_serialize(handle, dconfig, data, data_length);
+}
+
+int semanage_node_unserialize_policy(semanage_handle_t * handle,
+				     char *data, uint64_t data_length)
+{
+
+	dbase_config_t *dconfig = semanage_node_dbase_policy(handle);
+	return dbase_unserialize(handle, dconfig, data, data_length);
+}
libsemanage/tests/libsemanage-tests.c +2 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -25,6 +25,7 @@
 #include "test_context_record.h"
 #include "test_fcontext_record.h"
 #include "test_iface_record.h"
+#include "test_node_record.h"
 
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
@@ -65,6 +66,7 @@ static int do_tests(int interactive, int
 	DECLARE_SUITE(context_record);
 	DECLARE_SUITE(fcontext_record);
 	DECLARE_SUITE(iface_record);
+	DECLARE_SUITE(node_record);
 
 	if (verbose)
 		CU_basic_set_mode(CU_BRM_VERBOSE);
libsemanage/tests/test_node_record.c new file +173 -0

173 lines not on this page · raw message

libsemanage/tests/test_node_record.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_node_record.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_NODE_RECORD_H__
+#define __TEST_NODE_RECORD_H__
+
+#include <CUnit/Basic.h>
+
+int node_record_test_init(void);
+int node_record_test_cleanup(void);
+int node_record_add_tests(CU_pSuite suite);
+
+void test_semanage_node_serialize(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#35 lore raw

PATCH 19/33 libsemanage: port serialization

In reply to [email protected]
---
 libsemanage/include/semanage/ports_local.h  |   28 ++++
 libsemanage/include/semanage/ports_policy.h |    6 +
 libsemanage/src/port_internal.h             |   49 ++++++++
 libsemanage/src/port_record.c               |   48 ++++++++
 libsemanage/src/ports_local.c               |   16 ++
 libsemanage/src/ports_policy.c              |   16 ++
 libsemanage/tests/libsemanage-tests.c       |    2 
 libsemanage/tests/test_port_record.c        |  162 ++++++++++++++++++++++++++++
 libsemanage/tests/test_port_record.h        |   32 +++++
 9 files changed, 357 insertions(+), 2 deletions(-)
libsemanage/include/semanage/ports_local.h +27 -1
Index: selinux-pms-support/libsemanage/include/semanage/ports_local.h
===================================================================
@@ -1,8 +1,28 @@
-/* Copyright (C) 2005 Red Hat, Inc. */
+/* Authors: Ivan Gyurdiev        <[email protected]>
+ *          Christopher Ashworth <[email protected]>
+ *
+ * Copyright (C) 2005 Red Hat, Inc.
+ * 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_PORTS_LOCAL_H_
 #define _SEMANAGE_PORTS_LOCAL_H_
 
+#include <inttypes.h>
 #include <semanage/port_record.h>
 #include <semanage/handle.h>
 
@@ -33,4 +53,10 @@ extern int semanage_port_list_local(sema
 				    semanage_port_t *** records,
 				    unsigned int *count);
 
+extern int semanage_port_serialize_local(semanage_handle_t * handle,
+					 char **data, uint64_t * data_length);
+
+extern int semanage_port_unserialize_local(semanage_handle_t * handle,
+					   char *data, uint64_t data_length);
+
 #endif
libsemanage/include/semanage/ports_policy.h +6 -0
Index: selinux-pms-support/libsemanage/include/semanage/ports_policy.h
===================================================================
@@ -24,4 +24,10 @@ extern int semanage_port_iterate(semanag
 extern int semanage_port_list(semanage_handle_t * handle,
 			      semanage_port_t *** records, unsigned int *count);
 
+extern int semanage_port_serialize_policy(semanage_handle_t * handle,
+					  char **data, uint64_t * data_length);
+
+extern int semanage_port_unserialize_policy(semanage_handle_t * handle,
+					    char *data, uint64_t data_length);
+
 #endif
libsemanage/src/port_internal.h +49 -0

74 lines not on this page · raw message

libsemanage/src/port_record.c +47 -1

73 lines not on this page · raw message

libsemanage/src/ports_local.c +16 -0
Index: selinux-pms-support/libsemanage/src/ports_local.c
===================================================================
@@ -142,3 +142,19 @@ int hidden semanage_port_validate_local(
 	free(ports);
 	return STATUS_ERR;
 }
+
+int semanage_port_serialize_local(semanage_handle_t * handle,
+				  char **data, uint64_t * data_length)
+{
+
+	dbase_config_t *dconfig = semanage_port_dbase_local(handle);
+	return dbase_serialize(handle, dconfig, data, data_length);
+}
+
+int semanage_port_unserialize_local(semanage_handle_t * handle,
+				    char *data, uint64_t data_length)
+{
+
+	dbase_config_t *dconfig = semanage_port_dbase_local(handle);
+	return dbase_unserialize(handle, dconfig, data, data_length);
+}
libsemanage/src/ports_policy.c +16 -0
Index: selinux-pms-support/libsemanage/src/ports_policy.c
===================================================================
@@ -50,3 +50,19 @@ int semanage_port_list(semanage_handle_t
 	dbase_config_t *dconfig = semanage_port_dbase_policy(handle);
 	return dbase_list(handle, dconfig, records, count);
 }
+
+int semanage_port_serialize_policy(semanage_handle_t * handle,
+				   char **data, uint64_t * data_length)
+{
+
+	dbase_config_t *dconfig = semanage_port_dbase_policy(handle);
+	return dbase_serialize(handle, dconfig, data, data_length);
+}
+
+int semanage_port_unserialize_policy(semanage_handle_t * handle,
+				     char *data, uint64_t data_length)
+{
+
+	dbase_config_t *dconfig = semanage_port_dbase_policy(handle);
+	return dbase_unserialize(handle, dconfig, data, data_length);
+}
libsemanage/tests/libsemanage-tests.c +2 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -26,6 +26,7 @@
 #include "test_fcontext_record.h"
 #include "test_iface_record.h"
 #include "test_node_record.h"
+#include "test_port_record.h"
 
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
@@ -67,6 +68,7 @@ static int do_tests(int interactive, int
 	DECLARE_SUITE(fcontext_record);
 	DECLARE_SUITE(iface_record);
 	DECLARE_SUITE(node_record);
+	DECLARE_SUITE(port_record);
 
 	if (verbose)
 		CU_basic_set_mode(CU_BRM_VERBOSE);
libsemanage/tests/test_port_record.c new file +162 -0

162 lines not on this page · raw message

libsemanage/tests/test_port_record.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_port_record.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_PORT_RECORD_H__
+#define __TEST_PORT_RECORD_H__
+
+#include <CUnit/Basic.h>
+
+int port_record_test_init(void);
+int port_record_test_cleanup(void);
+int port_record_add_tests(CU_pSuite suite);
+
+void test_semanage_port_serialize(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#36 lore raw

PATCH 20/33 libsemanage: seuser serialization

In reply to [email protected]
---
 libsemanage/include/semanage/seusers_local.h  |   28 ++++
 libsemanage/include/semanage/seusers_policy.h |    7 +
 libsemanage/src/seuser_internal.h             |   40 ++++++
 libsemanage/src/seuser_record.c               |  149 +++++++++++++++++++++++++-
 libsemanage/src/seusers_local.c               |   16 ++
 libsemanage/src/seusers_policy.c              |   16 ++
 libsemanage/tests/libsemanage-tests.c         |    2 
 libsemanage/tests/test_seuser_record.c        |  143 ++++++++++++++++++++++++
 libsemanage/tests/test_seuser_record.h        |   32 +++++
 9 files changed, 429 insertions(+), 4 deletions(-)
libsemanage/include/semanage/seusers_local.h +27 -1
Index: selinux-pms-support/libsemanage/include/semanage/seusers_local.h
===================================================================
@@ -1,8 +1,28 @@
-/* Copyright (C) 2005 Red Hat, Inc. */
+/* Authors: Ivan Gyurdiev        <[email protected]>
+ *          Christopher Ashworth <[email protected]>
+ *
+ * Copyright (C) 2005 Red Hat, Inc.
+ * 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_SEUSERS_LOCAL_H_
 #define _SEMANAGE_SEUSERS_LOCAL_H_
 
+#include <inttypes.h>
 #include <semanage/seuser_record.h>
 #include <semanage/handle.h>
 
@@ -33,4 +53,10 @@ extern int semanage_seuser_list_local(se
 				      semanage_seuser_t *** records,
 				      unsigned int *count);
 
+extern int semanage_seuser_serialize_local(semanage_handle_t * handle,
+					   char **data, uint64_t * data_length);
+
+extern int semanage_seuser_unserialize_local(semanage_handle_t * handle,
+					     char *data, uint64_t data_length);
+
 #endif
libsemanage/include/semanage/seusers_policy.h +7 -0
Index: selinux-pms-support/libsemanage/include/semanage/seusers_policy.h
===================================================================
@@ -26,4 +26,11 @@ extern int semanage_seuser_list(semanage
 				semanage_seuser_t *** records,
 				unsigned int *count);
 
+extern int semanage_seuser_serialize_policy(semanage_handle_t * handle,
+					    char **data,
+					    uint64_t * data_length);
+
+extern int semanage_seuser_unserialize_policy(semanage_handle_t * handle,
+					      char *data, uint64_t data_length);
+
 #endif
libsemanage/src/seuser_internal.h +40 -0
Index: selinux-pms-support/libsemanage/src/seuser_internal.h
===================================================================
@@ -1,3 +1,25 @@
+/* Authors: Ivan Gyurdiev        <[email protected]>
+ *          Christopher Ashworth <[email protected]>
+ *          Caleb Case           <[email protected]>
+ *
+ * Copyright (C) 2005 Red Hat, Inc.
+ * 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_SEUSER_INTERNAL_H_
 #define _SEMANAGE_SEUSER_INTERNAL_H_
 
@@ -34,8 +56,26 @@ extern int seuser_file_dbase_init(semana
 
 extern void seuser_file_dbase_release(dbase_config_t * dconfig);
 
+extern int seuser_ps_local_dbase_init(semanage_handle_t * handle,
+				uint32_t sandbox_id, dbase_config_t * dconfig);
+
+extern void seuser_ps_local_dbase_release(dbase_config_t * dconfig);
+
 extern int hidden semanage_seuser_validate_local(semanage_handle_t * handle,
 						 const sepol_policydb_t *
 						 policydb);
 
+/*======== Internal API:  Serialize/Unserialize ========== */
+hidden int semanage_seuser_calculate_serialized_size(semanage_handle_t * handle,
+						     const semanage_seuser_t *
+						     seuser, uint64_t * size);
+
+hidden int semanage_seuser_serialize(semanage_handle_t * handle,
+				     const semanage_seuser_t * seuser,
+				     char **data, uint64_t * size);
+
+hidden int semanage_seuser_unserialize(semanage_handle_t * handle,
+				       char **data, uint64_t * size,
+				       semanage_seuser_t ** seuser);
+
 #endif
libsemanage/src/seuser_record.c +146 -3

172 lines not on this page · raw message

libsemanage/src/seusers_local.c +16 -0
Index: selinux-pms-support/libsemanage/src/seusers_local.c
===================================================================
@@ -173,3 +173,19 @@ int hidden semanage_seuser_validate_loca
 	arg.policydb = policydb;
 	return semanage_seuser_iterate_local(handle, validate_handler, &arg);
 }
+
+int semanage_seuser_serialize_local(semanage_handle_t * handle,
+				    char **data, uint64_t * data_length)
+{
+
+	dbase_config_t *dconfig = semanage_seuser_dbase_local(handle);
+	return dbase_serialize(handle, dconfig, data, data_length);
+}
+
+int semanage_seuser_unserialize_local(semanage_handle_t * handle,
+				      char *data, uint64_t data_length)
+{
+
+	dbase_config_t *dconfig = semanage_seuser_dbase_local(handle);
+	return dbase_unserialize(handle, dconfig, data, data_length);
+}
libsemanage/src/seusers_policy.c +16 -0
Index: selinux-pms-support/libsemanage/src/seusers_policy.c
===================================================================
@@ -56,3 +56,19 @@ int semanage_seuser_list(semanage_handle
 	dbase_config_t *dconfig = semanage_seuser_dbase_policy(handle);
 	return dbase_list(handle, dconfig, records, count);
 }
+
+int semanage_seuser_serialize_policy(semanage_handle_t * handle,
+				     char **data, uint64_t * data_length)
+{
+
+	dbase_config_t *dconfig = semanage_seuser_dbase_policy(handle);
+	return dbase_serialize(handle, dconfig, data, data_length);
+}
+
+int semanage_seuser_unserialize_policy(semanage_handle_t * handle,
+				       char *data, uint64_t data_length)
+{
+
+	dbase_config_t *dconfig = semanage_seuser_dbase_policy(handle);
+	return dbase_unserialize(handle, dconfig, data, data_length);
+}
libsemanage/tests/libsemanage-tests.c +2 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -27,6 +27,7 @@
 #include "test_iface_record.h"
 #include "test_node_record.h"
 #include "test_port_record.h"
+#include "test_seuser_record.h"
 
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
@@ -69,6 +70,7 @@ static int do_tests(int interactive, int
 	DECLARE_SUITE(iface_record);
 	DECLARE_SUITE(node_record);
 	DECLARE_SUITE(port_record);
+	DECLARE_SUITE(seuser_record);
 
 	if (verbose)
 		CU_basic_set_mode(CU_BRM_VERBOSE);
libsemanage/tests/test_seuser_record.c new file +143 -0

143 lines not on this page · raw message

libsemanage/tests/test_seuser_record.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_seuser_record.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_SEUSER_RECORD_H__
+#define __TEST_SEUSER_RECORD_H__
+
+#include <CUnit/Basic.h>
+
+int seuser_record_test_init(void);
+int seuser_record_test_cleanup(void);
+int seuser_record_add_tests(CU_pSuite suite);
+
+void test_semanage_seuser_serialize(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#37 lore raw

PATCH 21/33 libsemanage: user serialization

In reply to [email protected]
---
 libsemanage/include/semanage/users_local.h  |   28 ++++-
 libsemanage/include/semanage/users_policy.h |    6 +
 libsemanage/src/user_base_record.c          |   46 ++++++++
 libsemanage/src/user_extra_record.c         |  127 +++++++++++++++++++++++
 libsemanage/src/user_internal.h             |  105 +++++++++++++++++++
 libsemanage/src/user_record.c               |  120 +++++++++++++++++++++
 libsemanage/src/users_local.c               |   16 ++
 libsemanage/src/users_policy.c              |   16 ++
 libsemanage/tests/libsemanage-tests.c       |    2 
 libsemanage/tests/test_user_record.c        |  153 ++++++++++++++++++++++++++++
 libsemanage/tests/test_user_record.h        |   32 +++++
 11 files changed, 647 insertions(+), 4 deletions(-)
libsemanage/include/semanage/users_local.h +27 -1
Index: selinux-pms-support/libsemanage/include/semanage/users_local.h
===================================================================
@@ -1,8 +1,28 @@
-/* Copyright (C) 2005 Red Hat, Inc. */
+/* Authors: Ivan Gyurdiev        <[email protected]>
+ *          Christopher Ashworth <[email protected]>
+ *
+ * Copyright (C) 2005 Red Hat, Inc.
+ * 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_USERS_LOCAL_H_
 #define _SEMANAGE_USERS_LOCAL_H_
 
+#include <inttypes.h>
 #include <semanage/user_record.h>
 #include <semanage/handle.h>
 
@@ -33,4 +53,10 @@ extern int semanage_user_list_local(sema
 				    semanage_user_t *** records,
 				    unsigned int *count);
 
+extern int semanage_user_serialize_local(semanage_handle_t * handle,
+					 char **data, uint64_t * data_length);
+
+extern int semanage_user_unserialize_local(semanage_handle_t * handle,
+					   char *data, uint64_t data_length);
+
 #endif
libsemanage/include/semanage/users_policy.h +6 -0
Index: selinux-pms-support/libsemanage/include/semanage/users_policy.h
===================================================================
@@ -24,4 +24,10 @@ extern int semanage_user_iterate(semanag
 extern int semanage_user_list(semanage_handle_t * handle,
 			      semanage_user_t *** records, unsigned int *count);
 
+extern int semanage_user_serialize_policy(semanage_handle_t * handle,
+					  char **data, uint64_t * data_length);
+
+extern int semanage_user_unserialize_policy(semanage_handle_t * handle,
+					    char *data, uint64_t data_length);
+
 #endif
libsemanage/src/user_base_record.c +45 -1

59 lines not on this page · raw message

libsemanage/src/user_extra_record.c +126 -1

152 lines not on this page · raw message

libsemanage/src/user_internal.h +105 -0

165 lines not on this page · raw message

libsemanage/src/user_record.c +119 -1

145 lines not on this page · raw message

libsemanage/src/users_local.c +16 -0
Index: selinux-pms-support/libsemanage/src/users_local.c
===================================================================
@@ -68,3 +68,19 @@ int semanage_user_list_local(semanage_ha
 	dbase_config_t *dconfig = semanage_user_dbase_local(handle);
 	return dbase_list(handle, dconfig, records, count);
 }
+
+int semanage_user_serialize_local(semanage_handle_t * handle,
+				  char **data, uint64_t * data_length)
+{
+
+	dbase_config_t *dconfig = semanage_user_dbase_local(handle);
+	return dbase_serialize(handle, dconfig, data, data_length);
+}
+
+int semanage_user_unserialize_local(semanage_handle_t * handle,
+				    char *data, uint64_t data_length)
+{
+
+	dbase_config_t *dconfig = semanage_user_dbase_local(handle);
+	return dbase_unserialize(handle, dconfig, data, data_length);
+}
libsemanage/src/users_policy.c +16 -0
Index: selinux-pms-support/libsemanage/src/users_policy.c
===================================================================
@@ -54,3 +54,19 @@ int semanage_user_list(semanage_handle_t
 	dbase_config_t *dconfig = semanage_user_dbase_policy(handle);
 	return dbase_list(handle, dconfig, records, count);
 }
+
+int semanage_user_serialize_policy(semanage_handle_t * handle,
+				   char **data, uint64_t * data_length)
+{
+
+	dbase_config_t *dconfig = semanage_user_dbase_policy(handle);
+	return dbase_serialize(handle, dconfig, data, data_length);
+}
+
+int semanage_user_unserialize_policy(semanage_handle_t * handle,
+				     char *data, uint64_t data_length)
+{
+
+	dbase_config_t *dconfig = semanage_user_dbase_policy(handle);
+	return dbase_unserialize(handle, dconfig, data, data_length);
+}
libsemanage/tests/libsemanage-tests.c +2 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -28,6 +28,7 @@
 #include "test_node_record.h"
 #include "test_port_record.h"
 #include "test_seuser_record.h"
+#include "test_user_record.h"
 
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
@@ -71,6 +72,7 @@ static int do_tests(int interactive, int
 	DECLARE_SUITE(node_record);
 	DECLARE_SUITE(port_record);
 	DECLARE_SUITE(seuser_record);
+	DECLARE_SUITE(user_record);
 
 	if (verbose)
 		CU_basic_set_mode(CU_BRM_VERBOSE);
libsemanage/tests/test_user_record.c new file +153 -0

153 lines not on this page · raw message

libsemanage/tests/test_user_record.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_user_record.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_USER_RECORD_H__
+#define __TEST_USER_RECORD_H__
+
+#include <CUnit/Basic.h>
+
+int user_record_test_init(void);
+int user_record_test_cleanup(void);
+int user_record_add_tests(CU_pSuite suite);
+
+void test_semanage_user_serialize(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#38 lore raw

PATCH 22/33 libsemanage: module serialization

In reply to [email protected]
---
 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(-)
libsemanage/include/semanage/modules.h +11 -0
Index: 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
libsemanage/src/libsemanage.map +1 -0
Index: 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_*;
libsemanage/src/module_internal.h +3 -0
Index: 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
libsemanage/src/modules.c +140 -8

178 lines not on this page · raw message

Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#39 lore raw

PATCH 23/33 libsemanage: commit number serialization

In reply to [email protected]

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(+)
libsemanage/include/semanage/policy.h new file +31 -0
Index: selinux-pms-support/libsemanage/include/semanage/policy.h
===================================================================
@@ -0,0 +1,31 @@
+/* Authors: Caleb Case <[email protected]>
+ *
+ * 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
libsemanage/src/libsemanage.map +1 -0
Index: 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: *;
 };
libsemanage/src/policy.c new file +91 -0

91 lines not on this page · raw message

libsemanage/src/policy.h +4 -0
Index: 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
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#40 lore raw

PATCH 24/33 libsemanage: networking support

In reply to [email protected]

Sending/receiving utilities in messages.[ch]. Additional exported defines to support message processing.

---
 libsemanage/include/semanage/messages.h |  126 +++++++++++
 libsemanage/include/semanage/semanage.h |    3 
 libsemanage/src/messages.c              |  355 ++++++++++++++++++++++++++++++++
 libsemanage/src/messages_internal.h     |   39 +++
 4 files changed, 523 insertions(+)
libsemanage/include/semanage/messages.h new file +126 -0
Index: selinux-pms-support/libsemanage/include/semanage/messages.h
===================================================================
@@ -0,0 +1,126 @@
+/* Author:  Caleb Case                  <[email protected]>
+ *          Christopher Ashworth        <[email protected]>
+ *
+ * Copyright (C) 2004-2007 Tresys Technology, LLC
+ * Copyright (C) 2005 Red Hat, Inc.
+ *
+ *  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_MESSAGES_H_
+#define _SEMANAGE_MESSAGES_H_
+
+#ifndef SEMANAGE_PS_DEFAULT_TIMEOUT
+#define SEMANAGE_PS_DEFAULT_TIMEOUT 160
+#endif
+
+/* Message types in the client/server protocol.
+ */
+enum message_types {
+	PS_OK = 1,		/* policy server response */
+	PS_ERR,			/* policy server response */
+	PS_BUSY,		/* policy server response */
+	PS_INFO,		/* policy server response */
+	PS_CONNECT = 100,
+	PS_DISCONNECT,
+	PS_BEGIN_TRANSACTION,
+	PS_COMMIT,
+	PS_GET_COMMIT_NUMBER,
+	PS_INSTALL_MODULE,
+	PS_UPGRADE_MODULE,
+	PS_BASE_MODULE,
+	PS_REMOVE_MODULE,
+	PS_LIST_MODULES,
+	PS_GET_DATABASE,
+	PS_PUT_DATABASE
+};
+
+/* Database types in the client/server protocol.
+ */
+enum database_types {
+	DB_BOOLEAN_ACTIVE,
+	DB_BOOLEAN_LOCAL,
+	DB_BOOLEAN_POLICY,
+	DB_FCONTEXT_LOCAL,
+	DB_FCONTEXT_POLICY,
+	DB_INTERFACE_LOCAL,
+	DB_INTERFACE_POLICY,
+	DB_NODE_LOCAL,
+	DB_NODE_POLICY,
+	DB_PORT_LOCAL,
+	DB_PORT_POLICY,
+	DB_SEUSER_LOCAL,
+	DB_SEUSER_POLICY,
+	DB_USER_LOCAL,
+	DB_USER_POLICY,
+};
+
+/* Info and error message types and strings.
+ */
+#define PS_ERROR_MESSAGE_MAX_LENGTH 256
+
+#define PS_INFO_SERVER_CLOSING_NUM 100
+#define PS_INFO_SERVER_CLOSING_STR "Server is being shut down."
+#define PS_INFO_CHANGED_NUM 102
+#define PS_INFO_CHANGED_STR "Policy has been changed since session began."
+
+#define PS_BUSY_COMMIT_NUM 300
+#define PS_BUSY_COMMIT_STR "Another client is currently committing changes."
+#define PS_BUSY_WRITE_NUM 301
+#define PS_BUSY_WRITE_STR "Another client is currently writing."
+
+#define PS_ERROR_COULD_NOT_PARSE_NUM 400
+#define PS_ERROR_COULD_NOT_PARSE_STR "Could not parse request."
+#define PS_ERROR_NOTHING_TO_COMMIT_NUM 401
+#define PS_ERROR_NOTHING_TO_COMMIT_STR "There was nothing to commit."
+#define PS_ERROR_COULD_NOT_UPGRADE_NUM 402
+#define PS_ERROR_COULD_NOT_UPGRADE_STR "Module to be upgraded does not exist or is earlier than existing version."
+#define PS_ERROR_FORBIDDEN_NUM 403
+#define PS_ERROR_FORBIDDEN_STR "Could not access requested file or directory."
+#define PS_ERROR_NO_BASE_MODULE_NUM 404
+#define PS_ERROR_NO_BASE_MODULE_STR "Cannot execute command because no base module was found."
+#define PS_ERROR_METAVERIFY_FAILED_NUM 405
+#define PS_ERROR_METAVERIFY_FAILED_STR "The metapolicy did not accept a component."
+#define PS_ERROR_VERIFY_FAILED_NUM 406
+#define PS_ERROR_VERIFY_FAILED_STR "A verifier did not accept the new policy."
+#define PS_ERROR_COULD_NOT_EXPAND_NUM 409
+#define PS_ERROR_COULD_NOT_EXPAND_STR "Error while expanding policy."
+#define PS_ERROR_COULD_NOT_LINK_NUM 412
+#define PS_ERROR_COULD_NOT_LINK_STR "Error while linking modules."
+#define PS_ERROR_DATA_NOT_A_MODULE_NUM 415
+#define PS_ERROR_DATA_NOT_A_MODULE_STR "The supplied file was not a valid policy module."
+#define PS_ERROR_DATA_NOT_A_BASE_NUM 416
+#define PS_ERROR_DATA_NOT_A_BASE_STR "The supplied file was not a valid base policy module."
+#define PS_ERROR_COULD_NOT_LOAD_NUM 417
+#define PS_ERROR_COULD_NOT_LOAD_STR "Error while loading new policy."
+#define PS_ERROR_COULD_NOT_REMOVE_NUM 418
+#define PS_ERROR_COULD_NOT_REMOVE_STR "Error while removing policy."
+
+#define PS_ERROR_NOT_IMPLEMENTED_NUM 501
+#define PS_ERROR_NOT_IMPLEMENTED_STR "Function not implemented."
+#define PS_ERROR_BUSY_NUM 503
+#define PS_ERROR_BUSY_STR "Too many clients connected to server."
+#define PS_ERROR_UNSUPPORTED_VERSION_NUM 505
+#define PS_ERROR_UNSUPPORTED_VERSION_STR "That protocol version is not supported."
+#define PS_ERROR_MESSAGE_INVALID_NUM 506
+#define PS_ERROR_MESSAGE_INVALID_STR "The message was invalid."
+#define PS_ERROR_MESSAGE_TOO_BIG_NUM 507
+#define PS_ERROR_MESSAGE_TOO_BIG_STR "The message was longer than the supported maximum length."
+#define PS_ERROR_NO_SUCH_DATABASE_NUM 508
+#define PS_ERROR_NO_SUCH_DATABASE_STR "Database requested does not exist."
+
+
+#endif
libsemanage/include/semanage/semanage.h +3 -0
Index: selinux-pms-support/libsemanage/include/semanage/semanage.h
===================================================================
@@ -52,4 +52,7 @@
 #include <semanage/nodes_local.h>
 #include <semanage/nodes_policy.h>
 
+/* Messaging */
+#include <semanage/messages.h>
+
 #endif
libsemanage/src/messages.c new file +355 -0

355 lines not on this page · raw message

libsemanage/src/messages_internal.h new file +39 -0
Index: selinux-pms-support/libsemanage/src/messages_internal.h
===================================================================
@@ -0,0 +1,39 @@
+/* Author:  Caleb Case                  <[email protected]>
+ *          Christopher Ashworth        <[email protected]>
+ *
+ * Copyright (C) 2004-2007 Tresys Technology, LLC
+ * Copyright (C) 2005 Red Hat, Inc.
+ *
+ *  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_MESSAGES_INTERNAL_H_
+#define _SEMANAGE_MESSAGES_INTERNAL_H_
+
+#include <sys/types.h>
+
+#include <semanage/messages.h>
+
+int read_n(semanage_handle_t *sh, int socket_fd, int timeout, char *buf, size_t n);
+int flush_n(semanage_handle_t *sh, int socket_fd, int timeout, uint64_t n);
+int read_msg(semanage_handle_t *sh, int socket_fd, int timeout, uint32_t * message_type,
+	     uint64_t * data_length, char **data);
+int write_msg(semanage_handle_t *sh, int socket_fd, uint32_t message_type,
+	      uint64_t data_length, char *data);
+int read_server(semanage_handle_t *sh, int socket_fd, uint32_t * message_type,
+		uint64_t * data_length, char **data);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#41 lore raw

PATCH 25/33 libsemanage: policy server database hooks

In reply to [email protected]

Implements all database functions for a policy server backend.

---
 libsemanage/include/semanage/database_ps.h |   37 +
 libsemanage/include/semanage/handle.h      |    7 
 libsemanage/include/semanage/semanage.h    |    4 
 libsemanage/src/booleans_ps.c              |  100 ++++
 libsemanage/src/database.h                 |    9 
 libsemanage/src/database_ps.c              |  368 +++++++++++++++
 libsemanage/src/database_ps.h              |   55 ++
 libsemanage/src/fcontexts_ps.c             |   59 ++
 libsemanage/src/handle.c                   |   41 +
 libsemanage/src/handle.h                   |    2 
 libsemanage/src/handle_internal.h          |    2 
 libsemanage/src/interfaces_ps.c            |   78 +++
 libsemanage/src/libsemanage.map            |    2 
 libsemanage/src/nodes_ps.c                 |   78 +++
 libsemanage/src/ports_ps.c                 |   78 +++
 libsemanage/src/ps_api.c                   |  690 +++++++++++++++++++++++++++++
 libsemanage/src/ps_api.h                   |   31 +
 libsemanage/src/seusers_ps.c               |   58 ++
 libsemanage/src/users_ps.c                 |   82 +++
 libsemanage/tests/globals.h                |   39 +
 libsemanage/tests/libsemanage-tests.c      |   16 
 libsemanage/tests/test_ps_api_connect.c    |  346 ++++++++++++++
 libsemanage/tests/test_ps_api_connect.h    |   33 +
 libsemanage/tests/test_ps_api_disconnect.c |  178 +++++++
 libsemanage/tests/test_ps_api_disconnect.h |   33 +
 25 files changed, 2412 insertions(+), 14 deletions(-)
libsemanage/include/semanage/database_ps.h new file +37 -0
Index: selinux-pms-support/libsemanage/include/semanage/database_ps.h
===================================================================
@@ -0,0 +1,37 @@
+/* Authors: Caleb Case           <[email protected]>
+ *
+ * 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_DATABASE_PS_H_
+#define _SEMANAGE_DATABASE_PS_H_
+
+#include <stdio.h>
+#include "handle.h"
+
+#ifndef DBASE_CONFIG
+#define DBASE_CONFIG
+typedef struct dbase_config dbase_config_t;
+#endif
+
+/* PS - database type handling */
+extern int semanage_dbase_ps_get_database_type(semanage_handle_t *sh, dbase_config_t *dconfig, uint32_t * database_type);
+extern int semanage_dbase_ps_set_database_type(semanage_handle_t *sh, dbase_config_t *dconfig, uint32_t database_type);
+extern int semanage_dbase_ps_database_type_serialize(semanage_handle_t *sh, uint32_t database_type, char **data, uint64_t *size);
+extern int semanage_dbase_ps_database_type_unserialize(semanage_handle_t *sh, char **data, uint64_t *size, uint32_t *database_type) ;
+
+#endif
libsemanage/include/semanage/handle.h +6 -1
Index: selinux-pms-support/libsemanage/include/semanage/handle.h
===================================================================
@@ -26,6 +26,8 @@
 
 #include <inttypes.h>
 
+#include <sepol/handle.h>
+
 /* All accesses with semanage are through a "semanage_handle".  The
  * handle may ultimately reference local config files,
  * the binary policy file, a module store, or a policy management server. 
@@ -66,7 +68,7 @@ enum semanage_connect_type {
  * It must be called after semanage_handle_create but before 
  * semanage_connect. The argument should be the full path to the store.
  */
-void semanage_select_store(semanage_handle_t * handle, char *path,
+void semanage_select_store(semanage_handle_t * handle, const char *path,
 			   enum semanage_connect_type storetype);
 
 /* Just reload the policy */
@@ -81,6 +83,9 @@ void semanage_set_reload(semanage_handle
  * 1 for yes, 0 for no (default) */
 void semanage_set_rebuild(semanage_handle_t * handle, int do_rebuild);
 
+/* returns the sepol handle associated with this handle */
+sepol_handle_t *semanage_get_sepol_handle(semanage_handle_t * sh);
+
 /* create the store if it does not exist, this only has an effect on 
  * direct connections and must be called before semanage_connect 
  * 1 for yes, 0 for no (default) */
libsemanage/include/semanage/semanage.h +4 -0
Index: selinux-pms-support/libsemanage/include/semanage/semanage.h
===================================================================
@@ -24,6 +24,7 @@
 
 #include <semanage/handle.h>
 #include <semanage/modules.h>
+#include <semanage/policy.h>
 #include <semanage/debug.h>
 
 /* Records */
@@ -55,4 +56,7 @@
 /* Messaging */
 #include <semanage/messages.h>
 
+/* Database types */
+#include <semanage/database_ps.h>
+
 #endif
libsemanage/src/booleans_ps.c new file +100 -0

100 lines not on this page · raw message

libsemanage/src/database.h +7 -2
Index: selinux-pms-support/libsemanage/src/database.h
===================================================================
@@ -209,7 +209,7 @@ typedef struct dbase_table {
 
 } dbase_table_t;
 
-typedef struct dbase_config {
+struct dbase_config {
 
 	/* Database state */
 	dbase_t *dbase;
@@ -217,7 +217,12 @@ typedef struct dbase_config {
 	/* Database methods */
 	dbase_table_t *dtable;
 
-} dbase_config_t;
+};
+
+#ifndef DBASE_CONFIG
+#define DBASE_CONFIG
+typedef struct dbase_config dbase_config_t;
+#endif
 
 extern int dbase_add(struct semanage_handle *handle,
 		     dbase_config_t * dconfig,
libsemanage/src/database_ps.c new file +368 -0

368 lines not on this page · raw message

libsemanage/src/database_ps.h new file +55 -0

55 lines not on this page · raw message

libsemanage/src/fcontexts_ps.c new file +59 -0

59 lines not on this page · raw message

libsemanage/src/handle.c +31 -10

90 lines not on this page · raw message

libsemanage/src/handle.h +2 -0
Index: selinux-pms-support/libsemanage/src/handle.h
===================================================================
@@ -30,6 +30,7 @@
 #include "semanage_conf.h"
 #include "database.h"
 #include "direct_api.h"
+#include "ps_api.h"
 #include "policy.h"
 
 struct semanage_handle {
@@ -49,6 +50,7 @@ struct semanage_handle {
 	/* Direct vs Server specific handle */
 	union {
 		struct semanage_direct_handle direct;
+		struct semanage_ps_handle ps_handle;
 	} u;
 
 	/* Libsepol handle */
libsemanage/src/handle_internal.h +1 -1
Index: selinux-pms-support/libsemanage/src/handle_internal.h
===================================================================
@@ -12,5 +12,5 @@ hidden_proto(semanage_handle_get_version
 hidden_proto(semanage_handle_set_version)
 hidden_proto(semanage_handle_version_serialize)
 hidden_proto(semanage_handle_version_unserialize)
-
+hidden_proto(semanage_get_sepol_handle)
 #endif
libsemanage/src/interfaces_ps.c new file +78 -0

78 lines not on this page · raw message

libsemanage/src/libsemanage.map +2 -0
Index: selinux-pms-support/libsemanage/src/libsemanage.map
===================================================================
@@ -1,5 +1,6 @@
 LIBSEMANAGE_1.0 {
   global: semanage_handle_create; semanage_handle_destroy; 
+          semanage_get_sepol_handle;
           semanage_is_managed; semanage_connect; semanage_disconnect; 
 	  semanage_msg_*;
           semanage_begin_transaction; semanage_commit;
@@ -16,6 +17,7 @@ LIBSEMANAGE_1.0 {
 	  semanage_fcontext_*; semanage_access_check; semanage_set_create_store;
 	  semanage_*_serialize; semanage_*_unserialize;
 	  semanage_is_connected;
+	  semanage_handle_get_version; semanage_handle_set_version;
 	  semanage_policy_table_serialize_serial;
   local: *;
 };
libsemanage/src/nodes_ps.c new file +78 -0

78 lines not on this page · raw message

libsemanage/src/ports_ps.c new file +78 -0

78 lines not on this page · raw message

libsemanage/src/ps_api.c new file +690 -0

690 lines not on this page · raw message

libsemanage/src/ps_api.h new file +31 -0
Index: selinux-pms-support/libsemanage/src/ps_api.h
===================================================================
@@ -0,0 +1,31 @@
+#ifndef _SEMANAGE_PS_API_H_
+#define _SEMANAGE_PS_API_H_
+
+#include <sys/types.h>
+
+struct semanage_handle;
+
+struct semanage_ps_handle {
+	int socket_fd;
+};
+
+int semanage_ps_begintrans(semanage_handle_t * sh);
+int semanage_ps_commit(semanage_handle_t * sh);
+int semanage_ps_connect(semanage_handle_t * sh);
+int semanage_ps_is_managed(semanage_handle_t * sh);
+int semanage_ps_disconnect(semanage_handle_t * sh);
+int semanage_ps_install_base_module(semanage_handle_t * sh, char *base_data,
+				    size_t data_len);
+int semanage_ps_install_module(semanage_handle_t * sh, char *module_data,
+			       size_t data_len);
+int semanage_ps_list_modules(semanage_handle_t * sh,
+			     semanage_module_info_t ** mod_names,
+			     int *num_mods);
+int semanage_ps_list_sandbox(semanage_handle_t * sh);
+int semanage_ps_remove_module(semanage_handle_t * sh, char *module_name);
+int semanage_ps_upgrade_module(semanage_handle_t * sh, char *module_data,
+			       size_t data_len);
+int semanage_ps_get_commit_number(semanage_handle_t * sh);
+void semanage_ps_destroy(semanage_handle_t * sh);
+
+#endif
libsemanage/src/seusers_ps.c new file +58 -0

58 lines not on this page · raw message

libsemanage/src/users_ps.c new file +82 -0

82 lines not on this page · raw message

libsemanage/tests/globals.h +39 -0
Index: selinux-pms-support/libsemanage/tests/globals.h
===================================================================
@@ -24,4 +24,43 @@
 
 semanage_handle_t *sh;
 
+/* ps_api */
+pid_t ps_pid;
+char *socket_path;
+int server_socket_fd;
+int client_socket_fd;
+
+typedef int (*create_f) (
+			struct semanage_handle * handle,
+			record_t ** rec);
+typedef int (*key_extract_f) (
+			struct semanage_handle * handle,
+			const record_t * rec,
+			record_key_t ** key);
+typedef void (*key_free_f) (record_key_t * key);
+typedef int (*compare_f) (
+			const record_t * rec,
+			const record_key_t * key);
+typedef int (*compare2_f) (
+			const record_t * rec,
+			const record_t * rec2);
+typedef int (*compare2_qsort_f) (
+			const record_t ** rec,
+			const record_t ** rec2);
+typedef int (*clone_f) (
+			struct semanage_handle * handle,
+			const record_t * rec,
+			record_t ** new_rec);
+typedef int (*serialize_f) (
+			struct semanage_handle* handle,
+			const record_t* rec,
+			char** rec_data,
+			uint64_t* size);
+typedef int (*unserialize_f) (
+			struct semanage_handle* handle,
+			char** rec_data,
+			uint64_t* size,
+			record_t** rec);
+typedef void (*free_f) (record_t * rec);
+
 #endif
libsemanage/tests/libsemanage-tests.c +16 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -30,6 +30,9 @@
 #include "test_seuser_record.h"
 #include "test_user_record.h"
 
+#include "test_ps_api_connect.h"
+#include "test_ps_api_disconnect.h"
+
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
 #include <CUnit/TestDB.h>
@@ -74,6 +77,19 @@ static int do_tests(int interactive, int
 	DECLARE_SUITE(seuser_record);
 	DECLARE_SUITE(user_record);
 
+	/* The ps_api_connect test forks the
+	 * tests into client and server variants.
+	 */
+	DECLARE_SUITE(ps_api_connect);
+
+	/* These tests rely upon the policy server
+	 * being properly connected via the
+	 * ps_api_connect test.
+	 */
+
+	/* The ps_api_disconnect test 'unforks'. */
+	DECLARE_SUITE(ps_api_disconnect);
+
 	if (verbose)
 		CU_basic_set_mode(CU_BRM_VERBOSE);
 	else
libsemanage/tests/test_ps_api_connect.c new file +346 -0

346 lines not on this page · raw message

libsemanage/tests/test_ps_api_connect.h new file +33 -0
Index: selinux-pms-support/libsemanage/tests/test_ps_api_connect.h
===================================================================
@@ -0,0 +1,33 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_PS_API_CONNECT_H__
+#define __TEST_PS_API_CONNECT_H__
+
+#include "handle.h"
+#include <CUnit/Basic.h>
+
+int ps_api_connect_test_init(void);
+int ps_api_connect_test_cleanup(void);
+int ps_api_connect_add_tests(CU_pSuite suite);
+
+void test_semanage_ps_connect(void);
+
+#endif
libsemanage/tests/test_ps_api_disconnect.c new file +178 -0

178 lines not on this page · raw message

libsemanage/tests/test_ps_api_disconnect.h new file +33 -0
Index: selinux-pms-support/libsemanage/tests/test_ps_api_disconnect.h
===================================================================
@@ -0,0 +1,33 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_PS_API_DISCONNECT_H__
+#define __TEST_PS_API_DISCONNECT_H__
+
+#include <CUnit/Basic.h>
+
+int ps_api_disconnect_test_init(void);
+int ps_api_disconnect_test_cleanup(void);
+int ps_api_disconnect_add_tests(CU_pSuite suite);
+
+void test_semanage_ps_connect(void);
+void test_semanage_ps_disconnect(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#42 lore raw

Re: [PATCH 25/33] libsemanage: policy server database hooks

Quoted 2 lines · On Mon, 2007-04-23 at 17:35 -0400, [email protected] wrote:

plain text document attachment (semanage.ps_api.diff) Implements all database functions for a policy server backend.

Any thoughts on how this should be merged? I'm concerned about merging without a working policy server that has been reviewed as well.

* What are your plans for the policy server - will it be proposed for inclusion upstream?

* What is the timeline for completion of the policy server?

* Are their any docs at all about the protocol?

* Any progress on the exec-based policy server instead of the long running daemon?

Basically - this patch set is too large to review, there have been no ongoing design discussions, there is no way to review large portions of the patch set due to external dependencies, and I have seen no proposed plan for merging.

I have voiced these concerns previously and without at least some of the above I'm opposed merging at this time.

I would suggest as an alternative plan you do a depth-first submission instead of the breadth-first approach that you are currently attempting. That would allow a review of the end-to-end design with a relatively small amount of code. From that point expanding the coverage would only require a quick review that the patch continues on the already accepted approach.

That steps that I suggest are:

* Choose a _single_ and _simple_ semanage operation to control. Something like adding a role to a user.

* Post a minimal policy server that can control this operation (preferably exec-based).

* Post the libsemange code to communicate with the server _only_ that single operation.

* Create an example policy that controls this operation that can be used to test and demonstrate the functionality.

Karl

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#43 lore raw

RE: [PATCH 25/33] libsemanage: policy server database hooks

Quoted 11 lines

From: Karl MacMillan [mailto:[email protected]]

Quoted 1 line · On Mon, 2007-04-23 at 17:35 -0400, [email protected] wrote:

plain text document attachment (semanage.ps_api.diff)

Implements all

Quoted 1 line

database functions for a policy server backend.

Any thoughts on how this should be merged? I'm concerned about merging without a working policy server that has been reviewed as well.

Its available, review it ;) Note that it won't work with _just_ this patch set as it expects the enforcement hooks to be present. It should be trivial to comment out all the function pointers to get it to work without that though.

Quoted 3 lines

* What are your plans for the policy server - will it be proposed for inclusion upstream?

That was never my intention.

Quoted 2 lines

* What is the timeline for completion of the policy server?

I sent out an RFC/announcement a while back about its availability on oss.tresys.com, noone bothered to respond.

Quoted 2 lines

* Are their any docs at all about the protocol?

Some, I'll dig them out and post them on oss.

Quoted 3 lines

* Any progress on the exec-based policy server instead of the long running daemon?

The exec-based one has nothing to do with this patchset. The exec based policy server would merely run with the new and old policies as arguments and do its thing, it would not need to communicate with libsemanage. This patchset is for the long-running daemon that listens on a unix domain socket or tcp socket. The exec based one should come along with the hook code when that gets ported over to the new representation.

Quoted 5 lines

Basically - this patch set is too large to review, there have been no ongoing design discussions, there is no way to review large portions of the patch set due to external dependencies, and I have seen no proposed plan for merging.

There have been occasional RFC's that noone responded to.

Quoted 3 lines

I have voiced these concerns previously and without at least some of the above I'm opposed merging at this time.

I believe you have some misconceptions about this patchset, read below.

Quoted 8 lines

I would suggest as an alternative plan you do a depth-first submission instead of the breadth-first approach that you are currently attempting.
That would allow a review of the end-to-end design with a relatively small amount of code. From that point expanding the coverage would only require a quick review that the patch continues on the already accepted approach.

Quoted 5 lines

That steps that I suggest are:

* Choose a _single_ and _simple_ semanage operation to control. Something like adding a role to a user.

This patchset nor the hooks currently available do access control on semanage operations. Only policy modules have enforcement hooks written and all that is available on oss.tresys.com.

Quoted 3 lines

* Post a minimal policy server that can control this operation (preferably exec-based).

As part of the hooks, yes.

Quoted 3 lines

* Post the libsemange code to communicate with the server _only_ that single operation.

That is silly, to choose a new backend for libsemanage you need all the function pointers. Filling in all of them with direct versions except for a single one would be at least confusing and at most would break badly since both the local semanage and the policy server would attempt to lock the store.

Quoted 3 lines

* Create an example policy that controls this operation that can be used to test and demonstrate the functionality.

Example policy that controls what we have hooks for is available in tests and on oss.tresys.com.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#44 lore raw

RE: [PATCH 25/33] libsemanage: policy server database hooks

Quoted 5 lines · Joshua Brindle
Quoted 5 lines

From: Karl MacMillan [mailto:[email protected]]

Quoted 1 line · On Mon, 2007-04-23 at 17:35 -0400, [email protected] wrote:

plain text document attachment (semanage.ps_api.diff)

Implements all

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

database functions for a policy server backend.

Any thoughts on how this should be merged? I'm concerned about merging without a working policy server that has been reviewed as well.

Its available, review it ;)

I have - every time you have posted an RFC.

Quoted 5 lines

Note that it won't work with _just_ this
patch set as it expects the enforcement hooks to be present. It should be trivial to comment out all the function pointers to get it to work without that though.

But there is a working set of patches somewhere?

Quoted 6 lines
Quoted 3 lines

* What are your plans for the policy server - will it be proposed for inclusion upstream?

That was never my intention.

Well - that is a problem in my opinion. I think we get two choices:

1) policy server and libsemanage are both upstream and are considered closely coupled and developed in parallel.

2) protocol for communication with a policy server is well documented and designed for interop with multiple server implementations.

If you want these huge, intrusive changes for code that won't be part of upstream I think there needs to be some justification. Why should upstream take on the maintenance of code that it ultimately can't fix (because of a huge external dependency)? Why is this better as a separate project? How will maintenance work? Is a different implementation of the policy server really feasible or are the changes really tailored to your specific implementation?

Quoted 6 lines
Quoted 2 lines

* What is the timeline for completion of the policy server?

I sent out an RFC/announcement a while back about its availability on oss.tresys.com, noone bothered to respond.

I responded - http://marc.info/?l=selinux&m=117286669726063&w=2. That is where I first asked about an exec based server.

Quoted 5 lines
Quoted 2 lines

* Are their any docs at all about the protocol?

Some, I'll dig them out and post them on oss.

Quoted 8 lines
Quoted 3 lines

* Any progress on the exec-based policy server instead of the long running daemon?

The exec-based one has nothing to do with this patchset. The exec based policy server would merely run with the new and old policies as arguments and do its thing, it would not need to communicate with libsemanage.

I don't think that would work - how are you going to detect changes to port labels or seusers? It would at least be massively inefficient.

You can simply exec the server and communicate over unix-domain sockets (or a pair pipes). That would make the two servers very similar.

Quoted 5 lines

This patchset is for the long-running daemon that listens
on a unix domain socket or tcp socket. The exec based one should come along with the hook code when that gets ported over to the new representation.

What is the justification for the long-running daemon?

Quoted 8 lines
Quoted 5 lines

Basically - this patch set is too large to review, there have been no ongoing design discussions, there is no way to review large portions of the patch set due to external dependencies, and I have seen no proposed plan for merging.

There have been occasional RFC's that noone responded to.

I've responded to every RFC and stated these concerns every time. Trying to suggest that nobody has responded is very inaccurate.

Quoted 6 lines
Quoted 3 lines

I have voiced these concerns previously and without at least some of the above I'm opposed merging at this time.

I believe you have some misconceptions about this patchset, read below.

I don't think so. Basically - this forms the lowest part of the policy server protocol. Trying to understand whether these patches make sense in that context means understanding the system as a whole. Yes you have posted pieces, but I have not seen something that works end-to-end.

Additionally, you keep posting these massive patch sets. They are not reviewable in any sane way.

Quoted 8 lines
Quoted 8 lines

I would suggest as an alternative plan you do a depth-first submission instead of the breadth-first approach that you are currently attempting.
That would allow a review of the end-to-end design with a relatively small amount of code. From that point expanding the coverage would only require a quick review that the patch continues on the already accepted approach.

Quoted 8 lines
Quoted 5 lines

That steps that I suggest are:

* Choose a _single_ and _simple_ semanage operation to control. Something like adding a role to a user.

This patchset nor the hooks currently available do access control on semanage operations. Only policy modules have enforcement hooks written

Yes, but they need to eventually and without that serializing all of these data structures is not useful (at the moment). If they are only going to be used for the policyrep then we should merge them later and tailor them for that usage.

Quoted 10 lines
Quoted 3 lines

* Post a minimal policy server that can control this operation (preferably exec-based).

As part of the hooks, yes.

Quoted 3 lines

* Post the libsemange code to communicate with the server _only_ that single operation.

Quoted 6 lines

That is silly, to choose a new backend for libsemanage you need all the function pointers. Filling in all of them with direct versions except for a single one would be at least confusing and at most would break badly since both the local semanage and the policy server would attempt to lock the store.

Of course it would only work for a limited set of operations (and the rest would likely return an error rather than having direct versions substituted).

The point is that it would allow review of a smaller set of patches that makes some sort of sense as a whole. Your submissions are not tailored for thorough review and any feedback you receive is going to be shallow. I think that is harmful in the long run.

If others (Steve and Darrell) want to merge these patches that's fine. But based on the problems I have seen so far, the size of this patch set, and the _many_ larger questions I'm opposed.

My biggest concern, honestly, is the long term viability and maintenance of this code.

Karl

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#45 lore raw

RE: [PATCH 25/33] libsemanage: policy server database hooks

Quoted 10 lines

From: Karl MacMillan [mailto:[email protected]]

Quoted 7 lines · Joshua Brindle
Quoted 7 lines

From: Karl MacMillan [mailto:[email protected]]

Quoted 1 line · On Mon, 2007-04-23 at 17:35 -0400, [email protected] wrote:

plain text document attachment (semanage.ps_api.diff)

Implements all

Quoted 1 line

database functions for a policy server backend.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

Any thoughts on how this should be merged? I'm concerned about merging without a working policy server that has been reviewed as well.

Its available, review it ;)

I have - every time you have posted an RFC.

I meant the policy server itself.

Quoted 9 lines
Quoted 1 line

Note that it won't work with _just_ this patch set as it

expects the

Quoted 1 line

enforcement hooks to be present. It should be trivial to

comment out

Quoted 2 lines

all the function pointers to get it to work without that though.

But there is a working set of patches somewhere?

Yes, which include the hooks, I sent a link to the list which you responded to:
http://marc.info/?l=selinux&m=117286669726063&w=2

The full set of patches are in the srpms and in the svn tree.

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

* What are your plans for the policy server - will it be proposed for inclusion upstream?

That was never my intention.

Quoted 9 lines

Well - that is a problem in my opinion. I think we get two choices:

1) policy server and libsemanage are both upstream and are considered closely coupled and developed in parallel.

2) protocol for communication with a policy server is well documented and designed for interop with multiple server implementations.

I was going to go for #2. It doesn't matter that much to me though, we could put the policy server in the upstream tree.

Quoted 9 lines

If you want these huge, intrusive changes for code that won't be part of upstream I think there needs to be some justification. Why should upstream take on the maintenance of code that it ultimately can't fix (because of a huge external dependency)? Why is this better as a separate project? How will maintenance work? Is a different implementation of the policy server really feasible or are the changes really tailored to your specific implementation?

It's a generic protocol and we provide generic hooks (we actually provide more data in the hooks than my specific implementation uses). I don't know how useful another implementation would be, though.

Quoted 12 lines
Quoted 4 lines
Quoted 2 lines

* What is the timeline for completion of the policy server?

I sent out an RFC/announcement a while back about its

availability on

Quoted 2 lines

oss.tresys.com, noone bothered to respond.

I responded -
http://marc.info/?l=selinux&m=117286669726063&w=2. That is where I first asked about an exec based server.

Err.. Right, sorry about that

Quoted 12 lines
Quoted 6 lines
Quoted 2 lines

* Are their any docs at all about the protocol?

Some, I'll dig them out and post them on oss.

Quoted 1 line

* Any progress on the exec-based policy server instead of

the long

Quoted 5 lines
Quoted 2 lines

running daemon?

The exec-based one has nothing to do with this patchset. The exec based policy server would merely run with the new and old

Quoted 8 lines

policies as

Quoted 2 lines

arguments and do its thing, it would not need to communicate with libsemanage.

I don't think that would work - how are you going to detect changes to port labels or seusers? It would at least be massively inefficient.

The policy server will eventually have to implement access control on ocontext changes and we could just pass the whole active and previous directories to it to do the things not in policies, like seusers. I guess we could make it work with a socket pair though.

Quoted 4 lines

You can simply exec the server and communicate over unix-domain sockets (or a pair pipes). That would make the two servers very similar.

Quoted 9 lines
Quoted 1 line

This patchset is for the long-running daemon that listens

on a unix

Quoted 1 line

domain socket or tcp socket. The exec based one should come

along with

Quoted 2 lines

the hook code when that gets ported over to the new representation.

What is the justification for the long-running daemon?

Network management.

Quoted 5 lines
Quoted 1 line
Quoted 1 line

Basically - this patch set is too large to review, there

have been

Quoted 2 lines
Quoted 2 lines

no ongoing design discussions, there is no way to review large portions of the patch set due to external dependencies,

and I have

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

seen no proposed plan for merging.

There have been occasional RFC's that noone responded to.

I've responded to every RFC and stated these concerns every time. Trying to suggest that nobody has responded is very inaccurate.

Ok, ok, sorry about that mischaractorization.

Quoted 6 lines
Quoted 1 line
Quoted 1 line

I have voiced these concerns previously and without at

least some of

Quoted 4 lines
Quoted 2 lines

the above I'm opposed merging at this time.

I believe you have some misconceptions about this patchset,

Quoted 9 lines

read below.

Quoted 1 line

I don't think so. Basically - this forms the lowest part of the policy server protocol. Trying to understand whether these patches make sense in that context means understanding the system as a whole. Yes you have posted pieces, but I have not seen something that works end-to-end.

The stuff on oss works end-to-end.

Quoted 3 lines

Additionally, you keep posting these massive patch sets. They are not reviewable in any sane way.

Right, we've been sitting on these patches, I'll try to be better about doing things incrementally in the future (but to be fair this has been in the works for quite some time).

Quoted 18 lines
Quoted 4 lines
Quoted 4 lines

I would suggest as an alternative plan you do a depth-first submission instead of the breadth-first approach that you are currently attempting.
That would allow a review of the end-to-end design with a

relatively

Quoted 1 line
Quoted 1 line

small amount of code. From that point expanding the

coverage would

Quoted 1 line
Quoted 1 line

only require a quick review that the patch continues on

the already

Quoted 9 lines
Quoted 7 lines

accepted approach.

That steps that I suggest are:

* Choose a _single_ and _simple_ semanage operation to control. Something like adding a role to a user.

This patchset nor the hooks currently available do access

Quoted 9 lines

control on

Quoted 2 lines

semanage operations. Only policy modules have enforcement hooks written

Yes, but they need to eventually and without that serializing all of these data structures is not useful (at the moment). If they are only going to be used for the policyrep then we should merge them later and tailor them for that usage.

They should be useful for both cases. We'll need them for policyrep soon and for policy server later, I was hoping to have them up and generalized for both usages.

Quoted 14 lines
Quoted 6 lines
Quoted 3 lines

* Post a minimal policy server that can control this operation (preferably exec-based).

As part of the hooks, yes.

Quoted 7 lines
Quoted 3 lines

* Post the libsemange code to communicate with the server _only_ that single operation.

That is silly, to choose a new backend for libsemanage you need all the function pointers. Filling in all of them with direct versions except for a single one would be at least confusing and at

most would

Quoted 9 lines
Quoted 1 line

break badly since both the local semanage and the policy

server would

Quoted 2 lines

attempt to lock the store.

Of course it would only work for a limited set of operations (and the rest would likely return an error rather than having direct versions substituted).

That won't work with the current libsemanage setup, it'll just fail anytime you try to do anything.

Quoted 6 lines

The point is that it would allow review of a smaller set of patches that makes some sort of sense as a whole. Your submissions are not tailored for thorough review and any feedback you receive is going to be shallow.
I think that is harmful in the long run.

Yes, big bang integration sucks and this patch set to implement serialization was much bigger than I'd have liked it to be but its all done and starting over now makes little sense.

Quoted 7 lines

If others (Steve and Darrell) want to merge these patches that's fine. But based on the problems I have seen so far, the size of this patch set, and the _many_ larger questions I'm opposed.

My biggest concern, honestly, is the long term viability and maintenance of this code.

Fair enough.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#46 lore raw

RE: [PATCH 25/33] libsemanage: policy server database hooks

Quoted 1 line · Joshua Brindle
Quoted 1 line

From: Karl MacMillan [mailto:[email protected]]

<snip>

Quoted 5 lines
Quoted 5 lines

Well - that is a problem in my opinion. I think we get two choices:

1) policy server and libsemanage are both upstream and are considered closely coupled and developed in parallel.

Quoted 8 lines
Quoted 4 lines

2) protocol for communication with a policy server is well documented and designed for interop with multiple server implementations.

I was going to go for #2. It doesn't matter that much to me though, we could put the policy server in the upstream tree.

For #2 I think we need much more documentation and design review because it basically becomes a public protocol. That is why I think #1 is better
- then we can just say they are closely coupled and the protocol between the components is private. It will still need versioning, etc., but because they are maintained together we will have more freedom.

Quoted 10 lines
Quoted 9 lines

If you want these huge, intrusive changes for code that won't be part of upstream I think there needs to be some justification. Why should upstream take on the maintenance of code that it ultimately can't fix (because of a huge external dependency)? Why is this better as a separate project? How will maintenance work? Is a different implementation of the policy server really feasible or are the changes really tailored to your specific implementation?

Quoted 4 lines

It's a generic protocol and we provide generic hooks (we actually provide more data in the hooks than my specific implementation uses). I don't know how useful another implementation would be, though.

I don't think another implementation would be useful, which is why I think it is better just to upstream the policy server.

Quoted 31 lines
Quoted 12 lines
Quoted 4 lines
Quoted 2 lines

* What is the timeline for completion of the policy server?

I sent out an RFC/announcement a while back about its

availability on

Quoted 2 lines

oss.tresys.com, noone bothered to respond.

I responded -
http://marc.info/?l=selinux&m=117286669726063&w=2. That is where I first asked about an exec based server.

Err.. Right, sorry about that

Quoted 16 lines
Quoted 6 lines
Quoted 2 lines

* Are their any docs at all about the protocol?

Some, I'll dig them out and post them on oss.

Quoted 1 line

* Any progress on the exec-based policy server instead of

the long

Quoted 5 lines
Quoted 2 lines

running daemon?

The exec-based one has nothing to do with this patchset. The exec based policy server would merely run with the new and old

policies as

Quoted 2 lines

arguments and do its thing, it would not need to communicate with libsemanage.

Quoted 8 lines
Quoted 4 lines

I don't think that would work - how are you going to detect changes to port labels or seusers? It would at least be massively inefficient.

The policy server will eventually have to implement access control on ocontext changes and we could just pass the whole active and previous directories to it to do the things not in policies, like seusers.

It seems a shame to not use the information that we would already have about what changed.

Quoted 3 lines

I
guess we could make it work with a socket pair though.

That seems to be a gain in efficiency and makes it possible to easily have a daemon or an exec-based version.

Quoted 7 lines
Quoted 7 lines

You can simply exec the server and communicate over unix-domain sockets (or a pair pipes). That would make the two servers very similar.

Quoted 1 line

This patchset is for the long-running daemon that listens

on a unix

Quoted 1 line

domain socket or tcp socket. The exec based one should come

Quoted 9 lines
Quoted 6 lines

along with

Quoted 2 lines

the hook code when that gets ported over to the new representation.

What is the justification for the long-running daemon?

Network management.

Well - I still think that it is better to just allow proper local management and let higher-level tools (like
http://reductivelabs.com/projects/puppet/ for example) do the remote management parts. Plus, I really hesitate to expose something like this on the network on every client. Using something like puppet lets you use a pull model.

<snip>

Quoted 12 lines
Quoted 11 lines
Quoted 2 lines

This patchset nor the hooks currently available do access

control on

Quoted 2 lines

semanage operations. Only policy modules have enforcement hooks written

Yes, but they need to eventually and without that serializing all of these data structures is not useful (at the moment). If they are only going to be used for the policyrep then we should merge them later and tailor them for that usage.

Quoted 4 lines

They should be useful for both cases. We'll need them for policyrep soon and for policy server later, I was hoping to have them up and generalized for both usages.

Ok - looking through these again. If you take out the silly duplication between libsemanage / libsepol, just one set of serialization patches are fairly small. I'm not opposed in principal to merging that after the comments are addressed
(just for libsepol - I think we should remove the libsemanage code).

After that, could you post some more in-depth discussion about the networking bits?

Karl

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#47 lore raw

PATCH 26/33 libsemanage: module serialization tests

In reply to [email protected]
libsemanage/tests/libsemanage-tests.c +4 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -33,6 +33,8 @@
 #include "test_ps_api_connect.h"
 #include "test_ps_api_disconnect.h"
 
+#include "test_modules.h"
+
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
 #include <CUnit/TestDB.h>
@@ -82,6 +84,8 @@ static int do_tests(int interactive, int
 	 */
 	DECLARE_SUITE(ps_api_connect);
 
+	DECLARE_SUITE(modules);
+
 	/* These tests rely upon the policy server
 	 * being properly connected via the
 	 * ps_api_connect test.
libsemanage/tests/test_modules.c new file +235 -0

235 lines not on this page · raw message

libsemanage/tests/test_modules.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_modules.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_MODULES_H__
+#define __TEST_MODULES_H__
+
+#include <CUnit/Basic.h>
+
+int modules_test_init(void);
+int modules_test_cleanup(void);
+int modules_add_tests(CU_pSuite suite);
+
+void test_semanage_module_list_serialize(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#48 lore raw

PATCH 27/33 libsemanage: booleans serialization tests

In reply to [email protected]
---
 libsemanage/tests/libsemanage-tests.c    |    7 
 libsemanage/tests/test_booleans_active.c |  461 +++++++++++++++++++++++++++++++
 libsemanage/tests/test_booleans_active.h |   32 ++
 libsemanage/tests/test_booleans_file.c   |  457 ++++++++++++++++++++++++++++++
 libsemanage/tests/test_booleans_file.h   |   32 ++
 libsemanage/tests/test_booleans_policy.c |  352 +++++++++++++++++++++++
 libsemanage/tests/test_booleans_policy.h |   32 ++
 libsemanage/tests/utilities.c            |   58 +++
 libsemanage/tests/utilities.h            |    7 
 9 files changed, 1438 insertions(+)
libsemanage/tests/libsemanage-tests.c +7 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -35,6 +35,10 @@
 
 #include "test_modules.h"
 
+#include "test_booleans_active.h"
+#include "test_booleans_file.h"
+#include "test_booleans_policy.h"
+
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
 #include <CUnit/TestDB.h>
@@ -90,6 +94,9 @@ static int do_tests(int interactive, int
 	 * being properly connected via the
 	 * ps_api_connect test.
 	 */
+	DECLARE_SUITE(booleans_active);
+	DECLARE_SUITE(booleans_file);
+	DECLARE_SUITE(booleans_policy);
 
 	/* The ps_api_disconnect test 'unforks'. */
 	DECLARE_SUITE(ps_api_disconnect);
libsemanage/tests/test_booleans_active.c new file +461 -0

461 lines not on this page · raw message

libsemanage/tests/test_booleans_active.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_booleans_active.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_BOOLEANS_ACTIVE_H__
+#define __TEST_BOOLEANS_ACTIVE_H__
+
+#include <CUnit/Basic.h>
+
+int booleans_active_test_init(void);
+int booleans_active_test_cleanup(void);
+int booleans_active_add_tests(CU_pSuite suite);
+
+void test_semanage_bool_serialize_active(void);
+
+#endif
libsemanage/tests/test_booleans_file.c new file +457 -0

457 lines not on this page · raw message

libsemanage/tests/test_booleans_file.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_booleans_file.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_BOOLEANS_FILE_H__
+#define __TEST_BOOLEANS_FILE_H__
+
+#include <CUnit/Basic.h>
+
+int booleans_file_test_init(void);
+int booleans_file_test_cleanup(void);
+int booleans_file_add_tests(CU_pSuite suite);
+
+void test_semanage_bool_serialize_local(void);
+
+#endif
libsemanage/tests/test_booleans_policy.c new file +352 -0

352 lines not on this page · raw message

libsemanage/tests/test_booleans_policy.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_booleans_policy.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_BOOLEANS_POLICY_H__
+#define __TEST_BOOLEANS_POLICY_H__
+
+#include <CUnit/Basic.h>
+
+int booleans_policy_test_init(void);
+int booleans_policy_test_cleanup(void);
+int booleans_policy_add_tests(CU_pSuite suite);
+
+void test_semanage_bool_serialize_policy(void);
+
+#endif
libsemanage/tests/utilities.c +58 -0

67 lines not on this page · raw message

libsemanage/tests/utilities.h +7 -0
Index: selinux-pms-support/libsemanage/tests/utilities.h
===================================================================
@@ -17,7 +17,14 @@
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <inttypes.h>
+
 #include "handle.h"
 
 void test_msg_handler(void *varg, semanage_handle_t * handle, const char *fmt,
 		      ...);
+
+int test_semanage_serialize_serial(semanage_handle_t *sh, int commit_number, char **data, uint64_t *data_length);
+
+int test_semanage_ps_handle_get_commit_number(semanage_handle_t *sh, int commit_number);
+
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#49 lore raw

PATCH 28/33 libsemanage: fcontexts serialization tests

In reply to [email protected]
---
 libsemanage/tests/libsemanage-tests.c     |    6 
 libsemanage/tests/test_fcontexts_file.c   |  531 ++++++++++++++++++++++++++++++
 libsemanage/tests/test_fcontexts_file.h   |   32 +
 libsemanage/tests/test_fcontexts_policy.c |  394 ++++++++++++++++++++++
 libsemanage/tests/test_fcontexts_policy.h |   32 +
 5 files changed, 995 insertions(+)
libsemanage/tests/libsemanage-tests.c +6 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -39,6 +39,9 @@
 #include "test_booleans_file.h"
 #include "test_booleans_policy.h"
 
+#include "test_fcontexts_file.h"
+#include "test_fcontexts_policy.h"
+
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
 #include <CUnit/TestDB.h>
@@ -98,6 +101,9 @@ static int do_tests(int interactive, int
 	DECLARE_SUITE(booleans_file);
 	DECLARE_SUITE(booleans_policy);
 
+	DECLARE_SUITE(fcontexts_file);
+	DECLARE_SUITE(fcontexts_policy);
+
 	/* The ps_api_disconnect test 'unforks'. */
 	DECLARE_SUITE(ps_api_disconnect);
 
libsemanage/tests/test_fcontexts_file.c new file +531 -0

531 lines not on this page · raw message

libsemanage/tests/test_fcontexts_file.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_fcontexts_file.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_FCONTEXTS_FILE_H__
+#define __TEST_FCONTEXTS_FILE_H__
+
+#include <CUnit/Basic.h>
+
+int fcontexts_file_test_init(void);
+int fcontexts_file_test_cleanup(void);
+int fcontexts_file_add_tests(CU_pSuite suite);
+
+void test_semanage_fcontext_serialize_local(void);
+
+#endif
libsemanage/tests/test_fcontexts_policy.c new file +394 -0

394 lines not on this page · raw message

libsemanage/tests/test_fcontexts_policy.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_fcontexts_policy.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_FCONTEXTS_POLICY_H__
+#define __TEST_FCONTEXTS_POLICY_H__
+
+#include <CUnit/Basic.h>
+
+int fcontexts_policy_test_init(void);
+int fcontexts_policy_test_cleanup(void);
+int fcontexts_policy_add_tests(CU_pSuite suite);
+
+void test_semanage_fcontext_serialize_policy(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#50 lore raw

PATCH 29/33 libsemanage: interface serialization tests

In reply to [email protected]
---
 libsemanage/tests/libsemanage-tests.c      |    6 
 libsemanage/tests/test_interfaces_file.c   |  548 +++++++++++++++++++++++++++++
 libsemanage/tests/test_interfaces_file.h   |   32 +
 libsemanage/tests/test_interfaces_policy.c |  403 +++++++++++++++++++++
 libsemanage/tests/test_interfaces_policy.h |   32 +
 5 files changed, 1021 insertions(+)
libsemanage/tests/libsemanage-tests.c +6 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -42,6 +42,9 @@
 #include "test_fcontexts_file.h"
 #include "test_fcontexts_policy.h"
 
+#include "test_interfaces_file.h"
+#include "test_interfaces_policy.h"
+
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
 #include <CUnit/TestDB.h>
@@ -104,6 +107,9 @@ static int do_tests(int interactive, int
 	DECLARE_SUITE(fcontexts_file);
 	DECLARE_SUITE(fcontexts_policy);
 
+	DECLARE_SUITE(interfaces_file);
+	DECLARE_SUITE(interfaces_policy);
+
 	/* The ps_api_disconnect test 'unforks'. */
 	DECLARE_SUITE(ps_api_disconnect);
 
libsemanage/tests/test_interfaces_file.c new file +548 -0

548 lines not on this page · raw message

libsemanage/tests/test_interfaces_file.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_interfaces_file.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_INTERFACES_FILE_H__
+#define __TEST_INTERFACES_FILE_H__
+
+#include <CUnit/Basic.h>
+
+int interfaces_file_test_init(void);
+int interfaces_file_test_cleanup(void);
+int interfaces_file_add_tests(CU_pSuite suite);
+
+void test_semanage_iface_serialize_local(void);
+
+#endif
libsemanage/tests/test_interfaces_policy.c new file +403 -0

403 lines not on this page · raw message

libsemanage/tests/test_interfaces_policy.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_interfaces_policy.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_INTERFACES_POLICY_H__
+#define __TEST_INTERFACES_POLICY_H__
+
+#include <CUnit/Basic.h>
+
+int interfaces_policy_test_init(void);
+int interfaces_policy_test_cleanup(void);
+int interfaces_policy_add_tests(CU_pSuite suite);
+
+void test_semanage_iface_serialize_policy(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#51 lore raw

PATCH 30/33 libsemanage: node serialization tests

In reply to [email protected]
---
 libsemanage/tests/libsemanage-tests.c |    6 
 libsemanage/tests/test_nodes_file.c   |  529 ++++++++++++++++++++++++++++++++++
 libsemanage/tests/test_nodes_file.h   |   32 ++
 libsemanage/tests/test_nodes_policy.c |  392 +++++++++++++++++++++++++
 libsemanage/tests/test_nodes_policy.h |   32 ++
 5 files changed, 991 insertions(+)
libsemanage/tests/libsemanage-tests.c +6 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -45,6 +45,9 @@
 #include "test_interfaces_file.h"
 #include "test_interfaces_policy.h"
 
+#include "test_nodes_file.h"
+#include "test_nodes_policy.h"
+
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
 #include <CUnit/TestDB.h>
@@ -110,6 +113,9 @@ static int do_tests(int interactive, int
 	DECLARE_SUITE(interfaces_file);
 	DECLARE_SUITE(interfaces_policy);
 
+	DECLARE_SUITE(nodes_file);
+	DECLARE_SUITE(nodes_policy);
+
 	/* The ps_api_disconnect test 'unforks'. */
 	DECLARE_SUITE(ps_api_disconnect);
 
libsemanage/tests/test_nodes_file.c new file +529 -0

529 lines not on this page · raw message

libsemanage/tests/test_nodes_file.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_nodes_file.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_NODES_FILE_H__
+#define __TEST_NODES_FILE_H__
+
+#include <CUnit/Basic.h>
+
+int nodes_file_test_init(void);
+int nodes_file_test_cleanup(void);
+int nodes_file_add_tests(CU_pSuite suite);
+
+void test_semanage_node_serialize_local(void);
+
+#endif
libsemanage/tests/test_nodes_policy.c new file +392 -0

392 lines not on this page · raw message

libsemanage/tests/test_nodes_policy.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_nodes_policy.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_NODES_POLICY_H__
+#define __TEST_NODES_POLICY_H__
+
+#include <CUnit/Basic.h>
+
+int nodes_policy_test_init(void);
+int nodes_policy_test_cleanup(void);
+int nodes_policy_add_tests(CU_pSuite suite);
+
+void test_semanage_node_serialize_policy(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#52 lore raw

PATCH 31/33 libsemanage: port serialization tests

In reply to [email protected]
---
 libsemanage/tests/libsemanage-tests.c |    6 
 libsemanage/tests/test_ports_file.c   |  516 ++++++++++++++++++++++++++++++++++
 libsemanage/tests/test_ports_file.h   |   32 ++
 libsemanage/tests/test_ports_policy.c |  384 +++++++++++++++++++++++++
 libsemanage/tests/test_ports_policy.h |   32 ++
 5 files changed, 970 insertions(+)
libsemanage/tests/libsemanage-tests.c +6 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -48,6 +48,9 @@
 #include "test_nodes_file.h"
 #include "test_nodes_policy.h"
 
+#include "test_ports_file.h"
+#include "test_ports_policy.h"
+
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
 #include <CUnit/TestDB.h>
@@ -116,6 +119,9 @@ static int do_tests(int interactive, int
 	DECLARE_SUITE(nodes_file);
 	DECLARE_SUITE(nodes_policy);
 
+	DECLARE_SUITE(ports_file);
+	DECLARE_SUITE(ports_policy);
+
 	/* The ps_api_disconnect test 'unforks'. */
 	DECLARE_SUITE(ps_api_disconnect);
 
libsemanage/tests/test_ports_file.c new file +516 -0

516 lines not on this page · raw message

libsemanage/tests/test_ports_file.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_ports_file.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_PORTS_FILE_H__
+#define __TEST_PORTS_FILE_H__
+
+#include <CUnit/Basic.h>
+
+int ports_file_test_init(void);
+int ports_file_test_cleanup(void);
+int ports_file_add_tests(CU_pSuite suite);
+
+void test_semanage_port_serialize_local(void);
+
+#endif
libsemanage/tests/test_ports_policy.c new file +384 -0

384 lines not on this page · raw message

libsemanage/tests/test_ports_policy.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_ports_policy.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_PORTS_POLICY_H__
+#define __TEST_PORTS_POLICY_H__
+
+#include <CUnit/Basic.h>
+
+int ports_policy_test_init(void);
+int ports_policy_test_cleanup(void);
+int ports_policy_add_tests(CU_pSuite suite);
+
+void test_semanage_port_serialize_policy(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#53 lore raw

PATCH 32/33 libsemanage: seuser serialization tests

In reply to [email protected]
---
 libsemanage/tests/libsemanage-tests.c   |    6 
 libsemanage/tests/test_seusers_file.c   |  456 ++++++++++++++++++++++++++++++++
 libsemanage/tests/test_seusers_file.h   |   32 ++
 libsemanage/tests/test_seusers_policy.c |  354 ++++++++++++++++++++++++
 libsemanage/tests/test_seusers_policy.h |   32 ++
 5 files changed, 880 insertions(+)
libsemanage/tests/libsemanage-tests.c +6 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -51,6 +51,9 @@
 #include "test_ports_file.h"
 #include "test_ports_policy.h"
 
+#include "test_seusers_file.h"
+#include "test_seusers_policy.h"
+
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
 #include <CUnit/TestDB.h>
@@ -122,6 +125,9 @@ static int do_tests(int interactive, int
 	DECLARE_SUITE(ports_file);
 	DECLARE_SUITE(ports_policy);
 
+	DECLARE_SUITE(seusers_file);
+	DECLARE_SUITE(seusers_policy);
+
 	/* The ps_api_disconnect test 'unforks'. */
 	DECLARE_SUITE(ps_api_disconnect);
 
libsemanage/tests/test_seusers_file.c new file +456 -0

456 lines not on this page · raw message

libsemanage/tests/test_seusers_file.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_seusers_file.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_SEUSERS_FILE_H__
+#define __TEST_SEUSERS_FILE_H__
+
+#include <CUnit/Basic.h>
+
+int seusers_file_test_init(void);
+int seusers_file_test_cleanup(void);
+int seusers_file_add_tests(CU_pSuite suite);
+
+void test_semanage_seuser_serialize_local(void);
+
+#endif
libsemanage/tests/test_seusers_policy.c new file +354 -0

354 lines not on this page · raw message

libsemanage/tests/test_seusers_policy.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_seusers_policy.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_SEUSERS_POLICY_H__
+#define __TEST_SEUSERS_POLICY_H__
+
+#include <CUnit/Basic.h>
+
+int seusers_policy_test_init(void);
+int seusers_policy_test_cleanup(void);
+int seusers_policy_add_tests(CU_pSuite suite);
+
+void test_semanage_seuser_serialize_policy(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#54 lore raw

PATCH 33/33 libsemanage: user serialization tests

In reply to [email protected]
---
 libsemanage/tests/libsemanage-tests.c |    6 
 libsemanage/tests/test_users_file.c   |  534 ++++++++++++++++++++++++++++++++++
 libsemanage/tests/test_users_file.h   |   32 ++
 libsemanage/tests/test_users_policy.c |  391 ++++++++++++++++++++++++
 libsemanage/tests/test_users_policy.h |   32 ++
 5 files changed, 995 insertions(+)
libsemanage/tests/libsemanage-tests.c +6 -0
Index: selinux-pms-support/libsemanage/tests/libsemanage-tests.c
===================================================================
@@ -54,6 +54,9 @@
 #include "test_seusers_file.h"
 #include "test_seusers_policy.h"
 
+#include "test_users_file.h"
+#include "test_users_policy.h"
+
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
 #include <CUnit/TestDB.h>
@@ -128,6 +131,9 @@ static int do_tests(int interactive, int
 	DECLARE_SUITE(seusers_file);
 	DECLARE_SUITE(seusers_policy);
 
+	DECLARE_SUITE(users_file);
+	DECLARE_SUITE(users_policy);
+
 	/* The ps_api_disconnect test 'unforks'. */
 	DECLARE_SUITE(ps_api_disconnect);
 
libsemanage/tests/test_users_file.c new file +534 -0

534 lines not on this page · raw message

libsemanage/tests/test_users_file.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_users_file.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_USERS_FILE_H__
+#define __TEST_USERS_FILE_H__
+
+#include <CUnit/Basic.h>
+
+int users_file_test_init(void);
+int users_file_test_cleanup(void);
+int users_file_add_tests(CU_pSuite suite);
+
+void test_semanage_user_serialize_local(void);
+
+#endif
libsemanage/tests/test_users_policy.c new file +391 -0

391 lines not on this page · raw message

libsemanage/tests/test_users_policy.h new file +32 -0
Index: selinux-pms-support/libsemanage/tests/test_users_policy.h
===================================================================
@@ -0,0 +1,32 @@
+/* Authors: Christopher Ashworth <[email protected]>
+ *          Caleb Case <[email protected]>
+ *
+ * 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 __TEST_USERS_POLICY_H__
+#define __TEST_USERS_POLICY_H__
+
+#include <CUnit/Basic.h>
+
+int users_policy_test_init(void);
+int users_policy_test_cleanup(void);
+int users_policy_add_tests(CU_pSuite suite);
+
+void test_semanage_user_serialize_policy(void);
+
+#endif
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#55 lore raw
In reply to [email protected]
Quoted 8 lines · [email protected] wrote:

This is the majority of the patches from the policy server release a few months ago. This implements object serialization to send objects (eg., booleans, file contexts, etc) across the line to the policy server. It also implements the line protocol to connect to the policy server and the backend for libsemanage so that semodule, semanage, etc will talk to a policy server instead of doing local operations.

The object serialization will also be necessary for the policy representation branch as we will use this infrastructure to serialize the policy tree for module reading and writing.

The only part left for the policy server is the hooks that were implemented in the expander. As the policy representation work is going on and should remove the expander entirely these patches will have to wait until we have enough of the new representation work to implement them there.

This is obviously meant only for trunk and the policyrep branch.

I accidently sent this with a timestamp of 5:35 yesterday (vm loses time, oops). So if it fell off the bottom of your mail list and you are interested in the patches please check them out :)

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#56 lore raw
In reply to [email protected]
Quoted 7 lines · On Mon, 2007-04-23 at 17:34 -0400, [email protected] wrote:

This is the majority of the patches from the policy server release a few months ago. This implements object serialization to send objects (eg., booleans, file contexts, etc) across the line to the policy server. It also implements the line protocol to connect to the policy server and the backend for libsemanage so that semodule, semanage, etc will talk to a policy server instead of doing local operations.

The object serialization will also be necessary for the policy representation branch as we will use this infrastructure to serialize the policy tree for module reading and writing.

The only part left for the policy server is the hooks that were implemented in the expander. As the policy representation work is going on and should remove the expander entirely these patches will have to wait until we have enough of the new representation work to implement them there.

This is obviously meant only for trunk and the policyrep branch.

Karl asked me to have a look at this, and I haven't looked at all of
it ... but what I have seen worries me a bit.

[patch 22/33]

status = semanage_unserialize(handle, data, size, (void **)&temp_size,
NULL, SEMANAGE_SERIAL_UINT32_T);

This has the same problem I told Karl about, (foo **) doesn't convert
to (void **) in std. C.

[patch 24/33]
int read_n(semanage_handle_t *sh, int socket_fd, int timeout, char *buf, size_t n)
int flush_n(semanage_handle_t *sh, int socket_fd, int timeout, uint64_t
n)

Test the result of time() directly against (time_t)-1. select only easily handles fds upto FD_SETSIZE.
timeout parameter is "interesting" in that it can take upto (timeout *
2) easily, and even (n*timeout) seconds for the worst case. timeout == 0, means you spin on read() with an O_NONBLOCK fd. If you get read() == 0, Ie. EOF, you spin until the timeout expires.

int read_msg(semanage_handle_t *sh, int socket_fd, int timeout, uint32_t
* message_type,
uint64_t * data_length, char **data)

Having the parameters be: (len, buf) when read is (buf, len) is a bad
idea, IMO.

int write_msg(semanage_handle_t *sh, int socket_fd, uint32_t message_type,
uint64_t data_length, char *data)

This doesn't handle EINTR, assumes that writting the msg_header will
happen atomically (and won't get EAGAIN etc.).
Also the use of O_NONBLOCK and a while loop on write are not a good
combination.

int read_server(semanage_handle_t *sh, int socket_fd, uint32_t * message_type,
uint64_t * data_length, char **data)

WTF is the server sending that you can arbitrarily ignore it????

if (write_msg(handle, fd, PS_PUT_DATABASE, data_length, data)) if (read_server(handle, fd, &message_type, &data_length, &data))

[patch 25/33]
+static int dbase_ps_flush(semanage_handle_t * handle, dbase_config_t * dconfig)
{

[...]

       /* Clean up. */
       free(data);

       return STATUS_SUCCESS;

      err:
       ERR(handle, "could not flush database to policy server");
       free(data);
       free(type);
       free(records);
       return STATUS_ERR;
}

records/type is leaked on the normal path.

static int dbase_ps_cache(semanage_handle_t * handle, dbase_config_t * dconfig)
{
[...]
if (semanage_dbase_ps_database_type_serialize(handle,
dbase->database_type, &data, &data_length) != STATUS_SUCCESS)

		goto err;

	if (write_msg(handle, fd, PS_GET_DATABASE, data_length, data))
		goto err;

	data = NULL;
	data_length = 0;

This leaks data.

int semanage_ps_begintrans(semanage_handle_t * sh)

{
       uint32_t response_type = 0;
       uint64_t response_length = 0;
       char *response = NULL;

       err = write_msg(sh, fd, PS_BEGIN_TRANSACTION, 0, NULL);
       err = read_server(sh, fd, &response_type, &response_length,

&response);
}

/*
[...]
* The file descriptor will be set to non-blocking mode.
* Return the file descriptor used, -1 if the server could not be
* found, -2 if the server rejected this connection, or -3 for all
* other errors.
*/
int semanage_ps_connect(semanage_handle_t * sh)

Overloading the fd value in this way is pretty hacky.
Also is_connected is set to 1 early in this function, and isn't reset
to 0 on failures.

int semanage_ps_disconnect(semanage_handle_t * sh) {
[...]

       err = close(sh->u.ps_handle.socket_fd);
       sh->u.ps_handle.socket_fd = err;
       return err;
}

Setting socket_fd to 0, on success, is probably a really bad idea. This also doesn't reset is_connected to 0.

int semanage_ps_list_modules(semanage_handle_t * sh,
semanage_module_info_t ** modules, int
*num_mods)

This uses C99 variable declarations, is that intentional?

semanage_ps_begintrans
semanage_ps_install_base_module
semanage_ps_install_module
semanage_ps_remove_module
semanage_ps_upgrade_module

Are all basically the same function. And there are a few more which
also C&P this function with a bit added on the end.

static int connect_remote(semanage_handle_t * sh)

Probably at least need a comment that this is IPv4 only, and uses
gethostbyname().
The return value from inet_ntop() isn't checked.

Signature · 4 lines
James Antill - <[email protected]>
setsockopt(fd, IPPROTO_TCP, TCP_CONGESTION, ...);
setsockopt(fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, ...);
setsockopt(fd, SOL_SOCKET,  SO_ATTACH_FILTER, ...);
#57 lore raw
Quoted 11 lines · James Antill
Quoted 7 lines · On Mon, 2007-04-23 at 17:34 -0400, [email protected] wrote:

This is the majority of the patches from the policy server release a few months ago. This implements object serialization to send objects (eg., booleans, file contexts, etc) across the line to the policy server. It also implements the line protocol to connect to the policy server and the backend for libsemanage so that semodule, semanage, etc will talk to a policy server instead of doing local operations.

The object serialization will also be necessary for the policy representation branch as we will use this infrastructure to serialize the policy tree for module reading and writing.

The only part left for the policy server is the hooks that were implemented in the expander. As the policy representation work is going on and should remove the expander entirely these patches will have to wait until we have enough of the new representation work to implement them there.

This is obviously meant only for trunk and the policyrep branch.

Karl asked me to have a look at this, and I haven't looked at all of
it ... but what I have seen worries me a bit.

Here's the first parts:

[patch 01]

int sepol_serialize(sepol_handle_t * handle,
const void *datum,
size_t datum_length,
unsigned int datum_type, char **data, uint64_t * size)

This is better fixed by Karl's suggestion of not having a single function, but having datum_length which is ignored for SEPOL_SERIAL_INT32_T etc. is confusing.

The serialization for SEPOL_SERIAL_STRING:
Why are you using snprintf()?
You are moving datum_length into status (size_t into int), which is just asking for pain.

int sepol_unserialize(sepol_handle_t * handle,
char **data, uint64_t * size,
void **datum,
size_t ** datum_length,
unsigned int datum_type)

SEPOL_SERIAL_STRING_ARRAY:

                               /* Datum. */
				*datum =
					calloc(sizeof(char *),
							sizeof(char *) * (**datum_length));

I'm pretty sure you want calloc(sizeof(char *), **datum_length);

[patch 10]

int dbase_serialize(struct semanage_handle *handle,
dbase_config_t * dconfig, char **data, uint64_t * data_length)

size_t can still be 32bits, so storing uint64_t's in it might be bad.
I'm not sure I understand what the completed_count is doing, are you leaking anything if the calloc() fails? I think you want to free upto count all the time.

[patch 12]
semanage_serialize is an exact copy of sepol_serialize, AFAICS, so see above.

[patch 16]

I assume semanage_fcontext_get_con(fcontext) doesn't allocate anything, still it'd be nice to not call it twice and just reuse con.

I worry about having semanage_fcontext_unserialize() leave fcontext allocated on failure. A bunch of code does this with arrays ... but even so.

[patch 21]

Dito. user_extra is left allocated on the failure path, in semanage_user_extra_unserialize. Dito. user is left allocated on the failure path, in semanage_user_unserialize.

[patch 22]

 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;
}

temp_size is allocated on _each call_ to unserialize.

[patch 23]

Why are you calling serialize twice, INT32_T is a fixed size, no?

Signature · 1 line
James Antill <[email protected]>