Exemple #1
0
        private void StartService()
        {
            IPAddress        serverAddress = IPAddress.Any;
            SMBTransportType transportType = SMBTransportType.DirectTCPTransport;

            UserCollection       users          = null;
            List <ShareSettings> sharesSettings = null;
            int port = SettingsHelper.DefaultPort;

            try
            {
                users          = SettingsHelper.ReadUserSettings();
                sharesSettings = SettingsHelper.ReadSharesSettings();
                port           = SettingsHelper.ReadServerPort();
            }
            catch
            {
                m_logWriter.WriteLine("Fail to load Settings.xml");
                return;
            }

            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);
            // 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();
                    }
                }
            }
            catch (Exception ex)
            {
                m_logWriter.WriteLine(ex.Message);
            }
        }
Exemple #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            IPAddress        serverAddress = (IPAddress)comboIPAddress.SelectedValue;
            SMBTransportType transportType;

            if (rbtNetBiosOverTCP.Checked)
            {
                transportType = SMBTransportType.NetBiosOverTCP;
            }
            else
            {
                transportType = SMBTransportType.DirectTCPTransport;
            }

            NTLMAuthenticationProviderBase authenticationMechanism;

            if (chkIntegratedWindowsAuthentication.Checked)
            {
                authenticationMechanism = new IntegratedNTLMAuthenticationProvider();
            }
            else
            {
                UserCollection users;
                try
                {
                    users = SettingsHelper.ReadUserSettings();
                }
                catch
                {
                    MessageBox.Show("Cannot read " + SettingsHelper.SettingsFileName, "Error");
                    return;
                }

                authenticationMechanism = new IndependentNTLMAuthenticationProvider(users.GetUserPassword);
            }

            List <ShareSettings> sharesSettings;

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

            SMBShareCollection shares = new SMBShareCollection();

            foreach (ShareSettings shareSettings in sharesSettings)
            {
                FileSystemShare share = InitializeShare(shareSettings);
                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
            {
                m_server.Start(serverAddress, transportType, chkSMB1.Checked, chkSMB2.Checked);
                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();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
                return;
            }

            btnStart.Enabled              = false;
            btnStop.Enabled               = true;
            comboIPAddress.Enabled        = false;
            rbtDirectTCPTransport.Enabled = false;
            rbtNetBiosOverTCP.Enabled     = false;
            chkSMB1.Enabled               = false;
            chkSMB2.Enabled               = false;
            chkIntegratedWindowsAuthentication.Enabled = false;
        }
Exemple #3
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            IPAddress        serverAddress = (IPAddress)comboIPAddress.SelectedValue;
            SMBTransportType transportType;

            if (rbtNetBiosOverTCP.Checked)
            {
                transportType = SMBTransportType.NetBiosOverTCP;
            }
            else
            {
                transportType = SMBTransportType.DirectTCPTransport;
            }

            NTLMAuthenticationProviderBase authenticationMechanism;

            if (chkIntegratedWindowsAuthentication.Checked)
            {
                authenticationMechanism = new IntegratedNTLMAuthenticationProvider();
            }
            else
            {
                UserCollection users;
                try
                {
                    users = ReadUserSettings();
                }
                catch
                {
                    MessageBox.Show("Cannot read " + SettingsFileName, "Error");
                    return;
                }

                authenticationMechanism = new IndependentNTLMAuthenticationProvider(users.GetUserPassword);
            }

            SMBShareCollection shares;

            try
            {
                shares = ReadShareSettings();
            }
            catch (Exception)
            {
                MessageBox.Show("Cannot read " + SettingsFileName, "Error");
                return;
            }

            GSSProvider securityProvider = new GSSProvider(authenticationMechanism);

            m_server                = new SMBLibrary.Server.SMBServer(shares, securityProvider);
            m_logWriter             = new LogWriter();
            m_server.LogEntryAdded += new EventHandler <LogEntry>(m_logWriter.OnLogEntryAdded);

            try
            {
                m_server.Start(serverAddress, transportType, chkSMB1.Checked, chkSMB2.Checked);
                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();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
                return;
            }

            btnStart.Enabled              = false;
            btnStop.Enabled               = true;
            comboIPAddress.Enabled        = false;
            rbtDirectTCPTransport.Enabled = false;
            rbtNetBiosOverTCP.Enabled     = false;
            chkSMB1.Enabled               = false;
            chkSMB2.Enabled               = false;
            chkIntegratedWindowsAuthentication.Enabled = false;
        }
Exemple #4
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;
            }
        }
Exemple #5
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");
                }
            }
        }