Note that there are some explanatory texts on larger screens.

plurals
  1. POjava will intermittently not resolve symlinks on Linux
    primarykey
    data
    text
    <p>I'm trying to resolve canonical paths for all the files in a folder tree, but for some reason it will not resolve them (and intermittently the JVM security code will resolve the symlink properly within the FilePermission and cause a security error).</p> <p>Env:</p> <pre><code>$ java -version java version "1.6.0_23" OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.2) OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode) </code></pre> <p>A known symlink in the system is /usr/share/java/gnome-java-bridge.jar:</p> <pre><code>$ ls -l /usr/lib/jvm/java-6-openjdk/jre/lib/ext/gnome-java-bridge.jar lrwxrwxrwx 1 root root 50 2012-02-24 13:39 /usr/lib/jvm/java-6-openjdk/jre/lib/ext/gnome-java-bridge.jar -&gt; ../../../../../../share/java/gnome-java-bridge.jar </code></pre> <p>The following code should resolve this known symlink:</p> <pre><code>String symlinkedFilePath = "/usr/lib/jvm/java-6-openjdk/jre/lib/ext/gnome-java-bridge.jar"; File symlinkedFile = new File(symlinkedFilePath); System.out.println(symlinkedFile.getAbsolutePath()); System.out.println(symlinkedFile.getCanonicalPath()); </code></pre> <p>but produces:</p> <pre><code>/usr/lib/jvm/java-6-openjdk/jre/lib/ext/gnome-java-bridge.jar /usr/lib/jvm/java-6-openjdk/jre/lib/ext/gnome-java-bridge.jar </code></pre> <p>A further test, using the following code, will sometimes return true for the permission check, but sometimes will return false:</p> <pre><code>String symlinkedFilePath = "/usr/lib/jvm/java-6-openjdk/jre/lib/ext/gnome-java-bridge.jar"; File symlinkedFile = new File(symlinkedFilePath); FilePermission recursivePermission = new FilePermission( symlinkedFile.getParentFile().getParent() + "/-", "read"); FilePermission filePermission = new FilePermission( symlinkedFile.getAbsolutePath(), "read"); System.out.println(recursivePermission); System.out.println(filePermission); System.out.println( "Can read symlink: " + recursivePermission.implies(filePermission)); </code></pre> <p>The typical result is:</p> <pre><code>(java.io.FilePermission /usr/lib/jvm/java-6-openjdk/jre/lib/- read) (java.io.FilePermission /usr/lib/jvm/java-6-openjdk/jre/lib/ext/gnome-java-bridge.jar read) Can read symlink: true </code></pre> <p>but when debugging, if I step through the creation of the FilePermission on the target file, internally the path is resolved to the symlink, and the output results in:</p> <pre><code>(java.io.FilePermission /usr/lib/jvm/java-6-openjdk/jre/lib/- read) (java.io.FilePermission /usr/lib/jvm/java-6-openjdk/jre/lib/ext/gnome-java-bridge.jar read) Can read symlink: false </code></pre> <p>The problem is that within the context of the app in which the permission checking actually takes place, the symlink is always resolved by the FilePermission object, but never by my own calls to file.getCanonicalPath() as demonstrated above.</p> <p>Does this make sense to anyone?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload