Beispiel #1
0
bool NntpConnection::Authenticate()
{
    if (strlen(m_newsServer->GetUser()) == 0 || strlen(m_newsServer->GetPassword()) == 0)
    {
        ReportError("Could not connect to %s: server requested authorization but username/password are not set in settings",
                    m_newsServer->GetHost(), false, 0);
        m_authError = true;
        return false;
    }

    m_authError = !AuthInfoUser(0);
    return !m_authError;
}
Beispiel #2
0
bool NNTPConnection::Authenticate()
{
	if (!m_pNewsServer->GetUser() || strlen(m_pNewsServer->GetUser()) == 0 || 
		!m_pNewsServer->GetPassword() || strlen(m_pNewsServer->GetPassword()) == 0)
	{
		error("%c%s (%s) requested authorization but username/password are not set in settings", 
			toupper(m_pNewsServer->GetName()[0]), m_pNewsServer->GetName() + 1, m_pNewsServer->GetHost());
		m_bAuthError = true;
		return false;
	}

	m_bAuthError = !AuthInfoUser(0);
	return !m_bAuthError;
}
Beispiel #3
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;
}
Beispiel #4
0
bool NntpConnection::AuthInfoUser(int recur)
{
    if (recur > 10)
    {
        return false;
    }

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

    char* answer = ReadLine(m_lineBuf, m_lineBuf.Size(), nullptr);
    if (!answer)
    {
        ReportErrorAnswer("Authorization for %s (%s) failed: Connection closed by remote host", nullptr);
        return false;
    }

    if (!strncmp(answer, "281", 3))
    {
        debug("Authorization for %s successful", GetHost());
        return true;
    }
    else if (!strncmp(answer, "381", 3))
    {
        return AuthInfoPass(++recur);
    }
    else if (!strncmp(answer, "480", 3))
    {
        return AuthInfoUser(++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;
}