diff options
author | sanghyeok.oh <sanghyeok.oh@samsung.com> | 2019-07-30 12:01:33 +0900 |
---|---|---|
committer | sanghyeok.oh <sanghyeok.oh@samsung.com> | 2019-07-30 12:01:36 +0900 |
commit | 4911ed550dd3db381545eead47aa9a4b7f1492c7 (patch) | |
tree | 99fe693add0d6f9c7f0e664879438ea6698c470d | |
parent | 8bc6e79854e048e2913a2d7d66427064162b2ab5 (diff) | |
download | dbus-4911ed550dd3db381545eead47aa9a4b7f1492c7.tar.gz dbus-4911ed550dd3db381545eead47aa9a4b7f1492c7.tar.bz2 dbus-4911ed550dd3db381545eead47aa9a4b7f1492c7.zip |
policy: modify complaint log to print out matched rulesubmit/tizen/20190812.022819accepted/tizen/unified/20190816.112439
Reconstruct rule with xml format.
Change-Id: I760f5c89f519672743a10fa15b66ac14b7e819a1
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
-rw-r--r-- | bus/bus.c | 30 | ||||
-rw-r--r-- | bus/check.c | 2 | ||||
-rw-r--r-- | bus/policy.c | 110 | ||||
-rw-r--r-- | bus/policy.h | 6 |
4 files changed, 132 insertions, 16 deletions
@@ -1463,7 +1463,8 @@ complain_about_message (BusContext *context, dbus_bool_t requested_reply, dbus_bool_t log, const char *privilege, - DBusError *error) + DBusError *error, + const char *rule) { DBusError stack_error = DBUS_ERROR_INIT; const char *sender_name; @@ -1493,7 +1494,8 @@ complain_about_message (BusContext *context, "%s, %d matched rules; type=\"%s\", sender=\"%s\" (%s) " "interface=\"%s\" member=\"%s\" error name=\"%s\" " "requested_reply=\"%d\" destination=\"%s\" " - "privilege=\"%s\" (%s)", + "privilege=\"%s\" (%s) " + "rule(%s)", complaint, matched_rules, dbus_message_type_to_string (dbus_message_get_type (message)), @@ -1505,7 +1507,8 @@ complain_about_message (BusContext *context, requested_reply, nonnull (dbus_message_get_destination (message), DBUS_SERVICE_DBUS), nonnull (privilege, "(n/a)"), - proposed_recipient_loginfo); + proposed_recipient_loginfo, + rule); /* If we hit OOM while setting the error, this will syslog "out of memory" * which is itself an indication that something is seriously wrong */ @@ -1552,6 +1555,7 @@ bus_context_check_security_policy (BusContext *context, int type; dbus_bool_t requested_reply; const char *privilege; + char *out_rule = NULL; type = dbus_message_get_type (message); src = dbus_message_get_sender (message); @@ -1640,7 +1644,7 @@ bus_context_check_security_policy (BusContext *context, complain_about_message (context, DBUS_ERROR_ACCESS_DENIED, "An SELinux policy prevents this sender from sending this " "message to this recipient", - 0, message, sender, proposed_recipient, FALSE, FALSE, NULL, error); + 0, message, sender, proposed_recipient, FALSE, FALSE, NULL, error, NULL); _dbus_verbose ("SELinux security check denying send to service\n"); } @@ -1744,7 +1748,7 @@ bus_context_check_security_policy (BusContext *context, addressed_recipient, proposed_recipient, message, &toggles, &log, &privilege, - deferred_message)) + deferred_message, &out_rule)) { case BUS_RESULT_TRUE: break; @@ -1753,8 +1757,10 @@ bus_context_check_security_policy (BusContext *context, "Rejected send message", toggles, message, sender, proposed_recipient, requested_reply, (addressed_recipient == proposed_recipient), privilege, - error); + error, out_rule); _dbus_verbose ("security policy disallowing message due to sender policy\n"); + if (out_rule) + free (out_rule); return BUS_RESULT_FALSE; break; case BUS_RESULT_LATER: @@ -1770,7 +1776,7 @@ bus_context_check_security_policy (BusContext *context, complain_about_message (context, DBUS_ERROR_ACCESS_DENIED, "Would reject message", toggles, message, sender, proposed_recipient, requested_reply, - TRUE, privilege, NULL); + TRUE, privilege, NULL, NULL); } if (recipient_policy) { @@ -1779,7 +1785,7 @@ bus_context_check_security_policy (BusContext *context, requested_reply, sender, addressed_recipient, proposed_recipient, - message, &toggles, &privilege, deferred_message)) + message, &toggles, &privilege, deferred_message, &out_rule)) { case BUS_RESULT_TRUE: break; @@ -1787,9 +1793,11 @@ bus_context_check_security_policy (BusContext *context, complain_about_message(context, DBUS_ERROR_ACCESS_DENIED, "Rejected receive message", toggles, message, sender, proposed_recipient, requested_reply, - (addressed_recipient == proposed_recipient), privilege, error); + (addressed_recipient == proposed_recipient), privilege, error, out_rule); _dbus_verbose( "security policy disallowing message due to recipient policy\n"); + if (out_rule) + free (out_rule); return BUS_RESULT_FALSE; case BUS_RESULT_LATER: return BUS_RESULT_LATER; @@ -1873,7 +1881,7 @@ bus_context_complain_about_message (BusContext *context, DBusError *error) { complain_about_message(context, error_name, complaint, matched_rules, message, sender, - proposed_recipient, requested_reply, log, privilege, error); + proposed_recipient, requested_reply, log, privilege, error, NULL); } dbus_bool_t bus_context_check_recipient_message_limits (BusContext *context, @@ -1891,7 +1899,7 @@ dbus_bool_t bus_context_check_recipient_message_limits (BusContext *context, complain_about_message (context, DBUS_ERROR_LIMITS_EXCEEDED, "Rejected: destination has a full message queue", 0, message, sender, recipient, requested_reply, TRUE, NULL, - error); + error, NULL); _dbus_verbose ("security policy disallowing message due to full message queue\n"); return FALSE; } diff --git a/bus/check.c b/bus/check.c index 2aeb69e5..3cc01f81 100644 --- a/bus/check.c +++ b/bus/check.c @@ -173,7 +173,7 @@ bus_check_queued_message_reply_callback (BusDeferredMessage *deferred_message, deferred_message->response = bus_client_policy_check_can_receive(recipient_policy, registry, deferred_message->requested_reply, deferred_message->sender, deferred_message->addressed_recipient, deferred_message->proposed_recipient, deferred_message->message, - &toggles, NULL, &deferred_message_receive); + &toggles, NULL, &deferred_message_receive, NULL); if (deferred_message->response == BUS_RESULT_LATER) { /* replace deferred message associated with send check with the one associated with diff --git a/bus/policy.c b/bus/policy.c index 19906212..24c0f06d 100644 --- a/bus/policy.c +++ b/bus/policy.c @@ -868,6 +868,94 @@ bus_client_policy_append_rule (BusClientPolicy *policy, return TRUE; } +#define _dbus_string_append_printf_err_check(str, fmt, args...) \ + if (!_dbus_string_append_printf(str, fmt, ##args)) \ + { \ + _dbus_string_free (str); \ + return FALSE; \ + } + +dbus_bool_t bus_policy_rule_to_string (BusPolicyRule *rule, + char **out_rule) +{ + const char *sr; + const char *access; + const char *dest; + const char *msg_type[] = {"Invalid", "method_call", "method_return", "signal", "error"}; + DBusString str; + + *out_rule = NULL; + + switch (rule->access) + { + case BUS_POLICY_RULE_ACCESS_ALLOW: + access = "allow"; + break; + case BUS_POLICY_RULE_ACCESS_DENY: + access = "deny"; + break; + case BUS_POLICY_RULE_ACCESS_CHECK: + access = "check"; + break; + } + + if (rule->type == BUS_POLICY_RULE_SEND) + { + sr = "send"; + dest = "destination"; + } + else if (rule->type == BUS_POLICY_RULE_RECEIVE) + { + sr = "receive"; + dest = "sender"; + } + else + return FALSE; + + /* generate xml format */ + if (!_dbus_string_init (&str)) + return FALSE; + + _dbus_string_append_printf_err_check (&str, "<%s ", access); + + if (rule->d.send.destination_prefix) + { + _dbus_string_append_printf_err_check (&str, "%s_destination_prefix=\"%s\" ", sr, rule->d.send.destination); + } + else if (rule->d.send.destination) + { + _dbus_string_append_printf_err_check (&str, "%s_%s=\"%s\" ", sr, dest, rule->d.send.destination); + } + + if (rule->d.send.path) + _dbus_string_append_printf_err_check (&str, "%s_path=\"%s\" ", sr, rule->d.send.path); + if (rule->d.send.interface) + _dbus_string_append_printf_err_check (&str, "%s_interface=\"%s\" ", sr, rule->d.send.interface); + if (rule->d.send.member) + _dbus_string_append_printf_err_check (&str, "%s_member=\"%s\" ", sr, rule->d.send.member); + if (rule->d.send.message_type) + _dbus_string_append_printf_err_check (&str, "%s_type=\"%s\" ", sr, msg_type[rule->d.send.message_type]); + if (rule->privilege) + _dbus_string_append_printf_err_check (&str, "privilege=\"%s\" ", rule->privilege); + + if (!_dbus_string_append (&str, "/>")) + { + _dbus_string_free (&str); + return FALSE; + } + + if (!_dbus_string_steal_data (&str, out_rule)) + { + *out_rule = NULL; + _dbus_string_free (&str); + return FALSE; + } + + _dbus_string_free (&str); + + return TRUE; +} + BusResult bus_client_policy_check_can_send (DBusConnection *sender, BusClientPolicy *policy, @@ -879,11 +967,13 @@ bus_client_policy_check_can_send (DBusConnection *sender, dbus_int32_t *toggles, dbus_bool_t *log, const char **privilege_param, - BusDeferredMessage **deferred_message) + BusDeferredMessage **deferred_message, + char **out_rule) { DBusList *link; BusResult result; const char *privilege; + BusPolicyRule *matched_rule = NULL; /* policy->rules is in the order the rules appeared * in the config file, i.e. last rule that applies wins @@ -1103,6 +1193,7 @@ bus_client_policy_check_can_send (DBusConnection *sender, *log = rule->d.send.log; (*toggles)++; + matched_rule = rule; _dbus_verbose (" (policy) used rule, result now = %d\n", result); @@ -1125,6 +1216,12 @@ bus_client_policy_check_can_send (DBusConnection *sender, if (privilege_param != NULL) *privilege_param = privilege; + if (result == BUS_RESULT_FALSE) + { + if (matched_rule && out_rule) + bus_policy_rule_to_string (matched_rule, out_rule); + } + return result; } @@ -1141,12 +1238,14 @@ bus_client_policy_check_can_receive (BusClientPolicy *policy, DBusMessage *message, dbus_int32_t *toggles, const char **privilege_param, - BusDeferredMessage **deferred_message) + BusDeferredMessage **deferred_message, + char **out_rule) { DBusList *link; dbus_bool_t eavesdropping; BusResult result; const char *privilege; + BusPolicyRule *matched_rule = NULL; eavesdropping = addressed_recipient != proposed_recipient && @@ -1339,6 +1438,7 @@ bus_client_policy_check_can_receive (BusClientPolicy *policy, } (*toggles)++; + matched_rule = rule; _dbus_verbose (" (policy) used rule, result now = %d\n", result); @@ -1362,6 +1462,12 @@ bus_client_policy_check_can_receive (BusClientPolicy *policy, if (privilege_param != NULL) *privilege_param = privilege; + if (result == BUS_RESULT_FALSE) + { + if (matched_rule && out_rule) + bus_policy_rule_to_string (matched_rule, out_rule); + } + return result; } diff --git a/bus/policy.h b/bus/policy.h index d80c7753..951ece1f 100644 --- a/bus/policy.h +++ b/bus/policy.h @@ -160,7 +160,8 @@ BusResult bus_client_policy_check_can_send (DBusConnection *sende dbus_int32_t *toggles, dbus_bool_t *log, const char **privilege_param, - BusDeferredMessage **deferred_message); + BusDeferredMessage **deferred_message, + char **out_rule); BusResult bus_client_policy_check_can_receive (BusClientPolicy *policy, BusRegistry *registry, dbus_bool_t requested_reply, @@ -170,7 +171,8 @@ BusResult bus_client_policy_check_can_receive (BusClientPolicy *polic DBusMessage *message, dbus_int32_t *toggles, const char **privilege_param, - BusDeferredMessage **deferred_message); + BusDeferredMessage **deferred_message, + char **out_rule); BusResult bus_client_policy_check_can_own (BusClientPolicy *policy, const DBusString *service_name, DBusConnection *connection, |