Example #1
0
/*
 * mr_pass - registration message handler
 */
int mr_pass(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
  char password[BUFSIZE];
  int arg, len;

  assert(0 != cptr);
  assert(cptr == sptr);
  assert(!IsRegistered(sptr));

  /* Some clients (brokenly) send "PASS x y" rather than "PASS :x y"
   * when the user enters "x y" as the password.  Unsplit arguments to
   * work around this.
   */
  for (arg = 1, len = 0; arg < parc; ++arg)
  {
    ircd_strncpy(password + len, parv[arg], sizeof(password) - len);
    len += strlen(parv[arg]);
    password[len++] = ' ';
  }
  if (len > 0)
    --len;
  password[len] = '\0';

  if (EmptyString(password))
    return need_more_params(cptr, "PASS");

  ircd_strncpy(cli_passwd(cptr), password, PASSWDLEN);
  return cli_auth(cptr) ? auth_set_password(cli_auth(cptr), password) : 0;
}
Example #2
0
/** Handle a PASS message from an unregistered connection.
 *
 * \a parv[1..\a parc-1] is a possibly broken-up password.  Since some
 * clients do not prefix the password with ':', this functions stitches
 * the elements back together before using it.
 *
 * See @ref m_functions for discussion of the arguments.
 * @param[in] cptr Client that sent us the message.
 * @param[in] sptr Original source of message.
 * @param[in] parc Number of arguments.
 * @param[in] parv Argument vector.
 */
int mr_pass(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
  char password[BUFSIZE];
  int arg, len;

  assert(0 != cptr);
  assert(cptr == sptr);
  assert(!IsRegistered(sptr));

  /* Some clients (brokenly) send "PASS x y" rather than "PASS :x y"
   * when the user enters "x y" as the password.  Unsplit arguments to
   * work around this.
   */
  for (arg = 1, len = 0; arg < parc; ++arg)
  {
    ircd_strncpy(password + len, parv[arg], sizeof(password) - len);
    len += strlen(parv[arg]);
    password[len++] = ' ';
  }
  if (len > 0)
    --len;
  password[len] = '\0';

  if (EmptyString(password))
    return need_more_params(cptr, "PASS");

#if defined(DDB)
  if (IsUserPort(cptr))
  {
    /*
     *   PASS :server_pass[:ddb_pass]
     *   PASS :ddb_pass
     */
    char *ddb_pwd;

    ddb_pwd = strchr(password, ':');
    if (ddb_pwd)
      *ddb_pwd++ = '\0';
    else
      ddb_pwd = password;

    ircd_strncpy(cli_ddb_passwd(cptr), ddb_pwd, DDBPWDLEN);
  }
#endif
  ircd_strncpy(cli_passwd(cptr), password, PASSWDLEN);
  return cli_auth(cptr) ? auth_set_password(cli_auth(cptr), password) : 0;
}
Example #3
0
/*
 * mr_pass - registration message handler
 */
int mr_pass(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
  char password[BUFSIZE];
  int arg, len, i = 0, emptypass = 0;
  char* locargv[3] = {NULL, NULL, NULL};
  char *tmp = NULL;

  assert(0 != cptr);
  assert(cptr == sptr);
  assert(!IsRegistered(sptr));

  /* Some clients (brokenly) send "PASS x y" rather than "PASS :x y"
   * when the user enters "x y" as the password.  Unsplit arguments to
   * work around this.
   */
  for (arg = 1, len = 0; arg < parc; ++arg)
  {
    ircd_strncpy(password + len, parv[arg], sizeof(password) - len);
    len += strlen(parv[arg]);
    password[len++] = ' ';
  }
  if (len > 0)
    --len;
  password[len] = '\0';

  if (feature_bool(FEAT_LOGIN_ON_CONNECT) &&
      feature_bool(FEAT_EXTENDED_ACCOUNTS) &&
      !cli_loc(cptr) && (password[0] != '\0')) {
    emptypass = 1;
    tmp = password;
    if (*tmp == '/') {
      *tmp = '\0';
      tmp++;
    } else {
      tmp = strstr(tmp, " /");
      if (tmp != NULL) {
        *tmp = '\0';
        tmp += 2;
      }
    }

    while ((tmp != NULL) && *tmp && (i<3)) {
      locargv[i++] = tmp;
      tmp = strstr(tmp, "/");
      if (tmp != NULL) {
        *tmp = '\0';
        tmp++;
      }
    }

    if ((i>1) && !EmptyString(locargv[i-2]) && !EmptyString(locargv[i-1])) {
      cli_loc(cptr) = (struct LOCInfo *)MyMalloc(sizeof(struct LOCInfo));
      memset(cli_loc(cptr), 0, sizeof(struct LOCInfo));

      cli_loc(cptr)->cookie = 0;

      ircd_strncpy(cli_loc(cptr)->password, locargv[--i], ACCPASSWDLEN);
      ircd_strncpy(cli_loc(cptr)->account, locargv[--i], ACCOUNTLEN);

      if ((i>0) && !EmptyString(locargv[i-1]))
        ircd_strncpy(cli_loc(cptr)->service, locargv[--i], NICKLEN);
      else
        ircd_strncpy(cli_loc(cptr)->service, feature_str(FEAT_LOC_DEFAULT_SERVICE), NICKLEN);
    }
  }

  if ((password[0] == '\0') && !(cli_loc(cptr)) && !emptypass)
    return need_more_params(cptr, "PASS");

  if (cli_loc(cptr) && (password[0] == '\0') && !emptypass) {
    if (cli_auth(cptr))
      auth_end_loc(cli_auth(cptr));
    MyFree(cli_loc(cptr));
  }

  if (cli_passwd(cptr)[0] == '\0')
    ircd_strncpy(cli_passwd(cptr), password, PASSWDLEN);
  return cli_auth(cptr) ? auth_set_password(cli_auth(cptr), password) : 0;
}