Skip to contentSkip to conversation

libselinux: new callback mechanism

PATCH New Eamon Walsh 1 participant 1 message Jun 11, 2007 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux: new callback mechanism

The current method of setting callbacks, as implemented in avc_init(), is to pass in a large number of structures with individual fields for each callback. This is cumbersome and as a lead-up to the labeling support patchset, I have come up with another solution to this problem.

This new selinux_set_callback() function takes a type code and a function pointer that comes from a union of callback types.

This hopefully can become the way to set callbacks; the avc_init() call will be deprecated and replaced with another call that doesn't require passing in all the callbacks.

This patchset includes three callbacks. The various threading and locking ones can be added subsequently.

---

include/selinux/selinux.h |   25 +++++++++++++++++
src/callbacks.c           |   67 ++++++++++++++++++++++++++++++++++++++++++++++
src/callbacks.h           |   24 ++++++++++++++++
3 files changed, 116 insertions(+)
include/selinux/selinux.h +0 -0
Index: libselinux/include/selinux/selinux.h
===================================================================
@@ -132,6 +132,31 @@
	unsigned int seqno;
};

+/* Callback facilities */
+union selinux_callback {
+ /* log the printf-style format and arguments,
+ with the type code indicating the type of message */
+ int (*func_log) (int type, const char *fmt, ...);
+ /* store a string representation of auditdata (corresponding
+ to the given security class) into msgbuf. */
+ int (*func_audit) (void *auditdata, security_class_t cls,
+ char *msgbuf, size_t msgbufsize);
+ /* validate the supplied context, modifying if necessary */
+ int (*func_validate) (security_context_t *ctx);
+};
+
+#define SELINUX_CB_LOG 0
+#define SELINUX_CB_AUDIT 1
+#define SELINUX_CB_VALIDATE 2
+
+extern void selinux_set_callback(int type, union selinux_callback cb); +
+ /* Logging type codes, passed to the logging callback */
+#define SELINUX_ERROR 0
+#define SELINUX_WARNING 1
+#define SELINUX_INFO 2
+#define SELINUX_AVC 3
+
/* Compute an access decision. */
extern int security_compute_av(security_context_t scon,
security_context_t tcon,

src/callbacks.c +67 -0

67 lines not on this page · raw message

src/callbacks.h +24 -0
Index: libselinux/src/callbacks.h
===================================================================
@@ -0,0 +1,24 @@
+/*
+ * This file describes the callbacks passed to selinux_init() and available
+ * for use from the library code.  They all have default implementations.
+ */
+#ifndef _SELINUX_CALLBACKS_H_
+#define _SELINUX_CALLBACKS_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <selinux/selinux.h>
+#include "dso.h"
+
+/* callback pointers */
+extern int __attribute__ ((format(printf, 2, 3)))
+(*selinux_log) (int type, const char *, ...) hidden;
+
+extern int
+(*selinux_audit) (void *, security_class_t, char *, size_t) hidden;
+
+extern int
+(*selinux_validate)(security_context_t *ctx) hidden;
+
+#endif				/* _SELINUX_CALLBACKS_H_ */
Signature · 8 lines
Eamon Walsh <[email protected]>
National Security Agency


--
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.