Line data Source code
1 : /*
2 : Authors:
3 : Jakub Hrozek <jhrozek@redhat.com>
4 :
5 : Copyright (C) 2011 Red Hat
6 :
7 : This program is free software; you can redistribute it and/or modify
8 : it under the terms of the GNU General Public License as published by
9 : the Free Software Foundation; either version 3 of the License, or
10 : (at your option) any later version.
11 :
12 : This program is distributed in the hope that it will be useful,
13 : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : GNU General Public License for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with this program. If not, see <http://www.gnu.org/licenses/>.
19 : */
20 :
21 : #include <talloc.h>
22 : #include <tevent.h>
23 : #include <dbus/dbus.h>
24 : #include "sbus/sssd_dbus.h"
25 :
26 : #include "util/util.h"
27 : #include "sbus/sbus_client.h"
28 : #include "providers/data_provider.h"
29 : #include "responder/common/responder.h"
30 : #include "responder/autofs/autofs_private.h"
31 :
32 : struct sss_dp_get_autofs_info {
33 : struct sss_domain_info *dom;
34 :
35 : bool fast_reply;
36 : enum sss_dp_autofs_type type;
37 : const char *name;
38 : };
39 :
40 : static DBusMessage *
41 : sss_dp_get_autofs_msg(void *pvt);
42 :
43 : struct tevent_req *
44 0 : sss_dp_get_autofs_send(TALLOC_CTX *mem_ctx,
45 : struct resp_ctx *rctx,
46 : struct sss_domain_info *dom,
47 : bool fast_reply,
48 : enum sss_dp_autofs_type type,
49 : const char *name)
50 : {
51 : struct tevent_req *req;
52 : struct sss_dp_req_state *state;
53 : struct sss_dp_get_autofs_info *info;
54 : errno_t ret;
55 : char *key;
56 :
57 0 : req = tevent_req_create(mem_ctx, &state, struct sss_dp_req_state);
58 0 : if (!req) {
59 0 : ret = ENOMEM;
60 0 : goto error;
61 : }
62 :
63 0 : if (!dom) {
64 0 : ret = EINVAL;
65 0 : goto error;
66 : }
67 :
68 0 : info = talloc_zero(state, struct sss_dp_get_autofs_info);
69 0 : info->fast_reply = fast_reply;
70 0 : info->type = type;
71 0 : info->name = name;
72 0 : info->dom = dom;
73 :
74 0 : key = talloc_asprintf(state, "%d:%s@%s", type, name, dom->name);
75 0 : if (!key) {
76 0 : ret = ENOMEM;
77 0 : goto error;
78 : }
79 :
80 0 : ret = sss_dp_issue_request(state, rctx, key, dom, sss_dp_get_autofs_msg,
81 : info, req);
82 0 : talloc_free(key);
83 0 : if (ret != EOK) {
84 0 : DEBUG(SSSDBG_OP_FAILURE,
85 : "Could not issue DP request [%d]: %s\n",
86 : ret, strerror(ret));
87 0 : goto error;
88 : }
89 :
90 0 : return req;
91 :
92 : error:
93 0 : tevent_req_error(req, ret);
94 0 : tevent_req_post(req, rctx->ev);
95 0 : return req;
96 : }
97 :
98 : static DBusMessage *
99 0 : sss_dp_get_autofs_msg(void *pvt)
100 : {
101 : DBusMessage *msg;
102 : dbus_bool_t dbret;
103 : struct sss_dp_get_autofs_info *info;
104 0 : uint32_t be_type = BE_REQ_AUTOFS;
105 : char *filter;
106 :
107 0 : info = talloc_get_type(pvt, struct sss_dp_get_autofs_info);
108 :
109 0 : if (info->fast_reply) {
110 0 : be_type |= BE_REQ_FAST;
111 : }
112 :
113 0 : filter = talloc_asprintf(info, "mapname=%s", info->name);
114 0 : if (!filter) {
115 0 : DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory?!\n");
116 0 : return NULL;
117 : }
118 :
119 0 : msg = dbus_message_new_method_call(NULL,
120 : DP_PATH,
121 : DATA_PROVIDER_IFACE,
122 : DATA_PROVIDER_IFACE_AUTOFSHANDLER);
123 0 : if (msg == NULL) {
124 0 : DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory?!\n");
125 0 : return NULL;
126 : }
127 :
128 : /* create the message */
129 0 : DEBUG(SSSDBG_TRACE_FUNC,
130 : "Creating autofs request for [%s][%u][%s]\n",
131 : info->dom->name, be_type, filter);
132 :
133 0 : dbret = dbus_message_append_args(msg,
134 : DBUS_TYPE_UINT32, &be_type,
135 : DBUS_TYPE_STRING, &filter,
136 : DBUS_TYPE_INVALID);
137 0 : talloc_free(filter);
138 0 : if (!dbret) {
139 0 : DEBUG(SSSDBG_CRIT_FAILURE, "Failed to build message\n");
140 0 : dbus_message_unref(msg);
141 0 : return NULL;
142 : }
143 :
144 0 : return msg;
145 : }
146 :
147 : errno_t
148 0 : sss_dp_get_autofs_recv(TALLOC_CTX *mem_ctx,
149 : struct tevent_req *req,
150 : dbus_uint16_t *dp_err,
151 : dbus_uint32_t *dp_ret,
152 : char **err_msg)
153 : {
154 0 : return sss_dp_req_recv(mem_ctx, req, dp_err, dp_ret, err_msg);
155 : }
|