diff options
author | Chris Toshok <toshok@helixcode.com> | 2000-07-13 08:15:44 +0800 |
---|---|---|
committer | Chris Toshok <toshok@src.gnome.org> | 2000-07-13 08:15:44 +0800 |
commit | 0b66e8a93bd8d91d456015c36b9556fce4c91ec9 (patch) | |
tree | 10ae1b452b2bef101ecbafbd33d81c4918d20a5f /addressbook/gui/component | |
parent | d75a6c0b382e49706c0b56f52bf1d711658c2686 (diff) | |
download | gsoc2013-evolution-0b66e8a93bd8d91d456015c36b9556fce4c91ec9.tar.gz gsoc2013-evolution-0b66e8a93bd8d91d456015c36b9556fce4c91ec9.tar.zst gsoc2013-evolution-0b66e8a93bd8d91d456015c36b9556fce4c91ec9.zip |
oops. fix typo that was saving the port in the rootdn spot.
2000-07-12 Chris Toshok <toshok@helixcode.com>
* gui/component/e-ldap-storage.c (ldap_server_foreach): oops. fix
typo that was saving the port in the rootdn spot.
(save_ldap_data): make this a bit safer - writing to a new file
and renaming it.
(load_ldap_data): make this a bit smarter - if parsing the
ldapservers.xml file fails and there's a .new file there,
rename it.
svn path=/trunk/; revision=4131
Diffstat (limited to 'addressbook/gui/component')
-rw-r--r-- | addressbook/gui/component/e-ldap-storage.c | 64 |
1 files changed, 57 insertions, 7 deletions
diff --git a/addressbook/gui/component/e-ldap-storage.c b/addressbook/gui/component/e-ldap-storage.c index 052413d6bd..a4fc14c4b2 100644 --- a/addressbook/gui/component/e-ldap-storage.c +++ b/addressbook/gui/component/e-ldap-storage.c @@ -56,6 +56,11 @@ #include "e-util/e-util.h" #include "e-util/e-xml-utils.h" +#include <sys/types.h> +#include <sys/fcntl.h> +#include <sys/stat.h> +#include <errno.h> + #define LDAPSERVER_XML "ldapservers.xml" static gboolean load_ldap_data (EvolutionStorage *storage, const char *file_path); @@ -126,9 +131,31 @@ load_ldap_data (EvolutionStorage *storage, xmlNode *root; xmlNode *child; + tryagain: doc = xmlParseFile (file_path); if (doc == NULL) { - return FALSE; + /* check to see if a ldapserver.xml.new file is + there. if it is, rename it and run with it */ + char *new_path = g_strdup_printf ("%s.new", file_path); + struct stat sb; + + if (stat (new_path, &sb) == 0) { + int rv; + + rv = rename (new_path, file_path); + g_free (new_path); + + if (0 > rv) { + g_error ("Failed to rename ldapserver.xml: %s\n", strerror(errno)); + return FALSE; + } + else { + goto tryagain; + } + } + + g_free (new_path); + return TRUE; } root = xmlDocGetRootElement (doc); @@ -189,7 +216,7 @@ ldap_server_foreach(gpointer key, gpointer value, gpointer user_data) xmlNewChild (server_root, NULL, (xmlChar *) "host", (xmlChar *) server->port); xmlNewChild (server_root, NULL, (xmlChar *) "rootdn", - (xmlChar *) server->port); + (xmlChar *) server->rootdn); xmlNewChild (server_root, NULL, (xmlChar *) "scope", (xmlChar *) server->scope); } @@ -199,6 +226,10 @@ save_ldap_data (const char *file_path) { xmlDoc *doc; xmlNode *root; + int fd, rv; + xmlChar *buf; + int buf_size; + char *new_path = g_strdup_printf ("%s.new", file_path); doc = xmlNewDoc ((xmlChar *) "1.0"); root = xmlNewDocNode (doc, NULL, (xmlChar *) "contactservers", NULL); @@ -206,14 +237,33 @@ save_ldap_data (const char *file_path) g_hash_table_foreach (servers, ldap_server_foreach, root); - if (xmlSaveFile (file_path, doc) < 0) { - unlink (file_path); - xmlFreeDoc (doc); + fd = open (new_path, O_CREAT | O_TRUNC | O_WRONLY, 0600); + fchmod (fd, 0600); + + xmlDocDumpMemory (doc, &buf, &buf_size); + + if (buf == NULL) { + g_error ("Failed to write ldapserver.xml: xmlBufferCreate() == NULL"); return FALSE; } - xmlFreeDoc (doc); - return TRUE; + rv = write (fd, buf, buf_size); + xmlFree (buf); + close (fd); + + if (0 > rv) { + g_error ("Failed to write new ldapserver.xml: %s\n", strerror(errno)); + unlink (new_path); + return FALSE; + } + else { + if (0 > rename (new_path, file_path)) { + g_error ("Failed to rename ldapserver.xml: %s\n", strerror(errno)); + unlink (new_path); + return FALSE; + } + return TRUE; + } } void |