1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

Take advantage of newer gpg-error features.

This commit is contained in:
Werner Koch 2006-09-14 16:50:33 +00:00
parent 9577dd45ab
commit 03d3322e5f
55 changed files with 297 additions and 260 deletions

View file

@ -1,3 +1,8 @@
2006-09-14 Werner Koch <wk@g10code.com>
Replaced all call gpg_error_from_errno(errno) by
gpg_error_from_syserror().
2006-09-13 Werner Koch <wk@g10code.com>
* gpg.c (main): Made --require-cross-certification the default.

View file

@ -104,7 +104,7 @@ start_agent (void)
if (fflush (NULL))
{
gpg_error_t tmperr = gpg_error_from_errno (errno);
gpg_error_t tmperr = gpg_error_from_syserror ();
log_error ("error flushing pending output: %s\n", strerror (errno));
return tmperr;
}
@ -191,7 +191,7 @@ start_agent (void)
char *optstr;
if (asprintf (&optstr, "OPTION display=%s",
opt.display ? opt.display : dft_display) < 0)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
rc = assuan_transact (agent_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
NULL);
free (optstr);
@ -209,7 +209,7 @@ start_agent (void)
char *optstr;
if (asprintf (&optstr, "OPTION ttyname=%s",
opt.ttyname ? opt.ttyname : dft_ttyname) < 0)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
rc = assuan_transact (agent_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
NULL);
free (optstr);
@ -222,7 +222,7 @@ start_agent (void)
char *optstr;
if (asprintf (&optstr, "OPTION ttytype=%s",
opt.ttyname ? opt.ttytype : dft_ttytype) < 0)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
rc = assuan_transact (agent_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
NULL);
free (optstr);
@ -235,7 +235,7 @@ start_agent (void)
{
old_lc = strdup (old_lc);
if (!old_lc)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
}
dft_lc = setlocale (LC_CTYPE, "");
@ -245,7 +245,7 @@ start_agent (void)
char *optstr;
if (asprintf (&optstr, "OPTION lc-ctype=%s",
opt.lc_ctype ? opt.lc_ctype : dft_lc) < 0)
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
else
{
rc = assuan_transact (agent_ctx, optstr, NULL, NULL, NULL, NULL, NULL,
@ -268,7 +268,7 @@ start_agent (void)
{
old_lc = strdup (old_lc);
if (!old_lc)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
}
dft_lc = setlocale (LC_MESSAGES, "");
#endif
@ -277,7 +277,7 @@ start_agent (void)
char *optstr;
if (asprintf (&optstr, "OPTION lc-messages=%s",
opt.lc_messages ? opt.lc_messages : dft_lc) < 0)
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
else
{
rc = assuan_transact (agent_ctx, optstr, NULL, NULL, NULL, NULL, NULL,

View file

@ -58,7 +58,7 @@ dearmor_file( const char *fname )
errno = EPERM;
}
if (!inp) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("can't open `%s': %s\n"), fname? fname: "[stdin]",
strerror(errno) );
goto leave;
@ -107,7 +107,7 @@ enarmor_file( const char *fname )
errno = EPERM;
}
if (!inp) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("can't open `%s': %s\n"), fname? fname: "[stdin]",
strerror(errno) );
goto leave;

View file

@ -66,7 +66,7 @@ decrypt_message( const char *filename )
errno = EPERM;
}
if( !fp ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error (_("can't open `%s': %s\n"), print_fname_stdin(filename),
gpg_strerror (rc));
return rc;

View file

@ -189,7 +189,7 @@ encode_simple( const char *filename, int mode, int use_seskey )
errno = EPERM;
}
if( !inp ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("can't open `%s': %s\n"), filename? filename: "[stdin]",
strerror(errno) );
return rc;
@ -481,7 +481,7 @@ encode_crypt( const char *filename, STRLIST remusr, int use_symkey )
errno = EPERM;
}
if( !inp ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("can't open `%s': %s\n"),
filename? filename: "[stdin]",
gpg_strerror (rc) );

View file

