]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Allow --mode=print to read file from stdin
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 6 May 2024 22:10:14 +0000 (16:10 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 6 May 2024 22:10:35 +0000 (16:10 -0600)
Either works:

$ fort --mode=print   < cert.cer
$ fort --mode=print - < cert.cer

Progress for #122.

src/config.c
src/print_file.c

index 3bf9fcd9464a5be9668b731051bcac777dff4421..87040334a276f3d16313173d1efeef18a289860a 100644 (file)
@@ -993,9 +993,7 @@ static int
 validate_config(void)
 {
        if (rpki_config.mode == PRINT_FILE)
-               return (rpki_config.payload == NULL)
-                   ? pr_op_err("Missing file name.")
-                   : 0;
+               return 0;
 
        if (rpki_config.payload != NULL)
                return pr_op_err("I don't know what '%s' is.",
index b310d41c7d6ac3825f97b8a9181cf1088a022f6d..7bb4572cf80207dc381a4104bdadbaa7d4c588ad 100644 (file)
@@ -169,9 +169,13 @@ print_file(void)
        json_t *json = NULL;
        int error = 0;
 
-       file = fopen(filename, "rb");
-       if (file == NULL)
-               return pr_op_err("Cannot open file: %s", strerror(errno));
+       if (filename == NULL || strcmp(filename, "-") == 0) {
+               file = stdin;
+       } else {
+               file = fopen(filename, "rb");
+               if (file == NULL)
+                       return pr_op_err("Cannot open file: %s", strerror(errno));
+       }
 
        switch (guess_file_type(file)) {
        case FT_UNK:
@@ -190,7 +194,8 @@ print_file(void)
                break;
        }
 
-       fclose(file);
+       if (file != stdin)
+               fclose(file);
        if (error)
                return error;
        if (json == NULL)