Re: [PATCH] Fix FTP/SFTP authentication cancellation



Am Dienstag, den 18.10.2005, 09:57 +0200 schrieb Alexander Larsson:
> On Mon, 2005-10-17 at 20:45 +0200, Christian Neumair wrote:
> > Am Montag, den 17.10.2005, 13:09 +0200 schrieb Alexander Larsson:
> > >  static gboolean
> > > -prompt_authentication (SmbAuthContext *actx)
> > > +prompt_authentication (SmbAuthContext *actx,
> > > +                      gboolean       *cancelled)
> > > 
> > > This isn't fixing all uses of the old non-pointer cancelled variable.
> > > (In particular, it breaks the return value at the end.)
> > 
> > Eeek, I sent an old revision. I´ve actually changed the latter in a
> > later revision.
> > 
> > This one additionally initializes cancelled to FALSE in
> > prompt_authentication (gcc 4 complains, gcc 3 not), and improves the
> > previously bogus DEBUG_SMB macro invocations in perform_authentication.
> 
> It still looks the same. prompt_authentication() uses the the cancelled
> pointer without dereferencing it

Dunno why this isn't in the patch. It was in my local tree.

> and doesn't initialize it.

Well, it is IMHO only meant to be valid if invoked is TRUE. However,
I've changed it to match the semantics of the other modules.

