From d94f67e0c87b07bd747f357983253eee5c4a81b5 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sat, 13 Apr 2019 21:44:17 +0200 Subject: Fixed auth check --- src/args.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/args.rs') diff --git a/src/args.rs b/src/args.rs index 516e0b6..d1250c0 100644 --- a/src/args.rs +++ b/src/args.rs @@ -77,13 +77,24 @@ fn parse_interface(src: &str) -> Result { /// Checks wether the auth string is valid, i.e. it follows the syntax username:password fn parse_auth(src: &str) -> Result<(String, String), String> { - match src.find(':') { - Some(_) => { - let split = src.split(':').collect::>(); - Ok((split[0].to_owned(), split[1].to_owned())) - } - None => Err("Correct format is username:password".to_owned()), + let mut split = src.splitn(2, ':'); + + let username = match split.next() { + Some(username) => username, + None => return Err("Invalid credentials string, expected format is username:password".to_owned()) + }; + + let password = match split.next() { + Some(password) => password, + None => return Err("Invalid credentials string, expected format is username:password".to_owned()) + }; + // Should we allow empty passwords ? + + if username.len() > 255 { + return Err("Username length cannot exceed 255 characters".to_owned()); } + + Ok((username.to_owned(), password.to_owned())) } /// Parses the command line arguments -- cgit v1.2.3 From e900dba1aaf8f169b91f2b3c5abc711109e25e35 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sat, 13 Apr 2019 21:44:45 +0200 Subject: Cargo fmt --- src/args.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/args.rs') diff --git a/src/args.rs b/src/args.rs index d1250c0..f858308 100644 --- a/src/args.rs +++ b/src/args.rs @@ -81,12 +81,20 @@ fn parse_auth(src: &str) -> Result<(String, String), String> { let username = match split.next() { Some(username) => username, - None => return Err("Invalid credentials string, expected format is username:password".to_owned()) + None => { + return Err( + "Invalid credentials string, expected format is username:password".to_owned(), + ) + } }; let password = match split.next() { Some(password) => password, - None => return Err("Invalid credentials string, expected format is username:password".to_owned()) + None => { + return Err( + "Invalid credentials string, expected format is username:password".to_owned(), + ) + } }; // Should we allow empty passwords ? -- cgit v1.2.3 From 0991f5c5007c440898ffe0f2b0c7cfc0f931c497 Mon Sep 17 00:00:00 2001 From: boastful-squirrel Date: Mon, 15 Apr 2019 18:48:32 +0200 Subject: Fix parse_auth to make it RFC-compliant + updated comments --- src/args.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/args.rs') diff --git a/src/args.rs b/src/args.rs index f858308..5a0b5db 100644 --- a/src/args.rs +++ b/src/args.rs @@ -89,6 +89,7 @@ fn parse_auth(src: &str) -> Result<(String, String), String> { }; let password = match split.next() { + // This allows empty passwords, as the spec does not forbid it Some(password) => password, None => { return Err( @@ -96,10 +97,12 @@ fn parse_auth(src: &str) -> Result<(String, String), String> { ) } }; - // Should we allow empty passwords ? - if username.len() > 255 { - return Err("Username length cannot exceed 255 characters".to_owned()); + // To make it Windows-compatible,the password needs to be shorter than 255 characters. + // After 255 characters, Windows will truncate the value. + // As for the username, the spec does not mention a limit in length + if password.len() > 255 { + return Err("Password length cannot exceed 255 characters".to_owned()); } Ok((username.to_owned(), password.to_owned())) -- cgit v1.2.3 From 25cdd8d5f98f92e5b80d2611731b3403c30da7bb Mon Sep 17 00:00:00 2001 From: boastful-squirrel Date: Mon, 15 Apr 2019 18:54:00 +0200 Subject: Fix typo in comment --- src/args.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/args.rs') diff --git a/src/args.rs b/src/args.rs index 5a0b5db..825a4ac 100644 --- a/src/args.rs +++ b/src/args.rs @@ -98,7 +98,7 @@ fn parse_auth(src: &str) -> Result<(String, String), String> { } }; - // To make it Windows-compatible,the password needs to be shorter than 255 characters. + // To make it Windows-compatible, the password needs to be shorter than 255 characters. // After 255 characters, Windows will truncate the value. // As for the username, the spec does not mention a limit in length if password.len() > 255 { -- cgit v1.2.3