Skip to contentSkip to conversation

export sepol handle

PATCH In review Joshua Brindle 2 participants 3 messages Jul 26, 2006 – Jul 27, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 export sepol handle

Attached is a patch to export the error reporting handle in libsepol. The setools team needs this so that we can create, destroy, set the callback, and invoke the error reporting from outside libsepol. This will allow us to better propagate the errors into our analysis libraries. This has the earlier suggestions incorporated and should be applied to trunk.

setools_public-policydb-components/libsepol/include/sepol/handle.h renamed from libsepol/include/sepol/handle.h +20 -2
diff -urpN -x 'Change*' -x entries -x '*.orig' -x '*.rej' -x '*.svn*' -x '*.swp' trunk/libsepol/include/sepol/handle.h branch/setools_public-policydb-components/libsepol/include/sepol/handle.h
@@ -3,11 +3,29 @@
 
 struct sepol_handle;
 typedef struct sepol_handle sepol_handle_t;
+typedef void (*sepol_handle_callback_fn_t) (void *varg, sepol_handle_t * handle,
+					    const char *fmt, ...);
 
 /* Create and return a sepol handle. */
-sepol_handle_t *sepol_handle_create(void);
+extern sepol_handle_t *sepol_handle_create(void);
+
+/* Set the callback for a sepol handle */
+extern void sepol_handle_set_callback(sepol_handle_t * h,
+				      sepol_handle_callback_fn_t fn,
+				      void *varg);
+
+/* Call the callback for a sepol handle */
+extern void sepol_handle_do_callback(sepol_handle_t * handle, const char *fmt,
+				     ...)
+#ifdef __GNUC__
+    __attribute__ ((format(printf, 2, 3)))
+#endif
+    ;
+
+/* Get the severity level of the last message */
+extern int sepol_handle_get_level(sepol_handle_t * h);
 
 /* Destroy a sepol handle. */
-void sepol_handle_destroy(sepol_handle_t *);
+extern void sepol_handle_destroy(sepol_handle_t * h);
 
 #endif
setools_public-policydb-components/libsepol/src/handle.c renamed from libsepol/src/handle.c +38 -1
diff -urpN -x 'Change*' -x entries -x '*.orig' -x '*.rej' -x '*.svn*' -x '*.swp' trunk/libsepol/src/handle.c branch/setools_public-policydb-components/libsepol/src/handle.c
@@ -1,4 +1,6 @@
 #include <stdlib.h>
+#include <stdarg.h>
+#include <errno.h>
 #include "handle.h"
 #include "debug.h"
 
@@ -16,7 +18,42 @@ sepol_handle_t *sepol_handle_create(void
 	return sh;
 }
 
-void sepol_handle_destroy(sepol_handle_t * sh)
+void sepol_handle_set_callback(sepol_handle_t *h, sepol_handle_callback_fn_t fn, void *varg)
 {
+	if (h == NULL)
+		return;
+
+	h->msg_callback = fn;
+	h->msg_callback_arg = varg;
+}
+
+void sepol_handle_do_callback(sepol_handle_t* handle, const char* fmt, ...)
+{
+	char *tmp = NULL;
+	va_list ap;
+
+	if (handle == NULL)
+		return;
+
+	va_start(ap, fmt);
+	vasprintf(&tmp, fmt, ap);
+	va_end(ap);
+
+	ERR(handle, "%s", tmp);
+	free(tmp);
+}
+
+int sepol_handle_get_level(sepol_handle_t *h)
+{
+	if (h == NULL) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	return h->msg_level;
+}
+
+void sepol_handle_destroy(sepol_handle_t * sh) {
 	free(sh);
 }
+
setools_public-policydb-components/libsepol/src/handle.h renamed from libsepol/src/handle.h +1 -2
diff -urpN -x 'Change*' -x entries -x '*.orig' -x '*.rej' -x '*.svn*' -x '*.swp' trunk/libsepol/src/handle.h branch/setools_public-policydb-components/libsepol/src/handle.h
@@ -11,8 +11,7 @@ struct sepol_handle {
 #ifdef __GNUC__
 	__attribute__ ((format(printf, 3, 4)))
 #endif
-	void (*msg_callback) (void *varg,
-			      sepol_handle_t * handle, const char *fmt, ...);
+	sepol_handle_callback_fn_t msg_callback;
 	void *msg_callback_arg;
 };
 

--
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
Quoted 13 lines · Joshua Brindle

Attached is a patch to export the error reporting handle in libsepol. The setools team needs this so that we can create, destroy, set the callback, and invoke the error reporting from outside libsepol. This will allow us to better propagate the errors into our analysis libraries. This has the earlier suggestions incorporated and should be applied to trunk.

