Re: Patch for question callback



Here is another version of the sftp-module patch, is as some more
spaces, less debug spew and som other minor adjustments. And another
thing, nautilus seems to keep trying to access the host even if we
return access denied when the user press cancel. I have just looked at
the parts for this patch and I can't find the problem. From that I asume
that the problem might be in nautilus or a general problem for the sftp
module.

//Snaggen

On sön, 2004-04-18 at 22:12 +0200, Mattias Eriksson wrote:
> Here is an updated version of the patch where I have fixed the issues
> you point out. I now use a primary and secondary message and I have
> reversed the button ordering. And I have added alot of spaces :-).
> 
> //Snaggen
Index: sftp-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/sftp-method.c,v
retrieving revision 1.5
diff -u -B -r1.5 sftp-method.c
--- sftp-method.c	8 Mar 2004 18:53:47 -0000	1.5
+++ sftp-method.c	19 Apr 2004 18:07:44 -0000
@@ -51,6 +51,7 @@
 
 #include <config.h>
 
+#include <libgnomevfs/gnome-vfs-i18n.h>
 #include <libgnomevfs/gnome-vfs-context.h>
 #include <libgnomevfs/gnome-vfs-method.h>
 #include <libgnomevfs/gnome-vfs-module.h>
@@ -944,7 +945,10 @@
 	GError         *error = NULL;
 
 	gchar          *args[20]; /* Enough for now, extend if you add more args */
-
+	gboolean invoked; 		  
+	GnomeVFSModuleCallbackQuestionIn in_args; 
+	GnomeVFSModuleCallbackQuestionOut out_args;
+	
 	DEBUG (gchar *tmp);
 
 	/* Fill in the first few args */
@@ -1046,7 +1050,13 @@
 		char buffer[1024];
 		gsize len;
 		char *password;
-
+		char *choices[3];
+		char *pos;
+		char *startpos;
+		char *endpos;
+		char hostname[256];
+		char fingerprint[256];
+		
 		FD_ZERO (&ifds);
 		FD_SET (in_fd, &ifds);
 		FD_SET (tty_fd, &ifds);
@@ -1082,12 +1092,81 @@
 					goto bail;
 				}
 				done_auth = TRUE;
-			} else if (g_str_has_prefix (buffer, "The authenticity of host")) {
-				/* FIXME: This should do a callback asking the user if the host id is ok */
-				/* For now we just fail */
-				res = GNOME_VFS_ERROR_ACCESS_DENIED;
-				goto bail;
-                        }
+			} else if (g_str_has_prefix (buffer, "The authenticity of host '")) {
+
+				pos = strchr (&buffer[26],'\'');
+				if (!pos) {
+					res = GNOME_VFS_ERROR_GENERIC;
+					goto bail;
+				}
+
+				if (pos-(&buffer[26])<255) {
+					strncpy (hostname, &buffer[26], pos-(&buffer[26]));
+					hostname[pos-(&buffer[26])]='\0';
+				} else {
+					strncpy (hostname, &buffer[26], 255);
+					hostname[255]='\0';
+				}
+				
+				startpos = strstr (pos, "RSA key fingerprint is ");
+				if (!startpos) {
+					res = GNOME_VFS_ERROR_GENERIC;
+					goto bail;
+				}
+			
+				startpos = startpos + 23;
+				endpos = strchr (startpos, '.');
+				if (!endpos) {
+					res = GNOME_VFS_ERROR_GENERIC;
+					goto bail;
+				}
+				
+				if (endpos-startpos<255) {
+					strncpy (fingerprint, startpos, endpos-startpos);
+					fingerprint[endpos-startpos]='\0';
+				} else {
+					strncpy (fingerprint, startpos, 255);
+					fingerprint[255]='\0';
+				}
+				
+				in_args.primary_message = g_strdup_printf (_("Error while logging in to %s"), hostname);
+				in_args.secondary_message = g_strdup_printf (_("The identity of the remote computer seems to have changed since the last time it was accessed. This can happen in normal situations, such as a computer being upgraded. However, there is also a possibility that someone is maliciously impersonating the remote computer.\n \nThe identity sent by the remote host is:\n%s.\nIf you want to be sure it is safe to continue, contact the system administrator."), fingerprint);
+				
+				in_args.choices = choices;
+				in_args.choices[0] = _("Accept New Host Key");
+				in_args.choices[1] = _("Cancel");
+				in_args.choices[2] = NULL;
+				
+				invoked = gnome_vfs_module_callback_invoke
+					(GNOME_VFS_MODULE_CALLBACK_QUESTION,
+					 &in_args, sizeof (in_args),
+					 &out_args, sizeof (out_args));
+				
+				if (invoked) {
+					if (out_args.answer == 0) {
+						g_io_channel_write_chars (tty_channel, "yes\n", -1, &len, NULL);
+					} else {
+						g_io_channel_write_chars (tty_channel, "no\n", -1, &len, NULL);
+						g_free (in_args.primary_message);
+						g_free (in_args.secondary_message);
+						res = GNOME_VFS_ERROR_ACCESS_DENIED;
+						goto bail;
+					}
+					g_io_channel_flush (tty_channel, NULL);
+					buffer[0]='\0';
+				} else {
+					g_io_channel_write_chars (tty_channel, "no\n", -1, &len, NULL);
+					g_io_channel_flush (tty_channel, NULL);
+					buffer[0]='\0';
+					g_free (in_args.primary_message);
+					g_free (in_args.secondary_message);
+					res = GNOME_VFS_ERROR_ACCESS_DENIED;
+					goto bail;
+				}
+				g_free (in_args.primary_message);
+				g_free (in_args.secondary_message);
+			}
+			
 		}
 	}
 


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