6 #ifndef _Included_org_cacert_natives_SetUID
7 #define _Included_org_cacert_natives_SetUID
12 static jobject getStatus(JNIEnv *env, int successCode, const char * message) {
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);
20 JNIEXPORT jobject JNICALL Java_org_cacert_gigi_natives_SetUID_setUid
21 (JNIEnv *env, jobject obj, jint uid, jint gid) {
23 /* We don't need the reference for the object/class we are working on */
26 if(setgid((int)gid)) {
27 return (jobject)getStatus(env, 0, "Error while setting GID.");
30 if(setuid((int)uid)) {
31 return (jobject)getStatus(env, 0, "Error while setting UID.");
34 return (jobject)getStatus(env, 1, "Successfully set uid/gid.");