diff -urpN -x 'Change*' -x entries -x '*.orig' -x '*.rej' -x '*.svn*' -x '*.swp' trunk/libsepol/src/handle.c branch/setools_public-policydb-components/libsepol/src/handle.c

setools_public-policydb-components/libsepol/src/handle.c renamed from libsepol/src/handle.c +0 -0
@@ -16,7 +18,42 @@ sepol_handle_t *sepol_handle_create(void
 	return sh;
 }

setools_public-policydb-components/libsepol/src/handle.c sepol_handle_t *sepol_handle_create(void · line 28

Quoted 10 lines
setools_public-policydb-components/libsepol/src/handle.c renamed from libsepol/src/handle.c +7 -1
 
-void sepol_handle_destroy(sepol_handle_t * sh)
+void sepol_handle_set_callback(sepol_handle_t *h, sepol_handle_callback_fn_t fn, void *varg)
 {
+	if (h == NULL)
+		return;
+
+	h->msg_callback = fn;
+	h->msg_callback_arg = varg;
+}

This looks like sepol_msg_set_callback, which is what libsemanage already uses. Am I missing something?

Quoted 5 lines
setools_public-policydb-components/libsepol/src/handle.c renamed from libsepol/src/handle.c +5 -0
+void sepol_handle_do_callback(sepol_handle_t* handle, const char* fmt, ...)
+{
+	char *tmp = NULL;
+	va_list ap;
+

setools_public-policydb-components/libsepol/src/handle.c sepol_handle_t *sepol_handle_create(void · line 44

Quoted 10 lines
setools_public-policydb-components/libsepol/src/handle.c renamed from libsepol/src/handle.c +10 -0
+	if (handle == NULL)
+		return;
+
+	va_start(ap, fmt);
+	vasprintf(&tmp, fmt, ap);
+	va_end(ap);
+
+	ERR(handle, "%s", tmp);
+	free(tmp);
+}

I don't quite understand the intended usage. If I am generating an error message from outside the library, why would I call into the library and then have it call into the callback I provided in the first place? What's the point?

setools_public-policydb-components/libsepol/src/handle.c sepol_handle_t *sepol_handle_create(void · line 54

Quoted 9 lines
setools_public-policydb-components/libsepol/src/handle.c renamed from libsepol/src/handle.c +9 -0
+int sepol_handle_get_level(sepol_handle_t *h)
+{
+	if (h == NULL) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	return h->msg_level;
+}

This looks like sepol_msg_get_level().

Signature · 8 lines
Stephen Smalley
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.
#2 lore raw
Quoted 17 lines

From: Stephen Smalley [mailto:[email protected]]

setools_public-policydb-components/libsepol/src/handle.c sepol_handle_t *sepol_handle_create(void · line 28

Quoted 11 lines
setools_public-policydb-components/libsepol/src/handle.c renamed from libsepol/src/handle.c +8 -1
-void sepol_handle_destroy(sepol_handle_t * sh)
+void sepol_handle_set_callback(sepol_handle_t *h, 
+sepol_handle_callback_fn_t fn, void *varg)
 {
+	if (h == NULL)
+		return;
+
+	h->msg_callback = fn;
+	h->msg_callback_arg = varg;
+}

This looks like sepol_msg_set_callback, which is what libsemanage already uses. Am I missing something?

Yes, drop this patch, looks like someone didn't do their homework :\

Quoted 12 lines
Quoted 12 lines
setools_public-policydb-components/libsepol/src/handle.c renamed from libsepol/src/handle.c +12 -0
+void sepol_handle_do_callback(sepol_handle_t* handle, const char* 
+fmt, ...) {
+	char *tmp = NULL;
+	va_list ap;
+
+	if (handle == NULL)
+		return;
+
+	va_start(ap, fmt);
+	vasprintf(&tmp, fmt, ap);
+	va_end(ap);
+
Quoted 9 lines

setools_public-policydb-components/libsepol/src/handle.c sepol_handle_t *sepol_handle_create(void · line 44

Quoted 3 lines
setools_public-policydb-components/libsepol/src/handle.c renamed from libsepol/src/handle.c +3 -0
+	ERR(handle, "%s", tmp);
+	free(tmp);
+}

I don't quite understand the intended usage. If I am generating an error message from outside the library, why would I call into the library and then have it call into the callback I provided in the first place? What's the point?

The intention was for a library using libsepol (libqpol) to generate an sepol error that will call the callback in the application, granted its awkward. The setools guys will rethink this. For now just drop this patch.

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