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