Re: Patch

Dirk Nimmich <[email protected]>
Newsgroups gmane.network.tin.devel
Message-ID <[email protected]>
Urs Janßen wrote:
> nice to hear from you again :-)

Don't expect too much, I'm just doing some recreational excercises.
;-)

Attached another patch for two other bugs mentioned in TODO.


Additionally I tried to fix the auth bug you described in TODO but I
don't think I have understood the problem. There's no way to edit
the username in the first pass because I assumed that if there is a
.newsauth file there's no need to do so - everything should just be
correct in it, and you only need to interactively change things when
something goes wrong.

Nevertheless see the second patch for auth.c that should fix some
other minor bug (authentication with cached values is always
considered successful) and moves some code around. ;-) It now also
allows to specify if credentials must be supplied manually. Have
fun, play around and try if your problem is solved, but be aware
that I only made sure that the code compiles, I haven't tested it at
all (lack of server that requires authentication ;-).


All patches against snapshot of 2006-09-06.
192-2.diff (text/plain, 3.3 KB)
diff -Nur tin-1.9.2/doc/CHANGES tin-1.9.2-dn/doc/CHANGES
--- tin-1.9.2/doc/CHANGES	2006-09-06 16:39:19.000000000 +0200
+++ tin-1.9.2-dn/doc/CHANGES	2006-09-16 20:59:46.000000000 +0200
@@ -2,8 +2,11 @@
 
 U005) Dirk Nimmich <[email protected]>
       BUG. raw-mode didn't allow rot13
-      BUG. can't 'V'iew mime-parts with (illegal) encoded filename
-      FIX. proto.h, feed.c, page.c, save.c
+      BUG. can't 'V'iew mime-parts with (illegally) encoded filename
+      BUG. CatchupNextUnread in page level didn't always work
+      BUG. 'C'atchup in pager was still not correct (we didn't ever enter the
+           next group)
+      FIX. proto.h, feed.c, group.c, page.c, save.c, thread.c
 
  015) Michael Bienia <[email protected]>
       BUG. 'l' from the pager doesn't reposition cursor to last viewed
diff -Nur tin-1.9.2/doc/TODO tin-1.9.2-dn/doc/TODO
--- tin-1.9.2/doc/TODO	2006-09-03 03:55:06.000000000 +0200
+++ tin-1.9.2-dn/doc/TODO	2006-09-16 20:58:31.000000000 +0200
@@ -4,11 +4,6 @@
 
 Bugs
 ----
-o  CatchupNextUnread in pagelevel doesn't always work (if commeing directly
-   from group level (via GroupNextUnreadArtOrGrp)): instead of leaving the
-   thread and entering the next one it stays at the current article.
-   [20060515 Urs Janssen <[email protected]>]
-
 o  a wrong usename in ~/.newsauth can't be corrected in the first
    pass
    [20050816 Urs Janssen <[email protected]>]
@@ -35,9 +30,6 @@
    flashing changes to all affected groups and remove the reread of the
    attributes file from select.c
 
-o  'C'atchup in pager is still not correct (we don't ever enter the next group)
-   [20030515 Urs Janssen <[email protected]>]
-
 o  piping/printing articles grabbles screen
    [20030501 Urs Janssen <[email protected]>]
 
diff -Nur tin-1.9.2/src/group.c tin-1.9.2-dn/src/group.c
--- tin-1.9.2/src/group.c	2006-02-15 19:44:38.000000000 +0100
+++ tin-1.9.2-dn/src/group.c	2006-09-16 21:07:57.000000000 +0200
@@ -3,7 +3,7 @@
  *  Module    : group.c
  *  Author    : I. Lea & R. Skrenta
  *  Created   : 1991-04-01
- *  Updated   : 2005-07-02
+ *  Updated   : 2006-09-16
  *  Notes     :
  *
  * Copyright (c) 1991-2006 Iain Lea <[email protected]>, Rich Skrenta <[email protected]>
@@ -1573,8 +1573,11 @@
 						break;		/* Drop into next thread with unread */
 					}
 				}
-				/* No more unread threads in this group */
-				/* FALLTHROUGH */
+				/* No more unread threads in this group, enter next group */
+				grpmenu.curr = 0;
+				return GRP_NEXTUNREAD;
+				/* NOTREACHED */
+				break;
 
 			case GRP_KILLED:
 				grpmenu.curr = 0;
diff -Nur tin-1.9.2/src/thread.c tin-1.9.2-dn/src/thread.c
--- tin-1.9.2/src/thread.c	2006-07-20 17:08:47.000000000 +0200
+++ tin-1.9.2-dn/src/thread.c	2006-09-16 20:32:04.000000000 +0200
@@ -3,7 +3,7 @@
  *  Module    : thread.c
  *  Author    : I. Lea
  *  Created   : 1991-04-01
- *  Updated   : 2006-07-20
+ *  Updated   : 2006-09-16
  *  Notes     :
  *
  * Copyright (c) 1991-2006 Iain Lea <[email protected]>
