/* * Reconnect to server after a timeout, reissue last command to * get us back into the pre-timeout state */ static int reconnect( int retry) { char buf[NNTP_STRLEN]; /* * Tear down current connection */ NNTP_HARD_CLOSE; if (!tinrc.auto_reconnect) ring_bell(); DEBUG_IO((stderr, _("\nServer timed out, trying reconnect # %d\n"), retry)); /* * Exit tin if the user says no to reconnect. The exit code stops tin from trying * to disconnect again - the connection is already dead */ if (!tinrc.auto_reconnect && prompt_yn(cLINES, _(txt_reconnect_to_news_server), TRUE) != 1) tin_done(NNTP_ERROR_EXIT); /* user said no to reconnect */ clear_message(); strcpy(buf, last_put); /* Keep copy here, it will be clobbered a lot otherwise */ if (!nntp_open()) { /* * Re-establish our current group and resend last command */ if (curr_group != NULL) { DEBUG_IO((stderr, _("Rejoin current group\n"))); sprintf(last_put, "GROUP %s", curr_group->name); put_server(last_put); s_gets(last_put, NNTP_STRLEN, nntp_rd_fp); # ifdef DEBUG debug_nntp("<<<", last_put); # endif /* DEBUG */ DEBUG_IO((stderr, _("Read (%s)\n"), last_put)); } DEBUG_IO((stderr, _("Resend last command (%s)\n"), buf)); put_server(buf); return 0; } if (--retry == 0) /* No more tries? */ tin_done(NNTP_ERROR_EXIT); return retry; }
/* * Perform authentication with AUTHINFO USER method. Return response * code from server. * * we don't handle ERR_ENCRYPT right now */ static int do_authinfo_user( char *server, char *authuser, char *authpass) { char line[PATH_LEN]; int ret; snprintf(line, sizeof(line), "AUTHINFO USER %s", authuser); # ifdef DEBUG if (debug & DEBUG_NNTP) debug_print_file("NNTP", "authorization %s", line); # endif /* DEBUG */ put_server(line); if ((ret = get_only_respcode(NULL, 0)) != NEED_AUTHDATA) return ret; if ((authpass == NULL) || (*authpass == '\0')) { # ifdef DEBUG if (debug & DEBUG_NNTP) debug_print_file("NNTP", "authorization failed: no password"); # endif /* DEBUG */ error_message(2, _(txt_auth_failed_nopass), server); return ERR_AUTHBAD; } snprintf(line, sizeof(line), "AUTHINFO PASS %s", authpass); # ifdef DEBUG if (debug & DEBUG_NNTP) debug_print_file("NNTP", "authorization %s", line); # endif /* DEBUG */ put_server(line); ret = get_only_respcode(line, sizeof(line)); if (!batch_mode || verbose || ret != OK_AUTH) wait_message(2, (ret == OK_AUTH ? _(txt_authorization_ok) : _(txt_authorization_fail)), authuser); return ret; }
static int do_authinfo_sasl_plain( char *authuser, char *authpass) { char line[PATH_LEN]; char *foo; char *utf8user; char *utf8pass; int ret; # ifdef CHARSET_CONVERSION char *cp; int i, c = 0; t_bool contains_8bit = FALSE; # endif /* CHARSET_CONVERSION */ utf8user = my_strdup(authuser); utf8pass = my_strdup(authpass); # ifdef CHARSET_CONVERSION /* RFC 4616 */ if (!IS_LOCAL_CHARSET("UTF-8")) { for (cp = utf8user; *cp && !contains_8bit; cp++) { if (!isascii(*cp)) { contains_8bit = TRUE; break; } } for (cp = utf8pass; *cp && !contains_8bit; cp++) { if (!isascii(*cp)) { contains_8bit = TRUE; break; } } if (contains_8bit) { for (i = 0; txt_mime_charsets[i] != NULL; i++) { if (!strcasecmp("UTF-8", txt_mime_charsets[i])) { c = i; break; } } if (c == i) { /* should never fail */ if (!buffer_to_network(utf8user, c)) { free(utf8user); free(utf8pass); utf8user = my_strdup(authuser); utf8pass = my_strdup(authpass); } else { if (!buffer_to_network(utf8pass, c)) { free(utf8user); free(utf8pass); utf8user = my_strdup(authuser); utf8pass = my_strdup(authpass); } } } } } # endif /* CHARSET_CONVERSION */ # ifdef DEBUG if (debug & DEBUG_NNTP) debug_print_file("NNTP", "do_authinfo_sasl_plain(\"%s\", \"%s\")", BlankIfNull(authuser), BlankIfNull(authpass)); # endif /* DEBUG */ if ((foo = sasl_auth_plain(utf8user, utf8pass)) == NULL) { free(utf8user); free(utf8pass); return ERR_AUTHBAD; } free(utf8user); free(utf8pass); snprintf(line, sizeof(line), "AUTHINFO SASL PLAIN %s", foo); FreeIfNeeded(foo); # ifdef DEBUG if (debug & DEBUG_NNTP) debug_print_file("NNTP", "authorization %s", line); # endif /* DEBUG */ put_server(line); ret = get_only_respcode(line, sizeof(line)); if (!batch_mode || verbose || ret != OK_AUTH) wait_message(2, (ret == OK_AUTH ? _(txt_authorization_ok) : _(txt_authorization_fail)), authuser); return ret; }