]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/fileio.c
af22ec9110624ed7d157ede1f16e1f60d800142a
[thirdparty/systemd.git] / src / basic / fileio.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <ctype.h>
4 #include <errno.h>
5 #include <fcntl.h>
6 #include <limits.h>
7 #include <stdarg.h>
8 #include <stdint.h>
9 #include <stdio_ext.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <sys/stat.h>
13 #include <sys/types.h>
14 #include <unistd.h>
15
16 #include "alloc-util.h"
17 #include "fd-util.h"
18 #include "fileio.h"
19 #include "fs-util.h"
20 #include "hexdecoct.h"
21 #include "log.h"
22 #include "macro.h"
23 #include "missing.h"
24 #include "parse-util.h"
25 #include "path-util.h"
26 #include "stdio-util.h"
27 #include "string-util.h"
28 #include "tmpfile-util.h"
29
30 #define READ_FULL_BYTES_MAX (4U*1024U*1024U)
31
32 int fopen_unlocked(const char *path, const char *options, FILE **ret) {
33 assert(ret);
34
35 FILE *f = fopen(path, options);
36 if (!f)
37 return -errno;
38
39 (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
40
41 *ret = f;
42 return 0;
43 }
44
45 int fdopen_unlocked(int fd, const char *options, FILE **ret) {
46 assert(ret);
47
48 FILE *f = fdopen(fd, options);
49 if (!f)
50 return -errno;
51
52 (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
53
54 *ret = f;
55 return 0;
56 }
57
58 int write_string_stream_ts(
59 FILE *f,
60 const char *line,
61 WriteStringFileFlags flags,
62 struct timespec *ts) {
63
64 bool needs_nl;
65 int r;
66
67 assert(f);
68 assert(line);
69
70 if (ferror(f))
71 return -EIO;
72
73 needs_nl = !(flags & WRITE_STRING_FILE_AVOID_NEWLINE) && !endswith(line, "\n");
74
75 if (needs_nl && (flags & WRITE_STRING_FILE_DISABLE_BUFFER)) {
76 /* If STDIO buffering was disabled, then let's append the newline character to the string itself, so
77 * that the write goes out in one go, instead of two */
78
79 line = strjoina(line, "\n");
80 needs_nl = false;
81 }
82
83 if (fputs(line, f) == EOF)
84 return -errno;
85
86 if (needs_nl)
87 if (fputc('\n', f) == EOF)
88 return -errno;
89
90 if (flags & WRITE_STRING_FILE_SYNC)
91 r = fflush_sync_and_check(f);
92 else
93 r = fflush_and_check(f);
94 if (r < 0)
95 return r;
96
97 if (ts) {
98 struct timespec twice[2] = {*ts, *ts};
99
100 if (futimens(fileno(f), twice) < 0)
101 return -errno;
102 }
103
104 return 0;
105 }
106
107 static int write_string_file_atomic(
108 const char *fn,
109 const char *line,
110 WriteStringFileFlags flags,
111 struct timespec *ts) {
112
113 _cleanup_fclose_ FILE *f = NULL;
114 _cleanup_free_ char *p = NULL;
115 int r;
116
117 assert(fn);
118 assert(line);
119
120 r = fopen_temporary(fn, &f, &p);
121 if (r < 0)
122 return r;
123
124 (void) fchmod_umask(fileno(f), 0644);
125
126 r = write_string_stream_ts(f, line, flags, ts);
127 if (r < 0)
128 goto fail;
129
130 if (rename(p, fn) < 0) {
131 r = -errno;
132 goto fail;
133 }
134
135 return 0;
136
137 fail:
138 (void) unlink(p);
139 return r;
140 }
141
142 int write_string_file_ts(
143 const char *fn,
144 const char *line,
145 WriteStringFileFlags flags,
146 struct timespec *ts) {
147
148 _cleanup_fclose_ FILE *f = NULL;
149 int q, r;
150
151 assert(fn);
152 assert(line);
153
154 /* We don't know how to verify whether the file contents was already on-disk. */
155 assert(!((flags & WRITE_STRING_FILE_VERIFY_ON_FAILURE) && (flags & WRITE_STRING_FILE_SYNC)));
156
157 if (flags & WRITE_STRING_FILE_ATOMIC) {
158 assert(flags & WRITE_STRING_FILE_CREATE);
159
160 r = write_string_file_atomic(fn, line, flags, ts);
161 if (r < 0)
162 goto fail;
163
164 return r;
165 } else
166 assert(!ts);
167
168 if (flags & WRITE_STRING_FILE_CREATE) {
169 r = fopen_unlocked(fn, "we", &f);
170 if (r < 0)
171 goto fail;
172 } else {
173 int fd;
174
175 /* We manually build our own version of fopen(..., "we") that
176 * works without O_CREAT */
177 fd = open(fn, O_WRONLY|O_CLOEXEC|O_NOCTTY | ((flags & WRITE_STRING_FILE_NOFOLLOW) ? O_NOFOLLOW : 0));
178 if (fd < 0) {
179 r = -errno;
180 goto fail;
181 }
182
183 r = fdopen_unlocked(fd, "w", &f);
184 if (r < 0) {
185 safe_close(fd);
186 goto fail;
187 }
188 }
189
190 if (flags & WRITE_STRING_FILE_DISABLE_BUFFER)
191 setvbuf(f, NULL, _IONBF, 0);
192
193 r = write_string_stream_ts(f, line, flags, ts);
194 if (r < 0)
195 goto fail;
196
197 return 0;
198
199 fail:
200 if (!(flags & WRITE_STRING_FILE_VERIFY_ON_FAILURE))
201 return r;
202
203 f = safe_fclose(f);
204
205 /* OK, the operation failed, but let's see if the right
206 * contents in place already. If so, eat up the error. */
207
208 q = verify_file(fn, line, !(flags & WRITE_STRING_FILE_AVOID_NEWLINE));
209 if (q <= 0)
210 return r;
211
212 return 0;
213 }
214
215 int write_string_filef(
216 const char *fn,
217 WriteStringFileFlags flags,
218 const char *format, ...) {
219
220 _cleanup_free_ char *p = NULL;
221 va_list ap;
222 int r;
223
224 va_start(ap, format);
225 r = vasprintf(&p, format, ap);
226 va_end(ap);
227
228 if (r < 0)
229 return -ENOMEM;
230
231 return write_string_file(fn, p, flags);
232 }
233
234 int read_one_line_file(const char *fn, char **line) {
235 _cleanup_fclose_ FILE *f = NULL;
236 int r;
237
238 assert(fn);
239 assert(line);
240
241 r = fopen_unlocked(fn, "re", &f);
242 if (r < 0)
243 return r;
244
245 return read_line(f, LONG_LINE_MAX, line);
246 }
247
248 int verify_file(const char *fn, const char *blob, bool accept_extra_nl) {
249 _cleanup_fclose_ FILE *f = NULL;
250 _cleanup_free_ char *buf = NULL;
251 size_t l, k;
252 int r;
253
254 assert(fn);
255 assert(blob);
256
257 l = strlen(blob);
258
259 if (accept_extra_nl && endswith(blob, "\n"))
260 accept_extra_nl = false;
261
262 buf = malloc(l + accept_extra_nl + 1);
263 if (!buf)
264 return -ENOMEM;
265
266 r = fopen_unlocked(fn, "re", &f);
267 if (r < 0)
268 return r;
269
270 /* We try to read one byte more than we need, so that we know whether we hit eof */
271 errno = 0;
272 k = fread(buf, 1, l + accept_extra_nl + 1, f);
273 if (ferror(f))
274 return errno > 0 ? -errno : -EIO;
275
276 if (k != l && k != l + accept_extra_nl)
277 return 0;
278 if (memcmp(buf, blob, l) != 0)
279 return 0;
280 if (k > l && buf[l] != '\n')
281 return 0;
282
283 return 1;
284 }
285
286 int read_full_stream_full(
287 FILE *f,
288 const char *filename,
289 ReadFullFileFlags flags,
290 char **ret_contents,
291 size_t *ret_size) {
292
293 _cleanup_free_ char *buf = NULL;
294 struct stat st;
295 size_t n, n_next, l;
296 int fd, r;
297
298 assert(f);
299 assert(ret_contents);
300 assert(!(flags & READ_FULL_FILE_UNBASE64) || ret_size);
301
302 n_next = LINE_MAX; /* Start size */
303
304 fd = fileno(f);
305 if (fd >= 0) { /* If the FILE* object is backed by an fd (as opposed to memory or such, see fmemopen(), let's
306 * optimize our buffering) */
307
308 if (fstat(fd, &st) < 0)
309 return -errno;
310
311 if (S_ISREG(st.st_mode)) {
312
313 /* Safety check */
314 if (st.st_size > READ_FULL_BYTES_MAX)
315 return -E2BIG;
316
317 /* Start with the right file size, but be prepared for files from /proc which generally report a file
318 * size of 0. Note that we increase the size to read here by one, so that the first read attempt
319 * already makes us notice the EOF. */
320 if (st.st_size > 0)
321 n_next = st.st_size + 1;
322
323 if (flags & READ_FULL_FILE_SECURE)
324 (void) warn_file_is_world_accessible(filename, &st, NULL, 0);
325 }
326 }
327
328 n = l = 0;
329 for (;;) {
330 char *t;
331 size_t k;
332
333 if (flags & READ_FULL_FILE_SECURE) {
334 t = malloc(n_next + 1);
335 if (!t) {
336 r = -ENOMEM;
337 goto finalize;
338 }
339 memcpy_safe(t, buf, n);
340 explicit_bzero_safe(buf, n);
341 } else {
342 t = realloc(buf, n_next + 1);
343 if (!t)
344 return -ENOMEM;
345 }
346
347 buf = t;
348 n = n_next;
349
350 errno = 0;
351 k = fread(buf + l, 1, n - l, f);
352 if (k > 0)
353 l += k;
354
355 if (ferror(f)) {
356 r = errno > 0 ? -errno : -EIO;
357 goto finalize;
358 }
359
360 if (feof(f))
361 break;
362
363 /* We aren't expecting fread() to return a short read outside
364 * of (error && eof), assert buffer is full and enlarge buffer.
365 */
366 assert(l == n);
367
368 /* Safety check */
369 if (n >= READ_FULL_BYTES_MAX) {
370 r = -E2BIG;
371 goto finalize;
372 }
373
374 n_next = MIN(n * 2, READ_FULL_BYTES_MAX);
375 }
376
377 if (flags & READ_FULL_FILE_UNBASE64) {
378 buf[l++] = 0;
379 r = unbase64mem_full(buf, l, flags & READ_FULL_FILE_SECURE, (void **) ret_contents, ret_size);
380 goto finalize;
381 }
382
383 if (!ret_size) {
384 /* Safety check: if the caller doesn't want to know the size of what we just read it will rely on the
385 * trailing NUL byte. But if there's an embedded NUL byte, then we should refuse operation as otherwise
386 * there'd be ambiguity about what we just read. */
387
388 if (memchr(buf, 0, l)) {
389 r = -EBADMSG;
390 goto finalize;
391 }
392 }
393
394 buf[l] = 0;
395 *ret_contents = TAKE_PTR(buf);
396
397 if (ret_size)
398 *ret_size = l;
399
400 return 0;
401
402 finalize:
403 if (flags & READ_FULL_FILE_SECURE)
404 explicit_bzero_safe(buf, n);
405
406 return r;
407 }
408
409 int read_full_file_full(const char *filename, ReadFullFileFlags flags, char **contents, size_t *size) {
410 _cleanup_fclose_ FILE *f = NULL;
411 int r;
412
413 assert(filename);
414 assert(contents);
415
416 r = fopen_unlocked(filename, "re", &f);
417 if (r < 0)
418 return r;
419
420 return read_full_stream_full(f, filename, flags, contents, size);
421 }
422
423 int executable_is_script(const char *path, char **interpreter) {
424 _cleanup_free_ char *line = NULL;
425 size_t len;
426 char *ans;
427 int r;
428
429 assert(path);
430
431 r = read_one_line_file(path, &line);
432 if (r == -ENOBUFS) /* First line overly long? if so, then it's not a script */
433 return 0;
434 if (r < 0)
435 return r;
436
437 if (!startswith(line, "#!"))
438 return 0;
439
440 ans = strstrip(line + 2);
441 len = strcspn(ans, " \t");
442
443 if (len == 0)
444 return 0;
445
446 ans = strndup(ans, len);
447 if (!ans)
448 return -ENOMEM;
449
450 *interpreter = ans;
451 return 1;
452 }
453
454 /**
455 * Retrieve one field from a file like /proc/self/status. pattern
456 * should not include whitespace or the delimiter (':'). pattern matches only
457 * the beginning of a line. Whitespace before ':' is skipped. Whitespace and
458 * zeros after the ':' will be skipped. field must be freed afterwards.
459 * terminator specifies the terminating characters of the field value (not
460 * included in the value).
461 */
462 int get_proc_field(const char *filename, const char *pattern, const char *terminator, char **field) {
463 _cleanup_free_ char *status = NULL;
464 char *t, *f;
465 size_t len;
466 int r;
467
468 assert(terminator);
469 assert(filename);
470 assert(pattern);
471 assert(field);
472
473 r = read_full_file(filename, &status, NULL);
474 if (r < 0)
475 return r;
476
477 t = status;
478
479 do {
480 bool pattern_ok;
481
482 do {
483 t = strstr(t, pattern);
484 if (!t)
485 return -ENOENT;
486
487 /* Check that pattern occurs in beginning of line. */
488 pattern_ok = (t == status || t[-1] == '\n');
489
490 t += strlen(pattern);
491
492 } while (!pattern_ok);
493
494 t += strspn(t, " \t");
495 if (!*t)
496 return -ENOENT;
497
498 } while (*t != ':');
499
500 t++;
501
502 if (*t) {
503 t += strspn(t, " \t");
504
505 /* Also skip zeros, because when this is used for
506 * capabilities, we don't want the zeros. This way the
507 * same capability set always maps to the same string,
508 * irrespective of the total capability set size. For
509 * other numbers it shouldn't matter. */
510 t += strspn(t, "0");
511 /* Back off one char if there's nothing but whitespace
512 and zeros */
513 if (!*t || isspace(*t))
514 t--;
515 }
516
517 len = strcspn(t, terminator);
518
519 f = strndup(t, len);
520 if (!f)
521 return -ENOMEM;
522
523 *field = f;
524 return 0;
525 }
526
527 DIR *xopendirat(int fd, const char *name, int flags) {
528 int nfd;
529 DIR *d;
530
531 assert(!(flags & O_CREAT));
532
533 nfd = openat(fd, name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|flags, 0);
534 if (nfd < 0)
535 return NULL;
536
537 d = fdopendir(nfd);
538 if (!d) {
539 safe_close(nfd);
540 return NULL;
541 }
542
543 return d;
544 }
545
546 static int search_and_fopen_internal(const char *path, const char *mode, const char *root, char **search, FILE **_f) {
547 char **i;
548
549 assert(path);
550 assert(mode);
551 assert(_f);
552
553 if (!path_strv_resolve_uniq(search, root))
554 return -ENOMEM;
555
556 STRV_FOREACH(i, search) {
557 _cleanup_free_ char *p = NULL;
558 FILE *f;
559
560 if (root)
561 p = strjoin(root, *i, "/", path);
562 else
563 p = strjoin(*i, "/", path);
564 if (!p)
565 return -ENOMEM;
566
567 f = fopen(p, mode);
568 if (f) {
569 *_f = f;
570 return 0;
571 }
572
573 if (errno != ENOENT)
574 return -errno;
575 }
576
577 return -ENOENT;
578 }
579
580 int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f) {
581 _cleanup_strv_free_ char **copy = NULL;
582
583 assert(path);
584 assert(mode);
585 assert(_f);
586
587 if (path_is_absolute(path)) {
588 FILE *f;
589
590 f = fopen(path, mode);
591 if (f) {
592 *_f = f;
593 return 0;
594 }
595
596 return -errno;
597 }
598
599 copy = strv_copy((char**) search);
600 if (!copy)
601 return -ENOMEM;
602
603 return search_and_fopen_internal(path, mode, root, copy, _f);
604 }
605
606 int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f) {
607 _cleanup_strv_free_ char **s = NULL;
608
609 if (path_is_absolute(path)) {
610 FILE *f;
611
612 f = fopen(path, mode);
613 if (f) {
614 *_f = f;
615 return 0;
616 }
617
618 return -errno;
619 }
620
621 s = strv_split_nulstr(search);
622 if (!s)
623 return -ENOMEM;
624
625 return search_and_fopen_internal(path, mode, root, s, _f);
626 }
627
628 int fflush_and_check(FILE *f) {
629 assert(f);
630
631 errno = 0;
632 fflush(f);
633
634 if (ferror(f))
635 return errno > 0 ? -errno : -EIO;
636
637 return 0;
638 }
639
640 int fflush_sync_and_check(FILE *f) {
641 int r;
642
643 assert(f);
644
645 r = fflush_and_check(f);
646 if (r < 0)
647 return r;
648
649 if (fsync(fileno(f)) < 0)
650 return -errno;
651
652 r = fsync_directory_of_file(fileno(f));
653 if (r < 0)
654 return r;
655
656 return 0;
657 }
658
659 int write_timestamp_file_atomic(const char *fn, usec_t n) {
660 char ln[DECIMAL_STR_MAX(n)+2];
661
662 /* Creates a "timestamp" file, that contains nothing but a
663 * usec_t timestamp, formatted in ASCII. */
664
665 if (n <= 0 || n >= USEC_INFINITY)
666 return -ERANGE;
667
668 xsprintf(ln, USEC_FMT "\n", n);
669
670 return write_string_file(fn, ln, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC);
671 }
672
673 int read_timestamp_file(const char *fn, usec_t *ret) {
674 _cleanup_free_ char *ln = NULL;
675 uint64_t t;
676 int r;
677
678 r = read_one_line_file(fn, &ln);
679 if (r < 0)
680 return r;
681
682 r = safe_atou64(ln, &t);
683 if (r < 0)
684 return r;
685
686 if (t <= 0 || t >= (uint64_t) USEC_INFINITY)
687 return -ERANGE;
688
689 *ret = (usec_t) t;
690 return 0;
691 }
692
693 int fputs_with_space(FILE *f, const char *s, const char *separator, bool *space) {
694 int r;
695
696 assert(s);
697
698 /* Outputs the specified string with fputs(), but optionally prefixes it with a separator. The *space parameter
699 * when specified shall initially point to a boolean variable initialized to false. It is set to true after the
700 * first invocation. This call is supposed to be use in loops, where a separator shall be inserted between each
701 * element, but not before the first one. */
702
703 if (!f)
704 f = stdout;
705
706 if (space) {
707 if (!separator)
708 separator = " ";
709
710 if (*space) {
711 r = fputs(separator, f);
712 if (r < 0)
713 return r;
714 }
715
716 *space = true;
717 }
718
719 return fputs(s, f);
720 }
721
722 /* A bitmask of the EOL markers we know */
723 typedef enum EndOfLineMarker {
724 EOL_NONE = 0,
725 EOL_ZERO = 1 << 0, /* \0 (aka NUL) */
726 EOL_TEN = 1 << 1, /* \n (aka NL, aka LF) */
727 EOL_THIRTEEN = 1 << 2, /* \r (aka CR) */
728 } EndOfLineMarker;
729
730 static EndOfLineMarker categorize_eol(char c, ReadLineFlags flags) {
731
732 if (!IN_SET(flags, READ_LINE_ONLY_NUL)) {
733 if (c == '\n')
734 return EOL_TEN;
735 if (c == '\r')
736 return EOL_THIRTEEN;
737 }
738
739 if (c == '\0')
740 return EOL_ZERO;
741
742 return EOL_NONE;
743 }
744
745 DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, funlockfile);
746
747 int read_line_full(FILE *f, size_t limit, ReadLineFlags flags, char **ret) {
748 size_t n = 0, allocated = 0, count = 0;
749 _cleanup_free_ char *buffer = NULL;
750 int r;
751
752 assert(f);
753
754 /* Something like a bounded version of getline().
755 *
756 * Considers EOF, \n, \r and \0 end of line delimiters (or combinations of these), and does not include these
757 * delimiters in the string returned. Specifically, recognizes the following combinations of markers as line
758 * endings:
759 *
760 * • \n (UNIX)
761 * • \r (old MacOS)
762 * • \0 (C strings)
763 * • \n\0
764 * • \r\0
765 * • \r\n (Windows)
766 * • \n\r
767 * • \r\n\0
768 * • \n\r\0
769 *
770 * Returns the number of bytes read from the files (i.e. including delimiters — this hence usually differs from
771 * the number of characters in the returned string). When EOF is hit, 0 is returned.
772 *
773 * The input parameter limit is the maximum numbers of characters in the returned string, i.e. excluding
774 * delimiters. If the limit is hit we fail and return -ENOBUFS.
775 *
776 * If a line shall be skipped ret may be initialized as NULL. */
777
778 if (ret) {
779 if (!GREEDY_REALLOC(buffer, allocated, 1))
780 return -ENOMEM;
781 }
782
783 {
784 _unused_ _cleanup_(funlockfilep) FILE *flocked = f;
785 EndOfLineMarker previous_eol = EOL_NONE;
786 flockfile(f);
787
788 for (;;) {
789 EndOfLineMarker eol;
790 char c;
791
792 if (n >= limit)
793 return -ENOBUFS;
794
795 if (count >= INT_MAX) /* We couldn't return the counter anymore as "int", hence refuse this */
796 return -ENOBUFS;
797
798 r = safe_fgetc(f, &c);
799 if (r < 0)
800 return r;
801 if (r == 0) /* EOF is definitely EOL */
802 break;
803
804 eol = categorize_eol(c, flags);
805
806 if (FLAGS_SET(previous_eol, EOL_ZERO) ||
807 (eol == EOL_NONE && previous_eol != EOL_NONE) ||
808 (eol != EOL_NONE && (previous_eol & eol) != 0)) {
809 /* Previous char was a NUL? This is not an EOL, but the previous char was? This type of
810 * EOL marker has been seen right before? In either of these three cases we are
811 * done. But first, let's put this character back in the queue. (Note that we have to
812 * cast this to (unsigned char) here as ungetc() expects a positive 'int', and if we
813 * are on an architecture where 'char' equals 'signed char' we need to ensure we don't
814 * pass a negative value here. That said, to complicate things further ungetc() is
815 * actually happy with most negative characters and implicitly casts them back to
816 * positive ones as needed, except for \xff (aka -1, aka EOF), which it refuses. What a
817 * godawful API!) */
818 assert_se(ungetc((unsigned char) c, f) != EOF);
819 break;
820 }
821
822 count++;
823
824 if (eol != EOL_NONE) {
825 previous_eol |= eol;
826 continue;
827 }
828
829 if (ret) {
830 if (!GREEDY_REALLOC(buffer, allocated, n + 2))
831 return -ENOMEM;
832
833 buffer[n] = c;
834 }
835
836 n++;
837 }
838 }
839
840 if (ret) {
841 buffer[n] = 0;
842
843 *ret = TAKE_PTR(buffer);
844 }
845
846 return (int) count;
847 }
848
849 int safe_fgetc(FILE *f, char *ret) {
850 int k;
851
852 assert(f);
853
854 /* A safer version of plain fgetc(): let's propagate the error that happened while reading as such, and
855 * separate the EOF condition from the byte read, to avoid those confusion signed/unsigned issues fgetc()
856 * has. */
857
858 errno = 0;
859 k = fgetc(f);
860 if (k == EOF) {
861 if (ferror(f))
862 return errno > 0 ? -errno : -EIO;
863
864 if (ret)
865 *ret = 0;
866
867 return 0;
868 }
869
870 if (ret)
871 *ret = k;
872
873 return 1;
874 }
875
876 int warn_file_is_world_accessible(const char *filename, struct stat *st, const char *unit, unsigned line) {
877 struct stat _st;
878
879 if (!filename)
880 return 0;
881
882 if (!st) {
883 if (stat(filename, &_st) < 0)
884 return -errno;
885 st = &_st;
886 }
887
888 if ((st->st_mode & S_IRWXO) == 0)
889 return 0;
890
891 if (unit)
892 log_syntax(unit, LOG_WARNING, filename, line, 0,
893 "%s has %04o mode that is too permissive, please adjust the access mode.",
894 filename, st->st_mode & 07777);
895 else
896 log_warning("%s has %04o mode that is too permissive, please adjust the access mode.",
897 filename, st->st_mode & 07777);
898 return 0;
899 }