#include <glib/gi18n.h>
#include <stdio.h>
#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#if (defined(__DragonFly__) || defined (__NetBSD__) || defined (__FreeBSD__) || defined (__OpenBSD__))
+# include <sys/signal.h>
+#endif
#ifndef G_OS_WIN32
#include <sys/mman.h>
#endif
if (account == NULL)
account = account_get_default();
+ if (account->address == NULL) {
+ alertpanel_error(_("You have to save the account's information with \"OK\" "
+ "before being able to generate a key pair.\n"));
+ return;
+ }
if (ask_create) {
val = alertpanel(_("No PGP key found"),
_("Sylpheed-Claws did not find a secret PGP key, "
gpgme_release(ctx);
return;
} else {
- alertpanel_notice(_("Your new key pair has been generated. "
- "Its fingerprint is:\n%s"),
+ gchar *buf = g_strdup_printf(_("Your new key pair has been generated. "
+ "Its fingerprint is:\n%s\n\nDo you want to export it "
+ "to a keyserver?"),
key->fpr ? key->fpr:"null");
+ AlertValue val = alertpanel(_("Key generated"), buf,
+ GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL);
+ g_free(buf);
+ if (val == G_ALERTALTERNATE) {
+#ifndef G_OS_WIN32
+ gchar *cmd = g_strdup_printf("gpg --no-tty --send-keys %s", key->fpr);
+ int res = 0;
+ pid_t pid = 0;
+ pid = fork();
+ if (pid == -1) {
+ res = -1;
+ } else if (pid == 0) {
+ /* son */
+ res = system(cmd);
+ res = WEXITSTATUS(res);
+ _exit(res);
+ } else {
+ int status = 0;
+ time_t start_wait = time(NULL);
+ res = -1;
+ do {
+ if (waitpid(pid, &status, WNOHANG) == 0 || !WIFEXITED(status)) {
+ usleep(200000);
+ } else {
+ res = WEXITSTATUS(status);
+ break;
+ }
+ if (time(NULL) - start_wait > 5) {
+ debug_print("SIGTERM'ing gpg\n");
+ kill(pid, SIGTERM);
+ }
+ if (time(NULL) - start_wait > 6) {
+ debug_print("SIGKILL'ing gpg\n");
+ kill(pid, SIGKILL);
+ break;
+ }
+ } while(1);
+ }
+ if (res == 0) {
+ alertpanel_notice(_("Key exported."));
+ } else {
+ alertpanel_error(_("Couldn't export key."));
+ }
+ g_free(cmd);
+#else
+ alertpanel_error(_("Key export isn't implemented in Windows."));
+#endif
+ }
}
prefs_gpg_get_config()->gpg_ask_create_key = FALSE;
prefs_gpg_save_config();