| 1 | #include <stdio.h>
|
| 2 | #include <string.h>
|
| 3 | #include <syslog.h>
|
| 4 |
|
| 5 | #include "aconfig.h"
|
| 6 | #include "nntpd.h"
|
| 7 | #include "aprotos.h"
|
| 8 |
|
| 9 | #define _MAX_LINEBUF 256
|
| 10 |
|
| 11 | int connect_to_server (char *server, int port, int timeout)
|
| 12 | {
|
| 13 | int sock;
|
| 14 |
|
| 15 | if ((sock = connect_socket (server, port)) == -1)
|
| 16 | return -1;
|
| 17 |
|
| 18 | char response[cfg.BufSize];
|
| 19 | if (handshake_nntp (sock, response, timeout) != NULL) {
|
| 20 | close (sock);
|
| 21 | return -1;
|
| 22 | }
|
| 23 |
|
| 24 | return sock;
|
| 25 | }
|
| 26 |
|
| 27 | PROTO void auth_remote(AUTHRESULT *authres, CONFIG *cf, char *args)
|
| 28 | {
|
| 29 | char tmp[_MAX_LINEBUF];
|
| 30 | char server[128];
|
| 31 | int port;
|
| 32 | int sock;
|
| 33 |
|
| 34 | if ( sscanf(args, "%128[^:]:%d", server, &port) != 2 )
|
| 35 | {
|
| 36 | syslog(LOG_ERR, "auth_remote: Wrong argument syntax \"%s\"", args);
|
| 37 | authres->message = strdup(MSG_AUTH_ERR);
|
| 38 | return;
|
| 39 | }
|
| 40 |
|
| 41 | if ( (sock=connect_to_server(server, port, cf->ServerReadTimeout)) == -1 )
|
| 42 | {
|
| 43 | syslog(LOG_ERR, "auth_remote: Error connecting to authentication server");
|
| 44 | authres->message = strdup(MSG_AUTH_ERR);
|
| 45 | return;
|
| 46 | }
|
| 47 |
|
| 48 | sprintf(tmp, "AUTHINFO USER %s\r\n", authres->username_s);
|
| 49 | write_socket(sock, tmp, strlen(tmp), cf->ServerReadTimeout);
|
| 50 | if ( read_socket(sock, tmp, _MAX_LINEBUF, cf->ServerReadTimeout) <= 0 )
|
| 51 | {
|
| 52 | authres->message = strdup(MSG_AUTH_ERR);
|
| 53 | return;
|
| 54 | }
|
| 55 |
|
| 56 | sprintf(tmp, "AUTHINFO PASS %s\r\n", authres->password);
|
| 57 | write_socket(sock, tmp, strlen(tmp), cf->ServerReadTimeout);
|
| 58 | if ( read_socket(sock, tmp, _MAX_LINEBUF, cf->ServerReadTimeout) <= 0 )
|
| 59 | {
|
| 60 | authres->message = strdup(MSG_AUTH_ERR);
|
| 61 | return;
|
| 62 | }
|
| 63 |
|
| 64 | if ( atoi(tmp) == 281 )
|
| 65 | {
|
| 66 | authres->authenticated = true;
|
| 67 | authres->message = strdup(MSG_AUTH_OK);
|
| 68 | return;
|
| 69 | }
|
| 70 |
|
| 71 | authres->message = strdup(MSG_AUTH_REJ);
|
| 72 | return;
|
| 73 | }
|
| 74 |
|