chiark / gitweb /
tree-wide: remove Lennart's copyright lines
[elogind.git] / src / basic / path-util.c
index d7862f1398789d3108f6f4f4bf3aa5341ba3c45d..45713d6d76fed8a6c32a216502054af0a1c40174 100644 (file)
@@ -1,9 +1,4 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
-/***
-  This file is part of systemd.
-
-  Copyright 2010-2012 Lennart Poettering
-***/
 
 #include <errno.h>
 #include <limits.h>
@@ -895,17 +890,36 @@ bool hidden_or_backup_file(const char *filename) {
 #if 0 /// UNNEEDED by elogind
 bool is_device_path(const char *path) {
 
-        /* Returns true on paths that refer to a device, either in
-         * sysfs or in /dev */
+        /* Returns true on paths that likely refer to a device, either by path in sysfs or to something in /dev */
+
+        return PATH_STARTSWITH_SET(path, "/dev/", "/sys/");
+}
+
+bool valid_device_node_path(const char *path) {
+
+        /* Some superficial checks whether the specified path is a valid device node path, all without looking at the
+         * actual device node. */
+
+        if (!PATH_STARTSWITH_SET(path, "/dev/", "/run/systemd/inaccessible/"))
+                return false;
+
+        if (endswith(path, "/")) /* can't be a device node if it ends in a slash */
+                return false;
 
-        return path_startswith(path, "/dev/") ||
-               path_startswith(path, "/sys/");
+        return path_is_normalized(path);
 }
 
-bool is_deviceallow_pattern(const char *path) {
-        return path_startswith(path, "/dev/") ||
-               startswith(path, "block-") ||
-               startswith(path, "char-");
+bool valid_device_allow_pattern(const char *path) {
+        assert(path);
+
+        /* Like valid_device_node_path(), but also allows full-subsystem expressions, like DeviceAllow= and DeviceDeny=
+         * accept it */
+
+        if (startswith(path, "block-") ||
+            startswith(path, "char-"))
+                return true;
+
+        return valid_device_node_path(path);
 }
 
 int systemd_installation_has_version(const char *root, unsigned minimal_version) {
@@ -1024,14 +1038,14 @@ int path_simplify_and_warn(
                 if (!absolute && (flag & PATH_CHECK_ABSOLUTE)) {
                         log_syntax(unit, LOG_ERR, filename, line, 0,
                                    "%s= path is not absolute%s: %s",
-                                   fatal ? "" : ", ignoring", lvalue, path);
+                                   lvalue, fatal ? "" : ", ignoring", path);
                         return -EINVAL;
                 }
 
                 if (absolute && (flag & PATH_CHECK_RELATIVE)) {
                         log_syntax(unit, LOG_ERR, filename, line, 0,
                                    "%s= path is absolute%s: %s",
-                                   fatal ? "" : ", ignoring", lvalue, path);
+                                   lvalue, fatal ? "" : ", ignoring", path);
                         return -EINVAL;
                 }
         }
@@ -1041,7 +1055,7 @@ int path_simplify_and_warn(
         if (!path_is_normalized(path)) {
                 log_syntax(unit, LOG_ERR, filename, line, 0,
                            "%s= path is not normalized%s: %s",
-                           fatal ? "" : ", ignoring", lvalue, path);
+                           lvalue, fatal ? "" : ", ignoring", path);
                 return -EINVAL;
         }