KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > server > config > ServerConfiguration


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.server.config;
18
19 import java.io.IOException JavaDoc;
20 import java.net.InetAddress JavaDoc;
21 import java.net.InetSocketAddress JavaDoc;
22 import java.net.Socket JavaDoc;
23 import java.net.SocketException JavaDoc;
24 import java.net.UnknownHostException JavaDoc;
25 import java.security.Provider JavaDoc;
26 import java.security.Security JavaDoc;
27 import java.util.EnumSet JavaDoc;
28 import java.util.Enumeration JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.StringTokenizer JavaDoc;
31 import java.util.TimeZone JavaDoc;
32
33 import net.sf.acegisecurity.AuthenticationManager;
34
35 import org.alfresco.config.Config;
36 import org.alfresco.config.ConfigElement;
37 import org.alfresco.config.ConfigLookupContext;
38 import org.alfresco.config.ConfigService;
39 import org.alfresco.error.AlfrescoRuntimeException;
40 import org.alfresco.filesys.ftp.FTPPath;
41 import org.alfresco.filesys.ftp.InvalidPathException;
42 import org.alfresco.filesys.netbios.NetBIOSName;
43 import org.alfresco.filesys.netbios.NetBIOSNameList;
44 import org.alfresco.filesys.netbios.NetBIOSSession;
45 import org.alfresco.filesys.netbios.RFCNetBIOSProtocol;
46 import org.alfresco.filesys.netbios.win32.Win32NetBIOS;
47 import org.alfresco.filesys.server.NetworkServer;
48 import org.alfresco.filesys.server.NetworkServerList;
49 import org.alfresco.filesys.server.auth.LocalAuthenticator;
50 import org.alfresco.filesys.server.auth.SrvAuthenticator;
51 import org.alfresco.filesys.server.auth.UserAccount;
52 import org.alfresco.filesys.server.auth.UserAccountList;
53 import org.alfresco.filesys.server.auth.acl.ACLParseException;
54 import org.alfresco.filesys.server.auth.acl.AccessControl;
55 import org.alfresco.filesys.server.auth.acl.AccessControlList;
56 import org.alfresco.filesys.server.auth.acl.AccessControlManager;
57 import org.alfresco.filesys.server.auth.acl.AccessControlParser;
58 import org.alfresco.filesys.server.auth.acl.DefaultAccessControlManager;
59 import org.alfresco.filesys.server.auth.acl.InvalidACLTypeException;
60 import org.alfresco.filesys.server.core.DeviceContext;
61 import org.alfresco.filesys.server.core.DeviceContextException;
62 import org.alfresco.filesys.server.core.ShareMapper;
63 import org.alfresco.filesys.server.core.ShareType;
64 import org.alfresco.filesys.server.core.SharedDevice;
65 import org.alfresco.filesys.server.core.SharedDeviceList;
66 import org.alfresco.filesys.server.filesys.DefaultShareMapper;
67 import org.alfresco.filesys.server.filesys.DiskDeviceContext;
68 import org.alfresco.filesys.server.filesys.DiskInterface;
69 import org.alfresco.filesys.server.filesys.DiskSharedDevice;
70 import org.alfresco.filesys.server.filesys.HomeShareMapper;
71 import org.alfresco.filesys.smb.Dialect;
72 import org.alfresco.filesys.smb.DialectSelector;
73 import org.alfresco.filesys.smb.ServerType;
74 import org.alfresco.filesys.util.IPAddress;
75 import org.alfresco.repo.security.authentication.AuthenticationComponent;
76 import org.alfresco.repo.security.authentication.NTLMMode;
77 import org.alfresco.service.cmr.repository.NodeService;
78 import org.alfresco.service.cmr.security.AuthenticationService;
79 import org.alfresco.service.cmr.security.PersonService;
80 import org.alfresco.service.transaction.TransactionService;
81 import org.apache.commons.logging.Log;
82 import org.apache.commons.logging.LogFactory;
83 import org.springframework.context.ApplicationEvent;
84 import org.springframework.context.ApplicationListener;
85 import org.springframework.context.event.ContextRefreshedEvent;
86
87 /**
88  * <p>
89  * Provides the configuration parameters for the network file servers.
90  *
91  * @author Gary K. Spencer
92  */

