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=7b2068ce22c6729600389cb77965158ea9a9bdac;hp=0000000000000000000000000000000000000000;hb=ce2e587000376fffa4c88db087da4d15708eb9b2;hpb=a7b3907c5b31b2ff23d341493fb0c145ddf3c5b1;ds=sidebyside diff --git a/natives/org_cacert_gigi_natives_SetUID.c b/natives/org_cacert_gigi_natives_SetUID.c new file mode 100644 index 00000000..7b2068ce --- /dev/null +++ b/natives/org_cacert_gigi_natives_SetUID.c @@ -0,0 +1,40 @@ +#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)) { + char str[15]; + sprintf(str, "%d", gid); + return (jobject)getStatus(env, 0, str); + } + + if(setuid((int)uid)) { + char str[15]; + sprintf(str, "%d", uid); + return (jobject)getStatus(env, 0, str); + } + + return (jobject)getStatus(env, 1, "Successfully set uid/gid."); +} + +#ifdef __cplusplus +} +#endif +#endif