]> WPIA git - gigi.git/blob - natives/org_cacert_gigi_natives_SetUID.c
make method static to avoid export
[gigi.git] / natives / org_cacert_gigi_natives_SetUID.c
1 #include <jni.h>  
2 #include <sys/types.h>
3 #include <unistd.h> 
4   
5 #ifndef _Included_org_cacert_natives_SetUID  
6 #define _Included_org_cacert_natives_SetUID  
7 #ifdef __cplusplus  
8 extern "C" {  
9 #endif  
10   
11 static jobject getStatus(JNIEnv *env, int successCode, const char * message) {  
12   
13    jstring message_str = (*env)->NewStringUTF(env, message);
14    jboolean success = successCode;  
15    jclass cls = (*env)->FindClass(env, "Lorg/cacert/gigi/natives/SetUID$Status;");  
16    jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>", "(ZLjava/lang/String;)V");  
17    return (*env)->NewObject(env, cls, constructor, success, message_str);  
18 }  
19   
20 JNIEXPORT jobject JNICALL Java_org_cacert_gigi_natives_SetUID_setUid  
21   (JNIEnv *env, jobject obj, jint uid, jint gid) {  
22           if(setgid((int)gid)) {  
23          return (jobject)getStatus(env, 0, "Error while setting GID.");  
24       } 
25   
26       if(setuid((int)uid)) {
27          return (jobject)getStatus(env, 0, "Error while setting UID.");  
28       }  
29   
30       return (jobject)getStatus(env, 1, "Successfully set uid/gid.");  
31 }  
32   
33 #ifdef __cplusplus  
34 }  
35 #endif  
36 #endif