]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fileio: add READ_FULL_FILE_UNBASE64 flag for read_full_file_full()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 8 Apr 2019 14:40:22 +0000 (23:40 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 9 Apr 2019 06:50:22 +0000 (15:50 +0900)
src/basic/fileio.c
src/basic/fileio.h

index 78928979e9a78e9ccf17283b0883a5c4853cebe2..9ab2f501c7681f12100e1e43c87ab12c53063da9 100644 (file)
@@ -17,6 +17,7 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "fs-util.h"
+#include "hexdecoct.h"
 #include "log.h"
 #include "macro.h"
 #include "missing.h"
@@ -278,6 +279,7 @@ int read_full_stream_full(
 
         assert(f);
         assert(ret_contents);
+        assert(!(flags & READ_FULL_FILE_UNBASE64) || ret_size);
 
         n_next = LINE_MAX; /* Start size */
 
@@ -354,6 +356,12 @@ int read_full_stream_full(
                 n_next = MIN(n * 2, READ_FULL_BYTES_MAX);
         }
 
+        if (flags & READ_FULL_FILE_UNBASE64) {
+                buf[l++] = 0;
+                r = unbase64mem_full(buf, l, flags & READ_FULL_FILE_SECURE, (void **) ret_contents, ret_size);
+                goto finalize;
+        }
+
         if (!ret_size) {
                 /* Safety check: if the caller doesn't want to know the size of what we just read it will rely on the
                  * trailing NUL byte. But if there's an embedded NUL byte, then we should refuse operation as otherwise
index 6add67750a7e678f79317a73299ae935075998aa..760e7386884ef80ccf9181e5239b868e07a466de 100644 (file)
@@ -29,7 +29,8 @@ typedef enum {
 } WriteStringFileFlags;
 
 typedef enum {
-        READ_FULL_FILE_SECURE = 1 << 0,
+        READ_FULL_FILE_SECURE   = 1 << 0,
+        READ_FULL_FILE_UNBASE64 = 1 << 1,
 } ReadFullFileFlags;
 
 int write_string_stream_ts(FILE *f, const char *line, WriteStringFileFlags flags, struct timespec *ts);