summaryrefslogtreecommitdiffstats
path: root/sm
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2020-10-20 11:52:16 +0200
committerWerner Koch <wk@gnupg.org>2020-10-20 12:15:56 +0200
commit390497ea115e1aca93feec297a5bd6ae7b1ba6dd (patch)
tree675448ff809e3f333bba4918e4787eacda7f8190 /sm
parentReplace all calls to access by gnupg_access (diff)
downloadgnupg2-390497ea115e1aca93feec297a5bd6ae7b1ba6dd.tar.xz
gnupg2-390497ea115e1aca93feec297a5bd6ae7b1ba6dd.zip
Replace most of the remaining stdio calls by estream calls.
-- We need to use es_fopen on Windows to cope with non-ascii file names. This is quite a large but fortunately straightforward change. At a very few places we keep using stdio (for example due to the use of popen). GnuPG-bug-id: 5098 Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'sm')
-rw-r--r--sm/certchain.c22
-rw-r--r--sm/keydb.c18
-rw-r--r--sm/qualified.c14
3 files changed, 28 insertions, 26 deletions
diff --git a/sm/certchain.c b/sm/certchain.c
index d4047fd53..7aa7c1af3 100644
--- a/sm/certchain.c
+++ b/sm/certchain.c
@@ -308,7 +308,7 @@ check_cert_policy (ksba_cert_t cert, int listmode, estream_t fplist)
{
gpg_error_t err;
char *policies;
- FILE *fp;
+ estream_t fp;
int any_critical;
err = ksba_cert_get_cert_policies (cert, &policies);
@@ -340,7 +340,7 @@ check_cert_policy (ksba_cert_t cert, int listmode, estream_t fplist)
return 0;
}
- fp = fopen (opt.policy_file, "r");
+ fp = es_fopen (opt.policy_file, "r");
if (!fp)
{
if (opt.verbose || errno != ENOENT)
@@ -369,14 +369,14 @@ check_cert_policy (ksba_cert_t cert, int listmode, estream_t fplist)
/* read line */
do
{
- if (!fgets (line, DIM(line)-1, fp) )
+ if (!es_fgets (line, DIM(line)-1, fp) )
{
- gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
+ gpg_error_t tmperr = gpg_error_from_syserror ();
xfree (policies);
- if (feof (fp))
+ if (es_feof (fp))
{
- fclose (fp);
+ es_fclose (fp);
/* With no critical policies this is only a warning */
if (!any_critical)
{
@@ -388,16 +388,16 @@ check_cert_policy (ksba_cert_t cert, int listmode, estream_t fplist)
_("certificate policy not allowed"));
return gpg_error (GPG_ERR_NO_POLICY_MATCH);
}
- fclose (fp);
+ es_fclose (fp);
return tmperr;
}
if (!*line || line[strlen(line)-1] != '\n')
{
/* eat until end of line */
- while ( (c=getc (fp)) != EOF && c != '\n')
+ while ((c = es_getc (fp)) != EOF && c != '\n')
;
- fclose (fp);
+ es_fclose (fp);
xfree (policies);
return gpg_error (*line? GPG_ERR_LINE_TOO_LONG
: GPG_ERR_INCOMPLETE_LINE);
@@ -417,7 +417,7 @@ check_cert_policy (ksba_cert_t cert, int listmode, estream_t fplist)
p = strpbrk (allowed, " :\n");
if (!*p || p == allowed)
{
- fclose (fp);
+ es_fclose (fp);
xfree (policies);
return gpg_error (GPG_ERR_CONFIGURATION);
}
@@ -430,7 +430,7 @@ check_cert_policy (ksba_cert_t cert, int listmode, estream_t fplist)
if (p[strlen (allowed)] != ':')
continue; /* The length does not match. */
/* Yep - it does match so return okay. */
- fclose (fp);
+ es_fclose (fp);
xfree (policies);
return 0;
}
diff --git a/sm/keydb.c b/sm/keydb.c
index af8bf8629..875189ea6 100644
--- a/sm/keydb.c
+++ b/sm/keydb.c
@@ -208,7 +208,7 @@ maybe_create_keybox (char *filename, int force, int *r_created)
{
gpg_err_code_t ec;
dotlock_t lockhd = NULL;
- FILE *fp;
+ estream_t fp;
int rc;
mode_t oldmask;
char *last_slash_in_filename;
@@ -299,7 +299,7 @@ maybe_create_keybox (char *filename, int force, int *r_created)
/* The file does not yet exist, create it now. */
oldmask = umask (077);
- fp = fopen (filename, "wb");
+ fp = es_fopen (filename, "wb");
if (!fp)
{
rc = gpg_error_from_syserror ();
@@ -313,10 +313,10 @@ maybe_create_keybox (char *filename, int force, int *r_created)
/* Make sure that at least one record is in a new keybox file, so
that the detection magic for OpenPGP keyboxes works the next time
it is used. */
- rc = _keybox_write_header_blob (fp, NULL, 0);
+ rc = _keybox_write_header_blob (fp, 0);
if (rc)
{
- fclose (fp);
+ es_fclose (fp);
log_error (_("error creating keybox '%s': %s\n"),
filename, gpg_strerror (rc));
goto leave;
@@ -327,7 +327,7 @@ maybe_create_keybox (char *filename, int force, int *r_created)
if (r_created)
*r_created = 1;
- fclose (fp);
+ es_fclose (fp);
rc = 0;
leave:
@@ -394,14 +394,15 @@ keydb_add_resource (ctrl_t ctrl, const char *url, int force, int *auto_created)
/* see whether we can determine the filetype */
if (rt == KEYDB_RESOURCE_TYPE_NONE)
{
- FILE *fp = fopen( filename, "rb" );
+ estream_t fp;
+ fp = es_fopen( filename, "rb" );
if (fp)
{
u32 magic;
/* FIXME: check for the keybox magic */
- if (fread (&magic, 4, 1, fp) == 1 )
+ if (es_fread (&magic, 4, 1, fp) == 1 )
{
if (magic == 0x13579ace || magic == 0xce9a5713)
; /* GDBM magic - no more support */
@@ -410,7 +411,8 @@ keydb_add_resource (ctrl_t ctrl, const char *url, int force, int *auto_created)
}
else /* maybe empty: assume keybox */
rt = KEYDB_RESOURCE_TYPE_KEYBOX;
- fclose (fp);
+
+ es_fclose (fp);
}
else /* no file yet: create keybox */
rt = KEYDB_RESOURCE_TYPE_KEYBOX;
diff --git a/sm/qualified.c b/sm/qualified.c
index a1d6fe9bf..4d8dfccab 100644
--- a/sm/qualified.c
+++ b/sm/qualified.c
@@ -34,7 +34,7 @@
NULL indicates that this module has been initialized and if the
LISTFP is also NULL, no list of qualified signatures exists. */
static char *listname;
-static FILE *listfp;
+static estream_t listfp;
/* Read the trustlist and return entry by entry. KEY must point to a
@@ -58,7 +58,7 @@ read_list (char *key, char *country, int *lnr)
if (!listname)
{
listname = make_filename (gnupg_sysconfdir (), "qualified.txt", NULL);
- listfp = fopen (listname, "r");
+ listfp = es_fopen (listname, "r");
if (!listfp && errno != ENOENT)
{
err = gpg_error_from_syserror ();
@@ -72,9 +72,9 @@ read_list (char *key, char *country, int *lnr)
do
{
- if (!fgets (line, DIM(line)-1, listfp) )
+ if (!es_fgets (line, DIM(line)-1, listfp) )
{
- if (feof (listfp))
+ if (es_feof (listfp))
return gpg_error (GPG_ERR_EOF);
return gpg_error_from_syserror ();
}
@@ -82,7 +82,7 @@ read_list (char *key, char *country, int *lnr)
if (!*line || line[strlen(line)-1] != '\n')
{
/* Eat until end of line. */
- while ( (c=getc (listfp)) != EOF && c != '\n')
+ while ((c = es_getc (listfp)) != EOF && c != '\n')
;
return gpg_error (*line? GPG_ERR_LINE_TOO_LONG
: GPG_ERR_INCOMPLETE_LINE);
@@ -162,8 +162,8 @@ gpgsm_is_in_qualified_list (ctrl_t ctrl, ksba_cert_t cert, char *country)
if (listfp)
{
/* W32ce has no rewind, thus we use the equivalent code. */
- fseek (listfp, 0, SEEK_SET);
- clearerr (listfp);
+ es_fseek (listfp, 0, SEEK_SET);
+ es_clearerr (listfp);
}
while (!(err = read_list (key, mycountry, &lnr)))
{