sepolicy: Add better private API for setfscreatecon
Use `g_auto()` more sanely with a struct implmenting the "is initialized" pattern. This is way less ugly for callers, and fixes bugs like us calling `setfscreatecon()` even if an error occurred beforehand. Also fold in the logic for "NULL or not loaded" sepolicy into the setup rather than requiring callers to inline it. Prep for more users of this function. Closes: #746 Approved by: jlebon
This commit is contained in:
1 parent
d7f4a326b9
commit
7b2370dc86
3 files changed
+82
-30
No files matched your search
@@ -28,6 +28,7 @@
|
||||
#include "otutil.h"
|
||||
|
||||
#include "ostree-sepolicy.h"
|
||||
#include "ostree-sepolicy-private.h"
|
||||
#include "ostree-bootloader-uboot.h"
|
||||
#include "ostree-bootloader-syslinux.h"
|
||||
|
||||
@@ -690,3 +691,31 @@ ostree_sepolicy_fscreatecon_cleanup (void **unused)
|
||||
setfscreatecon (NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Currently private copy of the older sepolicy/fscreatecon API with a nicer
|
||||
* g_auto() cleanup. May be made public later.
|
||||
*/
|
||||
gboolean
|
||||
_ostree_sepolicy_preparefscreatecon (OstreeSepolicyFsCreatecon *con,
|
||||
OstreeSePolicy *self,
|
||||
const char *path,
|
||||
guint32 mode,
|
||||
GError **error)
|
||||
{
|
||||
if (!self || ostree_sepolicy_get_name (self) == NULL)
|
||||
return TRUE;
|
||||
|
||||
if (!ostree_sepolicy_setfscreatecon (self, path, mode, error))
|
||||
return FALSE;
|
||||
|
||||
con->initialized = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_sepolicy_fscreatecon_clear (OstreeSepolicyFsCreatecon *con)
|
||||
{
|
||||
if (!con->initialized)
|
||||
return;
|
||||
ostree_sepolicy_fscreatecon_cleanup (NULL);
|
||||
}
|
||||
Reference in new issue
Block a user