Skip to contentSkip to conversation

libsemanage: add semanage_handle_create_with_path

PATCH In review Tristan Ross 4 participants 17 messages Apr 11, 2025 – May 6, 2025 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 libsemanage: add semanage_handle_create_with_path

---
 libsemanage/include/semanage/handle.h |  6 +++++-
 libsemanage/src/handle.c              | 26 +++++++++++++++++++-------
 libsemanage/src/libsemanage.map       |  1 +
 3 files changed, 25 insertions(+), 8 deletions(-)
libsemanage/include/semanage/handle.h +5 -1
index a5ea31de..601cd9ee 100644
@@ -30,7 +30,11 @@
 struct semanage_handle;
 typedef struct semanage_handle semanage_handle_t;
 
-/* Create and return a semanage handle.
+/* Create and return a semanage handle with a specific config path.
+   The handle is initially in the disconnected state. */
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name);
+
+/* Create and return a semanage handle with the default config path.
    The handle is initially in the disconnected state. */
 extern semanage_handle_t *semanage_handle_create(void);
 
libsemanage/src/handle.c +19 -7
index faea0606..ca57702a 100644
@@ -59,19 +59,14 @@ const char * semanage_root(void)
 	return private_semanage_root;
 }
 
-
-semanage_handle_t *semanage_handle_create(void)
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name)
 {
 	semanage_handle_t *sh = NULL;
-	char *conf_name = NULL;
 
 	/* Allocate handle */
 	if ((sh = calloc(1, sizeof(semanage_handle_t))) == NULL)
 		goto err;
 
-	if ((conf_name = semanage_conf_path()) == NULL)
-		goto err;
-
 	if ((sh->conf = semanage_conf_parse(conf_name)) == NULL)
 		goto err;
 
@@ -106,13 +101,30 @@ semanage_handle_t *semanage_handle_create(void)
 	sh->msg_callback = semanage_msg_default_handler;
 	sh->msg_callback_arg = NULL;
 
+	return sh;
+
+      err:
+	semanage_handle_destroy(sh);
+	return NULL;
+}
+
+semanage_handle_t *semanage_handle_create(void)
+{
+	semanage_handle_t *sh = NULL;
+	char *conf_name = NULL;
+
+	if ((conf_name = semanage_conf_path()) == NULL)
+		goto err;
+
+	if ((sh = semanage_handle_create_with_path(conf_name)) == NULL)
+		goto err;
+
 	free(conf_name);
 
 	return sh;
 
       err:
 	free(conf_name);
-	semanage_handle_destroy(sh);
 	return NULL;
 }
 
libsemanage/src/libsemanage.map +1 -0
index c8214b26..02c615ac 100644
@@ -347,6 +347,7 @@ LIBSEMANAGE_1.1 {
 } LIBSEMANAGE_1.0;
 
 LIBSEMANAGE_3.4 {
+    semanage_handle_create_with_path;
     semanage_module_compute_checksum;
     semanage_set_check_ext_changes;
 } LIBSEMANAGE_1.1;
Signature · 1 line
2.47.2
#1 lore raw

PATCH 2/2 semodule: add config argument

---
 policycoreutils/semodule/semodule.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
policycoreutils/semodule/semodule.c +16 -5
index ebe062bf..274cdbd9 100644
@@ -145,6 +145,7 @@ static void usage(char *progname)
 	printf("  -v,--verbose     be verbose\n");
 	printf("  -P,--preserve_tunables	Preserve tunables in policy\n");
 	printf("  -C,--ignore-module-cache	Rebuild CIL modules compiled from HLL files\n");
+	printf("  -o,--config=PATH use an alternate path for the semanage config\n");
 	printf("  -p,--path        use an alternate path for the policy root\n");
 	printf("  -S,--store-path  use an alternate path for the policy store root\n");
 	printf("  -c, --cil extract module as cil. This only affects module extraction.\n");
