[PATCH BlueZ 1/1] mesh: Modify check of the node directory name upon removal

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This removes check for "mesh" as the parent directory name and, instead,
verifies that the node configuration directory name is the hexadecimal
string representating the node's UUID.
---
 mesh/storage.c | 39 +++++++++++++--------------------------
 1 file changed, 13 insertions(+), 26 deletions(-)

diff --git a/mesh/storage.c b/mesh/storage.c
index 1a9945aa8..54c985559 100644
--- a/mesh/storage.c
+++ b/mesh/storage.c
@@ -53,20 +53,6 @@ static const char *bak_ext = ".bak";
 static const char *tmp_ext = ".tmp";
 static const char *storage_dir;
 
-/* This is a thread-safe always malloced version of dirname which will work
- * regardless of which underlying dirname() implementation is used.
- */
-static char *alloc_dirname(const char *path)
-{
-	char *tmp = l_strdup(path);
-	char *dir;
-
-	dir = dirname(tmp);
-	strncpy(tmp, dir, strlen(path) + 1);
-
-	return tmp;
-}
-
 static bool read_node_cb(struct mesh_db_node *db_node, void *user_data)
 {
 	struct mesh_node *node = user_data;
@@ -486,20 +472,20 @@ void storage_save_config(struct mesh_node *node, bool no_wait,
 		l_idle_oneshot(idle_save_config, info, NULL);
 }
 
-static int create_dir(const char *dirname)
+static int create_dir(const char *dir_name)
 {
 	struct stat st;
 	char dir[PATH_MAX + 1], *prev, *next;
 	int err;
 
-	err = stat(dirname, &st);
+	err = stat(dir_name, &st);
 	if (!err && S_ISREG(st.st_mode))
 		return 0;
 
 	memset(dir, 0, PATH_MAX + 1);
 	strcat(dir, "/");
 
-	prev = strchr(dirname, '/');
+	prev = strchr(dir_name, '/');
 
 	while (prev) {
 		next = strchr(prev + 1, '/');
@@ -517,7 +503,7 @@ static int create_dir(const char *dirname)
 		prev = next;
 	}
 
-	mkdir(dirname, 0755);
+	mkdir(dir_name, 0755);
 
 	return 0;
 }
@@ -640,7 +626,8 @@ static int del_fobject(const char *fpath, const struct stat *sb, int typeflag,
 /* Permanently remove node configuration */
 void storage_remove_node_config(struct mesh_node *node)
 {
-	char *node_path, *mesh_path, *mesh_name;
+	char *node_path, *node_name;
+	char uuid[33];
 	struct json_object *jnode;
 
 	if (!node)
@@ -656,13 +643,13 @@ void storage_remove_node_config(struct mesh_node *node)
 	l_debug("Delete node config %s", node_path);
 
 	/* Make sure path name of node follows expected guidelines */
-	mesh_path = alloc_dirname(node_path);
-	mesh_name = basename(mesh_path);
-	if (strcmp(mesh_name, "mesh"))
-		goto done;
+	if (!hex2str(node_uuid_get(node), 16, uuid, sizeof(uuid)))
+		return;
 
-	nftw(node_path, del_fobject, 5, FTW_DEPTH | FTW_PHYS);
+	node_name = basename(node_path);
 
-done:
-	l_free(mesh_path);
+	if (strcmp(node_name, uuid))
+		return;
+
+	nftw(node_path, del_fobject, 5, FTW_DEPTH | FTW_PHYS);
 }
-- 
2.21.0




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux