🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
7 messages
7 total messages Started by Niz Sun, 16 Mar 2008 11:43
AUTHINFO problem
#78830
Author: Niz
Date: Sun, 16 Mar 2008 11:43
5 lines
1475 bytes
I'm having problems getting AUTHINFO to work. I have the 480 response 
code from the server and then I send immediately "AUTHINFO 
username\r\n" straight away afterwards. But then my application hangs, 
is this the correct login information?
Re: AUTHINFO problem
#78831
Author: Julien ÉLIE
Date: Sun, 16 Mar 2008 11:46
16 lines
1727 bytes
Hi Niz,

> I'm having problems getting AUTHINFO to work. I have the 480 response code from the server and then I send immediately "AUTHINFO 
> username\r\n" straight away afterwards. But then my application hangs, is this the correct login information?

AUTHINFO user <username>
AUTHINFO pass <password>

Does it work?

-- 
Julien ÉLIE

« -- Laissons-lui notre char et prenons le sien...
  -- Oui, ça nous dépannera... » (Astérix) 
Re: AUTHINFO problem
#78833
Author: Niz
Date: Sun, 16 Mar 2008 13:05
19 lines
1886 bytes
On 2008-03-16 11:46:20 +0000, Julien ÉLIE 
<iulius@nom-de-mon-site.com.invalid> said:

> Hi Niz,
> 
>> I'm having problems getting AUTHINFO to work. I have the 480 response 
>> code from the server and then I send immediately "AUTHINFO 
>> username\r\n" straight away afterwards. But then my application hangs, 
>> is this the correct login information?
> 
> AUTHINFO user <username>
> AUTHINFO pass <password>
> 
> Does it work?

Ah fantastic, I knew I must have been doing something stupid. I'll test 
it out now and see what happens.

Re: AUTHINFO problem
#78832
Author: Xavier Roche
Date: Sun, 16 Mar 2008 13:09
13 lines
1816 bytes
Niz a écrit :
> Ah fantastic, I knew I must have been doing something stupid. I'll test 
> it out now and see what happens.

You should also check the returncode of "AUTHINFO user <username>", 
which shall be "381" to request the password. The "AUTHINFO pass 
<password>" then returns either 281 ("OK"), or an error (typically 502)

Note: you should also send "\r\n" (rfc-style), and not "\n", as line 
termination, even is most servers accept both formats.

See "Common NNTP Extensions",
<http://www.ietf.org/rfc/rfc2980.txt>
Re: AUTHINFO problem
#78835
Author: Niz
Date: Sun, 16 Mar 2008 13:33
42 lines
2905 bytes
On 2008-03-16 13:09:34 +0000, Xavier Roche 
<xroche@free.fr.NOSPAM.invalid> said:

> Niz a écrit :
>> Ah fantastic, I knew I must have been doing something stupid. I'll test 
>> it out now and see what happens.
> 
> You should also check the returncode of "AUTHINFO user <username>", 
> which shall be "381" to request the password. The "AUTHINFO pass 
> <password>" then returns either 281 ("OK"), or an error (typically 502)
> 
> Note: you should also send "\r\n" (rfc-style), and not "\n", as line 
> termination, even is most servers accept both formats.
> 
> See "Common NNTP Extensions",
> <http://www.ietf.org/rfc/rfc2980.txt>

Still having problems unfortunately. Here is my code, I have 
succesfully recieved the 480 code requesting authentification. Once the 
program recieves that it immediately runs the following function, but 
just hangs. I have removed the username and password for obvious 
reasons.

I've read up on all the RFC documents I can find but I'm at a loss. I 
never seem to get any data back from the server suggesting that the 
program never actually sends the data.

int nntpLogin(char *buffer, int bufsize, int sock)
{
	char loginName[] = "AUTHINFO USER <username>\r\n";
	char passwd[] = "AUTHINFO PASS <password>\r\n";
	
	send(sock, loginName, sizeof(loginName), 0);
	recv(sock, buffer, bufsize, 0);
	printf("%s", buffer);
	send(sock, passwd, sizeof(passwd), 0);
	recv(sock, buffer, bufsize, 0);
	printf("%s", buffer);

	return 0;
}
Re: AUTHINFO problem
#78834
Author: Xavier Roche
Date: Sun, 16 Mar 2008 14:07
34 lines
2576 bytes
Niz a écrit :
>     send(sock, loginName, sizeof(loginName), 0);
>     recv(sock, buffer, bufsize, 0);

Humm, this is not a protocol issue, and this is IMHO off-topic in 
news.software.nntp, but anyway you should:

- careflly check and handle the send/recv returncode(s) (man recv and 
man send)
- loop until recv() a complete line, because there is no guarantee that 
the reply will be received at once ("The receive calls normally return 
any  data  available,  up  to  the requested amount, rather than waiting 
for receipt of the full amount requested.")

using something like (typo/syntax not checked):

int readLine((int sock, char *buffer, size_t bufsize) {
   ssize_t ret, size;
   for(size = 0 ; size < buffsize && (ret = recv(sock, buffer + size, 
bufsize - size, 0)) >=0 ; size += ret) {
    /* loop until end of line reached */
     if (size > 2 && buffer[size - 2] == '\r' && buffer[size - 1] == '\n') {
       break;
     }
   }
   return (ret >= 0 && size < buffsize);  /* ok ? */
}

..
if (readLine(sock, buffer, bufsize)) {
..
} else {
.. error handling
}
Re: AUTHINFO problem
#78836
Author: Niz
Date: Sun, 16 Mar 2008 15:08
43 lines
2940 bytes
On 2008-03-16 14:07:07 +0000, Xavier Roche 
<xroche@free.fr.NOSPAM.invalid> said:

> Niz a écrit :
>>     send(sock, loginName, sizeof(loginName), 0);
>>     recv(sock, buffer, bufsize, 0);
> 
> Humm, this is not a protocol issue, and this is IMHO off-topic in 
> news.software.nntp

Ah, sorry about that. I assumed it was just for general NNTP software 
enquires which I would class this as. I've been trying to find some 
decent information on NNTP in general.

> - careflly check and handle the send/recv returncode(s) (man recv and man send)
> - loop until recv() a complete line, because there is no guarantee that 
> the reply will be received at once ("The receive calls normally return 
> any  data  available,  up  to  the requested amount, rather than 
> waiting for receipt of the full amount requested.")
> 
> using something like (typo/syntax not checked):
> 
> int readLine((int sock, char *buffer, size_t bufsize) {
>    ssize_t ret, size;
>    for(size = 0 ; size < buffsize && (ret = recv(sock, buffer + size, 
> bufsize - size, 0)) >=0 ; size += ret) {
>     /* loop until end of line reached */
>      if (size > 2 && buffer[size - 2] == '\r' && buffer[size - 1] == '\n') {
>        break;
>      }
>    }
>    return (ret >= 0 && size < buffsize);  /* ok ? */
> }
> 
> ..
> if (readLine(sock, buffer, bufsize)) {
> ..
> } else {
> .. error handling
> }

Thank you for the advice. I'll look into it a bit more.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads