Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ else if ( m_trashDir.isFile())
throw new DeviceContextException("Trashcan path is not a folder - " + m_trashDir.getAbsolutePath());

// Make sure the trashcan folder is on the same volume as the shared folder, so we can rename deleted files
if ( rootDir.getParent().equalsIgnoreCase( m_trashDir.getParent()) == false) {
if (!isTrashcanOnSameVolume(rootDir, m_trashDir)) {

// File share and trash folders are not on the same volume
throw new DeviceContextException("File share and trash folders must be on the same volume");
Expand Down Expand Up @@ -169,6 +169,24 @@ else if ( m_trashDir.isFile())
}
}

/**
* Validate that the trashcan folder resides on the same volume as the shared
* folder. This is a requirement because we want to be able to move files into
* the trashcan by simply renaming them.
* <p>
* The default implementation only uses a simple heuristic, override this method
* to provide a more advanced platform-specific check if required.
*
* @param rootDir The root directory of the shared folder
* @param trashCan The proposed trashcan directory
* @return True if the proposed trashcan directory is acceptable, false to
* signal an error
*/
protected boolean isTrashcanOnSameVolume(File rootDir, File trashCan) {
return trashCan.getAbsolutePath().startsWith(rootDir.getAbsolutePath())
|| rootDir.getParent().equalsIgnoreCase(m_trashDir.getParent());
}

/**
* Check if the trashcan folder is configured
*
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/org/filesys/smb/server/disk/JavaNIODiskDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ public DeviceContext createContext(String shareName, ConfigElement args)
throws DeviceContextException {

// Parse the configuration and return the device context for this share
JavaNIODeviceContext ctx = new JavaNIODeviceContext( shareName, args);
JavaNIODeviceContext ctx = createJavaNIODeviceContext(shareName, args);

// If the trashcan folder is configured then check if there are any trash files left over from a previous
// server run
Expand Down Expand Up @@ -1063,6 +1063,20 @@ public void run() {
return ctx;
}

/**
* Provide a new <code>JavaNIODeviceContext</code> for
* <code>createContext</code> Override this method to provide your own class.
*
* @param shareName
* @param args
* @return DeviceContext
* @throws DeviceContextException Error creating the device context
*/
protected JavaNIODeviceContext createJavaNIODeviceContext(String shareName, ConfigElement args)
throws DeviceContextException {
return new JavaNIODeviceContext(shareName, args);
}

/**
* Connection opened to this disk device
*
Expand Down