chiark / gitweb /
tree-wide: drop license boilerplate
[elogind.git] / src / basic / path-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3   This file is part of systemd.
4
5   Copyright 2010-2012 Lennart Poettering
6 ***/
7
8 #include <errno.h>
9 #include <limits.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <sys/stat.h>
14 #include <unistd.h>
15
16 /* When we include libgen.h because we need dirname() we immediately
17  * undefine basename() since libgen.h defines it as a macro to the
18  * POSIX version which is really broken. We prefer GNU basename(). */
19 #include <libgen.h>
20 #undef basename
21
22 #include "alloc-util.h"
23 #include "extract-word.h"
24 #include "fs-util.h"
25 //#include "glob-util.h"
26 #include "log.h"
27 #include "macro.h"
28 #include "missing.h"
29 #include "parse-util.h"
30 #include "path-util.h"
31 #include "stat-util.h"
32 #include "string-util.h"
33 #include "strv.h"
34 #include "time-util.h"
35
36 bool path_is_absolute(const char *p) {
37         return p[0] == '/';
38 }
39
40 bool is_path(const char *p) {
41         return !!strchr(p, '/');
42 }
43
44 #if 0 /// UNNEEDED by elogind
45 int path_split_and_make_absolute(const char *p, char ***ret) {
46         char **l;
47         int r;
48
49         assert(p);
50         assert(ret);
51
52         l = strv_split(p, ":");
53         if (!l)
54                 return -ENOMEM;
55
56         r = path_strv_make_absolute_cwd(l);
57         if (r < 0) {
58                 strv_free(l);
59                 return r;
60         }
61
62         *ret = l;
63         return r;
64 }
65
66 char *path_make_absolute(const char *p, const char *prefix) {
67         assert(p);
68
69         /* Makes every item in the list an absolute path by prepending
70          * the prefix, if specified and necessary */
71
72         if (path_is_absolute(p) || isempty(prefix))
73                 return strdup(p);
74
75         if (endswith(prefix, "/"))
76                 return strjoin(prefix, p);
77         else
78                 return strjoin(prefix, "/", p);
79 }
80 #endif // 0
81
82 int safe_getcwd(char **ret) {
83         char *cwd;
84
85         cwd = get_current_dir_name();
86         if (!cwd)
87                 return negative_errno();
88
89         /* Let's make sure the directory is really absolute, to protect us from the logic behind
90          * CVE-2018-1000001 */
91         if (cwd[0] != '/') {
92                 free(cwd);
93                 return -ENOMEDIUM;
94         }
95
96         *ret = cwd;
97         return 0;
98 }
99
100 int path_make_absolute_cwd(const char *p, char **ret) {
101         char *c;
102         int r;
103
104         assert(p);
105         assert(ret);
106
107         /* Similar to path_make_absolute(), but prefixes with the
108          * current working directory. */
109
110         if (path_is_absolute(p))
111                 c = strdup(p);
112         else {
113                 _cleanup_free_ char *cwd = NULL;
114
115                 r = safe_getcwd(&cwd);
116                 if (r < 0)
117                         return r;
118
119                 if (endswith(cwd, "/"))
120                         c = strjoin(cwd, p);
121                 else
122                         c = strjoin(cwd, "/", p);
123         }
124         if (!c)
125                 return -ENOMEM;
126
127         *ret = c;
128         return 0;
129 }
130
131 #if 0 /// UNNEEDED by elogind
132 int path_make_relative(const char *from_dir, const char *to_path, char **_r) {
133         char *r, *p;
134         unsigned n_parents;
135
136         assert(from_dir);
137         assert(to_path);
138         assert(_r);
139
140         /* Strips the common part, and adds ".." elements as necessary. */
141
142         if (!path_is_absolute(from_dir))
143                 return -EINVAL;
144
145         if (!path_is_absolute(to_path))
146                 return -EINVAL;
147
148         /* Skip the common part. */
149         for (;;) {
150                 size_t a, b;
151
152                 from_dir += strspn(from_dir, "/");
153                 to_path += strspn(to_path, "/");
154
155                 if (!*from_dir) {
156                         if (!*to_path)
157                                 /* from_dir equals to_path. */
158                                 r = strdup(".");
159                         else
160                                 /* from_dir is a parent directory of to_path. */
161                                 r = strdup(to_path);
162                         if (!r)
163                                 return -ENOMEM;
164
165                         path_kill_slashes(r);
166
167                         *_r = r;
168                         return 0;
169                 }
170
171                 if (!*to_path)
172                         break;
173
174                 a = strcspn(from_dir, "/");
175                 b = strcspn(to_path, "/");
176
177                 if (a != b)
178                         break;
179
180                 if (memcmp(from_dir, to_path, a) != 0)
181                         break;
182
183                 from_dir += a;
184                 to_path += b;
185         }
186
187         /* If we're here, then "from_dir" has one or more elements that need to
188          * be replaced with "..". */
189
190         /* Count the number of necessary ".." elements. */
191         for (n_parents = 0;;) {
192                 size_t w;
193
194                 from_dir += strspn(from_dir, "/");
195
196                 if (!*from_dir)
197                         break;
198
199                 w = strcspn(from_dir, "/");
200
201                 /* If this includes ".." we can't do a simple series of "..", refuse */
202                 if (w == 2 && from_dir[0] == '.' && from_dir[1] == '.')
203                         return -EINVAL;
204
205                 /* Count number of elements, except if they are "." */
206                 if (w != 1 || from_dir[0] != '.')
207                         n_parents++;
208
209                 from_dir += w;
210         }
211
212         r = new(char, n_parents * 3 + strlen(to_path) + 1);
213         if (!r)
214                 return -ENOMEM;
215
216         for (p = r; n_parents > 0; n_parents--)
217                 p = mempcpy(p, "../", 3);
218
219         strcpy(p, to_path);
220         path_kill_slashes(r);
221
222         *_r = r;
223         return 0;
224 }
225
226 int path_strv_make_absolute_cwd(char **l) {
227         char **s;
228         int r;
229
230         /* Goes through every item in the string list and makes it
231          * absolute. This works in place and won't rollback any
232          * changes on failure. */
233
234         STRV_FOREACH(s, l) {
235                 char *t;
236
237                 r = path_make_absolute_cwd(*s, &t);
238                 if (r < 0)
239                         return r;
240
241                 path_kill_slashes(t);
242                 free_and_replace(*s, t);
243         }
244
245         return 0;
246 }
247 #endif // 0
248
249 char **path_strv_resolve(char **l, const char *root) {
250         char **s;
251         unsigned k = 0;
252         bool enomem = false;
253         int r;
254
255         if (strv_isempty(l))
256                 return l;
257
258         /* Goes through every item in the string list and canonicalize
259          * the path. This works in place and won't rollback any
260          * changes on failure. */
261
262         STRV_FOREACH(s, l) {
263                 _cleanup_free_ char *orig = NULL;
264                 char *t, *u;
265
266                 if (!path_is_absolute(*s)) {
267                         free(*s);
268                         continue;
269                 }
270
271                 if (root) {
272                         orig = *s;
273                         t = prefix_root(root, orig);
274                         if (!t) {
275                                 enomem = true;
276                                 continue;
277                         }
278                 } else
279                         t = *s;
280
281                 r = chase_symlinks(t, root, 0, &u);
282                 if (r == -ENOENT) {
283                         if (root) {
284                                 u = TAKE_PTR(orig);
285                                 free(t);
286                         } else
287                                 u = t;
288                 } else if (r < 0) {
289                         free(t);
290
291                         if (r == -ENOMEM)
292                                 enomem = true;
293
294                         continue;
295                 } else if (root) {
296                         char *x;
297
298                         free(t);
299                         x = path_startswith(u, root);
300                         if (x) {
301                                 /* restore the slash if it was lost */
302                                 if (!startswith(x, "/"))
303                                         *(--x) = '/';
304
305                                 t = strdup(x);
306                                 free(u);
307                                 if (!t) {
308                                         enomem = true;
309                                         continue;
310                                 }
311                                 u = t;
312                         } else {
313                                 /* canonicalized path goes outside of
314                                  * prefix, keep the original path instead */
315                                 free_and_replace(u, orig);
316                         }
317                 } else
318                         free(t);
319
320                 l[k++] = u;
321         }
322
323         l[k] = NULL;
324
325         if (enomem)
326                 return NULL;
327
328         return l;
329 }
330
331 char **path_strv_resolve_uniq(char **l, const char *root) {
332
333         if (strv_isempty(l))
334                 return l;
335
336         if (!path_strv_resolve(l, root))
337                 return NULL;
338
339         return strv_uniq(l);
340 }
341
342 char *path_kill_slashes(char *path) {
343         char *f, *t;
344         bool slash = false;
345
346         /* Removes redundant inner and trailing slashes. Modifies the
347          * passed string in-place.
348          *
349          * ///foo///bar/ becomes /foo/bar
350          */
351
352         for (f = path, t = path; *f; f++) {
353
354                 if (*f == '/') {
355                         slash = true;
356                         continue;
357                 }
358
359                 if (slash) {
360                         slash = false;
361                         *(t++) = '/';
362                 }
363
364                 *(t++) = *f;
365         }
366
367         /* Special rule, if we are talking of the root directory, a
368         trailing slash is good */
369
370         if (t == path && slash)
371                 *(t++) = '/';
372
373         *t = 0;
374         return path;
375 }
376
377 char* path_startswith(const char *path, const char *prefix) {
378         assert(path);
379         assert(prefix);
380
381         /* Returns a pointer to the start of the first component after the parts matched by
382          * the prefix, iff
383          * - both paths are absolute or both paths are relative,
384          * and
385          * - each component in prefix in turn matches a component in path at the same position.
386          * An empty string will be returned when the prefix and path are equivalent.
387          *
388          * Returns NULL otherwise.
389          */
390
391         if ((path[0] == '/') != (prefix[0] == '/'))
392                 return NULL;
393
394         for (;;) {
395                 size_t a, b;
396
397                 path += strspn(path, "/");
398                 prefix += strspn(prefix, "/");
399
400                 if (*prefix == 0)
401                         return (char*) path;
402
403                 if (*path == 0)
404                         return NULL;
405
406                 a = strcspn(path, "/");
407                 b = strcspn(prefix, "/");
408
409                 if (a != b)
410                         return NULL;
411
412                 if (memcmp(path, prefix, a) != 0)
413                         return NULL;
414
415                 path += a;
416                 prefix += b;
417         }
418 }
419
420 int path_compare(const char *a, const char *b) {
421         int d;
422
423         assert(a);
424         assert(b);
425
426         /* A relative path and an abolute path must not compare as equal.
427          * Which one is sorted before the other does not really matter.
428          * Here a relative path is ordered before an absolute path. */
429         d = (a[0] == '/') - (b[0] == '/');
430         if (d != 0)
431                 return d;
432
433         for (;;) {
434                 size_t j, k;
435
436                 a += strspn(a, "/");
437                 b += strspn(b, "/");
438
439                 if (*a == 0 && *b == 0)
440                         return 0;
441
442                 /* Order prefixes first: "/foo" before "/foo/bar" */
443                 if (*a == 0)
444                         return -1;
445                 if (*b == 0)
446                         return 1;
447
448                 j = strcspn(a, "/");
449                 k = strcspn(b, "/");
450
451                 /* Alphabetical sort: "/foo/aaa" before "/foo/b" */
452                 d = memcmp(a, b, MIN(j, k));
453                 if (d != 0)
454                         return (d > 0) - (d < 0); /* sign of d */
455
456                 /* Sort "/foo/a" before "/foo/aaa" */
457                 d = (j > k) - (j < k);  /* sign of (j - k) */
458                 if (d != 0)
459                         return d;
460
461                 a += j;
462                 b += k;
463         }
464 }
465
466 bool path_equal(const char *a, const char *b) {
467         return path_compare(a, b) == 0;
468 }
469
470 bool path_equal_or_files_same(const char *a, const char *b, int flags) {
471         return path_equal(a, b) || files_same(a, b, flags) > 0;
472 }
473
474 char* path_join(const char *root, const char *path, const char *rest) {
475         assert(path);
476
477         if (!isempty(root))
478                 return strjoin(root, endswith(root, "/") ? "" : "/",
479                                path[0] == '/' ? path+1 : path,
480                                rest ? (endswith(path, "/") ? "" : "/") : NULL,
481                                rest && rest[0] == '/' ? rest+1 : rest);
482         else
483                 return strjoin(path,
484                                rest ? (endswith(path, "/") ? "" : "/") : NULL,
485                                rest && rest[0] == '/' ? rest+1 : rest);
486 }
487
488 int find_binary(const char *name, char **ret) {
489         int last_error, r;
490         const char *p;
491
492         assert(name);
493
494         if (is_path(name)) {
495                 if (access(name, X_OK) < 0)
496                         return -errno;
497
498                 if (ret) {
499                         r = path_make_absolute_cwd(name, ret);
500                         if (r < 0)
501                                 return r;
502                 }
503
504                 return 0;
505         }
506
507         /**
508          * Plain getenv, not secure_getenv, because we want
509          * to actually allow the user to pick the binary.
510          */
511         p = getenv("PATH");
512         if (!p)
513                 p = DEFAULT_PATH;
514
515         last_error = -ENOENT;
516
517         for (;;) {
518                 _cleanup_free_ char *j = NULL, *element = NULL;
519
520                 r = extract_first_word(&p, &element, ":", EXTRACT_RELAX|EXTRACT_DONT_COALESCE_SEPARATORS);
521                 if (r < 0)
522                         return r;
523                 if (r == 0)
524                         break;
525
526                 if (!path_is_absolute(element))
527                         continue;
528
529                 j = strjoin(element, "/", name);
530                 if (!j)
531                         return -ENOMEM;
532
533                 if (access(j, X_OK) >= 0) {
534                         /* Found it! */
535
536                         if (ret) {
537                                 *ret = path_kill_slashes(j);
538                                 j = NULL;
539                         }
540
541                         return 0;
542                 }
543
544                 last_error = -errno;
545         }
546
547         return last_error;
548 }
549
550 #if 0 /// UNNEEDED by elogind
551 bool paths_check_timestamp(const char* const* paths, usec_t *timestamp, bool update) {
552         bool changed = false;
553         const char* const* i;
554
555         assert(timestamp);
556
557         if (!paths)
558                 return false;
559
560         STRV_FOREACH(i, paths) {
561                 struct stat stats;
562                 usec_t u;
563
564                 if (stat(*i, &stats) < 0)
565                         continue;
566
567                 u = timespec_load(&stats.st_mtim);
568
569                 /* first check */
570                 if (*timestamp >= u)
571                         continue;
572
573                 log_debug("timestamp of '%s' changed", *i);
574
575                 /* update timestamp */
576                 if (update) {
577                         *timestamp = u;
578                         changed = true;
579                 } else
580                         return true;
581         }
582
583         return changed;
584 }
585
586 static int binary_is_good(const char *binary) {
587         _cleanup_free_ char *p = NULL, *d = NULL;
588         int r;
589
590         r = find_binary(binary, &p);
591         if (r == -ENOENT)
592                 return 0;
593         if (r < 0)
594                 return r;
595
596         /* An fsck that is linked to /bin/true is a non-existent
597          * fsck */
598
599         r = readlink_malloc(p, &d);
600         if (r == -EINVAL) /* not a symlink */
601                 return 1;
602         if (r < 0)
603                 return r;
604
605         return !PATH_IN_SET(d, "true"
606                                "/bin/true",
607                                "/usr/bin/true",
608                                "/dev/null");
609 }
610
611 int fsck_exists(const char *fstype) {
612         const char *checker;
613
614         assert(fstype);
615
616         if (streq(fstype, "auto"))
617                 return -EINVAL;
618
619         checker = strjoina("fsck.", fstype);
620         return binary_is_good(checker);
621 }
622
623 int mkfs_exists(const char *fstype) {
624         const char *mkfs;
625
626         assert(fstype);
627
628         if (streq(fstype, "auto"))
629                 return -EINVAL;
630
631         mkfs = strjoina("mkfs.", fstype);
632         return binary_is_good(mkfs);
633 }
634 #endif // 0
635
636 char *prefix_root(const char *root, const char *path) {
637         char *n, *p;
638         size_t l;
639
640         /* If root is passed, prefixes path with it. Otherwise returns
641          * it as is. */
642
643         assert(path);
644
645         /* First, drop duplicate prefixing slashes from the path */
646         while (path[0] == '/' && path[1] == '/')
647                 path++;
648
649         if (isempty(root) || path_equal(root, "/"))
650                 return strdup(path);
651
652         l = strlen(root) + 1 + strlen(path) + 1;
653
654         n = new(char, l);
655         if (!n)
656                 return NULL;
657
658         p = stpcpy(n, root);
659
660         while (p > n && p[-1] == '/')
661                 p--;
662
663         if (path[0] != '/')
664                 *(p++) = '/';
665
666         strcpy(p, path);
667         return n;
668 }
669
670 #if 0 /// UNNEEDED by elogind
671 int parse_path_argument_and_warn(const char *path, bool suppress_root, char **arg) {
672         char *p;
673         int r;
674
675         /*
676          * This function is intended to be used in command line
677          * parsers, to handle paths that are passed in. It makes the
678          * path absolute, and reduces it to NULL if omitted or
679          * root (the latter optionally).
680          *
681          * NOTE THAT THIS WILL FREE THE PREVIOUS ARGUMENT POINTER ON
682          * SUCCESS! Hence, do not pass in uninitialized pointers.
683          */
684
685         if (isempty(path)) {
686                 *arg = mfree(*arg);
687                 return 0;
688         }
689
690         r = path_make_absolute_cwd(path, &p);
691         if (r < 0)
692                 return log_error_errno(r, "Failed to parse path \"%s\" and make it absolute: %m", path);
693
694         path_kill_slashes(p);
695         if (suppress_root && path_equal(p, "/"))
696                 p = mfree(p);
697
698         free(*arg);
699         *arg = p;
700         return 0;
701 }
702 #endif // 0
703
704 char* dirname_malloc(const char *path) {
705         char *d, *dir, *dir2;
706
707         assert(path);
708
709         d = strdup(path);
710         if (!d)
711                 return NULL;
712
713         dir = dirname(d);
714         assert(dir);
715
716         if (dir == d)
717                 return d;
718
719         dir2 = strdup(dir);
720         free(d);
721
722         return dir2;
723 }
724
725 const char *last_path_component(const char *path) {
726         /* Finds the last component of the path, preserving the
727          * optional trailing slash that signifies a directory.
728          *    a/b/c → c
729          *    a/b/c/ → c/
730          *    / → /
731          *    // → /
732          *    /foo/a → a
733          *    /foo/a/ → a/
734          * This is different than basename, which returns "" when
735          * a trailing slash is present.
736          */
737
738         unsigned l, k;
739
740         l = k = strlen(path);
741         if (l == 0) /* special case — an empty string */
742                 return path;
743
744         while (k > 0 && path[k-1] == '/')
745                 k--;
746
747         if (k == 0) /* the root directory */
748                 return path + l - 1;
749
750         while (k > 0 && path[k-1] != '/')
751                 k--;
752
753         return path + k;
754 }
755
756 bool filename_is_valid(const char *p) {
757         const char *e;
758
759         if (isempty(p))
760                 return false;
761
762         if (dot_or_dot_dot(p))
763                 return false;
764
765         e = strchrnul(p, '/');
766         if (*e != 0)
767                 return false;
768
769         if (e - p > FILENAME_MAX)
770                 return false;
771
772         return true;
773 }
774
775 bool path_is_normalized(const char *p) {
776
777         if (isempty(p))
778                 return false;
779
780         if (dot_or_dot_dot(p))
781                 return false;
782
783         if (startswith(p, "../") || endswith(p, "/..") || strstr(p, "/../"))
784                 return false;
785
786         if (strlen(p)+1 > PATH_MAX)
787                 return false;
788
789         if (startswith(p, "./") || endswith(p, "/.") || strstr(p, "/./"))
790                 return false;
791
792         if (strstr(p, "//"))
793                 return false;
794
795         return true;
796 }
797
798 char *file_in_same_dir(const char *path, const char *filename) {
799         char *e, *ret;
800         size_t k;
801
802         assert(path);
803         assert(filename);
804
805         /* This removes the last component of path and appends
806          * filename, unless the latter is absolute anyway or the
807          * former isn't */
808
809         if (path_is_absolute(filename))
810                 return strdup(filename);
811
812         e = strrchr(path, '/');
813         if (!e)
814                 return strdup(filename);
815
816         k = strlen(filename);
817         ret = new(char, (e + 1 - path) + k + 1);
818         if (!ret)
819                 return NULL;
820
821         memcpy(mempcpy(ret, path, e + 1 - path), filename, k + 1);
822         return ret;
823 }
824
825 bool hidden_or_backup_file(const char *filename) {
826         const char *p;
827
828         assert(filename);
829
830         if (filename[0] == '.' ||
831             streq(filename, "lost+found") ||
832             streq(filename, "aquota.user") ||
833             streq(filename, "aquota.group") ||
834             endswith(filename, "~"))
835                 return true;
836
837         p = strrchr(filename, '.');
838         if (!p)
839                 return false;
840
841         /* Please, let's not add more entries to the list below. If external projects think it's a good idea to come up
842          * with always new suffixes and that everybody else should just adjust to that, then it really should be on
843          * them. Hence, in future, let's not add any more entries. Instead, let's ask those packages to instead adopt
844          * one of the generic suffixes/prefixes for hidden files or backups, possibly augmented with an additional
845          * string. Specifically: there's now:
846          *
847          *    The generic suffixes "~" and ".bak" for backup files
848          *    The generic prefix "." for hidden files
849          *
850          * Thus, if a new package manager "foopkg" wants its own set of ".foopkg-new", ".foopkg-old", ".foopkg-dist"
851          * or so registered, let's refuse that and ask them to use ".foopkg.new", ".foopkg.old" or ".foopkg~" instead.
852          */
853
854         return STR_IN_SET(p + 1,
855                           "rpmnew",
856                           "rpmsave",
857                           "rpmorig",
858                           "dpkg-old",
859                           "dpkg-new",
860                           "dpkg-tmp",
861                           "dpkg-dist",
862                           "dpkg-bak",
863                           "dpkg-backup",
864                           "dpkg-remove",
865                           "ucf-new",
866                           "ucf-old",
867                           "ucf-dist",
868                           "swp",
869                           "bak",
870                           "old",
871                           "new");
872 }
873
874 #if 0 /// UNNEEDED by elogind
875 bool is_device_path(const char *path) {
876
877         /* Returns true on paths that refer to a device, either in
878          * sysfs or in /dev */
879
880         return path_startswith(path, "/dev/") ||
881                path_startswith(path, "/sys/");
882 }
883
884 bool is_deviceallow_pattern(const char *path) {
885         return path_startswith(path, "/dev/") ||
886                startswith(path, "block-") ||
887                startswith(path, "char-");
888 }
889
890 int systemd_installation_has_version(const char *root, unsigned minimal_version) {
891         const char *pattern;
892         int r;
893
894         /* Try to guess if systemd installation is later than the specified version. This
895          * is hacky and likely to yield false negatives, particularly if the installation
896          * is non-standard. False positives should be relatively rare.
897          */
898
899         NULSTR_FOREACH(pattern,
900                        /* /lib works for systems without usr-merge, and for systems with a sane
901                         * usr-merge, where /lib is a symlink to /usr/lib. /usr/lib is necessary
902                         * for Gentoo which does a merge without making /lib a symlink.
903                         */
904                        "lib/systemd/libsystemd-shared-*.so\0"
905                        "lib64/systemd/libsystemd-shared-*.so\0"
906                        "usr/lib/systemd/libsystemd-shared-*.so\0"
907                        "usr/lib64/systemd/libsystemd-shared-*.so\0") {
908
909                 _cleanup_strv_free_ char **names = NULL;
910                 _cleanup_free_ char *path = NULL;
911                 char *c, **name;
912
913                 path = prefix_root(root, pattern);
914                 if (!path)
915                         return -ENOMEM;
916
917                 r = glob_extend(&names, path);
918                 if (r == -ENOENT)
919                         continue;
920                 if (r < 0)
921                         return r;
922
923                 assert_se((c = endswith(path, "*.so")));
924                 *c = '\0'; /* truncate the glob part */
925
926                 STRV_FOREACH(name, names) {
927                         /* This is most likely to run only once, hence let's not optimize anything. */
928                         char *t, *t2;
929                         unsigned version;
930
931                         t = startswith(*name, path);
932                         if (!t)
933                                 continue;
934
935                         t2 = endswith(t, ".so");
936                         if (!t2)
937                                 continue;
938
939                         t2[0] = '\0'; /* truncate the suffix */
940
941                         r = safe_atou(t, &version);
942                         if (r < 0) {
943                                 log_debug_errno(r, "Found libsystemd shared at \"%s.so\", but failed to parse version: %m", *name);
944                                 continue;
945                         }
946
947                         log_debug("Found libsystemd shared at \"%s.so\", version %u (%s).",
948                                   *name, version,
949                                   version >= minimal_version ? "OK" : "too old");
950                         if (version >= minimal_version)
951                                 return true;
952                 }
953         }
954
955         return false;
956 }
957 #endif // 0
958
959 bool dot_or_dot_dot(const char *path) {
960         if (!path)
961                 return false;
962         if (path[0] != '.')
963                 return false;
964         if (path[1] == 0)
965                 return true;
966         if (path[1] != '.')
967                 return false;
968
969         return path[2] == 0;
970 }