Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Query the Mbed TLS compile time configuration |
| 3 | * |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 4 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 5 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 8 | #include "mbedtls/build_info.h" |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 9 | |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 10 | #include "mbedtls/platform.h" |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 11 | |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 12 | #define USAGE \ |
| 13 | "usage: %s [ -all | -any | -l ] <MBEDTLS_CONFIG> ...\n\n" \ |
| 14 | "This program takes command line arguments which correspond to\n" \ |
| 15 | "the string representation of Mbed TLS compile time configurations.\n\n" \ |
Jerry Yu | 08dccc1 | 2022-08-10 10:02:04 +0800 | [diff] [blame] | 16 | "If \"--all\" and \"--any\" are not used, then, if all given arguments\n" \ |
| 17 | "are defined in the Mbed TLS build, 0 is returned; otherwise 1 is\n" \ |
Jerry Yu | 62c8763 | 2022-08-11 10:18:36 +0800 | [diff] [blame] | 18 | "returned. Macro expansions of configurations will be printed (if any).\n" \ |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 19 | "-l\tPrint all available configuration.\n" \ |
| 20 | "-all\tReturn 0 if all configurations are defined. Otherwise, return 1\n" \ |
| 21 | "-any\tReturn 0 if any configuration is defined. Otherwise, return 1\n" \ |
| 22 | "-h\tPrint this usage\n" |
| 23 | |
Jerry Yu | a15f3cc | 2021-12-06 13:44:39 +0800 | [diff] [blame] | 24 | #include <string.h> |
Gilles Peskine | c772b18 | 2021-01-12 15:55:10 +0100 | [diff] [blame] | 25 | #include "query_config.h" |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 26 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 27 | int main(int argc, char *argv[]) |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 28 | { |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 29 | int i; |
| 30 | |
Aditya Deshpande | 9b45f6b | 2023-02-03 16:15:30 +0000 | [diff] [blame] | 31 | if (argc < 2 || strcmp(argv[1], "-h") == 0) { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 32 | mbedtls_printf(USAGE, argv[0]); |
| 33 | return MBEDTLS_EXIT_FAILURE; |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 34 | } |
| 35 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 36 | if (strcmp(argv[1], "-l") == 0) { |
Jerry Yu | a15f3cc | 2021-12-06 13:44:39 +0800 | [diff] [blame] | 37 | list_config(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 38 | return 0; |
Jerry Yu | a15f3cc | 2021-12-06 13:44:39 +0800 | [diff] [blame] | 39 | } |
| 40 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 41 | if (strcmp(argv[1], "-all") == 0) { |
| 42 | for (i = 2; i < argc; i++) { |
| 43 | if (query_config(argv[i]) != 0) { |
| 44 | return 1; |
| 45 | } |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 46 | } |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 47 | return 0; |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 48 | } |
| 49 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 50 | if (strcmp(argv[1], "-any") == 0) { |
| 51 | for (i = 2; i < argc; i++) { |
| 52 | if (query_config(argv[i]) == 0) { |
| 53 | return 0; |
| 54 | } |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 55 | } |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 56 | return 1; |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 57 | } |
| 58 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 59 | for (i = 1; i < argc; i++) { |
| 60 | if (query_config(argv[i]) != 0) { |
| 61 | return 1; |
| 62 | } |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 63 | } |
| 64 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 65 | return 0; |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 66 | } |