public int AddHost (WebServiceLogin login, string host) { using (DB db = new DB ()) { VerifyUserInRole (db, login, Roles.Administrator); if (string.IsNullOrEmpty (host)) throw new ArgumentNullException ("name"); for (int i = 0; i < host.Length; i++) { if (char.IsLetterOrDigit (host [i])) { continue; } else if (host [i] == '-' || host [i] == '_') { continue; } else { throw new ArgumentOutOfRangeException (string.Format ("The character '{0}' isn't valid.", host [i])); } } DBHost dbhost = new DBHost (); dbhost.host = host; dbhost.enabled = true; dbhost.Save (db); return dbhost.id; } }
public void EditHost (WebServiceLogin login, DBHost host) { //WebServiceResponse response = new WebServiceResponse (); using (DB db = new DB ()) { VerifyUserInRole (db, login, Roles.Administrator); var oldHost = FindHost (db, host.id, null); host.Save (db); Audit (login, "edited host `{0}` -> `{1}`", Newtonsoft.Json.JsonConvert.SerializeObject(oldHost), Newtonsoft.Json.JsonConvert.SerializeObject(host) ); } }
public void EditHostWithPassword (WebServiceLogin login, DBHost host, string password) { using (DB db = new DB ()) { using (IDbTransaction transaction = db.BeginTransaction ()) { VerifyUserInRole (db, login, Roles.Administrator); var oldHost = FindHost (db, host.id, null); host.Save (db); // NOTE: it is possible to change the password of an existing account by creating // a host with the same name and specify the password. Given that admin rights // are required to create/modify hosts, it shouldn't pose a security issue. // TODO: if host changed name, delete the old user account. DBPerson person = FindPerson (db, host.host); if (person == null) { person = new DBPerson (); person.login = host.host; person.roles = Roles.BuildBot; } else { if (person.roles != Roles.BuildBot) throw new ArgumentException ("The hosts entry in the person table must have its roles set to 'BuildBot'."); } person.password = password; person.Save (db); transaction.Commit (); Audit (login, "edited host `{0}` -> `{1}`", Newtonsoft.Json.JsonConvert.SerializeObject(oldHost), Newtonsoft.Json.JsonConvert.SerializeObject(host) ); } } }
public void EditHost (WebServiceLogin login, DBHost host) { //WebServiceResponse response = new WebServiceResponse (); using (DB db = new DB ()) { VerifyUserInRole (db, login, Roles.Administrator); host.Save (db); } }