@@ -448,7 +448,7 @@
 	 * See if we're on a direct call from the group menu to the pager
 	 */
 	if (page) {
-		if ((ret_code = enter_pager(page->art, page->ignore_unavail, GROUP_LEVEL)) != 0)
+		if ((ret_code =	enter_pager(find_response(thread_basenote, thdmenu.curr), page->ignore_unavail, GROUP_LEVEL)) != 0)
 			return ret_code;
 		/* else fall through to stay in thread level */
 	}
192-3.diff (text/plain, 7.8 KB)
--- tin-1.9.2/src/auth.c	2006-02-15 19:44:38.000000000 +0100
+++ tin-1.9.2-dn/src/auth.c	2006-09-17 00:43:51.000000000 +0200
@@ -3,7 +3,7 @@
  *  Module    : auth.c
  *  Author    : Dirk Nimmich <[email protected]>
  *  Created   : 1997-04-05
- *  Updated   : 2005-08-16
+ *  Updated   : 2006-09-17
  *  Notes     : Routines to authenticate to a news server via NNTP.
  *              DON'T USE get_respcode() THROUGHOUT THIS CODE.
  *
@@ -52,7 +52,7 @@
 /*
  * local prototypes
  */
-static int do_authinfo_original(char *server, char *authuser, char *authpass);
+static int do_authinfo_original(char *server, char *authuser, char *authpass, t_bool force_question, t_bool startup);
 static t_bool authinfo_generic(void);
 static t_bool read_newsauth_file(char *server, char *authuser, char *authpass);
 static t_bool authinfo_original(char *server, char *authuser, t_bool startup);
