You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/11/21 10:23:20 UTC

svn commit: r882865 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/io/Directory.java native/os/unix/dir.c native/os/win32/dir.c

Author: mturk
Date: Sat Nov 21 09:23:10 2009
New Revision: 882865

URL: http://svn.apache.org/viewvc?rev=882865&view=rev
Log:
Add Directory.changeRoot. Currently same as chdir on Windows

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java
    commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java?rev=882865&r1=882864&r2=882865&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java Sat Nov 21 09:23:10 2009
@@ -242,4 +242,15 @@
         }
     }
 
+    public static native int chroot0(String path)
+        throws IOException;
+    public static void changeRoot(Path path)
+        throws IOException
+    {
+        int rc = chroot0(path.toString());
+        if (rc != 0) {
+            throw new IOException(Status.describe(rc));
+        }
+    }
+
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c?rev=882865&r1=882864&r2=882865&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c Sat Nov 21 09:23:10 2009
@@ -307,3 +307,18 @@
 
     return rv;
 }
+
+ACR_IO_EXPORT_DECLARE(jint, Directory, chroot0)(ACR_JNISTDARGS, jstring path)
+{
+    int rv = ACR_EINVAL;
+
+    UNREFERENCED_O;
+    WITH_ZCSTR(path) {
+        if (chroot(J2S(path)))
+            rv = ACR_GET_OS_ERROR();
+        else
+            rv = 0;
+    } END_WITH_CSTR(path);
+
+    return rv;
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c?rev=882865&r1=882864&r2=882865&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c Sat Nov 21 09:23:10 2009
@@ -310,3 +310,26 @@
 
     return rv;
 }
+
+ACR_IO_EXPORT_DECLARE(jint, Directory, chroot0)(ACR_JNISTDARGS, jstring path)
+{
+    int rv = ACR_EINVAL;
+
+    UNREFERENCED_O;
+    WITH_ZWPATH(path) {
+        if (!SetCurrentDirectoryW(J2W(path)))
+            rv = ACR_GET_OS_ERROR();
+        else {
+            /* ### Use this directory for path resolution
+             * by not allowing going above the root.
+             * This would require changing all of our file function
+             * that use WIN32 api and simply making sure to use this path
+             * as prefix. However standard Java file API would still allow
+             * to go outside this root.
+             */
+            rv = 0;
+        }
+    } END_WITH_WPATH(path);
+
+    return rv;
+}