seteuid()/setegid() support
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@103 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -77,6 +77,26 @@ Java_com_threerings_util_unsafe_Unsafe_nativeSetgid (
|
|||||||
return JNI_TRUE;
|
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
|
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.
@@ -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.
|
* @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)
|
public static boolean setgid (int gid)
|
||||||
{
|
{
|
||||||
@@ -98,6 +98,32 @@ public class Unsafe
|
|||||||
return false;
|
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}.
|
* Reenable garbage collection after a call to {@link #disableGC}.
|
||||||
*/
|
*/
|
||||||
@@ -123,6 +149,16 @@ public class Unsafe
|
|||||||
*/
|
*/
|
||||||
protected static native boolean nativeSetgid (int gid);
|
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.
|
* Called to initialize our library.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -32,6 +32,34 @@ Java_com_threerings_util_unsafe_Unsafe_nativeSleep (
|
|||||||
/* not supported */
|
/* 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
|
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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,8 +7,6 @@
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
/* Inaccessible static: _gcEnabled */
|
|
||||||
/* Inaccessible static: _loaded */
|
|
||||||
/*
|
/*
|
||||||
* Class: com_threerings_util_unsafe_Unsafe
|
* Class: com_threerings_util_unsafe_Unsafe
|
||||||
* Method: enableGC
|
* 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
|
JNIEXPORT void JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSleep
|
||||||
(JNIEnv *, jclass, jint);
|
(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
|
* Class: com_threerings_util_unsafe_Unsafe
|
||||||
* Method: init
|
* Method: init
|
||||||
|
|||||||
Reference in New Issue
Block a user