Integrate parts of meta-intel-iot-security
[AGL/meta-agl.git] / meta-security / recipes-core / dbus / dbus-cynara / 0008-Add-GetConnectionSmackContext-D-Bus-daemon-method.patch
1 From 6c9997fb1cdff4281166e8c2fb8276018b1025dd Mon Sep 17 00:00:00 2001
2 From: Jacek Bukarewicz <j.bukarewicz@samsung.com>
3 Date: Mon, 15 Jun 2015 11:46:47 +0200
4 Subject: [PATCH 8/8] Add "GetConnectionSmackContext" D-Bus daemon method
5
6 This method is used to obtain smack label of given D-Bus client.
7 Note that it is deprecated and is included only for compatilibity with
8 existing D-Bus users. GetConnectionCredentials should be used to obtain
9 client's credentials.
10
11 Change-Id: Idf9648032ca5cbd9605ffab055e6384baa4eb9b4
12 ---
13  bus/driver.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14  1 file changed, 63 insertions(+)
15
16 diff --git a/bus/driver.c b/bus/driver.c
17 index 9708f49..4e76224 100644
18 --- a/bus/driver.c
19 +++ b/bus/driver.c
20 @@ -1759,6 +1759,65 @@ bus_driver_handle_get_id (DBusConnection *connection,
21    return BUS_RESULT_FALSE;
22  }
23  
24 +static BusResult
25 +bus_driver_handle_get_connection_smack_context (DBusConnection *connection,
26 +                                                BusTransaction *transaction,
27 +                                                DBusMessage    *message,
28 +                                                DBusError      *error)
29 +{
30 +  DBusConnection *conn;
31 +  DBusMessage *reply = NULL;
32 +  char *label = NULL;
33 +  const char *service;
34 +
35 +  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
36 +
37 +  conn = bus_driver_get_conn_helper (connection, message, "credentials",
38 +                                     &service, error);
39 +  if (conn == NULL)
40 +    goto err;
41 +
42 +  reply = dbus_message_new_method_return (message);
43 +  if (reply == NULL)
44 +    goto oom;
45 +
46 +  if (!_dbus_connection_get_linux_security_label (conn, &label))
47 +   {
48 +      dbus_set_error (error, DBUS_ERROR_FAILED,
49 +                      "Failed to get smack label of connection",
50 +                      conn);
51 +      goto err;
52 +   }
53 +
54 +  if (label == NULL)
55 +    goto oom;
56 +
57 +  if (!dbus_message_append_args (reply,
58 +                                 DBUS_TYPE_STRING, &label,
59 +                                 DBUS_TYPE_INVALID))
60 +    goto oom;
61 +
62 +  if (!bus_transaction_send_from_driver (transaction, connection, reply))
63 +    goto oom;
64 +
65 +  dbus_message_unref (reply);
66 +  dbus_free(label);
67 +
68 +  return BUS_RESULT_TRUE;
69 +
70 +oom:
71 +  BUS_SET_OOM (error);
72 +
73 +err:
74 +  if (reply != NULL)
75 +    dbus_message_unref (reply);
76 +
77 +  dbus_free(label);
78 +
79 +  return BUS_RESULT_FALSE;
80 +}
81 +
82 +
83  typedef struct
84  {
85    const char *name;
86 @@ -1849,6 +1908,10 @@ static const MessageHandler dbus_message_handlers[] = {
87      bus_driver_handle_get_id },
88    { "GetConnectionCredentials", "s", "a{sv}",
89      bus_driver_handle_get_connection_credentials },
90 +  { "GetConnectionSmackContext", /* deprecated - you should use GetConnectionCredentials instead */
91 +    DBUS_TYPE_STRING_AS_STRING,
92 +    DBUS_TYPE_STRING_AS_STRING,
93 +    bus_driver_handle_get_connection_smack_context },
94    { NULL, NULL, NULL, NULL }
95  };
96  
97 -- 
98 2.1.4
99