diff --git a/src/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_Unsafe.c b/src/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_Unsafe.c index 04ac0526..abe1fd3e 100644 --- a/src/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_Unsafe.c +++ b/src/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_Unsafe.c @@ -77,6 +77,26 @@ Java_com_threerings_util_unsafe_Unsafe_nativeSetgid ( return JNI_TRUE; } +JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSeteuid ( + JNIEnv* env, jclass clzz, jint uid) +{ + if (seteuid((uid_t)uid) != 0) { + fprintf(stderr, "seteuid(%d) failed: %s\n", uid, strerror(errno)); + return JNI_FALSE; + } + return JNI_TRUE; +} + +JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetegid ( + JNIEnv* env, jclass clazz, jint gid) +{ + if (setegid((gid_t)gid) != 0) { + fprintf(stderr, "setegid(%d) failed: %s\n", gid, strerror(errno)); + return JNI_FALSE; + } + return JNI_TRUE; +} + JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_init (JNIEnv* env, jclass clazz) { diff --git a/src/java/com/threerings/util/unsafe/Mac OS X/libunsafe.jnilib b/src/java/com/threerings/util/unsafe/Mac OS X/libunsafe.jnilib index 18b5c075..4e7796d8 100755 Binary files a/src/java/com/threerings/util/unsafe/Mac OS X/libunsafe.jnilib and b/src/java/com/threerings/util/unsafe/Mac OS X/libunsafe.jnilib differ diff --git a/src/java/com/threerings/util/unsafe/Unsafe.java b/src/java/com/threerings/util/unsafe/Unsafe.java index c275b402..1a7e030f 100644 --- a/src/java/com/threerings/util/unsafe/Unsafe.java +++ b/src/java/com/threerings/util/unsafe/Unsafe.java @@ -73,7 +73,7 @@ public class Unsafe } /** - * Sets the processes uid to the specified value. + * Sets the process' uid to the specified value. * * @return true if the uid was changed, false if we were unable to do so. */ @@ -86,9 +86,9 @@ public class Unsafe } /** - * Sets the processes uid to the specified value. + * Sets the process' gid to the specified value. * - * @return true if the uid was changed, false if we were unable to do so. + * @return true if the gid was changed, false if we were unable to do so. */ public static boolean setgid (int gid) { @@ -98,6 +98,32 @@ public class Unsafe return false; } + /** + * Sets the process' effective uid to the specified value. + * + * @return true if the euid was changed, false if we were unable to do so. + */ + public static boolean seteuid (int uid) + { + if (_loaded && !RunAnywhere.isWindows()) { + return nativeSeteuid(uid); + } + return false; + } + + /** + * Sets the process' effective gid to the specified value. + * + * @return true if the egid was changed, false if we were unable to do so. + */ + public static boolean setegid (int gid) + { + if (_loaded && !RunAnywhere.isWindows()) { + return nativeSetegid(gid); + } + return false; + } + /** * Reenable garbage collection after a call to {@link #disableGC}. */ @@ -123,6 +149,16 @@ public class Unsafe */ protected static native boolean nativeSetgid (int gid); + /** + * Calls through to the native OS system call to change our euid. + */ + protected static native boolean nativeSeteuid (int uid); + + /** + * Calls through to the native OS system call to change our egid. + */ + protected static native boolean nativeSetegid (int gid); + /** * Called to initialize our library. */ diff --git a/src/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_Unsafe.c b/src/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_Unsafe.c index dcb2e950..82622f94 100644 --- a/src/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_Unsafe.c +++ b/src/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_Unsafe.c @@ -32,6 +32,34 @@ Java_com_threerings_util_unsafe_Unsafe_nativeSleep ( /* not supported */ } +JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetuid + (JNIEnv *, jclass, jint) +{ + /* not supported */ + return JNI_FALSE; +} + +JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetgid + (JNIEnv *, jclass, jint) +{ + /* not supported */ + return JNI_FALSE; +} + +JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSeteuid ( + JNIEnv* env, jclass clzz, jint uid) +{ + /* not supported */ + return JNI_FALSE; +} + +JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetegid ( + JNIEnv* env, jclass clazz, jint gid) +{ + /* not supported */ + return JNI_FALSE; +} + JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_init (JNIEnv* env, jclass clazz) { diff --git a/src/java/com/threerings/util/unsafe/com_threerings_util_unsafe_Unsafe.h b/src/java/com/threerings/util/unsafe/com_threerings_util_unsafe_Unsafe.h index f439fed8..bae9f5aa 100644 --- a/src/java/com/threerings/util/unsafe/com_threerings_util_unsafe_Unsafe.h +++ b/src/java/com/threerings/util/unsafe/com_threerings_util_unsafe_Unsafe.h @@ -7,8 +7,6 @@ #ifdef __cplusplus extern "C" { #endif -/* Inaccessible static: _gcEnabled */ -/* Inaccessible static: _loaded */ /* * Class: com_threerings_util_unsafe_Unsafe * Method: enableGC @@ -33,6 +31,38 @@ JNIEXPORT void JNICALL Java_com_threerings_util_unsafe_Unsafe_disableGC JNIEXPORT void JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSleep (JNIEnv *, jclass, jint); +/* + * Class: com_threerings_util_unsafe_Unsafe + * Method: nativeSetuid + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetuid + (JNIEnv *, jclass, jint); + +/* + * Class: com_threerings_util_unsafe_Unsafe + * Method: nativeSetgid + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetgid + (JNIEnv *, jclass, jint); + +/* + * Class: com_threerings_util_unsafe_Unsafe + * Method: nativeSeteuid + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSeteuid + (JNIEnv *, jclass, jint); + +/* + * Class: com_threerings_util_unsafe_Unsafe + * Method: nativeSetegid + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetegid + (JNIEnv *, jclass, jint); + /* * Class: com_threerings_util_unsafe_Unsafe * Method: init