@@ -223,7 +224,7 @@ static void parse_command_line(int argc, char **argv)
 	check_ext_changes = 0;
 	priority = 400;
 	while ((i =
-		getopt_long(argc, argv, "s:b:hi:l::vr:u:RnNBDCPX:e:d:p:S:E:cHm",
+		getopt_long(argc, argv, "s:b:hi:l::vr:u:RnNBDCPX:e:d:p:o:S:E:cHm",
 			    opts, &longind)) != -1) {
 		switch (i) {
 		case '\0':
@@ -304,6 +305,14 @@ static void parse_command_line(int argc, char **argv)
 		case 'C':
 			ignore_module_cache = 1;
 			break;
+		case 'o':
+			sh = semanage_handle_create_with_path(optarg);
+			if (!sh) {
+				fprintf(stderr, "%s:  Could not create semanage handle\n",
+					argv[0]);
+				exit(1);
+			}
+			break;
 		case 'X':
 			set_mode(PRIORITY_M, optarg);
 			break;
@@ -421,11 +430,13 @@ int main(int argc, char *argv[])
 	if (build || check_ext_changes)
 		commit = 1;
 
-	sh = semanage_handle_create();
 	if (!sh) {
-		fprintf(stderr, "%s:  Could not create semanage handle\n",
-			argv[0]);
-		goto cleanup_nohandle;
+		sh = semanage_handle_create();
+		if (!sh) {
+			fprintf(stderr, "%s:  Could not create semanage handle\n",
+				argv[0]);
+			goto cleanup_nohandle;
+		}
 	}
 
 	if (store) {
Signature · 1 line
2.47.2
#2 lore raw
In reply to Tristan Ross
Quoted 86 lines · Tristan Ross
---
 libsemanage/include/semanage/handle.h |  6 +++++-
 libsemanage/src/handle.c              | 26 +++++++++++++++++++-------
 libsemanage/src/libsemanage.map       |  1 +
 3 files changed, 25 insertions(+), 8 deletions(-)
libsemanage/include/semanage/handle.h +5 -1
index a5ea31de..601cd9ee 100644
@@ -30,7 +30,11 @@
 struct semanage_handle;
 typedef struct semanage_handle semanage_handle_t;
 
-/* Create and return a semanage handle.
+/* Create and return a semanage handle with a specific config path.
+   The handle is initially in the disconnected state. */
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name);
+
+/* Create and return a semanage handle with the default config path.
    The handle is initially in the disconnected state. */
 extern semanage_handle_t *semanage_handle_create(void);
 
libsemanage/src/handle.c +19 -7
index faea0606..ca57702a 100644
@@ -59,19 +59,14 @@ const char * semanage_root(void)
        return private_semanage_root;
 }
 
-
-semanage_handle_t *semanage_handle_create(void)
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name)
 {
        semanage_handle_t *sh = NULL;
-       char *conf_name = NULL;
 
        /* Allocate handle */
        if ((sh = calloc(1, sizeof(semanage_handle_t))) == NULL)
                goto err;
 
-       if ((conf_name = semanage_conf_path()) == NULL)
-               goto err;
-
        if ((sh->conf = semanage_conf_parse(conf_name)) == NULL)
                goto err;
 
@@ -106,13 +101,30 @@ semanage_handle_t *semanage_handle_create(void)
        sh->msg_callback = semanage_msg_default_handler;
        sh->msg_callback_arg = NULL;
 
+       return sh;
+
+      err:
+       semanage_handle_destroy(sh);
+       return NULL;
+}
+
+semanage_handle_t *semanage_handle_create(void)
+{
+       semanage_handle_t *sh = NULL;
+       char *conf_name = NULL;
+
+       if ((conf_name = semanage_conf_path()) == NULL)
+               goto err;
+
+       if ((sh = semanage_handle_create_with_path(conf_name)) == NULL)
+               goto err;
+
        free(conf_name);
 
        return sh;
 
       err:
        free(conf_name);
-       semanage_handle_destroy(sh);
        return NULL;
 }
 
libsemanage/src/libsemanage.map +0 -0
index c8214b26..02c615ac 100644

libsemanage/src/libsemanage.map LIBSEMANAGE_1.1 { · line 350

Quoted 4 lines
libsemanage/src/libsemanage.map +1 -0
@@ -347,6 +347,7 @@ LIBSEMANAGE_1.1 {
 } LIBSEMANAGE_1.0;
 
 LIBSEMANAGE_3.4 {
+    semanage_handle_create_with_path;

This should be placed in a new soname section.

Quoted 7 lines
libsemanage/src/libsemanage.map +0 -1
     semanage_module_compute_checksum;
     semanage_set_check_ext_changes;
 } LIBSEMANAGE_1.1;
--

2.47.2

#3 lore raw

PATCH 1/2 libsemanage: add semanage_handle_create_with_path

---
 libsemanage/include/semanage/handle.h |  6 +++++-
 libsemanage/src/handle.c              | 26 +++++++++++++++++++-------
 libsemanage/src/libsemanage.map       |  4 ++++
 3 files changed, 28 insertions(+), 8 deletions(-)
libsemanage/include/semanage/handle.h +5 -1
index a5ea31de..601cd9ee 100644
@@ -30,7 +30,11 @@
 struct semanage_handle;
 typedef struct semanage_handle semanage_handle_t;
 
-/* Create and return a semanage handle.
+/* Create and return a semanage handle with a specific config path.
+   The handle is initially in the disconnected state. */
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name);
+
+/* Create and return a semanage handle with the default config path.
    The handle is initially in the disconnected state. */
 extern semanage_handle_t *semanage_handle_create(void);
 
libsemanage/src/handle.c +19 -7
index faea0606..ca57702a 100644
@@ -59,19 +59,14 @@ const char * semanage_root(void)
 	return private_semanage_root;
 }
 
-
-semanage_handle_t *semanage_handle_create(void)
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name)
 {
 	semanage_handle_t *sh = NULL;
-	char *conf_name = NULL;
 
 	/* Allocate handle */
 	if ((sh = calloc(1, sizeof(semanage_handle_t))) == NULL)
 		goto err;
 
-	if ((conf_name = semanage_conf_path()) == NULL)
-		goto err;
-
 	if ((sh->conf = semanage_conf_parse(conf_name)) == NULL)
 		goto err;
 
@@ -106,13 +101,30 @@ semanage_handle_t *semanage_handle_create(void)
 	sh->msg_callback = semanage_msg_default_handler;
 	sh->msg_callback_arg = NULL;
 
+	return sh;
+
+      err:
+	semanage_handle_destroy(sh);
+	return NULL;
+}
+
+semanage_handle_t *semanage_handle_create(void)
+{
+	semanage_handle_t *sh = NULL;
+	char *conf_name = NULL;
+
+	if ((conf_name = semanage_conf_path()) == NULL)
+		goto err;
+
+	if ((sh = semanage_handle_create_with_path(conf_name)) == NULL)
+		goto err;
+
 	free(conf_name);
 
 	return sh;
 
       err:
 	free(conf_name);
-	semanage_handle_destroy(sh);
 	return NULL;
 }
 
libsemanage/src/libsemanage.map +4 -0
index c8214b26..5dab7bf7 100644
@@ -350,3 +350,7 @@ LIBSEMANAGE_3.4 {
     semanage_module_compute_checksum;
     semanage_set_check_ext_changes;
 } LIBSEMANAGE_1.1;
+
+LIBSEMANAGE_3.5 {
+    semanage_handle_create_with_path;
+} LIBSEMANAGE_3.4;
Signature · 1 line
2.47.2
#4 lore raw
Quoted 1 line · Tristan Ross

Along with a "Signed-off-by" tag, both of these patches need a commit log that describes what they do and why they were created. Thanks,
Jim

Quoted 96 lines
---
 libsemanage/include/semanage/handle.h |  6 +++++-
 libsemanage/src/handle.c              | 26 +++++++++++++++++++-------
 libsemanage/src/libsemanage.map       |  4 ++++
 3 files changed, 28 insertions(+), 8 deletions(-)
libsemanage/include/semanage/handle.h +5 -1
index a5ea31de..601cd9ee 100644
@@ -30,7 +30,11 @@
 struct semanage_handle;
 typedef struct semanage_handle semanage_handle_t;
 
-/* Create and return a semanage handle.
+/* Create and return a semanage handle with a specific config path.
+   The handle is initially in the disconnected state. */
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name);
+
+/* Create and return a semanage handle with the default config path.
    The handle is initially in the disconnected state. */
 extern semanage_handle_t *semanage_handle_create(void);
 
libsemanage/src/handle.c +19 -7
index faea0606..ca57702a 100644
@@ -59,19 +59,14 @@ const char * semanage_root(void)
        return private_semanage_root;
 }
 
