summaryrefslogtreecommitdiffstats
path: root/meta-security/recipes-core/dbus/dbus-cynara/0008-Add-GetConnectionSmackContext-D-Bus-daemon-method.patch
blob: 43a1ef658e4084e694143386557dbb308ff43071 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
From 6c9997fb1cdff4281166e8c2fb8276018b1025dd Mon Sep 17 00:00:00 2001
From: Jacek Bukarewicz <j.bukarewicz@samsung.com>
Date: Mon, 15 Jun 2015 11:46:47 +0200
Subject: [PATCH 8/8] Add "GetConnectionSmackContext" D-Bus daemon method

This method is used to obtain smack label of given D-Bus client.
Note that it is deprecated and is included only for compatilibity with
existing D-Bus users. GetConnectionCredentials should be used to obtain
client's credentials.

Change-Id: Idf9648032ca5cbd9605ffab055e6384baa4eb9b4
---
 bus/driver.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/bus/driver.c b/bus/driver.c
index 9708f49..4e76224 100644
--- a/bus/driver.c
+++ b/bus/driver.c
@@ -1759,6 +1759,65 @@ bus_driver_handle_get_id (DBusConnection *connection,
   return BUS_RESULT_FALSE;
 }
 
+static BusResult
+bus_driver_handle_get_connection_smack_context (DBusConnection *connection,
+                                                BusTransaction *transaction,
+                                                DBusMessage    *message,
+                                                DBusError      *error)
+{
+  DBusConnection *conn;
+  DBusMessage *reply = NULL;
+  char *label = NULL;
+  const char *service;
+
+  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+  conn = bus_driver_get_conn_helper (connection, message, "credentials",
+                                     &service, error);
+  if (conn == NULL)
+    goto err;
+
+  reply = dbus_message_new_method_return (message);
+  if (reply == NULL)
+    goto oom;
+
+  if (!_dbus_connection_get_linux_security_label (conn, &label))
+   {
+      dbus_set_error (error, DBUS_ERROR_FAILED,
+                      "Failed to get smack label of connection",
+                      conn);
+      goto err;
+   }
+
+  if (label == NULL)
+    goto oom;
+
+  if (!dbus_message_append_args (reply,
+                                 DBUS_TYPE_STRING, &label,
+                                 DBUS_TYPE_INVALID))
+    goto oom;
+
+  if (!bus_transaction_send_from_driver (transaction, connection, reply))
+    goto oom;
+
+  dbus_message_unref (reply);
+  dbus_free(label);
+
+  return BUS_RESULT_TRUE;
+
+oom:
+  BUS_SET_OOM (error);
+
+err:
+  if (reply != NULL)
+    dbus_message_unref (reply);
+
+  dbus_free(label);
+
+  return BUS_RESULT_FALSE;
+}
+
+
 typedef struct
 {
   const char *name;
@@ -1849,6 +1908,10 @@ static const MessageHandler dbus_message_handlers[] = {
     bus_driver_handle_get_id },
   { "GetConnectionCredentials", "s", "a{sv}",
     bus_driver_handle_get_connection_credentials },
+  { "GetConnectionSmackContext", /* deprecated - you should use GetConnectionCredentials instead */
+    DBUS_TYPE_STRING_AS_STRING,
+    DBUS_TYPE_STRING_AS_STRING,
+    bus_driver_handle_get_connection_smack_context },
   { NULL, NULL, NULL, NULL }
 };
 
-- 
2.1.4