vw_small

Hardened fork of Vaultwarden (https://github.com/dani-garcia/vaultwarden) with fewer features.
git clone https://git.philomathiclife.com/repos/vw_small
Log | Files | Refs | README

commit d29b6bee2850795ac9565ee1ab70f4c53be68536
parent e2e37129215a437619610ac530a01eb5a72e4d53
Author: Daniel GarcĂ­a <dani-garcia@users.noreply.github.com>
Date:   Sat,  2 Nov 2019 17:39:01 +0100

Remove unnecessary clones and other clippy fixes

Diffstat:
Msrc/api/core/folders.rs | 2+-
Msrc/api/core/organizations.rs | 8++++----
Msrc/api/core/two_factor/duo.rs | 2+-
Msrc/api/core/two_factor/u2f.rs | 2+-
Msrc/api/icons.rs | 12+++---------
Msrc/auth.rs | 12++++++------
Msrc/config.rs | 18++++++------------
Msrc/mail.rs | 2+-
8 files changed, 23 insertions(+), 35 deletions(-)

diff --git a/src/api/core/folders.rs b/src/api/core/folders.rs @@ -59,7 +59,7 @@ pub struct FolderData { fn post_folders(data: JsonUpcase<FolderData>, headers: Headers, conn: DbConn, nt: Notify) -> JsonResult { let data: FolderData = data.into_inner().data; - let mut folder = Folder::new(headers.user.uuid.clone(), data.Name); + let mut folder = Folder::new(headers.user.uuid, data.Name); folder.save(&conn)?; nt.send_folder_update(UpdateType::FolderCreate, &folder); diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs @@ -77,7 +77,7 @@ fn create_organization(headers: Headers, data: JsonUpcase<OrgData>, conn: DbConn let data: OrgData = data.into_inner().data; let org = Organization::new(data.Name, data.BillingEmail); - let mut user_org = UserOrganization::new(headers.user.uuid.clone(), org.uuid.clone()); + let mut user_org = UserOrganization::new(headers.user.uuid, org.uuid.clone()); let collection = Collection::new(org.uuid.clone(), data.CollectionName); user_org.akey = data.Key; @@ -221,7 +221,7 @@ fn post_organization_collections( None => err!("Can't find organization details"), }; - let collection = Collection::new(org.uuid.clone(), data.Name); + let collection = Collection::new(org.uuid, data.Name); collection.save(&conn)?; Ok(Json(collection.to_json())) @@ -262,7 +262,7 @@ fn post_organization_collection_update( err!("Collection is not owned by organization"); } - collection.name = data.Name.clone(); + collection.name = data.Name; collection.save(&conn)?; Ok(Json(collection.to_json())) @@ -581,7 +581,7 @@ fn reinvite_user(org_id: String, user_org: String, headers: AdminHeaders, conn: Some(headers.user.email), )?; } else { - let invitation = Invitation::new(user.email.clone()); + let invitation = Invitation::new(user.email); invitation.save(&conn)?; } diff --git a/src/api/core/two_factor/duo.rs b/src/api/core/two_factor/duo.rs @@ -167,7 +167,7 @@ fn activate_duo(data: JsonUpcase<EnableDuoData>, headers: Headers, conn: DbConn) }; let type_ = TwoFactorType::Duo; - let twofactor = TwoFactor::new(headers.user.uuid.clone(), type_, data_str); + let twofactor = TwoFactor::new(headers.user.uuid, type_, data_str); twofactor.save(&conn)?; Ok(Json(json!({ diff --git a/src/api/core/two_factor/u2f.rs b/src/api/core/two_factor/u2f.rs @@ -164,7 +164,7 @@ fn activate_u2f(data: JsonUpcase<EnableU2FData>, headers: Headers, conn: DbConn) err!("Error registering U2F token") } - let registration = U2F.register_response(challenge.clone(), response.into())?; + let registration = U2F.register_response(challenge, response.into())?; let full_registration = U2FRegistration { id: data.Id.into_i32()?, name: data.Name, diff --git a/src/api/icons.rs b/src/api/icons.rs @@ -65,9 +65,8 @@ fn icon(domain: String) -> Content<Vec<u8>> { } fn check_icon_domain_is_blacklisted(domain: &str) -> bool { - let mut is_blacklisted = false; - if CONFIG.icon_blacklist_non_global_ips() { - is_blacklisted = (domain, 0) + let mut is_blacklisted = CONFIG.icon_blacklist_non_global_ips() + && (domain, 0) .to_socket_addrs() .map(|x| { for ip_port in x { @@ -79,7 +78,6 @@ fn check_icon_domain_is_blacklisted(domain: &str) -> bool { false }) .unwrap_or(false); - } // Skip the regex check if the previous one is true already if !is_blacklisted { @@ -279,11 +277,7 @@ fn get_page_with_cookies(url: &str, cookie_str: &str) -> Result<Response, Error> } if cookie_str.is_empty() { - CLIENT - .get(url) - .send()? - .error_for_status() - .map_err(Into::into) + CLIENT.get(url).send()?.error_for_status().map_err(Into::into) } else { CLIENT .get(url) diff --git a/src/auth.rs b/src/auth.rs @@ -118,7 +118,7 @@ pub fn generate_invite_claims( uuid: String, email: String, org_id: Option<String>, - org_user_id: Option<String>, + user_org_id: Option<String>, invited_by_email: Option<String>, ) -> InviteJWTClaims { let time_now = Utc::now().naive_utc(); @@ -126,11 +126,11 @@ pub fn generate_invite_claims( nbf: time_now.timestamp(), exp: (time_now + Duration::days(5)).timestamp(), iss: JWT_INVITE_ISSUER.to_string(), - sub: uuid.clone(), - email: email.clone(), - org_id: org_id.clone(), - user_org_id: org_user_id.clone(), - invited_by_email: invited_by_email.clone(), + sub: uuid, + email, + org_id, + user_org_id, + invited_by_email, } } diff --git a/src/config.rs b/src/config.rs @@ -368,22 +368,16 @@ make_config! { fn validate_config(cfg: &ConfigItems) -> Result<(), Error> { let db_url = cfg.database_url.to_lowercase(); - if cfg!(feature = "sqlite") { - if db_url.starts_with("mysql:") || db_url.starts_with("postgresql:") { - err!("`DATABASE_URL` is meant for MySQL or Postgres, while this server is meant for SQLite") - } + if cfg!(feature = "sqlite") && (db_url.starts_with("mysql:") || db_url.starts_with("postgresql:")) { + err!("`DATABASE_URL` is meant for MySQL or Postgres, while this server is meant for SQLite") } - if cfg!(feature = "mysql") { - if !db_url.starts_with("mysql:") { - err!("`DATABASE_URL` should start with mysql: when using the MySQL server") - } + if cfg!(feature = "mysql") && !db_url.starts_with("mysql:") { + err!("`DATABASE_URL` should start with mysql: when using the MySQL server") } - if cfg!(feature = "postgresql") { - if !db_url.starts_with("postgresql:") { - err!("`DATABASE_URL` should start with postgresql: when using the PostgreSQL server") - } + if cfg!(feature = "postgresql") && !db_url.starts_with("postgresql:") { + err!("`DATABASE_URL` should start with postgresql: when using the PostgreSQL server") } if let Some(ref token) = cfg.admin_token { diff --git a/src/mail.rs b/src/mail.rs @@ -105,7 +105,7 @@ pub fn send_invite( String::from(address), org_id.clone(), org_user_id.clone(), - invited_by_email.clone(), + invited_by_email, ); let invite_token = encode_jwt(&claims);