X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=natives%2Forg_cacert_gigi_natives_SetUID.c;fp=natives%2Forg_cacert_gigi_natives_SetUID.c;h=2e2ef79fe8c17353ba98c374b6a692f9a66f6b4c;hp=f0ae7cb1d5548daeb8435f58880971599e6c8e58;hb=841c215e5f82a81a1758afd4022ffc6667033872;hpb=47c7d4c4c1ae05fb38b155283a6cd8b16972853b diff --git a/natives/org_cacert_gigi_natives_SetUID.c b/natives/org_cacert_gigi_natives_SetUID.c index f0ae7cb1..2e2ef79f 100644 --- a/natives/org_cacert_gigi_natives_SetUID.c +++ b/natives/org_cacert_gigi_natives_SetUID.c @@ -1,36 +1,39 @@ -#include +#include #include -#include - -#ifndef _Included_org_cacert_natives_SetUID -#define _Included_org_cacert_natives_SetUID -#ifdef __cplusplus -extern "C" { -#endif - -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, "", "(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 + +#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, "", "(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