From 35952a203077fe08ce80286d2de7f732f067aabe Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Sat, 16 Sep 2023 14:01:47 +0100 Subject: [PATCH 1/2] fix: no need to send email out, the wolves ID is enough relates to #21 --- src/methods/discord.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/methods/discord.rs b/src/methods/discord.rs index ab01daf..dee2f00 100644 --- a/src/methods/discord.rs +++ b/src/methods/discord.rs @@ -35,7 +35,6 @@ pub mod account { #[derive(Debug, Deserialize, Serialize)] pub struct DiscordResult { discord: String, - email: String, wolves_id: String, } @@ -59,7 +58,6 @@ pub mod account { if !accounts.is_empty() { let tmp = DiscordResult { discord, - email: item.mail, wolves_id: accounts[0].id_wolves.to_owned(), }; -- 2.46.1 From dadaf73c7839ea5257c55d9a5f94a6fdd465ac10 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Sat, 16 Sep 2023 14:56:16 +0100 Subject: [PATCH 2/2] feat: added machanism for not allowing users to sign up with forbidden/restricted usernames. Names will be added to the nixos config. Closes #23 --- flake.nix | 14 ++++++++++---- src/lib.rs | 9 +++++++++ src/methods/account_new.rs | 7 +++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 102f3ed..4d913f4 100644 --- a/flake.nix +++ b/flake.nix @@ -55,10 +55,11 @@ SSH_ROOT = "skynet_old"; # special categories of users - USERS_ADMIN = lib.strings.concatStringsSep "," cfg.users.admin; - USERS_COMMITTEE = lib.strings.concatStringsSep "," cfg.users.committee; - USERS_LIFETIME = lib.strings.concatStringsSep "," cfg.users.lifetime; - USERS_BANNED = lib.strings.concatStringsSep "," cfg.users.banned; + USERS_ADMIN = lib.strings.concatStringsSep "," cfg.users.admin; + USERS_COMMITTEE = lib.strings.concatStringsSep "," cfg.users.committee; + USERS_LIFETIME = lib.strings.concatStringsSep "," cfg.users.lifetime; + USERS_BANNED = lib.strings.concatStringsSep "," cfg.users.banned; + USERS_RESTRICTED = lib.strings.concatStringsSep "," cfg.users.restricted; }; service_name = script: lib.strings.sanitizeDerivationName("${cfg.user}@${script}"); @@ -146,6 +147,11 @@ default = []; description = "array of banned users"; }; + restricted = mkOption rec { + type = types.listOf types.str; + default = []; + description = "array of restricted user accounts"; + }; }; host_port = mkOption rec { diff --git a/src/lib.rs b/src/lib.rs index 3647826..f649a20 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -190,6 +190,7 @@ pub struct Config { pub mail_pass: String, pub ssh_root: String, pub auth_discord: String, + pub users_restricted: Vec, } pub fn get_config() -> Config { @@ -209,6 +210,7 @@ pub fn get_config() -> Config { mail_pass: "".to_string(), ssh_root: "skynet_old".to_string(), auth_discord: "".to_string(), + users_restricted: vec![], }; if let Ok(x) = env::var("LDAP_HOST") { @@ -248,6 +250,13 @@ pub fn get_config() -> Config { config.auth_discord = x.trim().to_string(); } + if let Ok(x) = env::var("USERS_RESTRICTED") { + // usernames that are restricted + for user in x.split(',').collect::>() { + config.users_restricted.push(user.to_string()); + } + } + config } diff --git a/src/methods/account_new.rs b/src/methods/account_new.rs index e98ce6f..94aaddd 100644 --- a/src/methods/account_new.rs +++ b/src/methods/account_new.rs @@ -269,6 +269,13 @@ pub mod account { return Ok(json!({"result": "error", "error": error}).into()); } + // check against forbidden names first + for name in &config.users_restricted { + if user.contains(name) { + return Ok(json!({"result": "error", "error": "username not available"}).into()); + } + } + // easier to give each request its own connection let mut ldap = LdapConn::new(&config.ldap_host)?; -- 2.46.1