]> WPIA git - gigi.git/commitdiff
Merge branch 'BenBE_work'
authorJanis Streib <janis@dogcraft.de>
Sun, 6 Jul 2014 12:06:57 +0000 (14:06 +0200)
committerJanis Streib <janis@dogcraft.de>
Sun, 6 Jul 2014 12:06:57 +0000 (14:06 +0200)
Conflicts:
natives/org_cacert_gigi_natives_SetUID.c

natives/Makefile
natives/org_cacert_gigi_natives_SetUID.c

index b58e400672c0e222c313ab4583d07fb7b872ee46..faf073cd5b28b122db35e7ebf407430354d7a900 100644 (file)
@@ -1,11 +1,16 @@
 SYSTEM= $(shell uname | awk '{print tolower($$0)}')
+JAVAH?=javah
+CC?=gcc
+CFLAGS?=-O3 -g -flto -Wall -Werror -Wextra -pedantic -fsanitize=address -fPIC
+CFLAGS+=-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(SYSTEM)
+LDFLAGS?=-shared
 
 
 all: libsetuid.so
 
-libsetuid.so:
-       javah -classpath ../bin/ -jni org.cacert.gigi.natives.SetUID    
-       gcc -fPIC -o libsetuid.so -shared -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(SYSTEM) org_cacert_gigi_natives_SetUID.c
+libsetuid.so: org_cacert_gigi_natives_SetUID.c
+       $(JAVAH) -classpath ../bin/ -jni org.cacert.gigi.natives.SetUID && \
+       $(CC) $(CFLAGS) $(LDFLAGS) -o libsetuid.so org_cacert_gigi_natives_SetUID.c
 
 clean:
        rm -f *.so
index 96bf4c21503e09354d9f23ad3fd8e8fea200a417..6c94d619a397dfdf891d25136753febe390be827 100644 (file)
@@ -1,36 +1,40 @@
-#include <jni.h>  
+#include <jni.h>
 #include <sys/types.h>
-#include <unistd.h> 
-  
-#ifndef _Included_org_cacert_natives_SetUID  
-#define _Included_org_cacert_natives_SetUID  
-#ifdef __cplusplus  
-extern "C" {  
-#endif  
-  
-static jobject getStatus(JNIEnv *env, int successCode, const char * message) {  
-  
-   jstring message_str = (*env)->NewStringUTF(env, message);
-   jboolean success = successCode;  
-   jclass cls = (*env)->FindClass(env, "Lorg/cacert/gigi/natives/SetUID$Status;");  
-   jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>", "(ZLjava/lang/String;)V");  
-   return (*env)->NewObject(env, cls, constructor, success, message_str);  
-}  
-  
-JNIEXPORT jobject JNICALL Java_org_cacert_gigi_natives_SetUID_setUid  
-  (JNIEnv *env, jobject obj, jint uid, jint gid) {  
-         if(setgid((int)gid)) {  
-         return (jobject)getStatus(env, 0, "Error while setting GID.");  
-      } 
-  
-      if(setuid((int)uid)) {
-         return (jobject)getStatus(env, 0, "Error while setting UID.");  
-      }  
-  
-      return (jobject)getStatus(env, 1, "Successfully set uid/gid.");  
-}  
-  
-#ifdef __cplusplus  
-}  
-#endif  
-#endif  
+
+#include <unistd.h>
+
+#ifndef _Included_org_cacert_natives_SetUID
+#define _Included_org_cacert_natives_SetUID
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static jobject getStatus(JNIEnv *env, int successCode, const char * message) {
+    jstring message_str = (*env)->NewStringUTF(env, message);
+    jboolean success = successCode;
+    jclass cls = (*env)->FindClass(env, "Lorg/cacert/gigi/natives/SetUID$Status;");
+    jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>", "(ZLjava/lang/String;)V");
+    return (*env)->NewObject(env, cls, constructor, success, message_str);
+}
+
+JNIEXPORT jobject JNICALL Java_org_cacert_gigi_natives_SetUID_setUid
+        (JNIEnv *env, jobject obj, jint uid, jint gid) {
+
+    /* We don't need the reference for the object/class we are working on */
+    (void)obj;
+
+    if(setgid((int)gid)) {
+        return (jobject)getStatus(env, 0, "Error while setting GID.");
+    }
+
+    if(setuid((int)uid)) {
+        return (jobject)getStatus(env, 0, "Error while setting UID.");
+    }
+
+    return (jobject)getStatus(env, 1, "Successfully set uid/gid.");
+}
+
+#ifdef __cplusplus
+}
+#endif
+#endif