RNI Security Sample

This sample is located in \Samples\Security\Rni.

Note   To use this sample, it is recommended that you have Microsoft® Visual C++® version 5.0 or higher installed.

Description
Using the Sample
Key Project Files
Technologies Demonstrated

Description

This sample demonstrates how to protect access to resources from native code. There are two ways to do this:

The first mechanism has the advantage of always being safe regardless of who declares the Java wrapper for the native code. Anyone can easily link to the native code, regardless of who authored it. If the native code is installed on the system, it is accessible to fully-trusted code. For this reason, initiating the security check from native code ensures complete safety.

Because calling a Java method to perform a security check may incur a performance penalty, some scenarios may prefer the second mechanism, which prevents calls from normal native code from being penalized. COM code that is not specifically written to be called from Java will prefer the second mechanism. The second mechanism has the disadvantage of being slightly less safe for the reason previously indicated.

This sample demonstrates both mechanisms for Raw Native Interface (RNI) calls. Microsoft® J/Direct™ calls to native APIs may have some measure of built-in security by optionally checking the stack for fully-trusted code at each invocation, but the same mechanisms demonstrated here may be applied to J/Direct as well as to performing more specific types of security checks.

Using the Sample

To compile the sample

Use the following command in the base directory \Samples\Security\Rni to build debug versions of the classes and native library:

Nmake

Use the following command to build release versions:

nmake BUILD=retail

Prebuilt binaries are in the \Samples\Security\Rni\Sample directory. Substitute \debug or \retail for \sample in step 1 to run the versions you have built.

To install the sample

The .dll must be somewhere on the path (you can use ".").

To run the sample

  1. Set the current directory to \Samples\Security\Rni\Sample.

  2. Run the sample using one of the following:

Key Project Files

Main.java

This file is the main class that demonstrates RNI security. This class extends Applet and implements Runnable. It checks security by attempting to load files.

MyRNIObject.java

This simple class contains the native RNI methods from Rnisamp.dll and a Java accessor method that uses them.

rnisamp.cpp

This file is the source for the RNI code that implements the file access functions in C.

Technologies Demonstrated

Security

RNI

This sample shows how to:

© 1999 Microsoft Corporation. All rights reserved. Terms of use.