+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()
#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,
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)
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;
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;
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;
}
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));
#define NN_SYNTAX 5
#define NN_IOERR 6
#define NN_ERROR 7
+#define NN_AUTHREQ 8
+#define NN_AUTHCONT 9
#define NNTPBUFSIZE 8192
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);
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: