Example #1
0
        public void Start()
        {
            IPAddress        serverAddress = IPAddress.Parse(IpAddress);
            SMBTransportType transportType = SMBTransportType.DirectTCPTransport;

            UserCollection users = new UserCollection();

            users.Add(UserName, UserPassword);

            NTLMAuthenticationProviderBase authenticationMechanism = new IndependentNTLMAuthenticationProvider(users.GetUserPassword);

            SMBShareCollection shares = new SMBShareCollection();
            FileSystemShare    share  = new FileSystemShare("documents", new NTDirectoryFileSystem("/storage/emulated/0/Documents"));

            share.AccessRequested += delegate(object sender, AccessRequestArgs args)
            {
                // allow read and write on share
                args.Allow = true;
            };
            shares.Add(share);

            GSSProvider securityProvider = new GSSProvider(authenticationMechanism);

            server = new SmbServer2(shares, securityProvider);

            try
            {
                server.Start(serverAddress, transportType, true, true);
            }
            catch (Exception ex)
            {
            }
        }
Example #2
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);
            }
        }
Example #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 SmbLibraryStd.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;
        }
Example #4
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");
                }
            }
        }