-
-semanage_handle_t *semanage_handle_create(void)
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name)
 {
        semanage_handle_t *sh = NULL;
-       char *conf_name = NULL;
 
        /* Allocate handle */
        if ((sh = calloc(1, sizeof(semanage_handle_t))) == NULL)
                goto err;
 
-       if ((conf_name = semanage_conf_path()) == NULL)
-               goto err;
-
        if ((sh->conf = semanage_conf_parse(conf_name)) == NULL)
                goto err;
 
@@ -106,13 +101,30 @@ semanage_handle_t *semanage_handle_create(void)
        sh->msg_callback = semanage_msg_default_handler;
        sh->msg_callback_arg = NULL;
 
+       return sh;
+
+      err:
+       semanage_handle_destroy(sh);
+       return NULL;
+}
+
+semanage_handle_t *semanage_handle_create(void)
+{
+       semanage_handle_t *sh = NULL;
+       char *conf_name = NULL;
+
+       if ((conf_name = semanage_conf_path()) == NULL)
+               goto err;
+
+       if ((sh = semanage_handle_create_with_path(conf_name)) == NULL)
+               goto err;
+
        free(conf_name);
 
        return sh;
 
       err:
        free(conf_name);
-       semanage_handle_destroy(sh);
        return NULL;
 }
 
libsemanage/src/libsemanage.map +4 -1
index c8214b26..5dab7bf7 100644
@@ -350,3 +350,7 @@ LIBSEMANAGE_3.4 {
     semanage_module_compute_checksum;
     semanage_set_check_ext_changes;
 } LIBSEMANAGE_1.1;
+
+LIBSEMANAGE_3.5 {
+    semanage_handle_create_with_path;
+} LIBSEMANAGE_3.4;
--

2.47.2

#5 lore raw
In reply to Tristan Ross
Quoted 86 lines · Tristan Ross
---
 libsemanage/include/semanage/handle.h |  6 +++++-
 libsemanage/src/handle.c              | 26 +++++++++++++++++++-------
 libsemanage/src/libsemanage.map       |  4 ++++
 3 files changed, 28 insertions(+), 8 deletions(-)
libsemanage/include/semanage/handle.h +5 -1
index a5ea31de..601cd9ee 100644
@@ -30,7 +30,11 @@
 struct semanage_handle;
 typedef struct semanage_handle semanage_handle_t;
 
-/* Create and return a semanage handle.
+/* Create and return a semanage handle with a specific config path.
+   The handle is initially in the disconnected state. */
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name);
+
+/* Create and return a semanage handle with the default config path.
    The handle is initially in the disconnected state. */
 extern semanage_handle_t *semanage_handle_create(void);
 
libsemanage/src/handle.c +19 -7
index faea0606..ca57702a 100644
@@ -59,19 +59,14 @@ const char * semanage_root(void)
 	return private_semanage_root;
 }
 
-
-semanage_handle_t *semanage_handle_create(void)
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name)
 {
 	semanage_handle_t *sh = NULL;
-	char *conf_name = NULL;
 
 	/* Allocate handle */
 	if ((sh = calloc(1, sizeof(semanage_handle_t))) == NULL)
 		goto err;
 
-	if ((conf_name = semanage_conf_path()) == NULL)
-		goto err;
-
 	if ((sh->conf = semanage_conf_parse(conf_name)) == NULL)
 		goto err;
 
@@ -106,13 +101,30 @@ semanage_handle_t *semanage_handle_create(void)
 	sh->msg_callback = semanage_msg_default_handler;
 	sh->msg_callback_arg = NULL;
 
+	return sh;
+
+      err:
+	semanage_handle_destroy(sh);
+	return NULL;
+}
+
+semanage_handle_t *semanage_handle_create(void)
+{
+	semanage_handle_t *sh = NULL;
+	char *conf_name = NULL;
+
+	if ((conf_name = semanage_conf_path()) == NULL)
+		goto err;
+
+	if ((sh = semanage_handle_create_with_path(conf_name)) == NULL)
+		goto err;
+
 	free(conf_name);
 
 	return sh;
 
       err:
 	free(conf_name);
-	semanage_handle_destroy(sh);
 	return NULL;
 }
 
libsemanage/src/libsemanage.map +0 -0
index c8214b26..5dab7bf7 100644

libsemanage/src/libsemanage.map LIBSEMANAGE_3.4 { · line 356

Quoted 7 lines
libsemanage/src/libsemanage.map +4 -0
@@ -350,3 +350,7 @@ LIBSEMANAGE_3.4 {
     semanage_module_compute_checksum;
     semanage_set_check_ext_changes;
 } LIBSEMANAGE_1.1;
+
+LIBSEMANAGE_3.5 {
+    semanage_handle_create_with_path;
+} LIBSEMANAGE_3.4;

It will be part of the next 3.9 release therefore this should be

+LIBSEMANAGE_3.9 {
+ semanage_handle_create_with_path;
+} LIBSEMANAGE_3.4;

--

Quoted 1 line

2.47.2

#6 lore raw

PATCH 1/2 libsemanage: add semanage_handle_create_with_path

Adds "semanage_handle_create_with_path" to create an semanage handle with a config file from a specific path. This is useful for baking SELinux policy generation into a Nix derivation.

---
 libsemanage/include/semanage/handle.h |  6 +++++-
 libsemanage/src/handle.c              | 26 +++++++++++++++++++-------
 libsemanage/src/libsemanage.map       |  4 ++++
 3 files changed, 28 insertions(+), 8 deletions(-)
libsemanage/include/semanage/handle.h +5 -1
index a5ea31de..601cd9ee 100644
@@ -30,7 +30,11 @@
 struct semanage_handle;
 typedef struct semanage_handle semanage_handle_t;
 
-/* Create and return a semanage handle.
+/* Create and return a semanage handle with a specific config path.
+   The handle is initially in the disconnected state. */
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name);
+
+/* Create and return a semanage handle with the default config path.
    The handle is initially in the disconnected state. */
 extern semanage_handle_t *semanage_handle_create(void);
 
libsemanage/src/handle.c +19 -7
index faea0606..ca57702a 100644
@@ -59,19 +59,14 @@ const char * semanage_root(void)
 	return private_semanage_root;
 }
 
