6 changes: 4 additions & 2 deletions tools/tpm2_hmac.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -292,7 +292,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {

ctx.input = stdin;

*opts = tpm2_options_new("k:P:g:o:S:c:", ARRAY_LEN(topts), topts, on_option, on_args);
tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("k:P:g:o:S:c:", ARRAY_LEN(topts), topts,
on_option, on_args, empty_flags);

return *opts != NULL;
}
Expand Down
6 changes: 4 additions & 2 deletions tools/tpm2_listpersistent.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2016, Intel Corporation
// Copyright (c) 2016-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -142,7 +142,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{"kalg", required_argument, NULL, 'G'},
};

*opts = tpm2_options_new("g:G:", ARRAY_LEN(topts), topts, on_option, NULL);
tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("g:G:", ARRAY_LEN(topts), topts,
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
6 changes: 4 additions & 2 deletions tools/tpm2_load.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -199,7 +199,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
setbuf(stdout, NULL);
setvbuf (stdout, NULL, _IONBF, BUFSIZ);

*opts = tpm2_options_new("H:P:u:r:n:C:c:S:", ARRAY_LEN(topts), topts, on_option, NULL);
tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("H:P:u:r:n:C:c:S:", ARRAY_LEN(topts), topts,
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
6 changes: 4 additions & 2 deletions tools/tpm2_loadexternal.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -154,7 +154,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{ "context", required_argument, NULL, 'C'},
};

*opts = tpm2_options_new("H:u:r:C:", ARRAY_LEN(topts), topts, on_option, NULL);
tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("H:u:r:C:", ARRAY_LEN(topts), topts,
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
6 changes: 4 additions & 2 deletions tools/tpm2_makecredential.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -217,7 +217,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{NULL ,no_argument , NULL, '\0'}
};

*opts = tpm2_options_new("e:s:n:o:", ARRAY_LEN(topts), topts, on_option, NULL);
tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("e:s:n:o:", ARRAY_LEN(topts), topts,
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
6 changes: 4 additions & 2 deletions tools/tpm2_nvdefine.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -213,7 +213,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{ "input-session-handle", required_argument, NULL, 'S' },
};

*opts = tpm2_options_new("x:a:s:t:P:I:rwdL:S:X", ARRAY_LEN(topts), topts, on_option, NULL);
tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("x:a:s:t:P:I:rwdL:S:X", ARRAY_LEN(topts), topts,
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
5 changes: 3 additions & 2 deletions tools/tpm2_nvread.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -265,8 +265,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{"pcr-input-file", required_argument, NULL, 'F' },
};

tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("x:a:f:s:o:P:S:L:F:", ARRAY_LEN(topts),
topts, on_option, NULL);
topts, on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
6 changes: 4 additions & 2 deletions tools/tpm2_nvreadlock.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// Copyright (c) 2016, Atom Software Studios
// All rights reserved.
//
Expand Down Expand Up @@ -148,7 +148,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{ "input-session-handle",1, NULL, 'S' },
};

*opts = tpm2_options_new("x:a:P:Xp:d:S:hv", ARRAY_LEN(topts), topts, on_option, NULL);
tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("x:a:P:Xp:d:S:hv", ARRAY_LEN(topts), topts,
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
6 changes: 4 additions & 2 deletions tools/tpm2_nvrelease.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -135,7 +135,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{ "input-session-handle",1, NULL, 'S' },
};

*opts = tpm2_options_new("x:a:s:o:P:S:", ARRAY_LEN(topts), topts, on_option, NULL);
tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("x:a:s:o:P:S:", ARRAY_LEN(topts), topts,
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
5 changes: 3 additions & 2 deletions tools/tpm2_nvwrite.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -247,8 +247,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{"pcr-input-file", required_argument, NULL, 'F' },
};

tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("x:a:P:S:o:L:F:", ARRAY_LEN(topts), topts,
on_option, on_args);
on_option, on_args, empty_flags);

ctx.input_file = stdin;

Expand Down
5 changes: 3 additions & 2 deletions tools/tpm2_pcrevent.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -340,8 +340,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{ "password", required_argument, NULL, 'P' },
};

tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("i:S:P:", ARRAY_LEN(topts), topts,
on_option, on_arg);
on_option, on_arg, empty_flags);

return *opts != NULL;
}
Expand Down
5 changes: 3 additions & 2 deletions tools/tpm2_pcrextend.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2017, Intel Corporation
// Copyright (c) 2017-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -120,8 +120,9 @@ static bool on_arg(int argc, char **argv) {

bool tpm2_tool_onstart(tpm2_options **opts) {

tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new(NULL, 0, NULL,
NULL, on_arg);
NULL, on_arg, empty_flags);

return *opts != NULL;
}
Expand Down
5 changes: 3 additions & 2 deletions tools/tpm2_pcrlist.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -401,8 +401,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{ "format", required_argument, NULL, 'f' },
};

tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("g:o:L:s", ARRAY_LEN(topts), topts,
on_option, NULL);
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
5 changes: 3 additions & 2 deletions tools/tpm2_quote.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -259,8 +259,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{ "sig-hash-algorithm", required_argument, NULL, 'G' }
};

tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("k:c:P:l:g:L:S:q:s:m:f:G:", ARRAY_LEN(topts), topts,
on_option, NULL);
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
5 changes: 3 additions & 2 deletions tools/tpm2_rc_decode.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2016, Intel Corporation
// Copyright (c) 2016-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -244,8 +244,9 @@ static bool on_arg(int argc, char **argv) {

bool tpm2_tool_onstart(tpm2_options **opts) {

tpm2_option_flags flags = tpm2_option_flags_init(TPM2_OPTION_NO_SAPI);
*opts = tpm2_options_new(NULL, 0, NULL,
NULL, on_arg);
NULL, on_arg, flags);

