~ubuntu-branches/ubuntu/karmic/gnupg2/karmic-updates

« back to all changes in this revision

Viewing changes to common/maperror.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* maperror.c - Error mapping
2
 
 *      Copyright (C) 2001, 2002 Free Software Foundation, Inc.
3
 
 *
4
 
 * This file is part of GnuPG.
5
 
 *
6
 
 * GnuPG is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
9
 
 * (at your option) any later version.
10
 
 *
11
 
 * GnuPG is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19
 
 */
20
 
 
21
 
#include <config.h>
22
 
#include <errno.h>
23
 
#include <stdio.h>
24
 
#include <stdlib.h>
25
 
#include <string.h>
26
 
#include <ctype.h>
27
 
#include <unistd.h>
28
 
 
29
 
#include <assuan.h>
30
 
 
31
 
#include "util.h"
32
 
#include "errors.h"
33
 
 
34
 
 
35
 
/* Map Assuan error code ERR to an GPG_ERR_ code.  We need to
36
 
   distinguish between genuine (and legacy) Assuan error codes and
37
 
   application error codes shared with all GnuPG modules.  The rule is
38
 
   simple: All errors with a gpg_err_source of UNKNOWN are genuine
39
 
   Assuan codes all others are passed verbatim through. */
40
 
gpg_error_t
41
 
map_assuan_err_with_source (int source, int err)
42
 
{
43
 
  gpg_err_code_t ec;
44
 
 
45
 
  if (gpg_err_source (err))
46
 
    return err;
47
 
 
48
 
  switch (err)
49
 
    {
50
 
    case -1:                     ec = GPG_ERR_EOF; break;
51
 
    case 0:                      ec = 0; break;
52
 
 
53
 
    case ASSUAN_Canceled:        ec = GPG_ERR_CANCELED; break;
54
 
    case ASSUAN_Invalid_Index:   ec = GPG_ERR_INV_INDEX; break;
55
 
 
56
 
    case ASSUAN_Not_Implemented: ec = GPG_ERR_NOT_IMPLEMENTED; break;
57
 
    case ASSUAN_Server_Fault:    ec = GPG_ERR_ASSUAN_SERVER_FAULT; break;
58
 
    case ASSUAN_No_Public_Key:   ec = GPG_ERR_NO_PUBKEY; break;
59
 
    case ASSUAN_No_Secret_Key:   ec = GPG_ERR_NO_SECKEY; break;
60
 
 
61
 
    case ASSUAN_Cert_Revoked:    ec = GPG_ERR_CERT_REVOKED; break;
62
 
    case ASSUAN_No_CRL_For_Cert: ec = GPG_ERR_NO_CRL_KNOWN; break;       
63
 
    case ASSUAN_CRL_Too_Old:     ec = GPG_ERR_CRL_TOO_OLD; break;        
64
 
 
65
 
    case ASSUAN_Not_Trusted:     ec = GPG_ERR_NOT_TRUSTED; break;
66
 
 
67
 
    case ASSUAN_Card_Error:      ec = GPG_ERR_CARD; break;
68
 
    case ASSUAN_Invalid_Card:    ec = GPG_ERR_INV_CARD; break;
69
 
    case ASSUAN_No_PKCS15_App:   ec = GPG_ERR_NO_PKCS15_APP; break;
70
 
    case ASSUAN_Card_Not_Present: ec= GPG_ERR_CARD_NOT_PRESENT; break;
71
 
    case ASSUAN_Not_Confirmed:   ec = GPG_ERR_NOT_CONFIRMED; break;
72
 
    case ASSUAN_Invalid_Id:      ec = GPG_ERR_INV_ID; break;
73
 
 
74
 
    case ASSUAN_Locale_Problem:  ec = GPG_ERR_LOCALE_PROBLEM; break;
75
 
 
76
 
    default:
77
 
      ec = err < 100? GPG_ERR_ASSUAN_SERVER_FAULT : GPG_ERR_ASSUAN;
78
 
      break;
79
 
    }
80
 
  return gpg_err_make (source, ec);
81
 
}
82
 
 
83
 
/* Map GPG_xERR_xx error codes to Assuan status codes */
84
 
int
85
 
map_to_assuan_status (int rc)
86
 
{
87
 
  gpg_err_code_t   ec = gpg_err_code (rc);
88
 
  gpg_err_source_t es = gpg_err_source (rc);
89
 
 
90
 
  if (!rc)
91
 
    return 0;
92
 
  if (!es)
93
 
    {
94
 
      es = GPG_ERR_SOURCE_USER_4; /*  This should not happen, but we
95
 
                                      need to make sure to pass a new
96
 
                                      Assuan errorcode along. */
97
 
      log_debug ("map_to_assuan_status called with no error source\n");
98
 
    }
99
 
 
100
 
  if (ec == -1)
101
 
    ec = GPG_ERR_NO_DATA;  /* That used to be ASSUAN_No_Data_Available. */
102
 
 
103
 
  return gpg_err_make (es, ec);
104
 
}