--- /home/tvt01789/Downloads/main.c 2013-09-23 13:51:19.000000000 -0300 +++ main.c 2015-10-15 20:40:19.832272040 -0300 @@ -31,6 +31,8 @@ #include #include +#include + #include #include #include @@ -175,13 +177,112 @@ } + +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) { - user_dir = g_strconcat (g_get_tmp_dir (), G_DIR_SEPARATOR_S, - "haze-XXXXXX", NULL); + user_dir = g_strconcat (g_get_home_dir (), G_DIR_SEPARATOR_S, + ".haze", NULL); - if (!mkdtemp (user_dir)) { + if (!mkdir ("user_dir", 0644)) { g_error ("Couldn't make temporary conf directory: %s", strerror (errno)); } @@ -202,6 +303,8 @@ purple_dbus_uninit (); #endif + seed_tls_peers (); + purple_set_blist(purple_blist_new()); purple_blist_load(); @@ -268,7 +371,7 @@ argv); purple_core_quit (); - delete_user_dir (); + /* delete_user_dir (); */ return ret; }