Re: [evolution-patches] 42721, upgrading passwords 1.2 -> 1.3



damn, my finger slipped and i hit send instead of attach :)  (and i
thought i'd crashed the composer!).

On Fri, 2003-05-16 at 11:26, Not Zed wrote:
> This should upgrade passwords for 1.2 -> 1.3, not sure if versions prior
> to 1.2 stored them the same way.
> 
> Only tested for mail passwords, but so long as the component key has
> remained the same, it should work for other components too.
> 
> 
> _______________________________________________
> Evolution-patches mailing list
> Evolution-patches lists ximian com
> http://lists.ximian.com/mailman/listinfo/evolution-patches
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/shell/ChangeLog,v
retrieving revision 1.1275
diff -u -3 -r1.1275 ChangeLog
--- ChangeLog	15 May 2003 18:19:16 -0000	1.1275
+++ ChangeLog	16 May 2003 00:51:24 -0000
@@ -1,3 +1,15 @@
+2003-05-16  Not Zed  <NotZed Ximian com>
+
+	[#42721]
+	
+	* e-config-upgrade.c (import_passwords_1_2): upgrade passwords
+	from 1.2 to 1.3.x.  If by chance any password is already there,
+	leave it.
+	(e_config_upgrade): run the password upgrade if we're upgrading
+	from below 1.3 only.
+	(base64_decode, base64_decode_step): Added a base64 decoder
+	required for above.
+
 2003-05-15  Ettore Perazzoli  <ettore ximian com>
 
 	* e-shell.c (parse_default_uri): Protect against the component
Index: e-config-upgrade.c
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-config-upgrade.c,v
retrieving revision 1.10
diff -u -3 -r1.10 e-config-upgrade.c
--- e-config-upgrade.c	15 May 2003 15:21:16 -0000	1.10
+++ e-config-upgrade.c	16 May 2003 00:51:25 -0000
@@ -37,6 +37,8 @@
 #include <gconf/gconf.h>
 #include <gconf/gconf-client.h>
 
+#include <libgnome/gnome-config.h>
+
 #include <libxml/xmlmemory.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
@@ -45,10 +47,10 @@
 
 #define d(x) 
 
-/* output revision of configuration */
+/* output revision of configuration, bump the revision whenever this file changes & track the release number */
 #define CONF_MAJOR (1)
 #define CONF_MINOR (3)
-#define CONF_REVISION (1)
+#define CONF_REVISION (2)
 
 /* major/minor/revision of existing config */
 static unsigned int major = -1;
@@ -107,7 +109,91 @@
 	return res;
 }
 
-/* so we dont need camel, just copy here */
+/* from camel-mime-utils.c */
+static unsigned char camel_mime_base64_rank[256] = {
+	255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+	255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+	255,255,255,255,255,255,255,255,255,255,255, 62,255,255,255, 63,
+	 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,255,255,255,  0,255,255,
+	255,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
+	 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,255,255,255,255,255,
+	255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+	 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,255,255,255,255,255,
+	255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+	255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+	255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+	255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+	255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+	255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+	255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+	255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+};
+
+static int
+base64_decode_step(unsigned char *in, int len, unsigned char *out, int *state, unsigned int *save)
+{
+	register unsigned char *inptr, *outptr;
+	unsigned char *inend, c;
+	register unsigned int v;
+	int i;
+
+	inend = in+len;
+	outptr = out;
+
+	/* convert 4 base64 bytes to 3 normal bytes */
+	v=*save;
+	i=*state;
+	inptr = in;
+	while (inptr<inend) {
+		c = camel_mime_base64_rank[*inptr++];
+		if (c != 0xff) {
+			v = (v<<6) | c;
+			i++;
+			if (i==4) {
+				*outptr++ = v>>16;
+				*outptr++ = v>>8;
+				*outptr++ = v;
+				i=0;
+			}
+		}
+	}
+
+	*save = v;
+	*state = i;
+
+	/* quick scan back for '=' on the end somewhere */
+	/* fortunately we can drop 1 output char for each trailing = (upto 2) */
+	i=2;
+	while (inptr>in && i) {
+		inptr--;
+		if (camel_mime_base64_rank[*inptr] != 0xff) {
+			if (*inptr == '=')
+				outptr--;
+			i--;
+		}
+	}
+
+	/* if i!= 0 then there is a truncation error! */
+	return outptr-out;
+}
+
+static char *
+base64_decode(char *base64)
+{
+	unsigned char *plain, *pad = "==";
+	int len, out, state, save;
+	
+	len = strlen(base64);
+	plain = g_malloc0(len);
+	state = save = 0;
+	out = base64_decode_step((unsigned char *)base64, len, plain, &state, &save);
+	if (len % 4)
+		base64_decode_step(pad, 4 - len % 4, plain + out, &state, &save);
+	
+	return plain;
+}
+
+/* from camel-file-utils.c */
 static int
 camel_file_util_decode_uint32 (FILE *in, guint32 *dest)
 {
@@ -157,6 +243,7 @@
 	return 0;
 }
 
+
 /* For 1.0.8 conversion */
 
 /* as much info as we have on a given account */
@@ -1724,6 +1811,96 @@
 	return 0;
 }
 