@ -441,7 +441,7 @@ int exec_write(struct exec_info **info,const char *program,
(*info)->tochild=fdopen(to[1],binary?"wb":"w");
if((*info)->tochild==NULL)
{
ret = gpg_error_from_errno (errno);
ret = gpg_error_from_syserror ();
close(to[1]);
goto fail;
}
@ -451,7 +451,7 @@ int exec_write(struct exec_info **info,const char *program,
(*info)->fromchild=iobuf_fdopen(from[0],"r");
if((*info)->fromchild==NULL)
{
ret = gpg_error_from_errno (errno);
ret = gpg_error_from_syserror ();
close(from[0]);
goto fail;
}
@ -476,7 +476,7 @@ int exec_write(struct exec_info **info,const char *program,
(*info)->tochild=fopen((*info)->tempfile_in,binary?"wb":"w");
if((*info)->tochild==NULL)
{
ret = gpg_error_from_errno (errno);
ret = gpg_error_from_syserror ();
log_error(_("can't create `%s': %s\n"),
(*info)->tempfile_in,strerror(errno));
goto fail;
@ -550,7 +550,7 @@ int exec_read(struct exec_info *info)
}
if(info->fromchild==NULL)
{
ret = gpg_error_from_errno (errno);
ret = gpg_error_from_syserror ();
log_error(_("unable to read external program response: %s\n"),
strerror(errno));
goto fail;

View file

@ -1834,7 +1834,7 @@ main (int argc, char **argv )
opt.rfc2440_text=1;
opt.def_sig_expire="0";
opt.def_cert_expire="0";
opt.require_cross_cert = 1;
opt.flags.require_cross_cert = 1;
set_homedir ( default_homedir () );
/* Check whether we have a config file on the command line. */

View file

@ -112,7 +112,7 @@ maybe_create_keyring (char *filename, int force)
}
if (access (filename, F_OK))
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
*last_slash_in_filename = DIRSEP_C;
goto leave;
}
@ -166,7 +166,7 @@ maybe_create_keyring (char *filename, int force)
umask (oldmask);
if (!iobuf)
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error ( _("error creating keyring `%s': %s\n"),
filename, strerror(errno));
goto leave;

View file

@ -3732,7 +3732,7 @@ gen_card_key_with_backup (int algo, int keyno, int is_primary,
umask (oldmask);
if (!fp)
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error (_("can't create backup file `%s': %s\n"),
fname, strerror(errno) );
xfree (fname);

View file

@ -661,7 +661,7 @@ prepare_search (KEYRING_HANDLE hd)
hd->current.iobuf = iobuf_open (hd->current.kr->fname);
if (!hd->current.iobuf)
{
hd->current.error = gpg_error_from_errno (errno);
hd->current.error = gpg_error_from_syserror ();
log_error(_("can't open `%s'\n"), hd->current.kr->fname );
return hd->current.error;
}
@ -1200,7 +1200,7 @@ create_tmp_file (const char *template,
umask(oldmask);
if (!*r_fp)
{
int rc = gpg_error_from_errno (errno);
int rc = gpg_error_from_syserror ();
log_error(_("can't create `%s': %s\n"), tmpfname, strerror(errno) );
xfree (tmpfname);
xfree (bakfname);
@ -1232,7 +1232,7 @@ rename_tmp_file (const char *bakfname, const char *tmpfname,
#endif
if (rename (fname, bakfname) )
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error ("renaming `%s' to `%s' failed: %s\n",
fname, bakfname, strerror(errno) );
return rc;
@ -1247,7 +1247,7 @@ rename_tmp_file (const char *bakfname, const char *tmpfname,
unregister_secured_file (fname);
if (rename (tmpfname, fname) )
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error (_("renaming `%s' to `%s' failed: %s\n"),
tmpfname, fname, strerror(errno) );
register_secured_file (fname);
@ -1317,7 +1317,7 @@ write_keyblock (IOBUF fp, KBNODE keyblock)
iobuf_put (fp, 0); /* unused */
if (iobuf_put (fp, cacheval))
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error ("writing sigcache packet failed\n");
return rc;
}
@ -1362,7 +1362,7 @@ keyring_rebuild_cache (void *token,int noisy)
{
if (iobuf_close (tmpfp))
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error ("error closing `%s': %s\n",
tmpfilename, strerror (errno));
goto leave;
@ -1442,7 +1442,7 @@ keyring_rebuild_cache (void *token,int noisy)
{
if (iobuf_close (tmpfp))
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error ("error closing `%s': %s\n",
tmpfilename, strerror (errno));
goto leave;
@ -1486,7 +1486,7 @@ do_copy (int mode, const char *fname, KBNODE root, int secret,
/* Open the source file. Because we do a rename, we have to check the
permissions of the file */
if (access (fname, W_OK))
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
fp = iobuf_open (fname);
if (mode == 1 && !fp && errno == ENOENT) {
@ -1504,7 +1504,7 @@ do_copy (int mode, const char *fname, KBNODE root, int secret,
umask(oldmask);
if( !newfp )
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error (_("can't create `%s': %s\n"), fname, strerror(errno));
return rc;
}
@ -1521,7 +1521,7 @@ do_copy (int mode, const char *fname, KBNODE root, int secret,
}
}
if( iobuf_close(newfp) ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error ("%s: close failed: %s\n", fname, strerror(errno));
return rc;
}
@ -1530,7 +1530,7 @@ do_copy (int mode, const char *fname, KBNODE root, int secret,
if( !fp )
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("can't open `%s': %s\n"), fname, strerror(errno) );
goto leave;
}
@ -1613,12 +1613,12 @@ do_copy (int mode, const char *fname, KBNODE root, int secret,
/* close both files */
if( iobuf_close(fp) ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error("%s: close failed: %s\n", fname, strerror(errno) );
goto leave;
}
if( iobuf_close(newfp) ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error("%s: close failed: %s\n", tmpfname, strerror(errno) );
goto leave;
}

View file

@ -1406,7 +1406,7 @@ keyserver_spawn(enum ks_action action,STRLIST list,KEYDB_SEARCH_DESC *desc,
maxlen=1024;
if(iobuf_read_line(spawn->fromchild,&line,&buflen,&maxlen)==0)
{
ret = gpg_error_from_errno (errno);
ret = gpg_error_from_syserror ();
goto fail; /* i.e. EOF */
}

View file

@ -184,7 +184,7 @@ open_outfile( const char *iname, int mode, IOBUF *a )
if( iobuf_is_pipe_filename (iname) && !opt.outfile ) {
*a = iobuf_create(NULL);
if( !*a ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("can't open `%s': %s\n"), "[stdout]", strerror(errno) );
}
else if( opt.verbose )
@ -261,7 +261,7 @@ open_outfile( const char *iname, int mode, IOBUF *a )
*a = iobuf_create( name );
if( !*a )
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("can't create `%s': %s\n"), name, strerror(errno) );
}
else if( opt.verbose )

View file

@ -132,12 +132,12 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
else if (is_secured_filename (fname))
{
errno = EPERM;
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("error creating `%s': %s\n"), fname, strerror(errno) );
goto leave;
}
else if( !(fp = fopen(fname,"wb")) ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("error creating `%s': %s\n"), fname, strerror(errno) );
goto leave;
}
@ -187,7 +187,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
if( convert ) { /* text mode */
for( ; pt->len; pt->len-- ) {
if( (c = iobuf_get(pt->buf)) == -1 ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error ("problem reading source (%u bytes remaining)\n",
(unsigned)pt->len);
goto leave;
@ -210,7 +210,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
else if( putc( c, fp ) == EOF )
{
if (ferror (fp))
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
else
rc = gpg_error (GPG_ERR_EOF);
log_error ("error writing to `%s': %s\n",
@ -226,7 +226,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
int len = pt->len > 32768 ? 32768 : pt->len;
len = iobuf_read( pt->buf, buffer, len );
if( len == -1 ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error ("problem reading source (%u bytes remaining)\n",
(unsigned)pt->len);
xfree( buffer );
@ -246,7 +246,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
}
else if( fwrite( buffer, 1, len, fp ) != len )
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error ("error writing to `%s': %s\n",
fname, strerror(errno) );
xfree( buffer );
@ -279,7 +279,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
else if( putc( c, fp ) == EOF )
{
if ( ferror (fp ) )
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
else
rc = gpg_error (GPG_ERR_EOF);
log_error("error writing to `%s': %s\n",
@ -317,7 +317,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
goto leave;
}
else if( fwrite( buffer, 1, len, fp ) != len ) {
rc = (errno? gpg_error_from_errno (errno)
rc = (errno? gpg_error_from_syserror ()
: gpg_error (GPG_ERR_INTERNAL));
log_error ("error writing to `%s': %s\n",
fname, strerror(errno) );
@ -345,7 +345,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
}
else if( putc( c, fp ) == EOF )
{
rc = (errno? gpg_error_from_errno (errno)
rc = (errno? gpg_error_from_syserror ()
: gpg_error (GPG_ERR_INTERNAL));
log_error ("error writing to `%s': %s\n",
fname, strerror(errno) );
@ -385,7 +385,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
}
if( fp && fp != stdout && fclose(fp) ) {
rc = (errno? gpg_error_from_errno (errno)
rc = (errno? gpg_error_from_syserror ()
: gpg_error (GPG_ERR_INTERNAL));
log_error ("error closing `%s': %s\n", fname, strerror(errno) );
fp = NULL;
@ -487,7 +487,7 @@ ask_for_detached_datafile (gcry_md_hd_t md, gcry_md_hd_t md2,
}
else if( !fp )
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("can't open `%s': %s\n"), answer, strerror(errno));
goto leave;
}
@ -544,7 +544,7 @@ hash_datafiles( gcry_md_hd_t md, gcry_md_hd_t md2, STRLIST files,
errno = EPERM;
}
if( !fp ) {
int rc = gpg_error_from_errno (errno);
int rc = gpg_error_from_syserror ();
log_error(_("can't open signed data `%s'\n"),
print_fname_stdin(sl->d));
return rc;

View file

@ -808,7 +808,7 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
}
if( !inp )
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error (_("can't open `%s': %s\n"), fname? fname: "[stdin]",
strerror(errno) );
goto leave;
@ -826,7 +826,7 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
out = iobuf_create( outfile );
if( !out )
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("can't create `%s': %s\n"), outfile, strerror(errno) );
goto leave;
}
@ -1003,7 +1003,7 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
}
if( !inp )
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("can't open `%s': %s\n"),
sl->d,strerror(errno));
goto leave;
@ -1116,7 +1116,7 @@ clearsign_file( const char *fname, STRLIST locusr, const char *outfile )
errno = EPERM;
}
if( !inp ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error (_("can't open `%s': %s\n"),
fname? fname: "[stdin]", strerror(errno) );
goto leave;
@ -1132,7 +1132,7 @@ clearsign_file( const char *fname, STRLIST locusr, const char *outfile )
out = iobuf_create( outfile );
if( !out )
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("can't create `%s': %s\n"), outfile, strerror(errno) );
goto leave;
}
@ -1268,7 +1268,7 @@ sign_symencrypt_file (const char *fname, STRLIST locusr)
errno = EPERM;
}
if( !inp ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error (_("can't open `%s': %s\n"),
fname? fname: "[stdin]", strerror(errno) );
goto leave;

View file

@ -126,14 +126,14 @@ write_cache_item( CACHE_CTRL r )
int n;
if( lseek( db_fd, r->recno * TRUST_RECORD_LEN, SEEK_SET ) == -1 ) {
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
log_error(_("trustdb rec %lu: lseek failed: %s\n"),
r->recno, strerror(errno) );
return err;
}
n = write( db_fd, r->data, TRUST_RECORD_LEN);
if( n != TRUST_RECORD_LEN ) {
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
log_error(_("trustdb rec %lu: write failed (n=%d): %s\n"),
r->recno, n, strerror(errno) );
return err;
@ -1162,7 +1162,7 @@ tdbio_read_record( ulong recnum, TRUSTREC *rec, int expected )
buf = get_record_from_cache( recnum );
if( !buf ) {
if( lseek( db_fd, recnum * TRUST_RECORD_LEN, SEEK_SET ) == -1 ) {
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
log_error(_("trustdb: lseek failed: %s\n"), strerror(errno) );
return err;
}
@ -1171,7 +1171,7 @@ tdbio_read_record( ulong recnum, TRUSTREC *rec, int expected )
return -1; /* eof */
}
else if( n != TRUST_RECORD_LEN ) {
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
log_error(_("trustdb: read failed (n=%d): %s\n"), n,
strerror(errno) );
return err;
@ -1435,14 +1435,14 @@ tdbio_new_recnum()
rec.recnum = recnum;
rc = 0;
if( lseek( db_fd, recnum * TRUST_RECORD_LEN, SEEK_SET ) == -1 ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("trustdb rec %lu: lseek failed: %s\n"),
recnum, strerror(errno) );
}
else {
int n = write( db_fd, &rec, TRUST_RECORD_LEN);
if( n != TRUST_RECORD_LEN ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("trustdb rec %lu: write failed (n=%d): %s\n"),
recnum, n, strerror(errno) );
}

View file

@ -98,7 +98,7 @@ verify_signatures( int nfiles, char **files )
errno = EPERM;
}
if( !fp ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("can't open `%s': %s\n"),
print_fname_stdin(sigfile), strerror (errno));
return rc;
@ -154,7 +154,7 @@ verify_one_file( const char *name )
errno = EPERM;
}
if( !fp ) {
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
log_error(_("can't open `%s': %s\n"),
print_fname_stdin(name), strerror (errno));
print_file_status( STATUS_FILE_ERROR, name, 1 );