2001-11-24 18:43:43 +01:00
|
|
|
/* maperror.c - Error mapping
|
2002-01-10 20:46:20 +01:00
|
|
|
* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
|
2001-11-24 18:43:43 +01:00
|
|
|
*
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <ksba.h>
|
2003-04-29 12:39:22 +02:00
|
|
|
#include <assuan.h>
|
2001-11-24 18:43:43 +01:00
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
#include "errors.h"
|
|
|
|
|
|
|
|
/* Note: we might want to wrap this in a macro to get our hands on
|
2002-05-21 10:29:17 +02:00
|
|
|
the line and file where the error occured */
|
2001-11-24 18:43:43 +01:00
|
|
|
int
|
|
|
|
map_ksba_err (int err)
|
|
|
|
{
|
|
|
|
switch (err)
|
|
|
|
{
|
|
|
|
case -1:
|
2002-05-21 10:29:17 +02:00
|
|
|
case 0:
|
2001-11-24 18:43:43 +01:00
|
|
|
break;
|
2001-12-06 21:47:30 +01:00
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
case KSBA_Out_Of_Core: err = GPG_ERR_ENOMEM; break;
|
|
|
|
case KSBA_Invalid_Value: err = GPG_ERR_INV_VALUE; break;
|
|
|
|
case KSBA_Not_Implemented: err = GPG_ERR_NOT_IMPLEMENTED; break;
|
|
|
|
case KSBA_Conflict: err = GPG_ERR_CONFLICT; break;
|
|
|
|
case KSBA_Read_Error: err = GPG_ERR_EIO; break;
|
|
|
|
case KSBA_Write_Error: err = GPG_ERR_EIO; break;
|
|
|
|
case KSBA_No_Data: err = GPG_ERR_NO_DATA; break;
|
|
|
|
case KSBA_Bug: err = GPG_ERR_BUG; break;
|
|
|
|
case KSBA_Unsupported_Algorithm: err = GPG_ERR_UNSUPPORTED_ALGORITHM; break;
|
|
|
|
case KSBA_Invalid_Index: err = GPG_ERR_INV_INDEX; break;
|
|
|
|
case KSBA_Invalid_Sexp: err = GPG_ERR_INV_SEXP; break;
|
|
|
|
case KSBA_Unknown_Sexp: err = GPG_ERR_UNKNOWN_SEXP; break;
|
2001-11-24 18:43:43 +01:00
|
|
|
|
|
|
|
default:
|
2003-06-05 09:14:21 +02:00
|
|
|
err = GPG_ERR_GENERAL;
|
2001-11-24 18:43:43 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
map_gcry_err (int err)
|
|
|
|
{
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
map_kbx_err (int err)
|
|
|
|
{
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
/* Map Assuan error code ERR to an GPG_ERR_ code. We need to
|
|
|
|
distinguish between genuine (and legacy) Assuan error codes and
|
|
|
|
application error codes shared with all GnuPG modules. The rule is
|
|
|
|
simple: All errors with a gpg_err_source of UNKNOWN are genuine
|
|
|
|
Assuan codes all others are passed verbatim through. */
|
|
|
|
gpg_error_t
|
2001-12-06 00:45:42 +01:00
|
|
|
map_assuan_err (int err)
|
|
|
|
{
|
2003-06-05 09:14:21 +02:00
|
|
|
gpg_err_code_t ec;
|
|
|
|
|
|
|
|
if (gpg_err_source (err))
|
|
|
|
return err;
|
|
|
|
|
2001-12-06 00:45:42 +01:00
|
|
|
switch (err)
|
|
|
|
{
|
2003-06-05 09:14:21 +02:00
|
|
|
case -1: ec = GPG_ERR_EOF; break;
|
|
|
|
case 0: ec = 0; break;
|
2001-12-06 00:45:42 +01:00
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
case ASSUAN_Canceled: ec = GPG_ERR_CANCELED; break;
|
|
|
|
case ASSUAN_Invalid_Index: ec = GPG_ERR_INV_INDEX; break;
|
2002-01-19 19:20:45 +01:00
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
case ASSUAN_Not_Implemented: ec = GPG_ERR_NOT_IMPLEMENTED; break;
|
|
|
|
case ASSUAN_Server_Fault: ec = GPG_ERR_ASSUAN_SERVER_FAULT; break;
|
|
|
|
case ASSUAN_No_Public_Key: ec = GPG_ERR_NO_PUBKEY; break;
|
|
|
|
case ASSUAN_No_Secret_Key: ec = GPG_ERR_NO_SECKEY; break;
|
2001-12-06 00:45:42 +01:00
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
case ASSUAN_Cert_Revoked: ec = GPG_ERR_CERT_REVOKED; break;
|
|
|
|
case ASSUAN_No_CRL_For_Cert: ec = GPG_ERR_NO_CRL_KNOWN; break;
|
|
|
|
case ASSUAN_CRL_Too_Old: ec = GPG_ERR_CRL_TOO_OLD; break;
|
2002-01-11 18:07:15 +01:00
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
case ASSUAN_Not_Trusted: ec = GPG_ERR_NOT_TRUSTED; break;
|
2002-01-15 14:02:13 +01:00
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
case ASSUAN_Card_Error: ec = GPG_ERR_CARD; break;
|
|
|
|
case ASSUAN_Invalid_Card: ec = GPG_ERR_INV_CARD; break;
|
|
|
|
case ASSUAN_No_PKCS15_App: ec = GPG_ERR_NO_PKCS15_APP; break;
|
|
|
|
case ASSUAN_Card_Not_Present: ec= GPG_ERR_CARD_NOT_PRESENT; break;
|
|
|
|
case ASSUAN_Not_Confirmed: ec = GPG_ERR_NOT_CONFIRMED; break;
|
|
|
|
case ASSUAN_Invalid_Id: ec = GPG_ERR_INV_ID; break;
|
2002-01-15 14:02:13 +01:00
|
|
|
|
2001-12-06 00:45:42 +01:00
|
|
|
default:
|
2003-06-05 09:14:21 +02:00
|
|
|
ec = err < 100? GPG_ERR_ASSUAN_SERVER_FAULT : GPG_ERR_ASSUAN;
|
2001-12-06 00:45:42 +01:00
|
|
|
break;
|
|
|
|
}
|
2003-06-05 09:14:21 +02:00
|
|
|
return gpg_err_make (GPG_ERR_SOURCE_UNKNOWN, ec);
|
2001-12-06 00:45:42 +01:00
|
|
|
}
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
/* Map GPG_xERR_xx error codes to Assuan status codes */
|
2002-01-10 20:46:20 +01:00
|
|
|
int
|
|
|
|
map_to_assuan_status (int rc)
|
|
|
|
{
|
2003-06-05 09:14:21 +02:00
|
|
|
gpg_err_code_t ec = gpg_err_code (rc);
|
|
|
|
gpg_err_source_t es = gpg_err_source (rc);
|
2002-01-10 20:46:20 +01:00
|
|
|
|
2003-06-27 22:53:09 +02:00
|
|
|
if (!rc)
|
|
|
|
return 0;
|
2003-06-05 09:14:21 +02:00
|
|
|
if (!es)
|
|
|
|
{
|
|
|
|
es = GPG_ERR_SOURCE_USER_4; /* This should not happen, but we
|
|
|
|
need to make sure to pass a new
|
|
|
|
Assuan errorcode along. */
|
|
|
|
log_debug ("map_to_assuan_status called with no error source\n");
|
|
|
|
}
|
2002-02-18 21:46:09 +01:00
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
if (ec == -1)
|
|
|
|
ec = GPG_ERR_NO_DATA; /* That used to be ASSUAN_No_Data_Available. */
|
2002-01-10 20:46:20 +01:00
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
return gpg_err_make (es, ec);
|
2002-01-10 20:46:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-06-27 22:53:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|