Capabilities & Linux & Java

Posted by Marek Jelen on Stack Overflow See other posts from Stack Overflow or by Marek Jelen
Published on 2010-06-14T11:34:51Z Indexed on 2010/06/14 12:12 UTC
Read the original article Hit count: 201

Filed under:
|
|

Hi, I am experimenting with linux capabilities for java application ... I do not want to add capabilities to interpreter (JVM), so I tried to write simple wrapper (with debugging information printed to stdout):

#include <stdio.h>
#include <stdlib.h>
#include <sys/capability.h>
#include <unistd.h>

int main(int argc, char *argv[]){
        cap_t cap = cap_get_proc();

        if (!cap) {
                perror("cap_get_proc");
                exit(1);
        }
        printf("%s: running with caps %s\n", argv[0], cap_to_text(cap, NULL));

        return execlp("/usr/bin/java", "-server", "-jar", "project.jar", (char *)NULL);
}

This way, I can se that the capability is set for this execucatable:

./runner: running with caps = cap_net_bind_service+p

And getcap shows

runner = cap_net_bind_service+ip

I have the capability set to be inheritable, so there should be no problem. However java still don't want to bind to privileged ports :-(

I am getting this error:

sun/nio/ch/Net.java:-2:in `bind': java.net.SocketException: Permission denied (NativeException)

Can someone help me to resolve this?

Thanks in advance

© Stack Overflow or respective owner

Related posts about java

Related posts about linux