Esempio n. 1
0
        static void RunOptions(Options opts)
        {
            logger.Info("Options: {0}", opts);
            List <ShareSettings> sharesSettings;

            try {
                sharesSettings = SettingsHelper.ReadSharesSettings();
            }
            catch (Exception) {
                logger.Error("Cannot read " + SettingsHelper.SettingsFileName);
                return;
            }

            List <AggregatedShareSettings> aggregatedSharesSettings;

            try {
                aggregatedSharesSettings = SettingsHelper.ReadAggregatedSharesSettings();
            }
            catch (Exception) {
                logger.Error("Cannot read " + SettingsHelper.SettingsFileName);
                return;
            }

            SMBShareCollection shares = new SMBShareCollection();

            foreach (ShareSettings shareSettings in sharesSettings)
            {
                FileSystemShare share = InitializeShare(shareSettings);
                shares.Add(share);
            }
            foreach (AggregatedShareSettings settings in aggregatedSharesSettings)
            {
                FileSystemShare share = InitializeAggFSShare(settings);
                shares.Add(share);
            }

            NTLMAuthenticationProviderBase authenticationMechanism = new IntegratedNTLMAuthenticationProvider();
            GSSProvider securityProvider = new GSSProvider(authenticationMechanism);

            theServer = new SMBLibrary.Server.SMBServer(shares, securityProvider);
            if (opts.Verbose)
            {
                theServer.LogEntryAdded += TheServer_LogEntryAdded;
            }
            bool enableSMB1 = (opts.SMBProtocol & SMBProtocol.SMB1) == SMBProtocol.SMB1;
            bool enableSMB2 = (opts.SMBProtocol & SMBProtocol.SMB2) == SMBProtocol.SMB2;
            bool enableSMB3 = (opts.SMBProtocol & SMBProtocol.SMB3) == SMBProtocol.SMB3;

            IPAddress listenAddr;

            if (!IPAddress.TryParse(opts.ListenIPAddress, out listenAddr))
            {
                logger.Error(opts.ListenIPAddress + " is not a valid IP Address.");
                Environment.Exit(-1);
                return;
            }

            try {
                theServer.Start(listenAddr, opts.TransportType, enableSMB1, enableSMB2, enableSMB3);
                if (opts.TransportType == SMBTransportType.NetBiosOverTCP)
                {
                    if (listenAddr.AddressFamily == AddressFamily.InterNetwork && !IPAddress.Equals(listenAddr, IPAddress.Any))
                    {
                        IPAddress subnetMask = NetworkInterfaceHelper.GetSubnetMask(listenAddr);
                        theNameServer = new NameServer(listenAddr, subnetMask);
                        theNameServer.Start();
                    }
                }

                Console.Read();
            }
            catch (Exception ex) {
                logger.Error(ex.Message);
                Environment.Exit(-1);
                return;
            }
        }
Esempio n. 2
0
        private void StartButton_Click(object sender, RoutedEventArgs e)
        {
            string accountName = this.username_textbox.Text;
            string password    = this.password_box.Password;

            if (CommonUtils.IsEmptyString(accountName))
            {
                MessageBox.Show("User Name or Password cannot be empty!", "Error");
                return;
            }

            List <ShareSettings> sharesSettings = this.GetShareSettings();

            if (sharesSettings == null || sharesSettings.Count == 0)
            {
                MessageBox.Show("Please add directories for sharing!", "Error");
                return;
            }

            int port = SettingsHelper.DefaultPort;

            try
            {
                port = int.Parse(this.port_textbox.Text);
                SettingsHelper.WriteServerPort(port);
            }
            catch
            {
                MessageBox.Show("Invalid port number!", "Error");
                return;
            }

            UserCollection users = new UserCollection();

            users.Add(new User(accountName, password));
            // Save account if necessary
            if (this.NeedUpdateUserCollection())
            {
                SettingsHelper.WriteUserSettings(users);
            }

            bool runAsService = this.service_checkbox.IsChecked ?? false;

            if (runAsService)
            {
                if (!this.IsInAdminRole())
                {
                    MessageBox.Show("To start the service, please run application as administrator.", "Info");
                    return;
                }

                try
                {
                    ServiceController serviceController = new ServiceController("RedfishService");
                    serviceController.Start();
                    this.start_button.IsEnabled = false;
                    this.stop_button.IsEnabled  = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                }
            }
            else
            {
                KeyValuePair <string, IPAddress> selectedValue = (KeyValuePair <string, IPAddress>) this.address_combobox.SelectedValue;
                IPAddress        serverAddress = selectedValue.Value;
                SMBTransportType transportType = SMBTransportType.DirectTCPTransport;

                NTLMAuthenticationProviderBase authenticationMechanism = new IndependentNTLMAuthenticationProvider(users.GetUserPassword);

                SMBShareCollection shares = new SMBShareCollection();
                foreach (ShareSettings shareSettings in sharesSettings)
                {
                    FileSystemShare share = shareSettings.InitializeShare();
                    shares.Add(share);
                }

                GSSProvider securityProvider = new GSSProvider(authenticationMechanism);
                m_server    = new SMBLibrary.Server.SMBServer(shares, securityProvider);
                m_logWriter = new LogWriter();
                // The provided logging mechanism will synchronously write to the disk during server activity.
                // To maximize server performance, you can disable logging by commenting out the following line.
                m_server.LogEntryAdded += new EventHandler <LogEntry>(m_logWriter.OnLogEntryAdded);

                try
                {
                    SMBServer.DirectTCPPort = port;
                    m_server.Start(serverAddress, transportType);
                    if (transportType == SMBTransportType.NetBiosOverTCP)
                    {
                        if (serverAddress.AddressFamily == AddressFamily.InterNetwork && !IPAddress.Equals(serverAddress, IPAddress.Any))
                        {
                            IPAddress subnetMask = NetworkInterfaceHelper.GetSubnetMask(serverAddress);
                            m_nameServer = new NameServer(serverAddress, subnetMask);
                            m_nameServer.Start();
                        }
                    }

                    this.start_button.IsEnabled = false;
                    this.stop_button.IsEnabled  = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                }
            }
        }