/*
* Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Colin Leroy <colin@colino.net> and
- * the Claws Mail team
+ * Copyright (C) 1999-2016 Colin Leroy and the Claws Mail team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
static PrivacyDataPGP *smime_new_privacydata()
{
PrivacyDataPGP *data;
+ gpgme_ctx_t ctx;
+
+ if (gpgme_new(&ctx) != GPG_ERR_NO_ERROR) {
+ debug_print("gpgme_new failed\n");
+ return NULL;
+ }
data = g_new0(PrivacyDataPGP, 1);
data->data.system = &smime_system;
data->done_sigtest = FALSE;
data->is_signed = FALSE;
data->sigstatus = NULL;
- gpgme_new(&data->ctx);
+ data->ctx = ctx;
return data;
}
if (tmpstr && !g_ascii_strcasecmp(tmpstr, "signed-data")) {
if (data == NULL) {
data = smime_new_privacydata();
+ if (!data)
+ return FALSE;
mimeinfo->privacy = (PrivacyData *) data;
}
if (data == NULL) {
data = smime_new_privacydata();
+ if (!data)
+ return FALSE;
mimeinfo->privacy = (PrivacyData *) data;
}
const gchar *tmpstr;
gpgme_data_t sigdata = NULL, textdata = NULL;
gpgme_error_t err;
+ EncodingType oldenc = ENC_BINARY;
+
cm_return_val_if_fail(mimeinfo != NULL, -1);
cm_return_val_if_fail(mimeinfo->privacy != NULL, -1);
+
data = (PrivacyDataPGP *) mimeinfo->privacy;
- gpgme_new(&data->ctx);
- EncodingType oldenc = ENC_BINARY;
-
+
+ if (!data->ctx) {
+ if ((err = gpgme_new(&data->ctx)) != GPG_ERR_NO_ERROR) {
+ debug_print("gpgme_new failed: %s\n",
+ gpgme_strerror(err));
+ return -1;
+ }
+ }
+
debug_print("Checking S/MIME signature\n");
err = gpgme_set_protocol(data->ctx, GPGME_PROTOCOL_CMS);
decinfo = g_node_first_child(newinfo->node) != NULL ?
g_node_first_child(newinfo->node)->data : NULL;
- if (decinfo == NULL)
+ if (decinfo == NULL) {
+ g_free(textstr);
return -1;
+ }
g_node_unlink(decinfo->node);
- procmime_mimeinfo_free_all(newinfo);
+ procmime_mimeinfo_free_all(&newinfo);
decinfo->tmp = TRUE;
parentinfo = procmime_mimeinfo_parent(mimeinfo);
g_node_prepend(parentinfo->node, decinfo->node);
return 0;
} else {
+ g_free(textstr);
return -1;
}
}
}
g_node_unlink(decinfo->node);
- procmime_mimeinfo_free_all(parseinfo);
+ procmime_mimeinfo_free_all(&parseinfo);
decinfo->tmp = TRUE;
data = (PrivacyDataPGP *) decinfo->privacy;
} else {
data = smime_new_privacydata();
+ if (!data) {
+ gpgme_release(ctx);
+ return NULL;
+ }
decinfo->privacy = (PrivacyData *) data;
}
data->done_sigtest = TRUE;
result = gpgme_op_sign_result(ctx);
if (result && result->signatures) {
if (gpgme_get_protocol(ctx) == GPGME_PROTOCOL_OpenPGP) {
- micalg = g_strdup_printf("pgp-%s", g_ascii_strdown(gpgme_hash_algo_name(
- result->signatures->hash_algo),-1));
+ gchar *down_algo = g_ascii_strdown(gpgme_hash_algo_name(
+ result->signatures->hash_algo), -1);
+ micalg = g_strdup_printf("pgp-%s", down_algo);
+ g_free(down_algo);
} else {
micalg = g_strdup(gpgme_hash_algo_name(
result->signatures->hash_algo));
while (fprs[i] && strlen(fprs[i])) {
i++;
}
-
- gpgme_new(&ctx);
+
+ if ((err = gpgme_new(&ctx)) != GPG_ERR_NO_ERROR) {
+ debug_print ("gpgme_new failed: %s\n", gpgme_strerror(err));
+ return FALSE;
+ }
err = gpgme_set_protocol(ctx, GPGME_PROTOCOL_CMS);
if (err) {
debug_print ("gpgme_set_protocol failed: %s\n",
gpgme_strerror (err));
- return FALSE;
+ return FALSE;
}
kset = g_malloc(sizeof(gpgme_key_t)*(i+1));
tmpfile = get_tmp_file();
fp = g_fopen(tmpfile, "wb");
if (fp == NULL) {
- perror("get_tmp_file");
+ FILE_OP_ERROR(tmpfile, "create");
g_free(kset);
return FALSE;
}
canonicalize_file_replace(tmpfile);
fp = g_fopen(tmpfile, "rb");
if (fp == NULL) {
- perror("get_tmp_file");
+ FILE_OP_ERROR(tmpfile, "open");
g_free(kset);
return FALSE;
}
enccontent = sgpgme_data_release_and_get_mem(gpgenc, &len);
if (!enccontent) {
- g_warning("no enccontent\n");
+ g_warning("no enccontent");
return FALSE;
}
fclose(fp);
claws_unlink(tmpfile);
g_free(tmpfile);
+ g_free(enccontent);
return FALSE;
}
if (fclose(fp) == EOF) {
FILE_OP_ERROR(tmpfile, "fclose");
claws_unlink(tmpfile);
g_free(tmpfile);
+ g_free(enccontent);
return FALSE;
}
} else {
- perror("get_tmp_file");
+ FILE_OP_ERROR(tmpfile, "create");
g_free(tmpfile);
+ g_free(enccontent);
return FALSE;
}
gpgme_data_release(gpgtext);
g_free(textstr);
/* create encrypted multipart */
- procmime_mimeinfo_free_all(msgcontent);
+ procmime_mimeinfo_free_all(&msgcontent);
g_node_append(mimeinfo->node, encmultipart->node);
encmultipart->content = MIMECONTENT_FILE;