1 17 package org.alfresco.filesys.smb.server; 18 19 import java.net.InetAddress ; 20 import java.net.Socket ; 21 import java.net.SocketException ; 22 23 import org.alfresco.filesys.netbios.RFCNetBIOSProtocol; 24 import org.alfresco.filesys.server.config.ServerConfiguration; 25 import org.alfresco.filesys.smb.mailslot.TcpipNetBIOSHostAnnouncer; 26 27 30 public class NetBIOSSessionSocketHandler extends SessionSocketHandler 31 { 32 33 41 public NetBIOSSessionSocketHandler(SMBServer srv, int port, InetAddress bindAddr, boolean debug) 42 { 43 super("NetBIOS", srv, port, bindAddr, debug); 44 } 45 46 49 public void run() 50 { 51 52 try 53 { 54 55 57 clearShutdown(); 58 59 61 while (hasShutdown() == false) 62 { 63 64 66 if (logger.isDebugEnabled() && hasDebug()) 67 logger.debug("[SMB] Waiting for NetBIOS session request ..."); 68 69 71 Socket sessSock = getSocket().accept(); 72 73 75 if (logger.isDebugEnabled() && hasDebug()) 76 logger.debug("[SMB] NetBIOS session request received from " 77 + sessSock.getInetAddress().getHostAddress()); 78 79 try 80 { 81 82 84 PacketHandler pktHandler = new NetBIOSPacketHandler(sessSock); 85 86 88 SMBSrvSession srvSess = new SMBSrvSession(pktHandler, getServer()); 89 srvSess.setSessionId(getNextSessionId()); 90 srvSess.setUniqueId(pktHandler.getShortName() + srvSess.getSessionId()); 91 srvSess.setDebugPrefix("[" + pktHandler.getShortName() + srvSess.getSessionId() + "] "); 92 93 95 getServer().addSession(srvSess); 96 97 99 Thread srvThread = new Thread (srvSess); 100 srvThread.setDaemon(true); 101 srvThread.setName("Sess_N" + srvSess.getSessionId() + "_" 102 + sessSock.getInetAddress().getHostAddress()); 103 srvThread.start(); 104 } 105 catch (Exception ex) 106 { 107 108 110 logger.error("[SMB] NetBIOS Failed to create session, ", ex); 111 } 112 } 113 } 114 catch (SocketException ex) 115 { 116 117 120 if (hasShutdown() == false) 121 logger.error("[SMB] NetBIOS Socket error : ", ex); 122 } 123 catch (Exception ex) 124 { 125 126 129 if (hasShutdown() == false) 130 logger.error("[SMB] NetBIOS Server error : ", ex); 131 } 132 133 135 if (logger.isDebugEnabled() && hasDebug()) 136 logger.debug("[SMB] NetBIOS session handler closed"); 137 } 138 139 146 public final static void createSessionHandlers(SMBServer server, boolean sockDbg) throws Exception 147 { 148 149 151 ServerConfiguration config = server.getConfiguration(); 152 153 155 SessionSocketHandler sessHandler = new NetBIOSSessionSocketHandler(server, RFCNetBIOSProtocol.PORT, config 156 .getSMBBindAddress(), sockDbg); 157 sessHandler.initialize(); 158 159 161 server.addSessionHandler(sessHandler); 162 163 165 Thread nbThread = new Thread (sessHandler); 166 nbThread.setName("NetBIOS_Handler"); 167 nbThread.start(); 168 169 171 if (logger.isDebugEnabled() && sockDbg) 172 logger.debug("[SMB] TCP NetBIOS session handler created"); 173 174 176 if (config.hasEnableAnnouncer()) 177 { 178 179 181 TcpipNetBIOSHostAnnouncer announcer = new TcpipNetBIOSHostAnnouncer(); 182 183 185 announcer.addHostName(config.getServerName()); 186 announcer.setDomain(config.getDomainName()); 187 announcer.setComment(config.getComment()); 188 announcer.setBindAddress(config.getSMBBindAddress()); 189 190 192 if (config.getHostAnnounceInterval() > 0) 193 announcer.setInterval(config.getHostAnnounceInterval()); 194 195 try 196 { 197 announcer.setBroadcastAddress(config.getBroadcastMask()); 198 } 199 catch (Exception ex) 200 { 201 } 202 203 205 announcer.setServerType(config.getServerType()); 206 207 209 if (config.hasHostAnnounceDebug()) 210 announcer.setDebug(true); 211 212 214 server.addHostAnnouncer(announcer); 215 216 218 announcer.start(); 219 220 222 if (logger.isDebugEnabled() && sockDbg) 223 logger.debug("[SMB] TCP NetBIOS host announcer created"); 224 } 225 } 226 } 227 | Popular Tags |