Merged 1.4 to HEAD

svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4313 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4314 .
   svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4317 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4318 .


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4656 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-12-19 14:28:55 +00:00
parent cfb373ae36
commit 488450a988
17 changed files with 1807 additions and 877 deletions

View File

@@ -31,12 +31,8 @@ import org.alfresco.filesys.netbios.RFCNetBIOSProtocol;
import org.alfresco.filesys.server.SrvSession;
import org.alfresco.filesys.server.auth.AuthenticatorException;
import org.alfresco.filesys.server.auth.CifsAuthenticator;
import org.alfresco.filesys.server.core.DeviceInterface;
import org.alfresco.filesys.server.core.SharedDevice;
import org.alfresco.filesys.server.filesys.DiskDeviceContext;
import org.alfresco.filesys.server.filesys.DiskInterface;
import org.alfresco.filesys.server.filesys.NetworkFile;
import org.alfresco.filesys.server.filesys.SearchContext;
import org.alfresco.filesys.server.filesys.TooManyConnectionsException;
import org.alfresco.filesys.server.filesys.TreeConnection;
import org.alfresco.filesys.smb.Capability;
@@ -80,15 +76,6 @@ public class SMBSrvSession extends SrvSession implements Runnable
public static final int DefaultConnections = 4;
public static final int MaxConnections = 16;
// Tree ids are 16bit values
private static final int TreeIdMask = 0x0000FFFF;
// Default and maximum number of search slots
private static final int DefaultSearches = 8;
private static final int MaxSearches = 256;
// Maximum multiplexed packets allowed (client can send up to this many SMBs before waiting for
// a response)
//
@@ -131,20 +118,6 @@ public class SMBSrvSession extends SrvSession implements Runnable
private String m_callerNBName;
private String m_targetNBName;
// Connected share list and next tree id
private Hashtable<Integer, TreeConnection> m_connections;
private int m_treeId;
// Active search list for this session
private SearchContext[] m_search;
private int m_searchCount;
// Active transaction details
private SrvTransactBuffer m_transact;
// Notify change requests and notifications pending flag
private NotifyRequestList m_notifyList;
@@ -173,9 +146,13 @@ public class SMBSrvSession extends SrvSession implements Runnable
private int m_clientCaps;
// Session setup object, temporarily stored by an authenticator when the authentication is multi-stage
// Virtual circuit list
private Object m_setupObject;
private VirtualCircuitList m_vcircuits;
// Setup objects used during two stage session setup before the virtual circuit is allocated
private Hashtable<Integer, Object> m_setupObjects;
// Debug flag values
@@ -233,6 +210,10 @@ public class SMBSrvSession extends SrvSession implements Runnable
if (handler.hasClientName())
m_callerNBName = handler.getClientName();
}
// Allocate the virtual circuit list
m_vcircuits = new VirtualCircuitList();
}
/**
@@ -246,201 +227,127 @@ public class SMBSrvSession extends SrvSession implements Runnable
}
/**
* Add a new connection to this session. Return the allocated tree id for the new connection.
* Find the tree connection for the request
*
* @return int Allocated tree id (connection id).
* @param shrDev SharedDevice
* @param smbPkt SMBSrvPacket
* @return TreeConnection
*/
protected int addConnection(SharedDevice shrDev) throws TooManyConnectionsException
{
public final TreeConnection findTreeConnection(SMBSrvPacket smbPkt) {
// Check if the connection array has been allocated
// Find the virtual circuit for the request
if (m_connections == null)
m_connections = new Hashtable<Integer, TreeConnection>(DefaultConnections);
TreeConnection tree = null;
VirtualCircuit vc = findVirtualCircuit( smbPkt.getUserId());
// Allocate an id for the tree connection
if (vc != null) {
int treeId = 0;
// Find the tree connection
synchronized (m_connections)
{
tree = vc.findConnection(smbPkt.getTreeId());
}
// Check if the tree connection table is full
if (m_connections.size() == MaxConnections)
throw new TooManyConnectionsException();
// Find a free slot in the connection array
treeId = (m_treeId++ & TreeIdMask);
Integer key = new Integer(treeId);
while (m_connections.contains(key))
{
// Try another tree id for the new connection
treeId = (m_treeId++ & TreeIdMask);
key = new Integer(treeId);
}
// Store the new tree connection
m_connections.put(key, new TreeConnection(shrDev));
}
// Return the allocated tree id
return treeId;
}
// Return the tree connection, or null if invalid UID or TID
return tree;
}
/**
* Allocate a slot in the active searches list for a new search.
*
* @return int Search slot index, or -1 if there are no more search slots available.
*/
protected final int allocateSearchSlot()
{
// Check if the search array has been allocated
if (m_search == null)
m_search = new SearchContext[DefaultSearches];
// Find a free slot for the new search
int idx = 0;
while (idx < m_search.length && m_search[idx] != null)
idx++;
// Check if we found a free slot
if (idx == m_search.length)
{
// The search array needs to be extended, check if we reached the limit.
if (m_search.length >= MaxSearches)
return -1;
// Extend the search array
SearchContext[] newSearch = new SearchContext[m_search.length * 2];
System.arraycopy(m_search, 0, newSearch, 0, m_search.length);
m_search = newSearch;
}
// Return the allocated search slot index
m_searchCount++;
return idx;
* Add a new virtual circuit, return the allocated UID
*
* @param vc
* VirtualCircuit
* @return int
*/
public final int addVirtualCircuit( VirtualCircuit vc) {
// Add the new virtual circuit
return m_vcircuits.addCircuit( vc);
}
/**
* Cleanup any resources owned by this session, close files, searches and change notification
* requests.
*/
* Find a virtual circuit with the allocated UID
*
* @param uid int
* @return VirtualCircuit
*/
public final VirtualCircuit findVirtualCircuit(int uid) {
// Find the virtual circuit with the specified UID
VirtualCircuit vc = m_vcircuits.findCircuit(uid);
if (vc != null) {
// Set the session client information from the virtual circuit
setClientInformation(vc.getClientInformation());
// Set the current authenticated user for this request
getSMBServer().getAuthenticator().setCurrentUser( vc.getClientInformation());
}
// Return the virtual circuit
return vc;
}
/**
* Remove a virtual circuit
*
* @param uid
* int
*/
public final void removeVirtualCircuit(int uid) {
// Remove the virtual circuit with the specified UID
m_vcircuits.removeCircuit(uid, this);
}
/**
* Cleanup any resources owned by this session, close files, searches and
* change notification requests.
*/
protected final void cleanupSession()
{
// Debug
if (logger.isDebugEnabled() && hasDebug(DBG_STATE))
logger.debug("Cleanup session, searches=" + getSearchCount() + ", treeConns=" + getConnectionCount()
+ ", changeNotify=" + getNotifyChangeCount());
// Check if there are any active searches
if (m_search != null)
{
// Close all active searches
for (int idx = 0; idx < m_search.length; idx++)
{
// Check if the current search slot is active
if (m_search[idx] != null)
deallocateSearchSlot(idx);
}
// Release the search context list, clear the search count
m_search = null;
m_searchCount = 0;
}
// Check if there are open tree connections
if (m_connections != null)
{
synchronized (m_connections)
{
// Close all active tree connections
Enumeration<TreeConnection> enm = m_connections.elements();
while (enm.hasMoreElements())
{
// Get the current tree connection
TreeConnection tree = enm.nextElement();
DeviceInterface devIface = tree.getInterface();
// Check if there are open files on the share
if (tree.openFileCount() > 0)
{
// Close the open files, release locks
for (int i = 0; i < tree.getFileTableLength(); i++)
{
// Get an open file
NetworkFile curFile = tree.findFile(i);
if (curFile != null && devIface instanceof DiskInterface)
{
// Access the disk share interface
DiskInterface diskIface = (DiskInterface) devIface;
try
{
// Remove the file from the tree connection list
tree.removeFile(i, this);
// Close the file
diskIface.closeFile(this, tree, curFile);
}
catch (Exception ex)
{
}
}
}
}
// Inform the driver that the connection has been closed
if (devIface != null)
devIface.treeClosed(this, tree);
}
// Clear the tree connection list
m_connections.clear();
}
}
// Debug
if (logger.isDebugEnabled() && hasDebug(DBG_STATE))
logger.debug("Cleanup session, vcircuits=" + m_vcircuits.getCircuitCount() + ", changeNotify=" + getNotifyChangeCount());
// Close the virtual circuits
if ( m_vcircuits.getCircuitCount() > 0) {
// Enumerate the virtual circuits and close all circuits
Enumeration uidEnum = m_vcircuits.enumerateUIDs();
while ( uidEnum.hasMoreElements()) {
// Get the UID for the current circuit
Integer uid = (Integer) uidEnum.nextElement();
// Close the virtual circuit
VirtualCircuit vc = m_vcircuits.findCircuit( uid);
if ( vc != null) {
// DEBUG
if ( logger.isDebugEnabled() && hasDebug(DBG_STATE))
logger.debug(" Cleanup vc=" + vc);
vc.closeCircuit( this);
}
}
// Clear the virtual circuit list
m_vcircuits.clearCircuitList();
}
// Commit, or rollback, any active user transaction
@@ -530,30 +437,6 @@ public class SMBSrvSession extends SrvSession implements Runnable
}
/**
* Deallocate the specified search context/slot.
*
* @param ctxId int
*/
protected final void deallocateSearchSlot(int ctxId)
{
// Check if the search array has been allocated and that the index is valid
if (m_search == null || ctxId >= m_search.length)
return;
// Close the search
if (m_search[ctxId] != null)
m_search[ctxId].closeSearch();
// Free the specified search context slot
m_searchCount--;
m_search[ctxId] = null;
}
/**
* Finalize, object is about to be garbage collected. Make sure resources are released.
*/
@@ -569,25 +452,6 @@ public class SMBSrvSession extends SrvSession implements Runnable
closeSocket();
}
/**
* Return the tree connection details for the specified tree id.
*
* @param treeId int
* @return TreeConnection
*/
protected final TreeConnection findConnection(int treeId)
{
// Check if the tree id and connection array are valid
if (m_connections == null)
return null;
// Get the required tree connection details
return (TreeConnection) m_connections.get(new Integer(treeId));
}
/**
* Return the input/output metwork buffer for this session.
*
@@ -598,16 +462,6 @@ public class SMBSrvSession extends SrvSession implements Runnable
return m_buf;
}
/**
* Return the count of active connections for this session.
*
* @return int
*/
public final int getConnectionCount()
{
return m_connections != null ? m_connections.size() : 0;
}
/**
* Return the default flags SMB header value
*
@@ -763,35 +617,6 @@ public class SMBSrvSession extends SrvSession implements Runnable
return m_pktHandler.getRemoteAddress();
}
/**
* Return the search context for the specified search id.
*
* @param srchId int
* @return SearchContext
*/
protected final SearchContext getSearchContext(int srchId)
{
// Check if the search array is valid and the search index is valid
if (m_search == null || srchId >= m_search.length)
return null;
// Return the required search context
return m_search[srchId];
}
/**
* Return the number of active tree searches.
*
* @return int
*/
public final int getSearchCount()
{
return m_searchCount;
}
/**
* Return the server that this session is associated with.
*
@@ -812,26 +637,6 @@ public class SMBSrvSession extends SrvSession implements Runnable
return getSMBServer().getServerName();
}
/**
* Determine if the session has a setup object
*
* @return boolean
*/
public final boolean hasSetupObject()
{
return m_setupObject != null;
}
/**
* Return the session setup object
*
* @return Object
*/
public final Object getSetupObject()
{
return m_setupObject;
}
/**
* Return the session state
*
@@ -871,10 +676,59 @@ public class SMBSrvSession extends SrvSession implements Runnable
}
/**
* Check if there is a change notification update pending
*
* @return boolean
*/
* Determine if the session has a setup object for the specified PID
*
* @param pid int
* @return boolean
*/
public final boolean hasSetupObject(int pid) {
if (m_setupObjects == null)
return false;
return m_setupObjects.get(new Integer(pid)) != null ? true : false;
}
/**
* Return the session setup object for the specified PID
*
* @param pid int
* @return Object
*/
public final Object getSetupObject(int pid) {
if (m_setupObjects == null)
return null;
return m_setupObjects.get(new Integer(pid));
}
/**
* Store the setup object for the specified PID
*
* @param pid int
* @param obj Object
*/
public final void setSetupObject(int pid, Object obj) {
if (m_setupObjects == null)
m_setupObjects = new Hashtable<Integer, Object>();
m_setupObjects.put(new Integer(pid), obj);
}
/**
* Remove the session setup object for the specified PID
*
* @param pid
* int
* @return Object
*/
public final Object removeSetupObject(int pid) {
if (m_setupObjects == null)
return null;
return m_setupObjects.remove(new Integer(pid));
}
/**
* Check if there is a change notification update pending
*
* @return boolean
*/
public final boolean hasNotifyPending()
{
return m_notifyPending;
@@ -951,25 +805,6 @@ public class SMBSrvSession extends SrvSession implements Runnable
m_buf = pkt.getBuffer();
}
/**
* Store the seach context in the specified slot.
*
* @param slot Slot to store the search context.
* @param srch SearchContext
*/
protected final void setSearchContext(int slot, SearchContext srch)
{
// Check if the search slot id is valid
if (m_search == null || slot > m_search.length)
return;
// Store the context
m_search[slot] = srch;
}
/**
* Set the session state.
*
@@ -977,32 +812,16 @@ public class SMBSrvSession extends SrvSession implements Runnable
*/
protected void setState(int state)
{
// Debug
if (logger.isDebugEnabled() && hasDebug(DBG_STATE))
logger.debug("State changed to " + SMBSrvSessionState.getStateAsString(state));
// Clear the setup object if the new state is the main session state
if ( state == SMBSrvSessionState.SMBSESSION)
m_setupObject = null;
// Change the session state
m_state = state;
}
/**
* Set the setup object
*
* @param obj Object
*/
public final void setSetupObject( Object obj)
{
m_setupObject = obj;
}
/**
* Process the NetBIOS session request message, either accept the session request and send back
* a NetBIOS accept or reject the session and send back a NetBIOS reject and hangup the session.
@@ -1444,45 +1263,6 @@ public class SMBSrvSession extends SrvSession implements Runnable
getSMBServer().sessionOpened(this);
}
/**
* Remove the specified tree connection from the active connection list.
*
* @param treeId int
*/
protected void removeConnection(int treeId)
{
// Check if the tree id is valid
if (m_connections == null)
return;
// Close the connection and remove from the connection list
synchronized (m_connections)
{
// Get the connection
Integer key = new Integer(treeId);
TreeConnection tree = (TreeConnection) m_connections.get(key);
// Close the connection, release resources
if (tree != null)
{
// Close the connection
tree.closeConnection(this);
// Remove the connection from the connection list
m_connections.remove(key);
}
}
}
/**
* Start the SMB server session in a seperate thread.
*/
@@ -1780,10 +1560,20 @@ public class SMBSrvSession extends SrvSession implements Runnable
if (m_smbPkt.isLongErrorCode())
{
// Return the long/NT status code
sendErrorResponseSMB(ntCode, SMBStatus.NTErr);
// Return the long/NT status code
if ( ntCode != -1) {
// Use the 32bit NT error code
sendErrorResponseSMB( ntCode, SMBStatus.NTErr);
}
else {
// Use the DOS error code
sendErrorResponseSMB( stdCode, stdClass);
}
}
else
{
@@ -2035,34 +1825,4 @@ public class SMBSrvSession extends SrvSession implements Runnable
if (req.getDiskContext() != null)
req.getDiskContext().removeNotifyRequest(req);
}
/**
* Check if there is an active transaction
*
* @return boolean
*/
protected final boolean hasTransaction()
{
return m_transact != null ? true : false;
}
/**
* Return the active transaction buffer
*
* @return TransactBuffer
*/
protected final SrvTransactBuffer getTransaction()
{
return m_transact;
}
/**
* Set the active transaction buffer
*
* @param buf TransactBuffer
*/
protected final void setTransaction(SrvTransactBuffer buf)
{
m_transact = buf;
}
}