-- 
Christian Neumair <chris gnome-de org>
? modules/attachment.cgi?id=23538&action=view
Index: modules/ftp-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/ftp-method.c,v
retrieving revision 1.117
diff -u -p -r1.117 ftp-method.c
--- modules/ftp-method.c	2 Jun 2005 14:10:56 -0000	1.117
+++ modules/ftp-method.c	18 Oct 2005 15:16:25 -0000
@@ -809,7 +809,8 @@ save_authn_info (GnomeVFSURI *uri,
 
 static gboolean
 query_user_for_authn_info (GnomeVFSURI *uri, 
-			   char **user, char **pass, char **keyring, gboolean *save,
+			   char **user, char **pass, char **keyring,
+			   gboolean *save, gboolean *aborted,
 			   gboolean no_username)
 {
 	GnomeVFSModuleCallbackFullAuthenticationIn in_args;
@@ -850,10 +851,10 @@ query_user_for_authn_info (GnomeVFSURI *
 		*pass = g_strdup ("nobody gnome org");
                 goto error;
         }
-	
-        ret = !out_args.abort_auth;
-	
-        if (!ret) {
+
+	*aborted = out_args.abort_auth;
+
+	if (out_args.abort_auth) {
                 goto error;
         }
 	
@@ -882,8 +883,8 @@ query_user_for_authn_info (GnomeVFSURI *
        	g_free (out_args.domain);
        	g_free (out_args.password);
        	g_free (out_args.keyring);
-	
-	return ret;
+
+	return ret && !out_args.abort_auth;
 } 
 
 static gboolean
@@ -1249,6 +1250,7 @@ ftp_connection_create (FtpConnectionPool
 	gboolean got_connection;
 	gboolean ret;
 	gboolean connection_failed;
+	gboolean aborted;
 	
 	cancellation = get_cancellation (context);
 	
@@ -1320,7 +1322,7 @@ ftp_connection_create (FtpConnectionPool
 				pool->num_connections++;
 				G_UNLOCK (connection_pools);
 				ret = query_user_for_authn_info (uri, &user, &pass, &keyring, &save_authn, 
-								 !uri_has_username); 
+								 &aborted, !uri_has_username); 
 				G_LOCK (connection_pools);
 				pool->num_connections--;
 				if (!ret) {
@@ -1330,7 +1332,12 @@ ftp_connection_create (FtpConnectionPool
 					g_free (user);
 					g_free (pass);
 					g_free (keyring);
-                                	return GNOME_VFS_ERROR_LOGIN_FAILED;
+
+					if (aborted) {
+						return GNOME_VFS_ERROR_CANCELLED;
+					} else {
+						return GNOME_VFS_ERROR_LOGIN_FAILED;
+					}
 				}
 				g_string_free (conn->response_buffer, TRUE);
                         	conn->response_buffer = g_string_new ("");
Index: modules/sftp-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/sftp-method.c,v
retrieving revision 1.35
diff -u -p -r1.35 sftp-method.c
--- modules/sftp-method.c	18 Jul 2005 08:19:28 -0000	1.35
+++ modules/sftp-method.c	18 Oct 2005 15:16:25 -0000
@@ -927,7 +927,8 @@ invoke_full_auth (const GnomeVFSURI *uri
 		  char **user_out,
 		  char **object_out,
 		  char **authtype_out,
-		  gboolean *save_password_out)
+		  gboolean *save_password_out,
+		  gboolean *abort_auth_out)
 {
 	GnomeVFSModuleCallbackFullAuthenticationIn in_args;
 	GnomeVFSModuleCallbackFullAuthenticationOut out_args;
@@ -970,6 +971,8 @@ invoke_full_auth (const GnomeVFSURI *uri
 		*password_out = NULL;
 	}
 
+	*abort_auth_out = out_args.abort_auth;
+
 	g_free (in_args.uri);
 	g_free (in_args.username);
 	g_free (in_args.object);
@@ -1208,6 +1211,7 @@ sftp_connect (SftpConnection **connectio
 		char *endpos;
 		char *hostname = NULL;
 		char *fingerprint = NULL;
+		gboolean aborted;
 
 		if (client_vendor == SFTP_VENDOR_SSH) {
 			prompt_fd = err_fd;
@@ -1255,11 +1259,14 @@ sftp_connect (SftpConnection **connectio
 					g_io_channel_write_chars (tty_channel, "\n", 1, &len, NULL);
 					g_io_channel_flush (tty_channel, NULL);
 				} else if (invoke_full_auth (uri, done_auth, buffer, &password, &keyring, 
-							     &user, &object, &authtype, &save_password) && password != NULL) {
+							     &user, &object, &authtype, &save_password, &aborted) && password != NULL) {
 					full_auth = TRUE;
 					g_io_channel_write_chars (tty_channel, password, -1, &len, NULL);
 					g_io_channel_write_chars (tty_channel, "\n", 1, &len, NULL);
 					g_io_channel_flush (tty_channel, NULL);
+				} else if (aborted) {
+					res = GNOME_VFS_ERROR_CANCELLED;
+					goto bail;
 				} else {
 					res = GNOME_VFS_ERROR_ACCESS_DENIED;
 					goto bail;
Index: modules/smb-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/smb-method.c,v
retrieving revision 1.34
diff -u -p -r1.34 smb-method.c
--- modules/smb-method.c	5 Oct 2005 08:49:29 -0000	1.34
+++ modules/smb-method.c	18 Oct 2005 15:16:26 -0000
@@ -922,13 +922,14 @@ prefill_authentication (SmbAuthContext *
 }
 
 static gboolean
-prompt_authentication (SmbAuthContext *actx)
+prompt_authentication (SmbAuthContext *actx,
+		       gboolean       *cancelled)
 {
 	/* IMPORTANT: We are NOT in the lock at this point */
 
 	GnomeVFSModuleCallbackFullAuthenticationIn in_args;
 	GnomeVFSModuleCallbackFullAuthenticationOut out_args;
-	gboolean invoked, cancelled = FALSE;
+	gboolean invoked;
 	
 	g_return_val_if_fail (actx != NULL, FALSE);
 	g_return_val_if_fail (actx->for_server != NULL, FALSE);
@@ -961,7 +962,6 @@ prompt_authentication (SmbAuthContext *a
 		 &out_args, sizeof (out_args));
 
 	if (invoked) {
-		cancelled = out_args.abort_auth;
                 if (in_args.flags & GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION_NEED_USERNAME) {
                      g_free (actx->use_user);
                        actx->use_user = string_dup_nzero (out_args.username);
@@ -977,7 +977,9 @@ prompt_authentication (SmbAuthContext *a
 		actx->keyring = actx->save_auth && out_args.keyring ? g_strdup (out_args.keyring) : NULL;
 		DEBUG_SMB(("[auth] Prompted credentials: %s %s:%s\n", actx->use_user, actx->use_domain, actx->use_password));
 	} 
-	
+
+	*cancelled = out_args.abort_auth;
+
 	actx->state |= SMB_AUTH_STATE_PROMPTED;
 
 	g_free (out_args.username);
@@ -987,7 +989,7 @@ prompt_authentication (SmbAuthContext *a
 
 	g_free (in_args.uri);
 
-	return invoked && !cancelled;
+	return invoked && !*cancelled;
 }
 
 static void
@@ -1125,7 +1127,7 @@ init_authentication (SmbAuthContext *act
 static int
 perform_authentication (SmbAuthContext *actx)
 {
-	gboolean cont, auth_failed = FALSE;
+	gboolean cont, auth_failed = FALSE, auth_cancelled = FALSE;
 	int ret = -1;
 	
 	/* IMPORTANT: We are IN the lock at this point */
@@ -1203,7 +1205,7 @@ perform_authentication (SmbAuthContext *
 				}
 				
 				if (!cont)
-					cont = prompt_authentication (actx);
+					cont = prompt_authentication (actx, &auth_cancelled);
 				
 			LOCK_SMB();
 			
@@ -1214,9 +1216,16 @@ perform_authentication (SmbAuthContext *
 			if (cont)
 				ret = 1;
 			else {
-				/* Note that we leave actx->res set to whatever it was set to */
-				DEBUG_SMB(("[auth] Authentication cancelled by user.\n"));
 				ret = -1;
+
+				if (auth_cancelled) {
+					DEBUG_SMB(("[auth] Authentication cancelled by user.\n"));
+					actx->res = GNOME_VFS_ERROR_CANCELLED;
+				} else {
+					DEBUG_SMB(("[auth] Authentication failed with result %s.\n",
+						  gnome_vfs_result_to_string (actx->res)));
+					/* Note that we leave actx->res set to whatever it was set to */
+				}
 			}
 					
 		/* Weird, don't want authentication, but failed */

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]