-
-semanage_handle_t *semanage_handle_create(void)
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name)
 {
 	semanage_handle_t *sh = NULL;
-	char *conf_name = NULL;
 
 	/* Allocate handle */
 	if ((sh = calloc(1, sizeof(semanage_handle_t))) == NULL)
 		goto err;
 
-	if ((conf_name = semanage_conf_path()) == NULL)
-		goto err;
-
 	if ((sh->conf = semanage_conf_parse(conf_name)) == NULL)
 		goto err;
 
@@ -106,13 +101,30 @@ semanage_handle_t *semanage_handle_create(void)
 	sh->msg_callback = semanage_msg_default_handler;
 	sh->msg_callback_arg = NULL;
 
+	return sh;
+
+      err:
+	semanage_handle_destroy(sh);
+	return NULL;
+}
+
+semanage_handle_t *semanage_handle_create(void)
+{
+	semanage_handle_t *sh = NULL;
+	char *conf_name = NULL;
+
+	if ((conf_name = semanage_conf_path()) == NULL)
+		goto err;
+
+	if ((sh = semanage_handle_create_with_path(conf_name)) == NULL)
+		goto err;
+
 	free(conf_name);
 
 	return sh;
 
       err:
 	free(conf_name);
-	semanage_handle_destroy(sh);
 	return NULL;
 }
 
libsemanage/src/libsemanage.map +4 -0
index c8214b26..5dab7bf7 100644
@@ -350,3 +350,7 @@ LIBSEMANAGE_3.4 {
     semanage_module_compute_checksum;
     semanage_set_check_ext_changes;
 } LIBSEMANAGE_1.1;
+
+LIBSEMANAGE_3.5 {
+    semanage_handle_create_with_path;
+} LIBSEMANAGE_3.4;
Signature · 1 line
2.47.2
#7 lore raw

PATCH 2/2 semodule: add config argument

Use "semanage_handle_create_with_path" and implement a new flag for handling semanage config files at specific paths.

---
 policycoreutils/semodule/semodule.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
policycoreutils/semodule/semodule.c +17 -5
index ebe062bf..80fd0451 100644
@@ -145,6 +145,7 @@ static void usage(char *progname)
 	printf("  -v,--verbose     be verbose\n");
 	printf("  -P,--preserve_tunables	Preserve tunables in policy\n");
 	printf("  -C,--ignore-module-cache	Rebuild CIL modules compiled from HLL files\n");
+	printf("  -o,--config=PATH use an alternate path for the semanage config\n");
 	printf("  -p,--path        use an alternate path for the policy root\n");
 	printf("  -S,--store-path  use an alternate path for the policy store root\n");
 	printf("  -c, --cil extract module as cil. This only affects module extraction.\n");
@@ -210,6 +211,7 @@ static void parse_command_line(int argc, char **argv)
 		{"enable", required_argument, NULL, 'e'},
 		{"disable", required_argument, NULL, 'd'},
 		{"path", required_argument, NULL, 'p'},
+		{"config", required_argument, NULL, 'o'},
 		{"store-path", required_argument, NULL, 'S'},
 		{"checksum", 0, NULL, 'm'},
 		{NULL, 0, NULL, 0}
