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 |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 5 | * SPDX-License-Identifier: Apache-2.0 |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 8 | * not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 18 | */ |
| 19 | |
Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 20 | #include "mbedtls/build_info.h" |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 21 | |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 22 | #include "mbedtls/platform.h" |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 23 | |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 24 | #define USAGE \ |
| 25 | "usage: %s [ -all | -any | -l ] <MBEDTLS_CONFIG> ...\n\n" \ |
| 26 | "This program takes command line arguments which correspond to\n" \ |
| 27 | "the string representation of Mbed TLS compile time configurations.\n\n" \ |
Jerry Yu | 08dccc1 | 2022-08-10 10:02:04 +0800 | [diff] [blame] | 28 | "If \"--all\" and \"--any\" are not used, then, if all given arguments\n" \ |
| 29 | "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] | 30 | "returned. Macro expansions of configurations will be printed (if any).\n" \ |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 31 | "-l\tPrint all available configuration.\n" \ |
| 32 | "-all\tReturn 0 if all configurations are defined. Otherwise, return 1\n" \ |
| 33 | "-any\tReturn 0 if any configuration is defined. Otherwise, return 1\n" \ |
| 34 | "-h\tPrint this usage\n" |
| 35 | |
Jerry Yu | a15f3cc | 2021-12-06 13:44:39 +0800 | [diff] [blame] | 36 | #include <string.h> |
Gilles Peskine | c772b18 | 2021-01-12 15:55:10 +0100 | [diff] [blame] | 37 | #include "query_config.h" |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 38 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 39 | int main(int argc, char *argv[]) |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 40 | { |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 41 | int i; |
| 42 | |
Aditya Deshpande | 9b45f6b | 2023-02-03 16:15:30 +0000 | [diff] [blame] | 43 | if (argc < 2 || strcmp(argv[1], "-h") == 0) { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 44 | mbedtls_printf(USAGE, argv[0]); |
| 45 | return MBEDTLS_EXIT_FAILURE; |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 46 | } |
| 47 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 48 | if (strcmp(argv[1], "-l") == 0) { |
Jerry Yu | a15f3cc | 2021-12-06 13:44:39 +0800 | [diff] [blame] | 49 | list_config(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 50 | return 0; |
Jerry Yu | a15f3cc | 2021-12-06 13:44:39 +0800 | [diff] [blame] | 51 | } |
| 52 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 53 | if (strcmp(argv[1], "-all") == 0) { |
| 54 | for (i = 2; i < argc; i++) { |
| 55 | if (query_config(argv[i]) != 0) { |
| 56 | return 1; |
| 57 | } |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 58 | } |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 59 | return 0; |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 60 | } |
| 61 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 62 | if (strcmp(argv[1], "-any") == 0) { |
| 63 | for (i = 2; i < argc; i++) { |
| 64 | if (query_config(argv[i]) == 0) { |
| 65 | return 0; |
| 66 | } |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 67 | } |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 68 | return 1; |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 69 | } |
| 70 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 71 | for (i = 1; i < argc; i++) { |
| 72 | if (query_config(argv[i]) != 0) { |
| 73 | return 1; |
| 74 | } |
Jerry Yu | 2fcb056 | 2022-07-27 17:30:49 +0800 | [diff] [blame] | 75 | } |
| 76 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 77 | return 0; |
Andres AG | 509ba69 | 2018-10-26 18:41:08 +0100 | [diff] [blame] | 78 | } |