mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Added custom I/O control support to the CIFS server to support the client
side Windows application to expose repo specific functions such as check in/out. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2058 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -48,8 +48,6 @@ public final class FileName
|
||||
public static String buildPath(String dev, String path, String filename, char sep)
|
||||
{
|
||||
|
||||
// Debug.println ( "BuildPath: dev=" + dev + ", path=" + path + ",filename=" + filename);
|
||||
|
||||
// Build the path string
|
||||
|
||||
StringBuffer fullPath = new StringBuffer();
|
||||
@@ -102,10 +100,6 @@ public final class FileName
|
||||
fullPath.append(filename);
|
||||
}
|
||||
|
||||
// Debug
|
||||
|
||||
// Debug.println ( "BuildPath: " + fullPath.toString ());
|
||||
|
||||
// Convert the file seperator characters in the path if we are not using the normal
|
||||
// DOS file seperator character.
|
||||
|
||||
|
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
package org.alfresco.filesys.server.filesys;
|
||||
|
||||
/**
|
||||
* I/O Control Not Implemented Exception Class
|
||||
*
|
||||
* <p>This exception may be thrown by an IOCtlInterface implementation.
|
||||
*
|
||||
* @author gkspencer
|
||||
*/
|
||||
public class IOControlNotImplementedException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = -7107739317519497749L;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public IOControlNotImplementedException()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param s java.lang.String
|
||||
*/
|
||||
public IOControlNotImplementedException(String s)
|
||||
{
|
||||
super(s);
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
package org.alfresco.filesys.server.filesys;
|
||||
|
||||
import org.alfresco.filesys.server.SrvSession;
|
||||
import org.alfresco.filesys.smb.SMBException;
|
||||
import org.alfresco.filesys.util.DataBuffer;
|
||||
|
||||
/**
|
||||
* IO Control Interface
|
||||
*
|
||||
* <p>Optional interface that a DiskInterface driver can implement to enable NT I/O control function
|
||||
* processing.
|
||||
*
|
||||
* @author gkspencer
|
||||
*/
|
||||
public interface IOCtlInterface
|
||||
{
|
||||
/**
|
||||
* Process a filesystem I/O control request
|
||||
*
|
||||
* @param sess Server session
|
||||
* @param tree Tree connection.
|
||||
* @param ctrlCode I/O control code
|
||||
* @param fid File id
|
||||
* @param dataBuf I/O control specific input data
|
||||
* @param isFSCtrl true if this is a filesystem control, or false for a device control
|
||||
* @param filter if bit0 is set indicates that the control applies to the share root handle
|
||||
* @return DataBuffer
|
||||
* @exception IOControlNotImplementedException
|
||||
* @exception SMBException
|
||||
*/
|
||||
public DataBuffer processIOControl(SrvSession sess, TreeConnection tree, int ctrlCode, int fid, DataBuffer dataBuf,
|
||||
boolean isFSCtrl, int filter) throws IOControlNotImplementedException, SMBException;
|
||||
}
|
@@ -151,6 +151,10 @@ public class NTIOCtl
|
||||
public static final int FsCtlWriteUsnCloseRecord = 59;
|
||||
public static final int FsCtlExtendVolume = 60;
|
||||
|
||||
// Base value for custom control codes
|
||||
|
||||
public static final int FsCtlCustom = 0x800;
|
||||
|
||||
/**
|
||||
* Extract the device type from an I/O control code
|
||||
*
|
||||
|
@@ -47,6 +47,8 @@ import org.alfresco.filesys.server.filesys.FileOpenParams;
|
||||
import org.alfresco.filesys.server.filesys.FileSharingException;
|
||||
import org.alfresco.filesys.server.filesys.FileStatus;
|
||||
import org.alfresco.filesys.server.filesys.FileSystem;
|
||||
import org.alfresco.filesys.server.filesys.IOControlNotImplementedException;
|
||||
import org.alfresco.filesys.server.filesys.IOCtlInterface;
|
||||
import org.alfresco.filesys.server.filesys.NetworkFile;
|
||||
import org.alfresco.filesys.server.filesys.NotifyChange;
|
||||
import org.alfresco.filesys.server.filesys.PathNotFoundException;
|
||||
@@ -69,6 +71,7 @@ import org.alfresco.filesys.smb.NTTime;
|
||||
import org.alfresco.filesys.smb.PCShare;
|
||||
import org.alfresco.filesys.smb.PacketType;
|
||||
import org.alfresco.filesys.smb.SMBDate;
|
||||
import org.alfresco.filesys.smb.SMBException;
|
||||
import org.alfresco.filesys.smb.SMBStatus;
|
||||
import org.alfresco.filesys.smb.WinNT;
|
||||
import org.alfresco.filesys.smb.server.notify.NotifyChangeEventList;
|
||||
@@ -476,7 +479,8 @@ public class NTProtocolHandler extends CoreProtocolHandler
|
||||
logger.debug("NT Session setup from user=" + user + ", password="
|
||||
+ (uniPwd != null ? HexDump.hexString(uniPwd) : "none") + ", ANSIpwd="
|
||||
+ (ascPwd != null ? HexDump.hexString(ascPwd) : "none") + ", domain=" + domain + ", os=" + clientOS
|
||||
+ ", VC=" + vcNum + ", maxBuf=" + maxBufSize + ", maxMpx=" + maxMpx);
|
||||
+ ", VC=" + vcNum + ", maxBuf=" + maxBufSize + ", maxMpx=" + maxMpx
|
||||
+ ", challenge=" + HexDump.hexString(m_sess.getChallengeKey()));
|
||||
logger.debug(" MID=" + m_smbPkt.getMultiplexId() + ", UID=" + m_smbPkt.getUserId() + ", PID="
|
||||
+ m_smbPkt.getProcessId());
|
||||
}
|
||||
@@ -6639,16 +6643,99 @@ public class NTProtocolHandler extends CoreProtocolHandler
|
||||
int treeId = tbuf.getTreeId();
|
||||
TreeConnection conn = m_sess.findConnection(treeId);
|
||||
|
||||
if (conn == null)
|
||||
{
|
||||
if (conn == null) {
|
||||
m_sess.sendErrorResponseSMB(SMBStatus.NTInvalidParameter, SMBStatus.DOSInvalidDrive, SMBStatus.ErrDos);
|
||||
return;
|
||||
}
|
||||
|
||||
// Unpack the request details
|
||||
|
||||
DataBuffer setupBuf = tbuf.getSetupBuffer();
|
||||
|
||||
int ctrlCode = setupBuf.getInt();
|
||||
int fid = setupBuf.getShort();
|
||||
boolean fsctrl = setupBuf.getByte() == 1 ? true : false;
|
||||
int filter = setupBuf.getByte();
|
||||
|
||||
// Debug
|
||||
|
||||
if (logger.isDebugEnabled() && m_sess.hasDebug(SMBSrvSession.DBG_TRAN))
|
||||
logger.debug("NT IOCtl code=" + NTIOCtl.asString(ctrlCode) + ", fid=" + fid + ", fsctrl=" + fsctrl + ", filter=" + filter);
|
||||
|
||||
// Access the disk interface that is associated with the shared device
|
||||
|
||||
DiskInterface disk = null;
|
||||
try {
|
||||
|
||||
// Get the disk interface for the share
|
||||
|
||||
disk = (DiskInterface) conn.getSharedDevice().getInterface();
|
||||
}
|
||||
catch (InvalidDeviceInterfaceException ex) {
|
||||
|
||||
// Failed to get/initialize the disk interface
|
||||
|
||||
m_sess.sendErrorResponseSMB(SMBStatus.NTInvalidParameter, SMBStatus.DOSInvalidData, SMBStatus.ErrDos);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the disk interface implements the optional IO control interface
|
||||
|
||||
if ( disk instanceof IOCtlInterface) {
|
||||
|
||||
// Access the IO control interface
|
||||
|
||||
IOCtlInterface ioControl = (IOCtlInterface) disk;
|
||||
|
||||
try {
|
||||
|
||||
// Pass the request to the IO control interface for processing
|
||||
|
||||
DataBuffer response = ioControl.processIOControl(m_sess, conn, ctrlCode, fid, tbuf.getDataBuffer(), fsctrl, filter);
|
||||
|
||||
// Pack the response
|
||||
|
||||
if ( response != null) {
|
||||
|
||||
// Pack the response data block
|
||||
|
||||
outPkt.initTransactReply(null, 0, response.getBuffer(), response.getLength(), 1);
|
||||
outPkt.setSetupParameter(0, response.getLength());
|
||||
}
|
||||
else {
|
||||
|
||||
// Pack an empty response data block
|
||||
|
||||
outPkt.initTransactReply(null, 0, null, 0, 1);
|
||||
outPkt.setSetupParameter(0, 0);
|
||||
}
|
||||
}
|
||||
catch (IOControlNotImplementedException ex) {
|
||||
|
||||
// Return a not implemented error status
|
||||
|
||||
m_sess.sendErrorResponseSMB(SMBStatus.NTNotImplemented, SMBStatus.SRVInternalServerError, SMBStatus.ErrSrv);
|
||||
return;
|
||||
}
|
||||
catch (SMBException ex) {
|
||||
|
||||
// Return the specified SMB status, this should be an NT status code
|
||||
|
||||
m_sess.sendErrorResponseSMB(ex.getErrorCode(), SMBStatus.SRVInternalServerError, SMBStatus.ErrSrv);
|
||||
return;
|
||||
}
|
||||
|
||||
// Send the IOCtl response
|
||||
|
||||
m_sess.sendResponseSMB(outPkt);
|
||||
}
|
||||
else {
|
||||
|
||||
// Send back an error, IOctl not supported
|
||||
|
||||
m_sess.sendErrorResponseSMB(SMBStatus.NTNotImplemented, SMBStatus.SRVNotSupported, SMBStatus.ErrSrv);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an NT query security descriptor transaction
|
||||
|
@@ -25,10 +25,12 @@ import javax.transaction.UserTransaction;
|
||||
import org.alfresco.config.ConfigElement;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.filesys.server.SrvSession;
|
||||
import org.alfresco.filesys.server.auth.SrvAuthenticator;
|
||||
import org.alfresco.filesys.server.core.DeviceContext;
|
||||
import org.alfresco.filesys.server.core.DeviceContextException;
|
||||
import org.alfresco.filesys.server.filesys.AccessDeniedException;
|
||||
import org.alfresco.filesys.server.filesys.AccessMode;
|
||||
import org.alfresco.filesys.server.filesys.DiskDeviceContext;
|
||||
import org.alfresco.filesys.server.filesys.DiskInterface;
|
||||
import org.alfresco.filesys.server.filesys.FileInfo;
|
||||
import org.alfresco.filesys.server.filesys.FileName;
|
||||
@@ -36,13 +38,24 @@ import org.alfresco.filesys.server.filesys.FileOpenParams;
|
||||
import org.alfresco.filesys.server.filesys.FileSharingException;
|
||||
import org.alfresco.filesys.server.filesys.FileStatus;
|
||||
import org.alfresco.filesys.server.filesys.FileSystem;
|
||||
import org.alfresco.filesys.server.filesys.IOControlNotImplementedException;
|
||||
import org.alfresco.filesys.server.filesys.IOCtlInterface;
|
||||
import org.alfresco.filesys.server.filesys.NetworkFile;
|
||||
import org.alfresco.filesys.server.filesys.NotifyChange;
|
||||
import org.alfresco.filesys.server.filesys.SearchContext;
|
||||
import org.alfresco.filesys.server.filesys.SrvDiskInfo;
|
||||
import org.alfresco.filesys.server.filesys.TreeConnection;
|
||||
import org.alfresco.filesys.smb.NTIOCtl;
|
||||
import org.alfresco.filesys.smb.SMBException;
|
||||
import org.alfresco.filesys.smb.SMBStatus;
|
||||
import org.alfresco.filesys.smb.SharingMode;
|
||||
import org.alfresco.filesys.smb.server.repo.FileState.FileStateStatus;
|
||||
import org.alfresco.filesys.util.DataBuffer;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
import org.alfresco.service.cmr.lock.LockType;
|
||||
import org.alfresco.service.cmr.lock.NodeLockedException;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
@@ -62,12 +75,18 @@ import org.apache.commons.logging.LogFactory;
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class ContentDiskDriver implements DiskInterface
|
||||
public class ContentDiskDriver implements DiskInterface, IOCtlInterface
|
||||
{
|
||||
// Logging
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ContentDiskDriver.class);
|
||||
|
||||
// Configuration key names
|
||||
|
||||
private static final String KEY_STORE = "store";
|
||||
private static final String KEY_ROOT_PATH = "rootPath";
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ContentDiskDriver.class);
|
||||
// Services and helpers
|
||||
|
||||
private CifsHelper cifsHelper;
|
||||
private TransactionService transactionService;
|
||||
@@ -77,6 +96,11 @@ public class ContentDiskDriver implements DiskInterface
|
||||
private SearchService unprotectedSearchService;
|
||||
private ContentService contentService;
|
||||
private PermissionService permissionService;
|
||||
private CheckOutCheckInService checkInOutService;
|
||||
|
||||
// I/O control handler
|
||||
|
||||
private IOControlHandler m_ioHandler;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
@@ -147,6 +171,16 @@ public class ContentDiskDriver implements DiskInterface
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the check in/out service
|
||||
*
|
||||
* @param checkInOutService CheckOutCheckInService
|
||||
*/
|
||||
public void setCheckInOutService(CheckOutCheckInService checkInOutService)
|
||||
{
|
||||
this.checkInOutService = checkInOutService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and validate the parameter string and create a device context object for this instance
|
||||
* of the shared device. The same DeviceInterface implementation may be used for multiple
|
||||
@@ -261,6 +295,30 @@ public class ContentDiskDriver implements DiskInterface
|
||||
}
|
||||
}
|
||||
|
||||
// Load the I/O control handler, if available
|
||||
|
||||
try
|
||||
{
|
||||
// Load the I/O control handler class
|
||||
|
||||
Object ioctlObj = Class.forName("org.alfresco.filesys.server.smb.repo.ContentIOControlHandler").newInstance();
|
||||
|
||||
// Verify that the class is an I/O control interface
|
||||
|
||||
if ( ioctlObj instanceof IOControlHandler)
|
||||
{
|
||||
// Set the I/O control handler, and initialize
|
||||
|
||||
m_ioHandler = (IOControlHandler) ioctlObj;
|
||||
m_ioHandler.initialize( this, cifsHelper, transactionService, nodeService, checkInOutService);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if ( logger.isDebugEnabled())
|
||||
logger.debug("No I/O control handler available");
|
||||
}
|
||||
|
||||
// Return the context for this shared filesystem
|
||||
|
||||
return context;
|
||||
@@ -1464,7 +1522,7 @@ public class ContentDiskDriver implements DiskInterface
|
||||
* @return NodeRef
|
||||
* @exception FileNotFoundException
|
||||
*/
|
||||
private NodeRef getNodeForPath(TreeConnection tree, String path)
|
||||
public NodeRef getNodeForPath(TreeConnection tree, String path)
|
||||
throws FileNotFoundException
|
||||
{
|
||||
// Check if there is a cached state for the path
|
||||
@@ -1516,4 +1574,36 @@ public class ContentDiskDriver implements DiskInterface
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a filesystem I/O control request
|
||||
*
|
||||
* @param sess Server session
|
||||
* @param tree Tree connection.
|
||||
* @param ctrlCode I/O control code
|
||||
* @param fid File id
|
||||
* @param dataBuf I/O control specific input data
|
||||
* @param isFSCtrl true if this is a filesystem control, or false for a device control
|
||||
* @param filter if bit0 is set indicates that the control applies to the share root handle
|
||||
* @return DataBuffer
|
||||
* @exception IOControlNotImplementedException
|
||||
* @exception SMBException
|
||||
*/
|
||||
public DataBuffer processIOControl(SrvSession sess, TreeConnection tree, int ctrlCode, int fid, DataBuffer dataBuf,
|
||||
boolean isFSCtrl, int filter)
|
||||
throws IOControlNotImplementedException, SMBException
|
||||
{
|
||||
// Validate the file id
|
||||
|
||||
NetworkFile netFile = tree.findFile(fid);
|
||||
if ( netFile == null || netFile.isDirectory() == false)
|
||||
throw new SMBException(SMBStatus.NTErr, SMBStatus.NTInvalidParameter);
|
||||
|
||||
// Check if the I/O control handler is enabled
|
||||
|
||||
if ( m_ioHandler != null)
|
||||
return m_ioHandler.processIOControl( sess, tree, ctrlCode, fid, dataBuf, isFSCtrl, filter);
|
||||
else
|
||||
throw new IOControlNotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
package org.alfresco.filesys.smb.server.repo;
|
||||
|
||||
import org.alfresco.filesys.server.filesys.IOCtlInterface;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
|
||||
/**
|
||||
* I/O Control Handler Interface
|
||||
*
|
||||
* @author gkspencer
|
||||
*/
|
||||
public interface IOControlHandler extends IOCtlInterface
|
||||
{
|
||||
/**
|
||||
* Initialize the I/O control handler
|
||||
*
|
||||
*
|
||||
* @param contentDriver ContentDiskDriver
|
||||
* @param cifsHelper CifsHelper
|
||||
* @param transService TransactionService
|
||||
* @param nodeService NodeService
|
||||
* @param cociService CheckOutCheckInService
|
||||
*/
|
||||
public void initialize( ContentDiskDriver contentDriver, CifsHelper cifsHelper,
|
||||
TransactionService transService, NodeService nodeService, CheckOutCheckInService cociService);
|
||||
}
|
@@ -254,8 +254,12 @@ public class DataBuffer
|
||||
maxlen = availLen;
|
||||
|
||||
ret = DataPacker.getUnicodeString(m_data, m_pos, maxlen);
|
||||
if (ret != null)
|
||||
if (ret != null) {
|
||||
if ( ret.length() < maxlen)
|
||||
m_pos += (ret.length() * 2) + 2;
|
||||
else
|
||||
m_pos += maxlen * 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -269,8 +273,12 @@ public class DataBuffer
|
||||
// Unpack the ASCII string
|
||||
|
||||
ret = DataPacker.getString(m_data, m_pos, maxlen);
|
||||
if (ret != null)
|
||||
if (ret != null) {
|
||||
if ( ret.length() < maxlen)
|
||||
m_pos += ret.length() + 1;
|
||||
else
|
||||
m_pos += maxlen;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the string
|
||||
|
Reference in New Issue
Block a user