diff lib/config_file.c @ 330:532eb171d5c2

2003-12-7 Brian Masney <masneyb@gftp.org> * lib/config_file.c lib/gftp.h lib/misc.c lib/options.h - added scramble passwords option. This patch is mostly from Aurelien Jarno <lists@aurel32.net>, but it was modified by me quite a bit. This is not safe, and can be broken. That is why it's labeled scrambled passwords instead of encrypt passwords. * acinclude.m4 - fix to AC_INTL_PRINTF
author masneyb
date Mon, 08 Dec 2003 02:53:24 +0000
parents 0fcc6468a0af
children 6317b45645a8
line wrap: on
line diff
--- a/lib/config_file.c	Mon Dec 08 02:14:26 2003 +0000
+++ b/lib/config_file.c	Mon Dec 08 02:53:24 2003 +0000
@@ -258,7 +258,10 @@
 	  curpos = buf + 9;
 	  if (newentry->pass)
 	    g_free (newentry->pass);
-	  newentry->pass = g_strdup (curpos);
+
+	  /* Always try to descramble passords. If the password is not
+             scrambled, descramble_password returns the string unchanged */
+	  newentry->pass = gftp_descramble_password (curpos);
 	  newentry->save_password = *newentry->pass != '\0';
 	}
       else if (strncmp (buf, "account", 7) == 0 && newentry)
@@ -715,7 +718,8 @@
 gftp_write_bookmarks_file (void)
 {
   gftp_bookmarks_var * tempentry;
-  char *bmhdr, *tempstr;
+  char *bmhdr, *tempstr, *password;
+  intptr_t scramble_passwords;
   FILE * bmfile;
   int i;
 
@@ -739,6 +743,8 @@
   write_comment (bmfile, _(bmhdr));
   fwrite ("\n", 1, 1, bmfile);
 
+  gftp_lookup_global_option ("scramble_passwords", &scramble_passwords);
+  
   tempentry = gftp_bookmarks->children;
   while (tempentry != NULL)
     {
@@ -747,9 +753,21 @@
 	  tempentry = tempentry->children;
 	  continue;
 	}
+
       tempstr = tempentry->path;
       while (*tempstr == '/')
 	tempstr++;
+
+      if (tempentry->save_password && tempentry->pass != NULL)
+        {
+	  if (scramble_passwords)
+            password = gftp_scramble_password (tempentry->pass);
+	  else
+	    password = g_strdup (tempentry->pass);
+	}
+      else
+        password = NULL;
+
       fprintf (bmfile,
 	       "[%s]\nhostname=%s\nport=%d\nprotocol=%s\nremote directory=%s\nlocal directory=%s\nusername=%s\npassword=%s\naccount=%s\n",
 	       tempstr, tempentry->hostname == NULL ? "" : tempentry->hostname,
@@ -759,10 +777,12 @@
 	       tempentry->remote_dir == NULL ? "" : tempentry->remote_dir,
 	       tempentry->local_dir == NULL ? "" : tempentry->local_dir,
 	       tempentry->user == NULL ? "" : tempentry->user,
-	       !tempentry->save_password
-	       || tempentry->pass == NULL ? "" : tempentry->pass,
+	       password == NULL ? "" : password,
 	       tempentry->acct == NULL ? "" : tempentry->acct);
 
+      if (password != NULL)
+        g_free(password);
+
       if (tempentry->local_options_vars != NULL)
         {
           for (i=0; i<tempentry->num_local_options_vars; i++)