From f21926af0073534835631640bbe77e52593f26ed Mon Sep 17 00:00:00 2001 From: jey Date: Sun, 24 Mar 2002 14:12:38 +0000 Subject: [PATCH] - Started to add configuration file support to libopensc - Added typedefs for some basic structs (e.g. struct sc_card --> sc_card_t) - Added a second argument to sc_establish_context() to identify the calling application - Renamed sc_destroy_context() to sc_release_context() git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@378 c6295689-39f2-0310-b995-f0e70906c6a9 --- configure.in | 4 +++ etc/opensc.conf.example | 11 +++++++ src/libopensc/Makefile.am | 4 +-- src/libopensc/internal.h | 2 ++ src/libopensc/opensc.h | 41 +++++++++++++++++++------- src/libopensc/sc-internal.h | 2 ++ src/libopensc/sc.c | 59 +++++++++++++++++++++++++++++++++---- src/openssh/opensc-ssh.c | 4 +-- src/pkcs11/pkcs11-global.c | 2 +- src/scam/p15_eid.c | 4 +-- src/scam/p15_ldap.c | 4 +-- src/scam/scam.c | 8 ++--- src/tests/sc-test.c | 4 +-- src/tools/cryptoflex-tool.c | 8 +++-- src/tools/opensc-explorer.c | 8 +++-- src/tools/opensc-tool.c | 10 ++++--- src/tools/pkcs15-crypt.c | 6 ++-- src/tools/pkcs15-gpk.c | 1 + src/tools/pkcs15-init.c | 7 +++-- src/tools/pkcs15-tool.c | 6 ++-- src/tools/profile.c | 1 + src/tools/util.c | 4 +-- src/tools/util.h | 3 +- 23 files changed, 153 insertions(+), 50 deletions(-) create mode 100644 etc/opensc.conf.example diff --git a/configure.in b/configure.in index 8f218ba4..67f4164e 100644 --- a/configure.in +++ b/configure.in @@ -935,6 +935,10 @@ AM_CONDITIONAL(HAVE_SCIDI, test "foo" = "bar") scldap_etc_path=`eval echo ${sysconfdir}` ; scldap_etc_path=`eval echo ${scldap_etc_path}` AC_DEFINE_UNQUOTED(SCLDAP_ETC_PATH_CUSTOM, "$scldap_etc_path", [etc path for scldap]) +opensc_etc_path=`eval echo ${sysconfdir}` ; opensc_etc_path=`eval echo ${opensc_etc_path}` +AC_DEFINE_UNQUOTED(OPENSC_ETC_PATH, "$opensc_etc_path", [etc path for libopensc]) +opensc_conf_path=`eval echo ${opensc_etc_path}/opensc.conf` +AC_DEFINE_UNQUOTED(OPENSC_CONF_PATH, "$opensc_conf_path", [default config file for libopensc]) AC_SUBST(CFLAGS_OPENSC) CFLAGS_OPENSC="-I\${top_srcdir}/src/libopensc" diff --git a/etc/opensc.conf.example b/etc/opensc.conf.example new file mode 100644 index 00000000..d3331537 --- /dev/null +++ b/etc/opensc.conf.example @@ -0,0 +1,11 @@ +# Configuration file for OpenSC +# Example configuration file + +opensc defaults { + debuglevel = 0 +# debugfile = /tmp/opensc-debug.log +# errorfile = /tmp/opensc-errors.log +} + +opensc pam_pkcs15 { +} diff --git a/src/libopensc/Makefile.am b/src/libopensc/Makefile.am index 508f4c50..b1135760 100644 --- a/src/libopensc/Makefile.am +++ b/src/libopensc/Makefile.am @@ -12,7 +12,7 @@ PCSC_FLAGS = @CFLAGS_PCSC@ PCSC_LIB = @LIBPCSC@ endif -INCLUDES = $(PCSC_FLAGS) +INCLUDES = $(PCSC_FLAGS) -I../scconf bin_SCRIPTS = opensc-config @@ -24,7 +24,7 @@ libopensc_la_SOURCES = asn1.c base64.c sec.c log.c sc.c card.c iso7816.c \ card-setcos.c card-miocos.c card-flex.c card-gpk.c \ card-tcos.c card-emv.c card-default.c libopensc_la_LDFLAGS = -version-info 0:6:0 -libopensc_la_LIBADD = $(PCSC_LIB) $(SSL_LIB) +libopensc_la_LIBADD = $(PCSC_LIB) $(SSL_LIB) $(LIBSCCONF) include_HEADERS = opensc.h opensc-pkcs15.h opensc-emv.h \ cardctl.h diff --git a/src/libopensc/internal.h b/src/libopensc/internal.h index cbe0a5ca..e285b5fc 100644 --- a/src/libopensc/internal.h +++ b/src/libopensc/internal.h @@ -26,9 +26,11 @@ #endif #include "opensc.h" +#include #define SC_FILE_MAGIC 0x14426950 #define SC_CARD_MAGIC 0x27182818 +#define SC_CTX_MAGIC 0x0A550335 struct sc_atr_table { const u8 *atr; diff --git a/src/libopensc/opensc.h b/src/libopensc/opensc.h index dd87b348..bd0a83b4 100644 --- a/src/libopensc/opensc.h +++ b/src/libopensc/opensc.h @@ -26,12 +26,14 @@ #ifndef _OPENSC_H #define _OPENSC_H -#include -#ifndef NDEBUG -#include -#endif #include +#ifdef HAVE_PTHREAD +#include +#endif + +#include + #ifdef __cplusplus extern "C" { #endif @@ -192,6 +194,7 @@ struct sc_acl_entry { struct sc_acl_entry *next; }; +typedef struct sc_acl_entry sc_acl_entry_t; struct sc_file { struct sc_path path; @@ -213,6 +216,7 @@ struct sc_file { size_t prop_attr_len; unsigned int magic; }; +typedef struct sc_file sc_file_t; #define SC_SEC_OPERATION_DECIPHER 0x0001 #define SC_SEC_OPERATION_SIGN 0x0002 @@ -263,6 +267,7 @@ struct sc_security_env { u8 key_ref[8]; size_t key_ref_len; }; +typedef struct sc_security_env sc_security_env_t; struct sc_algorithm_id { unsigned int algorithm; @@ -280,6 +285,7 @@ struct sc_algorithm_info { } _rsa; } u; }; +typedef struct sc_algorithm_info sc_algorithm_info_t; struct sc_app_info { u8 aid[SC_MAX_AID_SIZE]; @@ -292,12 +298,12 @@ struct sc_app_info { const char *desc; /* App description, if known */ int rec_nr; /* -1, if EF(DIR) is transparent */ }; +typedef struct sc_app_info sc_app_info_t; struct sc_card_cache { struct sc_path current_path; }; - #define SC_PROTO_T0 0x00000001 #define SC_PROTO_T1 0x00000002 #define SC_PROTO_RAW 0x00001000 @@ -320,6 +326,7 @@ struct sc_slot_info { void *drv_data; }; +typedef struct sc_slot_info sc_slot_info_t; struct sc_event_listener { unsigned int event_mask; @@ -404,7 +411,6 @@ struct sc_card { struct sc_algorithm_info *algorithms; int algorithm_count; - pthread_mutex_t mutex; int lock_count; const struct sc_card_driver *driver; @@ -414,8 +420,12 @@ struct sc_card { struct sc_card_cache cache; int cache_valid; +#ifdef HAVE_PTHREAD + pthread_mutex_t mutex; +#endif unsigned int magic; }; +typedef struct sc_card sc_card_t; struct sc_card_operations { /* Called in sc_connect_card(). Must return 1, if the current @@ -522,6 +532,8 @@ struct sc_card_driver { }; struct sc_context { + scconf_context *conf; + char *app_name; int debug; FILE *debug_file, *error_file; @@ -535,8 +547,13 @@ struct sc_context { const struct sc_card_driver *card_drivers[SC_MAX_CARD_DRIVERS+1]; const struct sc_card_driver *forced_driver; + +#ifdef HAVE_PTHREAD pthread_mutex_t mutex; +#endif + unsigned int magic; }; +typedef struct sc_context sc_context_t; struct sc_apdu { int cse; /* APDU case */ @@ -550,6 +567,7 @@ struct sc_apdu { unsigned int sw1, sw2; /* Status words returned in R-APDU */ }; +typedef struct sc_apdu sc_apdu_t; /* Base64 encoding/decoding functions */ int sc_base64_encode(const u8 *in, size_t inlen, u8 *out, size_t outlen, @@ -564,13 +582,16 @@ void sc_format_apdu(struct sc_card *card, struct sc_apdu *apdu, int cse, int ins /** * Establishes an OpenSC context * @param ctx A pointer to a pointer that will receive the allocated context + * @param app_name A string that identifies the application, used primarily + * in finding application-specific configuration data. Can be NULL. */ -int sc_establish_context(struct sc_context **ctx); +int sc_establish_context(struct sc_context **ctx, const char *app_name); + /** - * Destroys an established OpenSC context - * @param ctx A pointer to the context structure to be destroyed + * Releases an established OpenSC context + * @param ctx A pointer to the context structure to be released */ -int sc_destroy_context(struct sc_context *ctx); +int sc_release_context(struct sc_context *ctx); /** * Forces the use of a specified card driver * @param ctx OpenSC context diff --git a/src/libopensc/sc-internal.h b/src/libopensc/sc-internal.h index cbe0a5ca..e285b5fc 100644 --- a/src/libopensc/sc-internal.h +++ b/src/libopensc/sc-internal.h @@ -26,9 +26,11 @@ #endif #include "opensc.h" +#include #define SC_FILE_MAGIC 0x14426950 #define SC_CARD_MAGIC 0x27182818 +#define SC_CTX_MAGIC 0x0A550335 struct sc_atr_table { const u8 *atr; diff --git a/src/libopensc/sc.c b/src/libopensc/sc.c index 239f3699..13738dff 100644 --- a/src/libopensc/sc.c +++ b/src/libopensc/sc.c @@ -142,20 +142,60 @@ int sc_wait_for_card(struct sc_context *ctx, int reader, int timeout) } #endif -int sc_establish_context(struct sc_context **ctx_out) +static void set_defaults(struct sc_context *ctx) +{ + ctx->debug = 0; + if (ctx->debug_file) + fclose(ctx->debug_file); + ctx->debug_file = NULL; + ctx->log_errors = 1; + ctx->error_file = stderr; +} + +static int load_parameters(struct sc_context *ctx, scconf_block *block) +{ + const char *val; + + val = scconf_find_value_first(block, "debuglevel"); + sscanf(val, "%d", &ctx->debug); + val = scconf_find_value_first(block, "debugfile"); + if (ctx->debug_file) + fclose(ctx->debug_file); + if (strcmp(val, "stdout") == 0) + ctx->debug_file = fopen(val, "a"); + val = scconf_find_value_first(block, "errorfile"); + if (ctx->error_file) + fclose(ctx->error_file); + if (strcmp(val, "stderr") != 0) + ctx->error_file = fopen(val, "a"); + + return 0; +} + +int sc_establish_context(struct sc_context **ctx_out, const char *app_name) { struct sc_context *ctx; - int i; + int i, r; assert(ctx_out != NULL); ctx = malloc(sizeof(struct sc_context)); if (ctx == NULL) return SC_ERROR_OUT_OF_MEMORY; memset(ctx, 0, sizeof(struct sc_context)); - ctx->log_errors = 1; - + set_defaults(ctx); + ctx->app_name = strdup(app_name); + ctx->conf = scconf_init(OPENSC_CONF_PATH); + if (ctx->conf != NULL) { + r = scconf_parse(ctx->conf); + if (scconf_parse(ctx->conf) < 1) { + scconf_deinit(ctx->conf); + ctx->conf = NULL; + } else + load_parameters(ctx, ctx->conf->root); + } +#ifdef HAVE_PTHREAD pthread_mutex_init(&ctx->mutex, NULL); - +#endif for (i = 0; i < SC_MAX_READER_DRIVERS+1; i++) ctx->reader_drivers[i] = NULL; i = 0; @@ -199,7 +239,7 @@ int sc_establish_context(struct sc_context **ctx_out) return 0; } -int sc_destroy_context(struct sc_context *ctx) +int sc_release_context(struct sc_context *ctx) { int i; @@ -220,6 +260,9 @@ int sc_destroy_context(struct sc_context *ctx) drv->ops->finish(ctx->reader_drv_data[i]); } ctx->debug_file = ctx->error_file = NULL; + if (ctx->conf) + scconf_deinit(ctx->conf); + free(ctx->app_name); free(ctx); return 0; } @@ -228,7 +271,9 @@ int sc_set_card_driver(struct sc_context *ctx, const char *short_name) { int i = 0, match = 0; +#ifdef HAVE_PTHREAD pthread_mutex_lock(&ctx->mutex); +#endif if (short_name == NULL) { ctx->forced_driver = NULL; match = 1; @@ -242,7 +287,9 @@ int sc_set_card_driver(struct sc_context *ctx, const char *short_name) } i++; } +#ifdef HAVE_PTHREAD pthread_mutex_unlock(&ctx->mutex); +#endif if (match == 0) return SC_ERROR_OBJECT_NOT_FOUND; /* FIXME: invent error */ return 0; diff --git a/src/openssh/opensc-ssh.c b/src/openssh/opensc-ssh.c index 8be8d34e..e37657c5 100644 --- a/src/openssh/opensc-ssh.c +++ b/src/openssh/opensc-ssh.c @@ -281,7 +281,7 @@ int main(int argc, char *const argv[]) } if (action_count == 0) print_usage_and_die(); - r = sc_establish_context(&ctx); + r = sc_establish_context(&ctx, "opensc-ssh"); if (r) { fprintf(stderr, "Failed to establish context: %s\n", sc_strerror(r)); return 1; @@ -329,6 +329,6 @@ end: sc_disconnect_card(card, 0); } if (ctx) - sc_destroy_context(ctx); + sc_release_context(ctx); return err; } diff --git a/src/pkcs11/pkcs11-global.c b/src/pkcs11/pkcs11-global.c index 12259671..d1e57fe5 100644 --- a/src/pkcs11/pkcs11-global.c +++ b/src/pkcs11/pkcs11-global.c @@ -80,7 +80,7 @@ CK_RV C_Finalize(CK_VOID_PTR pReserved) for (i=0; ireader_count; i++) card_removed(i); - sc_destroy_context(context); + sc_release_context(context); return CKR_OK; } diff --git a/src/scam/p15_eid.c b/src/scam/p15_eid.c index d923c871..1852f206 100644 --- a/src/scam/p15_eid.c +++ b/src/scam/p15_eid.c @@ -122,7 +122,7 @@ int p15_eid_init(int argc, const char **argv) if (ctx) { return SCAM_FAILED; } - r = sc_establish_context(&ctx); + r = sc_establish_context(&ctx, "scam"); if (r != SC_SUCCESS) { scam_fw_p15_eid.printmsg("sc_establish_context: %s\n", sc_strerror(r)); return SCAM_FAILED; @@ -372,7 +372,7 @@ void p15_eid_deinit(void) } card = NULL; if (ctx) { - sc_destroy_context(ctx); + sc_release_context(ctx); } ctx = NULL; } diff --git a/src/scam/p15_ldap.c b/src/scam/p15_ldap.c index 9fa7132d..86214d63 100644 --- a/src/scam/p15_ldap.c +++ b/src/scam/p15_ldap.c @@ -122,7 +122,7 @@ int p15_ldap_init(int argc, const char **argv) if (ctx || lctx) { return SCAM_FAILED; } - r = sc_establish_context(&ctx); + r = sc_establish_context(&ctx, "scam"); if (r != SC_SUCCESS) { scam_fw_p15_ldap.printmsg("sc_establish_context: %s\n", sc_strerror(r)); return SCAM_FAILED; @@ -312,7 +312,7 @@ void p15_ldap_deinit(void) } card = NULL; if (ctx) { - sc_destroy_context(ctx); + sc_release_context(ctx); } ctx = NULL; } diff --git a/src/scam/scam.c b/src/scam/scam.c index b52dd0be..2df3f310 100644 --- a/src/scam/scam.c +++ b/src/scam/scam.c @@ -70,16 +70,16 @@ const char *scam_get_atr(unsigned int readernum) return NULL; } if (readernum >= ctx->reader_count || readernum < 0) { - sc_destroy_context(ctx); + sc_release_context(ctx); return NULL; } if (sc_detect_card_presence(ctx->reader[readernum], 0) != 1) { - sc_destroy_context(ctx); + sc_release_context(ctx); return NULL; } r = sc_connect_card(ctx->reader[readernum], 0, &card); if (r) { - sc_destroy_context(ctx); + sc_release_context(ctx); return NULL; } for (i = 0; i < card->atr_len; i++) { @@ -103,7 +103,7 @@ const char *scam_get_atr(unsigned int readernum) } atr[c] = 0; sc_disconnect_card(card, 0); - sc_destroy_context(ctx); + sc_release_context(ctx); return &atr[0]; } diff --git a/src/tests/sc-test.c b/src/tests/sc-test.c index 2e423b81..b9ba6cbf 100644 --- a/src/tests/sc-test.c +++ b/src/tests/sc-test.c @@ -16,7 +16,7 @@ int sc_test_init(int *argc, char *argv[]) int i, c; printf("Using libopensc version %s.\n", sc_version); - i = sc_establish_context(&ctx); + i = sc_establish_context(&ctx, "tests"); if (i < 0) { printf("sc_establish_context() failed (%d)\n", i); return i; @@ -70,5 +70,5 @@ int sc_test_init(int *argc, char *argv[]) void sc_test_cleanup(void) { sc_disconnect_card(card, 0); - sc_destroy_context(ctx); + sc_release_context(ctx); } diff --git a/src/tools/cryptoflex-tool.c b/src/tools/cryptoflex-tool.c index fb07f8f3..fca9a379 100644 --- a/src/tools/cryptoflex-tool.c +++ b/src/tools/cryptoflex-tool.c @@ -29,6 +29,8 @@ #include #include +const char *app_name = "cryptoflex-tool"; + int opt_reader = 0, opt_debug = 0; int opt_key_num = 1, opt_pin_num = -1; int quiet = 0; @@ -1162,8 +1164,8 @@ int main(int argc, char * const argv[]) } } if (action_count == 0) - print_usage_and_die("cryptoflex-tool"); - r = sc_establish_context(&ctx); + print_usage_and_die(); + r = sc_establish_context(&ctx, app_name); if (r) { fprintf(stderr, "Failed to establish context: %s\n", sc_strerror(r)); return 1; @@ -1236,6 +1238,6 @@ end: sc_disconnect_card(card, 0); } if (ctx) - sc_destroy_context(ctx); + sc_release_context(ctx); return err; } diff --git a/src/tools/opensc-explorer.c b/src/tools/opensc-explorer.c index f03931ce..8316702e 100644 --- a/src/tools/opensc-explorer.c +++ b/src/tools/opensc-explorer.c @@ -33,6 +33,8 @@ #define DIM(v) (sizeof(v)/sizeof((v)[0])) +const char *app_name = "opensc-explorer"; + int opt_reader = 0, opt_debug = 0; const char *opt_driver = NULL; @@ -81,7 +83,7 @@ void die(int ret) sc_disconnect_card(card, 0); } if (ctx) - sc_destroy_context(ctx); + sc_release_context(ctx); exit(ret); } @@ -1154,7 +1156,7 @@ int main(int argc, char * const argv[]) if (c == -1) break; if (c == '?') - print_usage_and_die("opensc-explorer"); + print_usage_and_die(); switch (c) { case 'r': opt_reader = atoi(optarg); @@ -1168,7 +1170,7 @@ int main(int argc, char * const argv[]) } } - r = sc_establish_context(&ctx); + r = sc_establish_context(&ctx, app_name); if (r) { fprintf(stderr, "Failed to establish context: %s\n", sc_strerror(r)); return 1; diff --git a/src/tools/opensc-tool.c b/src/tools/opensc-tool.c index 8504d479..e6455954 100644 --- a/src/tools/opensc-tool.c +++ b/src/tools/opensc-tool.c @@ -38,6 +38,8 @@ #define OPT_PIN_ID 0x103 #define OPT_NO_CACHE 0x104 +const char *app_name = "opensc-tool"; + int opt_reader = 0, opt_no_cache = 0, opt_debug = 0; char * opt_apdus[8]; int opt_apdu_count = 0; @@ -356,7 +358,7 @@ int main(int argc, char * const argv[]) if (c == -1) break; if (c == '?') - print_usage_and_die("opensc-tool"); + print_usage_and_die(); switch (c) { case 'l': do_list_readers = 1; @@ -400,8 +402,8 @@ int main(int argc, char * const argv[]) } } if (action_count == 0) - print_usage_and_die("opensc-tool"); - r = sc_establish_context(&ctx); + print_usage_and_die(); + r = sc_establish_context(&ctx, app_name); if (r) { fprintf(stderr, "Failed to establish context: %s\n", sc_strerror(r)); return 1; @@ -481,6 +483,6 @@ end: sc_disconnect_card(card, 0); } if (ctx) - sc_destroy_context(ctx); + sc_release_context(ctx); return err; } diff --git a/src/tools/pkcs15-crypt.c b/src/tools/pkcs15-crypt.c index 167eb8ec..0fc54ae0 100644 --- a/src/tools/pkcs15-crypt.c +++ b/src/tools/pkcs15-crypt.c @@ -31,6 +31,8 @@ #include #include +const char *app_name = "pkcs15-crypt"; + int opt_reader = 0, quiet = 0; int opt_debug = 0; char * opt_pincode = NULL, * opt_key_id = NULL; @@ -256,7 +258,7 @@ int main(int argc, char * const argv[]) } if (action_count == 0) print_usage_and_die("pkcs15-crypt"); - r = sc_establish_context(&ctx); + r = sc_establish_context(&ctx, app_name); if (r) { fprintf(stderr, "Failed to establish context: %s\n", sc_strerror(r)); return 1; @@ -362,6 +364,6 @@ end: sc_disconnect_card(card, 0); } if (ctx) - sc_destroy_context(ctx); + sc_release_context(ctx); return err; } diff --git a/src/tools/pkcs15-gpk.c b/src/tools/pkcs15-gpk.c index 24f5ac3b..9315df68 100644 --- a/src/tools/pkcs15-gpk.c +++ b/src/tools/pkcs15-gpk.c @@ -23,6 +23,7 @@ #endif #include #include +#include #include #include "opensc.h" #include "cardctl.h" diff --git a/src/tools/pkcs15-init.c b/src/tools/pkcs15-init.c index e1af5257..f9916e8d 100644 --- a/src/tools/pkcs15-init.c +++ b/src/tools/pkcs15-init.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,8 @@ #include "profile.h" #include "pkcs15-init.h" +const char *app_name = "pkcs15-init"; + /* Handle encoding of PKCS15 on the card */ typedef int (*pkcs15_encoder)(struct sc_context *, struct sc_pkcs15_card *, u8 **, size_t *); @@ -278,7 +281,7 @@ done: if (card) { sc_unlock(card); sc_disconnect_card(card, 0); } - sc_destroy_context(ctx); + sc_release_context(ctx); return r? 1 : 0; } @@ -303,7 +306,7 @@ connect(int reader) { int r; - r = sc_establish_context(&ctx); + r = sc_establish_context(&ctx, app_name); if (r) { error("Failed to establish context: %s\n", sc_strerror(r)); return 0; diff --git a/src/tools/pkcs15-tool.c b/src/tools/pkcs15-tool.c index 579dac7a..d168b878 100644 --- a/src/tools/pkcs15-tool.c +++ b/src/tools/pkcs15-tool.c @@ -24,6 +24,8 @@ #include "util.h" #include +const char *app_name = "pkcs15-tool"; + int opt_reader = 0, opt_debug = 0; int opt_no_cache = 0; char * opt_pin_id; @@ -696,7 +698,7 @@ int main(int argc, char * const argv[]) } if (action_count == 0) print_usage_and_die("pkcs15-tool"); - r = sc_establish_context(&ctx); + r = sc_establish_context(&ctx, app_name); if (r) { fprintf(stderr, "Failed to establish context: %s\n", sc_strerror(r)); return 1; @@ -794,6 +796,6 @@ end: sc_disconnect_card(card, 0); } if (ctx) - sc_destroy_context(ctx); + sc_release_context(ctx); return err; } diff --git a/src/tools/profile.c b/src/tools/profile.c index dbf383bf..816cf0fe 100644 --- a/src/tools/profile.c +++ b/src/tools/profile.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "util.h" #include "profile.h" diff --git a/src/tools/util.c b/src/tools/util.c index e02ae774..d918920b 100644 --- a/src/tools/util.c +++ b/src/tools/util.c @@ -63,10 +63,10 @@ void hex_dump_asc(FILE *f, const u8 *in, size_t count, int addr) } } -void print_usage_and_die(const char *pgmname) +void print_usage_and_die() { int i = 0; - printf("Usage: %s [OPTIONS]\nOptions:\n", pgmname); + printf("Usage: %s [OPTIONS]\nOptions:\n", app_name); while (options[i].name) { char buf[40], tmp[5]; diff --git a/src/tools/util.h b/src/tools/util.h index 700c4cb1..e03d5412 100644 --- a/src/tools/util.h +++ b/src/tools/util.h @@ -18,11 +18,12 @@ extern const struct option options[]; extern const char *option_help[]; +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(const char *pgmname); +void print_usage_and_die(); const char * acl_to_str(const struct sc_acl_entry *e); void warn(const char *fmt, ...); void error(const char *fmt, ...);