Exemplo n.º 1
0
bool NntpConnection::AuthInfoPass(int recur)
{
    if (recur > 10)
    {
        return false;
    }

    WriteLine(BString<1024>("AUTHINFO PASS %s\r\n", m_newsServer->GetPassword()));

    char* answer = ReadLine(m_lineBuf, m_lineBuf.Size(), nullptr);
    if (!answer)
    {
        ReportErrorAnswer("Authorization failed for %s (%s): Connection closed by remote host", nullptr);
        return false;
    }
    else if (!strncmp(answer, "2", 1))
    {
        debug("Authorization for %s successful", GetHost());
        return true;
    }
    else if (!strncmp(answer, "381", 3))
    {
        return AuthInfoPass(++recur);
    }

    if (char* p = strrchr(answer, '\r')) *p = '\0'; // remove last CRLF from error message

    if (GetStatus() != csCancelled)
    {
        ReportErrorAnswer("Authorization for %s (%s) failed: %s", answer);
    }
    return false;
}
Exemplo n.º 2
0
bool NNTPConnection::AuthInfoUser(int iRecur)
{
	if (iRecur > 10)
	{
		return false;
	}

	char tmp[1024];
	snprintf(tmp, 1024, "AUTHINFO USER %s\r\n", m_pNewsServer->GetUser());
	tmp[1024-1] = '\0';

	WriteLine(tmp);

	char* answer = ReadLine(m_szLineBuf, CONNECTION_LINEBUFFER_SIZE, NULL);
	if (!answer)
	{
		ReportErrorAnswer("Authorization for server%i (%s) failed: Connection closed by remote host", NULL);
		return false;
	}

	if (!strncmp(answer, "281", 3))
	{
		debug("Authorization for %s successful", GetHost());
		return true;
	}
	else if (!strncmp(answer, "381", 3))
	{
		return AuthInfoPass(++iRecur);
	}
	else if (!strncmp(answer, "480", 3))
	{
		return AuthInfoUser(++iRecur);
	}

	if (char* p = strrchr(answer, '\r')) *p = '\0'; // remove last CRLF from error message

	if (GetStatus() != csCancelled)
	{
		ReportErrorAnswer("Authorization for server%i (%s) failed (Answer: %s)", answer);
	}
	return false;
}