From 5f38b1e898698b939d76419cd1fa970effb38ecd Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 17 Oct 2002 03:04:11 +0000 Subject: Don't need to pass a path to camel_gpg_context_new () anymore. 2002-10-16 Jeffrey Stedfast * mail-format.c (handle_multipart_signed): Don't need to pass a path to camel_gpg_context_new () anymore. (mail_get_message_body): Same here. (handle_multipart_encrypted): Use camel_gpg_context_new () instead of mail_crypto_get_pgp_cipher_context (). * mail-preferences.c (mail_preferences_construct): There's no security tab anymore. (mail_preferences_apply): No need to save any pgp config data, there's nothing to configure! * mail-crypto.c (mail_crypto_get_pgp_cipher_context): Updated to not pass a pgp path into camel_gpg_context_new (). * mail-config.c (mail_config_clear): No need to free a pgp_path variable anymore, we don't need one. (config_read): Don't read in a pgp-path or pgp-type anymore. (mail_config_write_on_exit): Don't save a pgp-path or pgp-type anymore, we don't use them. (pgpopen): Removed. (pgpclose): Removed. (mail_config_pgp_type_detect_from_path): Removed. (auto_detect_pgp_variables): Removed. (mail_config_get_pgp_type): Removed. (mail_config_set_pgp_type): Removed. (mail_config_get_pgp_path): Removed. (mail_config_set_pgp_path): Removed. svn path=/trunk/; revision=18384 --- mail/ChangeLog | 30 +++++ mail/mail-config.c | 349 +----------------------------------------------- mail/mail-config.glade | 76 ----------- mail/mail-config.h | 16 --- mail/mail-crypto.c | 2 +- mail/mail-format.c | 6 +- mail/mail-preferences.c | 21 --- mail/mail-preferences.h | 3 - 8 files changed, 37 insertions(+), 466 deletions(-) diff --git a/mail/ChangeLog b/mail/ChangeLog index 8de89bb23f..d8a9f89ae9 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,33 @@ +2002-10-16 Jeffrey Stedfast + + * mail-format.c (handle_multipart_signed): Don't need to pass a + path to camel_gpg_context_new () anymore. + (mail_get_message_body): Same here. + (handle_multipart_encrypted): Use camel_gpg_context_new () instead + of mail_crypto_get_pgp_cipher_context (). + + * mail-preferences.c (mail_preferences_construct): There's no + security tab anymore. + (mail_preferences_apply): No need to save any pgp config data, + there's nothing to configure! + + * mail-crypto.c (mail_crypto_get_pgp_cipher_context): Updated to + not pass a pgp path into camel_gpg_context_new (). + + * mail-config.c (mail_config_clear): No need to free a pgp_path + variable anymore, we don't need one. + (config_read): Don't read in a pgp-path or pgp-type anymore. + (mail_config_write_on_exit): Don't save a pgp-path or pgp-type + anymore, we don't use them. + (pgpopen): Removed. + (pgpclose): Removed. + (mail_config_pgp_type_detect_from_path): Removed. + (auto_detect_pgp_variables): Removed. + (mail_config_get_pgp_type): Removed. + (mail_config_set_pgp_type): Removed. + (mail_config_get_pgp_path): Removed. + (mail_config_set_pgp_path): Removed. + 2002-10-16 Jeffrey Stedfast * mail-callbacks.c (mail_generate_reply): If mode == REPLY_LIST diff --git a/mail/mail-config.c b/mail/mail-config.c index a019519738..58a7a111e3 100644 --- a/mail/mail-config.c +++ b/mail/mail-config.c @@ -26,19 +26,11 @@ #include #endif -/* this group of headers is for pgp detection */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include #include +#include +#include +#include #include #include @@ -107,9 +99,6 @@ typedef struct { GSList *accounts; int default_account; - char *pgp_path; - int pgp_type; - MailConfigHTTPMode http_mode; MailConfigForwardStyle default_forward_style; MailConfigReplyStyle default_reply_style; @@ -358,9 +347,6 @@ mail_config_clear (void) config->accounts = NULL; } - g_free (config->pgp_path); - config->pgp_path = NULL; - g_free (config->default_charset); config->default_charset = NULL; @@ -884,19 +870,6 @@ config_read (void) config->confirm_goto_next_folder = bonobo_config_get_boolean_with_default ( config->db, "/Mail/Prompts/confirm_goto_next_folder", TRUE, NULL); - /* PGP/GPG */ - config->pgp_path = bonobo_config_get_string (config->db, "/Mail/PGP/path", NULL); - - config->pgp_type = bonobo_config_get_long_with_default (config->db, - "/Mail/PGP/type", MAIL_CONFIG_PGP_TYPE_NONE, NULL); - - /* we only support GnuPG now */ - if (config->pgp_type != MAIL_CONFIG_PGP_TYPE_GPG) { - config->pgp_type = MAIL_CONFIG_PGP_TYPE_NONE; - g_free (config->pgp_path); - config->pgp_path = NULL; - } - /* HTTP images */ config->http_mode = bonobo_config_get_long_with_default (config->db, "/Mail/Display/http_images", MAIL_CONFIG_HTTP_NEVER, NULL); @@ -1276,13 +1249,6 @@ mail_config_write_on_exit (void) bonobo_config_set_boolean (config->db, "/Mail/Prompts/confirm_goto_next_folder", config->confirm_goto_next_folder, NULL); - /* PGP/GPG */ - bonobo_config_set_string_wrapper (config->db, "/Mail/PGP/path", - config->pgp_path, NULL); - - bonobo_config_set_long (config->db, "/Mail/PGP/type", - config->pgp_type, NULL); - /* HTTP images */ bonobo_config_set_long (config->db, "/Mail/Display/http_images", config->http_mode, NULL); @@ -1768,315 +1734,6 @@ mail_config_set_goto_next_folder (gboolean value) config->goto_next_folder = value; } -struct { - char *bin; - char *version; - int type; -} binaries[] = { - { "gpg", NULL, MAIL_CONFIG_PGP_TYPE_GPG }, - { "pgp", "6.5.8", MAIL_CONFIG_PGP_TYPE_PGP6 }, - { "pgp", "5.0", MAIL_CONFIG_PGP_TYPE_PGP5 }, - { "pgp", "2.6", MAIL_CONFIG_PGP_TYPE_PGP2 }, - { NULL, NULL, MAIL_CONFIG_PGP_TYPE_NONE } -}; - - -typedef struct _PGPFILE { - FILE *fp; - pid_t pid; -} PGPFILE; - -static PGPFILE * -pgpopen (const char *command, const char *mode) -{ - int in_fds[2], out_fds[2]; - PGPFILE *pgp = NULL; - char **argv = NULL; - pid_t child; - int fd; - - g_return_val_if_fail (command != NULL, NULL); - - if (*mode != 'r' && *mode != 'w') - return NULL; - - argv = g_strsplit (command, " ", 0); - if (!argv) - return NULL; - - if (pipe (in_fds) == -1) - goto error; - - if (pipe (out_fds) == -1) { - close (in_fds[0]); - close (in_fds[1]); - goto error; - } - - if ((child = fork ()) == 0) { - /* In child */ - int maxfd; - - if ((dup2 (in_fds[0], STDIN_FILENO) < 0 ) || - (dup2 (out_fds[1], STDOUT_FILENO) < 0 ) || - (dup2 (out_fds[1], STDERR_FILENO) < 0 )) { - _exit (255); - } - - /* Dissociate from evolution-mail's controlling - * terminal so that pgp/gpg won't be able to read from - * it: PGP 2 will fall back to asking for the password - * on /dev/tty if the passed-in password is incorrect. - * This will make that fail rather than hanging. - */ - setsid (); - - /* close all open fds that we aren't using */ - maxfd = sysconf (_SC_OPEN_MAX); - for (fd = 0; fd < maxfd; fd++) { - if (fd != STDIN_FILENO && fd != STDOUT_FILENO && fd != STDERR_FILENO) - close (fd); - } - - execvp (argv[0], argv); - fprintf (stderr, "Could not execute %s: %s\n", argv[0], - g_strerror (errno)); - _exit (255); - } else if (child < 0) { - close (in_fds[0]); - close (in_fds[1]); - close (out_fds[0]); - close (out_fds[1]); - goto error; - } - - /* Parent */ - g_strfreev (argv); - - close (in_fds[0]); /* pgp's stdin */ - close (out_fds[1]); /* pgp's stdout */ - - if (mode[0] == 'r') { - /* opening in read-mode */ - fd = out_fds[0]; - close (in_fds[1]); - } else { - /* opening in write-mode */ - fd = in_fds[1]; - close (out_fds[0]); - } - - pgp = g_new (PGPFILE, 1); - pgp->fp = fdopen (fd, mode); - pgp->pid = child; - - return pgp; - error: - g_strfreev (argv); - - return NULL; -} - -static int -pgpclose (PGPFILE *pgp) -{ - sigset_t mask, omask; - pid_t wait_result; - int status; - - if (pgp->fp) { - fclose (pgp->fp); - pgp->fp = NULL; - } - - /* PGP5 closes fds before exiting, meaning this might be called - * too early. So wait a bit for the result. - */ - sigemptyset (&mask); - sigaddset (&mask, SIGALRM); - sigprocmask (SIG_BLOCK, &mask, &omask); - alarm (1); - wait_result = waitpid (pgp->pid, &status, 0); - alarm (0); - sigprocmask (SIG_SETMASK, &omask, NULL); - - if (wait_result == -1 && errno == EINTR) { - /* PGP is hanging: send a friendly reminder. */ - kill (pgp->pid, SIGTERM); - sleep (1); - wait_result = waitpid (pgp->pid, &status, WNOHANG); - if (wait_result == 0) { - /* Still hanging; use brute force. */ - kill (pgp->pid, SIGKILL); - sleep (1); - wait_result = waitpid (pgp->pid, &status, WNOHANG); - } - } - - if (wait_result != -1 && WIFEXITED (status)) { - g_free (pgp); - return 0; - } else - return -1; -} - -int -mail_config_pgp_type_detect_from_path (const char *pgp) -{ - const char *bin = g_basename (pgp); - struct stat st; - int i; - - /* make sure the file exists *and* is executable? */ - if (stat (pgp, &st) == -1 || !(st.st_mode & (S_IXOTH | S_IXGRP | S_IXUSR))) - return MAIL_CONFIG_PGP_TYPE_NONE; - - for (i = 0; binaries[i].bin; i++) { - if (binaries[i].version) { - /* compare version strings */ - char buffer[256], *command; - gboolean found = FALSE; - PGPFILE *fp; - - command = g_strdup_printf ("%s --version", pgp); - fp = pgpopen (command, "r"); - g_free (command); - if (fp) { - while (!feof (fp->fp) && !found) { - memset (buffer, 0, sizeof (buffer)); - fgets (buffer, sizeof (buffer), fp->fp); - found = strstr (buffer, binaries[i].version) != NULL; - } - - pgpclose (fp); - - if (found) - return binaries[i].type; - } - } else if (!strcmp (binaries[i].bin, bin)) { - /* no version string to compare against... */ - return binaries[i].type; - } - } - - return MAIL_CONFIG_PGP_TYPE_NONE; -} - -static void -auto_detect_pgp_variables (void) -{ - int type = MAIL_CONFIG_PGP_TYPE_NONE; - const char *PATH, *path; - char *pgp = NULL; - - PATH = getenv ("PATH"); - - path = PATH; - while (path && *path && !type) { - const char *pend = strchr (path, ':'); - gboolean found = FALSE; - char *dirname; - int i; - - if (pend) { - /* don't even think of using "." */ - if (!strncmp (path, ".", pend - path)) { - path = pend + 1; - continue; - } - - dirname = g_strndup (path, pend - path); - path = pend + 1; - } else { - /* don't even think of using "." */ - if (!strcmp (path, ".")) - break; - - dirname = g_strdup (path); - path = NULL; - } - - for (i = 0; binaries[i].bin; i++) { - struct stat st; - - pgp = g_strdup_printf ("%s/%s", dirname, binaries[i].bin); - /* make sure the file exists *and* is executable? */ - if (stat (pgp, &st) != -1 && st.st_mode & (S_IXOTH | S_IXGRP | S_IXUSR)) { - if (binaries[i].version) { - /* compare version strings */ - char buffer[256], *command; - PGPFILE *fp; - - command = g_strdup_printf ("%s --version", pgp); - fp = pgpopen (command, "r"); - g_free (command); - if (fp) { - while (!feof (fp->fp) && !found) { - memset (buffer, 0, sizeof (buffer)); - fgets (buffer, sizeof (buffer), fp->fp); - found = strstr (buffer, binaries[i].version) != NULL; - } - - pgpclose (fp); - } - } else { - /* no version string to compare against... */ - found = TRUE; - } - - if (found) { - type = binaries[i].type; - break; - } - } - - g_free (pgp); - pgp = NULL; - } - - g_free (dirname); - } - - if (pgp && type) { - mail_config_set_pgp_path (pgp); - mail_config_set_pgp_type (type); - } - - g_free (pgp); -} - -int -mail_config_get_pgp_type (void) -{ - if (!config->pgp_path || !config->pgp_type) - auto_detect_pgp_variables (); - - return config->pgp_type; -} - -void -mail_config_set_pgp_type (int pgp_type) -{ - config->pgp_type = pgp_type; -} - -const char * -mail_config_get_pgp_path (void) -{ - if (!config->pgp_path || !config->pgp_type) - auto_detect_pgp_variables (); - - return config->pgp_path; -} - -void -mail_config_set_pgp_path (const char *pgp_path) -{ - g_free (config->pgp_path); - - config->pgp_path = g_strdup (pgp_path); -} - MailConfigHTTPMode mail_config_get_http_mode (void) { diff --git a/mail/mail-config.glade b/mail/mail-config.glade index 201bda6cf4..6c43dc9852 100644 --- a/mail/mail-config.glade +++ b/mail/mail-config.glade @@ -3110,82 +3110,6 @@ Baltic (ISO-8859-4) 0 - - GtkVBox - vboxSecurity - False - 0 - - - GtkHBox - hboxPgpPath - 4 - False - 4 - - 0 - False - True - - - - GtkLabel - lblPgpPath - - GTK_JUSTIFY_CENTER - False - 0.5 - 0.5 - 0 - 0 - combo-entry1 - - 0 - False - False - - - - - GnomeFileEntry - filePgpPath - 4 - Select PGP program - False - True - - 0 - True - True - - - - GtkEntry - GnomeEntry:entry - combo-entry1 - True - True - True - 0 - - - - - - - - GtkLabel - Notebook:tab - lblSecurity - - GTK_JUSTIFY_CENTER - False - 0.5 - 0.5 - 0 - 0 - - GtkFrame frameColours diff --git a/mail/mail-config.h b/mail/mail-config.h index 95159faafe..3b8732b97b 100644 --- a/mail/mail-config.h +++ b/mail/mail-config.h @@ -31,14 +31,6 @@ extern "C" { #pragma } #endif /* __cplusplus */ -enum { - MAIL_CONFIG_PGP_TYPE_NONE, - MAIL_CONFIG_PGP_TYPE_PGP2, /* no longer supported */ - MAIL_CONFIG_PGP_TYPE_PGP5, /* no longer supported */ - MAIL_CONFIG_PGP_TYPE_PGP6, /* no longer supported */ - MAIL_CONFIG_PGP_TYPE_GPG -}; - typedef struct { int id; char *name; @@ -229,14 +221,6 @@ void mail_config_set_confirm_goto_next_folder (gboolean value); gboolean mail_config_get_goto_next_folder (void); void mail_config_set_goto_next_folder (gboolean value); -int mail_config_pgp_type_detect_from_path (const char *pgp); - -int mail_config_get_pgp_type (void); -void mail_config_set_pgp_type (int pgp_type); - -const char *mail_config_get_pgp_path (void); -void mail_config_set_pgp_path (const char *pgp_path); - MailConfigHTTPMode mail_config_get_http_mode (void); void mail_config_set_http_mode (MailConfigHTTPMode); diff --git a/mail/mail-crypto.c b/mail/mail-crypto.c index 7eb604286b..115745d247 100644 --- a/mail/mail-crypto.c +++ b/mail/mail-crypto.c @@ -44,7 +44,7 @@ mail_crypto_get_pgp_cipher_context (const MailConfigAccount *account) { CamelCipherContext *cipher; - cipher = camel_gpg_context_new (session, mail_config_get_pgp_path ()); + cipher = camel_gpg_context_new (session); if (account) camel_gpg_context_set_always_trust ((CamelGpgContext *) cipher, account->pgp_always_trust); diff --git a/mail/mail-format.c b/mail/mail-format.c index dc63788b66..451b8a1ce1 100644 --- a/mail/mail-format.c +++ b/mail/mail-format.c @@ -1759,7 +1759,7 @@ handle_multipart_encrypted (CamelMimePart *part, const char *mime_type, mpe = CAMEL_MULTIPART_ENCRYPTED (wrapper); camel_exception_init (&ex); - cipher = mail_crypto_get_pgp_cipher_context (NULL); + cipher = camel_gpg_context_new (session); mime_part = camel_multipart_encrypted_decrypt (mpe, cipher, &ex); camel_object_unref (cipher); @@ -1847,7 +1847,7 @@ handle_multipart_signed (CamelMimePart *part, const char *mime_type, /* Write out the verification results */ /* TODO: use the right context for the right message ... */ camel_exception_init (&ex); - cipher = camel_gpg_context_new (session, mail_config_get_pgp_path ()); + cipher = camel_gpg_context_new (session); if (cipher) { valid = camel_multipart_signed_verify (mps, cipher, &ex); camel_object_unref (CAMEL_OBJECT (cipher)); @@ -2375,7 +2375,7 @@ mail_get_message_body (CamelDataWrapper *data, gboolean want_plain, gboolean cit mp = CAMEL_MULTIPART (data); if (CAMEL_IS_MULTIPART_ENCRYPTED (mp)) { - cipher = camel_gpg_context_new (session, mail_config_get_pgp_path ()); + cipher = camel_gpg_context_new (session); subpart = camel_multipart_encrypted_decrypt (CAMEL_MULTIPART_ENCRYPTED (mp), cipher, NULL); if (!subpart) diff --git a/mail/mail-preferences.c b/mail/mail-preferences.c index 7fab3c1567..758f9cd540 100644 --- a/mail/mail-preferences.c +++ b/mail/mail-preferences.c @@ -309,16 +309,6 @@ mail_preferences_construct (MailPreferences *prefs) gtk_signal_connect (GTK_OBJECT (prefs->prompt_unwanted_html), "toggled", toggle_button_toggled, prefs); - /* Security tab */ - - /* Pretty Good Privacy */ - prefs->pgp_path = GNOME_FILE_ENTRY (glade_xml_get_widget (gui, "filePgpPath")); - text = mail_config_get_pgp_path (); - gtk_entry_set_text (GTK_ENTRY (gnome_file_entry_gtk_entry (prefs->pgp_path)), text ? text : ""); - gnome_file_entry_set_default_path (prefs->pgp_path, mail_config_get_pgp_path ()); - gtk_signal_connect (GTK_OBJECT (gnome_file_entry_gtk_entry (prefs->pgp_path)), "changed", - entry_changed, prefs); - /* Labels and Colours tab */ for (i = 0; i < 5; i++) { char *widget_name; @@ -360,7 +350,6 @@ void mail_preferences_apply (MailPreferences *prefs) { GtkWidget *entry, *menu; - int pgp_type; char *string; guint32 rgb; int i, val; @@ -414,16 +403,6 @@ mail_preferences_apply (MailPreferences *prefs) mail_config_set_confirm_unwanted_html (gtk_toggle_button_get_active (prefs->prompt_unwanted_html)); - /* Security */ - entry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (prefs->pgp_path)); - string = gtk_entry_get_text (GTK_ENTRY (entry)); - - pgp_type = string && *string ? mail_config_pgp_type_detect_from_path (string) : MAIL_CONFIG_PGP_TYPE_NONE; - if (pgp_type == MAIL_CONFIG_PGP_TYPE_GPG) { - mail_config_set_pgp_path (string && *string ? string : NULL); - mail_config_set_pgp_type (pgp_type); - } - /* Labels and Colours */ for (i = 0; i < 5; i++) { /* save the label... */ diff --git a/mail/mail-preferences.h b/mail/mail-preferences.h index 86317a5239..36835f018e 100644 --- a/mail/mail-preferences.h +++ b/mail/mail-preferences.h @@ -93,9 +93,6 @@ struct _MailPreferences { /* GtkHTML Properties */ GtkHTMLPropmanager *pman; - /* Security tab */ - GnomeFileEntry *pgp_path; - /* Labels and Colours tab */ struct { GtkEntry *name; -- cgit