diff --git a/src/java/com/threerings/util/unsafe/Linux/com_threerings_util_unsafe_Unsafe.c b/src/java/com/threerings/util/unsafe/Linux/com_threerings_util_unsafe_Unsafe.c index a22893af5..683c55839 100644 --- a/src/java/com/threerings/util/unsafe/Linux/com_threerings_util_unsafe_Unsafe.c +++ b/src/java/com/threerings/util/unsafe/Linux/com_threerings_util_unsafe_Unsafe.c @@ -55,6 +55,28 @@ Java_com_threerings_util_unsafe_Unsafe_nativeSleep ( } } +JNIEXPORT jboolean JNICALL +Java_com_threerings_util_unsafe_Unsafe_nativeSetuid ( + JNIEnv* env, jclass clazz, jint uid) +{ + if (setuid((uid_t)uid) != 0) { + fprintf(stderr, "setuid(%d) failed: %s\n", uid, strerror(errno)); + return JNI_FALSE; + } + return JNI_TRUE; +} + +JNIEXPORT jboolean JNICALL +Java_com_threerings_util_unsafe_Unsafe_nativeSetgid ( + JNIEnv* env, jclass clazz, jint gid) +{ + if (setgid((gid_t)gid) != 0) { + fprintf(stderr, "setgid(%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/Linux/libunsafe.so b/src/java/com/threerings/util/unsafe/Linux/libunsafe.so index 671df8a7e..59305842f 100755 Binary files a/src/java/com/threerings/util/unsafe/Linux/libunsafe.so and b/src/java/com/threerings/util/unsafe/Linux/libunsafe.so differ diff --git a/src/java/com/threerings/util/unsafe/Unsafe.java b/src/java/com/threerings/util/unsafe/Unsafe.java index 114ea5e03..b7b845942 100644 --- a/src/java/com/threerings/util/unsafe/Unsafe.java +++ b/src/java/com/threerings/util/unsafe/Unsafe.java @@ -1,5 +1,5 @@ // -// $Id: Unsafe.java,v 1.2 2004/08/27 02:20:38 mdb Exp $ +// $Id$ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -71,6 +71,32 @@ public class Unsafe } } + /** + * Sets the processes uid to the specified value. + * + * @return true if the uid was changed, false if we were unable to do so. + */ + public static boolean setuid (int uid) + { + if (_loaded && !RunAnywhere.isWindows()) { + return nativeSetuid(uid); + } + return false; + } + + /** + * Sets the processes uid to the specified value. + * + * @return true if the uid was changed, false if we were unable to do so. + */ + public static boolean setgid (int gid) + { + if (_loaded && !RunAnywhere.isWindows()) { + return nativeSetgid(gid); + } + return false; + } + /** * Reenable garbage collection after a call to {@link #disableGC}. */ @@ -86,6 +112,16 @@ public class Unsafe */ protected static native void nativeSleep (int millis); + /** + * Calls through to the native OS system call to change our uid. + */ + protected static native boolean nativeSetuid (int uid); + + /** + * Calls through to the native OS system call to change our gid. + */ + protected static native boolean nativeSetgid (int gid); + /** * Called to initialize our library. */