int parse_polyaness(FILE* fp, int offset, polyaness_t** polyaness) { if (fp == NULL || *polyaness == NULL) return -1; int code = 0, recs = 0; char* buf = NULL; size_t len = 0, x_bufl = BUFLEN; if ((buf = (char*) malloc(sizeof(char) * x_bufl)) == NULL) return -1; rewind(fp); while ((code = fgetc(fp)) != EOF) { if (code == LF) { if (offset > 0) { offset--; continue; } if (add_data_polyaness(recs, count_keys(buf), buf, &polyaness) < 0) goto ERR; memset(buf, '\0', x_bufl); recs++; len = 0; } else { if (offset > 0) continue; if (len == (x_bufl - 1)) { x_bufl += BUFLEN; if ((buf = (char*) realloc(buf, sizeof(char) * x_bufl)) == NULL) goto ERR; } buf[len] = code; len++; } } free(buf); return 0; ERR: if (buf != NULL) { free(buf); buf = NULL; } return -1; }
/* Return an array of gpgme key objects derived from thye list of strings in RECPIENTS. */ static gpg_error_t prepare_recipient_keys (gpgme_key_t **r_keys, char **recipients, HWND hwnd) { gpg_error_t err; gpgme_key_t *keys = NULL; char **unknown = NULL; size_t n_keys, n_unknown, n_recp; int i; *r_keys = NULL; if (op_lookup_keys (recipients, &keys, &unknown)) { log_debug ("%s:%s: leave (lookup keys failed)\n", SRCNAME, __func__); return gpg_error (GPG_ERR_GENERAL); } n_recp = count_strings (recipients); n_keys = count_keys (keys); n_unknown = count_strings (unknown); log_debug ("%s:%s: found %d recipients, need %d, unknown=%d\n", SRCNAME, __func__, (int)n_keys, (int)n_recp, (int)n_unknown); if (n_keys != n_recp) { unsigned int opts; gpgme_key_t *keys2; log_debug ("%s:%s: calling recipient_dialog_box2", SRCNAME, __func__); opts = recipient_dialog_box2 (keys, unknown, &keys2); release_key_array (keys); keys = keys2; if ( (opts & OPT_FLAG_CANCEL) ) { err = gpg_error (GPG_ERR_CANCELED); goto leave; } } /* If a default key has been set, add it to the list of keys. Check that the key is actually available. */ if (opt.enable_default_key && opt.default_key && *opt.default_key) { gpgme_key_t defkey; defkey = op_get_one_key (opt.default_key); if (!defkey) { MessageBox (hwnd, _("The configured default encryption certificate is not " "available or does not unambigiously specify one. " "Please fix this in the option dialog.\n\n" "This message won't be be encrypted to this certificate!"), _("Encryption"), MB_ICONWARNING|MB_OK); } else { gpgme_key_t *tmpkeys; n_keys = count_keys (keys) + 1; tmpkeys = xcalloc (n_keys+1, sizeof *tmpkeys); for (i = 0; keys[i]; i++) { tmpkeys[i] = keys[i]; gpgme_key_ref (tmpkeys[i]); } tmpkeys[i++] = defkey; tmpkeys[i] = NULL; release_key_array (keys); keys = tmpkeys; } } if (keys) { for (i=0; keys[i]; i++) log_debug ("%s:%s: recp.%d 0x%s %s\n", SRCNAME, __func__, i, keyid_from_key (keys[i]), userid_from_key (keys[i])); } *r_keys = keys; keys = NULL; err = 0; leave: release_key_array (keys); return err; }