9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek/*
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek Authors:
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek Copyright (C) 2011 Red Hat
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek This program is free software; you can redistribute it and/or modify
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek it under the terms of the GNU General Public License as published by
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek the Free Software Foundation; either version 3 of the License, or
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek (at your option) any later version.
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek This program is distributed in the hope that it will be useful,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek GNU General Public License for more details.
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek You should have received a copy of the GNU General Public License
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek*/
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include <talloc.h>
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include <tevent.h>
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include <dbus/dbus.h>
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include "sbus/sssd_dbus.h"
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include "util/util.h"
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include "sbus/sbus_client.h"
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina#include "providers/data_provider/dp_responder_iface.h"
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include "responder/common/responder.h"
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include "responder/autofs/autofs_private.h"
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstruct sss_dp_get_autofs_info {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct sss_domain_info *dom;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek bool fast_reply;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek enum sss_dp_autofs_type type;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek const char *name;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek};
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic DBusMessage *
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozeksss_dp_get_autofs_msg(void *pvt);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstruct tevent_req *
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozeksss_dp_get_autofs_send(TALLOC_CTX *mem_ctx,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct resp_ctx *rctx,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct sss_domain_info *dom,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek bool fast_reply,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek enum sss_dp_autofs_type type,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek const char *name)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct tevent_req *req;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct sss_dp_req_state *state;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct sss_dp_get_autofs_info *info;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek errno_t ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek char *key;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct sss_dp_req_state);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!req) {
a0c764a36f2f432e6063de84be6f6af7e96ec159Sumit Bose return NULL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!dom) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = EINVAL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto error;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek info = talloc_zero(state, struct sss_dp_get_autofs_info);
2c6c3cff23a0750a5f68b52cb1a52e241aa20615Jakub Hrozek if (info == NULL) {
2c6c3cff23a0750a5f68b52cb1a52e241aa20615Jakub Hrozek ret = ENOMEM;
2c6c3cff23a0750a5f68b52cb1a52e241aa20615Jakub Hrozek goto error;
2c6c3cff23a0750a5f68b52cb1a52e241aa20615Jakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek info->fast_reply = fast_reply;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek info->type = type;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek info->name = name;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek info->dom = dom;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek key = talloc_asprintf(state, "%d:%s@%s", type, name, dom->name);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!key) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto error;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = sss_dp_issue_request(state, rctx, key, dom, sss_dp_get_autofs_msg,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek info, req);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_free(key);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not issue DP request [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto error;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return req;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekerror:
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek tevent_req_error(req, ret);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek tevent_req_post(req, rctx->ev);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return req;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic DBusMessage *
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozeksss_dp_get_autofs_msg(void *pvt)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DBusMessage *msg;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dbus_bool_t dbret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct sss_dp_get_autofs_info *info;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina uint32_t dp_flags = 0;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek info = talloc_get_type(pvt, struct sss_dp_get_autofs_info);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (info->fast_reply) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_flags |= DP_FAST_REPLY;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek msg = dbus_message_new_method_call(NULL,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DP_PATH,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina IFACE_DP,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina IFACE_DP_AUTOFSHANDLER);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (msg == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory?!\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return NULL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* create the message */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Creating autofs request for [%s][%u][%s]\n",
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina info->dom->name, dp_flags, info->name);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dbret = dbus_message_append_args(msg,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DBUS_TYPE_UINT32, &dp_flags,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DBUS_TYPE_STRING, &info->name,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DBUS_TYPE_INVALID);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!dbret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to build message\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dbus_message_unref(msg);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return NULL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return msg;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekerrno_t
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozeksss_dp_get_autofs_recv(TALLOC_CTX *mem_ctx,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct tevent_req *req,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dbus_uint16_t *dp_err,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dbus_uint32_t *dp_ret,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek char **err_msg)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return sss_dp_req_recv(mem_ctx, req, dp_err, dp_ret, err_msg);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}