public static string Dump() { DumpableDict du = new DumpableDict(Roles); XmlSerializer xmlSerializer = new XmlSerializer(du.GetType()); StringWriter textWriter = new StringWriter(); xmlSerializer.Serialize(textWriter, du); return textWriter.ToString(); }
public static string Dump() { DumpableDict du = new DumpableDict(Roles); XmlSerializer xmlSerializer = new XmlSerializer(du.GetType()); using (StringWriter textWriter = new StringWriter()) { xmlSerializer.Serialize(textWriter, du); return(textWriter.ToString()); } }
/// <summary> /// Load all roles /// </summary> public static void Init() { Core.RecoverFile(Configuration.Paths.Security); if (File.Exists(Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + "security.xml")) { DumpableDict dict = new DumpableDict(); XmlSerializer xmlSerializer = new XmlSerializer(dict.GetType()); StreamReader reader = new StreamReader(Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + "security.xml"); dict = (DumpableDict)xmlSerializer.Deserialize(reader); // first we need to create all roles in the file, that is important foreach (DumpableDict.RoleInfo ri in dict.Roles) { Roles.Add(ri.Name, new Role(ri.Level)); } foreach (DumpableDict.RoleInfo ri in dict.Roles) { // now give this role all permissions and roles it had foreach (string permission in ri.Permissions) { Roles[ri.Name].Grant(permission); } foreach (string role in ri.Roles) { if (!Roles.ContainsKey(role)) { Syslog.WarningLog("There is no role " + role + " that could be granted to " + ri.Name + " skipping it"); } Roles[ri.Name].Grant(Roles[role]); } } return; } // let's assume there is no role definition file, so we create some initial, built-in roles Roles.Add("null", new Role(0)); Roles.Add("trusted", new Role(1)); Roles.Add("operator", new Role(6)); Roles.Add("admin", new Role(20)); Roles.Add("root", new Role(65535)); Roles["trusted"].Grant("trust"); // trusted users can add users to trust list Roles["trusted"].Grant("trustadd"); Roles["trusted"].Grant("trustdel"); Roles["operator"].Grant(Roles["trusted"]); Roles["operator"].Grant("join"); Roles["admin"].Grant("admin"); Roles["admin"].Grant("drop"); Roles["admin"].Grant("part"); Roles["admin"].Grant(Roles["operator"]); // admins have all privileges as trusted users Roles["admin"].Grant(Roles["trusted"]); Roles["root"].Grant("root"); lock (ExtensionHandler.Extensions) { foreach (Module module in ExtensionHandler.Extensions) { try { module.RegisterPermissions(); } catch (Exception fail) { Core.HandleException(fail, module.Name); } } } }
/// <summary> /// Load all roles /// </summary> public static void Init() { Core.RecoverFile(Configuration.Paths.Security); if (File.Exists(Configuration.Paths.Security)) { DumpableDict dict = new DumpableDict(); XmlSerializer xmlSerializer = new XmlSerializer(dict.GetType()); using (StreamReader reader = new StreamReader(Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + "security.xml")) { dict = (DumpableDict)xmlSerializer.Deserialize(reader); } // first we need to create all roles in the file, that is important foreach (DumpableDict.RoleInfo ri in dict.Roles) { Roles.Add(ri.Name, new Role(ri.Level)); } foreach (DumpableDict.RoleInfo ri in dict.Roles) { // now give this role all permissions and roles it had foreach (string permission in ri.Permissions) { Roles[ri.Name].Grant(permission); } foreach (string role in ri.Roles) { if (!Roles.ContainsKey(role)) { Syslog.WarningLog("There is no role " + role + " that could be granted to " + ri.Name + " skipping it"); } Roles[ri.Name].Grant(Roles[role]); } } return; } // let's assume there is no role definition file, so we create some initial, built-in roles Roles.Add("null", new Role(0)); Roles.Add("trusted", new Role(100)); Roles.Add("operator", new Role(1000)); Roles.Add("admin", new Role(20000)); Roles.Add("root", new Role(65535)); Roles["trusted"].Grant("trust"); // trusted users can add users to trust list Roles["trusted"].Grant("trustadd"); Roles["trusted"].Grant("trustdel"); Roles["operator"].Grant(Roles["trusted"]); Roles["operator"].Grant("join"); Roles["admin"].Grant("admin"); Roles["admin"].Grant("drop"); Roles["admin"].Grant("suppress"); Roles["admin"].Grant("unsuppress"); Roles["admin"].Grant("part"); Roles["admin"].Grant(Roles["operator"]); // admins have all privileges as trusted users Roles["admin"].Grant(Roles["trusted"]); Roles["root"].Grant("root"); foreach (Module module in ExtensionHandler.ExtensionList) { try { module.RegisterPermissions(); } catch (Exception fail) { Core.HandleException(fail, module.Name); } } }