NS_IMETHODIMP 
nsPluggableJVM::StartupJVM(const char *classPath, 
			   nsPluggableJVMStatus *status,
			   jlong sup)
{
  JavaVMInitArgs vm_args;
  jint res;
  OJI_LOG("nsPluggableJVM::StartupJVM");
  *status = nsPluggableJVMStatus_Failed;
  if (sup == nsnull) return NS_ERROR_FAILURE;
  const char* plugin_home = getenv("WFHOME");
  if (plugin_home == NULL) {
    OJI_LOG("Env variable JAVA_PLUGIN_HOME not set");
    return NS_ERROR_FAILURE;
  }
  if (NS_FAILED(loadPluginDLL(plugin_home))) 
    return NS_ERROR_FAILURE;
  memset(&vm_args, 0, sizeof(vm_args));
  vm_args.version = JNI_VERSION_1_2;
  // XXX: add classpath here
  if (NS_FAILED(initJVM(&m_ctx, &vm_args))) 
    return NS_ERROR_FAILURE;
  // initialize capability mechanism 
  JVMP_SecurityCap cap;
  JVMP_FORBID_ALL_CAPS(cap);
  JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_SYSTEM);
  JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_SYSEVENT)
  JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_EVENT);
  JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_CALL);
  jbyte** prins;
  jint    pnum = 2;
  jint*   plen;
  if (!newPrincipalsFromStrings(&prins, &plen, 
				pnum, "CAPS", "MOZILLA"))
    return JNI_FALSE;
  if ((m_jvmp_context->JVMP_EnableCapabilities)
      (m_ctx, &cap, pnum, plen, prins) != JNI_TRUE) 
    {
      OJI_LOG("Can\'t enable caps");
      return JNI_FALSE;
    };
  deletePrincipals(prins, plen, pnum);
  SetConsoleVisibility(PR_TRUE);
  char* ext_dll = PR_GetLibraryName(plugin_home, LIBEXT);
  OJI_LOG2("JVMP_RegisterExtension: %s", ext_dll);
  res = (m_jvmp_context->JVMP_RegisterExtension)(m_ctx, 
						 ext_dll,
						 &m_extID,
						 sup);
  PR_Free(ext_dll);
  if (res != JNI_TRUE || m_extID == 0) return NS_ERROR_FAILURE;  
  OJI_LOG("JVMP_RegisterExtension OK");
  *status = nsPluggableJVMStatus_Running;
  return NS_OK;
}
Example #2
0
void b7_handler(GtkWidget *widget) {
  JVMP_SecurityCap cap;
  static int onoff = 0;  
  
  if (!jvmp_context) return;
  onoff = !onoff;
  JVMP_FORBID_ALL_CAPS(cap);
  JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_SYSTEM);
  JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_EVENT);
  JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_SYSEVENT);
  if (onoff)
      {
	  jbyte** prins;
	  jint    pnum = 2;
	  jint*   plen;
	  if (!newPrincipalsFromStrings(&prins, &plen, 
					pnum, "CAPS", "DUMMY"))
	    return;
	  if ((jvmp_context->JVMP_EnableCapabilities)
	      (ctx, &cap, pnum, plen, prins) != JNI_TRUE) 
	      {
		  jvmp_context->JVMP_GetLastErrorString(ctx, g_errbuf);
		  fprintf(stderr, "Can\'t enable caps: %s\n", g_errbuf);
		  return;
	      };
	  deletePrincipals(prins, plen, pnum);
      }

  else
      {
	  if ((jvmp_context->JVMP_DisableCapabilities)
	      (ctx, &cap) != JNI_TRUE) 
	      {
		  jvmp_context->JVMP_GetLastErrorString(ctx, g_errbuf);
		  fprintf(stderr, "Can\'t disable cap: %s\n", g_errbuf);
		  return;
	      };
      }
      
  fprintf(stderr, "Capabilities JVMP_CAP_SYS_SYSTEM and JVMP_CAP_SYS_EVENT triggered to %s\n",
	  onoff ? "ON" : "OFF");
}
Example #3
0
JVMP_ShmRequest* JVMP_NewShmReq(int msg_id, unsigned int func_no)
{
  JVMP_ShmRequest* req;
  
  req = (JVMP_ShmRequest*)malloc(sizeof(JVMP_ShmRequest));
  if (!req) return NULL;
  req->rid = 0;
  req->argt = NULL;
  req->argc = 0;
  req->length = 0;
  req->data = NULL;
  req->func_no = func_no;
  req->retval = 0; /* determined later in JVMP_WaitConfirmShmRequest*/
  req->msg_id = msg_id;
  req->shmid = 0;
  req->shmdata = NULL;
  req->nullmask = 0;
  req->shmlen = 0;
  JVMP_FORBID_ALL_CAPS(req->caps);
  JVMP_ALLOW_CAP(req->caps, JVMP_CAP_SYS_PARITY); /* integrity bit */
  return req;
}