| RSA BSAFE Micro Edition Suite |
Streamlined security for mobile and embedded devices |
 
![]() |
/* $Id: r_version.c,v 1.21 2005/05/11 00:26:22 jleiseboer Exp $ */ /* * Copyright (C) 1998-2003 RSA Security Inc. * * This file shall only be used to demonstrate how to interface to an * RSA Security Inc. licensed development product. * * You have a royalty-free right to use, reproduce and distribute this * demonstration file, provided that you agree that RSA Security Inc. * has no warranty, implied or otherwise, or liability for this * demonstration file (including any modified version). This software * is provided "as is" without warranties or representations of any * kind. RSA Security disclaims all conditions and warranties, statutory * and otherwise, both express and implied, with respect to the software, * its quality and performance, including but not limited to, all * implied warranties of merchantability, fitness for a particular * purpose, title and noninfringement of third party rights. Without * limiting the foregoing, RSA Security does not warrant that the * software is error-free or that errors in the product will be * corrected. You agree that RSA Security shall not be liable for any * direct, indirect, incidental, special, consequential, punitive or * other damages whatsoever resulting from your use of this software * or any modified version. * * */ #include "r_prod.h" #ifdef R_EVAL_BUILD #include "r_eval_display_decl.h" #endif /* R_EVAL_BUILD */ static char *version_usage[]= { "usage: r_version [options]\n", "where options are:\n", " -a - All flags\n", " -n - No prefix on output\n", " -b - BUILT_ON (date built)\n", " -B - BUILD_ID (build identifier)\n", " -i - ID (PLATFORM-BUILD_ID)\n", " -f - CFLAGS (compiler flags)\n", " -p - PLATFORM (platform name)\n", " -v - VERSION (version)\n", " -V - VERSION_NUMBER (version number)\n", " -e - EVAL (evaluation build)\n", " -fips140 - FIPS140 (FIPS140 build)\n", NULL }; static char *print_val(char *str); static char *v_prefix(char *str, int no_prefix); /* * Main sample program entry point * * @param argc [In] The number of arguments typed on the command line. * @param argv [In] The array of individual arguments from the command line. * * @returns R_ERROR_NONE indicates success. * See @ref R_ERROR_IDS for valid values. */ int main(int argc, char **argv) { BIO *out = NULL; #ifndef SPEC R_LIB_CTX *lib_ctx = NULL; #endif /* SPEC */ int ret = R_ERROR_NONE; int i; int cflags; int version; int date; int platform; int build; int id; int is_eval; int is_fips; int no_prefix; int version_id; /* Set the defaults */ cflags = 0; version = 0; date = 0; platform = 0; build = 0; id = 0; is_eval = 0; is_fips = 0; version_id = 0; no_prefix = 0; /* * Create BIO to stdout. BIOs are the Basic Input/Output mechanism * provided by RSA and are recommended for all input and output from * applications. */ if ((out = BIO_new_fp(stdout, BIO_NOCLOSE)) == NULL) { ret = R_ERROR_ALLOC_FAILURE; goto end; } #ifndef SPEC if ((ret = PRODUCT_LIBRARY_NEW(PRODUCT_DEFAULT_RESOURCE_LIST(), R_RES_FLAG_DEF, &lib_ctx)) != R_ERROR_NONE) { BIO_printf(out, "Unable to create the library context\n"); /* Keep going; still want to get version information */ lib_ctx = NULL; } #endif /* SPEC */ /* Parse the command line parameters */ /* No arguments indicates that the default will be used */ if (argc == 1) { version = 1; } /* Process all command line options */ for (i = 1; i < argc; i++) { if (Strcmp(argv[i], "-v") == 0) { version = 1; } else if (Strcmp(argv[i], "-V") == 0) { version_id = 1; } else if (Strcmp(argv[i], "-n") == 0) { no_prefix = 1; } else if (Strcmp(argv[i], "-b") == 0) { date = 1; } else if (Strcmp(argv[i], "-f") == 0) { cflags = 1; } else if (Strcmp(argv[i], "-p") == 0) { platform = 1; } else if (Strcmp(argv[i], "-B") == 0) { build = 1; } else if (Strcmp(argv[i], "-i") == 0) { id = 1; } else if (Strcmp(argv[i], "-e") == 0) { is_eval = 1; } else if (Strcmp(argv[i], "-fips140") == 0) { is_fips = 1; } else if (Strcmp(argv[i], "-a") == 0) { date = 1; version = 1; cflags = 1; platform = 1; is_eval = 1; is_fips = 1; version_id = 1; build = 1; id = 1; } else { BIO_printf(out, "Unknown option %s\n", argv[i]); goto bad; } } /* Display the help menu if an invalid option was entered */ if (0) { char **pp; bad: for (pp = version_usage; (*pp != NULL); pp++) { BIO_printf(out, *pp); } ret = R_ERROR_FAILED; goto end; } /* Retrieve and print the requested library version information */ /* Print the version if required */ if (version) { BIO_printf(out, "%s%s\n", v_prefix("VERSION", no_prefix), print_val("VERSION")); } /* Print the version number if required */ if (version_id) { BIO_printf(out, "%s%04x\n", v_prefix("VERSION_NUMBER", no_prefix), PRODUCT_LIBRARY_VERSION()); } /* Print the build date if required */ if (date) { BIO_printf(out, "%s%s\n", v_prefix("BUILT_ON", no_prefix), print_val("DATE")); } /* Print the build platform if required */ if (platform) { BIO_printf(out, "%s%s\n", v_prefix("PLATFORM", no_prefix), print_val("PLATFORM")); } /* Print the build ID if required */ if (build) { BIO_printf(out, "%s%s\n", v_prefix("BUILD_ID", no_prefix), print_val("BUILD ID")); } /* * ID is used when generating a name to uniquely identify a library * executable as it includes the platform name and the build identifier */ if (id) { BIO_printf(out, "%s%s-%s\n", v_prefix("ID", no_prefix), print_val("PLATFORM"), print_val("BUILD ID")); } /* Print the compile flags if required */ if (cflags) { BIO_printf(out, "%s%s\n", v_prefix("CFLAGS", no_prefix), print_val("FLAGS")); } /* Print the evaluation information if required */ if (is_eval) { BIO_printf(out, "%s%s\n", v_prefix("EVAL", no_prefix), print_val("EVAL")); #ifdef R_EVAL_BUILD #include "r_eval_display_impl.h" #endif } /* Print the FIPS 140 information if required */ if (is_fips) { BIO_printf(out, "%s%s\n", v_prefix("FIPS140", no_prefix), print_val("FIPS140")); } end: if ((ret != R_ERROR_NONE) && (out != NULL)) { BIO_printf(out, "Error: (%d)\n", ret); } #ifndef SPEC if (lib_ctx != NULL) { PRODUCT_LIBRARY_FREE(lib_ctx); } #endif /* SPEC */ /* * Clean up. Destroy the dynamically allocated objects and return an exit * code. */ if (out != NULL) { BIO_free(out); } return(R_ERROR_EXIT_CODE(ret)); } /* * Retrieves the requested library information value for printing. * * @param str [In] The string to look up. * * @returns The library information value string. */ static char *print_val(char *str) { char *val; /* * Retrieve the value of the library information requested. If it is * NULL, return an empty string. */ if ((val = PRODUCT_LIBRARY_INFO(PRODUCT_LIBRARY_INFO_TYPE_FROM_STRING(str))) == NULL) { val = ""; } return(val); } /* * Formats the prefix string. * * @param str [In] The string to format. * * @returns The formatted string. */ static char *v_prefix(char *str, int no_prefix) { static char pbuf[64]; char *prefix; /* * If no prefix is required then return an empty string. Otherwise, return * a formatted buffer. */ if (no_prefix) { prefix = ""; } else { sprintf(pbuf, "%15s: ", str); prefix = pbuf; } return(prefix); }