|
From: <ls...@us...> - 2009-03-29 07:49:11
|
Revision: 5176
http://jnode.svn.sourceforge.net/jnode/?rev=5176&view=rev
Author: lsantha
Date: 2009-03-29 07:49:07 +0000 (Sun, 29 Mar 2009)
Log Message:
-----------
Security fixes.
Modified Paths:
--------------
trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFSDirectory.java
trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFileSystem.java
trunk/fs/src/fs/org/jnode/fs/smbfs/SMBFileSystemType.java
trunk/shell/src/shell/org/jnode/shell/syntax/FileArgument.java
Modified: trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFSDirectory.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFSDirectory.java 2009-03-29 07:24:21 UTC (rev 5175)
+++ trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFSDirectory.java 2009-03-29 07:49:07 UTC (rev 5176)
@@ -27,6 +27,10 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
import com.enterprisedt.net.ftp.FTPFile;
@@ -64,16 +68,22 @@
private void ensureEntries() throws IOException {
try {
if (entries == null) {
- entries = new HashMap<String, FTPFSEntry>();
- FTPFile[] ftpFiles = null;
- synchronized (fileSystem) {
- ftpFiles = fileSystem.dirDetails(path());
- }
- for (FTPFile f : ftpFiles) {
- FTPFSEntry e = f.isDir() ? new FTPFSDirectory(fileSystem, f) : new FTPFSFile(fileSystem, f);
- e.setParent(this);
- entries.put(f.getName(), e);
- }
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+ @Override
+ public Object run() throws Exception {
+ entries = new HashMap<String, FTPFSEntry>();
+ FTPFile[] ftpFiles = null;
+ synchronized (fileSystem) {
+ ftpFiles = fileSystem.dirDetails(path());
+ }
+ for (FTPFile f : ftpFiles) {
+ FTPFSEntry e = f.isDir() ? new FTPFSDirectory(fileSystem, f) : new FTPFSFile(fileSystem, f);
+ e.setParent(FTPFSDirectory.this);
+ entries.put(f.getName(), e);
+ }
+ return null;
+ }
+ });
}
} catch (Exception e) {
e.printStackTrace();
Modified: trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFileSystem.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFileSystem.java 2009-03-29 07:24:21 UTC (rev 5175)
+++ trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFileSystem.java 2009-03-29 07:49:07 UTC (rev 5176)
@@ -48,7 +48,12 @@
FTPFileSystem(final FTPFSDevice device, final FTPFileSystemType type) {
this.type = type;
- this.client = new FTPClient();
+ this.client = AccessController.doPrivileged(new PrivilegedAction<FTPClient>(){
+ @Override
+ public FTPClient run() {
+ return new FTPClient();
+ }
+ });
this.device = device;
device.addListener(new DeviceListener() {
public void deviceStarted(Device device) {
Modified: trunk/fs/src/fs/org/jnode/fs/smbfs/SMBFileSystemType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/smbfs/SMBFileSystemType.java 2009-03-29 07:24:21 UTC (rev 5175)
+++ trunk/fs/src/fs/org/jnode/fs/smbfs/SMBFileSystemType.java 2009-03-29 07:49:07 UTC (rev 5176)
@@ -23,6 +23,8 @@
import org.jnode.driver.Device;
import org.jnode.fs.FileSystemException;
import org.jnode.fs.FileSystemType;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
/**
* @author Levente S\u00e1ntha
@@ -31,8 +33,14 @@
public static final Class<SMBFileSystemType> ID = SMBFileSystemType.class;
static {
- System.setProperty("jcifs.smb.client.attrExpirationPeriod", "10");
- System.setProperty("jcifs.smb.client.responseTimeout", "10000");
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
+ public Object run() {
+ System.setProperty("jcifs.smb.client.attrExpirationPeriod", "10");
+ System.setProperty("jcifs.smb.client.responseTimeout", "10000");
+ return null;
+ }
+ });
}
/**
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/FileArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/FileArgument.java 2009-03-29 07:24:21 UTC (rev 5175)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/FileArgument.java 2009-03-29 07:49:07 UTC (rev 5176)
@@ -17,7 +17,7 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.shell.syntax;
import java.io.File;
@@ -26,12 +26,13 @@
import org.jnode.driver.console.CompletionInfo;
import org.jnode.shell.CommandLine.Token;
+import sun.security.action.GetPropertyAction;
/**
* This argument class performs completion against the file system namespace. This
* Argument class understands the {@link Argument#EXISTING} and {@link Argument#NONEXISTENT}
* flags when accepting argument values, but not (yet) when completing them.
- *
+ *
* @author cr...@jn...
*/
public class FileArgument extends Argument<File> {
@@ -61,7 +62,7 @@
}
@Override
- public void complete(CompletionInfo completion, String partial) {
+ public void complete(final CompletionInfo completion, final String partial) {
// Get last full directory from the partial pathname.
final int idx = partial.lastIndexOf(File.separatorChar);
final String dir;
@@ -76,34 +77,41 @@
// Get the contents of that directory. (Note that the call to getProperty()
// is needed because new File("").exists() returns false. According to Sun, this
// behavior is "not a bug".)
- final File f = dir.isEmpty() ? new File(System.getProperty("user.dir")) : new File(dir);
+ String user_dir = AccessController.doPrivileged(new GetPropertyAction("user.dir"));
+ final File f = dir.isEmpty() ? new File(user_dir) : new File(dir);
final String[] names = AccessController.doPrivileged(
- new PrivilegedAction <String[]>() {
- public String[] run() {
- if (!f.exists()) {
- return null;
- } else {
- return f.list();
- }
+ new PrivilegedAction<String[]>() {
+ public String[] run() {
+ if (!f.exists()) {
+ return null;
+ } else {
+ return f.list();
}
- });
+ }
+ });
if (names == null) {
// The dir (or user.dir) denotes a non-existent directory.
// No completions are possible for this path name.
return;
}
- final String prefix =
- (dir.length() == 0) ? "" : dir.equals("/") ? "/" : dir + File.separatorChar;
- for (String n : names) {
- String name = prefix + n;
- if (name.startsWith(partial)) {
- if (new File(f, n).isDirectory()) {
- completion.addCompletion(name + File.separatorChar, true);
- } else {
- completion.addCompletion(name);
+ final String prefix = (dir.length() == 0) ? "" : dir.equals("/") ? "/" : dir + File.separatorChar;
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
+ public Object run() {
+ for (String n : names) {
+ String name = prefix + n;
+ if (name.startsWith(partial)) {
+ if (new File(f, n).isDirectory()) {
+ completion.addCompletion(name + File.separatorChar, true);
+ } else {
+ completion.addCompletion(name);
+ }
+ }
}
+ return null;
}
- }
+ });
+
// Completion of "." and ".." as the last pathname component have to be dealt with
// explicitly. The 'f.list()' call does not include "." and ".." in the result array.
int tmp = partial.length() - idx;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|