Skip to content

Commit 4200ee6

Browse files
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. Signed-off-by: Tristan Ross <[email protected]>
1 parent f057012 commit 4200ee6

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

libsemanage/include/semanage/handle.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
struct semanage_handle;
3131
typedef struct semanage_handle semanage_handle_t;
3232

33-
/* Create and return a semanage handle.
33+
/* Create and return a semanage handle with a specific config path.
34+
The handle is initially in the disconnected state. */
35+
semanage_handle_t *semanage_handle_create_with_path(const char *conf_name);
36+
37+
/* Create and return a semanage handle with the default config path.
3438
The handle is initially in the disconnected state. */
3539
extern semanage_handle_t *semanage_handle_create(void);
3640

libsemanage/src/handle.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,14 @@ const char * semanage_root(void)
5959
return private_semanage_root;
6060
}
6161

62-
63-
semanage_handle_t *semanage_handle_create(void)
62+
semanage_handle_t *semanage_handle_create_with_path(const char *conf_name)
6463
{
6564
semanage_handle_t *sh = NULL;
66-
char *conf_name = NULL;
6765

6866
/* Allocate handle */
6967
if ((sh = calloc(1, sizeof(semanage_handle_t))) == NULL)
7068
goto err;
7169

72-
if ((conf_name = semanage_conf_path()) == NULL)
73-
goto err;
74-
7570
if ((sh->conf = semanage_conf_parse(conf_name)) == NULL)
7671
goto err;
7772

@@ -106,13 +101,30 @@ semanage_handle_t *semanage_handle_create(void)
106101
sh->msg_callback = semanage_msg_default_handler;
107102
sh->msg_callback_arg = NULL;
108103

104+
return sh;
105+
106+
err:
107+
semanage_handle_destroy(sh);
108+
return NULL;
109+
}
110+
111+
semanage_handle_t *semanage_handle_create(void)
112+
{
113+
semanage_handle_t *sh = NULL;
114+
char *conf_name = NULL;
115+
116+
if ((conf_name = semanage_conf_path()) == NULL)
117+
goto err;
118+
119+
if ((sh = semanage_handle_create_with_path(conf_name)) == NULL)
120+
goto err;
121+
109122
free(conf_name);
110123

111124
return sh;
112125

113126
err:
114127
free(conf_name);
115-
semanage_handle_destroy(sh);
116128
return NULL;
117129
}
118130

libsemanage/src/libsemanage.map

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,7 @@ LIBSEMANAGE_3.4 {
350350
semanage_module_compute_checksum;
351351
semanage_set_check_ext_changes;
352352
} LIBSEMANAGE_1.1;
353+
354+
LIBSEMANAGE_3.9 {
355+
semanage_handle_create_with_path;
356+
} LIBSEMANAGE_3.4;

0 commit comments

Comments
 (0)