From b1985a2bf2026b783ac52189bc398a1ea3e5a3f1 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Tue, 8 Aug 2017 00:00:14 -0400 Subject: [PATCH] Added version into compiled binary. --- core/c/mpw-util.h | 6 ++++++ platform-independent/cli-c/build | 7 ++++++- platform-independent/cli-c/cli/mpw-cli.c | 20 +++++++++++++------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/core/c/mpw-util.h b/core/c/mpw-util.h index 19dbc29e..740661ac 100644 --- a/core/c/mpw-util.h +++ b/core/c/mpw-util.h @@ -85,6 +85,12 @@ extern int mpw_verbosity; #ifndef ERR #define ERR -1 #endif +#ifndef stringify +#define stringify(s) #s +#endif +#ifndef stringify_def +#define stringify_def(s) stringify(s) +#endif //// Buffers and memory. diff --git a/platform-independent/cli-c/build b/platform-independent/cli-c/build index 1b426e0d..5d2e9927 100755 --- a/platform-independent/cli-c/build +++ b/platform-independent/cli-c/build @@ -47,6 +47,12 @@ mpw_sodium=${mpw_sodium:-1} # Use libsodium if available instead of cperciva's l export CFLAGS="-O3 $CFLAGS" export LDFLAGS="$LDFLAGS" +# Version. +if { mpw_version=$(git describe --match '*-cli*' --long --dirty --broken) || mpw_version=$(/dev/null; then + CFLAGS+=" -DMP_VERSION=$mpw_version" +fi +echo 2>&1 "Building mpw version ${mpw_version:-}..." + # Distribution specific configuration. # Homebrew - openssl for scrypt if hash brew 2>/dev/null; then @@ -144,7 +150,6 @@ fetchSource() ( } else - echo >&2 "error: Missing git-svn or svn." echo >&2 "error: Please install either or manually check out the sources" echo >&2 "error: from: $home" diff --git a/platform-independent/cli-c/cli/mpw-cli.c b/platform-independent/cli-c/cli/mpw-cli.c index 52bc4ceb..44b338e5 100644 --- a/platform-independent/cli-c/cli/mpw-cli.c +++ b/platform-independent/cli-c/cli/mpw-cli.c @@ -16,11 +16,17 @@ #include "mpw-util.h" #include "mpw-marshall.h" -#define MP_env_fullName "MP_FULLNAME" -#define MP_env_algorithm "MP_ALGORITHM" +#ifndef MP_VERSION +#define MP_VERSION ? +#endif +#define MP_ENV_fullName "MP_FULLNAME" +#define MP_ENV_algorithm "MP_ALGORITHM" static void usage() { + inf( "" + " Master Password v%s\n" + " https://masterpasswordapp.com\n\n", stringify_def( MP_VERSION ) ); inf( "" "Usage:\n" " mpw [-u|-U full-name] [-t pw-type] [-c counter] [-a algorithm] [-s value]\n" @@ -29,7 +35,7 @@ static void usage() { " -u full-name Specify the full name of the user.\n" " -u checks the master password against the config,\n" " -U allows updating to a new master password.\n" - " Defaults to %s in env or prompts.\n\n", MP_env_fullName ); + " Defaults to %s in env or prompts.\n\n", MP_ENV_fullName ); inf( "" " -t pw-type Specify the password's template.\n" " Defaults to 'long' (-p a), 'name' (-p i) or 'phrase' (-p r).\n" @@ -48,7 +54,7 @@ static void usage() { inf( "" " -a version The algorithm version to use, %d - %d.\n" " Defaults to %s in env or %d.\n\n", - MPAlgorithmVersionFirst, MPAlgorithmVersionLast, MP_env_algorithm, MPAlgorithmVersionCurrent ); + MPAlgorithmVersionFirst, MPAlgorithmVersionLast, MP_ENV_algorithm, MPAlgorithmVersionCurrent ); inf( "" " -s value The value to save for -t P or -p i.\n\n" ); inf( "" @@ -81,7 +87,7 @@ static void usage() { " ENVIRONMENT\n\n" " %-14s | The full name of the user (see -u).\n" " %-14s | The default algorithm version (see -a).\n\n", - MP_env_fullName, MP_env_algorithm ); + MP_ENV_fullName, MP_ENV_algorithm ); exit( 0 ); } @@ -156,8 +162,8 @@ int main(int argc, char *const argv[]) { const char *fullNameArg = NULL, *masterPasswordArg = NULL, *siteNameArg = NULL; const char *passwordTypeArg = NULL, *siteCounterArg = NULL, *algorithmVersionArg = NULL, *saveValueArg = NULL; const char *keyPurposeArg = NULL, *keyContextArg = NULL, *sitesFormatArg = NULL, *sitesRedactedArg = NULL; - fullNameArg = mpw_getenv( MP_env_fullName ); - algorithmVersionArg = mpw_getenv( MP_env_algorithm ); + fullNameArg = mpw_getenv( MP_ENV_fullName ); + algorithmVersionArg = mpw_getenv( MP_ENV_algorithm ); // Read the command-line options. for (int opt; (opt = getopt( argc, argv, "u:U:P:t:c:a:s:p:C:f:F:R:vqh" )) != EOF;)