INTEGRATION: CWS kso11 (1.3.8); FILE MERGED
2004/03/10 15:45:29 kso 1.3.8.1: #115883# - Use osl Security when creating pipes.
This commit is contained in:
@@ -2,9 +2,9 @@
|
|||||||
*
|
*
|
||||||
* $RCSfile: com_sun_star_lib_connections_pipe_PipeConnection.c,v $
|
* $RCSfile: com_sun_star_lib_connections_pipe_PipeConnection.c,v $
|
||||||
*
|
*
|
||||||
* $Revision: 1.3 $
|
* $Revision: 1.4 $
|
||||||
*
|
*
|
||||||
* last change: $Author: hr $ $Date: 2004-02-04 12:14:32 $
|
* last change: $Author: kz $ $Date: 2004-03-25 11:04:12 $
|
||||||
*
|
*
|
||||||
* The Contents of this file are made available subject to the terms of
|
* The Contents of this file are made available subject to the terms of
|
||||||
* either of the following licenses
|
* either of the following licenses
|
||||||
@@ -63,6 +63,7 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "osl/security.h"
|
||||||
#include <osl/pipe.h>
|
#include <osl/pipe.h>
|
||||||
|
|
||||||
#include "com_sun_star_lib_connections_pipe_PipeConnection.h"
|
#include "com_sun_star_lib_connections_pipe_PipeConnection.h"
|
||||||
@@ -70,18 +71,9 @@
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* exception macros */
|
/* exception macros */
|
||||||
|
|
||||||
#define Throw_IfException(env) { \
|
|
||||||
if ((*env)->ExceptionOccurred(env) != NULL) break; }
|
|
||||||
|
|
||||||
#define ThrowException(env, type, msg) { \
|
#define ThrowException(env, type, msg) { \
|
||||||
(*env)->ThrowNew(env, (*env)->FindClass(env, type), msg); }
|
(*env)->ThrowNew(env, (*env)->FindClass(env, type), msg); }
|
||||||
|
|
||||||
#define ThrowIO_If(cond, env, msg) { if (cond) \
|
|
||||||
{ ThrowException(env, "com/sun/star/io/IOException", msg); break; } }
|
|
||||||
|
|
||||||
#define ThrowRT_If(cond, env, msg) { if (cond) \
|
|
||||||
{ ThrowException(env, "java/lang/RuntimeException", msg); break; } }
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* helper functions prototypes */
|
/* helper functions prototypes */
|
||||||
|
|
||||||
@@ -98,11 +90,22 @@ static oslPipe getPipe(JNIEnv * env, jobject obj_this)
|
|||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
tclass = (*env)->GetObjectClass(env, obj_this);
|
tclass = (*env)->GetObjectClass(env, obj_this);
|
||||||
ThrowRT_If((tclass == NULL),
|
if (tclass == NULL)
|
||||||
env, "native pipe cannot find class");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe cannot find class");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J");
|
fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J");
|
||||||
ThrowRT_If((fid == NULL),
|
if (fid == NULL)
|
||||||
env, "native pipe cannot find field");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe cannot find field");
|
||||||
|
break;
|
||||||
|
}
|
||||||
return ((oslPipe)((*env)->GetLongField(env, obj_this, fid)));
|
return ((oslPipe)((*env)->GetLongField(env, obj_this, fid)));
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -142,54 +145,100 @@ JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_cre
|
|||||||
jclass tclass;
|
jclass tclass;
|
||||||
jfieldID fid;
|
jfieldID fid;
|
||||||
|
|
||||||
|
oslSecurity psec = osl_getCurrentSecurity();
|
||||||
oslPipe npipe = NULL;
|
oslPipe npipe = NULL;
|
||||||
rtl_uString * pname = NULL;
|
rtl_uString * pname = NULL;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
ThrowRT_If(((*env)->MonitorEnter(env, obj_this) != 0),
|
if ((*env)->MonitorEnter(env, obj_this) != 0)
|
||||||
env, "native pipe cannot synchronize on the object");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe cannot synchronize on the object");
|
||||||
|
break;
|
||||||
|
}
|
||||||
state = INMONITOR;
|
state = INMONITOR;
|
||||||
|
|
||||||
/* check connection state */
|
/* check connection state */
|
||||||
npipe = getPipe(env, obj_this);
|
npipe = getPipe(env, obj_this);
|
||||||
Throw_IfException(env);
|
if ((*env)->ExceptionOccurred(env) != NULL)
|
||||||
ThrowIO_If((npipe != NULL),
|
break;
|
||||||
env, "native pipe is already connected");
|
if (npipe != NULL)
|
||||||
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"com/sun/star/io/IOException",
|
||||||
|
"native pipe is already connected");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* save the pipe name */
|
/* save the pipe name */
|
||||||
tclass = (*env)->GetObjectClass(env, obj_this);
|
tclass = (*env)->GetObjectClass(env, obj_this);
|
||||||
ThrowRT_If((tclass == NULL),
|
if (tclass == NULL)
|
||||||
env, "native pipe cannot find class");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe cannot find class");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
fid = (*env)->GetFieldID(env, tclass,
|
fid = (*env)->GetFieldID(env, tclass,
|
||||||
"_aDescription", "Ljava/lang/String;");
|
"_aDescription", "Ljava/lang/String;");
|
||||||
ThrowRT_If((fid == NULL),
|
if (fid == NULL)
|
||||||
env, "native pipe cannot find field");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe cannot find field");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
(*env)->SetObjectField(env, obj_this, fid, (jobject)name);
|
(*env)->SetObjectField(env, obj_this, fid, (jobject)name);
|
||||||
|
|
||||||
/* convert pipe name to rtl_uString */
|
/* convert pipe name to rtl_uString */
|
||||||
pname = jstring2ustring(env, name);
|
pname = jstring2ustring(env, name);
|
||||||
ThrowRT_If((pname == NULL),
|
if (pname == NULL)
|
||||||
env, "native pipe cannot convert name");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe cannot convert name");
|
||||||
|
break;
|
||||||
|
}
|
||||||
state = GOTNAME;
|
state = GOTNAME;
|
||||||
|
|
||||||
/* try to connect */
|
/* try to connect */
|
||||||
npipe = osl_createPipe(pname, osl_Pipe_OPEN, NULL);
|
npipe = osl_createPipe(pname, osl_Pipe_OPEN, psec);
|
||||||
ThrowRT_If((npipe == NULL),
|
if (npipe == NULL)
|
||||||
env, "cannot create native pipe");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"cannot create native pipe");
|
||||||
|
break;
|
||||||
|
}
|
||||||
state = CREATED;
|
state = CREATED;
|
||||||
|
|
||||||
/* save the pipe */
|
/* save the pipe */
|
||||||
tclass = (*env)->GetObjectClass(env, obj_this);
|
tclass = (*env)->GetObjectClass(env, obj_this);
|
||||||
ThrowRT_If((tclass == NULL),
|
if (tclass == NULL)
|
||||||
env, "native pipe cannot find class");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe cannot find class");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J");
|
fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J");
|
||||||
ThrowRT_If((fid == NULL),
|
if (fid == NULL)
|
||||||
env, "native pipe cannot find field");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe cannot find field");
|
||||||
|
break;
|
||||||
|
}
|
||||||
(*env)->SetLongField(env, obj_this, fid, (jlong)npipe);
|
(*env)->SetLongField(env, obj_this, fid, (jlong)npipe);
|
||||||
|
|
||||||
/* done */
|
/* done */
|
||||||
rtl_uString_release(pname);
|
rtl_uString_release(pname);
|
||||||
(*env)->MonitorExit(env, obj_this);
|
(*env)->MonitorExit(env, obj_this);
|
||||||
|
osl_freeSecurityHandle(psec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (state)
|
switch (state)
|
||||||
@@ -202,6 +251,7 @@ JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_cre
|
|||||||
case INMONITOR:
|
case INMONITOR:
|
||||||
(*env)->MonitorExit(env, obj_this);
|
(*env)->MonitorExit(env, obj_this);
|
||||||
case START:
|
case START:
|
||||||
|
osl_freeSecurityHandle(psec);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -229,23 +279,46 @@ JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_clo
|
|||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
ThrowRT_If(((*env)->MonitorEnter(env, obj_this) != 0),
|
if ((*env)->MonitorEnter(env, obj_this) != 0)
|
||||||
env, "native pipe cannot synchronize on the object");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe cannot synchronize on the object");
|
||||||
|
break;
|
||||||
|
}
|
||||||
state = INMONITOR;
|
state = INMONITOR;
|
||||||
|
|
||||||
/* check connection state */
|
/* check connection state */
|
||||||
npipe = getPipe(env, obj_this);
|
npipe = getPipe(env, obj_this);
|
||||||
Throw_IfException(env);
|
if ((*env)->ExceptionOccurred(env) != NULL)
|
||||||
ThrowIO_If((npipe == NULL),
|
break;
|
||||||
env, "native pipe is not connected");
|
if (npipe == NULL)
|
||||||
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"com/sun/star/io/IOException",
|
||||||
|
"native pipe is not connected");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* remove the reference to the pipe */
|
/* remove the reference to the pipe */
|
||||||
tclass = (*env)->GetObjectClass(env, obj_this);
|
tclass = (*env)->GetObjectClass(env, obj_this);
|
||||||
ThrowRT_If((tclass == NULL),
|
if (tclass == NULL)
|
||||||
env, "native pipe cannot find class");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe cannot find class");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J");
|
fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J");
|
||||||
ThrowRT_If((fid == NULL),
|
if (fid == NULL)
|
||||||
env, "native pipe cannot find field");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe cannot find field");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
(*env)->SetLongField(env, obj_this, fid, (jlong)0);
|
(*env)->SetLongField(env, obj_this, fid, (jlong)0);
|
||||||
|
|
||||||
/* release the pipe */
|
/* release the pipe */
|
||||||
@@ -292,23 +365,40 @@ JNIEXPORT jint JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_rea
|
|||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
/* enter monitor */
|
/* enter monitor */
|
||||||
ThrowRT_If(((*env)->MonitorEnter(env, obj_this) != 0),
|
if ((*env)->MonitorEnter(env, obj_this) != 0)
|
||||||
env, "native pipe cannot synchronize on the object");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe cannot synchronize on the object");
|
||||||
|
break;
|
||||||
|
}
|
||||||
state = INMONITOR;
|
state = INMONITOR;
|
||||||
|
|
||||||
/* check connection state */
|
/* check connection state */
|
||||||
npipe = getPipe(env, obj_this);
|
npipe = getPipe(env, obj_this);
|
||||||
Throw_IfException(env);
|
if ((*env)->ExceptionOccurred(env) != NULL)
|
||||||
ThrowIO_If((npipe == NULL),
|
break;
|
||||||
env, "native pipe is not connected");
|
if (npipe == NULL)
|
||||||
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"com/sun/star/io/IOException",
|
||||||
|
"native pipe is not connected");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* aquire pipe */
|
/* aquire pipe */
|
||||||
osl_acquirePipe( npipe );
|
osl_acquirePipe( npipe );
|
||||||
state = AQUIRED;
|
state = AQUIRED;
|
||||||
|
|
||||||
/* allocate a buffer */
|
/* allocate a buffer */
|
||||||
ThrowRT_If(((nbuff = malloc(len)) == NULL),
|
if ((nbuff = malloc(len)) == NULL)
|
||||||
env, "native pipe out of memory");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe out of memory");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
state = GOTBUFFER;
|
state = GOTBUFFER;
|
||||||
|
|
||||||
/* exit monitor */
|
/* exit monitor */
|
||||||
@@ -318,15 +408,26 @@ JNIEXPORT jint JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_rea
|
|||||||
nread = osl_readPipe(npipe, nbuff, len);
|
nread = osl_readPipe(npipe, nbuff, len);
|
||||||
|
|
||||||
/* enter monitor again */
|
/* enter monitor again */
|
||||||
ThrowRT_If(((*env)->MonitorEnter(env, obj_this) != 0),
|
if ((*env)->MonitorEnter(env, obj_this) != 0)
|
||||||
env, "native pipe cannot synchronize on the object");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe cannot synchronize on the object");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* copy buffer */
|
/* copy buffer */
|
||||||
if (nread >= 0)
|
if (nread >= 0)
|
||||||
{
|
{
|
||||||
bytes = (*env)->NewByteArray(env, len);
|
bytes = (*env)->NewByteArray(env, len);
|
||||||
ThrowRT_If((bytes == NULL),
|
if (bytes == NULL)
|
||||||
env, "native pipe out of memory");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe out of memory");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* save the data */
|
/* save the data */
|
||||||
(*env)->SetByteArrayRegion(env, bytes, 0, len, nbuff);
|
(*env)->SetByteArrayRegion(env, bytes, 0, len, nbuff);
|
||||||
(*env)->SetObjectArrayElement(env, buffer, 0, bytes);
|
(*env)->SetObjectArrayElement(env, buffer, 0, bytes);
|
||||||
@@ -378,28 +479,57 @@ JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_wri
|
|||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
ThrowRT_If(((*env)->MonitorEnter(env, obj_this) != 0),
|
if ((*env)->MonitorEnter(env, obj_this) != 0)
|
||||||
env, "native pipe cannot synchronize on the object");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe cannot synchronize on the object");
|
||||||
|
break;
|
||||||
|
}
|
||||||
state = INMONITOR;
|
state = INMONITOR;
|
||||||
|
|
||||||
/* check connection state */
|
/* check connection state */
|
||||||
npipe = getPipe(env, obj_this);
|
npipe = getPipe(env, obj_this);
|
||||||
Throw_IfException(env);
|
if ((*env)->ExceptionOccurred(env) != NULL)
|
||||||
ThrowIO_If((npipe == NULL),
|
break;
|
||||||
env, "native pipe is not connected");
|
if (npipe == NULL)
|
||||||
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"com/sun/star/io/IOException",
|
||||||
|
"native pipe is not connected");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
nwrite = (*env)->GetArrayLength(env, buffer);
|
nwrite = (*env)->GetArrayLength(env, buffer);
|
||||||
if (nwrite > 0)
|
if (nwrite > 0)
|
||||||
{
|
{
|
||||||
nbuff = (*env)->GetByteArrayElements(env, buffer, NULL);
|
nbuff = (*env)->GetByteArrayElements(env, buffer, NULL);
|
||||||
ThrowRT_If((nbuff == NULL),
|
if (nbuff == NULL)
|
||||||
env, "native pipe out of memory");
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe out of memory");
|
||||||
|
break;
|
||||||
|
}
|
||||||
state = GOTBUFFER;
|
state = GOTBUFFER;
|
||||||
|
|
||||||
(*env)->MonitorExit(env, obj_this);
|
(*env)->MonitorExit(env, obj_this);
|
||||||
/* writing */
|
/* writing */
|
||||||
count = osl_writePipe(npipe, nbuff, nwrite);
|
count = osl_writePipe(npipe, nbuff, nwrite);
|
||||||
ThrowRT_If(((*env)->MonitorEnter(env, obj_this) != 0),
|
if ((*env)->MonitorEnter(env, obj_this) != 0)
|
||||||
env, "native pipe cannot synchronize on the object");
|
{
|
||||||
ThrowIO_If((count != nwrite),
|
ThrowException(env,
|
||||||
env, "native pipe is failed to write");
|
"java/lang/RuntimeException",
|
||||||
|
"native pipe cannot synchronize on the object");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (count != nwrite)
|
||||||
|
{
|
||||||
|
ThrowException(env,
|
||||||
|
"com/sun/star/io/IOException",
|
||||||
|
"native pipe is failed to write");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* done */
|
/* done */
|
||||||
(*env)->ReleaseByteArrayElements(env, buffer, nbuff, JNI_ABORT);
|
(*env)->ReleaseByteArrayElements(env, buffer, nbuff, JNI_ABORT);
|
||||||
|
Reference in New Issue
Block a user