alexyoung / ircd.js

A Node ircd (IRC daemon)
GNU General Public License v3.0
528 stars 90 forks source link

Multiple OPERS cause login, then password incorrect. #42

Open matejkramny opened 12 years ago

matejkramny commented 12 years ago

Hi. Just discovered a bug. If you add more than one operators to the config file, and then try the OPER user pass command, the server will respond with :You are now an IRC operator followed by :Password Incorrect.

I fixed the issue. Code change in lib/commands.js

Original:

  // TODO: Local ops
  OPER: function(user, name, password) {
    if (!name || !password) {
      user.send(this.host, irc.errors.wasNoSuchNick, user.nick, ':OPER requires a nick and password');
    } else {
      var userConfig,
          self = this;

      Object.keys(this.config.opers).forEach(function(nick) {
        // TODO: ERR_NOOPERHOST (noOperHost)
        ircd.compareHash(password, self.config.opers[nick].password, function(err, res) {
          if (res) {
            user.send(self.host, irc.reply.youAreOper, user.nick, ':You are now an IRC operator');
            user.oper();
          } else {
            user.send(self.host, irc.errors.passwordWrong, user.nick, ':Password incorrect');
          }
        });
      });
    }
  },

Fixed:

  // TODO: Local ops
  OPER: function(user, name, password) {
    if (!name || !password) {
      user.send(this.host, irc.errors.wasNoSuchNick, user.nick, ':OPER requires a nick and password');
    } else {
      var userConfig,
          self = this;

      ircd.compareHash(password, self.config.opers[name].password, function(err, res) {
        if (res) {
          user.send(self.host, irc.reply.youAreOper, user.nick, ':You are now an IRC operator');
          user.oper();
        } else {
          user.send(self.host, irc.errors.passwordWrong, user.nick, ':Password incorrect');
        }
      });
    }
  },
alexyoung commented 12 years ago

Thanks