LCOV - code coverage report
Current view: top level - responder/ssh - sshsrv_dp.c (source / functions) Hit Total Coverage
Test: .coverage.total Lines: 0 54 0.0 %
Date: 2015-10-19 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /*
       2             :     Authors:
       3             :         Jakub Hrozek <jhrozek@redhat.com>
       4             : 
       5             :     Copyright (C) 2012 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/ssh/sshsrv_private.h"
      31             : 
      32             : struct sss_dp_get_ssh_host_info {
      33             :     struct sss_domain_info *dom;
      34             : 
      35             :     bool fast_reply;
      36             :     const char *name;
      37             :     const char *alias;
      38             : };
      39             : 
      40             : static DBusMessage *
      41             : sss_dp_get_ssh_host_msg(void *pvt);
      42             : 
      43             : struct tevent_req *
      44           0 : sss_dp_get_ssh_host_send(TALLOC_CTX *mem_ctx,
      45             :                          struct resp_ctx *rctx,
      46             :                          struct sss_domain_info *dom,
      47             :                          bool fast_reply,
      48             :                          const char *name,
      49             :                          const char *alias)
      50             : {
      51             :     errno_t ret;
      52             :     struct tevent_req *req;
      53             :     struct sss_dp_get_ssh_host_info *info;
      54             :     struct sss_dp_req_state *state;
      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_ssh_host_info);
      69           0 :     info->fast_reply = fast_reply;
      70           0 :     info->name = name;
      71           0 :     info->alias = alias;
      72           0 :     info->dom = dom;
      73             : 
      74           0 :     if (alias) {
      75           0 :         key = talloc_asprintf(state, "%s:%s@%s", name, alias, dom->name);
      76             :     } else {
      77           0 :         key = talloc_asprintf(state, "%s@%s", name, dom->name);
      78             :     }
      79           0 :     if (!key) {
      80           0 :         ret = ENOMEM;
      81           0 :         goto error;
      82             :     }
      83             : 
      84           0 :     ret = sss_dp_issue_request(state, rctx, key, dom, sss_dp_get_ssh_host_msg,
      85             :                                info, req);
      86           0 :     talloc_free(key);
      87           0 :     if (ret != EOK) {
      88           0 :         DEBUG(SSSDBG_OP_FAILURE,
      89             :               "Could not issue DP request [%d]: %s\n",
      90             :                ret, strerror(ret));
      91           0 :         goto error;
      92             :     }
      93             : 
      94           0 :     return req;
      95             : 
      96             : error:
      97           0 :     tevent_req_error(req, ret);
      98           0 :     tevent_req_post(req, rctx->ev);
      99           0 :     return req;
     100             : }
     101             : 
     102             : static DBusMessage *
     103           0 : sss_dp_get_ssh_host_msg(void *pvt)
     104             : {
     105             :     DBusMessage *msg;
     106             :     dbus_bool_t dbret;
     107             :     struct sss_dp_get_ssh_host_info *info;
     108           0 :     uint32_t be_type = 0;
     109             :     char *filter;
     110             : 
     111           0 :     info = talloc_get_type(pvt, struct sss_dp_get_ssh_host_info);
     112             : 
     113           0 :     if (info->fast_reply) {
     114           0 :         be_type |= BE_REQ_FAST;
     115             :     }
     116             : 
     117           0 :     if (info->alias) {
     118           0 :         filter = talloc_asprintf(info, "name=%s:%s", info->name, info->alias);
     119             :     } else {
     120           0 :         filter = talloc_asprintf(info, "name=%s", info->name);
     121             :     }
     122           0 :     if (!filter) {
     123           0 :         DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory?!\n");
     124           0 :         return NULL;
     125             :     }
     126             : 
     127           0 :     msg = dbus_message_new_method_call(NULL,
     128             :                                        DP_PATH,
     129             :                                        DATA_PROVIDER_IFACE,
     130             :                                        DATA_PROVIDER_IFACE_HOSTHANDLER);
     131           0 :     if (msg == NULL) {
     132           0 :         DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory?!\n");
     133           0 :         talloc_free(filter);
     134           0 :         return NULL;
     135             :     }
     136             : 
     137             :     /* create the message */
     138           0 :     DEBUG(SSSDBG_TRACE_FUNC,
     139             :           "Creating SSH host request for [%s][%u][%s]\n",
     140             :            info->dom->name, be_type, filter);
     141             : 
     142           0 :     dbret = dbus_message_append_args(msg,
     143             :                                      DBUS_TYPE_UINT32, &be_type,
     144             :                                      DBUS_TYPE_STRING, &filter,
     145             :                                      DBUS_TYPE_INVALID);
     146           0 :     talloc_free(filter);
     147           0 :     if (!dbret) {
     148           0 :         DEBUG(SSSDBG_CRIT_FAILURE, "Failed to build message\n");
     149           0 :         dbus_message_unref(msg);
     150           0 :         return NULL;
     151             :     }
     152             : 
     153           0 :     return msg;
     154             : }
     155             : 
     156             : errno_t
     157           0 : sss_dp_get_ssh_host_recv(TALLOC_CTX *mem_ctx,
     158             :                          struct tevent_req *req,
     159             :                          dbus_uint16_t *dp_err,
     160             :                          dbus_uint32_t *dp_ret,
     161             :                          char **err_msg)
     162             : {
     163           0 :     return sss_dp_req_recv(mem_ctx, req, dp_err, dp_ret, err_msg);
     164             : }

Generated by: LCOV version 1.10