public bool CanRead(Session sess, File item) { if (sess.CurrentUser == this.RootUser) { return true; } return item.CanView(sess.CurrentUser); }
public void FSCreateDirectory(string name, Session sess) { Console.WriteLine(this.Parent.Name + "\\\\" + this.Name + " : Creating Directory : " + name); string[] items = name.Split('\\'); File currentDir = this.RootFile; for (int i = 0; i < items.Length; i++) { currentDir = currentDir.GetDirectory(items[i], true, sess.CurrentUser); } }
public static void GenerateNetworks() { LocalHost = new ComputerSystem(LocalNetwork); LocalNetwork.AllSystems.Add(LocalHost); LocalSession = new Session(LocalHost.GetUser("Admin")); for (int i = 0; i < 5; i++) { Networks.Add(new Network()); } }
public static void GenerateBasicFilesystem(ComputerSystem sys, Session rootUser) { sys.FSCreateDirectory("Users", rootUser); for (int i = 0; i < Singiltons.rand.Next(100) + 40; i++) { sys.FSCreateFile("", GetRandomDLLName(), Singiltons.rand.Next(2000000), rootUser); } for (int i = 0; i < Singiltons.rand.Next(5) + 5; i++) { string exeName = GetRandom(EXENames); sys.FSCreateDirectory(exeName, rootUser); sys.FSCreateFile(exeName + "\\", exeName + ".exe", Singiltons.rand.Next(6000000), rootUser); for (int x = 0; x < Singiltons.rand.Next(4); x++) { sys.FSCreateFile(exeName + "\\", GetRandomDATName(), Singiltons.rand.Next(10000000), rootUser); } } sys.FSSweepPremissions("", true, sys.GetGroup("Admins"), new FilePremission(true, false), rootUser); sys.FSCreateDirectory("SystemStore", rootUser); }
public File FSGetDirectory(string name, Session sess) { string[] items = name.Split('\\'); File currentDir = this.RootFile; for (int i = 0; i < items.Length - 1; i++) { File target = currentDir.GetDirectory(items[i], false, sess.CurrentUser); if (target != null) { currentDir = target; } else { throw new Exception("Directory not Found"); } } return currentDir; }
public void FSCreateFile(string path, string name, int size, Session sess) { File currentDirectory = this.FSGetDirectory(path, sess); File newFile = new File(name, size, sess.CurrentUser); currentDirectory.Children.Add(newFile); }
public void FSSweepPremissions(File path, bool subdirectorys, UserGroup toJoin, FilePremission newPremission, Session sess) { foreach (File item in path.Children) { if (item.Directory) { if (!subdirectorys) { continue; } this.FSSetPremission(item, toJoin, newPremission, sess); this.FSSweepPremissions(item, subdirectorys, toJoin, newPremission, sess); } else { this.FSSetPremission(item, toJoin, newPremission, sess); } } }
public void FSSweepPremissions(string path, bool subdirectorys, UserGroup toJoin, FilePremission newPremission, Session sess) { File rootBase; if (path == "") { rootBase = this.RootFile; } else { rootBase = this.FSGetDirectory(path, sess); } this.FSSetPremission(rootBase, toJoin, newPremission, sess); this.FSSweepPremissions(rootBase, subdirectorys, toJoin, newPremission, sess); }
public void FSSetPremission(File item, UserGroup toJoin, FilePremission newPremission, Session sess) { if (item.CanView(sess.CurrentUser)) { if (item.GroupPremitions.ContainsKey(toJoin)) { item.GroupPremitions[toJoin] = newPremission; } else { item.GroupPremitions.Add(toJoin, newPremission); } } }