public static FileSystemShare InitializeShare(ShareSettings shareSettings) { string shareName = shareSettings.ShareName; string sharePath = shareSettings.SharePath; List <string> readAccess = shareSettings.ReadAccess; List <string> writeAccess = shareSettings.WriteAccess; FileSystemShare share = new FileSystemShare(shareName, new NTDirectoryFileSystem(sharePath)); share.AccessRequested += delegate(object sender, AccessRequestArgs args) { bool hasReadAccess = Contains(readAccess, "Users") || Contains(readAccess, args.UserName); bool hasWriteAccess = Contains(writeAccess, "Users") || Contains(writeAccess, args.UserName); if (args.RequestedAccess == FileAccess.Read) { args.Allow = hasReadAccess; } else if (args.RequestedAccess == FileAccess.Write) { args.Allow = hasWriteAccess; } else // FileAccess.ReadWrite { args.Allow = hasReadAccess && hasWriteAccess; } }; return(share); }
public Form1() { InitializeComponent(); if (!Directory.Exists(AppPath + "PS2")) { Directory.CreateDirectory(AppPath + "PS2"); } users.Add("Guest", ""); users.Add("Guest", "Guest"); authenticationMechanism = new IndependentNTLMAuthenticationProvider(users.GetUserPassword); List <ShareSettings> sharesSettings = new List <ShareSettings>(); ShareSettings itemtoshare = new ShareSettings("PS2", AppPath + "PS2", new List <string>() { "Guest" }, new List <string>() { "Guest" }); sharesSettings.Add(itemtoshare); 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); loadSettings(); m_logWriter = new LogWriter(); if (tsbEnableLog.Checked) { m_server.LogEntryAdded += m_server_LogEntryAdded; } }
public Form1() { InitializeComponent(); makeDirectory(); users.Add("Guest", ""); users.Add("Guest", "Guest"); authenticationMechanism = new IndependentNTLMAuthenticationProvider(users.GetUserPassword); List <ShareSettings> sharesSettings = new List <ShareSettings>(); foreach (string Directory in shareDirName) { ShareSettings itemtoshare = new ShareSettings(Directory, AppPath + Directory, new List <string>() { "Guest" }, new List <string>() { "Guest" }); sharesSettings.Add(itemtoshare); } 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); loadSettings(); m_logWriter = new LogWriter(); if (tsbEnableLog.Checked) { m_server.LogEntryAdded += m_server_LogEntryAdded; } string[] args = Environment.GetCommandLineArgs(); foreach (string arg in args) { if (arg.ToUpper() == "/NOLOG") { addLogList(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "Information", "Commandline", "/NOLOG"); tsbEnableLog.Checked = false; } if (arg.ToUpper() == "/START") { addLogList(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "Information", "Commandline", "/START"); tsbServerState.Checked = true; //tsbServerState_CheckedChanged(null, null); } } }