return *opts != NULL;
}
Expand Down
5 changes: 3 additions & 2 deletions tools/tpm2_readpublic.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -142,8 +142,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{ "format", required_argument, NULL,'f' }
};

tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("H:o:c:f:", ARRAY_LEN(topts), topts,
on_option, NULL);
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
5 changes: 3 additions & 2 deletions tools/tpm2_rsadecrypt.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -166,8 +166,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{ "input-session-handle",1, NULL, 'S' },
};

tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("k:P:I:o:c:S:", ARRAY_LEN(topts), topts,
on_option, NULL);
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
5 changes: 3 additions & 2 deletions tools/tpm2_rsaencrypt.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -140,8 +140,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{"key-context", required_argument, NULL, 'c'},
};

tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("k:o:c:", ARRAY_LEN(topts), topts,
on_option, on_args);
on_option, on_args, empty_flags);

return *opts != NULL;
}
Expand Down
5 changes: 3 additions & 2 deletions tools/tpm2_send.c
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Intel Corporation
* Copyright (c) 2016-2018, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -157,8 +157,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{ "--output", required_argument, NULL, 'o' },
};

tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("i:o:", ARRAY_LEN(topts), topts,
on_option, on_args);
on_option, on_args, empty_flags);

ctx.input = stdin;
ctx.output = stdout;
Expand Down
5 changes: 3 additions & 2 deletions tools/tpm2_sign.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -271,8 +271,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{"format", required_argument, NULL, 'f'}
};

tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("k:P:g:m:t:s:c:S:f:", ARRAY_LEN(topts), topts,
on_option, NULL);
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
5 changes: 3 additions & 2 deletions tools/tpm2_startup.c
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Intel Corporation
* Copyright (c) 2016-2018, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -70,8 +70,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{ "clear", no_argument, NULL, 'c' },
};

tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("cs", ARRAY_LEN(topts), topts,
on_option, NULL);
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
5 changes: 3 additions & 2 deletions tools/tpm2_takeownership.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018 Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -203,8 +203,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{ "clear", no_argument, NULL, 'c' },
};

tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("o:e:l:O:E:L:c", ARRAY_LEN(topts), topts,
on_option, NULL);
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
32 changes: 20 additions & 12 deletions tools/tpm2_tool.c
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Intel Corporation
* Copyright (c) 2016-2018, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -109,17 +109,25 @@ int main(int argc, char *argv[], char *envp[]) {
LOG_ERR("retrieving tool options");
return 1;
}
} else {
tpm2_option_flags ftmp = tpm2_option_flags_init(0);
tool_opts = tpm2_options_new(NULL, 0,
NULL, NULL, NULL, ftmp);
if (!tool_opts) {
return 1;
}
}

tpm2_option_flags flags = { .all = 0 };
tpm2_option_flags *flags = tpm2_options_get_flags(tool_opts);
TSS2_TCTI_CONTEXT *tcti;
tpm2_option_code rc = tpm2_handle_options(argc, argv, envp, tool_opts, &flags, &tcti);
tpm2_option_code rc = tpm2_handle_options(argc, argv, envp, tool_opts,
flags, &tcti);
if (rc != tpm2_option_code_continue) {
ret = rc == tpm2_option_code_err ? 1 : 0;
goto free_opts;
}

if (flags.verbose) {
if (flags->verbose) {
log_set_level(log_level_verbose);
}

Expand All @@ -130,29 +138,29 @@ int main(int argc, char *argv[], char *envp[]) {
* option and argument life-cycle. Thus TOOL_OUTPUT is only guaranteed
* to respect quiet from here on out (onrun and onexit).
*/
if (flags.quiet) {
if (flags->quiet) {
output_enabled = false;
}

/* figure out the tcti */
TSS2_SYS_CONTEXT *sapi_context = !flags->no_sapi ?
sapi_ctx_init(tcti) : NULL;

/* TODO SAPI INIT */
TSS2_SYS_CONTEXT *sapi_context = sapi_ctx_init(tcti);

if (flags.enable_errata) {
if (flags->enable_errata) {
tpm2_errata_init(sapi_context);
}

/*
* Call the specific tool, all tools implement this function instead of
* 'main'.
*/
ret = tpm2_tool_onrun(sapi_context, flags) ? 1 : 0;
ret = tpm2_tool_onrun(sapi_context, *flags) ? 1 : 0;
/*
* Cleanup contexts & memory allocated for the modified argument vector
* passed to execute_tool.
*/
sapi_teardown_full(sapi_context);
if (sapi_context) {
sapi_teardown_full(sapi_context);
}

free_opts:
if (tool_opts) {
Expand Down
5 changes: 3 additions & 2 deletions tools/tpm2_unseal.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -203,8 +203,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{NULL, no_argument, NULL, '\0'}
};

tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("H:P:o:c:S:L:F:", ARRAY_LEN(topts), topts,
on_option, NULL);
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down
6 changes: 3 additions & 3 deletions tools/tpm2_verifysignature.c
@@ -1,5 +1,5 @@
//**********************************************************************;
// Copyright (c) 2015, Intel Corporation
// Copyright (c) 2015-2018, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -271,9 +271,9 @@ bool tpm2_tool_onstart(tpm2_options **opts) {
{ "key-context", 1, NULL, 'c' },
};


tpm2_option_flags empty_flags = tpm2_option_flags_init(0);
*opts = tpm2_options_new("k:g:m:D:rs:t:c:", ARRAY_LEN(topts), topts,
on_option, NULL);
on_option, NULL, empty_flags);

return *opts != NULL;
}
Expand Down