summaryrefslogtreecommitdiff
path: root/source/l/hal/patches/fixup_udi_strings.diff
blob: 03549ec1de487654ac178536f31a41ccd6dec186 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Author: Danny Kukawka <danny.kukawka@web.de>
Date:   Mon Oct 13 12:55:48 2008 +0200

    fix udi: replace '/' in the last part of the udi
    
    Fixed udi handling. DBus forbids a '/' after the base path
    (in case of HAL: '/org/freedesktop/Hal/devices/) of a DBus
    path. Replace all not allowed chars in the last part of the
    UDI (everything but _a-zA-Z0-9) with a '_'.
    
    This fixes also fd.o#16040.

diff --git a/hald/hald.c b/hald/hald.c
index a28d22e..051b33b 100644
--- a/hald/hald.c
+++ b/hald/hald.c
@@ -265,6 +265,8 @@ hald_compute_udi (gchar *dst, gsize dstsize, const gchar *format, ...)
 	hal_util_compute_udi_valist (hald_get_gdl (), dst, dstsize, format, args);
 	va_end (args);
 
+	hal_util_validate_udi (dst, dstsize);
+
 	if (hal_device_store_find (hald_get_gdl (), dst) == NULL &&
 	    hal_device_store_find (hald_get_tdl (), dst) == NULL)
 		goto out;
diff --git a/hald/util.c b/hald/util.c
index 901e64f..81060e4 100644
--- a/hald/util.c
+++ b/hald/util.c
@@ -422,6 +422,26 @@ hal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gc
 	va_end (args);
 }
 
+void
+hal_util_validate_udi (gchar *udi, gsize size) {
+
+	char end[size];
+
+	if (sscanf (udi, "/org/freedesktop/Hal/devices/%s", end) == 1) {
+		if (strstr(end, "/") != NULL) {
+			HAL_DEBUG (("UDI end contains invalid char '/': '%s'", udi));
+
+			g_strcanon (end, "_"
+		    			 "abcdefghijklmnopqrstuvwxyz"
+		    			 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+		   	 		 "1234567890", '_');
+			g_snprintf (udi, size, "/org/freedesktop/Hal/devices/%s", end);
+
+			HAL_DEBUG (("Fixed UDI, replaced '/', new UDI: %s", udi));
+		}
+	} 
+}
+
 
 gboolean
 hal_util_path_ascend (gchar *path)
diff --git a/hald/util.h b/hald/util.h
index 510c36c..5377e35 100644
--- a/hald/util.h
+++ b/hald/util.h
@@ -70,6 +70,8 @@ void hal_util_compute_udi_valist (HalDeviceStore *store, gchar *dst, gsize dstsi
 
 void hal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, ...);
 
+void hal_util_validate_udi (gchar *udi, gsize size);
+
 gboolean hal_util_path_ascend (gchar *path);
 
 void hal_util_grep_discard_existing_data (void);