瀏覽代碼

darkirc: fix connection password

easye 1 年之前
父節點
當前提交
bfda6fcd9e
共有 1 個文件被更改,包括 9 次插入3 次删除
  1. 9 3
      bin/darkirc/src/irc/command.rs

+ 9 - 3
bin/darkirc/src/irc/command.rs

@@ -599,18 +599,24 @@ impl Client {
 
 
     /// `PASS <password>`
     /// `PASS <password>`
     ///
     ///
-    /// Used to set a ‘connection password’. If set, the password must
+    /// Used to set a connection `<password>`. If set, the password must
     /// be set before USER/NICK commands.
     /// be set before USER/NICK commands.
     pub async fn handle_cmd_pass(&self, args: &str) -> Result<Vec<ReplyType>> {
     pub async fn handle_cmd_pass(&self, args: &str) -> Result<Vec<ReplyType>> {
-        let mut tokens = args.split_ascii_whitespace();
         let nick = self.nickname.read().await.to_string();
         let nick = self.nickname.read().await.to_string();
-        let Some(password) = tokens.next() else {
+
+        // "the final parameter can be prepended with a (':', 0x3A) character"
+        // <https://modern.ircdocs.horse/#parameters>
+        let Some(i) = args.find(' ') else {
             // self.penalty.fetch_add(1, SeqCst);
             // self.penalty.fetch_add(1, SeqCst);
             return Ok(vec![ReplyType::Server((
             return Ok(vec![ReplyType::Server((
                 ERR_NEEDMOREPARAMS,
                 ERR_NEEDMOREPARAMS,
                 format!("{} PASS :{}", nick, INVALID_SYNTAX),
                 format!("{} PASS :{}", nick, INVALID_SYNTAX),
             ))])
             ))])
         };
         };
+        let mut password = &args[i + 1..];
+        if password.starts_with(':') {
+            password = &password[1..];
+        }
 
 
         if self.server.password == bcrypt_hash_password(password) {
         if self.server.password == bcrypt_hash_password(password) {
             self.is_pass_set.store(true, SeqCst);
             self.is_pass_set.store(true, SeqCst);