From 1c42865639fd0acfa89786a8257b788a9a76a074 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Sun, 01 Mar 2009 17:27:30 +0000 Subject: WIP --- Index: telepathy-haze-0.4.0/src/main.c =================================================================== --- telepathy-haze-0.4.0.orig/src/main.c +++ telepathy-haze-0.4.0/src/main.c @@ -30,6 +30,8 @@ #include +#include + #include #include #include @@ -175,6 +177,105 @@ set_libpurple_preferences (void) } + +static void +copy_one_cert_dir (const gchar *source_root, + GFile *target_dir) +{ + gchar *source_path; + GFile *source_dir; + GFileEnumerator *contents; + GFileInfo *child_info; + GError *error = NULL; + + source_path = g_build_filename (source_root, "telepathy-haze", + "certificates", NULL); + source_dir = g_file_new_for_path (source_path); + + contents = g_file_enumerate_children (source_dir, + G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NONE, NULL, &error); + + if (contents == NULL) + { + if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_NOT_FOUND) + DEBUG ("couldn't list %s (%s, %d, %s); skipping", source_path, + g_quark_to_string (error->domain), error->code, error->message); + + g_error_free (error); + goto finally; + } + + while ((child_info = g_file_enumerator_next_file (contents, NULL, &error))) + { + const gchar *child_name = g_file_info_get_name (child_info); + GFile *source_file = g_file_get_child (source_dir, child_name); + GFile *target_file = g_file_get_child (target_dir, child_name); + gboolean yay; + + yay = g_file_copy (source_file, target_file, 0, NULL, NULL, NULL, + &error); + + if (!yay) + { + DEBUG ("couldn't copy %s to %s: %s", g_file_get_basename + (source_file), g_file_get_basename (target_file), + error->message); + g_clear_error (&error); + } + + g_object_unref (source_file); + g_object_unref (target_file); + g_object_unref (child_info); + } + + g_object_unref (contents); + +finally: + g_object_unref (source_dir); + g_free (source_path); +} + + +/** + * seed_tls_peers: + * + * Adds known-trusted certificates from haze's data dirs to the temporary + * libpurple config directory. Thus, people can work around haze falling down + * a well if libpurple wants to ask the user to accept or decline a cert. + */ +static void +seed_tls_peers (void) +{ + const gchar * const *dirs = g_get_system_data_dirs (); + gchar *target_path; + GFile *target_dir; + int ret; + + target_path = g_build_filename (user_dir, "certificates", "x509", + "tls_peers", NULL); + ret = g_mkdir_with_parents (target_path, 0755); + DEBUG ("%s", target_path); + + if (ret != 0) + { + g_warning ("Couldn't mkdir -p %s: %s", target_path, g_strerror (errno)); + goto finally; + } + + target_dir = g_file_new_for_path (target_path); + + copy_one_cert_dir (g_get_user_data_dir (), target_dir); + + for (; *dirs != NULL; dirs++) + copy_one_cert_dir (*dirs, target_dir); + + g_object_unref (target_dir); + +finally: + g_free (target_path); +} + + static void init_libpurple (void) { @@ -202,6 +303,8 @@ init_libpurple (void) purple_dbus_uninit (); #endif + seed_tls_peers (); + purple_set_blist(purple_blist_new()); purple_blist_load(); Index: telepathy-haze-0.4.0/configure.ac =================================================================== --- telepathy-haze-0.4.0.orig/configure.ac +++ telepathy-haze-0.4.0/configure.ac @@ -74,6 +74,7 @@ AC_SUBST(ENABLE_LEAKY_REQUEST_STUBS) PKG_CHECK_MODULES(PURPLE,[purple >= 2.6]) PKG_CHECK_MODULES(TP_GLIB,[telepathy-glib >= 0.8.1]) PKG_CHECK_MODULES(GLIB,[glib-2.0 >= 2.20, gobject-2.0]) +PKG_CHECK_MODULES(GIO,[gio-2.0]) PKG_CHECK_MODULES(DBUS_GLIB,[dbus-glib-1 >= 0.73]) AC_ARG_ENABLE([mail-notification], Index: telepathy-haze-0.4.0/src/Makefile.am =================================================================== --- telepathy-haze-0.4.0.orig/src/Makefile.am +++ telepathy-haze-0.4.0/src/Makefile.am @@ -69,6 +69,7 @@ AM_CFLAGS = \ @PURPLE_CFLAGS@ \ @TP_GLIB_CFLAGS@ \ @DBUS_GLIB_CFLAGS@ \ - @GLIB_CFLAGS@ + @GLIB_CFLAGS@ \ + @GIO_CFLAGS@ -AM_LDFLAGS = @PURPLE_LIBS@ @TP_GLIB_LIBS@ @DBUS_GLIB_LIBS@ @GLIB_LIBS@ +AM_LDFLAGS = @PURPLE_LIBS@ @TP_GLIB_LIBS@ @DBUS_GLIB_LIBS@ @GLIB_LIBS@ @GIO_LIBS@