diff options
Diffstat (limited to 'sm')
-rw-r--r-- | sm/ChangeLog | 7 | ||||
-rw-r--r-- | sm/Makefile.am | 4 | ||||
-rw-r--r-- | sm/base64.c | 14 | ||||
-rw-r--r-- | sm/call-agent.c | 62 | ||||
-rw-r--r-- | sm/call-dirmngr.c | 25 | ||||
-rw-r--r-- | sm/certchain.c | 89 | ||||
-rw-r--r-- | sm/certcheck.c | 22 | ||||
-rw-r--r-- | sm/certlist.c | 32 | ||||
-rw-r--r-- | sm/certreqgen.c | 32 | ||||
-rw-r--r-- | sm/decrypt.c | 24 | ||||
-rw-r--r-- | sm/delete.c | 6 | ||||
-rw-r--r-- | sm/encrypt.c | 35 | ||||
-rw-r--r-- | sm/export.c | 5 | ||||
-rw-r--r-- | sm/fingerprint.c | 2 | ||||
-rw-r--r-- | sm/gpgsm.c | 45 | ||||
-rw-r--r-- | sm/gpgsm.h | 10 | ||||
-rw-r--r-- | sm/import.c | 14 | ||||
-rw-r--r-- | sm/keydb.c | 50 | ||||
-rw-r--r-- | sm/server.c | 51 | ||||
-rw-r--r-- | sm/sign.c | 29 | ||||
-rw-r--r-- | sm/verify.c | 22 |
21 files changed, 307 insertions, 273 deletions
diff --git a/sm/ChangeLog b/sm/ChangeLog index 18cf83995..24a95b103 100644 --- a/sm/ChangeLog +++ b/sm/ChangeLog @@ -1,3 +1,10 @@ +2003-06-03 Werner Koch <[email protected]> + + Changed all error codes in all files to the new libgpg-error scheme. + + * gpgsm.h: Include gpg-error.h . + * Makefile.am: Link with libgpg-error. + 2003-04-29 Werner Koch <[email protected]> * Makefile.am: Use libassuan. Don't override LDFLAGS anymore. diff --git a/sm/Makefile.am b/sm/Makefile.am index adbcb2cdb..4c215c61d 100644 --- a/sm/Makefile.am +++ b/sm/Makefile.am @@ -51,6 +51,4 @@ gpgsm_SOURCES = \ gpgsm_LDADD = ../jnlib/libjnlib.a ../kbx/libkeybox.a ../common/libcommon.a \ - $(LIBGCRYPT_LIBS) $(LIBASSUAN_LIBS) $(KSBA_LIBS) - - + $(LIBGCRYPT_LIBS) $(LIBASSUAN_LIBS) $(KSBA_LIBS) -lgpg-error
\ No newline at end of file diff --git a/sm/base64.c b/sm/base64.c index f70615e97..b3f9cc4c4 100644 --- a/sm/base64.c +++ b/sm/base64.c @@ -1,5 +1,5 @@ /* base64.c - * Copyright (C) 2001 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -482,7 +482,7 @@ base64_finish_write (struct writer_cb_parm_s *parm) fputs (parm->pem_name, fp); fputs ("-----\n", fp); } - return ferror (fp)? GNUPG_Write_Error : 0; + return ferror (fp)? gpg_error (gpg_err_code_from_errno (errno)) : 0; } @@ -504,13 +504,13 @@ gpgsm_create_reader (Base64Context *ctx, *r_reader = NULL; *ctx = xtrycalloc (1, sizeof **ctx); if (!*ctx) - return seterr (Out_Of_Core); + return OUT_OF_CORE (errno); r = ksba_reader_new (); if (!r) { xfree (*ctx); *ctx = NULL; - return seterr (Out_Of_Core); + return gpg_error (GPG_ERR_ENOMEM); } (*ctx)->u.rparm.fp = fp; @@ -569,13 +569,13 @@ gpgsm_create_writer (Base64Context *ctx, *r_writer = NULL; *ctx = xtrycalloc (1, sizeof **ctx); if (!*ctx) - return seterr (Out_Of_Core); + return OUT_OF_CORE (errno); w = ksba_writer_new (); if (!w) { xfree (*ctx); *ctx = NULL; - return seterr (Out_Of_Core); + return gpg_error (GPG_ERR_ENOMEM); } if (ctrl->create_pem || ctrl->create_base64) @@ -607,7 +607,7 @@ gpgsm_finish_writer (Base64Context ctx) struct writer_cb_parm_s *parm; if (!ctx) - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); parm = &ctx->u.wparm; if (parm->did_finish) return 0; /* already done */ diff --git a/sm/call-agent.c b/sm/call-agent.c index d518b2bc5..92098a7d8 100644 --- a/sm/call-agent.c +++ b/sm/call-agent.c @@ -1,5 +1,5 @@ /* call-agent.c - divert operations to the agent - * Copyright (C) 2001, 2002 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -30,9 +30,9 @@ #ifdef HAVE_LOCALE_H #include <locale.h> #endif +#include <assuan.h> #include "gpgsm.h" -#include "../assuan/assuan.h" #include "i18n.h" #include "keydb.h" /* fixme: Move this to import.c */ @@ -159,8 +159,9 @@ start_agent (void) if (fflush (NULL)) { + gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno)); log_error ("error flushing pending output: %s\n", strerror (errno)); - return seterr (Write_Error); + return tmperr; } if (!opt.agent_program || !*opt.agent_program) @@ -224,7 +225,7 @@ start_agent (void) if (rc) { log_error ("can't connect to the agent: %s\n", assuan_strerror (rc)); - return seterr (No_Agent); + return gpg_error (GPG_ERR_NO_AGENT); } agent_ctx = ctx; @@ -241,7 +242,7 @@ start_agent (void) char *optstr; if (asprintf (&optstr, "OPTION display=%s", opt.display ? opt.display : dft_display) < 0) - return GNUPG_Out_Of_Core; + return OUT_OF_CORE (errno); rc = assuan_transact (agent_ctx, optstr, NULL, NULL, NULL, NULL, NULL, NULL); free (optstr); @@ -259,7 +260,7 @@ start_agent (void) char *optstr; if (asprintf (&optstr, "OPTION ttyname=%s", opt.ttyname ? opt.ttyname : dft_ttyname) < 0) - return GNUPG_Out_Of_Core; + return OUT_OF_CORE (errno); rc = assuan_transact (agent_ctx, optstr, NULL, NULL, NULL, NULL, NULL, NULL); free (optstr); @@ -272,7 +273,7 @@ start_agent (void) char *optstr; if (asprintf (&optstr, "OPTION ttytype=%s", opt.ttyname ? opt.ttytype : dft_ttytype) < 0) - return GNUPG_Out_Of_Core; + return OUT_OF_CORE (errno); rc = assuan_transact (agent_ctx, optstr, NULL, NULL, NULL, NULL, NULL, NULL); free (optstr); @@ -285,7 +286,7 @@ start_agent (void) { old_lc = strdup (old_lc); if (!old_lc) - return GNUPG_Out_Of_Core; + return OUT_OF_CORE (errno); } dft_lc = setlocale (LC_CTYPE, ""); #endif @@ -294,7 +295,7 @@ start_agent (void) char *optstr; if (asprintf (&optstr, "OPTION lc-ctype=%s", opt.lc_ctype ? opt.lc_ctype : dft_lc) < 0) - rc = GNUPG_Out_Of_Core; + rc = OUT_OF_CORE (errno); else { rc = assuan_transact (agent_ctx, optstr, NULL, NULL, NULL, NULL, NULL, @@ -319,7 +320,7 @@ start_agent (void) { old_lc = strdup (old_lc); if (!old_lc) - return GNUPG_Out_Of_Core; + return OUT_OF_CORE (errno); } dft_lc = setlocale (LC_MESSAGES, ""); #endif @@ -328,7 +329,7 @@ start_agent (void) char *optstr; if (asprintf (&optstr, "OPTION lc-messages=%s", opt.lc_messages ? opt.lc_messages : dft_lc) < 0) - rc = GNUPG_Out_Of_Core; + rc = OUT_OF_CORE (errno); else { rc = assuan_transact (agent_ctx, optstr, NULL, NULL, NULL, NULL, NULL, @@ -381,7 +382,7 @@ gpgsm_agent_pksign (const char *keygrip, return rc; if (digestlen*2 + 50 > DIM(line)) - return seterr (General_Error); + return gpg_error (GPG_ERR_GENERAL); rc = assuan_transact (agent_ctx, "RESET", NULL, NULL, NULL, NULL, NULL, NULL); if (rc) @@ -414,10 +415,10 @@ gpgsm_agent_pksign (const char *keygrip, if (!gcry_sexp_canon_len (*r_buf, *r_buflen, NULL, NULL)) { xfree (*r_buf); *r_buf = NULL; - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); } - return *r_buf? 0 : GNUPG_Out_Of_Core; + return *r_buf? 0 : OUT_OF_CORE (errno); } @@ -454,12 +455,12 @@ gpgsm_agent_pkdecrypt (const char *keygrip, size_t ciphertextlen; if (!keygrip || strlen(keygrip) != 40 || !ciphertext || !r_buf || !r_buflen) - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); *r_buf = NULL; ciphertextlen = gcry_sexp_canon_len (ciphertext, 0, NULL, NULL); if (!ciphertextlen) - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); rc = start_agent (); if (rc) @@ -492,16 +493,17 @@ gpgsm_agent_pkdecrypt (const char *keygrip, put_membuf (&data, "", 1); /* make sure it is 0 terminated */ buf = get_membuf (&data, &len); if (!buf) - return seterr (Out_Of_Core); + return gpg_error (GPG_ERR_ENOMEM); /* FIXME: We would better a return a full S-exp and not just a part */ assert (len); len--; /* remove the terminating 0 */ n = strtoul (buf, &endp, 10); if (!n || *endp != ':') - return seterr (Invalid_Sexp); + return gpg_error (GPG_ERR_INVALID_SEXP); endp++; if (endp-buf+n > len) - return seterr (Invalid_Sexp); /* oops len does not match internal len*/ + return gpg_error (GPG_ERR_INVALID_SEXP); /* oops len does not + match internal len*/ memmove (buf, endp, n); *r_buflen = n; *r_buf = buf; @@ -550,7 +552,7 @@ gpgsm_agent_genkey (KsbaConstSexp keyparms, KsbaSexp *r_pubkey) gk_parm.sexp = keyparms; gk_parm.sexplen = gcry_sexp_canon_len (keyparms, 0, NULL, NULL); if (!gk_parm.sexplen) - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); rc = assuan_transact (agent_ctx, "GENKEY", membuf_data_cb, &data, inq_genkey_parms, &gk_parm, NULL, NULL); @@ -561,11 +563,11 @@ gpgsm_agent_genkey (KsbaConstSexp keyparms, KsbaSexp *r_pubkey) } buf = get_membuf (&data, &len); if (!buf) - return GNUPG_Out_Of_Core; + return gpg_error (GPG_ERR_ENOMEM); if (!gcry_sexp_canon_len (buf, len, NULL, NULL)) { xfree (buf); - return GNUPG_Invalid_Sexp; + return gpg_error (GPG_ERR_INVALID_SEXP); } *r_pubkey = buf; return 0; @@ -589,7 +591,7 @@ gpgsm_agent_istrusted (KsbaCert cert) if (!fpr) { log_error ("error getting the fingerprint\n"); - return seterr (General_Error); + return gpg_error (GPG_ERR_GENERAL); } snprintf (line, DIM(line)-1, "ISTRUSTED %s", fpr); @@ -616,14 +618,14 @@ gpgsm_agent_marktrusted (KsbaCert cert) if (!fpr) { log_error ("error getting the fingerprint\n"); - return seterr (General_Error); + return gpg_error (GPG_ERR_GENERAL); } dn = ksba_cert_get_issuer (cert, 0); if (!dn) { xfree (fpr); - return seterr (General_Error); + return gpg_error (GPG_ERR_GENERAL); } snprintf (line, DIM(line)-1, "MARKTRUSTED %s S %s", fpr, dn); line[DIM(line)-1] = 0; @@ -649,7 +651,7 @@ gpgsm_agent_havekey (const char *hexkeygrip) return rc; if (!hexkeygrip || strlen (hexkeygrip) != 40) - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); snprintf (line, DIM(line)-1, "HAVEKEY %s", hexkeygrip); line[DIM(line)-1] = 0; @@ -680,7 +682,7 @@ learn_cb (void *opaque, const void *buffer, size_t length) buf = get_membuf (parm->data, &len); if (!buf) { - parm->error = GNUPG_Out_Of_Core; + parm->error = gpg_error (GPG_ERR_ENOMEM); return 0; } @@ -689,7 +691,7 @@ learn_cb (void *opaque, const void *buffer, size_t length) cert = ksba_cert_new (); if (!cert) { - parm->error = GNUPG_Out_Of_Core; + parm->error = gpg_error (GPG_ERR_ENOMEM); return 0; } rc = ksba_cert_init_from_mem (cert, buf, len); @@ -702,7 +704,7 @@ learn_cb (void *opaque, const void *buffer, size_t length) } rc = gpgsm_basic_cert_check (cert); - if (rc == GNUPG_Missing_Certificate) + if (gpg_err_code (rc) == GPG_ERR_MISSING_CERT) { /* For later use we store it in the ephemeral database. */ log_info ("issuer certificate missing - storing as ephemeral\n"); keydb_store_cert (cert, 1, NULL); @@ -766,7 +768,7 @@ gpgsm_agent_passwd (const char *hexkeygrip) return rc; if (!hexkeygrip || strlen (hexkeygrip) != 40) - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); snprintf (line, DIM(line)-1, "PASSWD %s", hexkeygrip); line[DIM(line)-1] = 0; diff --git a/sm/call-dirmngr.c b/sm/call-dirmngr.c index 6c1156a83..78ec4174a 100644 --- a/sm/call-dirmngr.c +++ b/sm/call-dirmngr.c @@ -1,5 +1,5 @@ /* call-dirmngr.c - communication with the dromngr - * Copyright (C) 2002 Free Software Foundation, Inc. + * Copyright (C) 2002, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -29,9 +29,9 @@ #include <ctype.h> #include <gcrypt.h> +#include <assuan.h> #include "gpgsm.h" -#include "../assuan/assuan.h" #include "i18n.h" struct membuf { @@ -154,8 +154,9 @@ start_dirmngr (void) if (fflush (NULL)) { + gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno)); log_error ("error flushing pending output: %s\n", strerror (errno)); - return seterr (Write_Error); + return tmperr; } if (!opt.dirmngr_program || !*opt.dirmngr_program) @@ -219,7 +220,7 @@ start_dirmngr (void) if (rc) { log_error ("can't connect to the dirmngr: %s\n", assuan_strerror (rc)); - return seterr (No_Dirmngr); + return gpg_error (GPG_ERR_NO_DIRMNGR); } dirmngr_ctx = ctx; @@ -284,9 +285,9 @@ inq_certificate (void *opaque, const char *line) /* Call the directory manager to check whether the certificate is valid Returns 0 for valid or usually one of the errors: - GNUPG_Certificate_Revoked - GNUPG_No_CRL_Known - GNUPG_CRL_Too_Old + GPG_ERR_CERTIFICATE_REVOKED + GPG_ERR NO_CRL_KNOWN + GPG_ERR_CRL_TOO_OLD */ int gpgsm_dirmngr_isvalid (KsbaCert cert) @@ -304,7 +305,7 @@ gpgsm_dirmngr_isvalid (KsbaCert cert) if (!certid) { log_error ("error getting the certificate ID\n"); - return seterr (General_Error); + return gpg_error (GPG_ERR_GENERAL); } if (opt.verbose > 1) @@ -352,14 +353,14 @@ lookup_cb (void *opaque, const void *buffer, size_t length) buf = get_membuf (&parm->data, &len); if (!buf) { - parm->error = GNUPG_Out_Of_Core; + parm->error = gpg_error (GPG_ERR_ENOMEM); return 0; } cert = ksba_cert_new (); if (!cert) { - parm->error = GNUPG_Out_Of_Core; + parm->error = gpg_error (GPG_ERR_ENOMEM); return 0; } rc = ksba_cert_init_from_mem (cert, buf, len); @@ -475,7 +476,7 @@ gpgsm_dirmngr_lookup (CTRL ctrl, STRLIST names, pattern = pattern_from_strlist (names); if (!pattern) - return GNUPG_Out_Of_Core; + return OUT_OF_CORE (errno); snprintf (line, DIM(line)-1, "LOOKUP %s", pattern); line[DIM(line)-1] = 0; xfree (pattern); @@ -598,7 +599,7 @@ gpgsm_dirmngr_run_command (CTRL ctrl, const char *command, len += 1 + 3*strlen (argv[i]); /* enough space for percent escaping */ line = xtrymalloc (len); if (!line) - return GNUPG_Out_Of_Core; + return OUT_OF_CORE (errno); p = stpcpy (line, command); for (i=0; i < argc; i++) diff --git a/sm/certchain.c b/sm/certchain.c index b01398f18..34f665cfc 100644 --- a/sm/certchain.c +++ b/sm/certchain.c @@ -1,5 +1,5 @@ /* certchain.c - certificate chain validation - * Copyright (C) 2001, 2002 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -58,7 +58,7 @@ unknown_criticals (KsbaCert cert) { log_error (_("critical certificate extension %s is not supported\n"), oid); - rc = GNUPG_Unsupported_Certificate; + rc = gpg_error (GPG_ERR_UNSUPPORTED_CERT); } } if (err && err != -1) @@ -79,7 +79,7 @@ allowed_ca (KsbaCert cert, int *chainlen) if (!flag) { log_error (_("issuer certificate is not marked as a CA\n")); - return GNUPG_Bad_CA_Certificate; + return gpg_error (GPG_ERR_BAD_CA_CERT); } return 0; } @@ -116,7 +116,7 @@ check_cert_policy (KsbaCert cert) if (any_critical) { log_error ("critical marked policy without configured policies\n"); - return GNUPG_No_Policy_Match; + return gpg_error (GPG_ERR_NO_POLICY_MATCH); } return 0; } @@ -127,7 +127,7 @@ check_cert_policy (KsbaCert cert) log_error ("failed to open `%s': %s\n", opt.policy_file, strerror (errno)); xfree (policies); - return GNUPG_No_Policy_Match; + return gpg_error (GPG_ERR_NO_POLICY_MATCH); } for (;;) @@ -141,6 +141,8 @@ check_cert_policy (KsbaCert cert) { if (!fgets (line, DIM(line)-1, fp) ) { + gpg_error_t tmperr; + xfree (policies); if (feof (fp)) { @@ -152,10 +154,11 @@ check_cert_policy (KsbaCert cert) return 0; } log_error (_("certificate policy not allowed\n")); - return GNUPG_No_Policy_Match; + return gpg_error (GPG_ERR_NO_POLICY_MATCH); } + tmperr = gpg_error (gpg_err_code_from_errno (errno)); fclose (fp); - return GNUPG_Read_Error; + return tmperr; } if (!*line || line[strlen(line)-1] != '\n') @@ -165,7 +168,8 @@ check_cert_policy (KsbaCert cert) ; fclose (fp); xfree (policies); - return *line? GNUPG_Line_Too_Long: GNUPG_Incomplete_Line; + return gpg_error (*line? GPG_ERR_LINE_TOO_LONG + : GPG_ERR_INCOMPLETE_LINE); } /* Allow for empty lines and spaces */ @@ -182,7 +186,7 @@ check_cert_policy (KsbaCert cert) { fclose (fp); xfree (policies); - return GNUPG_Configuration_Error; + return gpg_error (GPG_ERR_CONFIGURATION_ERROR); } *p = 0; /* strip the rest of the line */ /* See whether we find ALLOWED (which is an OID) in POLICIES */ @@ -288,7 +292,7 @@ find_up (KEYDB_HANDLE kh, KsbaCert cert, const char *issuer) pattern = xtrymalloc (strlen (s)+2); if (!pattern) - return GNUPG_Out_Of_Core; + return OUT_OF_CORE (errno); strcpy (stpcpy (pattern, "/"), s); add_to_strlist (&names, pattern); xfree (pattern); @@ -332,7 +336,7 @@ gpgsm_walk_cert_chain (KsbaCert start, KsbaCert *r_next) if (!kh) { log_error (_("failed to allocated keyDB handle\n")); - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); goto leave; } @@ -341,13 +345,13 @@ gpgsm_walk_cert_chain (KsbaCert start, KsbaCert *r_next) if (!issuer) { log_error ("no issuer found in certificate\n"); - rc = GNUPG_Bad_Certificate; + rc = gpg_error (GPG_ERR_BAD_CERT); goto leave; } if (!subject) { log_error ("no subject found in certificate\n"); - rc = GNUPG_Bad_Certificate; + rc = gpg_error (GPG_ERR_BAD_CERT); goto leave; } @@ -364,7 +368,7 @@ gpgsm_walk_cert_chain (KsbaCert start, KsbaCert *r_next) print an error here */ if (rc != -1 && opt.verbose > 1) log_error ("failed to find issuer's certificate: rc=%d\n", rc); - rc = GNUPG_Missing_Certificate; + rc = gpg_error (GPG_ERR_MISSING_CERT); goto leave; } @@ -372,7 +376,7 @@ gpgsm_walk_cert_chain (KsbaCert start, KsbaCert *r_next) if (rc) { log_error ("failed to get cert: rc=%d\n", rc); - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); } leave: @@ -431,7 +435,7 @@ gpgsm_validate_chain (CTRL ctrl, KsbaCert cert, time_t *r_exptime) if (!kh) { log_error (_("failed to allocated keyDB handle\n")); - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); goto leave; } @@ -451,7 +455,7 @@ gpgsm_validate_chain (CTRL ctrl, KsbaCert cert, time_t *r_exptime) if (!issuer) { log_error ("no issuer found in certificate\n"); - rc = GNUPG_Bad_Certificate; + rc = gpg_error (GPG_ERR_BAD_CERT); goto leave; } @@ -463,7 +467,7 @@ gpgsm_validate_chain (CTRL ctrl, KsbaCert cert, time_t *r_exptime) if (not_before == (time_t)(-1) || not_after == (time_t)(-1)) { log_error ("certificate with invalid validity\n"); - rc = GNUPG_Bad_Certificate; + rc = gpg_error (GPG_ERR_BAD_CERT); goto leave; } @@ -480,7 +484,7 @@ gpgsm_validate_chain (CTRL ctrl, KsbaCert cert, time_t *r_exptime) log_error ("certificate too young; valid from "); gpgsm_dump_time (not_before); log_printf ("\n"); - rc = GNUPG_Certificate_Too_Young; + rc = gpg_error (GPG_ERR_CERT_TOO_YOUNG); goto leave; } if (not_after && current_time > not_after) @@ -499,7 +503,7 @@ gpgsm_validate_chain (CTRL ctrl, KsbaCert cert, time_t *r_exptime) if (!opt.no_policy_check) { rc = check_cert_policy (subject_cert); - if (rc == GNUPG_No_Policy_Match) + if (gpg_err_code (rc) == GPG_ERR_NO_POLICY_MATCH) { any_no_policy_match = 1; rc = 1; @@ -515,15 +519,15 @@ gpgsm_validate_chain (CTRL ctrl, KsbaCert cert, time_t *r_exptime) { switch (rc) { - case GNUPG_Certificate_Revoked: + case GPG_ERR_CERT_REVOKED: log_error (_("the certificate has been revoked\n")); any_revoked = 1; break; - case GNUPG_No_CRL_Known: + case GPG_ERR_NO_CRL_KNOWN: log_error (_("no CRL found for certificate\n")); any_no_crl = 1; break; - case GNUPG_CRL_Too_Old: + case GPG_ERR_CRL_TOO_OLD: log_error (_("the available CRL is too old\n")); log_info (_("please make sure that the " "\"dirmngr\" is properly installed\n")); @@ -531,7 +535,7 @@ gpgsm_validate_chain (CTRL ctrl, KsbaCert cert, time_t *r_exptime) break; default: log_error (_("checking the CRL failed: %s\n"), - gnupg_strerror (rc)); + gpg_strerror (rc)); goto leave; } rc = 0; @@ -543,7 +547,8 @@ gpgsm_validate_chain (CTRL ctrl, KsbaCert cert, time_t *r_exptime) if (gpgsm_check_cert_sig (subject_cert, subject_cert) ) { log_error ("selfsigned certificate has a BAD signatures\n"); - rc = depth? GNUPG_Bad_Certificate_Chain : GNUPG_Bad_Certificate; + rc = gpg_error (depth? GPG_ERR_BAD_CERT_CHAIN + : GPG_ERR_BAD_CERT); goto leave; } rc = allowed_ca (subject_cert, NULL); @@ -553,7 +558,7 @@ gpgsm_validate_chain (CTRL ctrl, KsbaCert cert, time_t *r_exptime) rc = gpgsm_agent_istrusted (subject_cert); if (!rc) ; - else if (rc == GNUPG_Not_Trusted) + else if (gpg_err_code (rc) == GPG_ERR_NOT_TRUSTED) { int rc2; @@ -590,7 +595,7 @@ gpgsm_validate_chain (CTRL ctrl, KsbaCert cert, time_t *r_exptime) if (depth > maxdepth) { log_error (_("certificate chain too long\n")); - rc = GNUPG_Bad_Certificate_Chain; + rc = gpg_error (GPG_ERR_BAD_CERT_CHAIN); goto leave; } @@ -607,7 +612,7 @@ gpgsm_validate_chain (CTRL ctrl, KsbaCert cert, time_t *r_exptime) } else log_error ("failed to find issuer's certificate: rc=%d\n", rc); - rc = GNUPG_Missing_Certificate; + rc = gpg_error (GPG_ERR_MISSING_CERT); goto leave; } @@ -616,7 +621,7 @@ gpgsm_validate_chain (CTRL ctrl, KsbaCert cert, time_t *r_exptime) if (rc) { log_error ("failed to get cert: rc=%d\n", rc); - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); goto leave; } @@ -629,7 +634,7 @@ gpgsm_validate_chain (CTRL ctrl, KsbaCert cert, time_t *r_exptime) if (gpgsm_check_cert_sig (issuer_cert, subject_cert) ) { log_error ("certificate has a BAD signatures\n"); - rc = GNUPG_Bad_Certificate_Chain; + rc = gpg_error (GPG_ERR_BAD_CERT_CHAIN); goto leave; } @@ -642,7 +647,7 @@ gpgsm_validate_chain (CTRL ctrl, KsbaCert cert, time_t *r_exptime) { log_error (_("certificate chain longer than allowed by CA (%d)\n"), chainlen); - rc = GNUPG_Bad_Certificate_Chain; + rc = gpg_error (GPG_ERR_BAD_CERT_CHAIN); goto leave; } } @@ -672,15 +677,15 @@ gpgsm_validate_chain (CTRL ctrl, KsbaCert cert, time_t *r_exptime) { /* If we encountered an error somewhere during the checks, set the error code to the most critical one */ if (any_revoked) - rc = GNUPG_Certificate_Revoked; + rc = gpg_error (GPG_ERR_CERT_REVOKED); else if (any_no_crl) - rc = GNUPG_No_CRL_Known; + rc = gpg_error (GPG_ERR_NO_CRL_KNOWN); else if (any_crl_too_old) - rc = GNUPG_CRL_Too_Old; + rc = gpg_error (GPG_ERR_CRL_TOO_OLD); else if (any_no_policy_match) - rc = GNUPG_No_Policy_Match; + rc = gpg_error (GPG_ERR_NO_POLICY_MATCH); else if (any_expired) - rc = GNUPG_Certificate_Expired; + rc = gpg_error (GPG_ERR_CERT_EXPIRED); } leave: @@ -717,7 +722,7 @@ gpgsm_basic_cert_check (KsbaCert cert) if (!kh) { log_error (_("failed to allocated keyDB handle\n")); - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); goto leave; } @@ -726,7 +731,7 @@ gpgsm_basic_cert_check (KsbaCert cert) if (!issuer) { log_error ("no issuer found in certificate\n"); - rc = GNUPG_Bad_Certificate; + rc = gpg_error (GPG_ERR_BAD_CERT); goto leave; } @@ -735,7 +740,7 @@ gpgsm_basic_cert_check (KsbaCert cert) if (gpgsm_check_cert_sig (cert, cert) ) { log_error ("selfsigned certificate has a BAD signatures\n"); - rc = GNUPG_Bad_Certificate; + rc = gpg_error (GPG_ERR_BAD_CERT); goto leave; } } @@ -754,7 +759,7 @@ gpgsm_basic_cert_check (KsbaCert cert) } else log_error ("failed to find issuer's certificate: rc=%d\n", rc); - rc = GNUPG_Missing_Certificate; + rc = gpg_error (GPG_ERR_MISSING_CERT); goto leave; } @@ -763,14 +768,14 @@ gpgsm_basic_cert_check (KsbaCert cert) if (rc) { log_error ("failed to get cert: rc=%d\n", rc); - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); goto leave; } if (gpgsm_check_cert_sig (issuer_cert, cert) ) { log_error ("certificate has a BAD signatures\n"); - rc = GNUPG_Bad_Certificate; + rc = gpg_error (GPG_ERR_BAD_CERT); goto leave; } if (opt.verbose) diff --git a/sm/certcheck.c b/sm/certcheck.c index 1f9054b13..93c0becc5 100644 --- a/sm/certcheck.c +++ b/sm/certcheck.c @@ -1,5 +1,5 @@ /* certcheck.c - check one certificate - * Copyright (C) 2001 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -50,7 +50,7 @@ do_encode_md (GCRY_MD_HD md, int algo, unsigned int nbits, if (gcry_md_algo_info (algo, GCRYCTL_GET_ASNOID, asn, &asnlen)) { log_error ("No object identifier for algo %d\n", algo); - return GNUPG_Internal_Error; + return gpg_error (GPG_ERR_INTERNAL); } len = gcry_md_get_algo_dlen (algo); @@ -59,7 +59,7 @@ do_encode_md (GCRY_MD_HD md, int algo, unsigned int nbits, { log_error ("can't encode a %d bit MD into a %d bits frame\n", (int)(len*8), (int)nbits); - return GNUPG_Internal_Error; + return gpg_error (GPG_ERR_INTERNAL); } /* We encode the MD in this way: @@ -70,7 +70,7 @@ do_encode_md (GCRY_MD_HD md, int algo, unsigned int nbits, */ frame = xtrymalloc (nframe); if (!frame) - return GNUPG_Out_Of_Core; + return OUT_OF_CORE (errno); n = 0; frame[n++] = 0; frame[n++] = 1; /* block type */ @@ -115,13 +115,13 @@ gpgsm_check_cert_sig (KsbaCert issuer_cert, KsbaCert cert) if (!algo) { log_error ("unknown hash algorithm `%s'\n", algoid? algoid:"?"); - return GNUPG_General_Error; + return gpg_error (GPG_ERR_GENERAL); } md = gcry_md_open (algo, 0); if (!md) { log_error ("md_open failed: %s\n", gcry_strerror (-1)); - return GNUPG_General_Error; + return gpg_error (GPG_ERR_GENERAL); } if (DBG_HASHING) gcry_md_start_debug (md, "hash.cert"); @@ -142,7 +142,7 @@ gpgsm_check_cert_sig (KsbaCert issuer_cert, KsbaCert cert) log_error ("libksba did not return a proper S-Exp\n"); gcry_md_close (md); ksba_free (p); - return GNUPG_Bug; + return gpg_error (GPG_ERR_BUG); } if (DBG_X509) { @@ -170,7 +170,7 @@ gpgsm_check_cert_sig (KsbaCert issuer_cert, KsbaCert cert) gcry_md_close (md); ksba_free (p); gcry_sexp_release (s_sig); - return GNUPG_Bug; + return gpg_error (GPG_ERR_BUG); } rc = gcry_sexp_sscan ( &s_pkey, NULL, p, n); ksba_free (p); @@ -223,7 +223,7 @@ gpgsm_check_cms_signature (KsbaCert cert, KsbaConstSexp sigval, if (!n) { log_error ("libksba did not return a proper S-Exp\n"); - return GNUPG_Bug; + return gpg_error (GPG_ERR_BUG); } rc = gcry_sexp_sscan (&s_sig, NULL, sigval, n); if (rc) @@ -239,7 +239,7 @@ gpgsm_check_cms_signature (KsbaCert cert, KsbaConstSexp sigval, log_error ("libksba did not return a proper S-Exp\n"); ksba_free (p); gcry_sexp_release (s_sig); - return GNUPG_Bug; + return gpg_error (GPG_ERR_BUG); } if (DBG_X509) log_printhex ("public key: ", p, n); @@ -287,7 +287,7 @@ gpgsm_create_cms_signature (KsbaCert cert, GCRY_MD_HD md, int mdalgo, grip = gpgsm_get_keygrip_hexstring (cert); if (!grip) - return seterr (Bad_Certificate); + return gpg_error (GPG_ERR_BAD_CERT); rc = gpgsm_agent_pksign (grip, gcry_md_read(md, mdalgo), gcry_md_get_algo_dlen (mdalgo), mdalgo, diff --git a/sm/certlist.c b/sm/certlist.c index f31e6ee2b..7224625a2 100644 --- a/sm/certlist.c +++ b/sm/certlist.c @@ -1,5 +1,5 @@ /* certlist.c - build list of certificates - * Copyright (C) 2001 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -65,7 +65,7 @@ cert_usage_p (KsbaCert cert, int mode) if ((use & (KSBA_KEYUSAGE_KEY_CERT_SIGN))) return 0; log_info ( _("certificate should have not been used certification\n")); - return GNUPG_Wrong_Key_Usage; + return gpg_error (GPG_ERR_WRONG_KEY_USAGE); } if ((use & ((mode&1)? @@ -77,7 +77,7 @@ cert_usage_p (KsbaCert cert, int mode) mode==2? _("certificate should have not been used for signing\n"): mode==1? _("certificate is not usable for encryption\n"): _("certificate is not usable for signing\n")); - return GNUPG_Wrong_Key_Usage; + return gpg_error (GPG_ERR_WRONG_KEY_USAGE); } @@ -150,7 +150,7 @@ gpgsm_add_to_certlist (CTRL ctrl, const char *name, int secret, { kh = keydb_new (0); if (!kh) - rc = GNUPG_Out_Of_Core; + rc = gpg_error (GPG_ERR_ENOMEM); else { int wrong_usage = 0; @@ -165,7 +165,7 @@ gpgsm_add_to_certlist (CTRL ctrl, const char *name, int secret, { rc = secret? gpgsm_cert_use_sign_p (cert) : gpgsm_cert_use_encrypt_p (cert); - if (rc == GNUPG_Wrong_Key_Usage) + if (gpg_err_code (rc) == GPG_ERR_WRONG_KEY_USAGE) { /* There might be another certificate with the correct usage, so we try again */ @@ -209,14 +209,16 @@ gpgsm_add_to_certlist (CTRL ctrl, const char *name, int secret, if (!keydb_get_cert (kh, &cert2)) { int tmp = (same_subject_issuer (subject, issuer, cert2) - && ((secret? gpgsm_cert_use_sign_p (cert2): - gpgsm_cert_use_encrypt_p (cert2)) - == GNUPG_Wrong_Key_Usage)); + && ((gpg_err_code ( + secret? gpgsm_cert_use_sign_p (cert2) + : gpgsm_cert_use_encrypt_p (cert2) + ) + ) == GPG_ERR_WRONG_KEY_USAGE)); ksba_cert_release (cert2); if (tmp) goto next_ambigious; } - rc = GNUPG_Ambiguous_Name; + rc = gpg_error (GPG_ERR_AMBIGUOUS_NAME); } } xfree (subject); @@ -226,7 +228,7 @@ gpgsm_add_to_certlist (CTRL ctrl, const char *name, int secret, { char *p; - rc = GNUPG_No_Secret_Key; + rc = gpg_error (GPG_ERR_NO_SECKEY); p = gpgsm_get_keygrip_hexstring (cert); if (p) { @@ -241,7 +243,7 @@ gpgsm_add_to_certlist (CTRL ctrl, const char *name, int secret, { CERTLIST cl = xtrycalloc (1, sizeof *cl); if (!cl) - rc = GNUPG_Out_Of_Core; + rc = OUT_OF_CORE (errno); else { cl->cert = cert; cert = NULL; @@ -254,7 +256,7 @@ gpgsm_add_to_certlist (CTRL ctrl, const char *name, int secret, keydb_release (kh); ksba_cert_release (cert); - return rc == -1? GNUPG_No_Public_Key: rc; + return rc == -1? gpg_error (GPG_ERR_NO_PUBKEY): rc; } void @@ -285,7 +287,7 @@ gpgsm_find_cert (const char *name, KsbaCert *r_cert) { kh = keydb_new (0); if (!kh) - rc = GNUPG_Out_Of_Core; + rc = gpg_error (GPG_ERR_ENOMEM); else { rc = keydb_search (kh, &desc, 1); @@ -299,7 +301,7 @@ gpgsm_find_cert (const char *name, KsbaCert *r_cert) else { if (!rc) - rc = GNUPG_Ambiguous_Name; + rc = gpg_error (GPG_ERR_AMBIGUOUS_NAME); ksba_cert_release (*r_cert); *r_cert = NULL; } @@ -308,6 +310,6 @@ gpgsm_find_cert (const char *name, KsbaCert *r_cert) } keydb_release (kh); - return rc == -1? GNUPG_No_Public_Key: rc; + return rc == -1? gpg_error (GPG_ERR_NO_PUBKEY): rc; } diff --git a/sm/certreqgen.c b/sm/certreqgen.c index 600a278bc..716cfcdeb 100644 --- a/sm/certreqgen.c +++ b/sm/certreqgen.c @@ -1,5 +1,5 @@ /* certreqgen.c - Generate a key and a certification request - * Copyright (C) 2002 Free Software Foundation, Inc. + * Copyright (C) 2002, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -366,12 +366,12 @@ read_parameters (FILE *fp, KsbaWriter writer) if (err) { log_error ("line %d: %s\n", outctrl.lnr, err); - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); } else if (ferror(fp)) { log_error ("line %d: read error: %s\n", outctrl.lnr, strerror(errno) ); - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); } else if (para) { @@ -382,7 +382,7 @@ read_parameters (FILE *fp, KsbaWriter writer) } if (!rc && !any) - rc = GNUPG_No_Data; + rc = gpg_error (GPG_ERR_NO_DATA); leave: release_parameter_list (para); @@ -436,7 +436,7 @@ proc_parameters (struct para_data_s *para, struct reqgen_ctrl_s *outctrl) { r = get_parameter (para, pKEYTYPE); log_error ("line %d: invalid algorithm\n", r->lnr); - return GNUPG_Invalid_Parameter; + return gpg_error (GPG_ERR_INV_PARAMETER); } /* check the keylength */ @@ -449,12 +449,12 @@ proc_parameters (struct para_data_s *para, struct reqgen_ctrl_s *outctrl) r = get_parameter (para, pKEYTYPE); log_error ("line %d: invalid key length %u (valid are 512 to 4096)\n", r->lnr, nbits); - return GNUPG_Invalid_Parameter; + return gpg_error (GPG_ERR_INV_PARAMETER); } /* check the usage */ if (parse_parameter_usage (para, pKEYUSAGE)) - return GNUPG_Invalid_Parameter; + return gpg_error (GPG_ERR_INV_PARAMETER); /* check that there is a subject name and that this DN fits our requirements */ @@ -462,7 +462,7 @@ proc_parameters (struct para_data_s *para, struct reqgen_ctrl_s *outctrl) { r = get_parameter (para, pKEYTYPE); log_error ("line %d: no subject name given\n", r->lnr); - return GNUPG_Invalid_Parameter; + return gpg_error (GPG_ERR_INV_PARAMETER); } /* fixme check s */ @@ -477,7 +477,7 @@ proc_parameters (struct para_data_s *para, struct reqgen_ctrl_s *outctrl) { r = get_parameter (para, pKEYTYPE); log_error ("line %d: not a valid email address\n", r->lnr); - return GNUPG_Invalid_Parameter; + return gpg_error (GPG_ERR_INV_PARAMETER); } } @@ -515,7 +515,7 @@ create_request (struct para_data_s *para, KsbaConstSexp public, cr = ksba_certreq_new (); if (!cr) - return seterr (Out_Of_Core); + return gpg_error (GPG_ERR_ENOMEM); md = gcry_md_open (GCRY_MD_SHA1, 0); if (!md) @@ -542,11 +542,12 @@ create_request (struct para_data_s *para, KsbaConstSexp public, s = get_parameter_value (para, pNAMEEMAIL); if (s) { - char *buf = xtrymalloc (strlen (s) + 3); + char *buf; + buf = xtrymalloc (strlen (s) + 3); if (!buf) { - rc = GNUPG_Out_Of_Core; + rc = OUT_OF_CORE (errno); goto leave; } *buf = '<'; @@ -594,7 +595,7 @@ create_request (struct para_data_s *para, KsbaConstSexp public, if (!n) { log_error ("libksba did not return a proper S-Exp\n"); - err = GNUPG_Bug; + err = gpg_error (GPG_ERR_BUG); goto leave; } rc = gcry_sexp_sscan (&s_pkey, NULL, public, n); @@ -606,7 +607,7 @@ create_request (struct para_data_s *para, KsbaConstSexp public, } if ( !gcry_pk_get_keygrip (s_pkey, grip) ) { - rc = seterr (General_Error); + rc = gpg_error (GPG_ERR_GENERAL); log_error ("can't figure out the keygrip\n"); gcry_sexp_release (s_pkey); goto leave; @@ -661,8 +662,9 @@ gpgsm_genkey (CTRL ctrl, int in_fd, FILE *out_fp) in_fp = fdopen (dup (in_fd), "rb"); if (!in_fp) { + gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno)); log_error ("fdopen() failed: %s\n", strerror (errno)); - return seterr (IO_Error); + return tmperr; } ctrl->pem_name = "NEW CERTIFICATE REQUEST"; diff --git a/sm/decrypt.c b/sm/decrypt.c index 012254e22..1882fb626 100644 --- a/sm/decrypt.c +++ b/sm/decrypt.c @@ -1,5 +1,5 @@ /* decrypt.c - Decrypt a message - * Copyright (C) 2001 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -82,7 +82,7 @@ prepare_decryption (const char *hexkeygrip, KsbaConstSexp enc_val, { if (n + 7 > seskeylen ) { - rc = seterr (Invalid_Session_Key); + rc = gpg_error (GPG_ERR_INV_SESSION_KEY); goto leave; } @@ -96,7 +96,7 @@ prepare_decryption (const char *hexkeygrip, KsbaConstSexp enc_val, if (seskey[n] != 2 ) /* wrong block type version */ { - rc = seterr (Invalid_Session_Key); + rc = gpg_error (GPG_ERR_INV_SESSION_KEY); goto leave; } @@ -105,7 +105,7 @@ prepare_decryption (const char *hexkeygrip, KsbaConstSexp enc_val, n++; /* and the zero byte */ if (n >= seskeylen ) { - rc = seterr (Invalid_Session_Key); + rc = gpg_error (GPG_ERR_INV_SESSION_KEY); goto leave; } } @@ -261,7 +261,7 @@ gpgsm_decrypt (CTRL ctrl, int in_fd, FILE *out_fp) if (!kh) { log_error (_("failed to allocated keyDB handle\n")); - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); goto leave; } @@ -269,8 +269,8 @@ gpgsm_decrypt (CTRL ctrl, int in_fd, FILE *out_fp) in_fp = fdopen ( dup (in_fd), "rb"); if (!in_fp) { + rc = gpg_error (gpg_err_code_from_errno (errno)); log_error ("fdopen() failed: %s\n", strerror (errno)); - rc = seterr (IO_Error); goto leave; } @@ -291,7 +291,7 @@ gpgsm_decrypt (CTRL ctrl, int in_fd, FILE *out_fp) cms = ksba_cms_new (); if (!cms) { - rc = seterr (Out_Of_Core); + rc = gpg_error (GPG_ERR_ENOMEM); goto leave; } @@ -327,7 +327,7 @@ gpgsm_decrypt (CTRL ctrl, int in_fd, FILE *out_fp) mode = gcry_cipher_mode_from_oid (algoid); if (!algo || !mode) { - rc = GNUPG_Unsupported_Algorithm; + rc = gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM); log_error ("unsupported algorithm `%s'\n", algoid? algoid:"?"); if (algoid && !strcmp (algoid, "1.2.840.113549.3.2")) log_info (_("(this is the RC2 algorithm)\n")); @@ -342,7 +342,7 @@ gpgsm_decrypt (CTRL ctrl, int in_fd, FILE *out_fp) dfparm.mode = mode; dfparm.blklen = gcry_cipher_get_algo_blklen (algo); if (dfparm.blklen > sizeof (dfparm.helpblock)) - return GNUPG_Bug; + return gpg_error (GPG_ERR_BUG); rc = ksba_cms_get_content_enc_iv (cms, dfparm.iv, @@ -437,7 +437,7 @@ gpgsm_decrypt (CTRL ctrl, int in_fd, FILE *out_fp) } if (!any_key) { - rc = GNUPG_No_Secret_Key; + rc = gpg_error (GPG_ERR_NO_SECKEY); goto leave; } } @@ -450,7 +450,7 @@ gpgsm_decrypt (CTRL ctrl, int in_fd, FILE *out_fp) if (!npadding || npadding > dfparm.blklen) { log_error ("invalid padding with value %d\n", npadding); - rc = seterr (Invalid_Data); + rc = gpg_error (GPG_ERR_INVALID_DATA); goto leave; } rc = ksba_writer_write (writer, @@ -466,7 +466,7 @@ gpgsm_decrypt (CTRL ctrl, int in_fd, FILE *out_fp) if (dfparm.lastblock[i] != npadding) { log_error ("inconsistent padding\n"); - rc = seterr (Invalid_Data); + rc = gpg_error (GPG_ERR_INVALID_DATA); goto leave; } } diff --git a/sm/delete.c b/sm/delete.c index cd1491a86..5ec5b1ad5 100644 --- a/sm/delete.c +++ b/sm/delete.c @@ -92,13 +92,13 @@ delete_one (CTRL ctrl, const char *username) goto next_ambigious; } } - rc = GNUPG_Ambiguous_Name; + rc = gpg_error (GPG_ERR_AMBIGUOUS_NAME); } } if (rc) { if (rc == -1) - rc = GNUPG_No_Public_Key; + rc = gpg_error (GPG_ERR_NO_PUBKEY); log_error (_("certificate `%s' not found: %s\n"), username, gnupg_strerror (rc)); gpgsm_status2 (ctrl, STATUS_DELETE_PROBLEM, "3", NULL); @@ -147,7 +147,7 @@ gpgsm_delete (CTRL ctrl, STRLIST names) if (!names) { log_error ("nothing to delete\n"); - return GNUPG_No_Data; + return gpg_error (GPG_ERR_NO_DATA); } for (; names; names=names->next ) diff --git a/sm/encrypt.c b/sm/encrypt.c index 40e12582f..3713a7d15 100644 --- a/sm/encrypt.c +++ b/sm/encrypt.c @@ -1,5 +1,5 @@ /* encrypt.c - Encrypt a message - * Copyright (C) 2001 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -72,28 +72,28 @@ init_dek (DEK dek) if (!dek->algo || !mode) { log_error ("unsupported algorithm `%s'\n", dek->algoid); - return GNUPG_Unsupported_Algorithm; + return gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM); } dek->keylen = gcry_cipher_get_algo_keylen (dek->algo); if (!dek->keylen || dek->keylen > sizeof (dek->key)) - return GNUPG_Bug; + return gpg_error (GPG_ERR_BUG); dek->ivlen = gcry_cipher_get_algo_blklen (dek->algo); if (!dek->ivlen || dek->ivlen > sizeof (dek->iv)) - return GNUPG_Bug; + return gpg_error (GPG_ERR_BUG); if (dek->keylen < 100/8) { /* make sure we don't use weak keys */ log_error ("key length of `%s' too small\n", dek->algoid); - return GNUPG_Unsupported_Algorithm; + return gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM); } dek->chd = gcry_cipher_open (dek->algo, mode, GCRY_CIPHER_SECURE); if (!dek->chd) { log_error ("failed to create cipher context: %s\n", gcry_strerror (-1)); - return GNUPG_General_Error; + return gpg_error (GPG_ERR_GENERAL); } for (i=0; i < 8; i++) @@ -218,13 +218,13 @@ encrypt_dek (const DEK dek, KsbaCert cert, char **encval) if (!buf) { log_error ("no public key for recipient\n"); - return GNUPG_No_Public_Key; + return gpg_error (GPG_ERR_NO_PUBKEY); } len = gcry_sexp_canon_len (buf, 0, NULL, NULL); if (!len) { log_error ("libksba did not return a proper S-Exp\n"); - return GNUPG_Bug; + return gpg_error (GPG_ERR_BUG); } rc = gcry_sexp_sscan (&s_pkey, NULL, buf, len); xfree (buf); buf = NULL; @@ -241,7 +241,7 @@ encrypt_dek (const DEK dek, KsbaCert cert, char **encval) if (!data) { gcry_mpi_release (data); - return GNUPG_General_Error; + return gpg_error (GPG_ERR_GENERAL); } if (gcry_sexp_build (&s_data, NULL, "%m", data)) BUG (); @@ -259,8 +259,9 @@ encrypt_dek (const DEK dek, KsbaCert cert, char **encval) buf = xtrymalloc (len); if (!buf) { + gpg_error_t tmperr = OUT_OF_CORE (errno); gcry_sexp_release (s_ciph); - return GNUPG_Out_Of_Core; + return tmperr; } len = gcry_sexp_sprint (s_ciph, GCRYSEXP_FMT_CANON, buf, len); assert (len); @@ -367,7 +368,7 @@ gpgsm_encrypt (CTRL ctrl, CERTLIST recplist, int data_fd, FILE *out_fp) { log_error(_("no valid recipients given\n")); gpgsm_status (ctrl, STATUS_NO_RECP, "0"); - rc = GNUPG_No_Public_Key; + rc = gpg_error (GPG_ERR_NO_PUBKEY); goto leave; } @@ -375,15 +376,15 @@ gpgsm_encrypt (CTRL ctrl, CERTLIST recplist, int data_fd, FILE *out_fp) if (!kh) { log_error (_("failed to allocated keyDB handle\n")); - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); goto leave; } data_fp = fdopen ( dup (data_fd), "rb"); if (!data_fp) { + rc = gpg_error (gpg_err_code_from_errno (errno)); log_error ("fdopen() failed: %s\n", strerror (errno)); - rc = seterr (IO_Error); goto leave; } @@ -410,7 +411,7 @@ gpgsm_encrypt (CTRL ctrl, CERTLIST recplist, int data_fd, FILE *out_fp) cms = ksba_cms_new (); if (!cms) { - rc = seterr (Out_Of_Core); + rc = gpg_error (GPG_ERR_ENOMEM); goto leave; } @@ -439,7 +440,7 @@ gpgsm_encrypt (CTRL ctrl, CERTLIST recplist, int data_fd, FILE *out_fp) /* create a session key */ dek = xtrycalloc (1, sizeof *dek); /* hmmm: should we put it into secmem?*/ if (!dek) - rc = GNUPG_Out_Of_Core; + rc = OUT_OF_CORE (errno); else { dek->algoid = opt.def_cipher_algoid; @@ -467,7 +468,7 @@ gpgsm_encrypt (CTRL ctrl, CERTLIST recplist, int data_fd, FILE *out_fp) encparm.buffer = xtrymalloc (encparm.bufsize); if (!encparm.buffer) { - rc = seterr (Out_Of_Core); + rc = OUT_OF_CORE (errno); goto leave; } @@ -523,7 +524,7 @@ gpgsm_encrypt (CTRL ctrl, CERTLIST recplist, int data_fd, FILE *out_fp) if (encparm.readerror) { log_error ("error reading input: %s\n", strerror (encparm.readerror)); - rc = seterr (Read_Error); + rc = gpg_error (gpg_err_code_from_errno (encparm.readerror)); goto leave; } diff --git a/sm/export.c b/sm/export.c index 042850752..1e279a564 100644 --- a/sm/export.c +++ b/sm/export.c @@ -1,5 +1,5 @@ /* export.c - * Copyright (C) 2002 Free Software Foundation, Inc. + * Copyright (C) 2002, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -70,7 +70,8 @@ gpgsm_export (CTRL ctrl, STRLIST names, FILE *fp) desc = xtrycalloc (ndesc, sizeof *desc); if (!ndesc) { - log_error ("%s\n", gnupg_strerror (GNUPG_Out_Of_Core)); + log_error ("allocating memory for export failed: %s\n", + gpg_strerror (OUT_OF_CORE (errno))); goto leave; } diff --git a/sm/fingerprint.c b/sm/fingerprint.c index 6a84966db..6e458cf76 100644 --- a/sm/fingerprint.c +++ b/sm/fingerprint.c @@ -171,7 +171,7 @@ gpgsm_get_keygrip (KsbaCert cert, char *array) gcry_sexp_release (s_pkey); if (!array) { - rc = seterr (General_Error); + rc = gpg_error (GPG_ERR_GENERAL); log_error ("can't calculate keygrip\n"); return NULL; } diff --git a/sm/gpgsm.c b/sm/gpgsm.c index 1583787a1..8fefe609c 100644 --- a/sm/gpgsm.c +++ b/sm/gpgsm.c @@ -1,5 +1,5 @@ /* gpgsm.c - GnuPG for S/MIME - * Copyright (C) 2001, 2002 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -28,8 +28,9 @@ #include <fcntl.h> #include <gcrypt.h> +#include <assuan.h> /* malloc hooks */ + #include "gpgsm.h" -#include "../assuan/assuan.h" /* malloc hooks */ #include "../kbx/keybox.h" /* malloc hooks */ #include "i18n.h" #include "keydb.h" @@ -1096,16 +1097,16 @@ main ( int argc, char **argv) log_error (_("can't sign using `%s': %s\n"), sl->d, gnupg_strerror (rc)); gpgsm_status2 (&ctrl, STATUS_INV_RECP, - rc == -1? "1": - rc == GNUPG_No_Public_Key? "1": - rc == GNUPG_Ambiguous_Name? "2": - rc == GNUPG_Wrong_Key_Usage? "3": - rc == GNUPG_Certificate_Revoked? "4": - rc == GNUPG_Certificate_Expired? "5": - rc == GNUPG_No_CRL_Known? "6": - rc == GNUPG_CRL_Too_Old? "7": - rc == GNUPG_No_Policy_Match? "8": - rc == GNUPG_No_Secret_Key? "9": + gpg_err_code (rc) == -1? "1": + gpg_err_code (rc) == GPG_ERR_NO_PUBKEY? "1": + gpg_err_code (rc) == GPG_ERR_AMBIGUOUS_NAME? "2": + gpg_err_code (rc) == GPG_ERR_WRONG_KEY_USAGE? "3": + gpg_err_code (rc) == GPG_ERR_CERT_REVOKED? "4": + gpg_err_code (rc) == GPG_ERR_CERT_EXPIRED? "5": + gpg_err_code (rc) == GPG_ERR_NO_CRL_KNOWN? "6": + gpg_err_code (rc) == GPG_ERR_CRL_TOO_OLD? "7": + gpg_err_code (rc) == GPG_ERR_NO_POLICY_MATCH? "8": + gpg_err_code (rc) == GPG_ERR_NO_SECKEY? "9": "0", sl->d, NULL); } @@ -1118,15 +1119,15 @@ main ( int argc, char **argv) log_error (_("can't encrypt to `%s': %s\n"), sl->d, gnupg_strerror (rc)); gpgsm_status2 (&ctrl, STATUS_INV_RECP, - rc == -1? "1": - rc == GNUPG_No_Public_Key? "1": - rc == GNUPG_Ambiguous_Name? "2": - rc == GNUPG_Wrong_Key_Usage? "3": - rc == GNUPG_Certificate_Revoked? "4": - rc == GNUPG_Certificate_Expired? "5": - rc == GNUPG_No_CRL_Known? "6": - rc == GNUPG_CRL_Too_Old? "7": - rc == GNUPG_No_Policy_Match? "8": + gpg_err_code (rc) == -1? "1": + gpg_err_code (rc) == GPG_ERR_NO_PUBKEY? "1": + gpg_err_code (rc) == GPG_ERR_AMBIGUOUS_NAME? "2": + gpg_err_code (rc) == GPG_ERR_WRONG_KEY_USAGE? "3": + gpg_err_code (rc) == GPG_ERR_CERT_REVOKED? "4": + gpg_err_code (rc) == GPG_ERR_CERT_EXPIRED? "5": + gpg_err_code (rc) == GPG_ERR_NO_CRL_KNOWN? "6": + gpg_err_code (rc) == GPG_ERR_CRL_TOO_OLD? "7": + gpg_err_code (rc) == GPG_ERR_NO_POLICY_MATCH? "8": "0", sl->d, NULL); } @@ -1306,7 +1307,7 @@ main ( int argc, char **argv) if (rc) ; else if (!(grip = gpgsm_get_keygrip_hexstring (cert))) - rc = GNUPG_Bug; + rc = gpg_error (GPG_ERR_BUG); else rc = gpgsm_agent_passwd (grip); if (rc) diff --git a/sm/gpgsm.h b/sm/gpgsm.h index dd91e3764..72abccac9 100644 --- a/sm/gpgsm.h +++ b/sm/gpgsm.h @@ -1,5 +1,5 @@ /* gpgsm.h - Global definitions for GpgSM - * Copyright (C) 2001 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -21,10 +21,18 @@ #ifndef GPGSM_H #define GPGSM_H +#ifdef GPG_ERR_SOURCE_DEFAULT +#error GPG_ERR_SOURCE_DEFAULT already defined +#endif +#define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_GPGSM +#include <gpg-error.h> + #include <ksba.h> #include "../common/util.h" #include "../common/errors.h" +#define OUT_OF_CORE(a) (gpg_error (gpg_err_code_from_errno ((a)))) + #define MAX_DIGEST_LEN 24 /* A large struct name "opt" to keep global flags */ diff --git a/sm/import.c b/sm/import.c index 2fc6b1a79..b3aaa823f 100644 --- a/sm/import.c +++ b/sm/import.c @@ -1,5 +1,5 @@ /* import.c - Import certificates - * Copyright (C) 2001 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -181,8 +181,8 @@ check_and_store (CTRL ctrl, struct stats_s *stats, KsbaCert cert, int depth) log_error (_("basic certificate checks failed - not imported\n")); stats->not_imported++; print_import_problem (ctrl, cert, - rc == GNUPG_Missing_Certificate? 2 : - rc == GNUPG_Bad_Certificate? 1 : 0); + gpg_err_code (rc) == GPG_ERR_MISSING_CERT? 2 : + gpg_err_code (rc) == GPG_ERR_BAD_CERT? 1 : 0); } } @@ -203,8 +203,8 @@ import_one (CTRL ctrl, struct stats_s *stats, int in_fd) fp = fdopen ( dup (in_fd), "rb"); if (!fp) { + rc = gpg_error (gpg_err_code_from_errno (errno)); log_error ("fdopen() failed: %s\n", strerror (errno)); - rc = seterr (IO_Error); goto leave; } @@ -224,7 +224,7 @@ import_one (CTRL ctrl, struct stats_s *stats, int in_fd) cms = ksba_cms_new (); if (!cms) { - rc = seterr (Out_Of_Core); + rc = gpg_error (GPG_ERR_ENOMEM); goto leave; } @@ -268,7 +268,7 @@ import_one (CTRL ctrl, struct stats_s *stats, int in_fd) cert = ksba_cert_new (); if (!cert) { - rc = seterr (Out_Of_Core); + rc = gpg_error (GPG_ERR_ENOMEM); goto leave; } @@ -284,7 +284,7 @@ import_one (CTRL ctrl, struct stats_s *stats, int in_fd) else { log_error ("can't extract certificates from input\n"); - rc = GNUPG_No_Data; + rc = gpg_error (GPG_ERR_NO_DATA); } leave: diff --git a/sm/keydb.c b/sm/keydb.c index 5b5722d3e..56c5e7e79 100644 --- a/sm/keydb.c +++ b/sm/keydb.c @@ -1,5 +1,5 @@ /* keydb.c - key database dispatcher - * Copyright (C) 2001 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -103,7 +103,7 @@ keydb_add_resource (const char *url, int force, int secret) else if (strchr (resname, ':')) { log_error ("invalid key resource URL `%s'\n", url ); - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); goto leave; } #endif /* !HAVE_DRIVE_LETTERS && !__riscos__ */ @@ -150,14 +150,14 @@ keydb_add_resource (const char *url, int force, int secret) { case KEYDB_RESOURCE_TYPE_NONE: log_error ("unknown type of key resource `%s'\n", url ); - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); goto leave; case KEYDB_RESOURCE_TYPE_KEYBOX: fp = fopen (filename, "rb"); if (!fp && !force) { - rc = GNUPG_File_Open_Error; + rc = gpg_error (gpg_err_code_from_errno (errno)); goto leave; } @@ -175,7 +175,7 @@ keydb_add_resource (const char *url, int force, int secret) terminated, so that on the next invocation can read the options file in on startup */ try_make_homedir (filename); - rc = GNUPG_File_Open_Error; + rc = gpg_error (GPG_ERR_FILE_OPEN_ERROR); *last_slash_in_filename = DIRSEP_C; goto leave; } @@ -185,9 +185,9 @@ keydb_add_resource (const char *url, int force, int secret) fp = fopen (filename, "w"); if (!fp) { + rc = gpg_error (gpg_err_code_from_errno (errno)); log_error (_("error creating keybox `%s': %s\n"), filename, strerror(errno)); - rc = GNUPG_File_Create_Error; goto leave; } @@ -204,7 +204,7 @@ keydb_add_resource (const char *url, int force, int secret) if (!token) ; /* already registered - ignore it */ else if (used_resources >= MAX_KEYDB_RESOURCES) - rc = GNUPG_Resource_Limit; + rc = gpg_error (GPG_ERR_RESOURCE_LIMIT); else { all_resources[used_resources].type = rt; @@ -223,7 +223,7 @@ keydb_add_resource (const char *url, int force, int secret) break; default: log_error ("resource type of `%s' not supported\n", url); - rc = GNUPG_Not_Supported; + rc = gpg_error (GPG_ERR_NOT_SUPPORTED); goto leave; } @@ -562,7 +562,7 @@ keydb_get_cert (KEYDB_HANDLE hd, KsbaCert *r_cert) int rc = 0; if (!hd) - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); if ( hd->found < 0 || hd->found >= hd->used) return -1; /* nothing found */ @@ -570,7 +570,7 @@ keydb_get_cert (KEYDB_HANDLE hd, KsbaCert *r_cert) switch (hd->active[hd->found].type) { case KEYDB_RESOURCE_TYPE_NONE: - rc = GNUPG_General_Error; /* oops */ + rc = gpg_error (GPG_ERR_GENERAL); /* oops */ break; case KEYDB_RESOURCE_TYPE_KEYBOX: rc = keybox_get_cert (hd->active[hd->found].u.kr, r_cert); @@ -591,7 +591,7 @@ keydb_insert_cert (KEYDB_HANDLE hd, KsbaCert cert) char digest[20]; if (!hd) - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); if (opt.dry_run) return 0; @@ -601,7 +601,7 @@ keydb_insert_cert (KEYDB_HANDLE hd, KsbaCert cert) else if ( hd->current >= 0 && hd->current < hd->used) idx = hd->current; else - return GNUPG_General_Error; + return gpg_error (GPG_ERR_GENERAL); rc = lock_all (hd); if (rc) @@ -612,7 +612,7 @@ keydb_insert_cert (KEYDB_HANDLE hd, KsbaCert cert) switch (hd->active[idx].type) { case KEYDB_RESOURCE_TYPE_NONE: - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); break; case KEYDB_RESOURCE_TYPE_KEYBOX: rc = keybox_insert_cert (hd->active[idx].u.kr, cert, digest); @@ -633,7 +633,7 @@ keydb_update_cert (KEYDB_HANDLE hd, KsbaCert cert) char digest[20]; if (!hd) - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); if ( hd->found < 0 || hd->found >= hd->used) return -1; /* nothing found */ @@ -650,7 +650,7 @@ keydb_update_cert (KEYDB_HANDLE hd, KsbaCert cert) switch (hd->active[hd->found].type) { case KEYDB_RESOURCE_TYPE_NONE: - rc = GNUPG_General_Error; /* oops */ + rc = gpg_error (GPG_ERR_GENERAL); /* oops */ break; case KEYDB_RESOURCE_TYPE_KEYBOX: rc = keybox_update_cert (hd->active[hd->found].u.kr, cert, digest); @@ -671,7 +671,7 @@ keydb_delete (KEYDB_HANDLE hd) int rc = -1; if (!hd) - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); if ( hd->found < 0 || hd->found >= hd->used) return -1; /* nothing found */ @@ -686,7 +686,7 @@ keydb_delete (KEYDB_HANDLE hd) switch (hd->active[hd->found].type) { case KEYDB_RESOURCE_TYPE_NONE: - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); break; case KEYDB_RESOURCE_TYPE_KEYBOX: rc = keybox_delete (hd->active[hd->found].u.kr); @@ -710,7 +710,7 @@ keydb_locate_writable (KEYDB_HANDLE hd, const char *reserved) int rc; if (!hd) - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); rc = keydb_search_reset (hd); /* this does reset hd->current */ if (rc) @@ -770,7 +770,7 @@ keydb_search_reset (KEYDB_HANDLE hd) int i, rc = 0; if (!hd) - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); hd->current = 0; hd->found = -1; @@ -800,7 +800,7 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc, size_t ndesc) int rc = -1; if (!hd) - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); while (rc == -1 && hd->current >= 0 && hd->current < hd->used) { @@ -891,12 +891,12 @@ keydb_search_issuer_sn (KEYDB_HANDLE hd, desc.mode = KEYDB_SEARCH_MODE_ISSUER_SN; s = serial; if (*s !='(') - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); s++; for (desc.snlen = 0; digitp (s); s++) desc.snlen = 10*desc.snlen + atoi_1 (s); if (*s !=':') - return GNUPG_Invalid_Value; + return gpg_error (GPG_ERR_INVALID_VALUE); desc.sn = s+1; desc.u.name = issuer; rc = keydb_search (hd, &desc, 1); @@ -1209,7 +1209,7 @@ keydb_classify_name (const char *name, KEYDB_SEARCH_DESC *desc) desc = &dummy_desc; if (!classify_user_id (name, desc, &dummy)) - return GNUPG_Invalid_Name; + return gpg_error (GPG_ERR_INV_NAME); return 0; } @@ -1231,14 +1231,14 @@ keydb_store_cert (KsbaCert cert, int ephemeral, int *existed) if (!gpgsm_get_fingerprint (cert, 0, fpr, NULL)) { log_error (_("failed to get the fingerprint\n")); - return GNUPG_General_Error; + return gpg_error (GPG_ERR_GENERAL); } kh = keydb_new (0); if (!kh) { log_error (_("failed to allocate keyDB handle\n")); - return GNUPG_Out_Of_Core; + return gpg_error (GPG_ERR_ENOMEM);; } if (ephemeral) diff --git a/sm/server.c b/sm/server.c index 9fc2cd078..60f553bee 100644 --- a/sm/server.c +++ b/sm/server.c @@ -245,18 +245,21 @@ cmd_recipient (ASSUAN_CONTEXT ctx, char *line) rc = gpgsm_add_to_certlist (ctrl, line, 0, &ctrl->server_local->recplist); if (rc) - gpgsm_status2 (ctrl, STATUS_INV_RECP, - rc == -1? "1": - rc == GNUPG_No_Public_Key? "1": - rc == GNUPG_Ambiguous_Name? "2": - rc == GNUPG_Wrong_Key_Usage? "3": - rc == GNUPG_Certificate_Revoked? "4": - rc == GNUPG_Certificate_Expired? "5": - rc == GNUPG_No_CRL_Known? "6": - rc == GNUPG_CRL_Too_Old? "7": - rc == GNUPG_No_Policy_Match? "8": + { + gpg_err_code_t r = gpg_err_code (rc); + gpgsm_status2 (ctrl, STATUS_INV_RECP, + r == -1? "1": + r == GPG_ERR_NO_PUBKEY? "1": + r == GPG_ERR_AMBIGUOUS_NAME? "2": + r == GPG_ERR_WRONG_KEY_USAGE? "3": + r == GPG_ERR_CERT_REVOKED? "4": + r == GPG_ERR_CERT_EXPIRED? "5": + r == GPG_ERR_NO_CRL_KNOWN? "6": + r == GPG_ERR_CRL_TOO_OLD? "7": + r == GPG_ERR_NO_POLICY_MATCH? "8": "0", line, NULL); + } return map_to_assuan_status (rc); } @@ -285,20 +288,22 @@ cmd_signer (ASSUAN_CONTEXT ctx, char *line) rc = gpgsm_add_to_certlist (ctrl, line, 1, &ctrl->server_local->signerlist); if (rc) - gpgsm_status2 (ctrl, STATUS_INV_RECP, - rc == -1? "1": - rc == GNUPG_No_Public_Key? "1": - rc == GNUPG_Ambiguous_Name? "2": - rc == GNUPG_Wrong_Key_Usage? "3": - rc == GNUPG_Certificate_Revoked? "4": - rc == GNUPG_Certificate_Expired? "5": - rc == GNUPG_No_CRL_Known? "6": - rc == GNUPG_CRL_Too_Old? "7": - rc == GNUPG_No_Policy_Match? "8": - rc == GNUPG_No_Secret_Key? "9": + { + gpg_err_code_t r = gpg_err_code (rc); + gpgsm_status2 (ctrl, STATUS_INV_RECP, + r == -1? "1": + r == GPG_ERR_NO_PUBKEY? "1": + r == GPG_ERR_AMBIGUOUS_NAME? "2": + r == GPG_ERR_WRONG_KEY_USAGE? "3": + r == GPG_ERR_CERT_REVOKED? "4": + r == GPG_ERR_CERT_EXPIRED? "5": + r == GPG_ERR_NO_CRL_KNOWN? "6": + r == GPG_ERR_CRL_TOO_OLD? "7": + r == GPG_ERR_NO_POLICY_MATCH? "8": + r == GPG_ERR_NO_SECKEY? "9": "0", - line, NULL); - + line, NULL); + } return map_to_assuan_status (rc); } @@ -1,5 +1,5 @@ /* sign.c - Sign a message - * Copyright (C) 2001, 2002 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -73,8 +73,9 @@ hash_and_copy_data (int fd, GCRY_MD_HD md, KsbaWriter writer) fp = fdopen ( dup (fd), "rb"); if (!fp) { + gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno)); log_error ("fdopen(%d) failed: %s\n", fd, strerror (errno)); - return GNUPG_File_Open_Error; + return tmperr; } do @@ -95,8 +96,8 @@ hash_and_copy_data (int fd, GCRY_MD_HD md, KsbaWriter writer) while (nread && !rc); if (ferror (fp)) { + rc = gpg_error (gpg_err_code_from_errno (errno)); log_error ("read error on fd %d: %s\n", fd, strerror (errno)); - rc = GNUPG_Read_Error; } fclose (fp); if (!any) @@ -106,7 +107,7 @@ hash_and_copy_data (int fd, GCRY_MD_HD md, KsbaWriter writer) already written the tag for data and now expects an octet string but an octet string of zeize 0 is illegal. */ log_error ("cannot sign an empty message\n"); - rc = GNUPG_No_Data; + rc = gpg_error (GPG_ERR_NO_DATA); } if (!rc) { @@ -134,7 +135,7 @@ gpgsm_get_default_cert (KsbaCert *r_cert) hd = keydb_new (0); if (!hd) - return GNUPG_General_Error; + return gpg_error (GPG_ERR_GENERAL); rc = keydb_search_first (hd); if (rc) { @@ -313,7 +314,7 @@ gpgsm_sign (CTRL ctrl, CERTLIST signerlist, if (!kh) { log_error (_("failed to allocated keyDB handle\n")); - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); goto leave; } @@ -328,7 +329,7 @@ gpgsm_sign (CTRL ctrl, CERTLIST signerlist, cms = ksba_cms_new (); if (!cms) { - rc = seterr (Out_Of_Core); + rc = gpg_error (GPG_ERR_ENOMEM); goto leave; } @@ -360,13 +361,13 @@ gpgsm_sign (CTRL ctrl, CERTLIST signerlist, if (!cert) { log_error ("no default signer found\n"); - rc = seterr (General_Error); + rc = gpg_error (GPG_ERR_GENERAL); goto leave; } signerlist = xtrycalloc (1, sizeof *signerlist); if (!signerlist) { - rc = GNUPG_Out_Of_Core; + rc = OUT_OF_CORE (errno); ksba_cert_release (cert); goto leave; } @@ -424,7 +425,7 @@ gpgsm_sign (CTRL ctrl, CERTLIST signerlist, if (!algo) { log_error ("unknown hash algorithm `%s'\n", algoid? algoid:"?"); - rc = GNUPG_Bug; + rc = gpg_error (GPG_ERR_BUG); goto leave; } gcry_md_enable (data_md, algo); @@ -446,7 +447,7 @@ gpgsm_sign (CTRL ctrl, CERTLIST signerlist, if ( !digest || !digest_len) { log_error ("problem getting the hash of the data\n"); - rc = GNUPG_Bug; + rc = gpg_error (GPG_ERR_BUG); goto leave; } for (cl=signerlist,signer=0; cl; cl = cl->next, signer++) @@ -505,7 +506,7 @@ gpgsm_sign (CTRL ctrl, CERTLIST signerlist, if ( !digest || !digest_len) { log_error ("problem getting the hash of the data\n"); - rc = GNUPG_Bug; + rc = gpg_error (GPG_ERR_BUG); goto leave; } for (cl=signerlist,signer=0; cl; cl = cl->next, signer++) @@ -574,7 +575,7 @@ gpgsm_sign (CTRL ctrl, CERTLIST signerlist, fpr = gpgsm_get_fingerprint_hexstring (cl->cert, GCRY_MD_SHA1); if (!fpr) { - rc = seterr (Out_Of_Core); + rc = gpg_error (GPG_ERR_ENOMEM); gcry_md_close (md); goto leave; } @@ -587,7 +588,7 @@ gpgsm_sign (CTRL ctrl, CERTLIST signerlist, xfree (fpr); if (rc < 0) { - rc = seterr (Out_Of_Core); + rc = gpg_error (GPG_ERR_ENOMEM); gcry_md_close (md); goto leave; } diff --git a/sm/verify.c b/sm/verify.c index 3461d68af..412f722d7 100644 --- a/sm/verify.c +++ b/sm/verify.c @@ -1,5 +1,5 @@ /* verify.c - Verify a messages signature - * Copyright (C) 2001, 2002 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -114,7 +114,7 @@ gpgsm_verify (CTRL ctrl, int in_fd, int data_fd, FILE *out_fp) if (!kh) { log_error (_("failed to allocated keyDB handle\n")); - rc = GNUPG_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); goto leave; } @@ -122,8 +122,8 @@ gpgsm_verify (CTRL ctrl, int in_fd, int data_fd, FILE *out_fp) fp = fdopen ( dup (in_fd), "rb"); if (!fp) { + rc = gpg_error (gpg_err_code_from_errno (errno)); log_error ("fdopen() failed: %s\n", strerror (errno)); - rc = seterr (IO_Error); goto leave; } @@ -147,7 +147,7 @@ gpgsm_verify (CTRL ctrl, int in_fd, int data_fd, FILE *out_fp) cms = ksba_cms_new (); if (!cms) { - rc = seterr (Out_Of_Core); + rc = gpg_error (GPG_ERR_ENOMEM); goto leave; } @@ -233,7 +233,7 @@ gpgsm_verify (CTRL ctrl, int in_fd, int data_fd, FILE *out_fp) if (data_fd != -1 && !is_detached) { log_error ("data given for a non-detached signature\n"); - rc = GNUPG_Conflict; + rc = gpg_error (GPG_ERR_CONFLICT); goto leave; } @@ -360,7 +360,7 @@ gpgsm_verify (CTRL ctrl, int in_fd, int data_fd, FILE *out_fp) if (rc == -1) { log_error ("certificate not found\n"); - rc = GNUPG_No_Public_Key; + rc = gpg_error (GPG_ERR_NO_PUBKEY); } else log_error ("failed to find the certificate: %s\n", @@ -457,7 +457,7 @@ gpgsm_verify (CTRL ctrl, int in_fd, int data_fd, FILE *out_fp) if (DBG_X509) log_debug ("signature okay - checking certs\n"); rc = gpgsm_validate_chain (ctrl, cert, &keyexptime); - if (rc == GNUPG_Certificate_Expired) + if (gpg_err_code (rc) == GPG_ERR_CERT_EXPIRED) { gpgsm_status (ctrl, STATUS_EXPKEYSIG, NULL); rc = 0; @@ -482,10 +482,10 @@ gpgsm_verify (CTRL ctrl, int in_fd, int data_fd, FILE *out_fp) if (rc) /* of validate_chain */ { log_error ("invalid certification chain: %s\n", gnupg_strerror (rc)); - if (rc == GNUPG_Bad_Certificate_Chain - || rc == GNUPG_Bad_Certificate - || rc == GNUPG_Bad_CA_Certificate - || rc == GNUPG_Certificate_Revoked) + if (gpg_err_code (rc) == GPG_ERR_BAD_CERT_CHAIN + || gpg_err_code (rc) == GPG_ERR_BAD_CERT + || gpg_err_code (rc) == GPG_ERR_BAD_CA_CERT + || gpg_err_code (rc) == GPG_ERR_CERT_REVOKED) gpgsm_status (ctrl, STATUS_TRUST_NEVER, gnupg_error_token (rc)); else gpgsm_status (ctrl, STATUS_TRUST_UNDEFINED, gnupg_error_token (rc)); |