Ejemplo n.º 1
0
/*
 * mr_pong - registration message handler
 *
 * parv[0] = sender prefix
 * parv[1] = pong response echo
 * NOTE: cptr is always unregistered here
 */
int mr_pong(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
  assert(0 != cptr);
  assert(cptr == sptr);
  assert(!IsRegistered(sptr));

  ClrFlag(cptr, FLAG_PINGSENT);
  cli_lasttime(cptr) = CurrentTime;
  /*
   * Check to see if this is a PONG :cookie reply from an
   * unregistered user.  If so, process it. -record
   */
  if (0 != cli_cookie(sptr) && COOKIE_VERIFIED != cli_cookie(sptr)) {
    if (parc > 1 && cli_cookie(sptr) == atol(parv[parc - 1])) {
      cli_cookie(sptr) = COOKIE_VERIFIED;
      if (cli_user(sptr) && *(cli_user(sptr))->host && (cli_name(sptr))[0])
        /*
         * NICK and USER OK
         */
        return register_user(cptr, sptr, cli_name(sptr), cli_user(sptr)->username);
    }
    else  
      send_reply(sptr, SND_EXPLICIT | ERR_BADPING,
		 ":To connect, type /QUOTE PONG %u", cli_cookie(sptr));
  }
  return 0;
}
Ejemplo n.º 2
0
/*
 * mr_pass - registration message handler
 */
int mr_pass(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
  const char* password;
  char* loc = NULL;
  char* locargv[3] = {NULL, NULL, NULL};

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

  /* TODO: For protocol negotiation */
#if 0
  if (ircd_strcmp(password,"PROT")==0) {
      /* Do something here */
  }
#endif

  if (parc == 2 && parv[1][0] == ':') {
    /*
     * All hail code duplication! 
     *
     * Here we emulate parse_client, for the benefit of buggy clients.
     * If there's only one arg that starts with a literal ':', we
     * split it again. Thus, a valid line might be:
     *     PASS ::X username :pass phrase
     * or
     *     PASS ::I-line-pass X username :pass phrase
     * or
     *     PASS ::I-Line-pass /X/username/passphrase
     *     PASS ::/X/username/passphrase
     *     PASS ::/username/passphrase
     *     PASS ::/passphrase   ??pull username from user/ident string??
     *
     * after a while we'll remove the non '/' version
     * when noone is using it anymore, and clean
     * this function up significantly.
     */
     char* s = &parv[1][1];
     
     parc = 1;
     for (;;) {
       while (*s == ' ')
         *s++ = 0;
       if (*s == 0)
         break;
       if (*s == ':') {
         parv[parc++] = s + 1;
         break;
       }
       parv[parc++] = s;
       if (parc >= MAXPARA)
         break;
       while (*s != ' ' && *s)
         s++;
     }
     parv[parc] = NULL;
  }

  password = parc > 1 ? parv[1] : 0;
  if (!EmptyString(password))
    ircd_strncpy(cli_passwd(cptr), password, PASSWDLEN);

  if (feature_bool(FEAT_LOGIN_ON_CONNECT) && !cli_loc(cptr)) {
    /* Check for leading '/' to indicate new-fangled LOC syntax */
    if (parc > 1 && parv[1][0] == '/')
      loc = parv[1]+1;
    else if (parc > 2 && parv[2][0] == '/')
      loc = parv[2]+1;
    if (loc && *loc) { /* Split loc up into locargv[0 through 2] */
      int locargc = 0;
      locargv[locargc++] = loc;
      for ( ; *loc; loc++) {
        if (*loc == '/') {
          *loc = 0;
          locargv[locargc++] = loc + 1;
          if (locargc > 2)
            break;
        }
      }
      if (locargc == 2) {
        /* Missing service nick, fill in default and shift arguments up */
        locargv[2] = locargv[1];
        locargv[1] = locargv[0];
        locargv[0] = (char *)feature_str(FEAT_LOC_DEFAULT_SERVICE);
      }
    }
    else if (parc > 3) { /* Old style for backward compatability: */
      locargv[0] = parv[parc - 3];
      locargv[1] = parv[parc - 2];
      locargv[2] = parv[parc - 1];
    }
    if (locargv[0] && *locargv[0] && locargv[1] && *locargv[1]) {
      cli_loc(cptr) = MyMalloc(sizeof(struct LOCInfo));
      memset(cli_loc(cptr), 0, sizeof(struct LOCInfo));

      cli_loc(cptr)->cookie = 0;

      ircd_strncpy(cli_loc(cptr)->service, locargv[0], NICKLEN);
      ircd_strncpy(cli_loc(cptr)->account, locargv[1], ACCOUNTLEN);

      if (locargv[2] && *locargv[2])
        ircd_strncpy(cli_loc(cptr)->password, locargv[2], ACCPASSWDLEN);
      else
        ircd_strncpy(cli_loc(cptr)->password, "", ACCPASSWDLEN);
    }
    
    /* handle retries */
    if ((cli_name(cptr))[0] && cli_cookie(cptr) == COOKIE_VERIFIED)
      return register_user(cptr, cptr, cli_name(cptr), cli_user(cptr)->username);
  }
  return 0;
}