From: Simon Josefsson Date: Wed, 12 Dec 2012 10:59:21 +0000 (+0100) Subject: Add version information. X-Git-Tag: v1.11.0~4 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df94c75f90295a2e0b986f1dbd6e30c460acca11;p=yubikey-personalization Add version information. --- diff --git a/Makefile.am b/Makefile.am index 53015a9..0fb531a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,10 +38,12 @@ AM_CFLAGS = $(WARN_CFLAGS) # The library. ykpers_includedir=$(includedir)/ykpers-1 -ykpers_include_HEADERS = ykpers.h ykcore/ykstatus.h ykcore/ykcore.h ykcore/ykdef.h ykpbkdf2.h +ykpers_include_HEADERS = ykpers.h ykpers-version.h +ykpers_include_HEADERS += ykcore/ykstatus.h ykcore/ykcore.h ykcore/ykdef.h +ykpers_include_HEADERS += ykpbkdf2.h lib_LTLIBRARIES = libykpers-1.la -libykpers_1_la_SOURCES = ykpers.c ykpbkdf2.c +libykpers_1_la_SOURCES = ykpers.c ykpers-version.c ykpbkdf2.c libykpers_1_la_SOURCES += rfc4634/hmac.c rfc4634/usha.c rfc4634/sha.h \ rfc4634/sha1.c rfc4634/sha224-256.c rfc4634/sha384-512.c \ rfc4634/sha-private.h diff --git a/NEWS b/NEWS index 7cb571a..4859bbb 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,13 @@ Yubikey-personalize NEWS -- History of user-visible changes. -*- outline -*- -* Version 1.10.1 (unreleased) +* Version 1.11.0 (unreleased) + +** Added version symbols and functions. +The header file is "ykpers-version.h" and it contains the following +symbols and functions: YKPERS_VERSION_STRING, YKPERS_VERSION_NUMBER, +YKPERS_VERSION_MAJOR, YKPERS_VERSION_MINOR, YKPERS_VERSION_PATCH, +ykpers_check_version. Requested by Giampaolo Bellini +. * Version 1.10.0 (released 2012-12-11) diff --git a/configure.ac b/configure.ac index a802e34..bcc07bb 100644 --- a/configure.ac +++ b/configure.ac @@ -26,7 +26,7 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -AC_INIT([yubikey-personalization], [1.10.1], +AC_INIT([yubikey-personalization], [1.11.0], [yubico-devel@googlegroups.com], [ykpers], [http://code.google.com/p/yubikey-personalization/]) AC_CONFIG_AUX_DIR([build-aux]) @@ -37,7 +37,7 @@ AC_CONFIG_MACRO_DIR([m4]) # Interfaces added: AGE++ # Interfaces removed: AGE=0 AC_SUBST(LT_CURRENT, 11) -AC_SUBST(LT_REVISION, 1) +AC_SUBST(LT_REVISION, 2) AC_SUBST(LT_AGE, 10) AM_INIT_AUTOMAKE([-Wall -Werror]) @@ -175,9 +175,15 @@ if test "$gl_gcc_warnings" = yes; then gl_WARN_ADD([-fdiagnostics-show-option]) fi +AC_SUBST(YKPERS_VERSION_MAJOR, `echo $PACKAGE_VERSION | sed 's/\(.*\)\..*\..*/\1/g'`) +AC_SUBST(YKPERS_VERSION_MINOR, `echo $PACKAGE_VERSION | sed 's/.*\.\(.*\)\..*/\1/g'`) +AC_SUBST(YKPERS_VERSION_PATCH, `echo $PACKAGE_VERSION | sed 's/.*\..*\.\(.*\)/\1/g'`) +AC_SUBST(YKPERS_VERSION_NUMBER, `printf "0x%02x%02x%02x" $YKPERS_VERSION_MAJOR $YKPERS_VERSION_MINOR $YKPERS_VERSION_PATCH`) + AC_CONFIG_FILES([ Makefile ykpers-1.pc + ykpers-version.h ykcore/Makefile tests/Makefile ]) @@ -185,7 +191,7 @@ AC_OUTPUT AC_MSG_NOTICE([summary of build options: - version: ${VERSION} shared $LT_CURRENT:$LT_REVISION:$LT_AGE + version: ${VERSION} shared $LT_CURRENT:$LT_REVISION:$LT_AGE major $YKPERS_VERSION_MAJOR minor $YKPERS_VERSION_MINOR patch $YKPERS_VERSION_PATCH number $YKPERS_VERSION_NUMBER Host type: ${host} Install prefix: ${prefix} Compiler: ${CC} diff --git a/libykpers-1.map b/libykpers-1.map index 9ee32ec..d3457e3 100644 --- a/libykpers-1.map +++ b/libykpers-1.map @@ -177,3 +177,9 @@ LIBYKPERS_1.10 { yk_write_scan_map; # Variables: } LIBYKPERS_1.9; + +LIBYKPERS_1.11 { + global: + ykpers_check_version; +# Variables: +} LIBYKPERS_1.10; diff --git a/tests/selftest.c b/tests/selftest.c index f8f60c6..a09e27f 100644 --- a/tests/selftest.c +++ b/tests/selftest.c @@ -29,6 +29,7 @@ */ #include +#include #include int main (void) @@ -36,6 +37,25 @@ int main (void) YKP_CONFIG *ykp; int rc; + if (strcmp (YKPERS_VERSION_STRING, ykpers_check_version (NULL)) != 0) + { + printf ("version mismatch %s != %s\n",YKPERS_VERSION_STRING, + ykpers_check_version (NULL)); + return 1; + } + + if (ykpers_check_version (YKPERS_VERSION_STRING) == NULL) + { + printf ("version NULL?\n"); + return 1; + } + + if (ykpers_check_version ("99.99.99") != NULL) + { + printf ("version not NULL?\n"); + return 1; + } + ykp = ykp_alloc (); if (!ykp) { diff --git a/ykpers-version.c b/ykpers-version.c new file mode 100644 index 0000000..0d0d473 --- /dev/null +++ b/ykpers-version.c @@ -0,0 +1,130 @@ +/* -*- mode:C; c-file-style: "bsd" -*- */ +/* + * Copyright (c) 2012 Yubico AB + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#define _GNU_SOURCE +#include + +/* From http://article.gmane.org/gmane.os.freebsd.devel.hackers/23606 */ +int +my_strverscmp(const char *s1, const char *s2) +{ + static const char *digits = "0123456789"; + int ret, lz1, lz2; + size_t p1, p2; + + p1 = strcspn(s1, digits); + p2 = strcspn(s2, digits); + while (p1 == p2 && s1[p1] != '\0' && s2[p2] != '\0') { + /* Different prefix */ + if ((ret = strncmp(s1, s2, p1)) != 0) + return ret; + + s1 += p1; + s2 += p2; + + lz1 = lz2 = 0; + if (*s1 == '0') + lz1 = 1; + if (*s2 == '0') + lz2 = 1; + + if (lz1 > lz2) + return -1; + else if (lz1 < lz2) + return 1; + else if (lz1 == 1) { + /* + * If the common prefix for s1 and s2 consists only of zeros, then the + * "longer" number has to compare less. Otherwise the comparison needs + * to be numerical (just fallthrough). See + * http://refspecs.freestandards.org/LSB_2.0.1/LSB-generic/ + * LSB-generic/baselib-strverscmp.html + */ + while (*s1 == '0' && *s2 == '0') { + ++s1; + ++s2; + } + + p1 = strspn(s1, digits); + p2 = strspn(s2, digits); + + /* Catch empty strings */ + if (p1 == 0 && p2 > 0) + return 1; + else if (p2 == 0 && p1 > 0) + return -1; + + /* Prefixes are not same */ + if (*s1 != *s2 && *s1 != '0' && *s2 != '0') { + if (p1 < p2) + return 1; + else if (p1 > p2) + return -1; + } else { + if (p1 < p2) + ret = strncmp(s1, s2, p1); + else if (p1 > p2) + ret = strncmp(s1, s2, p2); + if (ret != 0) + return ret; + } + } + + p1 = strspn(s1, digits); + p2 = strspn(s2, digits); + + if (p1 < p2) + return -1; + else if (p1 > p2) + return 1; + else if ((ret = strncmp(s1, s2, p1)) != 0) + return ret; + + /* Numbers are equal or not present, try with next ones. */ + s1 += p1; + s2 += p2; + p1 = strcspn(s1, digits); + p2 = strcspn(s2, digits); + } + + return strcmp(s1, s2); +} + +const char * +ykpers_check_version (const char *req_version) +{ + if (!req_version || my_strverscmp (req_version, YKPERS_VERSION_STRING) <= 0) + return YKPERS_VERSION_STRING; + + return NULL; +} diff --git a/ykpers-version.h.in b/ykpers-version.h.in new file mode 100644 index 0000000..a37d806 --- /dev/null +++ b/ykpers-version.h.in @@ -0,0 +1,90 @@ +/* -*- mode:C; c-file-style: "bsd" -*- */ +/* + * Copyright (c) 2012 Yubico AB + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __YKPERS_VERSION_H_INCLUDED__ +#define __YKPERS_VERSION_H_INCLUDED__ + +# ifdef __cplusplus +extern "C" { +# endif + +/** + * YKPERS_VERSION_STRING + * + * Pre-processor symbol with a string that describe the header file + * version number. Used together with ykpers_check_version() to verify + * header file and run-time library consistency. + */ +#define YKPERS_VERSION_STRING "@VERSION@" + +/** + * YKPERS_VERSION_NUMBER + * + * Pre-processor symbol with a hexadecimal value describing the header + * file version number. For example, when the header version is 1.2.3 + * this symbol will have the value 0x01020300. The last two digits + * are only used between public releases, and will otherwise be 00. + */ +#define YKPERS_VERSION_NUMBER @YKPERS_VERSION_NUMBER@ + +/** + * YKPERS_VERSION_MAJOR + * + * Pre-processor symbol with a decimal value that describe the major + * level of the header file version number. For example, when the + * header version is 1.2.3 this symbol will be 1. + */ +#define YKPERS_VERSION_MAJOR @YKPERS_VERSION_MAJOR@ + +/** + * YKPERS_VERSION_MINOR + * + * Pre-processor symbol with a decimal value that describe the minor + * level of the header file version number. For example, when the + * header version is 1.2.3 this symbol will be 2. + */ +#define YKPERS_VERSION_MINOR @YKPERS_VERSION_MINOR@ + +/** + * YKPERS_VERSION_PATCH + * + * Pre-processor symbol with a decimal value that describe the patch + * level of the header file version number. For example, when the + * header version is 1.2.3 this symbol will be 3. + */ +#define YKPERS_VERSION_PATCH @YKPERS_VERSION_PATCH@ + +const char *ykpers_check_version (const char *req_version); + +# ifdef __cplusplus +} +# endif + +#endif /* __YKPERS_VERSION_H_INCLUDED__ */