@@ -223,7 +225,7 @@ static void parse_command_line(int argc, char **argv)
 	check_ext_changes = 0;
 	priority = 400;
 	while ((i =
-		getopt_long(argc, argv, "s:b:hi:l::vr:u:RnNBDCPX:e:d:p:S:E:cHm",
+		getopt_long(argc, argv, "s:b:hi:l::vr:u:RnNBDCPX:e:d:p:o:S:E:cHm",
 			    opts, &longind)) != -1) {
 		switch (i) {
 		case '\0':
@@ -304,6 +306,14 @@ static void parse_command_line(int argc, char **argv)
 		case 'C':
 			ignore_module_cache = 1;
 			break;
+		case 'o':
+			sh = semanage_handle_create_with_path(optarg);
+			if (!sh) {
+				fprintf(stderr, "%s:  Could not create semanage handle\n",
+					argv[0]);
+				exit(1);
+			}
+			break;
 		case 'X':
 			set_mode(PRIORITY_M, optarg);
 			break;
@@ -421,11 +431,13 @@ int main(int argc, char *argv[])
 	if (build || check_ext_changes)
 		commit = 1;
 
-	sh = semanage_handle_create();
 	if (!sh) {
-		fprintf(stderr, "%s:  Could not create semanage handle\n",
-			argv[0]);
-		goto cleanup_nohandle;
+		sh = semanage_handle_create();
+		if (!sh) {
+			fprintf(stderr, "%s:  Could not create semanage handle\n",
+				argv[0]);
+			goto cleanup_nohandle;
+		}
 	}
 
 	if (store) {
Signature · 1 line
2.47.2
#8 lore raw

PATCH 1/2 libsemanage: add semanage_handle_create_with_path

In reply to Petr Lautrbach

Adds "semanage_handle_create_with_path" to create an semanage handle with a config file from a specific path. This is useful for baking SELinux policy generation into a Nix derivation.

---
 libsemanage/include/semanage/handle.h |  6 +++++-
 libsemanage/src/handle.c              | 26 +++++++++++++++++++-------
 libsemanage/src/libsemanage.map       |  4 ++++
 3 files changed, 28 insertions(+), 8 deletions(-)
libsemanage/include/semanage/handle.h +5 -1
index a5ea31de..601cd9ee 100644
@@ -30,7 +30,11 @@
 struct semanage_handle;
 typedef struct semanage_handle semanage_handle_t;
 
-/* Create and return a semanage handle.
+/* Create and return a semanage handle with a specific config path.
+   The handle is initially in the disconnected state. */
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name);
+
+/* Create and return a semanage handle with the default config path.
    The handle is initially in the disconnected state. */
 extern semanage_handle_t *semanage_handle_create(void);
 
libsemanage/src/handle.c +19 -7
index faea0606..ca57702a 100644
@@ -59,19 +59,14 @@ const char * semanage_root(void)
 	return private_semanage_root;
 }
 
-
-semanage_handle_t *semanage_handle_create(void)
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name)
 {
 	semanage_handle_t *sh = NULL;
-	char *conf_name = NULL;
 
 	/* Allocate handle */
 	if ((sh = calloc(1, sizeof(semanage_handle_t))) == NULL)
 		goto err;
 
-	if ((conf_name = semanage_conf_path()) == NULL)
-		goto err;
-
 	if ((sh->conf = semanage_conf_parse(conf_name)) == NULL)
 		goto err;
 
@@ -106,13 +101,30 @@ semanage_handle_t *semanage_handle_create(void)
 	sh->msg_callback = semanage_msg_default_handler;
 	sh->msg_callback_arg = NULL;
 
+	return sh;
+
+      err:
+	semanage_handle_destroy(sh);
+	return NULL;
+}
+
+semanage_handle_t *semanage_handle_create(void)
+{
+	semanage_handle_t *sh = NULL;
+	char *conf_name = NULL;
+
+	if ((conf_name = semanage_conf_path()) == NULL)
+		goto err;
+
+	if ((sh = semanage_handle_create_with_path(conf_name)) == NULL)
+		goto err;
+
 	free(conf_name);
 
 	return sh;
 
       err:
 	free(conf_name);
-	semanage_handle_destroy(sh);
 	return NULL;
 }
 
libsemanage/src/libsemanage.map +4 -0
index c8214b26..8d7d8b05 100644
@@ -350,3 +350,7 @@ LIBSEMANAGE_3.4 {
     semanage_module_compute_checksum;
     semanage_set_check_ext_changes;
 } LIBSEMANAGE_1.1;
+
+LIBSEMANAGE_3.9 {
+    semanage_handle_create_with_path;
+} LIBSEMANAGE_3.4;
Signature · 1 line
2.47.2
#9 lore raw

PATCH 2/2 semodule: add config argument

Use "semanage_handle_create_with_path" and implement a new flag for handling semanage config files at specific paths.

---
 policycoreutils/semodule/semodule.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
policycoreutils/semodule/semodule.c +17 -5
index ebe062bf..80fd0451 100644
@@ -145,6 +145,7 @@ static void usage(char *progname)
 	printf("  -v,--verbose     be verbose\n");
 	printf("  -P,--preserve_tunables	Preserve tunables in policy\n");
 	printf("  -C,--ignore-module-cache	Rebuild CIL modules compiled from HLL files\n");
+	printf("  -o,--config=PATH use an alternate path for the semanage config\n");
 	printf("  -p,--path        use an alternate path for the policy root\n");
 	printf("  -S,--store-path  use an alternate path for the policy store root\n");
 	printf("  -c, --cil extract module as cil. This only affects module extraction.\n");
@@ -210,6 +211,7 @@ static void parse_command_line(int argc, char **argv)
 		{"enable", required_argument, NULL, 'e'},
 		{"disable", required_argument, NULL, 'd'},
 		{"path", required_argument, NULL, 'p'},
+		{"config", required_argument, NULL, 'o'},
 		{"store-path", required_argument, NULL, 'S'},
 		{"checksum", 0, NULL, 'm'},
 		{NULL, 0, NULL, 0}
@@ -223,7 +225,7 @@ static void parse_command_line(int argc, char **argv)
 	check_ext_changes = 0;
 	priority = 400;
 	while ((i =
-		getopt_long(argc, argv, "s:b:hi:l::vr:u:RnNBDCPX:e:d:p:S:E:cHm",
+		getopt_long(argc, argv, "s:b:hi:l::vr:u:RnNBDCPX:e:d:p:o:S:E:cHm",
 			    opts, &longind)) != -1) {
 		switch (i) {
 		case '\0':
@@ -304,6 +306,14 @@ static void parse_command_line(int argc, char **argv)
 		case 'C':
 			ignore_module_cache = 1;
 			break;
+		case 'o':
+			sh = semanage_handle_create_with_path(optarg);
+			if (!sh) {
+				fprintf(stderr, "%s:  Could not create semanage handle\n",
+					argv[0]);
+				exit(1);
+			}
+			break;
 		case 'X':
 			set_mode(PRIORITY_M, optarg);
 			break;
@@ -421,11 +431,13 @@ int main(int argc, char *argv[])
 	if (build || check_ext_changes)
 		commit = 1;
 
-	sh = semanage_handle_create();
 	if (!sh) {
-		fprintf(stderr, "%s:  Could not create semanage handle\n",
-			argv[0]);
-		goto cleanup_nohandle;
+		sh = semanage_handle_create();
+		if (!sh) {
+			fprintf(stderr, "%s:  Could not create semanage handle\n",
+				argv[0]);
+			goto cleanup_nohandle;
+		}
 	}
 
 	if (store) {
Signature · 1 line
2.47.2
#10 lore raw

Re: [PATCH 2/2] semodule: add config argument

Quoted 14 lines · Tristan Ross

Use "semanage_handle_create_with_path" and implement a new flag for handling semanage config files at specific paths.

---
 policycoreutils/semodule/semodule.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
policycoreutils/semodule/semodule.c +0 -0
index ebe062bf..80fd0451 100644

policycoreutils/semodule/semodule.c static void usage(char *progname) · line 148

Quoted 4 lines
policycoreutils/semodule/semodule.c +1 -0
@@ -145,6 +145,7 @@ static void usage(char *progname)
        printf("  -v,--verbose     be verbose\n");
        printf("  -P,--preserve_tunables        Preserve tunables in policy\n");
        printf("  -C,--ignore-module-cache      Rebuild CIL modules compiled from HLL files\n");
+       printf("  -o,--config=PATH use an alternate path for the semanage config\n");

I know that all of the obvious letters have already been used, but I really don't want to use "o" for this.
I think I would prefer "g" to be used.

Also, the man page needs to be updated as well.

Functionally, everything looks good to me.

Thanks,
Jim

Quoted 57 lines
policycoreutils/semodule/semodule.c +16 -6
        printf("  -p,--path        use an alternate path for the policy root\n");
        printf("  -S,--store-path  use an alternate path for the policy store root\n");
        printf("  -c, --cil extract module as cil. This only affects module extraction.\n");
@@ -210,6 +211,7 @@ static void parse_command_line(int argc, char **argv)
                {"enable", required_argument, NULL, 'e'},
                {"disable", required_argument, NULL, 'd'},
                {"path", required_argument, NULL, 'p'},
+               {"config", required_argument, NULL, 'o'},
                {"store-path", required_argument, NULL, 'S'},
                {"checksum", 0, NULL, 'm'},
                {NULL, 0, NULL, 0}
@@ -223,7 +225,7 @@ static void parse_command_line(int argc, char **argv)
        check_ext_changes = 0;
        priority = 400;
        while ((i =
-               getopt_long(argc, argv, "s:b:hi:l::vr:u:RnNBDCPX:e:d:p:S:E:cHm",
+               getopt_long(argc, argv, "s:b:hi:l::vr:u:RnNBDCPX:e:d:p:o:S:E:cHm",
                            opts, &longind)) != -1) {
                switch (i) {
                case '\0':
@@ -304,6 +306,14 @@ static void parse_command_line(int argc, char **argv)
                case 'C':
                        ignore_module_cache = 1;
                        break;
+               case 'o':
+                       sh = semanage_handle_create_with_path(optarg);
+                       if (!sh) {
+                               fprintf(stderr, "%s:  Could not create semanage handle\n",
+                                       argv[0]);
+                               exit(1);
+                       }
+                       break;
                case 'X':
                        set_mode(PRIORITY_M, optarg);
                        break;
@@ -421,11 +431,13 @@ int main(int argc, char *argv[])
        if (build || check_ext_changes)
                commit = 1;
 
-       sh = semanage_handle_create();
        if (!sh) {
-               fprintf(stderr, "%s:  Could not create semanage handle\n",
-                       argv[0]);
-               goto cleanup_nohandle;
+               sh = semanage_handle_create();
+               if (!sh) {
+                       fprintf(stderr, "%s:  Could not create semanage handle\n",
+                               argv[0]);
+                       goto cleanup_nohandle;
+               }
        }
 
        if (store) {
--

2.47.2

#11 lore raw

PATCH 1/2 libsemanage: add semanage_handle_create_with_path

Adds "semanage_handle_create_with_path" to create an semanage handle with a config file from a specific path. This is useful for baking SELinux policy generation into a Nix derivation.

---
 libsemanage/include/semanage/handle.h |  6 +++++-
 libsemanage/src/handle.c              | 26 +++++++++++++++++++-------
 libsemanage/src/libsemanage.map       |  4 ++++
 3 files changed, 28 insertions(+), 8 deletions(-)
libsemanage/include/semanage/handle.h +5 -1
index a5ea31de..601cd9ee 100644
@@ -30,7 +30,11 @@
 struct semanage_handle;
 typedef struct semanage_handle semanage_handle_t;
 
-/* Create and return a semanage handle.
+/* Create and return a semanage handle with a specific config path.
+   The handle is initially in the disconnected state. */
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name);
+
+/* Create and return a semanage handle with the default config path.
    The handle is initially in the disconnected state. */
 extern semanage_handle_t *semanage_handle_create(void);
 
libsemanage/src/handle.c +19 -7
index faea0606..ca57702a 100644
@@ -59,19 +59,14 @@ const char * semanage_root(void)
 	return private_semanage_root;
 }
 
-
-semanage_handle_t *semanage_handle_create(void)
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name)
 {
 	semanage_handle_t *sh = NULL;
-	char *conf_name = NULL;
 
 	/* Allocate handle */
 	if ((sh = calloc(1, sizeof(semanage_handle_t))) == NULL)
 		goto err;
 
-	if ((conf_name = semanage_conf_path()) == NULL)
-		goto err;
-
 	if ((sh->conf = semanage_conf_parse(conf_name)) == NULL)
 		goto err;
 
@@ -106,13 +101,30 @@ semanage_handle_t *semanage_handle_create(void)
 	sh->msg_callback = semanage_msg_default_handler;
 	sh->msg_callback_arg = NULL;
 
+	return sh;
+
+      err:
+	semanage_handle_destroy(sh);
+	return NULL;
+}
+
+semanage_handle_t *semanage_handle_create(void)
+{
+	semanage_handle_t *sh = NULL;
+	char *conf_name = NULL;
+
+	if ((conf_name = semanage_conf_path()) == NULL)
+		goto err;
+
+	if ((sh = semanage_handle_create_with_path(conf_name)) == NULL)
+		goto err;
+
 	free(conf_name);
 
 	return sh;
 
       err:
 	free(conf_name);
-	semanage_handle_destroy(sh);
 	return NULL;
 }
 
libsemanage/src/libsemanage.map +4 -0
index c8214b26..8d7d8b05 100644
@@ -350,3 +350,7 @@ LIBSEMANAGE_3.4 {
     semanage_module_compute_checksum;
     semanage_set_check_ext_changes;
 } LIBSEMANAGE_1.1;
+
+LIBSEMANAGE_3.9 {
+    semanage_handle_create_with_path;
+} LIBSEMANAGE_3.4;
Signature · 1 line
2.47.2
#12 lore raw

PATCH 2/2 semodule: add config argument

Use "semanage_handle_create_with_path" and implement a new flag for handling semanage config files at specific paths.

---
 policycoreutils/semodule/semodule.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
policycoreutils/semodule/semodule.c +17 -5
index ebe062bf..ab5168eb 100644
@@ -145,6 +145,7 @@ static void usage(char *progname)
 	printf("  -v,--verbose     be verbose\n");
 	printf("  -P,--preserve_tunables	Preserve tunables in policy\n");
 	printf("  -C,--ignore-module-cache	Rebuild CIL modules compiled from HLL files\n");
+	printf("  -g,--config=PATH use an alternate path for the semanage config\n");
 	printf("  -p,--path        use an alternate path for the policy root\n");
 	printf("  -S,--store-path  use an alternate path for the policy store root\n");
 	printf("  -c, --cil extract module as cil. This only affects module extraction.\n");
@@ -210,6 +211,7 @@ static void parse_command_line(int argc, char **argv)
 		{"enable", required_argument, NULL, 'e'},
 		{"disable", required_argument, NULL, 'd'},
 		{"path", required_argument, NULL, 'p'},
+		{"config", required_argument, NULL, 'g'},
 		{"store-path", required_argument, NULL, 'S'},
 		{"checksum", 0, NULL, 'm'},
 		{NULL, 0, NULL, 0}
@@ -223,7 +225,7 @@ static void parse_command_line(int argc, char **argv)
 	check_ext_changes = 0;
 	priority = 400;
 	while ((i =
-		getopt_long(argc, argv, "s:b:hi:l::vr:u:RnNBDCPX:e:d:p:S:E:cHm",
+		getopt_long(argc, argv, "s:b:hi:l::vr:u:RnNBDCPX:e:d:p:g:S:E:cHm",
 			    opts, &longind)) != -1) {
 		switch (i) {
 		case '\0':
@@ -304,6 +306,14 @@ static void parse_command_line(int argc, char **argv)
 		case 'C':
 			ignore_module_cache = 1;
 			break;
+		case 'g':
+			sh = semanage_handle_create_with_path(optarg);
+			if (!sh) {
+				fprintf(stderr, "%s:  Could not create semanage handle\n",
+					argv[0]);
+				exit(1);
+			}
+			break;
 		case 'X':
 			set_mode(PRIORITY_M, optarg);
 			break;
@@ -421,11 +431,13 @@ int main(int argc, char *argv[])
 	if (build || check_ext_changes)
 		commit = 1;
 
-	sh = semanage_handle_create();
 	if (!sh) {
-		fprintf(stderr, "%s:  Could not create semanage handle\n",
-			argv[0]);
-		goto cleanup_nohandle;
+		sh = semanage_handle_create();
+		if (!sh) {
+			fprintf(stderr, "%s:  Could not create semanage handle\n",
+				argv[0]);
+			goto cleanup_nohandle;
+		}
 	}
 
 	if (store) {
Signature · 1 line
2.47.2
#13 lore raw

PATCH 1/2 libsemanage: add semanage_handle_create_with_path

In reply to James Carter

Adds "semanage_handle_create_with_path" to create an semanage handle with a config file from a specific path. This is useful for baking SELinux policy generation into a Nix derivation.

---
 libsemanage/include/semanage/handle.h |  6 +++++-
 libsemanage/src/handle.c              | 26 +++++++++++++++++++-------
 libsemanage/src/libsemanage.map       |  4 ++++
 3 files changed, 28 insertions(+), 8 deletions(-)
libsemanage/include/semanage/handle.h +5 -1
index a5ea31de..601cd9ee 100644
@@ -30,7 +30,11 @@
 struct semanage_handle;
 typedef struct semanage_handle semanage_handle_t;
 
-/* Create and return a semanage handle.
+/* Create and return a semanage handle with a specific config path.
+   The handle is initially in the disconnected state. */
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name);
+
+/* Create and return a semanage handle with the default config path.
    The handle is initially in the disconnected state. */
 extern semanage_handle_t *semanage_handle_create(void);
 
libsemanage/src/handle.c +19 -7
index faea0606..ca57702a 100644
@@ -59,19 +59,14 @@ const char * semanage_root(void)
 	return private_semanage_root;
 }
 
-
-semanage_handle_t *semanage_handle_create(void)
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name)
 {
 	semanage_handle_t *sh = NULL;
-	char *conf_name = NULL;
 
 	/* Allocate handle */
 	if ((sh = calloc(1, sizeof(semanage_handle_t))) == NULL)
 		goto err;
 
-	if ((conf_name = semanage_conf_path()) == NULL)
-		goto err;
-
 	if ((sh->conf = semanage_conf_parse(conf_name)) == NULL)
 		goto err;
 
@@ -106,13 +101,30 @@ semanage_handle_t *semanage_handle_create(void)
 	sh->msg_callback = semanage_msg_default_handler;
 	sh->msg_callback_arg = NULL;
 
+	return sh;
+
+      err:
+	semanage_handle_destroy(sh);
+	return NULL;
+}
+
+semanage_handle_t *semanage_handle_create(void)
+{
+	semanage_handle_t *sh = NULL;
+	char *conf_name = NULL;
+
+	if ((conf_name = semanage_conf_path()) == NULL)
+		goto err;
+
+	if ((sh = semanage_handle_create_with_path(conf_name)) == NULL)
+		goto err;
+
 	free(conf_name);
 
 	return sh;
 
       err:
 	free(conf_name);
-	semanage_handle_destroy(sh);
 	return NULL;
 }
 
libsemanage/src/libsemanage.map +4 -0
index c8214b26..8d7d8b05 100644
@@ -350,3 +350,7 @@ LIBSEMANAGE_3.4 {
     semanage_module_compute_checksum;
     semanage_set_check_ext_changes;
 } LIBSEMANAGE_1.1;
+
+LIBSEMANAGE_3.9 {
+    semanage_handle_create_with_path;
+} LIBSEMANAGE_3.4;
Signature · 1 line
2.47.2
#14 lore raw

PATCH 2/2 semodule: add config argument

Use "semanage_handle_create_with_path" and implement a new flag for handling semanage config files at specific paths.

---
 policycoreutils/semodule/semodule.8 |  3 +++
 policycoreutils/semodule/semodule.c | 22 +++++++++++++++++-----
 2 files changed, 20 insertions(+), 5 deletions(-)
policycoreutils/semodule/semodule.8 +3 -0
index 00c60c1e..ae928611 100644
@@ -86,6 +86,9 @@ Preserve tunables in policy
 .B \-C,\-\-ignore-module-cache
 Recompile CIL modules built from HLL files
 .TP
+.B \-g,\-\-config=PATH
+use an alternate path for the semanage config
+.TP
 .B \-p,\-\-path
 Use an alternate path for the policy root
 .TP
policycoreutils/semodule/semodule.c +17 -5
index ebe062bf..ab5168eb 100644
@@ -145,6 +145,7 @@ static void usage(char *progname)
 	printf("  -v,--verbose     be verbose\n");
 	printf("  -P,--preserve_tunables	Preserve tunables in policy\n");
 	printf("  -C,--ignore-module-cache	Rebuild CIL modules compiled from HLL files\n");
+	printf("  -g,--config=PATH use an alternate path for the semanage config\n");
 	printf("  -p,--path        use an alternate path for the policy root\n");
 	printf("  -S,--store-path  use an alternate path for the policy store root\n");
 	printf("  -c, --cil extract module as cil. This only affects module extraction.\n");
@@ -210,6 +211,7 @@ static void parse_command_line(int argc, char **argv)
 		{"enable", required_argument, NULL, 'e'},
 		{"disable", required_argument, NULL, 'd'},
 		{"path", required_argument, NULL, 'p'},
+		{"config", required_argument, NULL, 'g'},
 		{"store-path", required_argument, NULL, 'S'},
 		{"checksum", 0, NULL, 'm'},
 		{NULL, 0, NULL, 0}
@@ -223,7 +225,7 @@ static void parse_command_line(int argc, char **argv)
 	check_ext_changes = 0;
 	priority = 400;
 	while ((i =
-		getopt_long(argc, argv, "s:b:hi:l::vr:u:RnNBDCPX:e:d:p:S:E:cHm",
+		getopt_long(argc, argv, "s:b:hi:l::vr:u:RnNBDCPX:e:d:p:g:S:E:cHm",
 			    opts, &longind)) != -1) {
 		switch (i) {
 		case '\0':
@@ -304,6 +306,14 @@ static void parse_command_line(int argc, char **argv)
 		case 'C':
 			ignore_module_cache = 1;
 			break;
+		case 'g':
+			sh = semanage_handle_create_with_path(optarg);
+			if (!sh) {
+				fprintf(stderr, "%s:  Could not create semanage handle\n",
+					argv[0]);
+				exit(1);
+			}
+			break;
 		case 'X':
 			set_mode(PRIORITY_M, optarg);
 			break;
@@ -421,11 +431,13 @@ int main(int argc, char *argv[])
 	if (build || check_ext_changes)
 		commit = 1;
 
-	sh = semanage_handle_create();
 	if (!sh) {
-		fprintf(stderr, "%s:  Could not create semanage handle\n",
-			argv[0]);
-		goto cleanup_nohandle;
+		sh = semanage_handle_create();
+		if (!sh) {
+			fprintf(stderr, "%s:  Could not create semanage handle\n",
+				argv[0]);
+			goto cleanup_nohandle;
+		}
 	}
 
 	if (store) {
Signature · 1 line
2.47.2
Acked-by on v1 1/2
#15 lore raw
In reply to Tristan Ross
Quoted 6 lines · Tristan Ross

Adds "semanage_handle_create_with_path" to create an semanage handle with a config file from a specific path. This is useful for baking SELinux policy generation into a Nix derivation.

For these two patches:

Quoted 96 lines
---
 libsemanage/include/semanage/handle.h |  6 +++++-
 libsemanage/src/handle.c              | 26 +++++++++++++++++++-------
 libsemanage/src/libsemanage.map       |  4 ++++
 3 files changed, 28 insertions(+), 8 deletions(-)
libsemanage/include/semanage/handle.h +5 -1
index a5ea31de..601cd9ee 100644
@@ -30,7 +30,11 @@
 struct semanage_handle;
 typedef struct semanage_handle semanage_handle_t;
 
-/* Create and return a semanage handle.
+/* Create and return a semanage handle with a specific config path.
+   The handle is initially in the disconnected state. */
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name);
+
+/* Create and return a semanage handle with the default config path.
    The handle is initially in the disconnected state. */
 extern semanage_handle_t *semanage_handle_create(void);
 
libsemanage/src/handle.c +19 -7
index faea0606..ca57702a 100644
@@ -59,19 +59,14 @@ const char * semanage_root(void)
        return private_semanage_root;
 }
 
-
-semanage_handle_t *semanage_handle_create(void)
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name)
 {
        semanage_handle_t *sh = NULL;
-       char *conf_name = NULL;
 
        /* Allocate handle */
        if ((sh = calloc(1, sizeof(semanage_handle_t))) == NULL)
                goto err;
 
-       if ((conf_name = semanage_conf_path()) == NULL)
-               goto err;
-
        if ((sh->conf = semanage_conf_parse(conf_name)) == NULL)
                goto err;
 
@@ -106,13 +101,30 @@ semanage_handle_t *semanage_handle_create(void)
        sh->msg_callback = semanage_msg_default_handler;
        sh->msg_callback_arg = NULL;
 
+       return sh;
+
+      err:
+       semanage_handle_destroy(sh);
+       return NULL;
+}
+
+semanage_handle_t *semanage_handle_create(void)
+{
+       semanage_handle_t *sh = NULL;
+       char *conf_name = NULL;
+
+       if ((conf_name = semanage_conf_path()) == NULL)
+               goto err;
+
+       if ((sh = semanage_handle_create_with_path(conf_name)) == NULL)
+               goto err;
+
        free(conf_name);
 
        return sh;
 
       err:
        free(conf_name);
-       semanage_handle_destroy(sh);
        return NULL;
 }
 
libsemanage/src/libsemanage.map +4 -1
index c8214b26..8d7d8b05 100644
@@ -350,3 +350,7 @@ LIBSEMANAGE_3.4 {
     semanage_module_compute_checksum;
     semanage_set_check_ext_changes;
 } LIBSEMANAGE_1.1;
+
+LIBSEMANAGE_3.9 {
+    semanage_handle_create_with_path;
+} LIBSEMANAGE_3.4;
--

2.47.2

#16 lore raw
Quoted 12 lines · James Carter
Quoted 6 lines · Tristan Ross

Adds "semanage_handle_create_with_path" to create an semanage handle with a config file from a specific path. This is useful for baking SELinux policy generation into a Nix derivation.

For these two patches:

These two patches have been merged.
Thanks,
Jim

Quoted 96 lines
Quoted 96 lines
---
 libsemanage/include/semanage/handle.h |  6 +++++-
 libsemanage/src/handle.c              | 26 +++++++++++++++++++-------
 libsemanage/src/libsemanage.map       |  4 ++++
 3 files changed, 28 insertions(+), 8 deletions(-)
libsemanage/include/semanage/handle.h +5 -1
index a5ea31de..601cd9ee 100644
@@ -30,7 +30,11 @@
 struct semanage_handle;
 typedef struct semanage_handle semanage_handle_t;
 
-/* Create and return a semanage handle.
+/* Create and return a semanage handle with a specific config path.
+   The handle is initially in the disconnected state. */
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name);
+
+/* Create and return a semanage handle with the default config path.
    The handle is initially in the disconnected state. */
 extern semanage_handle_t *semanage_handle_create(void);
 
libsemanage/src/handle.c +19 -7
index faea0606..ca57702a 100644
@@ -59,19 +59,14 @@ const char * semanage_root(void)
        return private_semanage_root;
 }
 
-
-semanage_handle_t *semanage_handle_create(void)
+semanage_handle_t *semanage_handle_create_with_path(const char *conf_name)
 {
        semanage_handle_t *sh = NULL;
-       char *conf_name = NULL;
 
        /* Allocate handle */
        if ((sh = calloc(1, sizeof(semanage_handle_t))) == NULL)
                goto err;
 
-       if ((conf_name = semanage_conf_path()) == NULL)
-               goto err;
-
        if ((sh->conf = semanage_conf_parse(conf_name)) == NULL)
                goto err;
 
@@ -106,13 +101,30 @@ semanage_handle_t *semanage_handle_create(void)
        sh->msg_callback = semanage_msg_default_handler;
        sh->msg_callback_arg = NULL;
 
+       return sh;
+
+      err:
+       semanage_handle_destroy(sh);
+       return NULL;
+}
+
+semanage_handle_t *semanage_handle_create(void)
+{
+       semanage_handle_t *sh = NULL;
+       char *conf_name = NULL;
+
+       if ((conf_name = semanage_conf_path()) == NULL)
+               goto err;
+
+       if ((sh = semanage_handle_create_with_path(conf_name)) == NULL)
+               goto err;
+
        free(conf_name);
 
        return sh;
 
       err:
        free(conf_name);
-       semanage_handle_destroy(sh);
        return NULL;
 }
 
libsemanage/src/libsemanage.map +4 -1
index c8214b26..8d7d8b05 100644
@@ -350,3 +350,7 @@ LIBSEMANAGE_3.4 {
     semanage_module_compute_checksum;
     semanage_set_check_ext_changes;
 } LIBSEMANAGE_1.1;
+
+LIBSEMANAGE_3.9 {
+    semanage_handle_create_with_path;
+} LIBSEMANAGE_3.4;
--

2.47.2