summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPavel Březina <pbrezina@redhat.com>2012-04-23 18:30:14 +0200
committerStephen Gallagher <sgallagh@redhat.com>2012-06-29 11:37:17 -0400
commit2c5f1e5faf50b8a5118b99ad1dc19736d4f146b8 (patch)
tree7bcd0ff7c2ba0a69c6515ee7e07d3b525784e72f /src
parent7ca8196d719879840116b65398f6f2029c4b7cdb (diff)
downloadsssd-2c5f1e5faf50b8a5118b99ad1dc19736d4f146b8.tar.gz
sssd-2c5f1e5faf50b8a5118b99ad1dc19736d4f146b8.tar.bz2
sssd-2c5f1e5faf50b8a5118b99ad1dc19736d4f146b8.zip
sudo backend - add support for on demand refresh of specific rules
Diffstat (limited to 'src')
-rw-r--r--src/providers/data_provider_be.c68
1 files changed, 61 insertions, 7 deletions
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index 2bc02921..5d51f2fa 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -968,13 +968,18 @@ static int be_sudo_handler(DBusMessage *message, struct sbus_connection *conn)
{
DBusError dbus_error;
DBusMessage *reply = NULL;
+ DBusMessageIter iter;
+ dbus_bool_t iter_next = FALSE;
struct be_client *be_cli = NULL;
struct be_req *be_req = NULL;
struct be_sudo_req *sudo_req = NULL;
void *user_data = NULL;
int ret = 0;
uint32_t type;
+ uint32_t rules_num = 0;
+ const char *rule = NULL;
const char *err_msg = NULL;
+ int i;
DEBUG(SSSDBG_TRACE_FUNC, ("Entering be_sudo_handler()\n"));
@@ -1009,18 +1014,17 @@ static int be_sudo_handler(DBusMessage *message, struct sbus_connection *conn)
be_req->fn = be_sudo_handler_callback;
dbus_error_init(&dbus_error);
+ dbus_message_iter_init(message, &iter);
/* get type of the request */
- ret = dbus_message_get_args(message, &dbus_error,
- DBUS_TYPE_UINT32, &type,
- DBUS_TYPE_INVALID);
- if (!ret) {
- DEBUG(SSSDBG_CRIT_FAILURE, ("Failed, to parse message!\n"));
- if (dbus_error_is_set(&dbus_error)) dbus_error_free(&dbus_error);
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed, to parse the message!\n"));
ret = EIO;
- err_msg = "dbus_message_get_args failed";
+ err_msg = "Invalid D-Bus message format";
goto fail;
}
+ dbus_message_iter_get_basic(&iter, &type);
+ dbus_message_iter_next(&iter); /* step behind the request type */
/* If we are offline and fast reply was requested
* return offline immediately
@@ -1051,6 +1055,56 @@ static int be_sudo_handler(DBusMessage *message, struct sbus_connection *conn)
case BE_REQ_SUDO_FULL:
/* no arguments required */
break;
+ case BE_REQ_SUDO_RULES:
+ /* additional arguments:
+ * rules_num
+ * rules[rules_num]
+ */
+ /* read rules_num */
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed, to parse the message!\n"));
+ ret = EIO;
+ err_msg = "Invalid D-Bus message format";
+ goto fail;
+ }
+
+ dbus_message_iter_get_basic(&iter, &rules_num);
+
+ sudo_req->rules = talloc_array(sudo_req, char*, rules_num + 1);
+ if (sudo_req->rules == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("talloc_array failed.\n"));
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ /* read the rules */
+ for (i = 0; i < rules_num; i++) {
+ iter_next = dbus_message_iter_next(&iter);
+ if (iter_next == FALSE) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed, to parse the message!\n"));
+ ret = EIO;
+ err_msg = "Invalid D-Bus message format";
+ goto fail;
+ }
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed, to parse the message!\n"));
+ ret = EIO;
+ err_msg = "Invalid D-Bus message format";
+ goto fail;
+ }
+
+ dbus_message_iter_get_basic(&iter, &rule);
+ sudo_req->rules[i] = talloc_strdup(sudo_req->rules, rule);
+ if (sudo_req->rules[i] == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("talloc_strdup failed.\n"));
+ ret = ENOMEM;
+ goto fail;
+ }
+ }
+
+ sudo_req->rules[rules_num] = NULL;
+
+ break;
default:
DEBUG(SSSDBG_CRIT_FAILURE, ("Invalid request type %d\n", sudo_req->type));
ret = EINVAL;