Added NNTP authentication support

This commit is contained in:
Sergey Vlasov 2001-04-26 16:41:29 +00:00
parent d44e47a0ea
commit 8c246727a1
5 changed files with 114 additions and 7 deletions

View file

@ -1,3 +1,14 @@
2001-04-26 [sergey]
* src/news.c: news_query_password(), news_authenticate(): new
functions.
news_get_uncached_articles(): added NNTP authentication
handling.
* src/nntp.[ch]: nntp_authinfo_user(), nntp_authinfo_pass():
new functions.
* src/prefs_account.c: prefs_account_protocol_activated():
enable userid and password fields for NNTP.
2001-04-26
* configure.in: check for availability of strftime()

View file

@ -42,6 +42,9 @@
#include "codeconv.h"
#include "utils.h"
#include "prefs_common.h"
#include "prefs_account.h"
#include "inputdialog.h"
#include "alertpanel.h"
static gint news_get_article_cmd (NNTPSession *session,
const gchar *cmd,
@ -267,6 +270,58 @@ static gint news_get_header(NNTPSession *session, gint num, gchar *filename)
return news_get_article_cmd(session, "HEAD", num, filename);
}
static gchar *news_query_password(NNTPSession *session,
const gchar *user)
{
gchar *message;
gchar *pass;
message = g_strdup_printf
(_("Input password for %s on %s:"),
user,
SESSION(session)->server);
pass = input_dialog_with_invisible(_("Input password"),
message, NULL);
g_free(message);
/* manage_window_focus_in(inc_dialog->mainwin->window, */
/* NULL, NULL); */
return pass;
}
static gint news_authenticate(NNTPSession *session,
FolderItem *item)
{
gint ok;
const gchar *user;
gchar *pass;
gboolean need_free_pass = FALSE;
debug_print(_("news server requested authentication\n"));
if (!item || !item->folder || !item->folder->account)
return NN_ERROR;
user = item->folder->account->userid;
if (!user)
return NN_ERROR;
ok = nntp_authinfo_user(SESSION(session)->sock, user);
if (ok == NN_AUTHCONT) {
pass = item->folder->account->passwd;
if (!pass || !pass[0]) {
pass = news_query_password(session, user);
need_free_pass = TRUE;
}
ok = nntp_authinfo_pass(SESSION(session)->sock, pass);
if (need_free_pass)
g_free(pass);
}
if (ok != NN_SUCCESS) {
log_warning(_("NNTP authentication failed\n"));
alertpanel_error(_("Authentication for %s on %s failed."),
user, SESSION(session)->server);
}
return ok;
}
static GSList *news_get_uncached_articles(NNTPSession *session,
FolderItem *item, gint cache_last,
gint *rfirst, gint *rlast)
@ -288,6 +343,13 @@ static GSList *news_get_uncached_articles(NNTPSession *session,
ok = nntp_group(SESSION(session)->sock, item->path,
&num, &first, &last);
if (ok == NN_AUTHREQ) {
ok = news_authenticate(session, item);
if (ok != NN_SUCCESS)
return NULL;
ok = nntp_group(SESSION(session)->sock, item->path,
&num, &first, &last);
}
if (ok != NN_SUCCESS) {
log_warning(_("can't set group: %s\n"), item->path);
return NULL;

View file

@ -209,6 +209,28 @@ gint nntp_mode(gint sock, gboolean stream)
return ok;
}
gint nntp_authinfo_user(gint sock, const gchar *user)
{
gint ok;
gchar buf[NNTPBUFSIZE];
nntp_gen_send(sock, "AUTHINFO USER %s", user);
ok = nntp_ok(sock, buf);
return ok;
}
gint nntp_authinfo_pass(gint sock, const gchar *pass)
{
gint ok;
gchar buf[NNTPBUFSIZE];
nntp_gen_send(sock, "AUTHINFO PASS %s", pass);
ok = nntp_ok(sock, buf);
return ok;
}
gint nntp_ok(gint sock, gchar *argbuf)
{
gint ok;
@ -223,8 +245,12 @@ gint nntp_ok(gint sock, gchar *argbuf)
if (argbuf)
strcpy(argbuf, buf);
if (!strncmp(buf, "381 ", 4))
return NN_AUTHCONT;
return NN_SUCCESS;
} else
} else if (!strncmp(buf, "480 ", 4))
return NN_AUTHREQ;
else
return NN_ERROR;
}
@ -240,8 +266,12 @@ static void nntp_gen_send(gint sock, const gchar *format, ...)
g_vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
if (verbose)
log_print("NNTP> %s\n", buf);
if (verbose) {
if (!g_strncasecmp(buf, "AUTHINFO PASS", 13))
log_print("NNTP> AUTHINFO PASS ***\n");
else
log_print("NNTP> %s\n", buf);
}
strcat(buf, "\r\n");
sock_write(sock, buf, strlen(buf));

View file

@ -27,6 +27,8 @@
#define NN_SYNTAX 5
#define NN_IOERR 6
#define NN_ERROR 7
#define NN_AUTHREQ 8
#define NN_AUTHCONT 9
#define NNTPBUFSIZE 8192
@ -40,6 +42,8 @@ gint nntp_head(gint sock, gint num, gchar **msgid);
gint nntp_stat(gint sock, gint num, gchar **msgid);
gint nntp_next(gint sock, gint *num, gchar **msgid);
gint nntp_xover(gint sock, gint first, gint last);
gint nntp_authinfo_user(gint sock, const gchar *user);
gint nntp_authinfo_pass(gint sock, const gchar *pass);
gint nntp_post(gint sock, FILE *fp);
gint nntp_newgroups(gint sock);
gint nntp_newnews(gint sock);

View file

@ -1259,10 +1259,10 @@ static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
gtk_widget_hide(basic.smtpserv_label);
gtk_widget_hide(basic.smtpserv_entry);
gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table), 3, 0);
gtk_widget_set_sensitive(basic.uid_label, FALSE);
gtk_widget_set_sensitive(basic.pass_label, FALSE);
gtk_widget_set_sensitive(basic.uid_entry, FALSE);
gtk_widget_set_sensitive(basic.pass_entry, FALSE);
gtk_widget_set_sensitive(basic.uid_label, TRUE);
gtk_widget_set_sensitive(basic.pass_label, TRUE);
gtk_widget_set_sensitive(basic.uid_entry, TRUE);
gtk_widget_set_sensitive(basic.pass_entry, TRUE);
gtk_widget_set_sensitive(receive.pop3_frame, FALSE);
break;
case A_LOCAL: