From 516471381d60863938607d1311d5831719d16fa5 Mon Sep 17 00:00:00 2001 From: Gary Spencer Date: Tue, 16 Jan 2007 10:15:56 +0000 Subject: [PATCH] Updated CifsMounter to be able to connect from linux to an Alfresco CIFS server that is only running on NetBIOS. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4842 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../server/config/FileServerConfig.java | 47 ++++++++++++++++++- .../server/config/ServerConfiguration.java | 1 - .../alfresco/filesys/util/CifsMounter.java | 41 ++++++++++++++-- 3 files changed, 83 insertions(+), 6 deletions(-) diff --git a/source/java/org/alfresco/filesys/server/config/FileServerConfig.java b/source/java/org/alfresco/filesys/server/config/FileServerConfig.java index bc20a9be06..892b5ca571 100644 --- a/source/java/org/alfresco/filesys/server/config/FileServerConfig.java +++ b/source/java/org/alfresco/filesys/server/config/FileServerConfig.java @@ -16,9 +16,15 @@ */ package org.alfresco.filesys.server.config; +import java.net.InetAddress; + import org.alfresco.filesys.smb.TcpipSMB; import org.alfresco.filesys.util.CifsMounter; import org.alfresco.filesys.util.Platform; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.sun.star.io.UnknownHostException; /** * File Server Configuration MBean Class @@ -30,6 +36,10 @@ import org.alfresco.filesys.util.Platform; */ public class FileServerConfig implements FileServerConfigMBean { + // Debug logging + + private static final Log logger = LogFactory.getLog( FileServerConfig.class); + // File server configuration private ServerConfiguration m_serverConfig; @@ -88,8 +98,7 @@ public class FileServerConfig implements FileServerConfigMBean { */ public boolean isNFSServerEnabled() { -// return m_serverConfig.isNFSServerEnabled(); - return false; + return m_serverConfig.isNFSServerEnabled(); } /** @@ -129,6 +138,15 @@ public class FileServerConfig implements FileServerConfigMBean { CifsMounter cifsMounter = new CifsMounter(); cifsMounter.setServerName( getCIFSServerName()); + // Set the server address if the global bind address has been set + + if ( m_serverConfig.hasSMBBindAddress()) + { + // Use the global CIFS server bind address + + cifsMounter.setServerAddress( m_serverConfig.getSMBBindAddress().getHostAddress()); + } + // Get the local platform type Platform.Type platform = Platform.isPlatformType(); @@ -153,7 +171,32 @@ public class FileServerConfig implements FileServerConfigMBean { if ( m_serverConfig.hasWin32NetBIOS()) cifsMounter.setProtocolType( CifsMounter.Win32NetBIOS); else if ( m_serverConfig.hasNetBIOSSMB()) + { + // Set the protocol type for Java socket based NetBIOS + cifsMounter.setProtocolType( CifsMounter.NetBIOS); + + // Check if the socket NetBIOS is bound to a particular address + + if ( m_serverConfig.hasNetBIOSBindAddress()) + cifsMounter.setServerAddress( m_serverConfig.getNetBIOSBindAddress().getHostAddress()); + } + } + + // Check if the CIFS mounter server address has been set, if not then get the local address + + if ( cifsMounter.getServerAddress() == null) + { + // Set the CIFS mounter server address + + try + { + cifsMounter.setServerAddress( InetAddress.getLocalHost().getHostAddress()); + } + catch ( java.net.UnknownHostException ex) + { + logger.error( "Failed to get local IP address", ex); + } } // Return the CIFS mounter diff --git a/source/java/org/alfresco/filesys/server/config/ServerConfiguration.java b/source/java/org/alfresco/filesys/server/config/ServerConfiguration.java index f1a82dcc09..f7430b528a 100644 --- a/source/java/org/alfresco/filesys/server/config/ServerConfiguration.java +++ b/source/java/org/alfresco/filesys/server/config/ServerConfiguration.java @@ -76,7 +76,6 @@ import org.alfresco.filesys.server.core.SharedDeviceList; import org.alfresco.filesys.server.filesys.DefaultShareMapper; import org.alfresco.filesys.server.filesys.DiskInterface; import org.alfresco.filesys.server.filesys.DiskSharedDevice; -import org.alfresco.filesys.server.oncrpc.DefaultRpcAuthenticator; import org.alfresco.filesys.server.oncrpc.RpcAuthenticator; import org.alfresco.filesys.smb.ServerType; import org.alfresco.filesys.smb.TcpipSMB; diff --git a/source/java/org/alfresco/filesys/util/CifsMounter.java b/source/java/org/alfresco/filesys/util/CifsMounter.java index d70fd64fd3..3c249c4652 100644 --- a/source/java/org/alfresco/filesys/util/CifsMounter.java +++ b/source/java/org/alfresco/filesys/util/CifsMounter.java @@ -56,8 +56,9 @@ public class CifsMounter { private static final String LinuxMountSmbfsCmd = "mount -t smbfs //${srvname}/${sharename} ${mountpoint} -o username=${username},password=${password}"; private static final String LinuxMountCifsCmd = "mount -t cifs //${srvname}/${sharename} ${mountpoint} -o username=${username},password=${password}"; + private static final String LinuxMountCifsNBCmd = "mount.cifs //${srvname}/${sharename} ${mountpoint} -o servern=${srvname},port=139,username=${username},password=${password}"; private static final String LinuxUnMountCmd = "umount ${mountpoint}"; - + // Mac OS X mount/unmount commands private static final String MacOSXMountCmd = "mount_smbfs -U ${username} //${password}@${srvname}/${sharename} ${mountpoint}"; @@ -68,6 +69,10 @@ public class CifsMounter { private String m_srvName; private String m_shareName; + // Server address + + private String m_srvAddr; + // Access details for remote share private String m_userName; @@ -159,9 +164,19 @@ public class CifsMounter { } else { - // Set the command line to use the older smbfs VFS mounter to connect using NetBIOS + // Set the command line to use the CIFS VFS mounter to connect using NetBIOS - commandMap.put( "Linux", LinuxMountSmbfsCmd); + StringBuilder cmd = new StringBuilder( LinuxMountCifsNBCmd); + + if ( getServerAddress() != null) + { + cmd.append( ",ip="); + cmd.append( getServerAddress()); + } + + // Set the command line + + commandMap.put( "Linux", cmd.toString()); } break; @@ -287,6 +302,16 @@ public class CifsMounter { { return m_srvName; } + + /** + * Return hte server address + * + * @return String + */ + public final String getServerAddress() + { + return m_srvAddr; + } /** * Return the share name @@ -348,6 +373,16 @@ public class CifsMounter { m_srvName = name; } + /** + * Set the server address + * + * @param srvAddr String + */ + public final void setServerAddress(String srvAddr) + { + m_srvAddr = srvAddr; + } + /** * Set the share name *