+/* converts passwords from ~/evolution/private/config.xmldb to gnome_private() */
+static int
+import_passwords_1_2(void)
+{
+	xmlNodePtr root, entry;
+	char *filename;
+	xmlDocPtr priv_doc;
+	struct stat st;
+	int work = 0, res = -1;
+
+	filename =  g_build_filename(evolution_dir, "private/config.xmldb", NULL);
+	if (lstat(filename, &st) == 0 && S_ISREG(st.st_mode))
+		priv_doc = xmlParseFile(filename);
+	g_free(filename);
+
+	if (priv_doc == NULL)
+		return 0;
+
+	root = priv_doc->children;
+	if (strcmp(root->name, "bonobo-config") != 0) {
+		xmlFreeDoc(priv_doc);
+		return 0;
+	}
+
+	root = root->children;
+	while (root) {
+		if (!strcmp(root->name, "section")) {
+			char *path = xmlGetProp(root, "path");
+
+			/* All sections of form
+			   <section path="/Passwords/COMPONENT">
+			    <entry name="base64name" value="hexvalue">
+			  Are converted to:
+			  /Evolution/Passwords-COMPONENT/name = value
+			*/
+
+			if (path && !strncmp(path, "/Passwords/", 11)) {
+				entry = root->children;
+				while (entry) {
+					if (!strcmp(entry->name, "entry")) {
+						char *namep = xmlGetProp(entry, "name"), *valuep = xmlGetProp(entry, "value");
+						
+						if (namep && valuep) {
+							char *name = base64_decode(namep), *value = hex_decode(valuep);
+							char *p = name, *new;
+
+							d(printf("Found password entry '%s' = '%s'\n", name, value));
+
+							while (*p) {
+								if (*p == '/' || *p == '=')
+									*p = '_';
+								p++;
+							}
+
+							p = g_strdup_printf("/Evolution/Passwords-%s/%s", path+11, name);
+							new = gnome_config_private_get_string_with_default(p, NULL);
+							if (new == NULL) {
+								d(printf("password not there, setting '%s' = '%s'\n", p, value));
+								gnome_config_private_set_string(p, value);
+								work = TRUE;
+							} else {
+								d(printf("password already there, leaving\n"));
+							}
+							g_free(p);
+							g_free(name);
+							g_free(value);
+						}
+						xmlFree(namep);
+						xmlFree(valuep);
+					}
+					entry = entry->next;
+				}
+			}
+			xmlFree(path);
+		}
+		root = root->next;
+	}
+
+	xmlFreeDoc(priv_doc);
+
+	if (work) {
+		if (gnome_config_private_sync_file("/Evolution"))
+			res = 0;
+	} else {
+		res = 0;
+	}
+
+	return res;
+}
+
 /**
  * e_config_upgrade:
  * @edir: 
@@ -1832,12 +2009,18 @@
 		}
 	}
 
-	if (config_doc && major <=1 && minor < 3) {
+	if (major <=1 && minor < 3) {
 		/* move bonobo config to gconf */
-		if (import_bonobo_config(config_doc, gconf) == -1) {
-			g_warning("Could not move config from bonobo-conf to gconf");
-			goto error;
+		if (config_doc) {
+			if (import_bonobo_config(config_doc, gconf) == -1) {
+				g_warning("Could not move config from bonobo-conf to gconf");
+				goto error;
+			}
 		}
+
+		/* move passwords to gnome_private */
+		if (import_passwords_1_2() == -1)
+			g_warning("Could not upgrade passwords - continuing anyway");
 	}
 
 	if (major <=1 && minor <=3 && revision < 1) {


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