From 3dccd639899fdce44b14b7f4fa0e555ccc0acd46 Mon Sep 17 00:00:00 2001 From: aet Date: Fri, 19 Apr 2002 14:23:31 +0000 Subject: [PATCH] - C++ support. Compiles with gcc/g++ for Linux, otherwise completely untested. git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@574 c6295689-39f2-0310-b995-f0e70906c6a9 --- configure.in | 2 +- src/libopensc/asn1.c | 28 ++++++++--------- src/libopensc/asn1.h | 8 +++++ src/libopensc/base64.c | 2 +- src/libopensc/card-etoken.c | 2 +- src/libopensc/card-gpk.c | 2 +- src/libopensc/card-miocos.c | 2 +- src/libopensc/card-setcos.c | 2 +- src/libopensc/card.c | 6 ++-- src/libopensc/cardctl.h | 8 +++++ src/libopensc/ctx.c | 2 +- src/libopensc/dir.c | 8 ++--- src/libopensc/emv.h | 1 - src/libopensc/errors.h | 10 ++++++ src/libopensc/internal.h | 8 +++++ src/libopensc/iso7816.c | 8 ++--- src/libopensc/log.h | 8 +++++ src/libopensc/opensc.h | 10 +++--- src/libopensc/pkcs15-algo.c | 4 +-- src/libopensc/pkcs15-cache.c | 2 +- src/libopensc/pkcs15-cert.c | 4 +-- src/libopensc/pkcs15-prkey.c | 2 +- src/libopensc/pkcs15-pubkey.c | 2 +- src/libopensc/pkcs15-sec.c | 4 +-- src/libopensc/pkcs15-wrap.c | 2 +- src/libopensc/pkcs15.c | 18 +++++------ src/libopensc/pkcs15.h | 8 +++-- src/libopensc/reader-ctapi.c | 14 ++++----- src/libopensc/reader-pcsc.c | 8 ++--- src/libopensc/sc.c | 24 +++++++------- src/libopensc/types.h | 8 +++++ src/openssh/opensc-ssh.c | 10 +++--- src/pam/pam_opensc.c | 10 +++--- src/pam/pam_support.c | 2 +- src/pkcs11/framework-pkcs15.c | 18 +++++------ src/pkcs11/pkcs11-global.c | 2 +- src/pkcs11/pkcs11-object.c | 2 +- src/pkcs11/sc-pkcs11.h | 8 +++++ src/pkcs11/secretkey.c | 14 ++++----- src/pkcs15init/pkcs15-cflex.c | 8 ++--- src/pkcs15init/pkcs15-gpk.c | 59 ++++++++++++++++++----------------- src/pkcs15init/pkcs15-init.h | 8 +++++ src/pkcs15init/pkcs15-lib.c | 21 ++++++------- src/pkcs15init/profile.h | 7 +++++ src/scam/.cvsignore | 1 + src/scam/p15_eid.c | 10 +++--- src/scam/p15_ldap.c | 6 ++-- src/scconf/parse.c | 4 +-- src/scconf/scconf.c | 16 +++++----- src/scconf/write.c | 8 ++--- src/scldap/scldap.c | 28 ++++++++--------- src/scldap/test-ldap.c | 8 ++--- src/scrandom/scrandom.c | 12 +++---- src/scrandom/test-random.c | 2 +- src/signer/dialog.c | 12 +++---- src/signer/opensc-crypto.c | 4 +-- src/signer/opensc-support.c | 8 ++--- src/signer/signer.c | 6 ++-- src/tests/p15dump.c | 2 +- src/tests/print.c | 2 -- src/tests/sc-test.c | 1 + src/tests/sc-test.h | 8 +++++ src/tools/cryptoflex-tool.c | 4 +-- src/tools/pkcs15-crypt.c | 10 +++--- src/tools/pkcs15-init.c | 18 +++++------ src/tools/pkcs15-tool.c | 14 ++++----- src/tools/util.c | 2 +- src/tools/util.h | 10 +++++- 68 files changed, 335 insertions(+), 247 deletions(-) diff --git a/configure.in b/configure.in index 98423f5d..079f49be 100644 --- a/configure.in +++ b/configure.in @@ -165,7 +165,7 @@ AC_CHECK_FUNCS([getpass gettimeofday memset mkdir strdup strerror setutent]) dnl C Compiler features AC_C_INLINE if test "$GCC" = "yes"; then - CFLAGS="$CFLAGS -Wall" + CFLAGS="-Wall $CFLAGS" # Disabled until lex-parse.l doesn't give us a warning # -Werror fi diff --git a/src/libopensc/asn1.c b/src/libopensc/asn1.c index ee9c5aae..8928d84c 100644 --- a/src/libopensc/asn1.c +++ b/src/libopensc/asn1.c @@ -431,7 +431,7 @@ static int encode_bit_string(const u8 * inbuf, size_t bits_left, u8 **outbuf, int skipped = 0; bytes = (bits_left + 7)/8 + 1; - *outbuf = out = malloc(bytes); + *outbuf = out = (u8 *) malloc(bytes); if (out == NULL) return SC_ERROR_OUT_OF_MEMORY; *outlen = bytes; @@ -479,7 +479,7 @@ static int asn1_encode_integer(int in, u8 ** obj, size_t * objsize) int i = sizeof(in) * 8, skip = 1; u8 *p, b; - *obj = p = malloc(sizeof(in)); + *obj = p = (u8 *) malloc(sizeof(in)); if (*obj == NULL) return SC_ERROR_OUT_OF_MEMORY; do { @@ -568,7 +568,7 @@ int sc_asn1_encode_object_id(u8 **buf, size_t *buflen, } } *buflen = count = p - temp; - *buf = malloc(count); + *buf = (u8 *) malloc(count); memcpy(*buf, temp, count); return 0; } @@ -639,7 +639,7 @@ int asn1_write_element(struct sc_context *ctx, unsigned int tag, const u8 * data c++; } *outlen = 2 + c + datalen; - buf = malloc(*outlen); + buf = (u8 *) malloc(*outlen); if (buf == NULL) SC_FUNC_RETURN(ctx, 1, SC_ERROR_OUT_OF_MEMORY); *out = p = buf; @@ -828,7 +828,7 @@ static int asn1_decode_entry(struct sc_context *ctx, struct sc_asn1_entry *entry } if (entry->flags & SC_ASN1_ALLOC) { u8 **buf = (u8 **) parm; - *buf = malloc(objlen-1); + *buf = (u8 *) malloc(objlen-1); if (*buf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; break; @@ -849,7 +849,7 @@ static int asn1_decode_entry(struct sc_context *ctx, struct sc_asn1_entry *entry assert(len != NULL); if (entry->flags & SC_ASN1_ALLOC) { u8 **buf = (u8 **) parm; - *buf = malloc(objlen); + *buf = (u8 *) malloc(objlen); if (*buf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; break; @@ -872,7 +872,7 @@ static int asn1_decode_entry(struct sc_context *ctx, struct sc_asn1_entry *entry assert(len != NULL); if (entry->flags & SC_ASN1_ALLOC) { u8 **buf = (u8 **) parm; - *buf = malloc(objlen-1); + *buf = (u8 *) malloc(objlen-1); if (*buf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; break; @@ -880,7 +880,7 @@ static int asn1_decode_entry(struct sc_context *ctx, struct sc_asn1_entry *entry *len = objlen-1; parm = *buf; } - r = sc_asn1_decode_utf8string(obj, objlen, parm, len); + r = sc_asn1_decode_utf8string(obj, objlen, (u8 *) parm, len); } break; case SC_ASN1_PATH: @@ -889,7 +889,7 @@ static int asn1_decode_entry(struct sc_context *ctx, struct sc_asn1_entry *entry break; case SC_ASN1_PKCS15_ID: if (entry->parm != NULL) { - struct sc_pkcs15_id *id = parm; + struct sc_pkcs15_id *id = (struct sc_pkcs15_id *) parm; int c = objlen > sizeof(id->value) ? sizeof(id->value) : objlen; memcpy(id->value, obj, c); @@ -1045,7 +1045,7 @@ static int asn1_encode_entry(struct sc_context *ctx, const struct sc_asn1_entry buflen = 0; break; case SC_ASN1_BOOLEAN: - buf = malloc(1); + buf = (u8 *) malloc(1); if (buf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; break; @@ -1068,7 +1068,7 @@ static int asn1_encode_entry(struct sc_context *ctx, const struct sc_asn1_entry case SC_ASN1_OCTET_STRING: case SC_ASN1_UTF8STRING: assert(len != NULL); - buf = malloc(*len); + buf = (u8 *) malloc(*len); if (buf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; break; @@ -1085,9 +1085,9 @@ static int asn1_encode_entry(struct sc_context *ctx, const struct sc_asn1_entry break; case SC_ASN1_PKCS15_ID: if (entry->parm != NULL) { - const struct sc_pkcs15_id *id = parm; + const struct sc_pkcs15_id *id = (const struct sc_pkcs15_id *) parm; - buf = malloc(id->len); + buf = (u8 *) malloc(id->len); if (buf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; break; @@ -1147,7 +1147,7 @@ static int asn1_encode(struct sc_context *ctx, const struct sc_asn1_entry *asn1, free(buf); return r; } - buf = realloc(buf, total + objsize); + buf = (u8 *) realloc(buf, total + objsize); memcpy(buf + total, obj, objsize); free(obj); total += objsize; diff --git a/src/libopensc/asn1.h b/src/libopensc/asn1.h index 31af16f0..7819a585 100644 --- a/src/libopensc/asn1.h +++ b/src/libopensc/asn1.h @@ -21,6 +21,10 @@ #ifndef _SC_ASN1_H #define _SC_ASN1_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include @@ -186,4 +190,8 @@ void sc_asn1_clear_algorithm_id(struct sc_algorithm_id *); #define ASN1_UNIVERSALSTRING 28 #define ASN1_BMPSTRING 30 +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/libopensc/base64.c b/src/libopensc/base64.c index 88ef617b..89f4321c 100644 --- a/src/libopensc/base64.c +++ b/src/libopensc/base64.c @@ -24,7 +24,7 @@ #include #include -static const u8 base64_table[65] = +static const u8 base64_table[66] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" "0123456789+/="; diff --git a/src/libopensc/card-etoken.c b/src/libopensc/card-etoken.c index 1792f128..34619173 100644 --- a/src/libopensc/card-etoken.c +++ b/src/libopensc/card-etoken.c @@ -22,8 +22,8 @@ #include "errors.h" #include "opensc.h" #include "log.h" - #include +#include static const struct sc_card_operations *iso_ops = NULL; diff --git a/src/libopensc/card-gpk.c b/src/libopensc/card-gpk.c index 44bf5c0b..a37d4270 100644 --- a/src/libopensc/card-gpk.c +++ b/src/libopensc/card-gpk.c @@ -155,7 +155,7 @@ gpk_init(struct sc_card *card) if (!(ai = gpk_identify(card))) return SC_ERROR_INVALID_CARD; - card->drv_data = priv = malloc(sizeof(*priv)); + card->drv_data = priv = (struct gpk_private_data *) malloc(sizeof(*priv)); if (card->drv_data == NULL) return SC_ERROR_OUT_OF_MEMORY; memset(priv, 0, sizeof(*priv)); diff --git a/src/libopensc/card-miocos.c b/src/libopensc/card-miocos.c index 176c6cb2..2789e5a6 100644 --- a/src/libopensc/card-miocos.c +++ b/src/libopensc/card-miocos.c @@ -69,7 +69,7 @@ static int miocos_init(struct sc_card *card) i = _sc_match_atr(card, miocos_atrs, &id); if (i < 0) return 0; - priv = malloc(sizeof(struct miocos_priv_data)); + priv = (struct miocos_priv_data *) malloc(sizeof(struct miocos_priv_data)); if (priv == NULL) return SC_ERROR_OUT_OF_MEMORY; card->drv_data = priv; diff --git a/src/libopensc/card-setcos.c b/src/libopensc/card-setcos.c index 12b242dd..cb16b32e 100644 --- a/src/libopensc/card-setcos.c +++ b/src/libopensc/card-setcos.c @@ -73,7 +73,7 @@ static int setcos_init(struct sc_card *card) i = _sc_match_atr(card, setcos_atrs, &id); if (i < 0) return 0; - priv = malloc(sizeof(struct setcos_priv_data)); + priv = (struct setcos_priv_data *) malloc(sizeof(struct setcos_priv_data)); if (priv == NULL) return SC_ERROR_OUT_OF_MEMORY; card->drv_data = priv; diff --git a/src/libopensc/card.c b/src/libopensc/card.c index 4d027954..02ad0553 100644 --- a/src/libopensc/card.c +++ b/src/libopensc/card.c @@ -278,11 +278,11 @@ static struct sc_card * sc_card_new() { struct sc_card *card; - card = malloc(sizeof(struct sc_card)); + card = (struct sc_card *) malloc(sizeof(struct sc_card)); if (card == NULL) return NULL; memset(card, 0, sizeof(struct sc_card)); - card->ops = malloc(sizeof(struct sc_card_operations)); + card->ops = (struct sc_card_operations *) malloc(sizeof(struct sc_card_operations)); if (card->ops == NULL) { free(card); return NULL; @@ -742,7 +742,7 @@ int _sc_card_add_algorithm(struct sc_card *card, const struct sc_algorithm_info struct sc_algorithm_info *p; assert(sc_card_valid(card) && info != NULL); - card->algorithms = realloc(card->algorithms, (card->algorithm_count + 1) * sizeof(*info)); + card->algorithms = (struct sc_algorithm_info *) realloc(card->algorithms, (card->algorithm_count + 1) * sizeof(*info)); if (card->algorithms == NULL) { card->algorithm_count = 0; return SC_ERROR_OUT_OF_MEMORY; diff --git a/src/libopensc/cardctl.h b/src/libopensc/cardctl.h index 8bc80ccb..fee0faa4 100644 --- a/src/libopensc/cardctl.h +++ b/src/libopensc/cardctl.h @@ -14,6 +14,10 @@ #ifndef _OPENSC_CARDCTL_H #define _OPENSC_CARDCTL_H +#ifdef __cplusplus +extern "C" { +#endif + #define _CTL_PREFIX(a, b, c) (((a) << 24) | ((b) << 16) | ((c) << 8)) enum { @@ -91,4 +95,8 @@ struct sc_cardctl_miocos_ac_info { u8 unblock_value[8]; /* and here */ }; +#ifdef __cplusplus +} +#endif + #endif /* _OPENSC_CARDCTL_H */ diff --git a/src/libopensc/ctx.c b/src/libopensc/ctx.c index 6f41cf41..1a50a4ac 100644 --- a/src/libopensc/ctx.c +++ b/src/libopensc/ctx.c @@ -300,7 +300,7 @@ int sc_establish_context(struct sc_context **ctx_out, const char *app_name) struct _sc_ctx_options opts; assert(ctx_out != NULL); - ctx = malloc(sizeof(struct sc_context)); + ctx = (struct sc_context *) malloc(sizeof(struct sc_context)); if (ctx == NULL) return SC_ERROR_OUT_OF_MEMORY; memset(ctx, 0, sizeof(struct sc_context)); diff --git a/src/libopensc/dir.c b/src/libopensc/dir.c index fa861244..a6d1673c 100644 --- a/src/libopensc/dir.c +++ b/src/libopensc/dir.c @@ -92,7 +92,7 @@ static int parse_dir_record(struct sc_card *card, u8 ** buf, size_t *buflen, error(card->ctx, "AID is too long.\n"); return SC_ERROR_INVALID_ASN1_OBJECT; } - app = malloc(sizeof(struct sc_app_info)); + app = (struct sc_app_info *) malloc(sizeof(struct sc_app_info)); if (app == NULL) return SC_ERROR_OUT_OF_MEMORY; @@ -113,7 +113,7 @@ static int parse_dir_record(struct sc_card *card, u8 ** buf, size_t *buflen, } else app->path.len = 0; if (asn1_dirrecord[3].flags & SC_ASN1_PRESENT) { - app->ddo = malloc(ddo_len); + app->ddo = (u8 *) malloc(ddo_len); if (app->ddo == NULL) return 0; memcpy(app->ddo, ddo, ddo_len); @@ -261,7 +261,7 @@ static int update_transparent(struct sc_card *card, struct sc_file *file) free(buf); return r; } - buf = realloc(buf, buf_size + rec_size); + buf = (u8 *) realloc(buf, buf_size + rec_size); if (buf == NULL) { free(rec); return SC_ERROR_OUT_OF_MEMORY; @@ -270,7 +270,7 @@ static int update_transparent(struct sc_card *card, struct sc_file *file) buf_size += rec_size; } if (file->size > buf_size) { - buf = realloc(buf, file->size); + buf = (u8 *) realloc(buf, file->size); memset(buf + buf_size, 0, file->size - buf_size); buf_size = file->size; } diff --git a/src/libopensc/emv.h b/src/libopensc/emv.h index 188cf749..2cdf0096 100644 --- a/src/libopensc/emv.h +++ b/src/libopensc/emv.h @@ -38,5 +38,4 @@ int sc_emv_unbind(struct sc_emv_card *emv_card); } #endif - #endif diff --git a/src/libopensc/errors.h b/src/libopensc/errors.h index df8c9610..db1f73ba 100644 --- a/src/libopensc/errors.h +++ b/src/libopensc/errors.h @@ -21,6 +21,10 @@ #ifndef _OPENSC_ERRORS_H #define _OPENSC_ERRORS_H +#ifdef __cplusplus +extern "C" { +#endif + #define SC_SUCCESS 0 #define SC_NO_ERROR 0 @@ -82,4 +86,10 @@ #define SC_ERROR_UNKNOWN -1900 #define SC_ERROR_PKCS15_APP_NOT_FOUND -1901 +const char *sc_strerror(int sc_errno); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/libopensc/internal.h b/src/libopensc/internal.h index 9e2cbfe9..415a30be 100644 --- a/src/libopensc/internal.h +++ b/src/libopensc/internal.h @@ -25,6 +25,10 @@ #include #endif +#ifdef __cplusplus +extern "C" { +#endif + #include "opensc.h" #include @@ -60,4 +64,8 @@ int sc_module_open(struct sc_context *ctx, void **mod_handle, const char *filena int sc_module_close(struct sc_context *ctx, void *mod_handle); int sc_module_get_address(struct sc_context *ctx, void *mod_handle, void **sym_address, const char *sym_name); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/libopensc/iso7816.c b/src/libopensc/iso7816.c index a3c58e0e..ad6b411d 100644 --- a/src/libopensc/iso7816.c +++ b/src/libopensc/iso7816.c @@ -781,7 +781,7 @@ static int iso7816_decipher(struct sc_card *card, static int iso7816_change_reference_data(struct sc_card *card, unsigned int type, int ref, const u8 *old, size_t oldlen, - const u8 *new, size_t newlen, + const u8 *_new, size_t newlen, int *tries_left) { struct sc_apdu apdu; @@ -800,7 +800,7 @@ static int iso7816_change_reference_data(struct sc_card *card, unsigned int type p1 = 1; sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x24, p1, ref); memcpy(sbuf, old, oldlen); - memcpy(sbuf + oldlen, new, newlen); + memcpy(sbuf + oldlen, _new, newlen); apdu.lc = len; apdu.datalen = len; apdu.data = sbuf; @@ -819,7 +819,7 @@ static int iso7816_change_reference_data(struct sc_card *card, unsigned int type } static int iso7816_reset_retry_counter(struct sc_card *card, unsigned int type, int ref, - const u8 *puk, size_t puklen, const u8 *new, + const u8 *puk, size_t puklen, const u8 *_new, size_t newlen) { struct sc_apdu apdu; @@ -847,7 +847,7 @@ static int iso7816_reset_retry_counter(struct sc_card *card, unsigned int type, } sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x2C, p1, ref); memcpy(sbuf, puk, puklen); - memcpy(sbuf + puklen, new, newlen); + memcpy(sbuf + puklen, _new, newlen); apdu.lc = len; apdu.datalen = len; apdu.data = sbuf; diff --git a/src/libopensc/log.h b/src/libopensc/log.h index 46284d8e..32b7c1cb 100644 --- a/src/libopensc/log.h +++ b/src/libopensc/log.h @@ -21,6 +21,10 @@ #ifndef _SC_LOG_H #define _SC_LOG_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include @@ -67,4 +71,8 @@ void sc_hex_dump(struct sc_context *ctx, const u8 *buf, size_t len, char *out, size_t outlen); #define sc_perror(ctx, errno, str) { error((ctx), "%s: %s\n", str, sc_strerror((errno))); } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/libopensc/opensc.h b/src/libopensc/opensc.h index 963d1c22..2f6d277a 100644 --- a/src/libopensc/opensc.h +++ b/src/libopensc/opensc.h @@ -32,14 +32,14 @@ #include #endif -#include -#include -#include - #ifdef __cplusplus extern "C" { #endif +#include +#include +#include + #ifndef __GNUC__ #undef inline #define inline @@ -688,8 +688,6 @@ struct sc_card_error { const char *errorstr; }; -const char *sc_strerror(int sc_errno); - extern const char *sc_version; extern const struct sc_reader_driver *sc_get_pcsc_driver(void); diff --git a/src/libopensc/pkcs15-algo.c b/src/libopensc/pkcs15-algo.c index ac992d58..08675675 100644 --- a/src/libopensc/pkcs15-algo.c +++ b/src/libopensc/pkcs15-algo.c @@ -302,7 +302,7 @@ sc_asn1_decode_algorithm_id(struct sc_context *ctx, const u8 *in, /* See if we understand the algorithm, and if we do, check * whether we know how to decode any additional parameters */ - id->algorithm = -1; + id->algorithm = (unsigned int ) -1; if ((alg_info = sc_asn1_get_algorithm_info(id)) != NULL) { id->algorithm = alg_info->id; if (alg_info->decode) { @@ -361,7 +361,7 @@ sc_asn1_encode_algorithm_id(struct sc_context *ctx, } if (obj_len) { - *buf = realloc(*buf, *len + obj_len); + *buf = (u8 *) realloc(*buf, *len + obj_len); memcpy(*buf + *len, obj, obj_len); *len += obj_len; free(obj); diff --git a/src/libopensc/pkcs15-cache.c b/src/libopensc/pkcs15-cache.c index 59cfc9a6..b1c35017 100644 --- a/src/libopensc/pkcs15-cache.c +++ b/src/libopensc/pkcs15-cache.c @@ -79,7 +79,7 @@ int sc_pkcs15_read_cached_file(struct sc_pkcs15_card *p15card, return SC_ERROR_FILE_NOT_FOUND; c = stbuf.st_size; if (*buf == NULL) { - data = malloc(stbuf.st_size); + data = (u8 *) malloc(stbuf.st_size); if (data == NULL) return SC_ERROR_OUT_OF_MEMORY; } else diff --git a/src/libopensc/pkcs15-cert.c b/src/libopensc/pkcs15-cert.c index 0409b66f..b667dbb4 100644 --- a/src/libopensc/pkcs15-cert.c +++ b/src/libopensc/pkcs15-cert.c @@ -112,7 +112,7 @@ int sc_pkcs15_read_certificate(struct sc_pkcs15_card *p15card, } len = file->size; sc_file_free(file); - data = malloc(len); + data = (u8 *) malloc(len); if (data == NULL) { sc_unlock(p15card->card); return SC_ERROR_OUT_OF_MEMORY; @@ -125,7 +125,7 @@ int sc_pkcs15_read_certificate(struct sc_pkcs15_card *p15card, } sc_unlock(p15card->card); } - cert = malloc(sizeof(struct sc_pkcs15_cert)); + cert = (struct sc_pkcs15_cert *) malloc(sizeof(struct sc_pkcs15_cert)); if (cert == NULL) { free(data); return SC_ERROR_OUT_OF_MEMORY; diff --git a/src/libopensc/pkcs15-prkey.c b/src/libopensc/pkcs15-prkey.c index 3ab208b8..3fea9ab0 100644 --- a/src/libopensc/pkcs15-prkey.c +++ b/src/libopensc/pkcs15-prkey.c @@ -364,7 +364,7 @@ sc_pkcs15_read_prkey(struct sc_pkcs15_card *p15card, goto fail; } - *out = malloc(sizeof(key)); + *out = (struct sc_pkcs15_prkey *) malloc(sizeof(key)); if (*out == NULL) { r = SC_ERROR_OUT_OF_MEMORY; goto fail; diff --git a/src/libopensc/pkcs15-pubkey.c b/src/libopensc/pkcs15-pubkey.c index 977df6ce..642a3985 100644 --- a/src/libopensc/pkcs15-pubkey.c +++ b/src/libopensc/pkcs15-pubkey.c @@ -388,7 +388,7 @@ sc_pkcs15_read_pubkey(struct sc_pkcs15_card *p15card, return r; } - pubkey = malloc(sizeof(struct sc_pkcs15_pubkey)); + pubkey = (struct sc_pkcs15_pubkey *) malloc(sizeof(struct sc_pkcs15_pubkey)); if (pubkey == NULL) { free(data); return SC_ERROR_OUT_OF_MEMORY; diff --git a/src/libopensc/pkcs15-sec.c b/src/libopensc/pkcs15-sec.c index 7f42e340..44e4a2c2 100644 --- a/src/libopensc/pkcs15-sec.c +++ b/src/libopensc/pkcs15-sec.c @@ -35,7 +35,7 @@ int sc_pkcs15_decipher(struct sc_pkcs15_card *p15card, struct sc_security_env senv; struct sc_context *ctx = p15card->card->ctx; struct sc_path path, file_id; - const struct sc_pkcs15_prkey_info *prkey = obj->data; + const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data; /* If the key is extractable, the caller should extract the * key and do the crypto himself */ @@ -158,7 +158,7 @@ int sc_pkcs15_compute_signature(struct sc_pkcs15_card *p15card, struct sc_security_env senv; struct sc_context *ctx = p15card->card->ctx; struct sc_algorithm_info *alg_info; - const struct sc_pkcs15_prkey_info *prkey = obj->data; + const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data; u8 buf[512]; size_t buflen; struct sc_path path, file_id; diff --git a/src/libopensc/pkcs15-wrap.c b/src/libopensc/pkcs15-wrap.c index bdc82576..a97e7a78 100644 --- a/src/libopensc/pkcs15-wrap.c +++ b/src/libopensc/pkcs15-wrap.c @@ -130,7 +130,7 @@ do_cipher(struct sc_context *ctx, EVP_CIPHER_CTX *cipher_ctx, u8 *p; size_t bl, done, left, total; - *out = p = malloc(in_len + EVP_CIPHER_CTX_key_length(cipher_ctx)); + *out = p = (u8 *) malloc(in_len + EVP_CIPHER_CTX_key_length(cipher_ctx)); *out_len = total = 0; bl = EVP_CIPHER_CTX_block_size(cipher_ctx); diff --git a/src/libopensc/pkcs15.c b/src/libopensc/pkcs15.c index 7dda2908..b5b83fa4 100644 --- a/src/libopensc/pkcs15.c +++ b/src/libopensc/pkcs15.c @@ -99,7 +99,7 @@ static void parse_tokeninfo(struct sc_pkcs15_card *card, const u8 * buf, size_t goto err; } card->version += 1; - card->serial_number = malloc(serial_len * 2 + 1); + card->serial_number = (char *) malloc(serial_len * 2 + 1); card->serial_number[0] = 0; for (i = 0; i < serial_len; i++) { char byte[3]; @@ -378,12 +378,12 @@ int sc_pkcs15_encode_odf(struct sc_context *ctx, error(ctx, "No DF's found.\n"); return SC_ERROR_OBJECT_NOT_FOUND; } - asn1_odf = malloc(sizeof(struct sc_asn1_entry) * (df_count + 1)); + asn1_odf = (struct sc_asn1_entry *) malloc(sizeof(struct sc_asn1_entry) * (df_count + 1)); if (asn1_odf == NULL) { r = SC_ERROR_OUT_OF_MEMORY; goto err; } - asn1_paths = malloc(sizeof(struct sc_asn1_entry) * (df_count * 2)); + asn1_paths = (struct sc_asn1_entry *) malloc(sizeof(struct sc_asn1_entry) * (df_count * 2)); if (asn1_paths == NULL) { r = SC_ERROR_OUT_OF_MEMORY; goto err; @@ -420,7 +420,7 @@ struct sc_pkcs15_card * sc_pkcs15_card_new() { struct sc_pkcs15_card *p15card; - p15card = malloc(sizeof(struct sc_pkcs15_card)); + p15card = (struct sc_pkcs15_card *) malloc(sizeof(struct sc_pkcs15_card)); if (p15card == NULL) return NULL; memset(p15card, 0, sizeof(struct sc_pkcs15_card)); @@ -654,7 +654,7 @@ int sc_pkcs15_get_objects(struct sc_pkcs15_card *p15card, int type, static int compare_obj_id(struct sc_pkcs15_object *obj, void *arg) { void *data = obj->data; - const struct sc_pkcs15_id *id = arg; + const struct sc_pkcs15_id *id = (const struct sc_pkcs15_id *) arg; switch (obj->type) { case SC_PKCS15_TYPE_CERT_X509: @@ -782,7 +782,7 @@ int sc_pkcs15_add_df(struct sc_pkcs15_card *p15card, { struct sc_pkcs15_df *p = p15card->df_list, *newdf; - newdf = malloc(sizeof(struct sc_pkcs15_df)); + newdf = (struct sc_pkcs15_df *) malloc(sizeof(struct sc_pkcs15_df)); if (newdf == NULL) return SC_ERROR_OUT_OF_MEMORY; memset(newdf, 0, sizeof(struct sc_pkcs15_df)); @@ -860,7 +860,7 @@ int sc_pkcs15_encode_df(struct sc_context *ctx, free(buf); return r; } - buf = realloc(buf, bufsize + tmpsize); + buf = (u8 *) realloc(buf, bufsize + tmpsize); memcpy(buf + bufsize, tmp, tmpsize); free(tmp); bufsize += tmpsize; @@ -911,7 +911,7 @@ int sc_pkcs15_parse_df(struct sc_pkcs15_card *p15card, &buf, &bufsize, &df->file); p = buf; do { - obj = malloc(sizeof(struct sc_pkcs15_object)); + obj = (struct sc_pkcs15_object *) malloc(sizeof(struct sc_pkcs15_object)); if (obj == NULL) { r = SC_ERROR_OUT_OF_MEMORY; goto ret; @@ -968,7 +968,7 @@ int sc_pkcs15_read_file(struct sc_pkcs15_card *p15card, *file_out = file; else sc_file_free(file); - data = malloc(len); + data = (u8 *) malloc(len); if (data == NULL) { sc_unlock(p15card->card); return SC_ERROR_OUT_OF_MEMORY; diff --git a/src/libopensc/pkcs15.h b/src/libopensc/pkcs15.h index e043767c..d7c8be77 100644 --- a/src/libopensc/pkcs15.h +++ b/src/libopensc/pkcs15.h @@ -21,12 +21,12 @@ #ifndef _OPENSC_PKCS15_H #define _OPENSC_PKCS15_H -#include - #ifdef __cplusplus extern "C" { #endif +#include + #define SC_PKCS15_CACHE_DIR ".eid" #define SC_PKCS15_PIN_MAGIC 0x31415926 @@ -333,7 +333,7 @@ typedef struct sc_pkcs15_card { * valid PKCS #15 file structure. */ int sc_pkcs15_bind(struct sc_card *card, struct sc_pkcs15_card **pkcs15_card); -/* sc_pkcs_unbind: Releases a PKCS #15 card object, and frees any +/* sc_pkcs15_unbind: Releases a PKCS #15 card object, and frees any * memory allocations done on the card object. */ int sc_pkcs15_unbind(struct sc_pkcs15_card *card); @@ -347,6 +347,8 @@ int sc_pkcs15_get_objects_cond(struct sc_pkcs15_card *card, int type, struct sc_pkcs15_card * sc_pkcs15_card_new(); void sc_pkcs15_card_free(struct sc_pkcs15_card *p15card); +void sc_pkcs15_print_card(const struct sc_pkcs15_card *card); + int sc_pkcs15_decipher(struct sc_pkcs15_card *p15card, const struct sc_pkcs15_object *prkey_obj, const u8 *in, size_t inlen, u8 *out, size_t outlen); diff --git a/src/libopensc/reader-ctapi.c b/src/libopensc/reader-ctapi.c index f11229d2..bf9522fc 100644 --- a/src/libopensc/reader-ctapi.c +++ b/src/libopensc/reader-ctapi.c @@ -218,7 +218,7 @@ static struct ctapi_module * add_module(struct ctapi_global_private_data *gpriv, int i; i = gpriv->module_count; - gpriv->modules = realloc(gpriv->modules, sizeof(struct ctapi_module) * (i+1)); + gpriv->modules = (struct ctapi_module *) realloc(gpriv->modules, sizeof(struct ctapi_module) * (i+1)); gpriv->modules[i].name = strdup(name); gpriv->modules[i].dlhandle = dlhandle; gpriv->modules[i].ctn_count = 0; @@ -250,13 +250,13 @@ static int ctapi_load_module(struct sc_context *ctx, error(ctx, "Unable to open shared library '%s'\n", val); return -1; } - r = sc_module_get_address(ctx, dlh, (void *) &funcs.CT_init, "CT_init"); + r = sc_module_get_address(ctx, dlh, (void **) &funcs.CT_init, "CT_init"); if (r != SC_SUCCESS) goto symerr; - r = sc_module_get_address(ctx, dlh, (void *) &funcs.CT_close, "CT_close"); + r = sc_module_get_address(ctx, dlh, (void **) &funcs.CT_close, "CT_close"); if (r != SC_SUCCESS) goto symerr; - r = sc_module_get_address(ctx, dlh, (void *) &funcs.CT_data, "CT_data"); + r = sc_module_get_address(ctx, dlh, (void **) &funcs.CT_data, "CT_data"); if (r != SC_SUCCESS) goto symerr; mod = add_module(gpriv, val, dlh); @@ -277,8 +277,8 @@ static int ctapi_load_module(struct sc_context *ctx, error(ctx, "CT_init() failed with %d\n", rv); continue; } - reader = malloc(sizeof(struct sc_reader)); - priv = malloc(sizeof(struct ctapi_private_data)); + reader = (struct sc_reader *) malloc(sizeof(struct sc_reader)); + priv = (struct ctapi_private_data *) malloc(sizeof(struct ctapi_private_data)); memset(reader, 0, sizeof(*reader)); reader->drv_data = priv; reader->ops = &ctapi_ops; @@ -319,7 +319,7 @@ static int ctapi_init(struct sc_context *ctx, void **reader_data) struct ctapi_global_private_data *gpriv; scconf_block **blocks = NULL, *conf_block = NULL; - gpriv = malloc(sizeof(struct ctapi_global_private_data)); + gpriv = (struct ctapi_global_private_data *) malloc(sizeof(struct ctapi_global_private_data)); if (gpriv == NULL) return SC_ERROR_OUT_OF_MEMORY; memset(gpriv, 0, sizeof(*gpriv)); diff --git a/src/libopensc/reader-pcsc.c b/src/libopensc/reader-pcsc.c index 48b85343..5dd4f704 100644 --- a/src/libopensc/reader-pcsc.c +++ b/src/libopensc/reader-pcsc.c @@ -207,7 +207,7 @@ static int pcsc_connect(struct sc_reader *reader, struct sc_slot_info *slot) return r; if (!(slot->flags & SC_SLOT_CARD_PRESENT)) return SC_ERROR_CARD_NOT_PRESENT; - pslot = malloc(sizeof(struct pcsc_slot_data)); + pslot = (struct pcsc_slot_data *) malloc(sizeof(struct pcsc_slot_data)); if (pslot == NULL) return SC_ERROR_OUT_OF_MEMORY; rv = SCardConnect(priv->pcsc_ctx, priv->reader_name, @@ -302,7 +302,7 @@ static int pcsc_init(struct sc_context *ctx, void **reader_data) SCardReleaseContext(pcsc_ctx); return 0; /* No readers configured */ } - gpriv = malloc(sizeof(struct pcsc_global_private_data)); + gpriv = (struct pcsc_global_private_data *) malloc(sizeof(struct pcsc_global_private_data)); if (gpriv == NULL) { SCardReleaseContext(pcsc_ctx); return SC_ERROR_OUT_OF_MEMORY; @@ -315,8 +315,8 @@ static int pcsc_init(struct sc_context *ctx, void **reader_data) (LPDWORD) &reader_buf_size); p = reader_buf; do { - struct sc_reader *reader = malloc(sizeof(struct sc_reader)); - struct pcsc_private_data *priv = malloc(sizeof(struct pcsc_private_data)); + struct sc_reader *reader = (struct sc_reader *) malloc(sizeof(struct sc_reader)); + struct pcsc_private_data *priv = (struct pcsc_private_data *) malloc(sizeof(struct pcsc_private_data)); struct sc_slot_info *slot; if (reader == NULL || priv == NULL) { diff --git a/src/libopensc/sc.c b/src/libopensc/sc.c index de9e1eae..61043cb8 100644 --- a/src/libopensc/sc.c +++ b/src/libopensc/sc.c @@ -173,7 +173,7 @@ int sc_append_path_id(struct sc_path *dest, const u8 *id, size_t idlen) int sc_file_add_acl_entry(struct sc_file *file, unsigned int operation, unsigned int method, unsigned long key_ref) { - struct sc_acl_entry *p, *new; + struct sc_acl_entry *p, *_new; assert(file != NULL); assert(operation < SC_MAX_AC_OPS); @@ -202,21 +202,21 @@ int sc_file_add_acl_entry(struct sc_file *file, unsigned int operation, file->acl[operation] = NULL; } - new = malloc(sizeof(struct sc_acl_entry)); - if (new == NULL) + _new = (struct sc_acl_entry *) malloc(sizeof(struct sc_acl_entry)); + if (_new == NULL) return SC_ERROR_OUT_OF_MEMORY; - new->method = method; - new->key_ref = key_ref; - new->next = NULL; + _new->method = method; + _new->key_ref = key_ref; + _new->next = NULL; p = file->acl[operation]; if (p == NULL) { - file->acl[operation] = new; + file->acl[operation] = _new; return 0; } while (p->next != NULL) p = p->next; - p->next = new; + p->next = _new; return 0; } @@ -274,7 +274,7 @@ void sc_file_clear_acl_entries(struct sc_file *file, unsigned int operation) struct sc_file * sc_file_new() { - struct sc_file *file = malloc(sizeof(struct sc_file)); + struct sc_file *file = (struct sc_file *) malloc(sizeof(struct sc_file)); if (file == NULL) return NULL; @@ -333,7 +333,7 @@ int sc_file_set_sec_attr(struct sc_file *file, const u8 *sec_attr, file->sec_attr_len = 0; return 0; } - file->sec_attr = realloc(file->sec_attr, sec_attr_len); + file->sec_attr = (u8 *) realloc(file->sec_attr, sec_attr_len); if (file->sec_attr == NULL) { file->sec_attr_len = 0; return SC_ERROR_OUT_OF_MEMORY; @@ -356,7 +356,7 @@ int sc_file_set_prop_attr(struct sc_file *file, const u8 *prop_attr, file->prop_attr_len = 0; return 0; } - file->prop_attr = realloc(file->prop_attr, prop_attr_len); + file->prop_attr = (u8 *) realloc(file->prop_attr, prop_attr_len); if (file->prop_attr == NULL) { file->prop_attr_len = 0; return SC_ERROR_OUT_OF_MEMORY; @@ -379,7 +379,7 @@ int sc_file_set_type_attr(struct sc_file *file, const u8 *type_attr, file->type_attr_len = 0; return 0; } - file->type_attr = realloc(file->type_attr, type_attr_len); + file->type_attr = (u8 *) realloc(file->type_attr, type_attr_len); if (file->type_attr == NULL) { file->type_attr_len = 0; return SC_ERROR_OUT_OF_MEMORY; diff --git a/src/libopensc/types.h b/src/libopensc/types.h index ffc00cc9..206ed55e 100644 --- a/src/libopensc/types.h +++ b/src/libopensc/types.h @@ -21,6 +21,10 @@ #ifndef _OPENSC_TYPES_H #define _OPENSC_TYPES_H +#ifdef __cplusplus +extern "C" { +#endif + typedef unsigned char u8; #define SC_MAX_OBJECT_ID_OCTETS 16 @@ -94,4 +98,8 @@ typedef struct sc_apdu { unsigned int sw1, sw2; /* Status words returned in R-APDU */ } sc_apdu_t; +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/openssh/opensc-ssh.c b/src/openssh/opensc-ssh.c index 6fd73f2f..ccc5894a 100644 --- a/src/openssh/opensc-ssh.c +++ b/src/openssh/opensc-ssh.c @@ -76,7 +76,7 @@ u8 * bignum_to_buf(BIGNUM *value, int *length, int *skip) /* Function ripped from bufaux.c in OpenSSH * Compliments to Tatu Ylönen */ int bytes = BN_num_bytes(value) + 1; - u8 *buf = malloc(bytes); + u8 *buf = (u8 *) malloc(bytes); int oi; int hasnohigh = 0; buf[0] = '\0'; @@ -124,7 +124,7 @@ int put_string(const u8 *in, int inlen, u8 *out, int outlen, int *skip) int write_ssh_key(struct sc_pkcs15_cert_info *cinfo, RSA *rsa) { - u8 *buf = malloc(10240), *p = buf, *num; + u8 *buf = (u8 *) malloc(10240), *p = buf, *num; int r, len, skip, left = 10240; FILE *outf; @@ -149,7 +149,7 @@ int write_ssh_key(struct sc_pkcs15_cert_info *cinfo, RSA *rsa) free(num); len = p - buf; - p = malloc(len*5/3); + p = (u8 *) malloc(len*5/3); r = sc_base64_encode(buf, len, p, len*5/3, 0); if (r) { fprintf(stderr, "Base64 encoding failed: %s\n", sc_strerror(r)); @@ -208,7 +208,7 @@ int extract_key(void) count = r; if (opt_cert) { for (i = 0; i < count; i++) { - cinfo = objs[i]->data; + cinfo = (struct sc_pkcs15_cert_info *) objs[i]->data; if (sc_pkcs15_compare_id(&id, &cinfo->id) == 1) break; @@ -219,7 +219,7 @@ int extract_key(void) } } else { i = 0; - cinfo = objs[i]->data; + cinfo = (struct sc_pkcs15_cert_info *) objs[i]->data; } if (!quiet) fprintf(stderr, "Using certificate '%s'.\n", objs[i]->label); diff --git a/src/pam/pam_opensc.c b/src/pam/pam_opensc.c index be205aa8..d901f7cc 100644 --- a/src/pam/pam_opensc.c +++ b/src/pam/pam_opensc.c @@ -145,7 +145,7 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t * pamh, int flags, int argc, con return rv; } /* Check tty */ - rv = pam_get_item(pamh, PAM_TTY, (void *) &tty); + rv = pam_get_item(pamh, PAM_TTY, (PAM_CONST void **) &tty); /* Get the name of the service */ rv = pam_get_item(pamh, PAM_SERVICE, (PAM_CONST void **) &service); if (rv != PAM_SUCCESS) { @@ -247,14 +247,14 @@ PAM_EXTERN int pam_sm_open_session(pam_handle_t * pamh, int flags, int argc, if (sctx.method < 0) { return PAM_SESSION_ERR; } - rv = pam_get_item(pamh, PAM_USER, (void *) &user); + rv = pam_get_item(pamh, PAM_USER, (PAM_CONST void **) &user); if (!user || rv != PAM_SUCCESS) { opensc_pam_log(LOG_CRIT, pamh, "open_session - error recovering username\n"); return PAM_SESSION_ERR; /* How did we get authenticated with no username?! */ } if (on(OPENSC_DEBUG, ctrl)) opensc_pam_log(LOG_INFO, pamh, "Pam user name %s\n", user); - rv = pam_get_item(pamh, PAM_SERVICE, (void *) &service); + rv = pam_get_item(pamh, PAM_SERVICE, (PAM_CONST void **) &service); if (!service || rv != PAM_SUCCESS) { opensc_pam_log(LOG_CRIT, pamh, "open_session - error recovering service\n"); return PAM_SESSION_ERR; @@ -290,12 +290,12 @@ PAM_EXTERN int pam_sm_close_session(pam_handle_t * pamh, int flags, int argc, if (sctx.method < 0) { return PAM_SESSION_ERR; } - rv = pam_get_item(pamh, PAM_USER, (void *) &user); + rv = pam_get_item(pamh, PAM_USER, (PAM_CONST void **) &user); if (!user || rv != PAM_SUCCESS) { opensc_pam_log(LOG_CRIT, pamh, "close_session - error recovering username\n"); return PAM_SESSION_ERR; /* How did we get authenticated with no username?! */ } - rv = pam_get_item(pamh, PAM_SERVICE, (void *) &service); + rv = pam_get_item(pamh, PAM_SERVICE, (PAM_CONST void **) &service); if (!service || rv != PAM_SUCCESS) { opensc_pam_log(LOG_CRIT, pamh, "close_session - error recovering service\n"); return PAM_SESSION_ERR; diff --git a/src/pam/pam_support.c b/src/pam/pam_support.c index d58a4821..6f5d3d31 100644 --- a/src/pam/pam_support.c +++ b/src/pam/pam_support.c @@ -195,7 +195,7 @@ int _set_ctrl(pam_handle_t * pamh, int flags, int argc, const char **argv) static void _cleanup(pam_handle_t * pamh, void *x, int error_status) { - _pam_delete(x); + _pam_delete((char *) x); } /* ************************************************************** * diff --git a/src/pkcs11/framework-pkcs15.c b/src/pkcs11/framework-pkcs15.c index 1e6177b2..9be5d4a5 100644 --- a/src/pkcs11/framework-pkcs15.c +++ b/src/pkcs11/framework-pkcs15.c @@ -242,7 +242,7 @@ static void pkcs15_init_slot(struct sc_pkcs15_card *card, slot->token_info.flags = CKF_USER_PIN_INITIALIZED | CKF_TOKEN_INITIALIZED | CKF_WRITE_PROTECTED; - slot->fw_data = fw_data = calloc(1, sizeof(*fw_data)); + slot->fw_data = fw_data = (struct pkcs15_slot_data *) calloc(1, sizeof(*fw_data)); fw_data->auth_obj = auth; if (auth != NULL) { @@ -639,7 +639,7 @@ static CK_RV pkcs15_create_private_key(struct sc_pkcs11_card *p11card, if (attr->ulValueLen > 1024) return CKR_ATTRIBUTE_VALUE_INVALID; bn->len = attr->ulValueLen; - bn->data = attr->pValue; + bn->data = (u8 *) attr->pValue; } } @@ -729,7 +729,7 @@ static CK_RV pkcs15_create_public_key(struct sc_pkcs11_card *p11card, if (attr->ulValueLen > 1024) return CKR_ATTRIBUTE_VALUE_INVALID; bn->len = attr->ulValueLen; - bn->data = attr->pValue; + bn->data = (u8 *) attr->pValue; } } @@ -802,7 +802,7 @@ static CK_RV pkcs15_create_certificate(struct sc_pkcs11_card *p11card, break; case CKA_VALUE: args.der_encoded.len = attr->ulValueLen; - args.der_encoded.value = attr->pValue; + args.der_encoded.value = (u8 *) attr->pValue; break; default: /* ignore unknown attrs, or flag error? */ @@ -837,10 +837,10 @@ static CK_RV pkcs15_create_object(struct sc_pkcs11_card *p11card, { struct sc_profile *profile = NULL; struct pkcs15_slot_data *data; - CK_OBJECT_CLASS class; + CK_OBJECT_CLASS _class; int rv, rc; - rv = attr_find(pTemplate, ulCount, CKA_CLASS, &class, NULL); + rv = attr_find(pTemplate, ulCount, CKA_CLASS, &_class, NULL); if (rv != CKR_OK) return rv; @@ -861,7 +861,7 @@ static CK_RV pkcs15_create_object(struct sc_pkcs11_card *p11card, sc_pkcs15init_set_pin_data(profile, SC_PKCS15INIT_USER_PIN, data->pin[CKU_USER].value, data->pin[CKU_USER].len); - switch (class) { + switch (_class) { case CKO_PRIVATE_KEY: rv = pkcs15_create_private_key(p11card, slot, profile, pTemplate, ulCount, phObject); @@ -987,7 +987,7 @@ pkcs15_cert_cmp_attribute(struct sc_pkcs11_session *session, case CKA_ISSUER: if (cert->certificate->issuer_len == 0) break; - data = attr->pValue; + data = (u8 *) attr->pValue; len = attr->ulValueLen; /* SEQUENCE is tag 0x30, SET is 0x31 * I know this code is icky, but hey... this is netscape @@ -1423,7 +1423,7 @@ asn1_sequence_wrapper(const u8 *data, size_t len, CK_ATTRIBUTE_PTR attr) check_attribute_buffer(attr, len + 1 + sizeof(len)); - dest = attr->pValue; + dest = (u8 *) attr->pValue; *dest++ = 0x30; /* SEQUENCE tag */ if (len <= 127) { *dest++ = len; diff --git a/src/pkcs11/pkcs11-global.c b/src/pkcs11/pkcs11-global.c index c95defd0..f8d1789d 100644 --- a/src/pkcs11/pkcs11-global.c +++ b/src/pkcs11/pkcs11-global.c @@ -27,7 +27,7 @@ struct sc_pkcs11_pool session_pool; struct sc_pkcs11_slot virtual_slots[SC_PKCS11_MAX_VIRTUAL_SLOTS]; struct sc_pkcs11_card card_table[SC_PKCS11_MAX_READERS]; -CK_FUNCTION_LIST pkcs11_function_list; +extern CK_FUNCTION_LIST pkcs11_function_list; CK_RV C_Initialize(CK_VOID_PTR pReserved) { diff --git a/src/pkcs11/pkcs11-object.c b/src/pkcs11/pkcs11-object.c index 51ca03ed..1ff8ad1b 100644 --- a/src/pkcs11/pkcs11-object.c +++ b/src/pkcs11/pkcs11-object.c @@ -89,7 +89,7 @@ CK_RV C_GetAttributeValue(CK_SESSION_HANDLE hSession, /* the session's handle debug(context, "Object %d, Attribute 0x%x\n", hObject, pTemplate[i].type); rv = object->ops->get_attribute(session, object, &pTemplate[i]); if (rv != CKR_OK) - pTemplate[i].ulValueLen = -1; + pTemplate[i].ulValueLen = (CK_ULONG) -1; } return CKR_OK; diff --git a/src/pkcs11/sc-pkcs11.h b/src/pkcs11/sc-pkcs11.h index 7a9ca019..c702f689 100644 --- a/src/pkcs11/sc-pkcs11.h +++ b/src/pkcs11/sc-pkcs11.h @@ -29,6 +29,10 @@ #include #include "rsaref/pkcs11.h" +#ifdef __cplusplus +extern "C" { +#endif + #define SC_PKCS11_MAX_VIRTUAL_SLOTS 4 #define SC_PKCS11_MAX_READERS 2 @@ -242,4 +246,8 @@ CK_RV attr_find_ptr(CK_ATTRIBUTE_PTR, CK_ULONG, CK_ULONG, void **, size_t *); CK_RV attr_find_var(CK_ATTRIBUTE_PTR, CK_ULONG, CK_ULONG, void *, size_t *); CK_RV attr_extract(CK_ATTRIBUTE_PTR, void *, size_t *); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/pkcs11/secretkey.c b/src/pkcs11/secretkey.c index 9da12aaa..86bbf2c8 100644 --- a/src/pkcs11/secretkey.c +++ b/src/pkcs11/secretkey.c @@ -58,7 +58,7 @@ extern struct sc_pkcs11_object_ops pkcs11_secret_key_ops; CK_RV sc_pkcs11_create_secret_key(struct sc_pkcs11_session *session, const u8 *value, size_t value_len, - CK_ATTRIBUTE_PTR template, + CK_ATTRIBUTE_PTR _template, CK_ULONG attribute_count, struct sc_pkcs11_object **out) { @@ -66,8 +66,8 @@ sc_pkcs11_create_secret_key(struct sc_pkcs11_session *session, CK_ATTRIBUTE_PTR attr; int n, rv; - if (!(key = calloc(1, sizeof(*key))) - || !(key->value = malloc(value_len))) { + if (!(key = (struct pkcs11_secret_key *) calloc(1, sizeof(*key))) + || !(key->value = (CK_BYTE *) malloc(value_len))) { pkcs11_secret_key_ops.release(key); return CKR_HOST_MEMORY; /* XXX correct? */ } @@ -76,7 +76,7 @@ sc_pkcs11_create_secret_key(struct sc_pkcs11_session *session, key->object.ops = &pkcs11_secret_key_ops; /* Make sure the key type is given in the template */ - for (n = attribute_count, attr = template; n--; attr++) { + for (n = attribute_count, attr = _template; n--; attr++) { if (attr->type == CKA_KEY_TYPE) { set_attr(key->type, attr); break; @@ -88,7 +88,7 @@ sc_pkcs11_create_secret_key(struct sc_pkcs11_session *session, } /* Set all the other attributes */ - for (n = attribute_count, attr = template; n--; attr++) { + for (n = attribute_count, attr = _template; n--; attr++) { rv = key->object.ops->set_attribute(session, key, attr); if (rv != CKR_OK) { pkcs11_secret_key_ops.release(key); @@ -139,7 +139,7 @@ sc_pkcs11_secret_key_set_attribute(struct sc_pkcs11_session *session, case CKA_LABEL: if (key->label) free(key->label); - key->label = strdup(attr->pValue); + key->label = strdup((const char *) attr->pValue); break; case CKA_TOKEN: set_attr(ck_bbool, attr); @@ -149,7 +149,7 @@ sc_pkcs11_secret_key_set_attribute(struct sc_pkcs11_session *session, case CKA_VALUE: if (key->value) free(key->value); - key->value = malloc(attr->ulValueLen); + key->value = (CK_BYTE *) malloc(attr->ulValueLen); key->value_len = attr->ulValueLen; memcpy(key->value, attr->pValue, key->value_len); break; diff --git a/src/pkcs15init/pkcs15-cflex.c b/src/pkcs15init/pkcs15-cflex.c index d027ba51..85754e2c 100644 --- a/src/pkcs15init/pkcs15-cflex.c +++ b/src/pkcs15init/pkcs15-cflex.c @@ -83,15 +83,15 @@ cflex_new_pin(struct sc_profile *profile, struct sc_card *card, { sc_file_t *pinfile; struct sc_pkcs15_pin_info tmpinfo; - char template[30]; + char _template[30]; int pin_tries, puk_tries; int r; index++; - sprintf(template, "pinfile-%d", index); + sprintf(_template, "pinfile-%d", index); /* Profile must define a "pinfile" for each PIN */ - if (sc_profile_get_file(profile, template, &pinfile) < 0) { - profile->cbs->error("Profile doesn't define \"%s\"", template); + if (sc_profile_get_file(profile, _template, &pinfile) < 0) { + profile->cbs->error("Profile doesn't define \"%s\"", _template); return SC_ERROR_INVALID_ARGUMENTS; } info->path = pinfile->path; diff --git a/src/pkcs15init/pkcs15-gpk.c b/src/pkcs15init/pkcs15-gpk.c index d3f87681..3b412300 100644 --- a/src/pkcs15init/pkcs15-gpk.c +++ b/src/pkcs15init/pkcs15-gpk.c @@ -43,14 +43,17 @@ struct pkcomp { u8 * data; unsigned int size; }; + +struct pkpart { + struct pkcomp components[7]; + unsigned int count; + unsigned int size; +}; + struct pkdata { unsigned int algo; unsigned int usage; - struct pkpart { - struct pkcomp components[7]; - unsigned int count; - unsigned int size; - } public, private; + struct pkpart _public, _private; unsigned int bits, bytes; }; @@ -752,7 +755,7 @@ gpk_add_bignum(struct pkpart *part, unsigned int tag, memset(comp, 0, sizeof(*comp)); comp->tag = tag; comp->size = size + 1; - comp->data = malloc(size + 1); + comp->data = (u8 *) malloc(size + 1); /* Add the tag */ comp->data[0] = tag; @@ -788,8 +791,8 @@ gpk_encode_rsa_key(struct sc_profile *profile, p->bits = p->bytes << 3; /* Set up the list of public elements */ - gpk_add_bignum(&p->public, 0x01, &rsa->modulus, 0); - gpk_add_bignum(&p->public, 0x07, &rsa->exponent, 0); + gpk_add_bignum(&p->_public, 0x01, &rsa->modulus, 0); + gpk_add_bignum(&p->_public, 0x07, &rsa->exponent, 0); /* Set up the list of private elements */ if (!rsa->p.len || !rsa->q.len || !rsa->dmp1.len || !rsa->dmq1.len || !rsa->iqmp.len) { @@ -798,14 +801,14 @@ gpk_encode_rsa_key(struct sc_profile *profile, error(profile, "incomplete RSA private key"); return SC_ERROR_INVALID_ARGUMENTS; } - gpk_add_bignum(&p->private, 0x04, &rsa->d, 0); + gpk_add_bignum(&p->_private, 0x04, &rsa->d, 0); } else if (5 * (p->bytes / 2) < 256) { /* All CRT elements are stored in one record */ struct pkcomp *comp; unsigned int K = p->bytes / 2; u8 *crtbuf; - crtbuf = malloc(5 * K + 1); + crtbuf = (u8 *) malloc(5 * K + 1); crtbuf[0] = 0x05; gpk_bn2bin(crtbuf + 1 + 0 * K, &rsa->p, K); @@ -814,7 +817,7 @@ gpk_encode_rsa_key(struct sc_profile *profile, gpk_bn2bin(crtbuf + 1 + 3 * K, &rsa->dmp1, K); gpk_bn2bin(crtbuf + 1 + 4 * K, &rsa->dmq1, K); - comp = &p->private.components[p->private.count++]; + comp = &p->_private.components[p->_private.count++]; comp->tag = 0x05; comp->size = 5 * K + 1; comp->data = crtbuf; @@ -822,11 +825,11 @@ gpk_encode_rsa_key(struct sc_profile *profile, /* CRT elements stored in individual records. * Make sure they're all fixed length even if they're * shorter */ - gpk_add_bignum(&p->private, 0x51, &rsa->p, p->bytes/2); - gpk_add_bignum(&p->private, 0x52, &rsa->q, p->bytes/2); - gpk_add_bignum(&p->private, 0x53, &rsa->iqmp, p->bytes/2); - gpk_add_bignum(&p->private, 0x54, &rsa->dmp1, p->bytes/2); - gpk_add_bignum(&p->private, 0x55, &rsa->dmq1, p->bytes/2); + gpk_add_bignum(&p->_private, 0x51, &rsa->p, p->bytes/2); + gpk_add_bignum(&p->_private, 0x52, &rsa->q, p->bytes/2); + gpk_add_bignum(&p->_private, 0x53, &rsa->iqmp, p->bytes/2); + gpk_add_bignum(&p->_private, 0x54, &rsa->dmp1, p->bytes/2); + gpk_add_bignum(&p->_private, 0x55, &rsa->dmq1, p->bytes/2); } return 0; @@ -868,13 +871,13 @@ gpk_encode_dsa_key(struct sc_profile *profile, } /* Set up the list of public elements */ - gpk_add_bignum(&p->public, 0x09, &dsa->p, 0); - gpk_add_bignum(&p->public, 0x0a, &dsa->q, 0); - gpk_add_bignum(&p->public, 0x0b, &dsa->g, 0); - gpk_add_bignum(&p->public, 0x0c, &dsa->pub, 0); + gpk_add_bignum(&p->_public, 0x09, &dsa->p, 0); + gpk_add_bignum(&p->_public, 0x0a, &dsa->q, 0); + gpk_add_bignum(&p->_public, 0x0b, &dsa->g, 0); + gpk_add_bignum(&p->_public, 0x0c, &dsa->pub, 0); /* Set up the list of private elements */ - gpk_add_bignum(&p->private, 0x0d, &dsa->priv, 0); + gpk_add_bignum(&p->_private, 0x0d, &dsa->priv, 0); return 0; } @@ -886,18 +889,18 @@ gpk_store_pk(struct sc_profile *profile, struct sc_card *card, int r; /* Compute length of private/public key parts */ - gpk_compute_publen(&p->public); - gpk_compute_privlen(&p->private); + gpk_compute_publen(&p->_public); + gpk_compute_privlen(&p->_private); if (card->ctx->debug) printf("Storing pk: %u bits, pub %u bytes, priv %u bytes\n", - p->bits, p->bytes, p->private.size); + p->bits, p->bytes, p->_private.size); /* Strange, strange, strange... when I create the public part with * the exact size of 8 + PK elements, the card refuses to store * the last record even though there's enough room in the file. * XXX: Check why */ - file->size = p->public.size + 8 + p->private.size + 8; + file->size = p->_public.size + 8 + p->_private.size + 8; r = gpk_pkfile_create(profile, card, file); if (r < 0) return r; @@ -909,17 +912,17 @@ gpk_store_pk(struct sc_profile *profile, struct sc_card *card, return r; /* Put the public key elements */ - r = gpk_pkfile_update_public(profile, card, &p->public); + r = gpk_pkfile_update_public(profile, card, &p->_public); if (r < 0) return r; /* Create the private key part */ - r = gpk_pkfile_init_private(card, file, p->private.size); + r = gpk_pkfile_init_private(card, file, p->_private.size); if (r < 0) return r; /* Now store the private key elements */ - r = gpk_pkfile_update_private(profile, card, file, &p->private); + r = gpk_pkfile_update_private(profile, card, file, &p->_private); return r; } diff --git a/src/pkcs15init/pkcs15-init.h b/src/pkcs15init/pkcs15-init.h index 12706ca4..7ba0be69 100644 --- a/src/pkcs15init/pkcs15-init.h +++ b/src/pkcs15init/pkcs15-init.h @@ -7,6 +7,10 @@ #ifndef PKCS15_INIT_H #define PKCS15_INIT_H +#ifdef __cplusplus +extern "C" { +#endif + #include struct sc_profile; /* opaque type */ @@ -180,4 +184,8 @@ extern int sc_pkcs15init_get_label(struct sc_profile *, const char **); extern void sc_pkcs15init_set_pin_data(struct sc_profile *, int, const void *, size_t); +#ifdef __cplusplus +} +#endif + #endif /* PKCS15_INIT_H */ diff --git a/src/pkcs15init/pkcs15-lib.c b/src/pkcs15init/pkcs15-lib.c index b63b5bb1..4ddbd150 100644 --- a/src/pkcs15init/pkcs15-lib.c +++ b/src/pkcs15init/pkcs15-lib.c @@ -337,7 +337,6 @@ aodf_add_pin(struct sc_pkcs15_card *p15card, struct sc_profile *profile, { struct sc_pkcs15_pin_info *info; struct sc_pkcs15_object *object; - int r; info = (struct sc_pkcs15_pin_info *) calloc(1, sizeof(*info)); *info = *pin; @@ -443,7 +442,7 @@ sc_pkcs15init_store_private_key(struct sc_pkcs15_card *p15card, } } - key_info = calloc(1, sizeof(*key_info)); + key_info = (struct sc_pkcs15_prkey_info *) calloc(1, sizeof(*key_info)); key_info->id = keyargs->id; key_info->usage = usage; key_info->native = 1; @@ -451,7 +450,7 @@ sc_pkcs15init_store_private_key(struct sc_pkcs15_card *p15card, key_info->modulus_length = keybits; /* path set by card driver */ - object = calloc(1, sizeof(*object)); + object = (struct sc_pkcs15_object *) calloc(1, sizeof(*object)); object->type = type; object->data = key_info; object->flags = DEFAULT_PRKEY_FLAGS; @@ -563,12 +562,12 @@ sc_pkcs15init_store_public_key(struct sc_pkcs15_card *p15card, if ((label = keyargs->label) == NULL) label = "Public Key"; - key_info = calloc(1, sizeof(*key_info)); + key_info = (struct sc_pkcs15_pubkey_info *) calloc(1, sizeof(*key_info)); key_info->id = keyargs->id; key_info->usage = usage; key_info->modulus_length = keybits; - object = calloc(1, sizeof(*object)); + object = (struct sc_pkcs15_object *) calloc(1, sizeof(*object)); object->type = type; object->data = key_info; object->flags = DEFAULT_PUBKEY_FLAGS; @@ -641,10 +640,10 @@ sc_pkcs15init_store_certificate(struct sc_pkcs15_card *p15card, } } - cert_info = calloc(1, sizeof(*cert_info)); + cert_info = (struct sc_pkcs15_cert_info *) calloc(1, sizeof(*cert_info)); cert_info->id = args->id; - object = calloc(1, sizeof(*object)); + object = (struct sc_pkcs15_object *) calloc(1, sizeof(*object)); object->type = SC_PKCS15_TYPE_CERT_X509; object->data = cert_info; object->flags = DEFAULT_CERT_FLAGS; @@ -729,11 +728,11 @@ static unsigned int x509_to_pkcs15_public_key_usage[16] = { }; static int -sc_pkcs15init_map_usage(unsigned long x509_usage, int private) +sc_pkcs15init_map_usage(unsigned long x509_usage, int _private) { unsigned int p15_usage, n, *bits; - bits = private? x509_to_pkcs15_private_key_usage + bits = _private? x509_to_pkcs15_private_key_usage : x509_to_pkcs15_public_key_usage; for (n = p15_usage = 0; n < 16; n++) { if (x509_usage & (1 << n)) @@ -1011,7 +1010,7 @@ void sc_pkcs15init_set_pin_data(struct sc_profile *profile, int pin_id, const void *value, size_t len) { - sc_profile_set_secret(profile, SC_AC_SYMBOLIC, pin_id, value, len); + sc_profile_set_secret(profile, SC_AC_SYMBOLIC, pin_id, (const u8 *) value, len); } /* @@ -1245,7 +1244,7 @@ sc_pkcs15init_update_file(struct sc_profile *profile, struct sc_card *card, /* Present authentication info needed */ r = sc_pkcs15init_authenticate(profile, card, file, SC_AC_OP_UPDATE); if (r >= 0 && datalen) - r = sc_update_binary(card, 0, data, datalen, 0); + r = sc_update_binary(card, 0, (const u8 *) data, datalen, 0); return r; } diff --git a/src/pkcs15init/profile.h b/src/pkcs15init/profile.h index 84559a7a..0b6f3150 100644 --- a/src/pkcs15init/profile.h +++ b/src/pkcs15init/profile.h @@ -7,6 +7,10 @@ #ifndef _OPENSC_PROFILE_H #define _OPENSC_PROFILE_H +#ifdef __cplusplus +extern "C" { +#endif + #include #ifndef SC_PKCS15_PROFILE_DIRECTORY @@ -95,5 +99,8 @@ int sc_profile_get_file_by_path(struct sc_profile *, int sc_profile_get_path(struct sc_profile *, const char *, struct sc_path *); +#ifdef __cplusplus +} +#endif #endif /* _OPENSC_PROFILE_H */ diff --git a/src/scam/.cvsignore b/src/scam/.cvsignore index fe633271..28bdbdc5 100644 --- a/src/scam/.cvsignore +++ b/src/scam/.cvsignore @@ -12,6 +12,7 @@ *~ *.lo *.la +*.u gmon.out core Makefile diff --git a/src/scam/p15_eid.c b/src/scam/p15_eid.c index acfacc3a..be655c11 100644 --- a/src/scam/p15_eid.c +++ b/src/scam/p15_eid.c @@ -132,7 +132,7 @@ int p15_eid_init(scam_context * sctx, int argc, const char **argv) return SCAM_FAILED; /* FIXME: Add support for selecting certificate by ID */ - data->cinfo = data->objs[0]->data; + data->cinfo = (struct sc_pkcs15_cert_info *) data->objs[0]->data; r = sc_pkcs15_find_prkey_by_id(data->p15card, &data->cinfo->id, &data->prkey); if (r != SC_SUCCESS) { @@ -156,7 +156,7 @@ const char *p15_eid_pinentry(scam_context * sctx) if (!sctx->method_data) { return NULL; } - pininfo = data->pin->data; + pininfo = (struct sc_pkcs15_pin_info *) data->pin->data; snprintf(buf, 64, "Enter PIN%d [%s]: ", pininfo->reference, data->pin->label); return buf; } @@ -183,7 +183,7 @@ static int format_eid_dir_path(const char *user, char **buf) if (!pwent) return SCAM_FAILED; - dir = malloc(strlen(pwent->pw_dir) + strlen(eid_path) + 2); + dir = (char *) malloc(strlen(pwent->pw_dir) + strlen(eid_path) + 2); if (!dir) return SCAM_FAILED; strcpy(dir, pwent->pw_dir); @@ -221,7 +221,7 @@ static int get_certificate(const char *user, X509 ** cert_out) r = format_eid_dir_path(user, &dir); if (r != SCAM_SUCCESS) return r; - cert_path = malloc(strlen(dir) + strlen(auth_cert_file) + 2); + cert_path = (char *) malloc(strlen(dir) + strlen(auth_cert_file) + 2); if (!cert_path) { goto end; } @@ -287,7 +287,7 @@ int p15_eid_auth(scam_context * sctx, int argc, const char **argv, scam_log_msg(sctx, "scrandom_get_data failed.\n"); goto end; } - r = sc_pkcs15_verify_pin(data->p15card, data->pin->data, (const u8 *) password, strlen(password)); + r = sc_pkcs15_verify_pin(data->p15card, (struct sc_pkcs15_pin_info *) data->pin->data, (const u8 *) password, strlen(password)); if (r != SC_SUCCESS) { scam_print_msg(sctx, "sc_pkcs15_verify_pin: %s\n", sc_strerror(r)); goto end; diff --git a/src/scam/p15_ldap.c b/src/scam/p15_ldap.c index 7cc3a501..3af05d23 100644 --- a/src/scam/p15_ldap.c +++ b/src/scam/p15_ldap.c @@ -131,7 +131,7 @@ int p15_ldap_init(scam_context * sctx, int argc, const char **argv) return SCAM_FAILED; /* FIXME: Add support for selecting certificate by ID */ - data->cinfo = data->objs[0]->data; + data->cinfo = (struct sc_pkcs15_cert_info *) data->objs[0]->data; r = sc_pkcs15_find_prkey_by_id(data->p15card, &data->cinfo->id, &data->prkey); if (r != SC_SUCCESS) { @@ -160,7 +160,7 @@ const char *p15_ldap_pinentry(scam_context * sctx) if (!sctx->method_data) { return NULL; } - pininfo = data->pin->data; + pininfo = (struct sc_pkcs15_pin_info *) data->pin->data; snprintf(buf, 64, "Enter PIN%d [%s]: ", pininfo->reference, data->pin->label); return buf; } @@ -220,7 +220,7 @@ int p15_ldap_auth(scam_context * sctx, int argc, const char **argv, scam_log_msg(sctx, "scrandom_get_data failed.\n"); goto end; } - r = sc_pkcs15_verify_pin(data->p15card, data->pin->data, (const u8 *) password, strlen(password)); + r = sc_pkcs15_verify_pin(data->p15card, (struct sc_pkcs15_pin_info *) data->pin->data, (const u8 *) password, strlen(password)); if (r != SC_SUCCESS) { scam_print_msg(sctx, "sc_pkcs15_verify_pin: %s\n", sc_strerror(r)); goto end; diff --git a/src/scconf/parse.c b/src/scconf/parse.c index 65a5e62a..c75a09d1 100644 --- a/src/scconf/parse.c +++ b/src/scconf/parse.c @@ -88,7 +88,7 @@ static scconf_item *scconf_item_add(scconf_parser * parser, int type) return item; } } - item = malloc(sizeof(scconf_item)); + item = (scconf_item *) malloc(sizeof(scconf_item)); if (!item) { return NULL; } @@ -114,7 +114,7 @@ static void scconf_block_add(scconf_parser * parser) item = scconf_item_add(parser, SCCONF_ITEM_TYPE_BLOCK); - block = malloc(sizeof(scconf_block)); + block = (scconf_block *) malloc(sizeof(scconf_block)); if (!block) { return; } diff --git a/src/scconf/scconf.c b/src/scconf/scconf.c index be30dd16..d3702056 100644 --- a/src/scconf/scconf.c +++ b/src/scconf/scconf.c @@ -32,13 +32,13 @@ scconf_context *scconf_new(const char *filename) { scconf_context *config; - config = malloc(sizeof(scconf_context)); + config = (scconf_context *) malloc(sizeof(scconf_context)); if (!config) { return NULL; } memset(config, 0, sizeof(scconf_context)); config->filename = filename ? strdup(filename) : NULL; - config->root = malloc(sizeof(scconf_block)); + config->root = (scconf_block *) malloc(sizeof(scconf_block)); if (!config->root) { if (config->filename) { free(config->filename); @@ -95,7 +95,7 @@ scconf_block **scconf_find_blocks(scconf_context * config, const scconf_block * } size = 0; alloc_size = 10; - blocks = realloc(blocks, sizeof(scconf_block *) * alloc_size); + blocks = (scconf_block **) realloc(blocks, sizeof(scconf_block *) * alloc_size); for (item = block->items; item; item = item->next) { if (item->type == SCCONF_ITEM_TYPE_BLOCK && @@ -105,7 +105,7 @@ scconf_block **scconf_find_blocks(scconf_context * config, const scconf_block * } if (size + 1 >= alloc_size) { alloc_size *= 2; - blocks = realloc(blocks, sizeof(scconf_block *) * alloc_size); + blocks = (scconf_block **) realloc(blocks, sizeof(scconf_block *) * alloc_size); } blocks[size++] = item->value.block; } @@ -203,7 +203,7 @@ scconf_list *scconf_list_add(scconf_list ** list, const char *value) { scconf_list *rec, **tmp; - rec = malloc(sizeof(scconf_list)); + rec = (scconf_list *) malloc(sizeof(scconf_list)); if (!rec) { return NULL; } @@ -267,7 +267,7 @@ char *scconf_list_strdup(const scconf_list * list, const char *filler) if (filler) { len += scconf_list_array_length(list) * (strlen(filler) + 1); } - buf = malloc(len); + buf = (char *) malloc(len); if (!buf) { return NULL; } @@ -374,7 +374,7 @@ static int parse_type(scconf_context * config, const scconf_block * block, sccon if (parm) { if (entry->flags & SCCONF_ALLOC) { char **buf = (char **) parm; - *buf = malloc(vallen + 1); + *buf = (char *) malloc(vallen + 1); if (*buf == NULL) { r = 1; break; @@ -422,7 +422,7 @@ static scconf_block **getblocks(scconf_context * config, const scconf_block * bl if (config->debug) { fprintf(stderr, "list found (%s)\n", entry->name); } - blocks = realloc(blocks, sizeof(scconf_block *) * 2); + blocks = (scconf_block **) realloc(blocks, sizeof(scconf_block *) * 2); if (!blocks) return NULL; blocks[0] = (scconf_block *) block; diff --git a/src/scconf/write.c b/src/scconf/write.c index 403ba81e..39670856 100644 --- a/src/scconf/write.c +++ b/src/scconf/write.c @@ -83,7 +83,7 @@ static char *scconf_list_get_string(scconf_list * list) } len = 0; alloc_len = 1024; - buffer = realloc(buffer, alloc_len); + buffer = (char *) realloc(buffer, alloc_len); if (!buffer) { return strdup(""); } @@ -92,7 +92,7 @@ static char *scconf_list_get_string(scconf_list * list) datalen = strlen(list->data); if (len + datalen + 4 > alloc_len) { alloc_len += datalen + 2; - buffer = realloc(buffer, alloc_len); + buffer = (char *) realloc(buffer, alloc_len); } if (len != 0) { memcpy(buffer + len, ", ", 2); @@ -131,7 +131,7 @@ static void scconf_write_items(scconf_writer * writer, scconf_block * block) /* header */ name = scconf_list_get_string(subblock->name); datalen = strlen(item->key) + strlen(name) + 6; - data = malloc(datalen); + data = (char *) malloc(datalen); if (!data) { continue; } @@ -153,7 +153,7 @@ static void scconf_write_items(scconf_writer * writer, scconf_block * block) case SCCONF_ITEM_TYPE_VALUE: name = scconf_list_get_string(item->value.list); datalen = strlen(item->key) + strlen(name) + 6; - data = malloc(datalen); + data = (char *) malloc(datalen); if (!data) { continue; } diff --git a/src/scldap/scldap.c b/src/scldap/scldap.c index 5d60ccff..18224746 100644 --- a/src/scldap/scldap.c +++ b/src/scldap/scldap.c @@ -99,7 +99,7 @@ static int ldap_cb(scconf_context * config, const scconf_block * block, scconf_e len = strlen(cardprefix) + 1; } len += strlen(ldapsuffix) + 1; - lentry->entry = malloc(len); + lentry->entry = (char *) malloc(len); if (!lentry->entry) { free(ldapsuffix); return 1; @@ -184,7 +184,7 @@ scldap_context *scldap_parse_parameters(const char *filename) void scldap_show_parameters(scldap_context * ctx) { - int i, j; + unsigned int i, j; if (!ctx) return; @@ -212,7 +212,7 @@ void scldap_show_parameters(scldap_context * ctx) void scldap_free_parameters(scldap_context * ctx) { - int i, j; + unsigned int i, j; if (!ctx) return; @@ -367,7 +367,7 @@ const char *scldap_show_arguments(void) int scldap_add_entry(scldap_context * ctx, const char *entry) { - int i; + unsigned int i; if (!ctx) return 0; @@ -394,7 +394,7 @@ int scldap_add_entry(scldap_context * ctx, const char *entry) int scldap_get_entry(scldap_context * ctx, const char *entry) { - int i; + unsigned int i; if (!ctx) return 0; @@ -412,7 +412,7 @@ int scldap_get_entry(scldap_context * ctx, const char *entry) void scldap_set_entry(scldap_context * ctx, const char *entry) { - int i; + unsigned int i; if (!ctx) return; @@ -430,7 +430,7 @@ void scldap_set_entry(scldap_context * ctx, const char *entry) void scldap_remove_entry(scldap_context * ctx, const char *entry) { - int i, j; + unsigned int i, j; if (!ctx) return; @@ -590,7 +590,7 @@ int scldap_url_to_entry(scldap_context * ctx, const char *entry, const char *url int scldap_approx_base_by_dn(scldap_context * ctx, const char *entry, const char *dn, char **base) { scldap_result *splitdn = NULL; - int i = 0, j = 0, numdns = 0; + unsigned int i = 0, j = 0, numdns = 0; char **founddns = NULL; if (!ctx || !entry || !dn) { @@ -645,7 +645,7 @@ int scldap_dn_to_result(const char *dn, scldap_result ** result, int notypes) { scldap_result *_result = NULL; char *buf = NULL, **tmp = NULL; - int i; + unsigned int i; if (!dn || *result) return -1; @@ -667,7 +667,7 @@ int scldap_dn_to_result(const char *dn, scldap_result ** result, int notypes) memset(buf, 0, (strlen(dn) + 1) * 2); if (dn[0] == '/') { - int i, c = 0; + unsigned int c = 0; for (i = 1; i < strlen(dn); i++) { if (dn[i] == '/') { @@ -710,7 +710,7 @@ static void scldap_get_result(LDAP * ld, LDAPMessage * res, scldap_param_entry * struct berval **bvals = NULL; BerElement *ber = NULL; char *name = NULL; - int i = 0, j, o, k; + unsigned int i = 0, j, o; for (name = ldap_first_attribute(ld, res, &ber); name; name = ldap_next_attribute(ld, res, ber)) { @@ -725,7 +725,7 @@ static void scldap_get_result(LDAP * ld, LDAPMessage * res, scldap_param_entry * memset(result->result[result->results].data, 0, result->result[result->results].datalen + 1); \ memcpy(result->result[result->results].data, bvals[i]->bv_val, result->result[result->results].datalen); \ for (o = 0; o < bvals[i]->bv_len; o++) { \ - k = bvals[i]->bv_val[o]; \ + int k = bvals[i]->bv_val[o]; \ if (!isascii(k)) { \ result->result[result->results].binary = 1; \ break; \ @@ -774,7 +774,7 @@ static char *combinestr(char *str,...) if (!str) { return NULL; } - buf = malloc(MAX_BUF_LEN); + buf = (char *) malloc(MAX_BUF_LEN); if (!buf) { return NULL; } @@ -888,7 +888,7 @@ int scldap_search(scldap_context * ctx, const char *entry, void scldap_free_result(scldap_result * result) { - int i; + unsigned int i; if (result) { for (i = 0; i < result->results; i++) { diff --git a/src/scldap/test-ldap.c b/src/scldap/test-ldap.c index 43c6f9be..bd11bb0d 100644 --- a/src/scldap/test-ldap.c +++ b/src/scldap/test-ldap.c @@ -36,7 +36,7 @@ static void hex_dump_asc(FILE * f, const unsigned char *in, size_t count, int ad while (count) { char ascbuf[17]; - int i; + unsigned int i; if (addr >= 0) { fprintf(f, "%08X: ", addr); @@ -74,11 +74,11 @@ static void usage(void) int main(int argc, char **argv) { char *entry = NULL, *searchword = NULL; - int i, verbose = 0, dump = 0, save = 0, ffound = 0; + unsigned int i, verbose = 0, dump = 0, save = 0, ffound = 0; scldap_context *lctx = NULL; scldap_result *lresult = NULL; - for (i = 0; i < argc; i++) { + for (i = 0; i < (unsigned int) argc; i++) { if (argv[i][0] == '-') { char *optarg = (char *) argv[i + 1]; switch (argv[i][1]) { @@ -163,7 +163,7 @@ int main(int argc, char **argv) if (save && lresult->result[i].name) { const char *prefix = "ldap-dump-"; int filenamelen = strlen(lresult->result[i].name) + strlen(prefix) + 6; - char *filename = malloc(filenamelen); + char *filename = (char *) malloc(filenamelen); FILE *fp = NULL; if (!filename) diff --git a/src/scrandom/scrandom.c b/src/scrandom/scrandom.c index a99814fa..b3f55519 100644 --- a/src/scrandom/scrandom.c +++ b/src/scrandom/scrandom.c @@ -35,21 +35,19 @@ #ifdef HAVE_OPENSSL #include #endif +#include "scrandom.h" -static ssize_t atomicio(ssize_t(*f) (), int fd, void *_s, size_t n) +static ssize_t atomicio(ssize_t(*f) (int fd, void *_s, size_t n), int fd, void *_s, size_t n) { - char *s = _s; - ssize_t res, pos = 0; + char *s = (char *) _s; + size_t pos = 0; + ssize_t res; while (n > pos) { res = (f) (fd, s + pos, n - pos); switch (res) { case -1: -#ifdef EWOULDBLOCK - if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) { -#else if (errno == EINTR || errno == EAGAIN) { -#endif continue; } case 0: diff --git a/src/scrandom/test-random.c b/src/scrandom/test-random.c index bb213e84..a533d94a 100644 --- a/src/scrandom/test-random.c +++ b/src/scrandom/test-random.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include "scrandom.h" int main(int argc, char **argv) { diff --git a/src/signer/dialog.c b/src/signer/dialog.c index dcef2855..b4f3c1ef 100644 --- a/src/signer/dialog.c +++ b/src/signer/dialog.c @@ -15,7 +15,7 @@ struct entry_parm_s { static AssuanError getpin_cb (void *opaque, const void *buffer, size_t length) { - struct entry_parm_s *parm = opaque; + struct entry_parm_s *parm = (struct entry_parm_s *) opaque; /* we expect the pin to fit on one line */ if (parm->lines || length >= parm->size) @@ -26,7 +26,7 @@ getpin_cb (void *opaque, const void *buffer, size_t length) memcpy(parm->buffer, buffer, length); parm->buffer[length] = 0; parm->lines++; - return 0; + return (AssuanError) 0; } int ask_and_verify_pin_code(struct sc_pkcs15_card *p15card, @@ -39,7 +39,7 @@ int ask_and_verify_pin_code(struct sc_pkcs15_card *p15card, char buf[500]; char errtext[100]; struct entry_parm_s parm; - struct sc_pkcs15_pin_info *pinfo = pin->data; + struct sc_pkcs15_pin_info *pinfo = (struct sc_pkcs15_pin_info *) pin->data; argv[0] = pgmname; argv[1] = NULL; @@ -47,13 +47,13 @@ int ask_and_verify_pin_code(struct sc_pkcs15_card *p15card, r = assuan_pipe_connect(&ctx, pgmname, (char **) argv, 0); if (r) { printf("Can't connect to the PIN entry module: %s\n", - assuan_strerror(r)); + assuan_strerror((AssuanError) r)); goto err; } sprintf(buf, "SETDESC Enter PIN [%s] for digital signing ", pin->label); r = assuan_transact(ctx, buf, NULL, NULL, NULL, NULL, NULL, NULL); if (r) { - printf("SETDESC: %s\n", assuan_strerror(r)); + printf("SETDESC: %s\n", assuan_strerror((AssuanError) r)); goto err; } errtext[0] = 0; @@ -72,7 +72,7 @@ int ask_and_verify_pin_code(struct sc_pkcs15_card *p15card, return -2; } if (r) { - printf("GETPIN: %s\n", assuan_strerror(r)); + printf("GETPIN: %s\n", assuan_strerror((AssuanError) r)); goto err; } r = strlen(buf); diff --git a/src/signer/opensc-crypto.c b/src/signer/opensc-crypto.c index 19316047..0b4c7eaa 100644 --- a/src/signer/opensc-crypto.c +++ b/src/signer/opensc-crypto.c @@ -85,7 +85,7 @@ static int sc_private_decrypt(int flen, u_char *from, u_char *to, RSA *rsa, goto err; goto err; } - r = sc_pkcs15_decipher(priv->p15card, key->data, from, flen, to, flen); + r = sc_pkcs15_decipher(priv->p15card, (const struct sc_pkcs15_object *) key->data, from, flen, to, flen); if (r < 0) { #if 0 error("sc_pkcs15_decipher() failed: %s", sc_strerror(r)); @@ -172,7 +172,7 @@ sc_finish(RSA *rsa) struct sc_priv_data *priv; DBG(printf("sc_finish() called\n")); - priv = RSA_get_app_data(rsa); + priv = (struct sc_priv_data *) RSA_get_app_data(rsa); if (priv != NULL) { priv->ref_count--; if (priv->ref_count == 0) { diff --git a/src/signer/opensc-support.c b/src/signer/opensc-support.c index 3a59b6cb..56925a96 100644 --- a/src/signer/opensc-support.c +++ b/src/signer/opensc-support.c @@ -23,7 +23,7 @@ static int get_certificate(PluginInstance *inst, cert_id.len = 0; count = r; for (i = 0; i < count; i++) { - struct sc_pkcs15_prkey_info *key = objs[i]->data; + struct sc_pkcs15_prkey_info *key = (struct sc_pkcs15_prkey_info *) objs[i]->data; #if 0 if (key->usage & SC_PKCS15_PRKEY_USAGE_NONREPUDIATION) { @@ -40,7 +40,7 @@ static int get_certificate(PluginInstance *inst, r = sc_pkcs15_find_cert_by_id(inst->p15card, &cert_id, &cert_obj); if (r) return r; - cinfo = cert_obj->data; + cinfo = (struct sc_pkcs15_cert_info *) cert_obj->data; r = sc_pkcs15_read_certificate(inst->p15card, cinfo, &cert); if (r) return r; @@ -119,7 +119,7 @@ static int extract_certificate_and_pkey(PluginInstance *inst, goto err; rsa->flags |= RSA_FLAG_SIGN_VER; RSA_set_method(rsa, sc_get_method()); - priv = malloc(sizeof(*priv)); + priv = (struct sc_priv_data *) malloc(sizeof(*priv)); if (priv == NULL) goto err; memset(priv, 0, sizeof(struct sc_priv_data)); @@ -206,7 +206,7 @@ int create_envelope(PluginInstance *inst, u8 **data, int *datalen) r = -1; goto err; } - buf = malloc(r); + buf = (u8 *) malloc(r); if (buf == NULL) goto err; *data = buf; diff --git a/src/signer/signer.c b/src/signer/signer.c index d9c95ccd..c9957b15 100644 --- a/src/signer/signer.c +++ b/src/signer/signer.c @@ -63,7 +63,7 @@ post_data(NPP instance, const char *url, const char *target, uint32 len, taglen = strlen(tag); content_len = taglen + len + 1; - content = NPN_MemAlloc(content_len); + content = (char *) NPN_MemAlloc(content_len); if (content == NULL) return NPERR_OUT_OF_MEMORY_ERROR; memcpy(content, tag, taglen); @@ -73,7 +73,7 @@ post_data(NPP instance, const char *url, const char *target, uint32 len, sprintf(headers, "Content-type: application/x-www-form-urlencoded\r\n" "Content-Length: %u\r\n\r\n", (unsigned int) content_len); hdrlen = strlen(headers); - sendbuf = NPN_MemAlloc(hdrlen + content_len); + sendbuf = (char *) NPN_MemAlloc(hdrlen + content_len); if (sendbuf == NULL) return NPERR_OUT_OF_MEMORY_ERROR; memcpy(sendbuf, headers, hdrlen); @@ -141,7 +141,7 @@ NPP_New(NPMIMEType pluginType, goto err; } b64datalen = datalen * 4 / 3 + 4; - b64data = malloc(b64datalen); + b64data = (u8 *) malloc(b64datalen); r = sc_base64_encode(data, datalen, b64data, b64datalen, 0); if (r) { r = NPERR_GENERIC_ERROR; diff --git a/src/tests/p15dump.c b/src/tests/p15dump.c index 53bc80d3..99faa42f 100644 --- a/src/tests/p15dump.c +++ b/src/tests/p15dump.c @@ -36,7 +36,7 @@ static int dump_objects(const char *what, int type) } printf("%u found.\n", count); - objs = calloc(count, sizeof(*objs)); + objs = (struct sc_pkcs15_object **) calloc(count, sizeof(*objs)); if ((count = sc_pkcs15_get_objects(p15card, type, objs, count)) < 0) { fprintf(stderr, "Error enumerating %s: %s\n", what, sc_strerror(count)); diff --git a/src/tests/print.c b/src/tests/print.c index a9b9a940..e0d90f55 100644 --- a/src/tests/print.c +++ b/src/tests/print.c @@ -10,8 +10,6 @@ #include #include "sc-test.h" -struct sc_pkcs15_card *p15card; - static void print_pin(const struct sc_pkcs15_object *obj) { const char *pin_flags[] = diff --git a/src/tests/sc-test.c b/src/tests/sc-test.c index 4c6d883d..4a5073aa 100644 --- a/src/tests/sc-test.c +++ b/src/tests/sc-test.c @@ -7,6 +7,7 @@ #include #include #include +#include "sc-test.h" struct sc_context *ctx; struct sc_card *card; diff --git a/src/tests/sc-test.h b/src/tests/sc-test.h index 071f5956..80fd3d31 100644 --- a/src/tests/sc-test.h +++ b/src/tests/sc-test.h @@ -1,6 +1,10 @@ #ifndef _SC_TEST_H #define _SC_TEST_H +#ifdef __cplusplus +extern "C" { +#endif + extern struct sc_context *ctx; extern struct sc_card *card; struct sc_pkcs15_object; @@ -9,4 +13,8 @@ int sc_test_init(int *argc, char *argv[]); void sc_test_cleanup(); void sc_test_print_object(const struct sc_pkcs15_object *); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/tools/cryptoflex-tool.c b/src/tools/cryptoflex-tool.c index a2e38e88..a04a7249 100644 --- a/src/tools/cryptoflex-tool.c +++ b/src/tools/cryptoflex-tool.c @@ -97,7 +97,7 @@ char *getpin(const char *prompt) pass[i] = 0; if (strlen(pass) == 0) return NULL; - buf = malloc(8); + buf = (char *) malloc(8); if (buf == NULL) return NULL; if (strlen(pass) > 8) { @@ -1078,7 +1078,7 @@ int main(int argc, char * const argv[]) if (c == -1) break; if (c == '?') - print_usage_and_die("cryptoflex-tool"); + print_usage_and_die(); switch (c) { case 'l': do_list_keys = 1; diff --git a/src/tools/pkcs15-crypt.c b/src/tools/pkcs15-crypt.c index b9a108c4..c2fc4054 100644 --- a/src/tools/pkcs15-crypt.c +++ b/src/tools/pkcs15-crypt.c @@ -87,7 +87,7 @@ char * get_pin(struct sc_pkcs15_object *obj) { char buf[80]; char *pincode; - struct sc_pkcs15_pin_info *pinfo = obj->data; + struct sc_pkcs15_pin_info *pinfo = (struct sc_pkcs15_pin_info *) obj->data; if (opt_pincode != NULL) return strdup(opt_pincode); @@ -276,7 +276,7 @@ int sign_ext(struct sc_pkcs15_object *obj, int sign(struct sc_pkcs15_object *obj) { u8 buf[1024], out[1024]; - struct sc_pkcs15_prkey_info *key = obj->data; + struct sc_pkcs15_prkey_info *key = (struct sc_pkcs15_prkey_info *) obj->data; int r, c, len; if (opt_input == NULL) { @@ -398,7 +398,7 @@ int main(int argc, char * const argv[]) if (c == -1) break; if (c == '?') - print_usage_and_die("pkcs15-crypt"); + print_usage_and_die(); switch (c) { case 's': do_sign++; @@ -442,7 +442,7 @@ int main(int argc, char * const argv[]) } } if (action_count == 0) - print_usage_and_die("pkcs15-crypt"); + print_usage_and_die(); r = sc_establish_context(&ctx, app_name); if (r) { fprintf(stderr, "Failed to establish context: %s\n", sc_strerror(r)); @@ -519,7 +519,7 @@ int main(int argc, char * const argv[]) err = 5; goto end; } - r = sc_pkcs15_verify_pin(p15card, pin->data, (const u8 *) pincode, strlen(pincode)); + r = sc_pkcs15_verify_pin(p15card, (struct sc_pkcs15_pin_info *) pin->data, (const u8 *) pincode, strlen(pincode)); if (r) { fprintf(stderr, "PIN code verification failed: %s\n", sc_strerror(r)); err = 5; diff --git a/src/tools/pkcs15-init.c b/src/tools/pkcs15-init.c index afd373bb..cc1ddfaa 100644 --- a/src/tools/pkcs15-init.c +++ b/src/tools/pkcs15-init.c @@ -219,14 +219,14 @@ main(int argc, char **argv) parse_commandline(argc, argv); if (optind != argc) - print_usage_and_die("pkcs15-init"); + print_usage_and_die(); if (opt_action == ACTION_NONE) { fprintf(stderr, "No action specified.\n"); - print_usage_and_die("pkcs15-init"); + print_usage_and_die(); } if (!opt_profile) { fprintf(stderr, "No profile specified.\n"); - print_usage_and_die("pkcs15-init"); + print_usage_and_die(); } /* Connect to the card */ @@ -955,7 +955,7 @@ do_convert_bignum(sc_pkcs15_bignum_t *dst, BIGNUM *src) if (src == 0) return 0; dst->len = BN_num_bytes(src); - dst->data = malloc(dst->len); + dst->data = (u8 *) malloc(dst->len); BN_bn2bin(src, dst->data); return 1; } @@ -1040,10 +1040,10 @@ do_convert_public_key(struct sc_pkcs15_pubkey *key, EVP_PKEY *pk) int do_convert_cert(sc_pkcs15_der_t *der, X509 *cert) { - unsigned char *p; + u8 *p; der->len = i2d_X509(cert, NULL); - der->value = p = malloc(der->len); + der->value = p = (u8 *) malloc(der->len); i2d_X509(cert, &p); return 0; } @@ -1121,7 +1121,7 @@ handle_option(int c) opt_extractable++; break; default: - print_usage_and_die("pkcs15-init"); + print_usage_and_die(); } } @@ -1184,7 +1184,7 @@ read_options_file(const char *filename) break; if (!o->name) { error("Unknown option \"%s\"\n", name); - print_usage_and_die("pkcs15-init"); + print_usage_and_die(); } if (o->has_arg != no_argument) { optarg = strtok(NULL, ""); @@ -1197,7 +1197,7 @@ read_options_file(const char *filename) if (o->has_arg == required_argument && (!optarg || !*optarg)) { error("Option %s: missing argument\n", name); - print_usage_and_die("pkcs15-init"); + print_usage_and_die(); } handle_option(o->val); name = strtok(NULL, " \t"); diff --git a/src/tools/pkcs15-tool.c b/src/tools/pkcs15-tool.c index 6e570afd..db2cffce 100644 --- a/src/tools/pkcs15-tool.c +++ b/src/tools/pkcs15-tool.c @@ -170,7 +170,7 @@ int read_certificate(void) } count = r; for (i = 0; i < count; i++) { - struct sc_pkcs15_cert_info *cinfo = objs[i]->data; + struct sc_pkcs15_cert_info *cinfo = (struct sc_pkcs15_cert_info *) objs[i]->data; struct sc_pkcs15_cert *cert; if (sc_pkcs15_compare_id(&id, &cinfo->id) != 1) @@ -336,7 +336,7 @@ int read_public_key(void) } count = r; for (i = 0; i < count; i++) { - struct sc_pkcs15_pubkey_info *info = objs[i]->data; + struct sc_pkcs15_pubkey_info *info = (struct sc_pkcs15_pubkey_info *) objs[i]->data; sc_pkcs15_der_t raw_key, pem_key; int algorithm; @@ -405,7 +405,7 @@ u8 * get_pin(const char *prompt, struct sc_pkcs15_pin_info **pin_out) return NULL; } obj = objs[0]; - pinfo = obj->data; + pinfo = (struct sc_pkcs15_pin_info *) obj->data; } else if (pinfo == NULL) { struct sc_pkcs15_id pin_id; @@ -415,7 +415,7 @@ u8 * get_pin(const char *prompt, struct sc_pkcs15_pin_info **pin_out) fprintf(stderr, "Unable to find PIN code: %s\n", sc_strerror(r)); return NULL; } - pinfo = obj->data; + pinfo = (struct sc_pkcs15_pin_info *) obj->data; } if (pin_out != NULL) @@ -620,7 +620,7 @@ int learn_card(void) read_and_cache_file(&df->path); printf("Caching %d certificate(s)...\n", r); for (i = 0; i < cert_count; i++) { - struct sc_pkcs15_cert_info *cinfo = certs[i]->data; + struct sc_pkcs15_cert_info *cinfo = (struct sc_pkcs15_cert_info *) certs[i]->data; printf("[%s]\n", certs[i]->label); read_and_cache_file(&cinfo->path); @@ -647,7 +647,7 @@ int main(int argc, char * const argv[]) if (c == -1) break; if (c == '?') - print_usage_and_die("pkcs15-tool"); + print_usage_and_die(); switch (c) { case 'r': opt_cert = optarg; @@ -704,7 +704,7 @@ int main(int argc, char * const argv[]) } } if (action_count == 0) - print_usage_and_die("pkcs15-tool"); + print_usage_and_die(); r = sc_establish_context(&ctx, app_name); if (r) { fprintf(stderr, "Failed to establish context: %s\n", sc_strerror(r)); diff --git a/src/tools/util.c b/src/tools/util.c index d918920b..41a8abd2 100644 --- a/src/tools/util.c +++ b/src/tools/util.c @@ -63,7 +63,7 @@ void hex_dump_asc(FILE *f, const u8 *in, size_t count, int addr) } } -void print_usage_and_die() +void print_usage_and_die(void) { int i = 0; printf("Usage: %s [OPTIONS]\nOptions:\n", app_name); diff --git a/src/tools/util.h b/src/tools/util.h index 6f6d318e..f21cff59 100644 --- a/src/tools/util.h +++ b/src/tools/util.h @@ -16,6 +16,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + extern const struct option options[]; extern const char *option_help[]; extern const char *app_name; @@ -23,10 +27,14 @@ extern const char *app_name; void print_binary(FILE *f, const u8 *buf, int count); void hex_dump(FILE *f, const u8 *in, int len, const char *sep); void hex_dump_asc(FILE *f, const u8 *in, size_t count, int addr); -void print_usage_and_die(); +void print_usage_and_die(void); const char * acl_to_str(const struct sc_acl_entry *e); void warn(const char *fmt, ...); void error(const char *fmt, ...); void fatal(const char *fmt, ...); +#ifdef __cplusplus +} +#endif + #endif