93 public class ServerConfiguration implements ApplicationListener
94 {
95     // Debug logging
96

97     private static final Log logger = LogFactory.getLog("org.alfresco.smb.protocol");
98
99     // Filesystem configuration constants
100

101     private static final String JavaDoc ConfigArea = "file-servers";
102     private static final String JavaDoc ConfigCIFS = "CIFS Server";
103     private static final String JavaDoc ConfigFTP = "FTP Server";
104     private static final String JavaDoc ConfigFilesystems = "Filesystems";
105     private static final String JavaDoc ConfigSecurity = "Filesystem Security";
106
107     // Server configuration bean name
108

109     public static final String JavaDoc SERVER_CONFIGURATION = "fileServerConfiguration";
110     
111     // SMB/CIFS session debug type strings
112
//
113
// Must match the bit mask order
114

115     private static final String JavaDoc m_sessDbgStr[] = { "NETBIOS", "STATE", "NEGOTIATE", "TREE", "SEARCH", "INFO", "FILE",
116             "FILEIO", "TRANSACT", "ECHO", "ERROR", "IPC", "LOCK", "PKTTYPE", "DCERPC", "STATECACHE", "NOTIFY",
117             "STREAMS", "SOCKET" };
118
119     // FTP server debug type strings
120

121     private static final String JavaDoc m_ftpDebugStr[] = { "STATE", "SEARCH", "INFO", "FILE", "FILEIO", "ERROR", "PKTTYPE",
122             "TIMING", "DATAPORT", "DIRECTORY" };
123
124     // Default FTP server port
125

126     private static final int DefaultFTPServerPort = 21;
127     
128     // Default FTP anonymous account name
129

130     private static final String JavaDoc DefaultFTPAnonymousAccount = "anonymous";
131     
132     // Platform types
133

134     public enum PlatformType
135     {
136         Unknown, WINDOWS, LINUX, SOLARIS, MACOSX
137     };
138
139     // Token name to substitute current server name into the CIFS server name
140
private static final String JavaDoc TokenLocalName = "${localname}";
141
142     // Acegi authentication manager
143
private AuthenticationManager authenticationManager;
144
145     // Configuration service
146
private ConfigService configService;
147
148     /** the device to connect use */
149     private DiskInterface diskInterface;
150
151     // Runtime platform type
152

153     private PlatformType m_platform = PlatformType.Unknown;
154
155     // Main server enable flags, to enable SMB, FTP and/or NFS server components
156

157     private boolean m_smbEnable = true;
158     private boolean m_ftpEnable = true;
159
160     // Server name
161
private String JavaDoc m_name;
162
163     // Server type, used by the host announcer
164
private int m_srvType = ServerType.WorkStation + ServerType.Server + ServerType.NTServer;
165
166     // Active server list
167
private NetworkServerList m_serverList;
168
169     // Server comment
170
private String JavaDoc m_comment;
171
172     // Server domain
173
private String JavaDoc m_domain;
174
175     // Network broadcast mask string
176
private String JavaDoc m_broadcast;
177
178     // Announce the server to network neighborhood, announcement interval in
179
// minutes
180
private boolean m_announce;
181
182     private int m_announceInterval;
183
184     // Default SMB dialects to enable
185
private DialectSelector m_dialects;
186
187     // List of shared devices
188
private SharedDeviceList m_shareList;
189
190     // Authenticator, used to authenticate users and share connections.
191
private SrvAuthenticator m_authenticator;
192
193     // Share mapper
194
private ShareMapper m_shareMapper;
195
196     // Access control manager
197
private AccessControlManager m_aclManager;
198
199     // Global access control list, applied to all shares that do not have access
200
// controls
201
private AccessControlList m_globalACLs;
202
203     private boolean m_nbDebug = false;
204
205     private boolean m_announceDebug = false;
206
207     // Default session debugging setting
208
private int m_sessDebug;
209
210     // Flags to indicate if NetBIOS, native TCP/IP SMB and/or Win32 NetBIOS
211
// should be enabled
212
private boolean m_netBIOSEnable = true;
213
214     private boolean m_tcpSMBEnable = false;
215
216     private boolean m_win32NBEnable = false;
217
218     // Address to bind the SMB server to, if null all local addresses are used
219
private InetAddress JavaDoc m_smbBindAddress;
220
221     // Address to bind the NetBIOS name server to, if null all addresses are
222
// used
223
private InetAddress JavaDoc m_nbBindAddress;
224
225     // WINS servers
226
private InetAddress JavaDoc m_winsPrimary;
227     private InetAddress JavaDoc m_winsSecondary;
228
229     // User account list
230
private UserAccountList m_userList;
231
232     // Enable/disable Macintosh extension SMBs
233
private boolean m_macExtensions;
234
235     // --------------------------------------------------------------------------------
236
// Win32 NetBIOS configuration
237
//
238
// Server name to register under Win32 NetBIOS, if not set the main server
239
// name is used
240
private String JavaDoc m_win32NBName;
241
242     // LANA to be used for Win32 NetBIOS, if not specified the first available
243
// is used
244
private int m_win32NBLANA = -1;
245
246     // Send out host announcements via the Win32 NetBIOS interface
247
private boolean m_win32NBAnnounce = false;
248     private int m_win32NBAnnounceInterval;
249     
250     // Use Winsock NetBIOS interface if true, else use the Netbios() API interface
251

252     private boolean m_win32NBUseWinsock = true;
253
254     // --------------------------------------------------------------------------------
255
// FTP specific configuration parameters
256
//
257
// Bind address and FTP server port.
258

259     private InetAddress JavaDoc m_ftpBindAddress;
260     private int m_ftpPort = DefaultFTPServerPort;
261
262     // Allow anonymous FTP access and anonymous FTP account name
263

264     private boolean m_ftpAllowAnonymous;
265     private String JavaDoc m_ftpAnonymousAccount;
266
267     // FTP root path, if not specified defaults to listing all shares as the root
268

269     private String JavaDoc m_ftpRootPath;
270
271     // FTP server debug flags
272

273     private int m_ftpDebug;
274
275     // --------------------------------------------------------------------------------
276
// Global server configuration
277
//
278
// Timezone name and offset from UTC in minutes
279
private String JavaDoc m_timeZone;
280     private int m_tzOffset;
281
282     // JCE provider class name
283
private String JavaDoc m_jceProviderClass;
284
285     // Local server name and domain/workgroup name
286

287     private String JavaDoc m_localName;
288     private String JavaDoc m_localDomain;
289
290     /** flag indicating successful initialisation */
291     private boolean initialised;
292
293     // Main authentication service, public API
294

295     private AuthenticationService authenticationService;
296
297     // Authentication component, for internal functions
298

299     private AuthenticationComponent m_authenticationComponent;
300     
301     // Various services
302

303     private NodeService m_nodeService;
304     private PersonService m_personService;
305     private TransactionService m_transactionService;
306
307     /**
308      * Class constructor
309      */

310     public ServerConfiguration()
311     {
312         // Allocate the shared device list
313

314         m_shareList = new SharedDeviceList();
315
316         // Allocate the SMB dialect selector, and initialize using the default
317
// list of dialects
318

319         m_dialects = new DialectSelector();
320
321         m_dialects.AddDialect(Dialect.DOSLanMan1);
322         m_dialects.AddDialect(Dialect.DOSLanMan2);
323         m_dialects.AddDialect(Dialect.LanMan1);
324         m_dialects.AddDialect(Dialect.LanMan2);
325         m_dialects.AddDialect(Dialect.LanMan2_1);
326         m_dialects.AddDialect(Dialect.NT);
327
328         // Use the local authenticator, that allows locally defined users to connect to the
329
// server
330

331         setAuthenticator(new LocalAuthenticator(), null, true);
332
333         // Use the default share mapper
334

335         m_shareMapper = new DefaultShareMapper();
336
337         try
338         {
339             m_shareMapper.initializeMapper(this, null);
340         }
341         catch (InvalidConfigurationException ex)
342         {
343             throw new AlfrescoRuntimeException("Failed to initialise share mapper", ex);
344         }
345
346         // Set the default access control manager
347

348         m_aclManager = new DefaultAccessControlManager();
349         m_aclManager.initialize(this, null);
350
351         // Use the default timezone
352

353         try
354         {
355             setTimeZone(TimeZone.getDefault().getID());
356         }
357         catch (Exception JavaDoc ex)
358         {
359             throw new AlfrescoRuntimeException("Failed to set timezone", ex);
360         }
361
362         // Allocate the active server list
363

364         m_serverList = new NetworkServerList();
365     }
366     
367     public void setAuthenticationManager(AuthenticationManager authenticationManager)
368     {
369         this.authenticationManager = authenticationManager;
370     }
371
372     public void setAuthenticationService(AuthenticationService authenticationService)
373     {
374         this.authenticationService = authenticationService;
375     }
376
377     public void setConfigService(ConfigService configService)
378     {
379         this.configService = configService;
380     }
381
382     public void setDiskInterface(DiskInterface diskInterface)
383     {
384         this.diskInterface = diskInterface;
385     }
386
387     public void setAuthenticationComponent(AuthenticationComponent component)
388     {
389         m_authenticationComponent = component;
390     }
391
392     public void setNodeService(NodeService service)
393     {
394         m_nodeService = service;
395     }
396
397     public void setPersonService(PersonService service)
398     {
399         m_personService = service;
400     }
401
402     public void setTransactionService(TransactionService service)
403     {
404         m_transactionService = service;
405     }
406
407     /**
408      * @return Returns true if the configuration was fully initialised
409      */

410     public boolean isInitialised()
411     {
412         return initialised;
413     }
414
415     /*
416      * (non-Javadoc)
417      * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
418      */

419     public void onApplicationEvent(ApplicationEvent event)
420     {
421         if (event instanceof ContextRefreshedEvent)
422         {
423             init();
424         }
425     }
426     
427     /**
428      * Initialize the configuration using the configuration service
429      */

430     public void init()
431     {
432         // check that all required properties have been set
433
if (authenticationManager == null)
434         {
435             throw new AlfrescoRuntimeException("Property 'authenticationManager' not set");
436         }
437         else if (m_authenticationComponent == null)
438         {
439             throw new AlfrescoRuntimeException("Property 'authenticationComponent' not set");
440         }
441         else if (authenticationService == null)
442         {
443             throw new AlfrescoRuntimeException("Property 'authenticationService' not set");
444         }
445         else if (m_nodeService == null)
446         {
447             throw new AlfrescoRuntimeException("Property 'nodeService' not set");
448         }
449         else if (m_personService == null)
450         {
451             throw new AlfrescoRuntimeException("Property 'personService' not set");
452         }
453         else if (m_transactionService == null)
454         {
455             throw new AlfrescoRuntimeException("Property 'transactionService' not set");
456         }
457         else if (diskInterface == null)
458         {
459             throw new AlfrescoRuntimeException("Property 'diskInterface' not set");
460         }
461         else if (configService == null)
462         {
463             throw new AlfrescoRuntimeException("Property 'configService' not set");
464         }
465         
466         initialised = false;
467
468         // Create the configuration context
469

470         ConfigLookupContext configCtx = new ConfigLookupContext(ConfigArea);
471
472         // Set the platform type
473

474         determinePlatformType();
475
476         try
477         {
478
479             // Process the CIFS server configuration
480

481             Config config = configService.getConfig(ConfigCIFS, configCtx);
482             processCIFSServerConfig(config);
483
484             // Process the FTP server configuration
485

486             config = configService.getConfig(ConfigFTP, configCtx);
487             processFTPServerConfig(config);
488
489             // Process the security configuration
490

491             config = configService.getConfig(ConfigSecurity, configCtx);
492             processSecurityConfig(config);
493
494             // Process the filesystems configuration
495

496             config = configService.getConfig(ConfigFilesystems, configCtx);
497             processFilesystemsConfig(config);
498
499             // Successful initialisation
500
initialised = true;
501         }
502         catch (UnsatisfiedLinkError JavaDoc ex)
503         {
504             // Error accessing the Win32NetBIOS DLL code
505

506             logger.error("Error accessing Win32 NetBIOS, check DLL is on the path");
507
508             // Disable the CIFS server
509

510             setNetBIOSSMB(false);
511             setTcpipSMB(false);
512             setWin32NetBIOS(false);
513
514             setSMBServerEnabled(false);
515         }
516         catch (Throwable JavaDoc ex)
517         {
518             // Configuration error
519

520             logger.error("File server configuration error, " + ex.getMessage(), ex);
521
522             // Disable the CIFS server
523

524             setNetBIOSSMB(false);
525             setTcpipSMB(false);
526             setWin32NetBIOS(false);
527
528             setSMBServerEnabled(false);
529         }
530     }
531
532     /**
533      * Determine the platform type
534      */

535     private final void determinePlatformType()
536     {
537         // Get the operating system type
538

539         String JavaDoc osName = System.getProperty("os.name");
540
541         if (osName.startsWith("Windows"))
542             m_platform = PlatformType.WINDOWS;
543         else if (osName.equalsIgnoreCase("Linux"))
544             m_platform = PlatformType.LINUX;
545         else if (osName.startsWith("Mac OS X"))
546             m_platform = PlatformType.MACOSX;
547         else if (osName.startsWith("Solaris"))
548             m_platform = PlatformType.SOLARIS;
549     }
550
551     /**
552      * Return the platform type
553      *
554      * @return PlatformType
555      */

556     public final PlatformType getPlatformType()
557     {
558         return m_platform;
559     }
560
561     /**
562      * Process the CIFS server configuration
563      *
564      * @param config Config
565      */

566     private final void processCIFSServerConfig(Config config)
567     {
568         // If the configuration section is not valid then CIFS is disabled
569

570         if ( config == null || config.getConfigElements().isEmpty())
571         {
572             setSMBServerEnabled(false);
573             return;
574         }
575             
576         // Get the network broadcast address
577
//
578
// Note: We need to set this first as the call to getLocalDomainName() may use a NetBIOS
579
// name lookup, so the broadcast mask must be set before then.
580

581         ConfigElement elem = config.getConfigElement("broadcast");
582         if (elem != null)
583         {
584
585             // Check if the broadcast mask is a valid numeric IP address
586

587             if (IPAddress.isNumericAddress(elem.getValue()) == false)
588                 throw new AlfrescoRuntimeException("Invalid broadcast mask, must be n.n.n.n format");
589
590             // Set the network broadcast mask
591

592             setBroadcastMask(elem.getValue());
593         }
594
595         // Get the host configuration
596

597         elem = config.getConfigElement("host");
598         if (elem == null)
599             throw new AlfrescoRuntimeException("CIFS server host settings not specified");
600
601         String JavaDoc hostName = elem.getAttribute("name");
602         if (hostName == null || hostName.length() == 0)
603             throw new AlfrescoRuntimeException("Host name not specified or invalid");
604
605         // Check if the host name contains the local name token
606

607         int pos = hostName.indexOf(TokenLocalName);
608         if (pos != -1)
609         {
610
611             // Get the local server name
612

613             String JavaDoc srvName = getLocalServerName(true);
614
615             // Rebuild the host name substituting the token with the local server name
616

617             StringBuilder JavaDoc hostStr = new StringBuilder JavaDoc();
618
619             hostStr.append(hostName.substring(0, pos));
620             hostStr.append(srvName);
621
622             pos += TokenLocalName.length();
623             if (pos < hostName.length())
624                 hostStr.append(hostName.substring(pos));
625
626             hostName = hostStr.toString();
627
628             // Make sure the CIFS server name does not match the local server name
629

630             if (hostName.equals(srvName))
631                 throw new AlfrescoRuntimeException("CIFS server name must be unique");
632         }
633
634         // Set the CIFS server name
635

636         setServerName(hostName.toUpperCase());
637
638         // Get the domain/workgroup name
639

640         String JavaDoc domain = elem.getAttribute("domain");
641         if (domain != null && domain.length() > 0)
642         {
643             // Set the domain/workgroup name
644

645             setDomainName(domain.toUpperCase());
646         }
647         else
648         {
649             // Get the local domain/workgroup name
650

651             String JavaDoc localDomain = getLocalDomainName();
652             
653             if ( localDomain == null && getPlatformType() != PlatformType.WINDOWS)
654             {
655                 // Use a default domain/workgroup name
656

657                 localDomain = "WORKGROUP";
658                 
659                 // Output a warning
660

661                 logger.error("Failed to get local domain/workgroup name, using default of " + localDomain);
662                 logger.error("(This may be due to firewall settings or incorrect <broadcast> setting)");
663             }
664             
665             // Set the local domain/workgroup that the CIFS server belongs to
666

667             setDomainName( localDomain);
668         }
669
670         // Check for a server comment
671

672         elem = config.getConfigElement("comment");
673         if (elem != null)
674             setComment(elem.getValue());
675
676         // Check for a bind address
677

678         elem = config.getConfigElement("bindto");
679         if (elem != null)
680         {
681
682             // Validate the bind address
683

684             String JavaDoc bindText = elem.getValue();
685
686             try
687             {
688
689                 // Check the bind address
690

691                 InetAddress JavaDoc bindAddr = InetAddress.getByName(bindText);
692
693                 // Set the bind address for the server
694

695                 setSMBBindAddress(bindAddr);
696             }
697             catch (UnknownHostException JavaDoc ex)
698             {
699                 throw new AlfrescoRuntimeException("Invalid CIFS server bind address");
700             }
701         }
702
703         // Check if the host announcer should be enabled
704

705         elem = config.getConfigElement("hostAnnounce");
706         if (elem != null)
707         {
708
709             // Check for an announcement interval
710

711             String JavaDoc interval = elem.getAttribute("interval");
712             if (interval != null && interval.length() > 0)
713             {
714                 try
715                 {
716                     setHostAnnounceInterval(Integer.parseInt(interval));
717                 }
718                 catch (NumberFormatException JavaDoc ex)
719                 {
720                     throw new AlfrescoRuntimeException("Invalid host announcement interval");
721                 }
722             }
723
724             // Check if the domain name has been set, this is required if the
725
// host announcer is enabled
726

727             if (getDomainName() == null)
728                 throw new AlfrescoRuntimeException("Domain name must be specified if host announcement is enabled");
729
730             // Enable host announcement
731

732             setHostAnnouncer(true);
733         }
734
735         // Check if NetBIOS SMB is enabled
736

737         elem = config.getConfigElement("netBIOSSMB");
738         if (elem != null)
739         {
740             // Check if NetBIOS over TCP/IP is enabled for the current platform
741

742             String JavaDoc platformsStr = elem.getAttribute("platforms");
743             boolean platformOK = false;
744
745             if (platformsStr != null)
746             {
747                 // Parse the list of platforms that NetBIOS over TCP/IP is to be enabled for and
748
// check if the current platform is included
749

750                 EnumSet JavaDoc<PlatformType> enabledPlatforms = parsePlatformString(platformsStr);
751                 if (enabledPlatforms.contains(getPlatformType()))
752                     platformOK = true;
753             }
754             else
755             {
756                 // No restriction on platforms
757

758                 platformOK = true;
759             }
760
761             // Check if the broadcast mask has been specified
762

763             if (getBroadcastMask() == null)
764                 throw new AlfrescoRuntimeException("Network broadcast mask not specified");
765
766             // Enable the NetBIOS SMB support, if enabled for this platform
767

768             setNetBIOSSMB(platformOK);
769
770             // Check for a bind address
771

772             String JavaDoc bindto = elem.getAttribute("bindto");
773             if (bindto != null && bindto.length() > 0)
774             {
775
776                 // Validate the bind address
777

778                 try
779                 {
780
781                     // Check the bind address
782

783                     InetAddress JavaDoc bindAddr = InetAddress.getByName(bindto);
784
785                     // Set the bind address for the NetBIOS name server
786

787                     setNetBIOSBindAddress(bindAddr);
788                 }
789                 catch (UnknownHostException JavaDoc ex)
790                 {
791                     throw new AlfrescoRuntimeException("Invalid NetBIOS bind address");
792                 }
793             }
794             else if (hasSMBBindAddress())
795             {
796
797                 // Use the SMB bind address for the NetBIOS name server
798

799                 setNetBIOSBindAddress(getSMBBindAddress());
800             }
801             else
802             {
803                 // Get a list of all the local addresses
804

805                 InetAddress JavaDoc[] addrs = null;
806                     
807                 try
808                 {
809                     // Get the local server IP address list
810

811                     addrs = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
812                 }
813                 catch (UnknownHostException JavaDoc ex)
814                 {
815                     logger.error("Failed to get local address list", ex);
816                 }
817                 
818                 // Check the address list for one or more valid local addresses filtering out the loopback address
819

820                 int addrCnt = 0;
821
822                 if ( addrs != null)
823                 {
824                     for (int i = 0; i < addrs.length; i++)
825                     {
826     
827                         // Check for a valid address, filter out '127.0.0.1' and '0.0.0.0' addresses
828

829                         if (addrs[i].getHostAddress().equals("127.0.0.1") == false
830                                 && addrs[i].getHostAddress().equals("0.0.0.0") == false)
831                             addrCnt++;
832                     }
833                 }
834                 
835                 // Check if any addresses were found
836

837                 if ( addrCnt == 0)
838                 {
839                     // Log the available IP addresses
840

841                     if ( logger.isDebugEnabled())
842                     {
843                         logger.debug("Local address list dump :-");
844                         if ( addrs != null)
845                         {
846                             for ( int i = 0; i < addrs.length; i++)
847                                 logger.debug( " Address: " + addrs[i]);
848                         }
849                         else
850                             logger.debug(" No addresses");
851                     }
852                     
853                     // Throw an exception to stop the CIFS/NetBIOS name server from starting
854

855                     throw new AlfrescoRuntimeException( "Failed to get IP address(es) for the local server, check hosts file and/or DNS setup");
856                 }
857                 
858             }
859         }
860         else
861         {
862
863             // Disable NetBIOS SMB support
864

865             setNetBIOSSMB(false);
866         }
867
868         // Check if TCP/IP SMB is enabled
869

870         elem = config.getConfigElement("tcpipSMB");
871         if (elem != null)
872         {
873
874             // Check if native SMB is enabled for the current platform
875

876             String JavaDoc platformsStr = elem.getAttribute("platforms");
877             boolean platformOK = false;
878
879             if (platformsStr != null)
880             {
881                 // Parse the list of platforms that native SMB is to be enabled for and
882
// check if the current platform is included
883

884                 EnumSet JavaDoc<PlatformType> enabledPlatforms = parsePlatformString(platformsStr);
885                 if (enabledPlatforms.contains(getPlatformType()))
886                     platformOK = true;
887             }
888             else
889             {
890                 // No restriction on platforms
891

892                 platformOK = true;
893             }
894
895             // Enable the TCP/IP SMB support, if enabled for this platform
896

897             setTcpipSMB(platformOK);
898         }
899         else
900         {
901
902             // Disable TCP/IP SMB support
903

904             setTcpipSMB(false);
905         }
906
907         // Check if Win32 NetBIOS is enabled
908

909         elem = config.getConfigElement("Win32NetBIOS");
910         if (elem != null)
911         {
912
913             // Check if the Win32 NetBIOS server name has been specified
914

915             String JavaDoc win32Name = elem.getAttribute("name");
916             if (win32Name != null && win32Name.length() > 0)
917             {
918
919                 // Validate the name
920

921                 if (win32Name.length() > 16)
922                     throw new AlfrescoRuntimeException("Invalid Win32 NetBIOS name, " + win32Name);
923
924                 // Set the Win32 NetBIOS file server name
925

926                 setWin32NetBIOSName(win32Name);
927             }
928
929             // Check if the Win32 NetBIOS LANA has been specified
930

931             String JavaDoc lanaStr = elem.getAttribute("lana");
932             if (lanaStr != null && lanaStr.length() > 0)
933             {
934
935                 // Validate the LANA number
936

937                 int lana = -1;
938
939                 try
940                 {
941                     lana = Integer.parseInt(lanaStr);
942                 }
943                 catch (NumberFormatException JavaDoc ex)
944                 {
945                     throw new AlfrescoRuntimeException("Invalid win32 NetBIOS LANA specified");
946                 }
947
948                 // LANA should be in the range 0-255
949

950                 if (lana < 0 || lana > 255)
951                     throw new AlfrescoRuntimeException("Invalid Win32 NetBIOS LANA number, " + lana);
952
953                 // Set the LANA number
954

955                 setWin32LANA(lana);
956             }
957
958             // Check if the native NetBIOS interface has been specified, either 'winsock' or 'netbios'
959

960             String JavaDoc nativeAPI = elem.getAttribute("api");
961             if ( nativeAPI != null && nativeAPI.length() > 0)
962             {
963                 // Validate the API type
964

965                 boolean useWinsock = true;
966                 
967                 if ( nativeAPI.equalsIgnoreCase("netbios"))
968                     useWinsock = false;
969                 else if ( nativeAPI.equalsIgnoreCase("winsock") == false)
970                     throw new AlfrescoRuntimeException("Invalid NetBIOS API type, spefify 'winsock' or 'netbios'");
971                 
972                 // Set the NetBIOS API to use
973

974                 setWin32WinsockNetBIOS( useWinsock);
975             }
976             
977             // Check if the current operating system is supported by the Win32
978
// NetBIOS handler
979

980             String JavaDoc osName = System.getProperty("os.name");
981             if (osName.startsWith("Windows")
982                     && (osName.endsWith("95") == false && osName.endsWith("98") == false && osName.endsWith("ME") == false))
983             {
984
985                 // Call the Win32NetBIOS native code to make sure it is initialized
986

987                 if ( Win32NetBIOS.LanaEnumerate() != null)
988                 {
989                     // Enable Win32 NetBIOS
990

991                     setWin32NetBIOS(true);
992                 }
993                 else
994                 {
995                     logger.warn("No NetBIOS LANAs available");
996                 }
997             }
998             else
999             {
1000
1001                // Win32 NetBIOS not supported on the current operating system
1002

1003                setWin32NetBIOS(false);
1004            }
1005        }
1006        else
1007        {
1008
1009            // Disable Win32 NetBIOS
1010

1011            setWin32NetBIOS(false);
1012        }
1013
1014        // Check if the host announcer should be enabled
1015

1016        elem = config.getConfigElement("Win32Announce");
1017        if (elem != null)
1018        {
1019
1020            // Check for an announcement interval
1021

1022            String JavaDoc interval = elem.getAttribute("interval");
1023            if (interval != null && interval.length() > 0)
1024            {
1025                try
1026                {
1027                    setWin32HostAnnounceInterval(Integer.parseInt(interval));
1028                }
1029                catch (NumberFormatException JavaDoc ex)
1030                {
1031                    throw new AlfrescoRuntimeException("Invalid host announcement interval");
1032                }
1033            }
1034
1035            // Check if the domain name has been set, this is required if the
1036
// host announcer is enabled
1037

1038            if (getDomainName() == null)
1039                throw new AlfrescoRuntimeException("Domain name must be specified if host announcement is enabled");
1040
1041            // Enable Win32 NetBIOS host announcement
1042

1043            setWin32HostAnnouncer(true);
1044        }
1045
1046        // Check if NetBIOS and/or TCP/IP SMB have been enabled
1047

1048        if (hasNetBIOSSMB() == false && hasTcpipSMB() == false && hasWin32NetBIOS() == false)
1049            throw new AlfrescoRuntimeException("NetBIOS SMB, TCP/IP SMB or Win32 NetBIOS must be enabled");
1050
1051        // Check if WINS servers are configured
1052

1053        elem = config.getConfigElement("WINS");
1054
1055        if (elem != null)
1056        {
1057
1058            // Get the primary WINS server
1059

1060            ConfigElement priWinsElem = elem.getChild("primary");
1061
1062            if (priWinsElem == null || priWinsElem.getValue().length() == 0)
1063                throw new AlfrescoRuntimeException("No primary WINS server configured");
1064
1065            // Validate the WINS server address
1066

1067            InetAddress JavaDoc primaryWINS = null;
1068
1069            try
1070            {
1071                primaryWINS = InetAddress.getByName(priWinsElem.getValue());
1072            }
1073            catch (UnknownHostException JavaDoc ex)
1074            {
1075                throw new AlfrescoRuntimeException("Invalid primary WINS server address, " + priWinsElem.getValue());
1076            }
1077
1078            // Check if a secondary WINS server has been specified
1079

1080            ConfigElement secWinsElem = elem.getChild("secondary");
1081            InetAddress JavaDoc secondaryWINS = null;
1082
1083            if (secWinsElem != null)
1084            {
1085
1086                // Validate the secondary WINS server address
1087

1088                try
1089                {
1090                    secondaryWINS = InetAddress.getByName(secWinsElem.getValue());
1091                }
1092                catch (UnknownHostException JavaDoc ex)
1093                {
1094                    throw new AlfrescoRuntimeException("Invalid secondary WINS server address, "
1095                            + secWinsElem.getValue());
1096                }
1097            }
1098
1099            // Set the WINS server address(es)
1100

1101            setPrimaryWINSServer(primaryWINS);
1102            if (secondaryWINS != null)
1103                setSecondaryWINSServer(secondaryWINS);
1104
1105            // Pass the setting to the NetBIOS session class
1106

1107            NetBIOSSession.setWINSServer(primaryWINS);
1108        }
1109
1110        // Check if WINS is configured, if we are running on Windows and socket based NetBIOS is enabled
1111

1112        else if (hasNetBIOSSMB() && getPlatformType() == PlatformType.WINDOWS)
1113        {
1114            // Get the WINS server list
1115

1116            String JavaDoc winsServers = Win32NetBIOS.getWINSServerList();
1117
1118            if (winsServers != null)
1119            {
1120                // Use the first WINS server address for now
1121

1122                StringTokenizer JavaDoc tokens = new StringTokenizer JavaDoc(winsServers, ",");
1123                String JavaDoc addr = tokens.nextToken();
1124
1125                try
1126                {
1127                    // Convert to a network address and check if the WINS server is accessible
1128

1129                    InetAddress JavaDoc winsAddr = InetAddress.getByName(addr);
1130
1131                    Socket JavaDoc winsSocket = new Socket JavaDoc();
1132                    InetSocketAddress JavaDoc sockAddr = new InetSocketAddress JavaDoc( winsAddr, RFCNetBIOSProtocol.NAME_PORT);
1133                    
1134                    winsSocket.connect(sockAddr, 3000);
1135                    winsSocket.close();
1136                    
1137                    // Set the primary WINS server address
1138

1139                    setPrimaryWINSServer(winsAddr);
1140
1141                    // Debug
1142

1143                    if (logger.isDebugEnabled())
1144                        logger.debug("Configuring to use WINS server " + addr);
1145                }
1146                catch (UnknownHostException JavaDoc ex)
1147                {
1148                    throw new AlfrescoRuntimeException("Invalid auto WINS server address, " + addr);
1149                }
1150                catch (IOException JavaDoc ex)
1151                {
1152                    if ( logger.isDebugEnabled())
1153                        logger.debug("Failed to connect to auto WINS server " + addr);
1154                }
1155            }
1156        }
1157
1158        // Check if session debug is enabled
1159

1160        elem = config.getConfigElement("sessionDebug");
1161        if (elem != null)
1162        {
1163
1164            // Check for session debug flags
1165

1166            String JavaDoc flags = elem.getAttribute("flags");
1167            int sessDbg = 0;
1168
1169            if (flags != null)
1170            {
1171
1172                // Parse the flags
1173

1174                flags = flags.toUpperCase();
1175                StringTokenizer JavaDoc token = new StringTokenizer JavaDoc(flags, ",");
1176
1177                while (token.hasMoreTokens())
1178                {
1179
1180                    // Get the current debug flag token
1181

1182                    String JavaDoc dbg = token.nextToken().trim();
1183
1184                    // Find the debug flag name
1185

1186                    int idx = 0;
1187
1188                    while (idx < m_sessDbgStr.length && m_sessDbgStr[idx].equalsIgnoreCase(dbg) == false)
1189                        idx++;
1190
1191                    if (idx > m_sessDbgStr.length)
1192                        throw new AlfrescoRuntimeException("Invalid session debug flag, " + dbg);
1193
1194                    // Set the debug flag
1195

1196                    sessDbg += 1 << idx;
1197                }
1198            }
1199
1200            // Set the session debug flags
1201

1202            setSessionDebugFlags(sessDbg);
1203        }
1204    }
1205
1206    /**
1207     * Process the FTP server configuration
1208     *
1209     * @param config Config
1210     */

1211    private final void processFTPServerConfig(Config config)
1212    {
1213        // If the configuration section is not valid then FTP is disabled
1214

1215        if ( config == null)
1216        {
1217            setFTPServerEnabled(false);
1218            return;
1219        }
1220            
1221        // Check for a bind address
1222

1223        ConfigElement elem = config.getConfigElement("bindto");
1224        if ( elem != null) {
1225        
1226            // Validate the bind address
1227

1228            String JavaDoc bindText = elem.getValue();
1229        
1230            try {
1231            
1232                // Check the bind address
1233

1234                InetAddress JavaDoc bindAddr = InetAddress.getByName(bindText);
1235        
1236                // Set the bind address for the FTP server
1237

1238                setFTPBindAddress(bindAddr);
1239            }
1240            catch (UnknownHostException JavaDoc ex) {
1241                throw new AlfrescoRuntimeException("Invalid FTP bindto address, " + elem.getValue());
1242            }
1243        }
1244
1245        // Check for an FTP server port
1246

1247        elem = config.getConfigElement("port");
1248        if ( elem != null) {
1249            try {
1250                setFTPPort(Integer.parseInt(elem.getValue()));
1251                if ( getFTPPort() <= 0 || getFTPPort() >= 65535)
1252                    throw new AlfrescoRuntimeException("FTP server port out of valid range");
1253            }
1254            catch (NumberFormatException JavaDoc ex) {
1255                throw new AlfrescoRuntimeException("Invalid FTP server port");
1256            }
1257        }
1258        else {
1259        
1260            // Use the default FTP port
1261

1262            setFTPPort(DefaultFTPServerPort);
1263        }
1264    
1265        // Check if anonymous login is allowed
1266

1267        elem = config.getConfigElement("allowAnonymous");
1268        if ( elem != null) {
1269        
1270            // Enable anonymous login to the FTP server
1271

1272            setAllowAnonymousFTP(true);
1273        
1274            // Check if an anonymous account has been specified
1275

1276            String JavaDoc anonAcc = elem.getAttribute("user");
1277            if ( anonAcc != null && anonAcc.length() > 0) {
1278            
1279                // Set the anonymous account name
1280

1281                setAnonymousFTPAccount(anonAcc);
1282            
1283                // Check if the anonymous account name is valid
1284

1285                if ( getAnonymousFTPAccount() == null || getAnonymousFTPAccount().length() == 0)
1286                    throw new AlfrescoRuntimeException("Anonymous FTP account invalid");
1287            }
1288            else {
1289            
1290                // Use the default anonymous account name
1291

1292                setAnonymousFTPAccount(DefaultFTPAnonymousAccount);
1293            }
1294        }
1295        else {
1296        
1297            // Disable anonymous logins
1298

1299            setAllowAnonymousFTP(false);
1300        }
1301
1302        // Check if a root path has been specified
1303

1304        elem = config.getConfigElement("rootDirectory");
1305        if ( elem != null) {
1306
1307            // Get the root path
1308

1309            String JavaDoc rootPath = elem.getValue();
1310                        
1311            // Validate the root path
1312

1313            try {
1314                
1315                // Parse the path
1316

1317                FTPPath ftpPath = new FTPPath(rootPath);
1318                
1319                // Set the root path
1320

1321                setFTPRootPath(rootPath);
1322            }
1323            catch (InvalidPathException ex) {
1324                throw new AlfrescoRuntimeException("Invalid FTP root directory, " + rootPath);
1325            }
1326        }
1327
1328        // Check if FTP debug is enabled
1329

1330        elem = config.getConfigElement("debug");
1331        if (elem != null) {
1332        
1333            // Check for FTP debug flags
1334

1335            String JavaDoc flags = elem.getAttribute("flags");
1336            int ftpDbg = 0;
1337        
1338            if ( flags != null) {
1339            
1340                // Parse the flags
1341

1342                flags = flags.toUpperCase();
1343                StringTokenizer JavaDoc token = new StringTokenizer JavaDoc(flags,",");
1344            
1345                while ( token.hasMoreTokens()) {
1346                
1347                    // Get the current debug flag token
1348

1349                    String JavaDoc dbg = token.nextToken().trim();
1350                
1351                    // Find the debug flag name
1352

1353                    int idx = 0;
1354                
1355                    while ( idx < m_ftpDebugStr.length && m_ftpDebugStr[idx].equalsIgnoreCase(dbg) == false)
1356                        idx++;
1357                    
1358                    if ( idx >= m_ftpDebugStr.length)
1359                        throw new AlfrescoRuntimeException("Invalid FTP debug flag, " + dbg);
1360                    
1361                    // Set the debug flag
1362

1363                    ftpDbg += 1 << idx;
1364                }
1365            }
1366
1367            // Set the FTP debug flags
1368

1369            setFTPDebug(ftpDbg);
1370        }
1371    }
1372
1373    /**
1374     * Process the filesystems configuration
1375     *
1376     * @param config Config
1377     */

1378    private final void processFilesystemsConfig(Config config)
1379    {
1380        // Check for the home folder filesystem
1381

1382        ConfigElement homeElem = config.getConfigElement("homeFolder");
1383        
1384        if ( homeElem != null)
1385        {
1386            try
1387            {
1388                // Create the home folder share mapper
1389

1390                HomeShareMapper shareMapper = new HomeShareMapper();
1391                shareMapper.initializeMapper( this, homeElem);
1392                
1393                // Use the home folder share mapper
1394

1395                m_shareMapper = shareMapper;
1396                
1397                // Debug
1398

1399                if ( logger.isDebugEnabled())
1400                    logger.debug("Using home folder share mapper");
1401            }
1402            catch (InvalidConfigurationException ex)
1403            {
1404                throw new AlfrescoRuntimeException("Failed to initialize home folder share mapper", ex);
1405            }
1406        }
1407        
1408        // Get the filesystem configuration elements
1409

1410        List JavaDoc<ConfigElement> filesysElems = config.getConfigElementList("filesystem");
1411
1412        if (filesysElems != null)
1413        {
1414
1415            // Add the filesystems
1416

1417            for (int i = 0; i < filesysElems.size(); i++)
1418            {
1419
1420                // Get the current filesystem configuration
1421

1422                ConfigElement elem = filesysElems.get(i);
1423                String JavaDoc filesysName = elem.getAttribute("name");
1424
1425                try
1426                {
1427                    // Create a new filesystem driver instance and create a context for
1428
// the new filesystem
1429
DiskInterface filesysDriver = this.diskInterface;
1430                    DiskDeviceContext filesysContext = (DiskDeviceContext) filesysDriver.createContext(elem);
1431
1432                    // Check if an access control list has been specified
1433

1434                    AccessControlList acls = null;
1435                    ConfigElement aclElem = elem.getChild("accessControl");
1436
1437                    if (aclElem != null)
1438                    {
1439
1440                        // Parse the access control list
1441

1442                        acls = processAccessControlList(aclElem);
1443                    }
1444                    else if (hasGlobalAccessControls())
1445                    {
1446
1447                        // Use the global access control list for this disk share
1448

1449                        acls = getGlobalAccessControls();
1450                    }
1451
1452                    // Check if change notifications are disabled
1453

1454                    boolean changeNotify = elem.getChild("disableChangeNotification") == null ? true : false;
1455
1456                    // Create the shared filesystem
1457

1458                    DiskSharedDevice filesys = new DiskSharedDevice(filesysName, filesysDriver, filesysContext);
1459
1460                    // Add any access controls to the share
1461

1462                    filesys.setAccessControlList(acls);
1463
1464                    // Enable/disable change notification for this device
1465

1466                    filesysContext.enableChangeHandler(changeNotify);
1467
1468                    // Start the filesystem
1469

1470                    filesysContext.startFilesystem(filesys);
1471
1472                    // Create the shared device and add to the list of available
1473
// shared filesystems
1474

1475                    addShare(filesys);
1476                }
1477                catch (DeviceContextException ex)
1478                {
1479                    throw new AlfrescoRuntimeException("Error creating filesystem " + filesysName, ex);
1480                }
1481            }
1482        }
1483    }
1484
1485    /**
1486     * Process the security configuration
1487     *
1488     * @param config Config
1489     */

1490    private final void processSecurityConfig(Config config)
1491    {
1492
1493        // Check if global access controls have been specified
1494

1495        ConfigElement globalACLs = config.getConfigElement("globalAccessControl");
1496        if (globalACLs != null)
1497        {
1498
1499            // Parse the access control list
1500

1501            AccessControlList acls = processAccessControlList(globalACLs);
1502            if (acls != null)
1503                setGlobalAccessControls(acls);
1504        }
1505
1506        // Check if a JCE provider class has been specified
1507

1508        ConfigElement jceElem = config.getConfigElement("JCEProvider");
1509        if (jceElem != null)
1510        {
1511
1512            // Set the JCE provider
1513

1514            setJCEProvider(jceElem.getValue());
1515        }
1516        else
1517        {
1518            // Use the default Cryptix JCE provider
1519

1520            setJCEProvider("cryptix.jce.provider.CryptixCrypto");
1521        }
1522        
1523        // Check if an authenticator has been specified
1524

1525        ConfigElement authElem = config.getConfigElement("authenticator");
1526        if (authElem != null)
1527        {
1528
1529            // Get the authenticator type, should be either 'local' or 'passthru'
1530

1531            String JavaDoc authType = authElem.getAttribute("type");
1532            if (authType == null)
1533                throw new AlfrescoRuntimeException("Authenticator type not specified");
1534
1535            // Get the authentication component type
1536

1537            NTLMMode ntlmMode = m_authenticationComponent.getNTLMMode();
1538            
1539            // Set the authenticator class to use
1540

1541            SrvAuthenticator auth = null;
1542            if (authType.equalsIgnoreCase("local"))
1543                auth = new LocalAuthenticator();
1544            else if (authType.equalsIgnoreCase("passthru"))
1545            {
1546                // Check if the appropriate authentication component type is configured
1547

1548                if ( ntlmMode != NTLMMode.NONE)
1549                    throw new AlfrescoRuntimeException("Wrong authentication setup for passthru authenticator");
1550                
1551                // Load the passthru authenticator dynamically
1552

1553                auth = loadAuthenticatorClass("org.alfresco.filesys.server.auth.passthru.PassthruAuthenticator");
1554                if ( auth == null)
1555                    throw new AlfrescoRuntimeException("Failed to load passthru authenticator");
1556            }
1557            else if (authType.equalsIgnoreCase("acegi"))
1558            {
1559                // Load the Acegi authenticator dynamically
1560

1561                auth = loadAuthenticatorClass("org.alfresco.filesys.server.auth.passthru.AcegiPassthruAuthenticator");
1562                if ( auth == null)
1563                    throw new AlfrescoRuntimeException("Failed to load Acegi passthru authenticator");
1564            }
1565            else if (authType.equalsIgnoreCase("alfresco"))
1566            {
1567                // Standard authenticator requires MD4 or passthru based authentication
1568

1569                if ( ntlmMode == NTLMMode.NONE)
1570                    throw new AlfrescoRuntimeException("Wrong authentication setup for alfresco authenticator");
1571                
1572                // Load the Alfresco authenticator dynamically
1573

1574                auth = loadAuthenticatorClass("org.alfresco.filesys.server.auth.ntlm.AlfrescoAuthenticator");
1575                if ( auth == null)
1576                    auth = loadAuthenticatorClass("org.alfresco.filesys.server.auth.AlfrescoAuthenticator");
1577                
1578                if ( auth == null)
1579                    throw new AlfrescoRuntimeException("Failed to load Alfresco authenticator");
1580            }
1581            else
1582                throw new AlfrescoRuntimeException("Invalid authenticator type, " + authType);
1583
1584            // Get the allow guest and map unknown user to guest settings
1585

1586            boolean allowGuest = authElem.getChild("allowGuest") != null ? true : false;
1587            boolean mapGuest = authElem.getChild("mapUnknownUserToGuest") != null ? true : false;
1588
1589            // Initialize and set the authenticator class
1590

1591            setAuthenticator(auth, authElem, allowGuest);
1592            auth.setMapToGuest( mapGuest);
1593        }
1594
1595        // Add the users
1596

1597        ConfigElement usersElem = config.getConfigElement("users");
1598        if (usersElem != null)
1599        {
1600
1601            // Get the list of user elements
1602

1603            List JavaDoc<ConfigElement> userElemList = usersElem.getChildren();
1604
1605            for (int i = 0; i < userElemList.size(); i++)
1606            {
1607
1608                // Get the current user element
1609

1610                ConfigElement curUserElem = userElemList.get(i);
1611
1612                if (curUserElem.getName().equals("localuser"))
1613                {
1614                    processUser(curUserElem);
1615                }
1616            }
1617        }
1618
1619    }
1620
1621    /**
1622     * Process an access control sub-section and return the access control list
1623     *
1624     * @param aclsElem ConfigElement
1625     */

1626    private final AccessControlList processAccessControlList(ConfigElement aclsElem)
1627    {
1628
1629        // Check if there is an access control manager configured
1630

1631        if (getAccessControlManager() == null)
1632            throw new AlfrescoRuntimeException("No access control manager configured");
1633
1634        // Create the access control list
1635

1636        AccessControlList acls = new AccessControlList();
1637
1638        // Check if there is a default access level for the ACL group
1639

1640        String JavaDoc attrib = aclsElem.getAttribute("default");
1641
1642        if (attrib != null && attrib.length() > 0)
1643        {
1644
1645            // Get the access level and validate
1646

1647            try
1648            {
1649
1650                // Parse the access level name
1651

1652                int access = AccessControlParser.parseAccessTypeString(attrib);
1653
1654                // Set the default access level for the access control list
1655

1656                acls.setDefaultAccessLevel(access);
1657            }
1658            catch (InvalidACLTypeException ex)
1659            {
1660                throw new AlfrescoRuntimeException("Default access level error", ex);
1661            }
1662            catch (ACLParseException ex)
1663            {
1664                throw new AlfrescoRuntimeException("Default access level error", ex);
1665            }
1666        }
1667
1668        // Parse each access control element
1669

1670        List JavaDoc<ConfigElement> aclElemList = aclsElem.getChildren();
1671
1672        if (aclElemList != null && aclElemList.size() > 0)
1673        {
1674
1675            // Create the access controls
1676

1677            for (int i = 0; i < aclsElem.getChildCount(); i++)
1678            {
1679
1680                // Get the current ACL element
1681

1682                ConfigElement curAclElem = aclElemList.get(i);
1683
1684                try
1685                {
1686                    // Create the access control and add to the list
1687

1688                    acls.addControl(getAccessControlManager().createAccessControl(curAclElem.getName(), curAclElem));
1689                }
1690                catch (InvalidACLTypeException ex)
1691                {
1692                    throw new AlfrescoRuntimeException("Invalid access control type - " + curAclElem.getName());
1693                }
1694                catch (ACLParseException ex)
1695                {
1696                    throw new AlfrescoRuntimeException("Access control parse error (" + curAclElem.getName() + ")", ex);
1697                }
1698            }
1699        }
1700
1701        // Check if there are no access control rules but the default access level is set to 'None',
1702
// this is not allowed as the share would not be accessible or visible.
1703

1704        if (acls.getDefaultAccessLevel() == AccessControl.NoAccess && acls.numberOfControls() == 0)
1705            throw new AlfrescoRuntimeException("Empty access control list and default access 'None' not allowed");
1706
1707        // Return the access control list
1708

1709        return acls;
1710    }
1711
1712    /**
1713     * Add a user account
1714     *
1715     * @param user ConfigElement
1716     */

1717    private final void processUser(ConfigElement user)
1718    {
1719
1720        // Get the username
1721

1722        String JavaDoc attr = user.getAttribute("name");
1723        if (attr == null || attr.length() == 0)
1724            throw new AlfrescoRuntimeException("User name not specified, or zero length");
1725
1726        // Check if the user already exists
1727

1728        String JavaDoc userName = attr;
1729
1730        if (hasUserAccounts() && getUserAccounts().findUser(userName) != null)
1731            throw new AlfrescoRuntimeException("User " + userName + " already defined");
1732
1733        // Get the password for the account
1734

1735        ConfigElement elem = user.getChild("password");
1736        if (elem == null)
1737            throw new AlfrescoRuntimeException("No password specified for user " + userName);
1738
1739        String JavaDoc password = elem.getValue();
1740
1741        // Create the user account
1742

1743        UserAccount userAcc = new UserAccount(userName, password);
1744
1745        // Check if the user in an administrator
1746

1747        if (user.getChild("administrator") != null)
1748            userAcc.setAdministrator(true);
1749
1750        // Get the real user name and comment
1751

1752        elem = user.getChild("realname");
1753        if (elem != null)
1754            userAcc.setRealName(elem.getValue());
1755
1756        elem = user.getChild("comment");
1757        if (elem != null)
1758            userAcc.setComment(elem.getValue());
1759
1760        // Add the user account
1761

1762        UserAccountList accList = getUserAccounts();
1763        if (accList == null)
1764            setUserAccounts(new UserAccountList());
1765        getUserAccounts().addUser(userAcc);
1766    }
1767
1768    /**
1769     * Parse the platforms attribute returning the set of platform ids
1770     *
1771     * @param platformStr String
1772     * @return EnumSet<PlatformType>
1773     */

1774    private final EnumSet JavaDoc<PlatformType> parsePlatformString(String JavaDoc platformStr)
1775    {
1776        // Split the platform string and build up a set of platform types
1777

1778        EnumSet JavaDoc<PlatformType> platformTypes = EnumSet.noneOf(PlatformType.class);
1779        if (platformStr == null || platformStr.length() == 0)
1780            return platformTypes;
1781
1782        StringTokenizer JavaDoc token = new StringTokenizer JavaDoc(platformStr.toUpperCase(), ",");
1783        String JavaDoc typ = null;
1784
1785        try
1786        {
1787            while (token.hasMoreTokens())
1788            {
1789
1790                // Get the current platform type string and validate
1791

1792                typ = token.nextToken().trim();
1793                PlatformType platform = PlatformType.valueOf(typ);
1794
1795                if (platform != PlatformType.Unknown)
1796                    platformTypes.add(platform);
1797                else
1798                    throw new AlfrescoRuntimeException("Invalid platform type, " + typ);
1799            }
1800        }
1801        catch (IllegalArgumentException JavaDoc ex)
1802        {
1803            throw new AlfrescoRuntimeException("Invalid platform type, " + typ);
1804        }
1805
1806        // Return the platform types
1807

1808        return platformTypes;
1809    }
1810
1811    /**
1812     * Add a shared device to the server configuration.
1813     *
1814     * @param shr SharedDevice
1815     * @return boolean
1816     */

1817    public final boolean addShare(SharedDevice shr)
1818    {
1819        return m_shareList.addShare(shr);
1820    }
1821
1822    /**
1823     * Add a server to the list of active servers
1824     *
1825     * @param srv NetworkServer
1826     */

1827    public synchronized final void addServer(NetworkServer srv)
1828    {
1829        m_serverList.addServer(srv);
1830    }
1831
1832    /**
1833     * Find an active server using the protocol name
1834     *
1835     * @param proto String
1836     * @return NetworkServer
1837     */

1838    public final NetworkServer findServer(String JavaDoc proto)
1839    {
1840        return m_serverList.findServer(proto);
1841    }
1842
1843    /**
1844     * Remove an active server
1845     *
1846     * @param proto String
1847     * @return NetworkServer
1848     */

1849    public final NetworkServer removeServer(String JavaDoc proto)
1850    {
1851        return m_serverList.removeServer(proto);
1852    }
1853
1854    /**
1855     * Return the number of active servers
1856     *
1857     * @return int
1858     */

1859    public final int numberOfServers()
1860    {
1861        return m_serverList.numberOfServers();
1862    }
1863
1864    /**
1865     * Return the server at the specified index
1866     *
1867     * @param idx int
1868     * @return NetworkServer
1869     */

1870    public final NetworkServer getServer(int idx)
1871    {
1872        return m_serverList.getServer(idx);
1873    }
1874
1875    /**
1876     * Check if there is an access control manager configured
1877     *
1878     * @return boolean
1879     */

1880    public final boolean hasAccessControlManager()
1881    {
1882        return m_aclManager != null ? true : false;
1883    }
1884
1885    /**
1886     * Get the access control manager that is used to control per share access
1887     *
1888     * @return AccessControlManager
1889     */

1890    public final AccessControlManager getAccessControlManager()
1891    {
1892        return m_aclManager;
1893    }
1894
1895    /**
1896     * Return the associated Acegi authentication manager
1897     *
1898     * @return AuthenticationManager
1899     */

1900    public final AuthenticationManager getAuthenticationManager()
1901    {
1902        return authenticationManager;
1903    }
1904
1905    /**
1906     * Check if the global access control list is configured
1907     *
1908     * @return boolean
1909     */

1910    public final boolean hasGlobalAccessControls()
1911    {
1912        return m_globalACLs != null ? true : false;
1913    }
1914
1915    /**
1916     * Return the global access control list
1917     *
1918     * @return AccessControlList
1919     */

1920    public final AccessControlList getGlobalAccessControls()
1921    {
1922        return m_globalACLs;
1923    }
1924
1925    /**
1926     * Get the authenticator object that is used to provide user and share connection
1927     * authentication.
1928     *
1929     * @return Authenticator
1930     */

1931    public final SrvAuthenticator getAuthenticator()
1932    {
1933        return m_authenticator;
1934    }
1935
1936    /**
1937     * Get the alfreso authentication service.
1938     *
1939     * @return
1940     */

1941    public final AuthenticationService getAuthenticationService()
1942    {
1943        return authenticationService;
1944    }
1945    
1946    /**
1947     * Return the authentication component, for access to internal functions
1948     *
1949     * @return AuthenticationComponent
1950     */

1951    public final AuthenticationComponent getAuthenticationComponent()
1952    {
1953        return m_authenticationComponent;
1954    }
1955    
1956    /**
1957     * Return the node service
1958     *
1959     * @return NodeService
1960     */

1961    public final NodeService getNodeService()
1962    {
1963        return m_nodeService;
1964    }
1965    
1966    /**
1967     * Return the person service
1968     *
1969     * @return PersonService
1970     */

1971    public final PersonService getPersonService()
1972    {
1973        return m_personService;
1974    }
1975    
1976    /**
1977     * Return the transaction service
1978     *
1979     * @return TransactionService
1980     */

1981    public final TransactionService getTransactionService()
1982    {
1983        return m_transactionService;
1984    }
1985    
1986    /**
1987     * Return the local address that the SMB server should bind to.
1988     *
1989     * @return java.net.InetAddress
1990     */

1991    public final InetAddress JavaDoc getSMBBindAddress()
1992    {
1993        return m_smbBindAddress;
1994    }
1995
1996    /**
1997     * Return the local address that the NetBIOS name server should bind to.
1998     *
1999     * @return java.net.InetAddress
2000     */

2001    public final InetAddress JavaDoc getNetBIOSBindAddress()
2002    {
2003        return m_nbBindAddress;
2004    }
2005
2006    /**
2007     * Return the network broadcast mask to be used for broadcast datagrams.
2008     *
2009     * @return java.lang.String
2010     */

2011    public final String JavaDoc getBroadcastMask()
2012    {
2013        return m_broadcast;
2014    }
2015
2016    /**
2017     * Return the server comment.
2018     *
2019     * @return java.lang.String
2020     */

2021    public final String JavaDoc getComment()
2022    {
2023        return m_comment != null ? m_comment : "";
2024    }
2025
2026    /**
2027     * Return the disk interface to be used to create shares
2028     *
2029     * @return DiskInterface
2030     */

2031    public final DiskInterface getDiskInterface()
2032    {
2033        return diskInterface;
2034    }
2035    
2036    /**
2037     * Return the domain name.
2038     *
2039     * @return java.lang.String
2040     */

2041    public final String JavaDoc getDomainName()
2042    {
2043        return m_domain;
2044    }
2045
2046    /**
2047     * Return the enabled SMB dialects that the server will use when negotiating sessions.
2048     *
2049     * @return DialectSelector
2050     */

2051    public final DialectSelector getEnabledDialects()
2052    {
2053        return m_dialects;
2054    }
2055
2056    /**
2057     * Return the server name.
2058     *
2059     * @return java.lang.String
2060     */

2061    public final String JavaDoc getServerName()
2062    {
2063        return m_name;
2064    }
2065
2066    /**
2067     * Return the server type flags.
2068     *
2069     * @return int
2070     */

2071    public final int getServerType()
2072    {
2073        return m_srvType;
2074    }
2075
2076    /**
2077     * Return the server debug flags.
2078     *
2079     * @return int
2080     */

2081    public final int getSessionDebugFlags()
2082    {
2083        return m_sessDebug;
2084    }
2085
2086    /**
2087     * Return the shared device list.
2088     *
2089     * @return SharedDeviceList
2090     */

2091    public final SharedDeviceList getShares()
2092    {
2093        return m_shareList;
2094    }
2095
2096    /**
2097     * Return the share mapper
2098     *
2099     * @return ShareMapper
2100     */

2101    public final ShareMapper getShareMapper()
2102    {
2103        return m_shareMapper;
2104    }
2105
2106    /**
2107     * Return the user account list.
2108     *
2109     * @return UserAccountList
2110     */

2111    public final UserAccountList getUserAccounts()
2112    {
2113        return m_userList;
2114    }
2115
2116    /**
2117     * Return the Win32 NetBIOS server name, if null the default server name will be used
2118     *
2119     * @return String
2120     */

2121    public final String JavaDoc getWin32ServerName()
2122    {
2123        return m_win32NBName;
2124    }
2125
2126    /**
2127     * Determine if the server should be announced via Win32 NetBIOS, so that it appears under
2128     * Network Neighborhood.
2129     *
2130     * @return boolean
2131     */

2132    public final boolean hasWin32EnableAnnouncer()
2133    {
2134        return m_win32NBAnnounce;
2135    }
2136
2137    /**
2138     * Return the Win32 NetBIOS host announcement interval, in minutes
2139     *
2140     * @return int
2141     */

2142    public final int getWin32HostAnnounceInterval()
2143    {
2144        return m_win32NBAnnounceInterval;
2145    }
2146
2147    /**
2148     * Return the Win3 NetBIOS LANA number to use, or -1 for the first available
2149     *
2150     * @return int
2151     */

2152    public final int getWin32LANA()
2153    {
2154        return m_win32NBLANA;
2155    }
2156
2157    /**
2158     * Determine if the Win32 Netbios() API or Winsock Netbios calls should be used
2159     *
2160     * @return boolean
2161     */

2162    public final boolean useWinsockNetBIOS()
2163    {
2164        return m_win32NBUseWinsock;
2165    }
2166    
2167    /**
2168     * Return the timezone name
2169     *
2170     * @return String
2171     */

2172    public final String JavaDoc getTimeZone()
2173    {
2174        return m_timeZone;
2175    }
2176
2177    /**
2178     * Return the timezone offset from UTC in seconds
2179     *
2180     * @return int
2181     */

2182    public final int getTimeZoneOffset()
2183    {
2184        return m_tzOffset;
2185    }
2186
2187    /**
2188     * Determine if the primary WINS server address has been set
2189     *
2190     * @return boolean
2191     */

2192    public final boolean hasPrimaryWINSServer()
2193    {
2194        return m_winsPrimary != null ? true : false;
2195    }
2196
2197    /**
2198     * Return the primary WINS server address
2199     *
2200     * @return InetAddress
2201     */

2202    public final InetAddress JavaDoc getPrimaryWINSServer()
2203    {
2204        return m_winsPrimary;
2205    }
2206
2207    /**
2208     * Determine if the secondary WINS server address has been set
2209     *
2210     * @return boolean
2211     */

2212    public final boolean hasSecondaryWINSServer()
2213    {
2214        return m_winsSecondary != null ? true : false;
2215    }
2216
2217    /**
2218     * Return the secondary WINS server address
2219     *
2220     * @return InetAddress
2221     */

2222    public final InetAddress JavaDoc getSecondaryWINSServer()
2223    {
2224        return m_winsSecondary;
2225    }
2226
2227    /**
2228     * Determine if the SMB server should bind to a particular local address
2229     *
2230     * @return boolean
2231     */

2232    public final boolean hasSMBBindAddress()
2233    {
2234        return m_smbBindAddress != null ? true : false;
2235    }
2236
2237    /**
2238     * Determine if the NetBIOS name server should bind to a particular local address
2239     *
2240     * @return boolean
2241     */

2242    public final boolean hasNetBIOSBindAddress()
2243    {
2244        return m_nbBindAddress != null ? true : false;
2245    }
2246
2247    /**
2248     * Determine if NetBIOS name server debugging is enabled
2249     *
2250     * @return boolean
2251     */

2252    public final boolean hasNetBIOSDebug()
2253    {
2254        return m_nbDebug;
2255    }
2256
2257    /**
2258     * Determine if host announcement debugging is enabled
2259     *
2260     * @return boolean
2261     */

2262    public final boolean hasHostAnnounceDebug()
2263    {
2264        return m_announceDebug;
2265    }
2266
2267    /**
2268     * Determine if the server should be announced so that it appears under Network Neighborhood.
2269     *
2270     * @return boolean
2271     */

2272    public final boolean hasEnableAnnouncer()
2273    {
2274        return m_announce;
2275    }
2276
2277    /**
2278     * Return the host announcement interval, in minutes
2279     *
2280     * @return int
2281     */

2282    public final int getHostAnnounceInterval()
2283    {
2284        return m_announceInterval;
2285    }
2286
2287    /**
2288     * Return the JCE provider class name
2289     *
2290     * @return String
2291     */

2292    public final String JavaDoc getJCEProvider()
2293    {
2294        return m_jceProviderClass;
2295    }
2296
2297    /**
2298     * Get the local server name and optionally trim the domain name
2299     *
2300     * @param trimDomain boolean
2301     * @return String
2302     */

2303    public final String JavaDoc getLocalServerName(boolean trimDomain)
2304    {
2305        // Check if the name has already been set
2306

2307        if (m_localName != null)
2308            return m_localName;
2309
2310        // Find the local server name
2311

2312        String JavaDoc srvName = null;
2313
2314        if (getPlatformType() == PlatformType.WINDOWS)
2315        {
2316            // Get the local name via JNI
2317

2318            srvName = Win32NetBIOS.GetLocalNetBIOSName();
2319        }
2320        else
2321        {
2322            // Get the DNS name of the local system
2323

2324            try
2325            {
2326                srvName = InetAddress.getLocalHost().getHostName();
2327            }
2328            catch (UnknownHostException JavaDoc ex)
2329            {
2330            }
2331        }
2332
2333        // Strip the domain name
2334

2335        if (trimDomain && srvName != null)
2336        {
2337            int pos = srvName.indexOf(".");
2338            if (pos != -1)
2339                srvName = srvName.substring(0, pos);
2340        }
2341
2342        // Save the local server name
2343

2344        m_localName = srvName;
2345
2346        // Return the local server name
2347

2348        return srvName;
2349    }
2350
2351    /**
2352     * Get the local domain/workgroup name
2353     *
2354     * @return String
2355     */

2356    public final String JavaDoc getLocalDomainName()
2357    {
2358        // Check if the local domain has been set
2359

2360        if (m_localDomain != null)
2361            return m_localDomain;
2362
2363        // Find the local domain name
2364

2365        String JavaDoc domainName = null;
2366
2367        if (getPlatformType() == PlatformType.WINDOWS)
2368        {
2369            // Get the local domain/workgroup name via JNI
2370

2371            domainName = Win32NetBIOS.GetLocalDomainName();
2372
2373            // Debug
2374

2375            if (logger.isDebugEnabled())
2376                logger.debug("Local domain name is " + domainName + " (via JNI)");
2377        }
2378        else
2379        {
2380            NetBIOSName nbName = null;
2381
2382            try
2383            {
2384                // Try and find the browse master on the local network
2385

2386                nbName = NetBIOSSession.FindName(NetBIOSName.BrowseMasterName, NetBIOSName.BrowseMasterGroup, 5000);
2387
2388                // Log the browse master details
2389

2390                if (logger.isDebugEnabled())
2391                    logger.debug("Found browse master at " + nbName.getIPAddressString(0));
2392
2393                // Get the NetBIOS name list from the browse master
2394

2395                NetBIOSNameList nbNameList = NetBIOSSession.FindNamesForAddress(nbName.getIPAddressString(0));
2396                nbName = nbNameList.findName(NetBIOSName.MasterBrowser, false);
2397
2398                // Set the domain/workgroup name
2399

2400                if (nbName != null)
2401                    domainName = nbName.getName();
2402            }
2403            catch (IOException JavaDoc ex)
2404            {
2405            }
2406        }
2407
2408        // Save the local domain name
2409

2410        m_localDomain = domainName;
2411
2412        // Return the local domain/workgroup name
2413

2414        return domainName;
2415    }
2416
2417    /**
2418     * Return the primary filesystem shared device, or null if not available
2419     *
2420     * @return DiskSharedDevice
2421     */

2422    public final DiskSharedDevice getPrimaryFilesystem()
2423    {
2424        // Check if there are any global shares defined
2425

2426        SharedDeviceList shares = getShares();
2427        DiskSharedDevice diskShare = null;
2428        
2429        if ( shares != null && shares.numberOfShares() > 0)
2430        {
2431            // Find the first available filesystem device
2432

2433            Enumeration JavaDoc<SharedDevice> shareEnum = shares.enumerateShares();
2434
2435            while ( diskShare == null && shareEnum.hasMoreElements())
2436            {
2437                SharedDevice curShare = shareEnum.nextElement();
2438                if ( curShare.getType() == ShareType.DISK)
2439                    diskShare = (DiskSharedDevice) curShare;
2440            }
2441        }
2442        
2443        // Return the first filesystem device, or null
2444

2445        return diskShare;
2446    }
2447    
2448    /**
2449     * Determine if Macintosh extension SMBs are enabled
2450     *
2451     * @return boolean
2452     */

2453    public final boolean hasMacintoshExtensions()
2454    {
2455        return m_macExtensions;
2456    }
2457
2458    /**
2459     * Determine if there are any user accounts defined.
2460     *
2461     * @return boolean
2462     */

2463    public final boolean hasUserAccounts()
2464    {
2465        if (m_userList != null && m_userList.numberOfUsers() > 0)
2466            return true;
2467        return false;
2468    }
2469
2470    /**
2471     * Determine if NetBIOS SMB is enabled
2472     *
2473     * @return boolean
2474     */

2475    public final boolean hasNetBIOSSMB()
2476    {
2477        return m_netBIOSEnable;
2478    }
2479
2480    /**
2481     * Determine if TCP/IP SMB is enabled
2482     *
2483     * @return boolean
2484     */

2485    public final boolean hasTcpipSMB()
2486    {
2487        return m_tcpSMBEnable;
2488    }
2489
2490    /**
2491     * Determine if Win32 NetBIOS is enabled
2492     *
2493     * @return boolean
2494     */

2495    public final boolean hasWin32NetBIOS()
2496    {
2497        return m_win32NBEnable;
2498    }
2499
2500    /**
2501     * Check if the SMB server is enabled
2502     *
2503     * @return boolean
2504     */

2505    public final boolean isSMBServerEnabled()
2506    {
2507        return m_smbEnable;
2508    }
2509
2510    /**
2511     * Set the SMB server enabled state
2512     *
2513     * @param ena boolean
2514     */

2515    public final void setSMBServerEnabled(boolean ena)
2516    {
2517        m_smbEnable = ena;
2518    }
2519
2520    /**
2521     * Set the FTP server enabled state
2522     *
2523     * @param ena boolean
2524     */

2525    public final void setFTPServerEnabled(boolean ena)
2526    {
2527        m_ftpEnable = ena;
2528    }
2529    
2530    /**
2531     * Set the authenticator to be used to authenticate users and share connections.
2532     *
2533     * @param auth SrvAuthenticator
2534     * @param params ConfigElement
2535     * @param allowGuest boolean
2536     */

2537    public final void setAuthenticator(SrvAuthenticator auth, ConfigElement params, boolean allowGuest)
2538    {
2539
2540        // Set the server authenticator mode and guest access
2541

2542        auth.setAccessMode(SrvAuthenticator.USER_MODE);
2543        auth.setAllowGuest(allowGuest);
2544
2545        // Initialize the authenticator using the parameter values
2546

2547        try
2548        {
2549            auth.initialize(this, params);
2550        }
2551        catch (InvalidConfigurationException ex)
2552        {
2553            throw new AlfrescoRuntimeException("Failed to initialize authenticator", ex);
2554        }
2555
2556        // Set the server authenticator and initialization parameters
2557

2558        m_authenticator = auth;
2559    }
2560
2561    /**
2562     * Set the local address that the SMB server should bind to.
2563     *
2564     * @param addr InetAddress
2565     */

2566    public final void setSMBBindAddress(InetAddress JavaDoc addr)
2567    {
2568        m_smbBindAddress = addr;
2569    }
2570
2571    /**
2572     * Set the local address that the NetBIOS name server should bind to.
2573     *
2574     * @param addr InetAddress
2575     */

2576    public final void setNetBIOSBindAddress(InetAddress JavaDoc addr)
2577    {
2578        m_nbBindAddress = addr;
2579    }
2580
2581    /**
2582     * Set the broadcast mask to be used for broadcast datagrams.
2583     *
2584     * @param mask String
2585     */

2586    public final void setBroadcastMask(String JavaDoc mask)
2587    {
2588        m_broadcast = mask;
2589
2590        // Copy settings to the NetBIOS session class
2591

2592        NetBIOSSession.setSubnetMask(mask);
2593    }
2594
2595    /**
2596     * Set the server comment.
2597     *
2598     * @param comment String
2599     */

2600    public final void setComment(String JavaDoc comment)
2601    {
2602        m_comment = comment;
2603    }
2604
2605    /**
2606     * Set the domain that the server belongs to.
2607     *
2608     * @param domain String
2609     */

2610    public final void setDomainName(String JavaDoc domain)
2611    {
2612        m_domain = domain;
2613    }
2614
2615    /**
2616     * Enable/disable the host announcer.
2617     *
2618     * @param b boolean
2619     */

2620    public final void setHostAnnouncer(boolean b)
2621    {
2622        m_announce = b;
2623    }
2624
2625    /**
2626     * Set the host announcement interval, in minutes
2627     *
2628     * @param ival int
2629     */

2630    public final void setHostAnnounceInterval(int ival)
2631    {
2632        m_announceInterval = ival;
2633    }
2634
2635    /**
2636     * Set the JCE provider
2637     *
2638     * @param providerClass String
2639     */

2640    public final void setJCEProvider(String JavaDoc providerClass)
2641    {
2642
2643        // Validate the JCE provider class
2644

2645        try
2646        {
2647
2648            // Load the JCE provider class and validate
2649

2650            Object JavaDoc jceObj = Class.forName(providerClass).newInstance();
2651            if (jceObj instanceof java.security.Provider JavaDoc)
2652            {
2653
2654                // Inform listeners, validate the configuration change
2655

2656                Provider JavaDoc jceProvider = (Provider JavaDoc) jceObj;
2657
2658                // Save the JCE provider class name
2659

2660                m_jceProviderClass = providerClass;
2661
2662                // Add the JCE provider
2663

2664                Security.addProvider(jceProvider);
2665            }
2666            else
2667            {
2668                throw new AlfrescoRuntimeException("JCE provider class is not a valid Provider class");
2669            }
2670        }
2671        catch (ClassNotFoundException JavaDoc ex)
2672        {
2673            throw new AlfrescoRuntimeException("JCE provider class " + providerClass + " not found");
2674        }
2675        catch (Exception JavaDoc ex)
2676        {
2677            throw new AlfrescoRuntimeException("JCE provider class error", ex);
2678        }
2679    }
2680
2681    /**
2682     * Enable/disable NetBIOS name server debug output
2683     *
2684     * @param ena boolean
2685     */

2686    public final void setNetBIOSDebug(boolean ena)
2687    {
2688        m_nbDebug = ena;
2689    }
2690
2691    /**
2692     * Enable/disable host announcement debug output
2693     *
2694     * @param ena boolean
2695     */

2696    public final void setHostAnnounceDebug(boolean ena)
2697    {
2698        m_announceDebug = ena;
2699    }
2700
2701    /**
2702     * Set the server name.
2703     *
2704     * @param name String
2705     */

2706    public final void setServerName(String JavaDoc name)
2707    {
2708        m_name = name;
2709    }
2710
2711    /**
2712     * Set the debug flags to be used by the server.
2713     *
2714     * @param flags int
2715     */

2716    public final void setSessionDebugFlags(int flags)
2717    {
2718        m_sessDebug = flags;
2719    }
2720
2721    /**
2722     * Set the user account list.
2723     *
2724     * @param users UserAccountList
2725     */

2726    public final void setUserAccounts(UserAccountList users)
2727    {
2728        m_userList = users;
2729    }
2730
2731    /**
2732     * Set the global access control list
2733     *
2734     * @param acls AccessControlList
2735     */

2736    public final void setGlobalAccessControls(AccessControlList acls)
2737    {
2738        m_globalACLs = acls;
2739    }
2740
2741    /**
2742     * Enable/disable the NetBIOS SMB support
2743     *
2744     * @param ena boolean
2745     */

2746    public final void setNetBIOSSMB(boolean ena)
2747    {
2748        m_netBIOSEnable = ena;
2749    }
2750
2751    /**
2752     * Enable/disable the TCP/IP SMB support
2753     *
2754     * @param ena boolean
2755     */

2756    public final void setTcpipSMB(boolean ena)
2757    {
2758        m_tcpSMBEnable = ena;
2759    }
2760
2761    /**
2762     * Enable/disable the Win32 NetBIOS SMB support
2763     *
2764     * @param ena boolean
2765     */

2766    public final void setWin32NetBIOS(boolean ena)
2767    {
2768        m_win32NBEnable = ena;
2769    }
2770
2771    /**
2772     * Set the Win32 NetBIOS file server name
2773     *
2774     * @param name String
2775     */

2776    public final void setWin32NetBIOSName(String JavaDoc name)
2777    {
2778        m_win32NBName = name;
2779    }
2780
2781    /**
2782     * Enable/disable the Win32 NetBIOS host announcer.
2783     *
2784     * @param b boolean
2785     */

2786    public final void setWin32HostAnnouncer(boolean b)
2787    {
2788        m_win32NBAnnounce = b;
2789    }
2790
2791    /**
2792     * Set the Win32 LANA to be used by the Win32 NetBIOS interface
2793     *
2794     * @param ival int
2795     */

2796    public final void setWin32LANA(int ival)
2797    {
2798        m_win32NBLANA = ival;
2799    }
2800
2801    /**
2802     * Set the Win32 NetBIOS host announcement interval, in minutes
2803     *
2804     * @param ival int
2805     */

2806    public final void setWin32HostAnnounceInterval(int ival)
2807    {
2808        m_win32NBAnnounceInterval = ival;
2809    }
2810
2811    /**
2812     * Set the Win32 NetBIOS interface to use either Winsock NetBIOS or the Netbios() API calls
2813     *
2814     * @param useWinsock boolean
2815     */

2816    public final void setWin32WinsockNetBIOS(boolean useWinsock)
2817    {
2818        m_win32NBUseWinsock = useWinsock;
2819    }
2820    
2821    /**
2822     * Set the server timezone name
2823     *
2824     * @param name String
2825     * @exception InvalidConfigurationException If the timezone is invalid
2826     */

2827    public final void setTimeZone(String JavaDoc name) throws InvalidConfigurationException
2828    {
2829
2830        // Validate the timezone
2831

2832        TimeZone JavaDoc tz = TimeZone.getTimeZone(name);
2833        if (tz == null)
2834            throw new InvalidConfigurationException("Invalid timezone, " + name);
2835
2836        // Set the timezone name and offset from UTC in minutes
2837
//
2838
// Invert the result of TimeZone.getRawOffset() as SMB/CIFS requires
2839
// positive minutes west of UTC
2840

2841        m_timeZone = name;
2842        m_tzOffset = -(tz.getRawOffset() / 60000);
2843    }
2844
2845    /**
2846     * Set the timezone offset from UTC in seconds (+/-)
2847     *
2848     * @param offset int
2849     */

2850    public final void setTimeZoneOffset(int offset)
2851    {
2852        m_tzOffset = offset;
2853    }
2854
2855    /**
2856     * Set the primary WINS server address
2857     *
2858     * @param addr InetAddress
2859     */

2860    public final void setPrimaryWINSServer(InetAddress JavaDoc addr)
2861    {
2862        m_winsPrimary = addr;
2863    }
2864
2865    /**
2866     * Set the secondary WINS server address
2867     *
2868     * @param addr InetAddress
2869     */

2870    public final void setSecondaryWINSServer(InetAddress JavaDoc addr)
2871    {
2872        m_winsSecondary = addr;
2873    }
2874
2875    /**
2876     * Check if the FTP server is enabled
2877     *
2878     * @return boolean
2879     */

2880    public final boolean isFTPServerEnabled()
2881    {
2882        return m_ftpEnable;
2883    }
2884
2885    /**
2886     * Return the FTP server bind address, may be null to indicate bind to all available addresses
2887     *
2888     * @return InetAddress
2889     */

2890    public final InetAddress JavaDoc getFTPBindAddress()
2891    {
2892        return m_ftpBindAddress;
2893    }
2894
2895    /**
2896     * Return the FTP server port to use for incoming connections
2897     *
2898     * @return int
2899     */

2900    public final int getFTPPort()
2901    {
2902        return m_ftpPort;
2903    }
2904
2905    /**
2906     * Determine if anonymous FTP access is allowed
2907     *
2908     * @return boolean
2909     */

2910    public final boolean allowAnonymousFTP()
2911    {
2912        return m_ftpAllowAnonymous;
2913    }
2914
2915    /**
2916     * Return the anonymous FTP account name
2917     *
2918     * @return String
2919     */

2920    public final String JavaDoc getAnonymousFTPAccount()
2921    {
2922        return m_ftpAnonymousAccount;
2923    }
2924
2925    /**
2926     * Return the FTP debug flags
2927     *
2928     * @return int
2929     */

2930    public final int getFTPDebug()
2931    {
2932        return m_ftpDebug;
2933    }
2934
2935    /**
2936     * Check if an FTP root path has been configured
2937     *
2938     * @return boolean
2939     */

2940    public final boolean hasFTPRootPath()
2941    {
2942        return m_ftpRootPath != null ? true : false;
2943    }
2944
2945    /**
2946     * Return the FTP root path
2947     *
2948     * @return String
2949     */

2950    public final String JavaDoc getFTPRootPath()
2951    {
2952        return m_ftpRootPath;
2953    }
2954
2955    /**
2956     * Set the FTP server bind address, may be null to indicate bind to all available addresses
2957     *
2958     * @param addr InetAddress
2959     */

2960    public final void setFTPBindAddress(InetAddress JavaDoc addr)
2961    {
2962        m_ftpBindAddress = addr;
2963    }
2964
2965    /**
2966     * Set the FTP server port to use for incoming connections, -1 indicates disable the FTP server
2967     *
2968     * @param port int
2969     */

2970    public final void setFTPPort(int port)
2971    {
2972        m_ftpPort = port;
2973    }
2974
2975    /**
2976     * Set the FTP root path
2977     *
2978     * @param path String
2979     */

2980    public final void setFTPRootPath(String JavaDoc path)
2981    {
2982        m_ftpRootPath = path;
2983    }
2984
2985    /**
2986     * Enable/disable anonymous FTP access
2987     *
2988     * @param ena boolean
2989     */

2990    public final void setAllowAnonymousFTP(boolean ena)
2991    {
2992        m_ftpAllowAnonymous = ena;
2993    }
2994
2995    /**
2996     * Set the anonymous FTP account name
2997     *
2998     * @param acc String
2999     */

3000    public final void setAnonymousFTPAccount(String JavaDoc acc)
3001    {
3002        m_ftpAnonymousAccount = acc;
3003    }
3004
3005    /**
3006     * Set the FTP debug flags
3007     *
3008     * @param dbg int
3009     */

3010    public final void setFTPDebug(int dbg)
3011    {
3012        m_ftpDebug = dbg;
3013    }
3014    
3015    /**
3016     * Close the server configuration, used to close various components that are shared between protocol
3017     * handlers.
3018     */

3019    public final void closeConfiguration()
3020    {
3021        // Close the authenticator
3022

3023        if ( getAuthenticator() != null)
3024        {
3025            getAuthenticator().closeAuthenticator();
3026            m_authenticator = null;
3027        }
3028
3029        // Close the shared filesystems
3030

3031        if ( getShares() != null && getShares().numberOfShares() > 0)
3032        {
3033            // Close the shared filesystems
3034

3035            Enumeration JavaDoc<SharedDevice> shareEnum = getShares().enumerateShares();
3036            
3037            while ( shareEnum.hasMoreElements())
3038            {
3039                SharedDevice share = shareEnum.nextElement();
3040                DeviceContext devCtx = share.getContext();
3041                
3042                if ( devCtx != null)
3043                    devCtx.CloseContext();
3044            }
3045        }
3046    }
3047    
3048    /**
3049     * Load an authenticator using dyanmic loading
3050     *
3051     * @param className String
3052     * @return SrvAuthenticator
3053     */

3054    private final SrvAuthenticator loadAuthenticatorClass(String JavaDoc className)
3055    {
3056        SrvAuthenticator srvAuth = null;
3057        
3058        try
3059        {
3060            // Load the authenticator class
3061

3062            Object JavaDoc authObj = Class.forName(className).newInstance();
3063            
3064            // Verify that the class is an authenticator
3065

3066            if ( authObj instanceof SrvAuthenticator)
3067                srvAuth = (SrvAuthenticator) authObj;
3068        }
3069        catch (Exception JavaDoc ex)
3070        {
3071            // Debug
3072

3073            if ( logger.isDebugEnabled())
3074                logger.debug("Failed to load authenticator class " + className);
3075        }
3076        
3077        // Return the authenticator class, or null if not available or invalid
3078

3079        return srvAuth;
3080    }
3081}
Popular Tags