Cosmetic: use always g_getenv instead of getenv
[claws.git] / src / plugins / pgpcore / sgpgme.c
index cbbfcc49623d90e1be401a4fd9a95c4124019b9c..7afe4bfe82dee98a36da6fc8222472e7c4e294ea 100644 (file)
@@ -14,7 +14,6 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
  */
 
 #ifdef HAVE_CONFIG_H
@@ -213,24 +212,23 @@ gchar *sgpgme_sigstat_info_short(gpgme_ctx_t ctx, gpgme_verify_result_t status)
                if (!warned)
                        alertpanel_error(_("PGP Core: Can't get key - no gpg-agent running."));
                else
-                       g_warning(_("PGP Core: Can't get key - no gpg-agent running."));
+                       g_warning("PGP Core: Can't get key - no gpg-agent running.");
                warned = TRUE;
        } else if (gpg_err_code(err) != GPG_ERR_NO_ERROR && gpg_err_code(err) != GPG_ERR_EOF) {
                return g_strdup_printf(_("The signature can't be checked - %s"), 
                        gpgme_strerror(err));
-       } else if (gpg_err_code(err) != GPG_ERR_NO_ERROR && gpg_err_code(err) == GPG_ERR_EOF) {
-               /*
-                * When gpg is upgraded to gpg-v21 then installer tries to migrate the old
-                * gpg keyrings found in ~/.gnupg to the new version. If the keyrings contain
-                * very old keys using ciphers no more supported in gpg-v21 this transition
-                * can fail and the left-over ~/.gnupg/pubring.gpg will cause claws to crash
-                * when the above condition is meet.
-                */
-               debug_print("left-over ~/.gnupg/pubring.gpg might solve the\n"
-                           "problem if you have installed gpg-v21\n");
-               return g_strdup_printf(_("The signature can't be checked - %s."),
+       } else if (gpg_err_code(err) != GPG_ERR_NO_ERROR && gpg_err_code(err) == GPG_ERR_EOF &&
+                  key == NULL) {
+               /*
+                * When gpg is upgraded to gpg-v21 then installer tries to migrate the old
+                * gpg keyrings found in ~/.gnupg to the new version. If the keyrings contain
+                * very old keys using ciphers no more supported in gpg-v21 this transition
+                * can fail and the left-over ~/.gnupg/pubring.gpg will cause claws to crash
+                * when the above condition is meet.
+                */
+               return g_strdup_printf(_("The signature can't be checked - %s."),
                         gpgme_strerror(err));
-       }
+        }
        if (key)
                uname = extract_name(key->uids->uid);
        else
@@ -337,7 +335,7 @@ gchar *sgpgme_sigstat_info_full(gpgme_ctx_t ctx, gpgme_verify_result_t status)
                case GPG_ERR_NO_ERROR:
                        g_string_append_printf(siginfo,
                                _("Good signature from uid \"%s\" (Validity: %s)\n"),
-                               uid, get_validity_str(key->uids?key->uids->validity:GPGME_VALIDITY_UNKNOWN));
+                               uid, get_validity_str((key && key->uids) ? key->uids->validity:GPGME_VALIDITY_UNKNOWN));
                        break;
                case GPG_ERR_KEY_EXPIRED:
                        g_string_append_printf(siginfo,
@@ -347,7 +345,7 @@ gchar *sgpgme_sigstat_info_full(gpgme_ctx_t ctx, gpgme_verify_result_t status)
                case GPG_ERR_SIG_EXPIRED:
                        g_string_append_printf(siginfo,
                                _("Expired signature from uid \"%s\" (Validity: %s)\n"),
-                               uid, get_validity_str(key->uids?key->uids->validity:GPGME_VALIDITY_UNKNOWN));
+                               uid, get_validity_str((key && key->uids) ? key->uids->validity:GPGME_VALIDITY_UNKNOWN));
                        break;
                case GPG_ERR_CERT_REVOKED:
                        g_string_append_printf(siginfo,
@@ -364,17 +362,20 @@ gchar *sgpgme_sigstat_info_full(gpgme_ctx_t ctx, gpgme_verify_result_t status)
                }
                if (sig->status != GPG_ERR_BAD_SIGNATURE) {
                        gint j = 1;
-                       key->uids = key->uids ? key->uids->next : NULL;
-                       while (key->uids != NULL) {
-                               g_string_append_printf(siginfo,
-                                       _("                    uid \"%s\" (Validity: %s)\n"),
-                                       key->uids->uid,
-                                       key->uids->revoked==TRUE?_("Revoked"):get_validity_str(key->uids->validity));
-                               j++;
-                               key->uids = key->uids->next;
+                       if (key) {
+                               key->uids = key->uids ? key->uids->next : NULL;
+                               while (key->uids != NULL) {
+                                       g_string_append_printf(siginfo,
+                                               g_strconcat("                    ",
+                                                           _("uid \"%s\" (Validity: %s)\n"), NULL),
+                                               key->uids->uid,
+                                               key->uids->revoked==TRUE?_("Revoked"):get_validity_str(key->uids->validity));
+                                       j++;
+                                       key->uids = key->uids->next;
+                               }
                        }
                        g_string_append_printf(siginfo,_("Owner Trust: %s\n"),
-                                              get_owner_trust_str(key->owner_trust));
+                                              key ? get_owner_trust_str(key->owner_trust) : _("No key!"));
                        g_string_append(siginfo,
                                _("Primary key fingerprint:"));
                        const char* primary_fpr = NULL;
@@ -456,7 +457,7 @@ gpgme_data_t sgpgme_decrypt_verify(gpgme_data_t cipher, gpgme_verify_result_t *s
        
        if (gpgme_get_protocol(ctx) == GPGME_PROTOCOL_OpenPGP) {
                prefs_gpg_enable_agent(prefs_gpg_get_config()->use_gpg_agent);
-               if (!getenv("GPG_AGENT_INFO") || !prefs_gpg_get_config()->use_gpg_agent) {
+               if (!g_getenv("GPG_AGENT_INFO") || !prefs_gpg_get_config()->use_gpg_agent) {
                        info.c = ctx;
                        gpgme_set_passphrase_cb (ctx, gpgmegtk_passphrase_cb, &info);
                }
@@ -604,7 +605,7 @@ gboolean sgpgme_setup_signers(gpgme_ctx_t ctx, PrefsAccount *account,
                        if (found_key != NULL) {
                                gpgme_key_release(key);
                                gpgme_op_keylist_end(ctx);
-                               g_warning("ambiguous specification of secret key '%s'\n", keyid);
+                               g_warning("ambiguous specification of secret key '%s'", keyid);
                                privacy_set_error(_("Secret key specification is ambiguous"));
                                goto bail;
                        }
@@ -626,7 +627,7 @@ gboolean sgpgme_setup_signers(gpgme_ctx_t ctx, PrefsAccount *account,
                gpgme_key_release(found_key);
 
                if (err) {
-                       g_warning("error adding secret key: %s\n",
+                       g_warning("error adding secret key: %s",
                                  gpgme_strerror(err));
                        privacy_set_error(_("Error setting secret key: %s"),
                                          gpgme_strerror(err));
@@ -998,7 +999,7 @@ void *sgpgme_data_release_and_get_mem(gpgme_data_t data, size_t *len)
        while ((r = gpgme_data_read(data, buf, BUFSIZ)) > 0) {
                void *rresult = realloc(result, r + w);
                if (rresult == NULL) {
-                       g_warning("can't allocate memory\n");
+                       g_warning("can't allocate memory");
                        if (result != NULL)
                                free(result);
                        return NULL;