1 17 package org.alfresco.filesys.server.config; 18 19 import java.io.IOException ; 20 import java.net.InetAddress ; 21 import java.net.InetSocketAddress ; 22 import java.net.Socket ; 23 import java.net.SocketException ; 24 import java.net.UnknownHostException ; 25 import java.security.Provider ; 26 import java.security.Security ; 27 import java.util.EnumSet ; 28 import java.util.Enumeration ; 29 import java.util.List ; 30 import java.util.StringTokenizer ; 31 import java.util.TimeZone ; 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 93 public class ServerConfiguration implements ApplicationListener 94 { 95 97 private static final Log logger = LogFactory.getLog("org.alfresco.smb.protocol"); 98 99 101 private static final String ConfigArea = "file-servers"; 102 private static final String ConfigCIFS = "CIFS Server"; 103 private static final String ConfigFTP = "FTP Server"; 104 private static final String ConfigFilesystems = "Filesystems"; 105 private static final String ConfigSecurity = "Filesystem Security"; 106 107 109 public static final String SERVER_CONFIGURATION = "fileServerConfiguration"; 110 111 115 private static final String 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 121 private static final String m_ftpDebugStr[] = { "STATE", "SEARCH", "INFO", "FILE", "FILEIO", "ERROR", "PKTTYPE", 122 "TIMING", "DATAPORT", "DIRECTORY" }; 123 124 126 private static final int DefaultFTPServerPort = 21; 127 128 130 private static final String DefaultFTPAnonymousAccount = "anonymous"; 131 132 134 public enum PlatformType 135 { 136 Unknown, WINDOWS, LINUX, SOLARIS, MACOSX 137 }; 138 139 private static final String TokenLocalName = "${localname}"; 141 142 private AuthenticationManager authenticationManager; 144 145 private ConfigService configService; 147 148 149 private DiskInterface diskInterface; 150 151 153 private PlatformType m_platform = PlatformType.Unknown; 154 155 157 private boolean m_smbEnable = true; 158 private boolean m_ftpEnable = true; 159 160 private String m_name; 162 163 private int m_srvType = ServerType.WorkStation + ServerType.Server + ServerType.NTServer; 165 166 private NetworkServerList m_serverList; 168 169 private String m_comment; 171 172 private String m_domain; 174 175 private String m_broadcast; 177 178 private boolean m_announce; 181 182 private int m_announceInterval; 183 184 private DialectSelector m_dialects; 186 187 private SharedDeviceList m_shareList; 189 190 private SrvAuthenticator m_authenticator; 192 193 private ShareMapper m_shareMapper; 195 196 private AccessControlManager m_aclManager; 198 199 private AccessControlList m_globalACLs; 202 203 private boolean m_nbDebug = false; 204 205 private boolean m_announceDebug = false; 206 207 private int m_sessDebug; 209 210 private boolean m_netBIOSEnable = true; 213 214 private boolean m_tcpSMBEnable = false; 215 216 private boolean m_win32NBEnable = false; 217 218 private InetAddress m_smbBindAddress; 220 221 private InetAddress m_nbBindAddress; 224 225 private InetAddress m_winsPrimary; 227 private InetAddress m_winsSecondary; 228 229 private UserAccountList m_userList; 231 232 private boolean m_macExtensions; 234 235 private String m_win32NBName; 241 242 private int m_win32NBLANA = -1; 245 246 private boolean m_win32NBAnnounce = false; 248 private int m_win32NBAnnounceInterval; 249 250 252 private boolean m_win32NBUseWinsock = true; 253 254 259 private InetAddress m_ftpBindAddress; 260 private int m_ftpPort = DefaultFTPServerPort; 261 262 264 private boolean m_ftpAllowAnonymous; 265 private String m_ftpAnonymousAccount; 266 267 269 private String m_ftpRootPath; 270 271 273 private int m_ftpDebug; 274 275 private String m_timeZone; 280 private int m_tzOffset; 281 282 private String m_jceProviderClass; 284 285 287 private String m_localName; 288 private String m_localDomain; 289 290 291 private boolean initialised; 292 293 295 private AuthenticationService authenticationService; 296 297 299 private AuthenticationComponent m_authenticationComponent; 300 301 303 private NodeService m_nodeService; 304 private PersonService m_personService; 305 private TransactionService m_transactionService; 306 307 310 public ServerConfiguration() 311 { 312 314 m_shareList = new SharedDeviceList(); 315 316 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 331 setAuthenticator(new LocalAuthenticator(), null, true); 332 333 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 348 m_aclManager = new DefaultAccessControlManager(); 349 m_aclManager.initialize(this, null); 350 351 353 try 354 { 355 setTimeZone(TimeZone.getDefault().getID()); 356 } 357 catch (Exception ex) 358 { 359 throw new AlfrescoRuntimeException("Failed to set timezone", ex); 360 } 361 362 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 410 public boolean isInitialised() 411 { 412 return initialised; 413 } 414 415 419 public void onApplicationEvent(ApplicationEvent event) 420 { 421 if (event instanceof ContextRefreshedEvent) 422 { 423 init(); 424 } 425 } 426 427 430 public void init() 431 { 432 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 470 ConfigLookupContext configCtx = new ConfigLookupContext(ConfigArea); 471 472 474 determinePlatformType(); 475 476 try 477 { 478 479 481 Config config = configService.getConfig(ConfigCIFS, configCtx); 482 processCIFSServerConfig(config); 483 484 486 config = configService.getConfig(ConfigFTP, configCtx); 487 processFTPServerConfig(config); 488 489 491 config = configService.getConfig(ConfigSecurity, configCtx); 492 processSecurityConfig(config); 493 494 496 config = configService.getConfig(ConfigFilesystems, configCtx); 497 processFilesystemsConfig(config); 498 499 initialised = true; 501 } 502 catch (UnsatisfiedLinkError ex) 503 { 504 506 logger.error("Error accessing Win32 NetBIOS, check DLL is on the path"); 507 508 510 setNetBIOSSMB(false); 511 setTcpipSMB(false); 512 setWin32NetBIOS(false); 513 514 setSMBServerEnabled(false); 515 } 516 catch (Throwable ex) 517 { 518 520 logger.error("File server configuration error, " + ex.getMessage(), ex); 521 522 524 setNetBIOSSMB(false); 525 setTcpipSMB(false); 526 setWin32NetBIOS(false); 527 528 setSMBServerEnabled(false); 529 } 530 } 531 532 535 private final void determinePlatformType() 536 { 537 539 String 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 556 public final PlatformType getPlatformType() 557 { 558 return m_platform; 559 } 560 561 566 private final void processCIFSServerConfig(Config config) 567 { 568 570 if ( config == null || config.getConfigElements().isEmpty()) 571 { 572 setSMBServerEnabled(false); 573 return; 574 } 575 576 581 ConfigElement elem = config.getConfigElement("broadcast"); 582 if (elem != null) 583 { 584 585 587 if (IPAddress.isNumericAddress(elem.getValue()) == false) 588 throw new AlfrescoRuntimeException("Invalid broadcast mask, must be n.n.n.n format"); 589 590 592 setBroadcastMask(elem.getValue()); 593 } 594 595 597 elem = config.getConfigElement("host"); 598 if (elem == null) 599 throw new AlfrescoRuntimeException("CIFS server host settings not specified"); 600 601 String hostName = elem.getAttribute("name"); 602 if (hostName == null || hostName.length() == 0) 603 throw new AlfrescoRuntimeException("Host name not specified or invalid"); 604 605 607 int pos = hostName.indexOf(TokenLocalName); 608 if (pos != -1) 609 { 610 611 613 String srvName = getLocalServerName(true); 614 615 617 StringBuilder hostStr = new StringBuilder (); 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 630 if (hostName.equals(srvName)) 631 throw new AlfrescoRuntimeException("CIFS server name must be unique"); 632 } 633 634 636 setServerName(hostName.toUpperCase()); 637 638 640 String domain = elem.getAttribute("domain"); 641 if (domain != null && domain.length() > 0) 642 { 643 645 setDomainName(domain.toUpperCase()); 646 } 647 else 648 { 649 651 String localDomain = getLocalDomainName(); 652 653 if ( localDomain == null && getPlatformType() != PlatformType.WINDOWS) 654 { 655 657 localDomain = "WORKGROUP"; 658 659 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 667 setDomainName( localDomain); 668 } 669 670 672 elem = config.getConfigElement("comment"); 673 if (elem != null) 674 setComment(elem.getValue()); 675 676 678 elem = config.getConfigElement("bindto"); 679 if (elem != null) 680 { 681 682 684 String bindText = elem.getValue(); 685 686 try 687 { 688 689 691 InetAddress bindAddr = InetAddress.getByName(bindText); 692 693 695 setSMBBindAddress(bindAddr); 696 } 697 catch (UnknownHostException ex) 698 { 699 throw new AlfrescoRuntimeException("Invalid CIFS server bind address"); 700 } 701 } 702 703 705 elem = config.getConfigElement("hostAnnounce"); 706 if (elem != null) 707 { 708 709 711 String interval = elem.getAttribute("interval"); 712 if (interval != null && interval.length() > 0) 713 { 714 try 715 { 716 setHostAnnounceInterval(Integer.parseInt(interval)); 717 } 718 catch (NumberFormatException ex) 719 { 720 throw new AlfrescoRuntimeException("Invalid host announcement interval"); 721 } 722 } 723 724 727 if (getDomainName() == null) 728 throw new AlfrescoRuntimeException("Domain name must be specified if host announcement is enabled"); 729 730 732 setHostAnnouncer(true); 733 } 734 735 737 elem = config.getConfigElement("netBIOSSMB"); 738 if (elem != null) 739 { 740 742 String platformsStr = elem.getAttribute("platforms"); 743 boolean platformOK = false; 744 745 if (platformsStr != null) 746 { 747 750 EnumSet <PlatformType> enabledPlatforms = parsePlatformString(platformsStr); 751 if (enabledPlatforms.contains(getPlatformType())) 752 platformOK = true; 753 } 754 else 755 { 756 758 platformOK = true; 759 } 760 761 763 if (getBroadcastMask() == null) 764 throw new AlfrescoRuntimeException("Network broadcast mask not specified"); 765 766 768 setNetBIOSSMB(platformOK); 769 770 772 String bindto = elem.getAttribute("bindto"); 773 if (bindto != null && bindto.length() > 0) 774 { 775 776 778 try 779 { 780 781 783 InetAddress bindAddr = InetAddress.getByName(bindto); 784 785 787 setNetBIOSBindAddress(bindAddr); 788 } 789 catch (UnknownHostException ex) 790 { 791 throw new AlfrescoRuntimeException("Invalid NetBIOS bind address"); 792 } 793 } 794 else if (hasSMBBindAddress()) 795 { 796 797 799 setNetBIOSBindAddress(getSMBBindAddress()); 800 } 801 else 802 { 803 805 InetAddress [] addrs = null; 806 807 try 808 { 809 811 addrs = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName()); 812 } 813 catch (UnknownHostException ex) 814 { 815 logger.error("Failed to get local address list", ex); 816 } 817 818 820 int addrCnt = 0; 821 822 if ( addrs != null) 823 { 824 for (int i = 0; i < addrs.length; i++) 825 { 826 827 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 837 if ( addrCnt == 0) 838 { 839 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 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 865 setNetBIOSSMB(false); 866 } 867 868 870 elem = config.getConfigElement("tcpipSMB"); 871 if (elem != null) 872 { 873 874 876 String platformsStr = elem.getAttribute("platforms"); 877 boolean platformOK = false; 878 879 if (platformsStr != null) 880 { 881 884 EnumSet <PlatformType> enabledPlatforms = parsePlatformString(platformsStr); 885 if (enabledPlatforms.contains(getPlatformType())) 886 platformOK = true; 887 } 888 else 889 { 890 892 platformOK = true; 893 } 894 895 897 setTcpipSMB(platformOK); 898 } 899 else 900 { 901 902 904 setTcpipSMB(false); 905 } 906 907 909 elem = config.getConfigElement("Win32NetBIOS"); 910 if (elem != null) 911 { 912 913 915 String win32Name = elem.getAttribute("name"); 916 if (win32Name != null && win32Name.length() > 0) 917 { 918 919 921 if (win32Name.length() > 16) 922 throw new AlfrescoRuntimeException("Invalid Win32 NetBIOS name, " + win32Name); 923 924 926 setWin32NetBIOSName(win32Name); 927 } 928 929 931 String lanaStr = elem.getAttribute("lana"); 932 if (lanaStr != null && lanaStr.length() > 0) 933 { 934 935 937 int lana = -1; 938 939 try 940 { 941 lana = Integer.parseInt(lanaStr); 942 } 943 catch (NumberFormatException ex) 944 { 945 throw new AlfrescoRuntimeException("Invalid win32 NetBIOS LANA specified"); 946 } 947 948 950 if (lana < 0 || lana > 255) 951 throw new AlfrescoRuntimeException("Invalid Win32 NetBIOS LANA number, " + lana); 952 953 955 setWin32LANA(lana); 956 } 957 958 960 String nativeAPI = elem.getAttribute("api"); 961 if ( nativeAPI != null && nativeAPI.length() > 0) 962 { 963 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 974 setWin32WinsockNetBIOS( useWinsock); 975 } 976 977 980 String 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 987 if ( Win32NetBIOS.LanaEnumerate() != null) 988 { 989 991 setWin32NetBIOS(true); 992 } 993 else 994 { 995 logger.warn("No NetBIOS LANAs available"); 996 } 997 } 998 else 999 { 1000 1001 1003 setWin32NetBIOS(false); 1004 } 1005 } 1006 else 1007 { 1008 1009 1011 setWin32NetBIOS(false); 1012 } 1013 1014 1016 elem = config.getConfigElement("Win32Announce"); 1017 if (elem != null) 1018 { 1019 1020 1022 String interval = elem.getAttribute("interval"); 1023 if (interval != null && interval.length() > 0) 1024 { 1025 try 1026 { 1027 setWin32HostAnnounceInterval(Integer.parseInt(interval)); 1028 } 1029 catch (NumberFormatException ex) 1030 { 1031 throw new AlfrescoRuntimeException("Invalid host announcement interval"); 1032 } 1033 } 1034 1035 1038 if (getDomainName() == null) 1039 throw new AlfrescoRuntimeException("Domain name must be specified if host announcement is enabled"); 1040 1041 1043 setWin32HostAnnouncer(true); 1044 } 1045 1046 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 1053 elem = config.getConfigElement("WINS"); 1054 1055 if (elem != null) 1056 { 1057 1058 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 1067 InetAddress primaryWINS = null; 1068 1069 try 1070 { 1071 primaryWINS = InetAddress.getByName(priWinsElem.getValue()); 1072 } 1073 catch (UnknownHostException ex) 1074 { 1075 throw new AlfrescoRuntimeException("Invalid primary WINS server address, " + priWinsElem.getValue()); 1076 } 1077 1078 1080 ConfigElement secWinsElem = elem.getChild("secondary"); 1081 InetAddress secondaryWINS = null; 1082 1083 if (secWinsElem != null) 1084 { 1085 1086 1088 try 1089 { 1090 secondaryWINS = InetAddress.getByName(secWinsElem.getValue()); 1091 } 1092 catch (UnknownHostException ex) 1093 { 1094 throw new AlfrescoRuntimeException("Invalid secondary WINS server address, " 1095 + secWinsElem.getValue()); 1096 } 1097 } 1098 1099 1101 setPrimaryWINSServer(primaryWINS); 1102 if (secondaryWINS != null) 1103 setSecondaryWINSServer(secondaryWINS); 1104 1105 1107 NetBIOSSession.setWINSServer(primaryWINS); 1108 } 1109 1110 1112 else if (hasNetBIOSSMB() && getPlatformType() == PlatformType.WINDOWS) 1113 { 1114 1116 String winsServers = Win32NetBIOS.getWINSServerList(); 1117 1118 if (winsServers != null) 1119 { 1120 1122 StringTokenizer tokens = new StringTokenizer (winsServers, ","); 1123 String addr = tokens.nextToken(); 1124 1125 try 1126 { 1127 1129 InetAddress winsAddr = InetAddress.getByName(addr); 1130 1131 Socket winsSocket = new Socket (); 1132 InetSocketAddress sockAddr = new InetSocketAddress ( winsAddr, RFCNetBIOSProtocol.NAME_PORT); 1133 1134 winsSocket.connect(sockAddr, 3000); 1135 winsSocket.close(); 1136 1137 1139 setPrimaryWINSServer(winsAddr); 1140 1141 1143 if (logger.isDebugEnabled()) 1144 logger.debug("Configuring to use WINS server " + addr); 1145 } 1146 catch (UnknownHostException ex) 1147 { 1148 throw new AlfrescoRuntimeException("Invalid auto WINS server address, " + addr); 1149 } 1150 catch (IOException ex) 1151 { 1152 if ( logger.isDebugEnabled()) 1153 logger.debug("Failed to connect to auto WINS server " + addr); 1154 } 1155 } 1156 } 1157 1158 1160 elem = config.getConfigElement("sessionDebug"); 1161 if (elem != null) 1162 { 1163 1164 1166 String flags = elem.getAttribute("flags"); 1167 int sessDbg = 0; 1168 1169 if (flags != null) 1170 { 1171 1172 1174 flags = flags.toUpperCase(); 1175 StringTokenizer token = new StringTokenizer (flags, ","); 1176 1177 while (token.hasMoreTokens()) 1178 { 1179 1180 1182 String dbg = token.nextToken().trim(); 1183 1184 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 1196 sessDbg += 1 << idx; 1197 } 1198 } 1199 1200 1202 setSessionDebugFlags(sessDbg); 1203 } 1204 } 1205 1206 1211 private final void processFTPServerConfig(Config config) 1212 { 1213 1215 if ( config == null) 1216 { 1217 setFTPServerEnabled(false); 1218 return; 1219 } 1220 1221 1223 ConfigElement elem = config.getConfigElement("bindto"); 1224 if ( elem != null) { 1225 1226 1228 String bindText = elem.getValue(); 1229 1230 try { 1231 1232 1234 InetAddress bindAddr = InetAddress.getByName(bindText); 1235 1236 1238 setFTPBindAddress(bindAddr); 1239 } 1240 catch (UnknownHostException ex) { 1241 throw new AlfrescoRuntimeException("Invalid FTP bindto address, " + elem.getValue()); 1242 } 1243 } 1244 1245 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 ex) { 1255 throw new AlfrescoRuntimeException("Invalid FTP server port"); 1256 } 1257 } 1258 else { 1259 1260 1262 setFTPPort(DefaultFTPServerPort); 1263 } 1264 1265 1267 elem = config.getConfigElement("allowAnonymous"); 1268 if ( elem != null) { 1269 1270 1272 setAllowAnonymousFTP(true); 1273 1274 1276 String anonAcc = elem.getAttribute("user"); 1277 if ( anonAcc != null && anonAcc.length() > 0) { 1278 1279 1281 setAnonymousFTPAccount(anonAcc); 1282 1283 1285 if ( getAnonymousFTPAccount() == null || getAnonymousFTPAccount().length() == 0) 1286 throw new AlfrescoRuntimeException("Anonymous FTP account invalid"); 1287 } 1288 else { 1289 1290 1292 setAnonymousFTPAccount(DefaultFTPAnonymousAccount); 1293 } 1294 } 1295 else { 1296 1297 1299 setAllowAnonymousFTP(false); 1300 } 1301 1302 1304 elem = config.getConfigElement("rootDirectory"); 1305 if ( elem != null) { 1306 1307 1309 String rootPath = elem.getValue(); 1310 1311 1313 try { 1314 1315 1317 FTPPath ftpPath = new FTPPath(rootPath); 1318 1319 1321 setFTPRootPath(rootPath); 1322 } 1323 catch (InvalidPathException ex) { 1324 throw new AlfrescoRuntimeException("Invalid FTP root directory, " + rootPath); 1325 } 1326 } 1327 1328 1330 elem = config.getConfigElement("debug"); 1331 if (elem != null) { 1332 1333 1335 String flags = elem.getAttribute("flags"); 1336 int ftpDbg = 0; 1337 1338 if ( flags != null) { 1339 1340 1342 flags = flags.toUpperCase(); 1343 StringTokenizer token = new StringTokenizer (flags,","); 1344 1345 while ( token.hasMoreTokens()) { 1346 1347 1349 String dbg = token.nextToken().trim(); 1350 1351 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 1363 ftpDbg += 1 << idx; 1364 } 1365 } 1366 1367 1369 setFTPDebug(ftpDbg); 1370 } 1371 } 1372 1373 1378 private final void processFilesystemsConfig(Config config) 1379 { 1380 1382 ConfigElement homeElem = config.getConfigElement("homeFolder"); 1383 1384 if ( homeElem != null) 1385 { 1386 try 1387 { 1388 1390 HomeShareMapper shareMapper = new HomeShareMapper(); 1391 shareMapper.initializeMapper( this, homeElem); 1392 1393 1395 m_shareMapper = shareMapper; 1396 1397 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 1410 List <ConfigElement> filesysElems = config.getConfigElementList("filesystem"); 1411 1412 if (filesysElems != null) 1413 { 1414 1415 1417 for (int i = 0; i < filesysElems.size(); i++) 1418 { 1419 1420 1422 ConfigElement elem = filesysElems.get(i); 1423 String filesysName = elem.getAttribute("name"); 1424 1425 try 1426 { 1427 DiskInterface filesysDriver = this.diskInterface; 1430 DiskDeviceContext filesysContext = (DiskDeviceContext) filesysDriver.createContext(elem); 1431 1432 1434 AccessControlList acls = null; 1435 ConfigElement aclElem = elem.getChild("accessControl"); 1436 1437 if (aclElem != null) 1438 { 1439 1440 1442 acls = processAccessControlList(aclElem); 1443 } 1444 else if (hasGlobalAccessControls()) 1445 { 1446 1447 1449 acls = getGlobalAccessControls(); 1450 } 1451 1452 1454 boolean changeNotify = elem.getChild("disableChangeNotification") == null ? true : false; 1455 1456 1458 DiskSharedDevice filesys = new DiskSharedDevice(filesysName, filesysDriver, filesysContext); 1459 1460 1462 filesys.setAccessControlList(acls); 1463 1464 1466 filesysContext.enableChangeHandler(changeNotify); 1467 1468 1470 filesysContext.startFilesystem(filesys); 1471 1472 1475 addShare(filesys); 1476 } 1477 catch (DeviceContextException ex) 1478 { 1479 throw new AlfrescoRuntimeException("Error creating filesystem " + filesysName, ex); 1480 } 1481 } 1482 } 1483 } 1484 1485 1490 private final void processSecurityConfig(Config config) 1491 { 1492 1493 1495 ConfigElement globalACLs = config.getConfigElement("globalAccessControl"); 1496 if (globalACLs != null) 1497 { 1498 1499 1501 AccessControlList acls = processAccessControlList(globalACLs); 1502 if (acls != null) 1503 setGlobalAccessControls(acls); 1504 } 1505 1506 1508 ConfigElement jceElem = config.getConfigElement("JCEProvider"); 1509 if (jceElem != null) 1510 { 1511 1512 1514 setJCEProvider(jceElem.getValue()); 1515 } 1516 else 1517 { 1518 1520 setJCEProvider("cryptix.jce.provider.CryptixCrypto"); 1521 } 1522 1523 1525 ConfigElement authElem = config.getConfigElement("authenticator"); 1526 if (authElem != null) 1527 { 1528 1529 1531 String authType = authElem.getAttribute("type"); 1532 if (authType == null) 1533 throw new AlfrescoRuntimeException("Authenticator type not specified"); 1534 1535 1537 NTLMMode ntlmMode = m_authenticationComponent.getNTLMMode(); 1538 1539 1541 SrvAuthenticator auth = null; 1542 if (authType.equalsIgnoreCase("local")) 1543 auth = new LocalAuthenticator(); 1544 else if (authType.equalsIgnoreCase("passthru")) 1545 { 1546 1548 if ( ntlmMode != NTLMMode.NONE) 1549 throw new AlfrescoRuntimeException("Wrong authentication setup for passthru authenticator"); 1550 1551 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 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 1569 if ( ntlmMode == NTLMMode.NONE) 1570 throw new AlfrescoRuntimeException("Wrong authentication setup for alfresco authenticator"); 1571 1572 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 1586 boolean allowGuest = authElem.getChild("allowGuest") != null ? true : false; 1587 boolean mapGuest = authElem.getChild("mapUnknownUserToGuest") != null ? true : false; 1588 1589 1591 setAuthenticator(auth, authElem, allowGuest); 1592 auth.setMapToGuest( mapGuest); 1593 } 1594 1595 1597 ConfigElement usersElem = config.getConfigElement("users"); 1598 if (usersElem != null) 1599 { 1600 1601 1603 List <ConfigElement> userElemList = usersElem.getChildren(); 1604 1605 for (int i = 0; i < userElemList.size(); i++) 1606 { 1607 1608 1610 ConfigElement curUserElem = userElemList.get(i); 1611 1612 if (curUserElem.getName().equals("localuser")) 1613 { 1614 processUser(curUserElem); 1615 } 1616 } 1617 } 1618 1619 } 1620 1621 1626 private final AccessControlList processAccessControlList(ConfigElement aclsElem) 1627 { 1628 1629 1631 if (getAccessControlManager() == null) 1632 throw new AlfrescoRuntimeException("No access control manager configured"); 1633 1634 1636 AccessControlList acls = new AccessControlList(); 1637 1638 1640 String attrib = aclsElem.getAttribute("default"); 1641 1642 if (attrib != null && attrib.length() > 0) 1643 { 1644 1645 1647 try 1648 { 1649 1650 1652 int access = AccessControlParser.parseAccessTypeString(attrib); 1653 1654 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 1670 List <ConfigElement> aclElemList = aclsElem.getChildren(); 1671 1672 if (aclElemList != null && aclElemList.size() > 0) 1673 { 1674 1675 1677 for (int i = 0; i < aclsElem.getChildCount(); i++) 1678 { 1679 1680 1682 ConfigElement curAclElem = aclElemList.get(i); 1683 1684 try 1685 { 1686 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 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 1709 return acls; 1710 } 1711 1712 1717 private final void processUser(ConfigElement user) 1718 { 1719 1720 1722 String attr = user.getAttribute("name"); 1723 if (attr == null || attr.length() == 0) 1724 throw new AlfrescoRuntimeException("User name not specified, or zero length"); 1725 1726 1728 String userName = attr; 1729 1730 if (hasUserAccounts() && getUserAccounts().findUser(userName) != null) 1731 throw new AlfrescoRuntimeException("User " + userName + " already defined"); 1732 1733 1735 ConfigElement elem = user.getChild("password"); 1736 if (elem == null) 1737 throw new AlfrescoRuntimeException("No password specified for user " + userName); 1738 1739 String password = elem.getValue(); 1740 1741 1743 UserAccount userAcc = new UserAccount(userName, password); 1744 1745 1747 if (user.getChild("administrator") != null) 1748 userAcc.setAdministrator(true); 1749 1750 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 1762 UserAccountList accList = getUserAccounts(); 1763 if (accList == null) 1764 setUserAccounts(new UserAccountList()); 1765 getUserAccounts().addUser(userAcc); 1766 } 1767 1768 1774 private final EnumSet <PlatformType> parsePlatformString(String platformStr) 1775 { 1776 1778 EnumSet <PlatformType> platformTypes = EnumSet.noneOf(PlatformType.class); 1779 if (platformStr == null || platformStr.length() == 0) 1780 return platformTypes; 1781 1782 StringTokenizer token = new StringTokenizer (platformStr.toUpperCase(), ","); 1783 String typ = null; 1784 1785 try 1786 { 1787 while (token.hasMoreTokens()) 1788 { 1789 1790 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 ex) 1802 { 1803 throw new AlfrescoRuntimeException("Invalid platform type, " + typ); 1804 } 1805 1806 1808 return platformTypes; 1809 } 1810 1811 1817 public final boolean addShare(SharedDevice shr) 1818 { 1819 return m_shareList.addShare(shr); 1820 } 1821 1822 1827 public synchronized final void addServer(NetworkServer srv) 1828 { 1829 m_serverList.addServer(srv); 1830 } 1831 1832 1838 public final NetworkServer findServer(String proto) 1839 { 1840 return m_serverList.findServer(proto); 1841 } 1842 1843 1849 public final NetworkServer removeServer(String proto) 1850 { 1851 return m_serverList.removeServer(proto); 1852 } 1853 1854 1859 public final int numberOfServers() 1860 { 1861 return m_serverList.numberOfServers(); 1862 } 1863 1864 1870 public final NetworkServer getServer(int idx) 1871 { 1872 return m_serverList.getServer(idx); 1873 } 1874 1875 1880 public final boolean hasAccessControlManager() 1881 { 1882 return m_aclManager != null ? true : false; 1883 } 1884 1885 1890 public final AccessControlManager getAccessControlManager() 1891 { 1892 return m_aclManager; 1893 } 1894 1895 1900 public final AuthenticationManager getAuthenticationManager() 1901 { 1902 return authenticationManager; 1903 } 1904 1905 1910 public final boolean hasGlobalAccessControls() 1911 { 1912 return m_globalACLs != null ? true : false; 1913 } 1914 1915 1920 public final AccessControlList getGlobalAccessControls() 1921 { 1922 return m_globalACLs; 1923 } 1924 1925 1931 public final SrvAuthenticator getAuthenticator() 1932 { 1933 return m_authenticator; 1934 } 1935 1936 1941 public final AuthenticationService getAuthenticationService() 1942 { 1943 return authenticationService; 1944 } 1945 1946 1951 public final AuthenticationComponent getAuthenticationComponent() 1952 { 1953 return m_authenticationComponent; 1954 } 1955 1956 1961 public final NodeService getNodeService() 1962 { 1963 return m_nodeService; 1964 } 1965 1966 1971 public final PersonService getPersonService() 1972 { 1973 return m_personService; 1974 } 1975 1976 1981 public final TransactionService getTransactionService() 1982 { 1983 return m_transactionService; 1984 } 1985 1986 1991 public final InetAddress getSMBBindAddress() 1992 { 1993 return m_smbBindAddress; 1994 } 1995 1996 2001 public final InetAddress getNetBIOSBindAddress() 2002 { 2003 return m_nbBindAddress; 2004 } 2005 2006 2011 public final String getBroadcastMask() 2012 { 2013 return m_broadcast; 2014 } 2015 2016 2021 public final String getComment() 2022 { 2023 return m_comment != null ? m_comment : ""; 2024 } 2025 2026 2031 public final DiskInterface getDiskInterface() 2032 { 2033 return diskInterface; 2034 } 2035 2036 2041 public final String getDomainName() 2042 { 2043 return m_domain; 2044 } 2045 2046 2051 public final DialectSelector getEnabledDialects() 2052 { 2053 return m_dialects; 2054 } 2055 2056 2061 public final String getServerName() 2062 { 2063 return m_name; 2064 } 2065 2066 2071 public final int getServerType() 2072 { 2073 return m_srvType; 2074 } 2075 2076 2081 public final int getSessionDebugFlags() 2082 { 2083 return m_sessDebug; 2084 } 2085 2086 2091 public final SharedDeviceList getShares() 2092 { 2093 return m_shareList; 2094 } 2095 2096 2101 public final ShareMapper getShareMapper() 2102 { 2103 return m_shareMapper; 2104 } 2105 2106 2111 public final UserAccountList getUserAccounts() 2112 { 2113 return m_userList; 2114 } 2115 2116 2121 public final String getWin32ServerName() 2122 { 2123 return m_win32NBName; 2124 } 2125 2126 2132 public final boolean hasWin32EnableAnnouncer() 2133 { 2134 return m_win32NBAnnounce; 2135 } 2136 2137 2142 public final int getWin32HostAnnounceInterval() 2143 { 2144 return m_win32NBAnnounceInterval; 2145 } 2146 2147 2152 public final int getWin32LANA() 2153 { 2154 return m_win32NBLANA; 2155 } 2156 2157 2162 public final boolean useWinsockNetBIOS() 2163 { 2164 return m_win32NBUseWinsock; 2165 } 2166 2167 2172 public final String getTimeZone() 2173 { 2174 return m_timeZone; 2175 } 2176 2177 2182 public final int getTimeZoneOffset() 2183 { 2184 return m_tzOffset; 2185 } 2186 2187 2192 public final boolean hasPrimaryWINSServer() 2193 { 2194 return m_winsPrimary != null ? true : false; 2195 } 2196 2197 2202 public final InetAddress getPrimaryWINSServer() 2203 { 2204 return m_winsPrimary; 2205 } 2206 2207 2212 public final boolean hasSecondaryWINSServer() 2213 { 2214 return m_winsSecondary != null ? true : false; 2215 } 2216 2217 2222 public final InetAddress getSecondaryWINSServer() 2223 { 2224 return m_winsSecondary; 2225 } 2226 2227 2232 public final boolean hasSMBBindAddress() 2233 { 2234 return m_smbBindAddress != null ? true : false; 2235 } 2236 2237 2242 public final boolean hasNetBIOSBindAddress() 2243 { 2244 return m_nbBindAddress != null ? true : false; 2245 } 2246 2247 2252 public final boolean hasNetBIOSDebug() 2253 { 2254 return m_nbDebug; 2255 } 2256 2257 2262 public final boolean hasHostAnnounceDebug() 2263 { 2264 return m_announceDebug; 2265 } 2266 2267 2272 public final boolean hasEnableAnnouncer() 2273 { 2274 return m_announce; 2275 } 2276 2277 2282 public final int getHostAnnounceInterval() 2283 { 2284 return m_announceInterval; 2285 } 2286 2287 2292 public final String getJCEProvider() 2293 { 2294 return m_jceProviderClass; 2295 } 2296 2297 2303 public final String getLocalServerName(boolean trimDomain) 2304 { 2305 2307 if (m_localName != null) 2308 return m_localName; 2309 2310 2312 String srvName = null; 2313 2314 if (getPlatformType() == PlatformType.WINDOWS) 2315 { 2316 2318 srvName = Win32NetBIOS.GetLocalNetBIOSName(); 2319 } 2320 else 2321 { 2322 2324 try 2325 { 2326 srvName = InetAddress.getLocalHost().getHostName(); 2327 } 2328 catch (UnknownHostException ex) 2329 { 2330 } 2331 } 2332 2333 2335 if (trimDomain && srvName != null) 2336 { 2337 int pos = srvName.indexOf("."); 2338 if (pos != -1) 2339 srvName = srvName.substring(0, pos); 2340 } 2341 2342 2344 m_localName = srvName; 2345 2346 2348 return srvName; 2349 } 2350 2351 2356 public final String getLocalDomainName() 2357 { 2358 2360 if (m_localDomain != null) 2361 return m_localDomain; 2362 2363 2365 String domainName = null; 2366 2367 if (getPlatformType() == PlatformType.WINDOWS) 2368 { 2369 2371 domainName = Win32NetBIOS.GetLocalDomainName(); 2372 2373 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 2386 nbName = NetBIOSSession.FindName(NetBIOSName.BrowseMasterName, NetBIOSName.BrowseMasterGroup, 5000); 2387 2388 2390 if (logger.isDebugEnabled()) 2391 logger.debug("Found browse master at " + nbName.getIPAddressString(0)); 2392 2393 2395 NetBIOSNameList nbNameList = NetBIOSSession.FindNamesForAddress(nbName.getIPAddressString(0)); 2396 nbName = nbNameList.findName(NetBIOSName.MasterBrowser, false); 2397 2398 2400 if (nbName != null) 2401 domainName = nbName.getName(); 2402 } 2403 catch (IOException ex) 2404 { 2405 } 2406 } 2407 2408 2410 m_localDomain = domainName; 2411 2412 2414 return domainName; 2415 } 2416 2417 2422 public final DiskSharedDevice getPrimaryFilesystem() 2423 { 2424 2426 SharedDeviceList shares = getShares(); 2427 DiskSharedDevice diskShare = null; 2428 2429 if ( shares != null && shares.numberOfShares() > 0) 2430 { 2431 2433 Enumeration <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 2445 return diskShare; 2446 } 2447 2448 2453 public final boolean hasMacintoshExtensions() 2454 { 2455 return m_macExtensions; 2456 } 2457 2458 2463 public final boolean hasUserAccounts() 2464 { 2465 if (m_userList != null && m_userList.numberOfUsers() > 0) 2466 return true; 2467 return false; 2468 } 2469 2470 2475 public final boolean hasNetBIOSSMB() 2476 { 2477 return m_netBIOSEnable; 2478 } 2479 2480 2485 public final boolean hasTcpipSMB() 2486 { 2487 return m_tcpSMBEnable; 2488 } 2489 2490 2495 public final boolean hasWin32NetBIOS() 2496 { 2497 return m_win32NBEnable; 2498 } 2499 2500 2505 public final boolean isSMBServerEnabled() 2506 { 2507 return m_smbEnable; 2508 } 2509 2510 2515 public final void setSMBServerEnabled(boolean ena) 2516 { 2517 m_smbEnable = ena; 2518 } 2519 2520 2525 public final void setFTPServerEnabled(boolean ena) 2526 { 2527 m_ftpEnable = ena; 2528 } 2529 2530 2537 public final void setAuthenticator(SrvAuthenticator auth, ConfigElement params, boolean allowGuest) 2538 { 2539 2540 2542 auth.setAccessMode(SrvAuthenticator.USER_MODE); 2543 auth.setAllowGuest(allowGuest); 2544 2545 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 2558 m_authenticator = auth; 2559 } 2560 2561 2566 public final void setSMBBindAddress(InetAddress addr) 2567 { 2568 m_smbBindAddress = addr; 2569 } 2570 2571 2576 public final void setNetBIOSBindAddress(InetAddress addr) 2577 { 2578 m_nbBindAddress = addr; 2579 } 2580 2581 2586 public final void setBroadcastMask(String mask) 2587 { 2588 m_broadcast = mask; 2589 2590 2592 NetBIOSSession.setSubnetMask(mask); 2593 } 2594 2595 2600 public final void setComment(String comment) 2601 { 2602 m_comment = comment; 2603 } 2604 2605 2610 public final void setDomainName(String domain) 2611 { 2612 m_domain = domain; 2613 } 2614 2615 2620 public final void setHostAnnouncer(boolean b) 2621 { 2622 m_announce = b; 2623 } 2624 2625 2630 public final void setHostAnnounceInterval(int ival) 2631 { 2632 m_announceInterval = ival; 2633 } 2634 2635 2640 public final void setJCEProvider(String providerClass) 2641 { 2642 2643 2645 try 2646 { 2647 2648 2650 Object jceObj = Class.forName(providerClass).newInstance(); 2651 if (jceObj instanceof java.security.Provider ) 2652 { 2653 2654 2656 Provider jceProvider = (Provider ) jceObj; 2657 2658 2660 m_jceProviderClass = providerClass; 2661 2662 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 ex) 2672 { 2673 throw new AlfrescoRuntimeException("JCE provider class " + providerClass + " not found"); 2674 } 2675 catch (Exception ex) 2676 { 2677 throw new AlfrescoRuntimeException("JCE provider class error", ex); 2678 } 2679 } 2680 2681 2686 public final void setNetBIOSDebug(boolean ena) 2687 { 2688 m_nbDebug = ena; 2689 } 2690 2691 2696 public final void setHostAnnounceDebug(boolean ena) 2697 { 2698 m_announceDebug = ena; 2699 } 2700 2701 2706 public final void setServerName(String name) 2707 { 2708 m_name = name; 2709 } 2710 2711 2716 public final void setSessionDebugFlags(int flags) 2717 { 2718 m_sessDebug = flags; 2719 } 2720 2721 2726 public final void setUserAccounts(UserAccountList users) 2727 { 2728 m_userList = users; 2729 } 2730 2731 2736 public final void setGlobalAccessControls(AccessControlList acls) 2737 { 2738 m_globalACLs = acls; 2739 } 2740 2741 2746 public final void setNetBIOSSMB(boolean ena) 2747 { 2748 m_netBIOSEnable = ena; 2749 } 2750 2751 2756 public final void setTcpipSMB(boolean ena) 2757 { 2758 m_tcpSMBEnable = ena; 2759 } 2760 2761 2766 public final void setWin32NetBIOS(boolean ena) 2767 { 2768 m_win32NBEnable = ena; 2769 } 2770 2771 2776 public final void setWin32NetBIOSName(String name) 2777 { 2778 m_win32NBName = name; 2779 } 2780 2781 2786 public final void setWin32HostAnnouncer(boolean b) 2787 { 2788 m_win32NBAnnounce = b; 2789 } 2790 2791 2796 public final void setWin32LANA(int ival) 2797 { 2798 m_win32NBLANA = ival; 2799 } 2800 2801 2806 public final void setWin32HostAnnounceInterval(int ival) 2807 { 2808 m_win32NBAnnounceInterval = ival; 2809 } 2810 2811 2816 public final void setWin32WinsockNetBIOS(boolean useWinsock) 2817 { 2818 m_win32NBUseWinsock = useWinsock; 2819 } 2820 2821 2827 public final void setTimeZone(String name) throws InvalidConfigurationException 2828 { 2829 2830 2832 TimeZone tz = TimeZone.getTimeZone(name); 2833 if (tz == null) 2834 throw new InvalidConfigurationException("Invalid timezone, " + name); 2835 2836 2841 m_timeZone = name; 2842 m_tzOffset = -(tz.getRawOffset() / 60000); 2843 } 2844 2845 2850 public final void setTimeZoneOffset(int offset) 2851 { 2852 m_tzOffset = offset; 2853 } 2854 2855 2860 public final void setPrimaryWINSServer(InetAddress addr) 2861 { 2862 m_winsPrimary = addr; 2863 } 2864 2865 2870 public final void setSecondaryWINSServer(InetAddress addr) 2871 { 2872 m_winsSecondary = addr; 2873 } 2874 2875 2880 public final boolean isFTPServerEnabled() 2881 { 2882 return m_ftpEnable; 2883 } 2884 2885 2890 public final InetAddress getFTPBindAddress() 2891 { 2892 return m_ftpBindAddress; 2893 } 2894 2895 2900 public final int getFTPPort() 2901 { 2902 return m_ftpPort; 2903 } 2904 2905 2910 public final boolean allowAnonymousFTP() 2911 { 2912 return m_ftpAllowAnonymous; 2913 } 2914 2915 2920 public final String getAnonymousFTPAccount() 2921 { 2922 return m_ftpAnonymousAccount; 2923 } 2924 2925 2930 public final int getFTPDebug() 2931 { 2932 return m_ftpDebug; 2933 } 2934 2935 2940 public final boolean hasFTPRootPath() 2941 { 2942 return m_ftpRootPath != null ? true : false; 2943 } 2944 2945 2950 public final String getFTPRootPath() 2951 { 2952 return m_ftpRootPath; 2953 } 2954 2955 2960 public final void setFTPBindAddress(InetAddress addr) 2961 { 2962 m_ftpBindAddress = addr; 2963 } 2964 2965 2970 public final void setFTPPort(int port) 2971 { 2972 m_ftpPort = port; 2973 } 2974 2975 2980 public final void setFTPRootPath(String path) 2981 { 2982 m_ftpRootPath = path; 2983 } 2984 2985 2990 public final void setAllowAnonymousFTP(boolean ena) 2991 { 2992 m_ftpAllowAnonymous = ena; 2993 } 2994 2995 3000 public final void setAnonymousFTPAccount(String acc) 3001 { 3002 m_ftpAnonymousAccount = acc; 3003 } 3004 3005 3010 public final void setFTPDebug(int dbg) 3011 { 3012 m_ftpDebug = dbg; 3013 } 3014 3015 3019 public final void closeConfiguration() 3020 { 3021 3023 if ( getAuthenticator() != null) 3024 { 3025 getAuthenticator().closeAuthenticator(); 3026 m_authenticator = null; 3027 } 3028 3029 3031 if ( getShares() != null && getShares().numberOfShares() > 0) 3032 { 3033 3035 Enumeration <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 3054 private final SrvAuthenticator loadAuthenticatorClass(String className) 3055 { 3056 SrvAuthenticator srvAuth = null; 3057 3058 try 3059 { 3060 3062 Object authObj = Class.forName(className).newInstance(); 3063 3064 3066 if ( authObj instanceof SrvAuthenticator) 3067 srvAuth = (SrvAuthenticator) authObj; 3068 } 3069 catch (Exception ex) 3070 { 3071 3073 if ( logger.isDebugEnabled()) 3074 logger.debug("Failed to load authenticator class " + className); 3075 } 3076 3077 3079 return srvAuth; 3080 } 3081} | Popular Tags |