1 /*
2  *  Query the Mbed TLS compile time configuration
3  *
4  *  Copyright The Mbed TLS Contributors
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.
18  */
19 
20 #include "mbedtls/build_info.h"
21 
22 #include "mbedtls/platform.h"
23 
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"    \
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"        \
30     "returned. Macro expansions of configurations will be printed (if any).\n"                                 \
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 
36 #include <string.h>
37 #include "query_config.h"
38 
main(int argc,char * argv[])39 int main(int argc, char *argv[])
40 {
41     int i;
42 
43     if (argc < 2 || strcmp(argv[1], "-h") == 0) {
44         mbedtls_printf(USAGE, argv[0]);
45         return MBEDTLS_EXIT_FAILURE;
46     }
47 
48     if (strcmp(argv[1], "-l") == 0) {
49         list_config();
50         return 0;
51     }
52 
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             }
58         }
59         return 0;
60     }
61 
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             }
67         }
68         return 1;
69     }
70 
71     for (i = 1; i < argc; i++) {
72         if (query_config(argv[i]) != 0) {
73             return 1;
74         }
75     }
76 
77     return 0;
78 }
79