Added setuid() and setgid() to Unsafe.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3653 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -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
|
JNIEXPORT jboolean JNICALL
|
||||||
Java_com_threerings_util_unsafe_Unsafe_init (JNIEnv* env, jclass clazz)
|
Java_com_threerings_util_unsafe_Unsafe_init (JNIEnv* env, jclass clazz)
|
||||||
{
|
{
|
||||||
|
|||||||
Binary file not shown.
@@ -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
|
// Narya library - tools for developing networked games
|
||||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
// 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}.
|
* Reenable garbage collection after a call to {@link #disableGC}.
|
||||||
*/
|
*/
|
||||||
@@ -86,6 +112,16 @@ public class Unsafe
|
|||||||
*/
|
*/
|
||||||
protected static native void nativeSleep (int millis);
|
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.
|
* Called to initialize our library.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user