1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

Fixed an fopen problem on Windows Vista.

This commit is contained in:
Werner Koch 2009-06-03 17:24:24 +00:00
parent 323cca8041
commit dac70ca2fd
6 changed files with 70 additions and 74 deletions

View file

@ -1,3 +1,13 @@
2009-06-03 Werner Koch <wk@g10code.com>
* protect-tool.c: Include estream.h.
(store_private_key): Replace stdio streams by estream functions
for a portable use of the "x" mode.
* trustlist.c: Include estream.h.
(agent_marktrusted): Repalce stdio stream by estream functions.
* protect-tool.c (store_private_key): Use bin2hex.
2009-06-02 Werner Koch <wk@g10code.com>
* gpg-agent.c (main): Run pth_kill after fork. Fixes bug#1066.

View file

@ -44,6 +44,7 @@
#include "i18n.h"
#include "get-passphrase.h"
#include "sysutils.h"
#include "estream.h"
enum cmd_and_opt_values
@ -1199,18 +1200,15 @@ static int
store_private_key (const unsigned char *grip,
const void *buffer, size_t length, int force)
{
int i;
char *fname;
FILE *fp;
estream_t fp;
char hexgrip[40+4+1];
for (i=0; i < 20; i++)
sprintf (hexgrip+2*i, "%02X", grip[i]);
strcpy (hexgrip+40, ".key");
bin2hex (grip, 20, hexgrip);
fname = make_filename (opt_homedir, GNUPG_PRIVATE_KEYS_DIR, hexgrip, NULL);
if (force)
fp = fopen (fname, "wb");
fp = es_fopen (fname, "wb");
else
{
if (!access (fname, F_OK))
@ -1224,9 +1222,9 @@ store_private_key (const unsigned char *grip,
xfree (fname);
return opt_no_fail_on_exist? 0 : -1;
}
fp = fopen (fname, "wbx"); /* FIXME: the x is a GNU extension - let
configure check whether this actually
works */
/* FWIW: Under Windows Vista the standard fopen in the msvcrt
fails if the "x" GNU extension is used. */
fp = es_fopen (fname, "wbx");
}
if (!fp)
@ -1236,15 +1234,15 @@ store_private_key (const unsigned char *grip,
return -1;
}
if (fwrite (buffer, length, 1, fp) != 1)
if (es_fwrite (buffer, length, 1, fp) != 1)
{
log_error ("error writing `%s': %s\n", fname, strerror (errno));
fclose (fp);
es_fclose (fp);
remove (fname);
xfree (fname);
return -1;
}
if ( fclose (fp) )
if (es_fclose (fp))
{
log_error ("error closing `%s': %s\n", fname, strerror (errno));
remove (fname);

View file

@ -31,6 +31,7 @@
#include "agent.h"
#include <assuan.h> /* fixme: need a way to avoid assuan calls here */
#include "i18n.h"
#include "estream.h"
/* A structure to store the information from the trust file. */
@ -552,7 +553,7 @@ agent_marktrusted (ctrl_t ctrl, const char *name, const char *fpr, int flag)
gpg_error_t err = 0;
char *desc;
char *fname;
FILE *fp;
estream_t fp;
char *fprformatted;
char *nameformatted;
int is_disabled;
@ -691,7 +692,7 @@ agent_marktrusted (ctrl_t ctrl, const char *name, const char *fpr, int flag)
fname = make_filename (opt.homedir, "trustlist.txt", NULL);
if ( access (fname, F_OK) && errno == ENOENT)
{
fp = fopen (fname, "wx"); /* Warning: "x" is a GNU extension. */
fp = es_fopen (fname, "wx");
if (!fp)
{
err = gpg_error_from_syserror ();
@ -702,10 +703,10 @@ agent_marktrusted (ctrl_t ctrl, const char *name, const char *fpr, int flag)
xfree (nameformatted);
return err;
}
fputs (headerblurb, fp);
fclose (fp);
es_fputs (headerblurb, fp);
es_fclose (fp);
}
fp = fopen (fname, "a+");
fp = es_fopen (fname, "a+");
if (!fp)
{
err = gpg_error_from_syserror ();
@ -718,22 +719,22 @@ agent_marktrusted (ctrl_t ctrl, const char *name, const char *fpr, int flag)
}
/* Append the key. */
fputs ("\n# ", fp);
es_fputs ("\n# ", fp);
xfree (nameformatted);
nameformatted = reformat_name (name, "\n# ");
if (!nameformatted || strchr (name, '\n'))
{
/* Note that there should never be a LF in NAME but we better
play safe and print a sanitized version in this case. */
print_sanitized_string (fp, name, 0);
es_write_sanitized (fp, name, strlen (name), NULL, NULL);
}
else
fputs (nameformatted, fp);
fprintf (fp, "\n%s%s %c\n", yes_i_trust?"":"!", fprformatted, flag);
if (ferror (fp))
es_fputs (nameformatted, fp);
es_fprintf (fp, "\n%s%s %c\n", yes_i_trust?"":"!", fprformatted, flag);
if (es_ferror (fp))
err = gpg_error_from_syserror ();
if (fclose (fp))
if (es_fclose (fp))
err = gpg_error_from_syserror ();
agent_reload_trustlist ();