From: Antoine Martin <antoine@nagafix.co.uk>
To: Karl MacMillan <kmacmillan@mentalrootkit.com>
Cc: Dave Quigley <dquigley+selinux@gmail.com>,
selinux@tycho.nsa.gov, slide@tresys.com
Subject: Re: Java bindings for SELinux libraries
Date: Sun, 01 Apr 2007 15:30:29 +0100 [thread overview]
Message-ID: <460FC205.5070704@nagafix.co.uk> (raw)
In-Reply-To: <1175266261.3102.20.camel@localhost.localdomain>
Karl MacMillan wrote:
> On Thu, 2007-03-29 at 17:20 -0400, Dave Quigley wrote:
>> Hello,
>> I was wondering if anyone has written or has seen java bindings
>> for the selinux userspace libraries? A search through google doesn't
>> yield any good results.
>>
>
> There are not generally available Java bindings of which I am aware.
> However, the python bindings are done with Swig, which should make
> producing Java bindings fairly straightforward.
I have written some JNI stubs for use in a CMS, but never took it beyond
the proof-of-concept stage (for lack of time). It is pretty easy to
generate the JNI stubs using the sun tools.
Here is an example for getfilecon:
This is generated by the Sun tools (just had to fill in the blanks):
#include <jni.h>
#include <sys/types.h>
#include <selinux/selinux.h>
JNIEXPORT jstring JNICALL Java_uk_org_devloop_GetFileCon_getfilecon
(JNIEnv * env, jobject jobj, jstring filename) {
jboolean iscopy;
const char *mfile = (*env)->GetStringUTFChars(
env, filename, &iscopy);
security_context_t sc = NULL;
int ret = getfilecon(mfile, &sc);
jstring str = (*env)->NewStringUTF (env,sc);
freecon(sc);
return (str);
}
Compile it:
gcc -o getfilecon.so -Wl,-soname,libgetfilecon.so
-I/opt/java/jdk1.6/include/ -I/opt/java/jdk1.6/include/linux
GetFileCon.c -shared -fPIC -lselinux
Then you can use it in Java:
public class GetFileCon {
//Native method declaration
native String getfilecon(String filename);
//Load the library
static {
System.loadLibrary("getfilecon");
}
public static void main(String args[]) {
GetFileCon gfc = new GetFileCon();
String file = ".";
String buf = gfc.getfilecon(file);
System.out.println("getfilecon("+file+")="+buf);
}
}
Obviously, you wouldn't write a .so for each method to call. this is
just a PoC.
Antoine
> Also, the SLIDE
> developers (http://oss.tresys.com/projects/slide) may have some bindings
> (CC'd).
>
> Karl
>
>
>
>
> --
> This message was distributed to subscribers of the selinux mailing list.
> If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
> the words "unsubscribe selinux" without quotes as the message.
>
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.
next prev parent reply other threads:[~2007-04-01 14:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-29 21:20 Java bindings for SELinux libraries Dave Quigley
2007-03-30 14:51 ` Karl MacMillan
2007-04-01 14:30 ` Antoine Martin [this message]
2007-04-02 14:54 ` Brian M. Williams
2007-04-02 15:43 ` KaiGai Kohei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=460FC205.5070704@nagafix.co.uk \
--to=antoine@nagafix.co.uk \
--cc=dquigley+selinux@gmail.com \
--cc=kmacmillan@mentalrootkit.com \
--cc=selinux@tycho.nsa.gov \
--cc=slide@tresys.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.