@@ -253,11 +253,43 @@
 do_authinfo_original(
 	char *server,
 	char *authuser,
-	char *authpass)
+	char *authpass,
+	t_bool force_question,
+	t_bool startup)
 {
 	char line[PATH_LEN];
 	int ret;
+	t_bool message_displayed = FALSE;
+
+	if ((authuser == NULL) || (*authuser == '\0') || force_question) {
+		t_bool valid = FALSE;
+
+		if ((authuser != NULL) && (force_auth_on_conn_open || force_question || !startup)) {
+#ifdef USE_CURSES
+			int state = RawState();
+#endif /* USE_CURSES */
+
+			wait_message(0, _(txt_auth_needed));
+			message_displayed = TRUE;
+#ifdef USE_CURSES
+			Raw(TRUE);
+#endif /* USE_CURSES */
 
+			valid = prompt_default_string(_(txt_auth_user), authuser, PATH_LEN, authuser, HIST_NONE);
+#ifdef USE_CURSES
+			Raw(state);
+#endif /* USE_CURSES */
+		}
+
+		if ((authuser == NULL) || (!valid) || (*authuser == '\0')) {
+#ifdef DEBUG
+			debug_nntp("authorization", "failed: no username");
+#endif /* DEBUG */
+			error_message(_(txt_nntp_authorization_failed), server);
+			return ERR_AUTHBAD;
+		}
+	}
+	
 	snprintf(line, sizeof(line), "AUTHINFO USER %s", authuser);
 #ifdef DEBUG
 	debug_nntp("authorization", line);
@@ -266,12 +298,41 @@
 	if ((ret = get_only_respcode(NULL, 0)) != NEED_AUTHDATA)
 		return ret;
 
-	if ((authpass == NULL) || (*authpass == '\0')) {
+
+	if ((authpass == NULL) || (*authpass == '\0') || force_question) {
+		/* ask for password; on startup only if forced */
+		if ((authpass != NULL) && (force_auth_on_conn_open || force_question || !startup)) {
+			if (!message_displayed)
+				wait_message(0, _(txt_auth_needed));
+
+#ifdef USE_CURSES
+			my_printf("%s", _(txt_auth_pass));
+			/*
+			 * TODO: wgetnstr is probably not useful here; passwords must not
+			 * be echoed on screen
+			 */
+			wgetnstr(stdscr, authpass, PATH_LEN - 1);
+#else
+#	if 0
+		/*
+		 * on some systems (i.e. Solaris) getpass(3) is limited to 8 chars ->
+		 * we use tin_getline() till we have a config check
+		 * for getpass() or our own getpass()
+		 */
+			authpass = strncpy(authpass, getpass(_(txt_auth_pass)), PATH_LEN - 1);
+#	else
+			authpass = strncpy(authpass, tin_getline(_(txt_auth_pass), FALSE, NULL, PATH_LEN, TRUE, HIST_NONE), PATH_LEN - 1);
+#	endif /* 0 */
+#endif /* USE_CURSES */
+		}
+		
+		if ((authpass == NULL) || (authpass == '\0')) {
 #ifdef DEBUG
-		debug_nntp("authorization", "failed: no password");
+			debug_nntp("authorization", "failed: no password");
 #endif /* DEBUG */
-		error_message(_(txt_nntp_authorization_failed), server);
-		return ERR_AUTHBAD;
+			error_message(_(txt_nntp_authorization_failed), server);
+			return ERR_AUTHBAD;
+		}
 	}
 
 	snprintf(line, sizeof(line), "AUTHINFO PASS %s", authpass);
@@ -311,6 +372,7 @@
 	static char last_server[PATH_LEN] = "";
 	static t_bool already_failed = FALSE;
 	static t_bool initialized = FALSE;
+	t_bool cached_failed = FALSE;
 
 #ifdef DEBUG
 	debug_nntp("authorization", "original authinfo");
@@ -318,22 +380,29 @@
 
 
 	changed = strcmp(server, last_server);	/* do we need new auth values? */
-	strncpy(last_server, server, PATH_LEN - 1);
-	last_server[PATH_LEN - 1] = '\0';
+	STRCPY(last_server, server);
 
 	/*
 	 * Let's try the previous auth pair first, if applicable.
 	 * Else, proceed to the other mechanisms.
 	 */
-	if (initialized && !changed && !already_failed && do_authinfo_original(server, authusername, authpassword))
+	if (initialized && !changed && !already_failed && !(cached_failed = (OK_AUTH != do_authinfo_original(server, authusername, authpassword, FALSE, startup)))) {
+#ifdef DEBUG
+		debug_nntp("authorization", "succeeded");
+#endif /* DEBUG */
 		return TRUE;
+	}
 
-	authpassword[0] = '\0';
-	authuser = strncpy(authusername, authuser, sizeof(authusername) - 1);
+	/*
+	 * At this point either values are not initialized or cached values 
+	 * failed
+	 */
+	
+	STRCPY(authusername, authuser);	/* username now default value */
+	authpassword[0] = '\0';			/* password now empty */
 	authpass = authpassword;
 
 	/*
-	 * No username/password given yet.
 	 * Read .newsauth only if we had not failed authentication yet for the
 	 * current server (we don't want to try wrong username/password pairs
 	 * more than once because this may lead to an infinite loop at connection
@@ -348,70 +417,18 @@
 	 */
 	if (changed || (!changed && !already_failed)) {
 		already_failed = FALSE;
-		if (read_newsauth_file(server, authuser, authpass)) {
-			ret = do_authinfo_original(server, authuser, authpass);
-			if (!(already_failed = (ret != OK_AUTH))) {
-#ifdef DEBUG
-				debug_nntp("authorization", "succeeded");
-#endif /* DEBUG */
-				initialized = TRUE;
-				return TRUE;
-			}
-		}
+		read_newsauth_file(server, authusername, authpassword);
 	}
-
+	
 	/*
-	 * At this point, either authentication with username/password pair from
-	 * .newsauth has failed or there's no .newsauth file respectively no
-	 * matching username/password for the current server. If we are not at
-	 * startup we ask the user to enter such a pair by hand. Don't ask him
-	 * startup except if requested by -A option because if he doesn't need
-	 * authenticate(we don't know), the "Server expects authentication"
-	 * messages are annoying (and even wrong).
-	 * UNSURE: Maybe we want to make this decision configurable in the
-	 * options menu, too, so that the user doesn't need -A.
-	 * TODO: Put questions into do_authinfo_original because it is possible
-	 * that the server doesn't want a password; so only ask for it if needed.
+	 * Now authenticate. If done again because of earlier failures (previous
+	 * pass or cached values), enforce user interaction.
 	 */
-	if (force_auth_on_conn_open || !startup) {
-#ifdef USE_CURSES
-		int state = RawState();
-#endif /* USE_CURSES */
-
-		wait_message(0, _(txt_auth_needed));
-#ifdef USE_CURSES
-		Raw(TRUE);
-#endif /* USE_CURSES */
-
-		if (!prompt_default_string(_(txt_auth_user), authuser, PATH_LEN, authusername, HIST_NONE)) {
-#ifdef DEBUG
-			debug_nntp("authorization", "failed: no username");
-#endif /* DEBUG */
-			return FALSE;
-		}
-
-#ifdef USE_CURSES
-		Raw(state);
-		my_printf("%s", _(txt_auth_pass));
-		wgetnstr(stdscr, authpassword, sizeof(authpassword));
-		Raw(TRUE);
-#else
-#	if 0
-		/*
-		 * on some systems (i.e. Solaris) getpass(3) is limited to 8 chars ->
-		 * we use tin_getline() till we have a config check
-		 * for getpass() or our own getpass()
-		 */
-		authpass = strncpy(authpassword, getpass(_(txt_auth_pass)), sizeof(authpassword) - 1);
-#	else
-		authpass = strncpy(authpassword, tin_getline(_(txt_auth_pass), FALSE, NULL, PATH_LEN, TRUE, HIST_NONE), sizeof(authpassword) - 1);
-#	endif /* 0 */
-#endif /* USE_CURSES */
-
-		ret = do_authinfo_original(server, authuser, authpass);
-		initialized = TRUE;
-		my_retouch();			/* Get rid of the chaff */
-	}
+	 
+	ret = do_authinfo_original(server, authusername, authpassword, already_failed || cached_failed, startup);
+	already_failed = (ret != OK_AUTH); 
+	initialized = TRUE;
+	my_retouch();			/* Get rid of the chaff */
 
 #ifdef DEBUG
 	debug_nntp("authorization", (ret == OK_AUTH ? "succeeded" : "failed"));
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.